sync
[sdk/emulator/qemu.git] / tizen / src / option.c
1 /* 
2  * Emulator
3  *
4  * Copyright (C) 2011, 2012 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: 
7  * SeokYeon Hwang <syeon.hwang@samsung.com>
8  * MunKyu Im <munkyu.im@samsung.com>
9  * GiWoong Kim <giwoong.kim@samsung.com>
10  * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
11  * HyunJun Son
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
26  *
27  * Contributors:
28  * - S-Core Co., Ltd
29  *
30  */
31
32 /**
33   @file option.c
34   @brief    collection of dialog function
35  */
36
37 #include "option.h"
38 #include "emulator.h"
39 #include "maru_common.h"
40 #if defined (CONFIG_LINUX)
41 #include <sys/ioctl.h>
42 #include <sys/types.h>
43 #include <sys/stat.h>
44 #include <sys/socket.h>
45 #include <unistd.h>
46 #include <netinet/in.h>
47 #include <net/if.h>
48 #elif defined (CONFIG_WIN32)
49 #include <windows.h>
50 #include <winsock2.h>
51 #include <iphlpapi.h>
52 #include <winreg.h>
53 #elif defined (CONFIG_DARWIN)
54 #include <SystemConfiguration/SystemConfiguration.h>
55 CFDictionaryRef proxySettings;
56 #endif
57 #include <curl/curl.h>
58
59 #include "debug_ch.h"
60
61 #define HTTP_PROTOCOL "http="
62 #define HTTP_PREFIX "http://"
63 #define HTTPS_PROTOCOL "https="
64 #define FTP_PROTOCOL "ftp="
65 #define SOCKS_PROTOCOL "socks="
66 #define DIRECT "DIRECT"
67 #define PROXY "PROXY"
68 #define MAXPORTLEN 6
69 MULTI_DEBUG_CHANNEL(tizen, option);
70 #if defined(CONFIG_WIN32)
71 BYTE *url;
72 #endif
73 const char *pactempfile = ".autoproxy"; 
74
75 /**
76   @brief    get host DNS server address
77   @param    dns1: return value (first dns server address)
78   @param    dns2: return value (second dns server address)
79   @return always 0
80  */
81 int gethostDNS(char *dns1, char *dns2)
82 {
83 #ifndef _WIN32
84     FILE *resolv;
85     char buf[255];
86     memset(buf, 0, sizeof(char)*255);
87
88     resolv = fopen("/etc/resolv.conf", "r");
89     if (resolv <= 0) {
90         ERR( "Can't open \"/etc/resolv.conf.\"\n");
91         fclose(resolv);
92         return 1;
93     }
94
95     while(fscanf(resolv , "%s", buf) != EOF) {
96         if(strcmp(buf, "nameserver") == 0)
97         {
98             if(fscanf(resolv , "%s", dns1) <= 0) {
99                 // do nothing...
100             }
101             break;
102         }
103     }
104
105     while(fscanf(resolv , "%s", buf) != EOF) {
106         if(strcmp(buf, "nameserver") == 0)
107         {
108             if(fscanf(resolv , "%s", dns2) <= 0) {
109                 // do nothing...
110             }
111             break;
112         }
113     }
114
115     fclose(resolv);
116 #else
117     PIP_ADAPTER_ADDRESSES pAdapterAddr;
118     PIP_ADAPTER_ADDRESSES pAddr;
119     PIP_ADAPTER_DNS_SERVER_ADDRESS pDnsAddr;
120     unsigned long nBufferLength = sizeof(IP_ADAPTER_ADDRESSES);
121     pAdapterAddr = (PIP_ADAPTER_ADDRESSES)malloc(nBufferLength);
122     memset(pAdapterAddr, 0x00, nBufferLength);
123
124     while (GetAdaptersAddresses(AF_INET, 0, NULL, pAdapterAddr, &nBufferLength)
125             == ERROR_BUFFER_OVERFLOW) {
126         free(pAdapterAddr);
127         pAdapterAddr = (PIP_ADAPTER_ADDRESSES)malloc(nBufferLength);
128         memset(pAdapterAddr, 0x00, nBufferLength);
129     }
130
131     pAddr = pAdapterAddr;
132     for (; pAddr != NULL; pAddr = pAddr->Next) {
133         pDnsAddr = pAddr->FirstDnsServerAddress;
134         for (; pDnsAddr != NULL; pDnsAddr = pDnsAddr->Next) {
135             struct sockaddr_in *pSockAddr = (struct sockaddr_in*)pDnsAddr->Address.lpSockaddr;
136             if(*dns1 == 0) {
137                 strcpy(dns1, inet_ntoa(pSockAddr->sin_addr));
138                 continue;
139             }
140             if(*dns2 == 0) {
141                 strcpy(dns2, inet_ntoa(pSockAddr->sin_addr));
142                 continue;
143             }
144         }
145     }
146     free(pAdapterAddr);
147 #endif
148
149     // by caramis... change DNS address if localhost has DNS server or DNS cache.
150     if(!strncmp(dns1, "127.0.0.1", 9) || !strncmp(dns1, "localhost", 9)) {
151         strncpy(dns1, "10.0.2.2", 9);
152     }
153     if(!strncmp(dns2, "127.0.0.1", 9) || !strncmp(dns2, "localhost", 9)) {
154         strncpy(dns2, "10.0.2.2", 9);
155     }
156
157     return 0;
158 }
159
160 #if defined (CONFIG_DARWIN)
161 static char *cfstring_to_cstring(CFStringRef str) {
162     if (str == NULL) {
163         return NULL;
164     }
165
166     CFIndex length = CFStringGetLength(str);
167     CFIndex maxSize = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8);
168     char *buffer = (char *)malloc(maxSize);
169     if (CFStringGetCString(str, buffer, maxSize, kCFStringEncodingUTF8))
170         return buffer;
171     return NULL;
172 }
173
174 static int cfnumber_to_int(CFNumberRef num) {
175     if (!num)
176         return 0;
177
178     int value;
179     CFNumberGetValue(num, kCFNumberIntType, &value);
180     return value;
181 }
182 #endif
183
184 static size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) 
185 {     
186     size_t written;
187     written = fwrite(ptr, size, nmemb, stream);
188     return written;
189 }  
190
191 static void download_url(char *url) 
192 {     
193     CURL *curl;     
194     FILE *fp;     
195     CURLcode res;     
196
197     curl = curl_easy_init();
198     if (curl) { 
199         fp = fopen(pactempfile,"wb");
200         curl_easy_setopt(curl, CURLOPT_URL, url);
201         curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
202         //just in case network does not work.
203         curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, 3000);
204         curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
205         res = curl_easy_perform(curl);
206         if(res != 0) {
207             ERR("Fail to download pac file: %s\n", url);
208         }
209         curl_easy_cleanup(curl); 
210         fclose(fp);
211     }     
212
213     return; 
214
215
216 #if defined (CONFIG_DARWIN)
217 static void getmacproxy(char *http_proxy, char *https_proxy, char *ftp_proxy, char *socks_proxy)
218 {
219     char *hostname;
220     int port;
221     CFNumberRef isEnable;
222     CFStringRef proxyHostname;
223     CFNumberRef proxyPort;
224     CFDictionaryRef proxySettings;
225     proxySettings = SCDynamicStoreCopyProxies(NULL);
226
227     isEnable  = CFDictionaryGetValue(proxySettings, kSCPropNetProxiesHTTPEnable);
228     if (cfnumber_to_int(isEnable)) {        
229         // Get proxy hostname
230         proxyHostname = CFDictionaryGetValue(proxySettings, kSCPropNetProxiesHTTPProxy);
231         hostname = cfstring_to_cstring(proxyHostname);
232         // Get proxy port
233         proxyPort = CFDictionaryGetValue(proxySettings, kSCPropNetProxiesHTTPPort);
234         port = cfnumber_to_int(proxyPort);
235         // Save hostname & port
236         snprintf(http_proxy, MAXLEN, "%s:%d", hostname, port);
237
238         free(hostname);
239     } else {
240         INFO("http proxy is null\n");
241     }
242     
243     isEnable  = CFDictionaryGetValue(proxySettings, kSCPropNetProxiesHTTPSEnable);
244     if (cfnumber_to_int(isEnable)) {        
245         // Get proxy hostname
246         proxyHostname = CFDictionaryGetValue(proxySettings, kSCPropNetProxiesHTTPSProxy);
247         hostname = cfstring_to_cstring(proxyHostname);
248         // Get proxy port
249         proxyPort = CFDictionaryGetValue(proxySettings, kSCPropNetProxiesHTTPSPort);
250         port = cfnumber_to_int(proxyPort);
251         // Save hostname & port
252         snprintf(https_proxy, MAXLEN, "%s:%d", hostname, port);
253
254         free(hostname);
255     } else {
256         INFO("https proxy is null\n");
257     }
258     
259     isEnable  = CFDictionaryGetValue(proxySettings, kSCPropNetProxiesFTPEnable);
260     if (cfnumber_to_int(isEnable)) {        
261         // Get proxy hostname
262         proxyHostname = CFDictionaryGetValue(proxySettings, kSCPropNetProxiesFTPProxy);
263         hostname = cfstring_to_cstring(proxyHostname);
264         // Get proxy port
265         proxyPort = CFDictionaryGetValue(proxySettings, kSCPropNetProxiesFTPPort);
266         port = cfnumber_to_int(proxyPort);
267         // Save hostname & port
268         snprintf(ftp_proxy, MAXLEN, "%s:%d", hostname, port);
269
270         free(hostname);
271     } else {
272         INFO("ftp proxy is null\n");
273     }
274     
275     isEnable  = CFDictionaryGetValue(proxySettings, kSCPropNetProxiesSOCKSEnable);
276     if (cfnumber_to_int(isEnable)) {        
277         // Get proxy hostname
278         proxyHostname = CFDictionaryGetValue(proxySettings, kSCPropNetProxiesSOCKSProxy);
279         hostname = cfstring_to_cstring(proxyHostname);
280         // Get proxy port
281         proxyPort = CFDictionaryGetValue(proxySettings, kSCPropNetProxiesSOCKSPort);
282         port = cfnumber_to_int(proxyPort);
283         // Save hostname & port
284         snprintf(socks_proxy, MAXLEN, "%s:%d", hostname, port);
285
286         free(hostname);
287     } else {
288         INFO("socks proxy is null\n");
289     }
290     CFRelease(proxySettings);
291 }
292 #endif
293
294 static void remove_string(char *src, char *dst, const char *toremove)
295 {
296     int len = strlen(toremove);
297     int i, j;
298     int max_len = strlen(src);
299
300     for(i = len, j = 0; i < max_len; i++)
301     {
302         dst[j++] = src[i];
303     }
304
305     dst[j] = '\0';
306 }
307
308 #if defined (CONFIG_LINUX)    
309 static void getlinuxproxy(char *http_proxy, char *https_proxy, char *ftp_proxy, char *socks_proxy)
310 {
311     char buf[MAXLEN] = {0,};
312     char buf_port[MAXPORTLEN] = {0,};
313     char buf_proxy[MAXLEN] = {0,};
314     char *buf_proxy_bak;
315     char *proxy;
316     FILE *output;
317     int MAXPROXYLEN = MAXLEN + MAXPORTLEN;
318
319     output = popen("gconftool-2 --get /system/http_proxy/host", "r");
320     if(fscanf(output, "%s", buf) > 0) {
321         snprintf(buf_proxy, MAXLEN, "%s", buf);
322     }
323     pclose(output);
324     
325     output = popen("gconftool-2 --get /system/http_proxy/port", "r");
326     if(fscanf(output, "%s", buf_port) <= 0) {
327         //for abnormal case: if can't find the key of http port, get from environment value.
328         buf_proxy_bak = getenv("http_proxy");
329         INFO("http_proxy from env: %s\n", buf_proxy_bak);
330         if(buf_proxy_bak != NULL) {
331             proxy = malloc(MAXLEN);
332             remove_string(buf_proxy_bak, proxy, HTTP_PREFIX);
333             strncpy(http_proxy, proxy, strlen(proxy)-1);
334             INFO("final http_proxy value: %s\n", http_proxy);
335             free(proxy);
336         }
337         else {
338             INFO("http_proxy is not set on env.\n");
339             pclose(output);
340             return;
341         }
342
343     }
344     else {
345         snprintf(http_proxy, MAXPROXYLEN, "%s:%s", buf_proxy, buf_port);
346         memset(buf_proxy, 0, MAXLEN);
347         INFO("http_proxy: %s\n", http_proxy);
348     }
349     pclose(output);
350
351     memset(buf, 0, MAXLEN);
352
353     output = popen("gconftool-2 --get /system/proxy/secure_host", "r");
354     if(fscanf(output, "%s", buf) > 0) {
355         snprintf(buf_proxy, MAXLEN, "%s", buf);
356     }
357     pclose(output);
358
359     output = popen("gconftool-2 --get /system/proxy/secure_port", "r");
360     if(fscanf(output, "%s", buf) > 0) {
361         snprintf(https_proxy, MAXPROXYLEN, "%s:%s", buf_proxy, buf);
362     }
363     pclose(output);
364     memset(buf, 0, MAXLEN);
365     memset(buf_proxy, 0, MAXLEN);
366     INFO("https_proxy : %s\n", https_proxy);
367
368     output = popen("gconftool-2 --get /system/proxy/ftp_host", "r");
369     if(fscanf(output, "%s", buf) > 0) {
370         snprintf(buf_proxy, MAXLEN, "%s", buf);
371     }
372     pclose(output);
373
374     output = popen("gconftool-2 --get /system/proxy/ftp_port", "r");
375     if(fscanf(output, "%s", buf) > 0) {
376         snprintf(ftp_proxy, MAXPROXYLEN, "%s:%s", buf_proxy, buf);
377     }
378     pclose(output);
379     memset(buf, 0, MAXLEN);
380     memset(buf_proxy, 0, MAXLEN);
381     INFO("ftp_proxy : %s\n", ftp_proxy);
382
383     output = popen("gconftool-2 --get /system/proxy/socks_host", "r");
384     if(fscanf(output, "%s", buf) > 0) {
385         snprintf(buf_proxy, MAXLEN, "%s", buf);
386     }
387     pclose(output);
388
389     output = popen("gconftool-2 --get /system/proxy/socks_port", "r");
390     if(fscanf(output, "%s", buf) > 0) {
391         snprintf(socks_proxy, MAXPROXYLEN, "%s:%s", buf_proxy, buf);
392     }
393     pclose(output);
394     INFO("socks_proxy : %s\n", socks_proxy);
395 }
396 #endif
397
398 static int getautoproxy(char *http_proxy, char *https_proxy, char *ftp_proxy, char *socks_proxy)
399 {
400     char type[MAXLEN];
401     char proxy[MAXLEN];
402     char line[MAXLEN];
403     FILE *fp_pacfile;
404     char *p = NULL;
405 #if defined(CONFIG_LINUX)
406     FILE *output;
407     char buf[MAXLEN];
408
409     output = popen("gconftool-2 --get /system/proxy/autoconfig_url", "r");
410     if(fscanf(output, "%s", buf) > 0) {
411         INFO("pac address: %s\n", buf);
412         download_url(buf);
413     }
414     pclose(output);
415 #elif defined(CONFIG_WIN32)    
416     INFO("pac address: %s\n", (char*)url);
417     download_url((char*)url);
418 #elif defined(CONFIG_DARWIN)
419     CFStringRef pacURL = (CFStringRef)CFDictionaryGetValue(proxySettings,
420                                 kSCPropNetProxiesProxyAutoConfigURLString);
421         if (pacURL) {
422                 char url[MAXLEN] = {};
423                 CFStringGetCString(pacURL, url, sizeof url, kCFStringEncodingASCII);
424                 INFO("pac address: %s\n", (char*)url);
425                 download_url(url);
426         }
427 #endif
428     fp_pacfile = fopen(pactempfile, "r");
429     if(fp_pacfile != NULL) {
430         while(fgets(line, MAXLEN, fp_pacfile) != NULL) {
431             if( (strstr(line, "return") != NULL) && (strstr(line, "if") == NULL)) {
432                 INFO("line found %s", line);
433                 sscanf(line, "%*[^\"]\"%s %s", type, proxy);
434             }
435         }
436
437         if(g_str_has_prefix(type, DIRECT)) {
438             INFO("auto proxy is set to direct mode\n");
439             fclose(fp_pacfile);
440         }
441         else if(g_str_has_prefix(type, PROXY)) {
442             INFO("auto proxy is set to proxy mode\n");
443             INFO("type: %s, proxy: %s\n", type, proxy);
444             p = strtok(proxy, "\";");
445             if(p != NULL) {
446                 INFO("auto proxy to set: %s\n",p);
447                 strcpy(http_proxy, p);
448                 strcpy(https_proxy, p);
449                 strcpy(ftp_proxy, p);
450                 strcpy(socks_proxy, p);
451             }
452             fclose(fp_pacfile);
453         }
454         else
455         {
456             ERR("pac file is not wrong! It could be the wrong pac address or pac file format\n");
457             fclose(fp_pacfile);
458         }
459     } 
460     else {
461         ERR("fail to get pacfile fp\n");
462         return -1;
463     }
464
465     remove(pactempfile);
466     return 0;
467 }
468
469
470 /**
471   @brief    get host proxy server address
472   @param    proxy: return value (proxy server address)
473   @return always 0
474  */
475 int gethostproxy(char *http_proxy, char *https_proxy, char *ftp_proxy, char *socks_proxy)
476 {
477 #if defined(CONFIG_LINUX) 
478     char buf[MAXLEN];
479     FILE *output;
480
481     output = popen("gconftool-2 --get /system/proxy/mode", "r");
482     if(fscanf(output, "%s", buf) > 0) {
483         //priority : auto > manual > none       
484         if (strcmp(buf, "auto") == 0) {
485             INFO("AUTO PROXY MODE\n");
486             getautoproxy(http_proxy, https_proxy, ftp_proxy, socks_proxy);
487         }
488         else if (strcmp(buf, "manual") == 0) {
489             INFO("MANUAL PROXY MODE\n");
490             getlinuxproxy(http_proxy, https_proxy, ftp_proxy, socks_proxy);
491         }
492         else if (strcmp(buf, "none") == 0) {
493             INFO("DIRECT PROXY MODE\n");
494         }
495     }
496     pclose(output);
497
498 #elif defined(CONFIG_WIN32)
499     HKEY hKey;
500     int nRet;
501     LONG lRet;
502     BYTE *proxyenable, *proxyserver;
503     char *p;
504     char *real_proxy;
505
506     DWORD dwLength = 0;
507     nRet = RegOpenKeyEx(HKEY_CURRENT_USER,
508             "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
509             0, KEY_QUERY_VALUE, &hKey);
510     if (nRet != ERROR_SUCCESS) {
511         ERR("Failed to open registry from %s\n",
512                 "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings");
513         return 0;
514     }
515     //check auto proxy key exists
516     lRet = RegQueryValueEx(hKey, "AutoConfigURL", 0, NULL, NULL, &dwLength);
517     if (lRet != ERROR_SUCCESS && dwLength == 0) {
518         ERR("Failed to query value from %s\n",
519                 "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\AutoConfigURL");
520     }
521     else {
522         //if exists
523         url = (char*)malloc(dwLength);
524         if (url == NULL) {
525             ERR( "Failed to allocate a buffer\n");
526         }
527         else {
528             memset(url, 0x00, dwLength);
529             lRet = RegQueryValueEx(hKey, "AutoConfigURL", 0, NULL, url, &dwLength);
530             if (lRet == ERROR_SUCCESS && dwLength != 0) {
531                 getautoproxy(http_proxy, https_proxy, ftp_proxy, socks_proxy);
532                 RegCloseKey(hKey);      
533                 return 0;
534             }
535         }
536     }
537     //check manual proxy key exists
538     lRet = RegQueryValueEx(hKey, "ProxyEnable", 0, NULL, NULL, &dwLength);
539     if (lRet != ERROR_SUCCESS && dwLength == 0) {
540         ERR(stderr, "Failed to query value from %s\n",
541                 "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ProxyEnable");
542         RegCloseKey(hKey);
543         return 0;
544     }
545     proxyenable = (BYTE*)malloc(dwLength);
546     if (proxyenable == NULL) {
547         ERR( "Failed to allocate a buffer\n");
548         RegCloseKey(hKey);
549         return 0;
550     }
551
552     lRet = RegQueryValueEx(hKey, "ProxyEnable", 0, NULL, proxyenable, &dwLength);
553     if (lRet != ERROR_SUCCESS) {
554         free(proxyenable);
555         ERR("Failed to query value from %s\n",
556                 "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ProxyEnable");
557         RegCloseKey(hKey);
558         return 0;
559     }
560     if (*(char*)proxyenable == 0) {
561         free(proxyenable);
562         RegCloseKey(hKey);      
563         return 0;
564     }
565
566     dwLength = 0;
567     lRet = RegQueryValueEx(hKey, "ProxyServer", 0, NULL, NULL, &dwLength);
568     if (lRet != ERROR_SUCCESS && dwLength == 0) {
569         ERR("Failed to query value from from %s\n",
570                 "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings");
571         RegCloseKey(hKey);      
572         return 0;
573     }
574
575     proxyserver = (BYTE*)malloc(dwLength);
576     if (proxyserver == NULL) {
577         ERR( "Failed to allocate a buffer\n");
578         RegCloseKey(hKey);      
579         return 0;
580     }
581
582     memset(proxyserver, 0x00, dwLength);
583     lRet = RegQueryValueEx(hKey, "ProxyServer", 0, NULL, proxyserver, &dwLength);
584     if (lRet != ERROR_SUCCESS) {
585         free(proxyserver);
586         ERR( "Failed to query value from from %s\n",
587                 "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings");
588         RegCloseKey(hKey);
589         return 0;
590     }
591     
592     if((char*)proxyserver != NULL) {
593         INFO("proxy value: %s\n", (char*)proxyserver);
594         real_proxy = malloc(MAXLEN);
595         
596         for(p = strtok((char*)proxyserver, ";"); p; p = strtok(NULL, ";")){
597             if(strstr(p, HTTP_PROTOCOL)) {
598                 remove_string(p, real_proxy, HTTP_PROTOCOL);
599                 strcpy(http_proxy, real_proxy);
600             }
601             else if(strstr(p, HTTPS_PROTOCOL)) {
602                 remove_string(p, real_proxy, HTTPS_PROTOCOL);
603                 strcpy(https_proxy, real_proxy);
604             }
605             else if(strstr(p, FTP_PROTOCOL)) {
606                 remove_string(p, real_proxy, FTP_PROTOCOL);
607                 strcpy(ftp_proxy, real_proxy);
608             }
609             else if(strstr(p, SOCKS_PROTOCOL)) {
610                 remove_string(p, real_proxy, SOCKS_PROTOCOL);
611                 strcpy(socks_proxy, real_proxy);
612             }
613             else {
614                 INFO("all protocol uses the same proxy server: %s\n", p);
615                 strcpy(http_proxy, p);
616                 strcpy(https_proxy, p);
617                 strcpy(ftp_proxy, p);
618                 strcpy(socks_proxy, p);
619             }
620         }
621         free(real_proxy);
622     }
623     else {
624         INFO("proxy is null\n");
625         return 0;
626     }
627     RegCloseKey(hKey);
628 #elif defined (CONFIG_DARWIN)
629     int ret;
630     proxySettings = SCDynamicStoreCopyProxies(NULL);
631     if(proxySettings) {
632         INFO("AUTO PROXY MODE\n");
633         ret = getautoproxy(http_proxy, https_proxy, ftp_proxy, socks_proxy); 
634         if(strlen(http_proxy) == 0 && ret < 0) {
635             INFO("MANUAL PROXY MODE\n");
636                 getmacproxy(http_proxy, https_proxy, ftp_proxy, socks_proxy); 
637             }
638     }
639 #endif
640     return 0;
641 }