From 72d1d46ab2833703aa189bb88f375dedc3c1f553 Mon Sep 17 00:00:00 2001 From: "munkyu.im" Date: Thu, 15 Mar 2012 01:18:40 +0900 Subject: [PATCH] [Title]add getting DNS and proxy [Type] [Module] [Priority] [CQ#] [Redmine#] [Problem] [Cause] [Solution] [TestCase] --- tizen/src/Makefile.tizen | 2 +- tizen/src/emulator.c | 21 ++-- tizen/src/option.c | 242 +++++++++++++++++++++++++++++++++++++++++++++++ tizen/src/option.h | 49 ++++++++++ 4 files changed, 307 insertions(+), 7 deletions(-) create mode 100644 tizen/src/option.c create mode 100644 tizen/src/option.h diff --git a/tizen/src/Makefile.tizen b/tizen/src/Makefile.tizen index 12396d1..d205156 100644 --- a/tizen/src/Makefile.tizen +++ b/tizen/src/Makefile.tizen @@ -16,7 +16,7 @@ LIBS += -lavformat -lavcodec -lavutil -lm -lGL endif # maru loader -obj-y += emulator.o process.o maru_signal.o maru_sdl.o +obj-y += emulator.o process.o option.o maru_signal.o maru_sdl.o # sdb obj-y += sdb.o diff --git a/tizen/src/emulator.c b/tizen/src/emulator.c index f4208f6..4c599bd 100644 --- a/tizen/src/emulator.c +++ b/tizen/src/emulator.c @@ -41,14 +41,15 @@ #include "guest_server.h" #include "debug_ch.h" #include "process.h" +#include "option.h" #ifdef _WIN32 #include #endif MULTI_DEBUG_CHANNEL(qemu, main); -#define IMAGE_PATH_PREFIX "file=" -#define IMAGE_PATH_SUFFIX ",if=virtio" +#define IMAGE_PATH_PREFIX "file=" +#define IMAGE_PATH_SUFFIX ",if=virtio" #define SDB_PORT_PREFIX "sdb_port=" #define MAXLEN 512 #define MIDBUF 128 @@ -87,13 +88,14 @@ static void construct_main_window(int skin_argc, char* skin_argv[]) } -static void parse_options(int argc, char* argv[], int* skin_argc, char*** skin_argv, int* qemu_argc, char*** qemu_argv) +static void parse_options(int argc, char* argv[], char* proxy, char* dns1, char* dns2, int* skin_argc, char*** skin_argv, int* qemu_argc, char*** qemu_argv) { int i; int j; - + char *point = NULL; // FIXME !!! // TODO: + for(i = 1; i < argc; ++i) { if(strncmp(argv[i], "--skin-args", 11) == 0) @@ -112,7 +114,10 @@ static void parse_options(int argc, char* argv[], int* skin_argc, char*** skin_a *qemu_argv = &(argv[j]); argv[j] = argv[0]; - + } + if((point = strstr(argv[j], "console")) != NULL) + { + argv[j] = g_strdup_printf("%s proxy=%s dns1=%s dns2=%s", argv[9], proxy, dns1, dns2); break; } } @@ -177,8 +182,12 @@ int main(int argc, char* argv[]) int qemu_argc = 0; char** qemu_argv = NULL; + char proxy[MIDBUF] ={0}, dns1[MIDBUF] = {0}, dns2[MIDBUF] = {0}; + + gethostproxy(proxy); + gethostDNS(dns1, dns2); - parse_options(argc, argv, &skin_argc, &skin_argv, &qemu_argc, &qemu_argv); + parse_options(argc, argv, proxy, dns1, dns2, &skin_argc, &skin_argv, &qemu_argc, &qemu_argv); int i; diff --git a/tizen/src/option.c b/tizen/src/option.c new file mode 100644 index 0000000..44f6591 --- /dev/null +++ b/tizen/src/option.c @@ -0,0 +1,242 @@ +/* + * Emulator + * + * Copyright (C) 2011, 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SeokYeon Hwang + * HyunJun Son + * MunKyu Im + * GiWoong Kim + * YeongKyoon Lee + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +/** + @file option.c + @brief collection of dialog function + */ + +#include "option.h" + +#ifndef _WIN32 +#include +#include +#include +#include +#include +#include +#include +#else +#ifdef WINVER < 0x0501 +#undef WINVER +#define WINVER 0x0501 +#include +#include +#include +#include +#endif +#endif + +#include "debug_ch.h" + +//DEFAULT_DEBUG_CHANNEL(tizen); +MULTI_DEBUG_CHANNEL(tizen, option); + +/** + @brief get host DNS server address + @param dns1: return value (first dns server address) + @param dns2: return value (second dns server address) + @return always 0 + */ +int gethostDNS(char *dns1, char *dns2) +{ +#ifndef _WIN32 + FILE *resolv; + char buf[255]; + memset(buf, 0, sizeof(char)*255); + + resolv = fopen("/etc/resolv.conf", "r"); + if (resolv <= 0) { + ERR( "Cann't open \"/etc/resolv.conf.\"\n"); + return 1; + } + + while(fscanf(resolv , "%s", buf) != EOF) { + if(strcmp(buf, "nameserver") == 0) + { + fscanf(resolv , "%s", dns1); + break; + } + } + + while(fscanf(resolv , "%s", buf) != EOF) { + if(strcmp(buf, "nameserver") == 0) + { + fscanf(resolv , "%s", dns2); + break; + } + } + + fclose(resolv); +#else + PIP_ADAPTER_ADDRESSES pAdapterAddr; + PIP_ADAPTER_ADDRESSES pAddr; + PIP_ADAPTER_DNS_SERVER_ADDRESS pDnsAddr; + unsigned long dwResult; + unsigned long nBufferLength = sizeof(IP_ADAPTER_ADDRESSES); + pAdapterAddr = (PIP_ADAPTER_ADDRESSES)malloc(nBufferLength); + memset(pAdapterAddr, 0x00, nBufferLength); + + while ((dwResult = GetAdaptersAddresses(AF_INET, 0, NULL, pAdapterAddr, &nBufferLength)) + == ERROR_BUFFER_OVERFLOW) { + free(pAdapterAddr); + pAdapterAddr = (PIP_ADAPTER_ADDRESSES)malloc(nBufferLength); + memset(pAdapterAddr, 0x00, nBufferLength); + } + + pAddr = pAdapterAddr; + for (; pAddr != NULL; pAddr = pAddr->Next) { + pDnsAddr = pAddr->FirstDnsServerAddress; + for (; pDnsAddr != NULL; pDnsAddr = pDnsAddr->Next) { + struct sockaddr_in *pSockAddr = (struct sockaddr_in*)pDnsAddr->Address.lpSockaddr; + if(*dns1 == 0) { + strcpy(dns1, inet_ntoa(pSockAddr->sin_addr)); + continue; + } + if(*dns2 == 0) { + strcpy(dns2, inet_ntoa(pSockAddr->sin_addr)); + continue; + } + } + } + free(pAdapterAddr); +#endif + return 0; +} + +/** + @brief get host proxy server address + @param proxy: return value (proxy server address) + @return always 0 + */ +int gethostproxy(char *proxy) +{ +#ifndef _WIN32 + char buf[255]; + FILE *output; + + output = popen("gconftool-2 --get /system/proxy/mode", "r"); + fscanf(output, "%s", buf); + pclose(output); + + if (strcmp(buf, "manual") == 0){ + output = popen("gconftool-2 --get /system/http_proxy/host", "r"); + fscanf(output , "%s", buf); + sprintf(proxy, "%s", buf); + pclose(output); + + output = popen("gconftool-2 --get /system/http_proxy/port", "r"); + fscanf(output , "%s", buf); + sprintf(proxy, "%s:%s", proxy, buf); + pclose(output); + + }else if (strcmp(buf, "auto") == 0){ + INFO( "Emulator can't support automatic proxy currently. starts up with normal proxy.\n"); + //can't support proxy auto setting +// output = popen("gconftool-2 --get /system/proxy/autoconfig_url", "r"); +// fscanf(output , "%s", buf); +// sprintf(proxy, "%s", buf); +// pclose(output); + } + +#else + HKEY hKey; + int nRet; + LONG lRet; + BYTE *proxyenable, *proxyserver; + DWORD dwLength = 0; + nRet = RegOpenKeyEx(HKEY_CURRENT_USER, + "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", + 0, KEY_QUERY_VALUE, &hKey); + if (nRet != ERROR_SUCCESS) { + fprintf(stderr, "Failed to open registry from %s\n", + "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"); + return 0; + } + lRet = RegQueryValueEx(hKey, "ProxyEnable", 0, NULL, NULL, &dwLength); + if (lRet != ERROR_SUCCESS && dwLength == 0) { + fprintf(stderr, "Failed to query value from from %s\n", + "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"); + RegCloseKey(hKey); + return 0; + } + proxyenable = (BYTE*)malloc(dwLength); + if (proxyenable == NULL) { + fprintf(stderr, "Failed to allocate a buffer\n"); + RegCloseKey(hKey); + return 0; + } + + lRet = RegQueryValueEx(hKey, "ProxyEnable", 0, NULL, proxyenable, &dwLength); + if (lRet != ERROR_SUCCESS) { + free(proxyenable); + fprintf(stderr, "Failed to query value from from %s\n", + "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"); + RegCloseKey(hKey); + return 0; + } + if (*(char*)proxyenable == 0) { + free(proxyenable); + RegCloseKey(hKey); + return 0; + } + + dwLength = 0; + lRet = RegQueryValueEx(hKey, "ProxyServer", 0, NULL, NULL, &dwLength); + if (lRet != ERROR_SUCCESS && dwLength == 0) { + fprintf(stderr, "Failed to query value from from %s\n", + "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"); + RegCloseKey(hKey); + return 0; + } + + proxyserver = (BYTE*)malloc(dwLength); + if (proxyserver == NULL) { + fprintf(stderr, "Failed to allocate a buffer\n"); + RegCloseKey(hKey); + return 0; + } + + memset(proxyserver, 0x00, dwLength); + lRet = RegQueryValueEx(hKey, "ProxyServer", 0, NULL, proxyserver, &dwLength); + if (lRet != ERROR_SUCCESS) { + free(proxyserver); + fprintf(stderr, "Failed to query value from from %s\n", + "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"); + RegCloseKey(hKey); + return 0; + } + if (proxyserver != NULL) strcpy(proxy, (char*)proxyserver); + free(proxyserver); + RegCloseKey(hKey); +#endif + return 0; +} diff --git a/tizen/src/option.h b/tizen/src/option.h new file mode 100644 index 0000000..f7b1ddf --- /dev/null +++ b/tizen/src/option.h @@ -0,0 +1,49 @@ +/* + * Emulator + * + * Copyright (C) 2011, 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SeokYeon Hwang + * HyunJun Son + * MunKyu Im + * GiWoong Kim + * YeongKyoon Lee + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#ifndef __OPTION_H__ +#define __OPTION_H__ + +#include +#ifndef _WIN32 +#include +#endif +#include +#include +#include +#include +#include +#include + +int gethostDNS(char *dns1, char *dns2); +int gethostproxy(char *proxy); +#endif + -- 2.7.4