From 4db9f4b371282ac8dab2dc2015a64cb5d5727b60 Mon Sep 17 00:00:00 2001 From: "munkyu.im" Date: Tue, 22 Jan 2013 22:01:12 +0900 Subject: [PATCH] osutil: Migration "get host proxy" to osutil on Mac Signed-off-by: munkyu.im --- tizen/src/emulator.c | 2 +- tizen/src/osutil-darwin.c | 172 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 173 insertions(+), 1 deletion(-) diff --git a/tizen/src/emulator.c b/tizen/src/emulator.c index e35c52c..65407f8 100644 --- a/tizen/src/emulator.c +++ b/tizen/src/emulator.c @@ -345,7 +345,7 @@ static void prepare_basic_features(void) tizen_base_port = get_sdb_base_port(); // TODO: Codes about Getting host proxy migration is processing... -#if defined(CONFIG_LINUX) +#if !defined(CONFIG_WIN32) get_host_proxy(http_proxy, https_proxy, ftp_proxy, socks_proxy); #else gethostproxy(http_proxy, https_proxy, ftp_proxy, socks_proxy); diff --git a/tizen/src/osutil-darwin.c b/tizen/src/osutil-darwin.c index 966e7f6..5a15ec0 100644 --- a/tizen/src/osutil-darwin.c +++ b/tizen/src/osutil-darwin.c @@ -43,10 +43,34 @@ #include #include #include +#include MULTI_DEBUG_CHANNEL(qemu, osutil); extern int tizen_base_port; +CFDictionaryRef proxySettings; + +static char *cfstring_to_cstring(CFStringRef str) { + if (str == NULL) { + return NULL; + } + + CFIndex length = CFStringGetLength(str); + CFIndex maxSize = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8); + char *buffer = (char *)malloc(maxSize); + if (CFStringGetCString(str, buffer, maxSize, kCFStringEncodingUTF8)) + return buffer; + return NULL; +} + +static int cfnumber_to_int(CFNumberRef num) { + if (!num) + return 0; + + int value; + CFNumberGetValue(num, kCFNumberIntType, &value); + return value; +} void check_vm_lock_os(void) { @@ -151,3 +175,151 @@ void print_system_info_os(void) INFO("* Total memory : %llu bytes\n", sys_num); } } + +static int get_auto_proxy(char *http_proxy, char *https_proxy, char *ftp_proxy, char *socks_proxy) +{ + char type[MAXLEN]; + char proxy[MAXLEN]; + char line[MAXLEN]; + FILE *fp_pacfile; + char *p = NULL; + + CFStringRef pacURL = (CFStringRef)CFDictionaryGetValue(proxySettings, + kSCPropNetProxiesProxyAutoConfigURLString); + if (pacURL) { + char url[MAXLEN] = {}; + CFStringGetCString(pacURL, url, sizeof url, kCFStringEncodingASCII); + INFO("pac address: %s\n", (char*)url); + download_url(url); + } + + fp_pacfile = fopen(pac_tempfile, "r"); + if(fp_pacfile != NULL) { + while(fgets(line, MAXLEN, fp_pacfile) != NULL) { + if( (strstr(line, "return") != NULL) && (strstr(line, "if") == NULL)) { + INFO("line found %s", line); + sscanf(line, "%*[^\"]\"%s %s", type, proxy); + } + } + + if(g_str_has_prefix(type, DIRECT)) { + INFO("auto proxy is set to direct mode\n"); + fclose(fp_pacfile); + } + else if(g_str_has_prefix(type, PROXY)) { + INFO("auto proxy is set to proxy mode\n"); + INFO("type: %s, proxy: %s\n", type, proxy); + p = strtok(proxy, "\";"); + if(p != NULL) { + INFO("auto proxy to set: %s\n",p); + strcpy(http_proxy, p); + strcpy(https_proxy, p); + strcpy(ftp_proxy, p); + strcpy(socks_proxy, p); + } + fclose(fp_pacfile); + } + else + { + ERR("pac file is not wrong! It could be the wrong pac address or pac file format\n"); + fclose(fp_pacfile); + } + } + else { + ERR("fail to get pacfile fp\n"); + return -1; + } + + remove(pac_tempfile); + return 0; +} + +static void get_proxy(char *http_proxy, char *https_proxy, char *ftp_proxy, char *socks_proxy) +{ + char *hostname; + int port; + CFNumberRef isEnable; + CFStringRef proxyHostname; + CFNumberRef proxyPort; + CFDictionaryRef proxySettings; + proxySettings = SCDynamicStoreCopyProxies(NULL); + + isEnable = CFDictionaryGetValue(proxySettings, kSCPropNetProxiesHTTPEnable); + if (cfnumber_to_int(isEnable)) { + // Get proxy hostname + proxyHostname = CFDictionaryGetValue(proxySettings, kSCPropNetProxiesHTTPProxy); + hostname = cfstring_to_cstring(proxyHostname); + // Get proxy port + proxyPort = CFDictionaryGetValue(proxySettings, kSCPropNetProxiesHTTPPort); + port = cfnumber_to_int(proxyPort); + // Save hostname & port + snprintf(http_proxy, MAXLEN, "%s:%d", hostname, port); + + free(hostname); + } else { + INFO("http proxy is null\n"); + } + + isEnable = CFDictionaryGetValue(proxySettings, kSCPropNetProxiesHTTPSEnable); + if (cfnumber_to_int(isEnable)) { + // Get proxy hostname + proxyHostname = CFDictionaryGetValue(proxySettings, kSCPropNetProxiesHTTPSProxy); + hostname = cfstring_to_cstring(proxyHostname); + // Get proxy port + proxyPort = CFDictionaryGetValue(proxySettings, kSCPropNetProxiesHTTPSPort); + port = cfnumber_to_int(proxyPort); + // Save hostname & port + snprintf(https_proxy, MAXLEN, "%s:%d", hostname, port); + + free(hostname); + } else { + INFO("https proxy is null\n"); + } + + isEnable = CFDictionaryGetValue(proxySettings, kSCPropNetProxiesFTPEnable); + if (cfnumber_to_int(isEnable)) { + // Get proxy hostname + proxyHostname = CFDictionaryGetValue(proxySettings, kSCPropNetProxiesFTPProxy); + hostname = cfstring_to_cstring(proxyHostname); + // Get proxy port + proxyPort = CFDictionaryGetValue(proxySettings, kSCPropNetProxiesFTPPort); + port = cfnumber_to_int(proxyPort); + // Save hostname & port + snprintf(ftp_proxy, MAXLEN, "%s:%d", hostname, port); + + free(hostname); + } else { + INFO("ftp proxy is null\n"); + } + + isEnable = CFDictionaryGetValue(proxySettings, kSCPropNetProxiesSOCKSEnable); + if (cfnumber_to_int(isEnable)) { + // Get proxy hostname + proxyHostname = CFDictionaryGetValue(proxySettings, kSCPropNetProxiesSOCKSProxy); + hostname = cfstring_to_cstring(proxyHostname); + // Get proxy port + proxyPort = CFDictionaryGetValue(proxySettings, kSCPropNetProxiesSOCKSPort); + port = cfnumber_to_int(proxyPort); + // Save hostname & port + snprintf(socks_proxy, MAXLEN, "%s:%d", hostname, port); + + free(hostname); + } else { + INFO("socks proxy is null\n"); + } + CFRelease(proxySettings); +} + +void get_host_proxy_os(char *http_proxy, char *https_proxy, char *ftp_proxy, char *socks_proxy) +{ + int ret; + proxySettings = SCDynamicStoreCopyProxies(NULL); + if(proxySettings) { + INFO("AUTO PROXY MODE\n"); + ret = get_auto_proxy(http_proxy, https_proxy, ftp_proxy, socks_proxy); + if(strlen(http_proxy) == 0 && ret < 0) { + INFO("MANUAL PROXY MODE\n"); + get_proxy(http_proxy, https_proxy, ftp_proxy, socks_proxy); + } + } +} -- 2.7.4