4 * Copyright (C) 2012, 2013 Samsung Electronics Co., Ltd. All rights reserved.
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>
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.
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.
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.
34 @brief Collection of utilities for win32
38 #include "maru_common.h"
42 #include "maru_err_table.h"
51 MULTI_DEBUG_CHANNEL (emulator, osutil);
53 extern char tizen_target_img_path[];
54 extern int tizen_base_port;
56 static const char *pactempfile = ".autoproxy";
58 void check_vm_lock_os(void)
61 char *base_port = NULL;
65 for (port = 26100; port < 26200; port += 10) {
66 base_port = g_strdup_printf("%d", port);
67 hMapFile = OpenFileMapping(FILE_MAP_READ, TRUE, base_port);
68 if (hMapFile == NULL) {
69 INFO("port %s is not used.\n", base_port);
72 pBuf = (char *)MapViewOfFile(hMapFile, FILE_MAP_READ, 0, 0, 50);
74 ERR("Could not map view of file (%d).\n", GetLastError());
75 CloseHandle(hMapFile);
78 if (strcmp(pBuf, tizen_target_img_path) == 0) {
79 maru_register_exit_msg(MARU_EXIT_UNKNOWN,
80 "Can not execute this VM.\n"
81 "The same name is running now.");
82 UnmapViewOfFile(pBuf);
83 CloseHandle(hMapFile);
87 UnmapViewOfFile(pBuf);
91 CloseHandle(hMapFile);
96 void make_vm_lock_os(void)
103 shared_memory = g_strdup_printf("%s", tizen_target_img_path);
104 port_in_use = g_strdup_printf("%d", tizen_base_port);
105 hMapFile = CreateFileMapping(
106 INVALID_HANDLE_VALUE, /* use paging file */
107 NULL, /* default security */
108 PAGE_READWRITE, /* read/write access */
109 0, /* maximum object size (high-order DWORD) */
110 50, /* maximum object size (low-order DWORD) */
111 port_in_use); /* name of mapping object */
112 if (hMapFile == NULL) {
113 ERR("Could not create file mapping object (%d).\n", GetLastError());
116 pBuf = MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, 50);
119 ERR("Could not map view of file (%d).\n", GetLastError());
120 CloseHandle(hMapFile);
124 CopyMemory((PVOID)pBuf, shared_memory, strlen(shared_memory));
129 void set_bin_path_os(gchar * exec_argv)
131 gchar link_path[PATH_MAX] = { 0, };
132 gchar *file_name = NULL;
134 if (!GetModuleFileName(NULL, link_path, PATH_MAX)) {
138 file_name = g_strrstr(link_path, "\\");
139 g_strlcpy(bin_path, link_path, strlen(link_path) - strlen(file_name) + 1);
141 g_strlcat(bin_path, "\\", PATH_MAX);
144 void print_system_info_os(void)
148 INFO("* LibPNG Version : %s\n", PNG_LIBPNG_VER_STRING);
150 /* Retrieves information about the current os */
152 ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
153 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
155 if (GetVersionEx(&osvi)) {
156 INFO("* MajorVersion : %d, MinorVersion : %d, BuildNumber : %d, "
157 "PlatformId : %d, CSDVersion : %s\n", osvi.dwMajorVersion,
158 osvi.dwMinorVersion, osvi.dwBuildNumber,
159 osvi.dwPlatformId, osvi.szCSDVersion);
162 /* Retrieves information about the current system */
164 ZeroMemory(&sysi, sizeof(SYSTEM_INFO));
166 GetSystemInfo(&sysi);
167 INFO("* Processor type : %d, Number of processors : %d\n",
168 sysi.dwProcessorType, sysi.dwNumberOfProcessors);
170 MEMORYSTATUSEX memInfo;
171 memInfo.dwLength = sizeof(MEMORYSTATUSEX);
172 GlobalMemoryStatusEx(&memInfo);
173 INFO("* Total Ram : %llu kB, Free: %lld kB\n",
174 memInfo.ullTotalPhys / 1024, memInfo.ullAvailPhys / 1024);
177 static int get_auto_proxy(BYTE *url, char *http_proxy, char *https_proxy, char *ftp_proxy, char *socks_proxy)
185 INFO("pac address: %s\n", (char*)url);
186 download_url((char*)url);
188 fp_pacfile = fopen(pactempfile, "r");
189 if(fp_pacfile != NULL) {
190 while(fgets(line, MAXLEN, fp_pacfile) != NULL) {
191 if( (strstr(line, "return") != NULL) && (strstr(line, "if") == NULL)) {
192 INFO("line found %s", line);
193 sscanf(line, "%*[^\"]\"%s %s", type, proxy);
197 if(g_str_has_prefix(type, DIRECT)) {
198 INFO("auto proxy is set to direct mode\n");
201 else if(g_str_has_prefix(type, PROXY)) {
202 INFO("auto proxy is set to proxy mode\n");
203 INFO("type: %s, proxy: %s\n", type, proxy);
204 p = strtok(proxy, "\";");
206 INFO("auto proxy to set: %s\n",p);
207 strcpy(http_proxy, p);
208 strcpy(https_proxy, p);
209 strcpy(ftp_proxy, p);
210 strcpy(socks_proxy, p);
216 ERR("pac file is not wrong! It could be the wrong pac address or pac file format\n");
221 ERR("fail to get pacfile fp\n");
230 void get_host_proxy_os(char *http_proxy, char *https_proxy, char *ftp_proxy, char *socks_proxy)
235 BYTE *proxyenable, *proxyserver;
241 nRet = RegOpenKeyEx(HKEY_CURRENT_USER,
242 "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
243 0, KEY_QUERY_VALUE, &hKey);
244 if (nRet != ERROR_SUCCESS) {
245 ERR("Failed to open registry from %s\n",
246 "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings");
249 //check auto proxy key exists
250 lRet = RegQueryValueEx(hKey, "AutoConfigURL", 0, NULL, NULL, &dwLength);
251 if (lRet != ERROR_SUCCESS && dwLength == 0) {
252 ERR("Failed to query value from %s\n",
253 "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\AutoConfigURL");
257 url = (char*)malloc(dwLength);
259 ERR( "Failed to allocate a buffer\n");
262 memset(url, 0x00, dwLength);
263 lRet = RegQueryValueEx(hKey, "AutoConfigURL", 0, NULL, url, &dwLength);
264 if (lRet == ERROR_SUCCESS && dwLength != 0) {
265 get_auto_proxy(url, http_proxy, https_proxy, ftp_proxy, socks_proxy);
271 //check manual proxy key exists
272 lRet = RegQueryValueEx(hKey, "ProxyEnable", 0, NULL, NULL, &dwLength);
273 if (lRet != ERROR_SUCCESS && dwLength == 0) {
274 ERR(stderr, "Failed to query value from %s\n",
275 "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ProxyEnable");
279 proxyenable = (BYTE*)malloc(dwLength);
280 if (proxyenable == NULL) {
281 ERR( "Failed to allocate a buffer\n");
286 lRet = RegQueryValueEx(hKey, "ProxyEnable", 0, NULL, proxyenable, &dwLength);
287 if (lRet != ERROR_SUCCESS) {
289 ERR("Failed to query value from %s\n",
290 "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ProxyEnable");
294 if (*(char*)proxyenable == 0) {
301 lRet = RegQueryValueEx(hKey, "ProxyServer", 0, NULL, NULL, &dwLength);
302 if (lRet != ERROR_SUCCESS && dwLength == 0) {
303 ERR("Failed to query value from from %s\n",
304 "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings");
309 proxyserver = (BYTE*)malloc(dwLength);
310 if (proxyserver == NULL) {
311 ERR( "Failed to allocate a buffer\n");
316 memset(proxyserver, 0x00, dwLength);
317 lRet = RegQueryValueEx(hKey, "ProxyServer", 0, NULL, proxyserver, &dwLength);
318 if (lRet != ERROR_SUCCESS) {
320 ERR( "Failed to query value from from %s\n",
321 "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings");
326 if((char*)proxyserver != NULL) {
327 INFO("proxy value: %s\n", (char*)proxyserver);
328 real_proxy = malloc(MAXLEN);
330 for(p = strtok((char*)proxyserver, ";"); p; p = strtok(NULL, ";")){
331 if(strstr(p, HTTP_PROTOCOL)) {
332 remove_string(p, real_proxy, HTTP_PROTOCOL);
333 strcpy(http_proxy, real_proxy);
335 else if(strstr(p, HTTPS_PROTOCOL)) {
336 remove_string(p, real_proxy, HTTPS_PROTOCOL);
337 strcpy(https_proxy, real_proxy);
339 else if(strstr(p, FTP_PROTOCOL)) {
340 remove_string(p, real_proxy, FTP_PROTOCOL);
341 strcpy(ftp_proxy, real_proxy);
343 else if(strstr(p, SOCKS_PROTOCOL)) {
344 remove_string(p, real_proxy, SOCKS_PROTOCOL);
345 strcpy(socks_proxy, real_proxy);
348 INFO("all protocol uses the same proxy server: %s\n", p);
349 strcpy(http_proxy, p);
350 strcpy(https_proxy, p);
351 strcpy(ftp_proxy, p);
352 strcpy(socks_proxy, p);
358 INFO("proxy is null\n");