--- /dev/null
-HANDLE g_hFile;
+ /*
+ * Emulator
+ *
+ * Copyright (C) 2012, 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * MunKyu Im <munkyu.im@samsung.com>
+ * GiWoong Kim <giwoong.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ * HyunJun Son
+ *
+ * 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 osutil-win32.c
+ @brief Collection of utilities for win32
+ */
+
+ #include <png.h>
+ #include "emulator_common.h"
+ #include "osutil.h"
+ #include "emulator.h"
+ #include "emul_state.h"
+ #include "debug_ch.h"
+ #include "maru_err_table.h"
+ #include "sdb.h"
+
+ #ifndef CONFIG_WIN32
+ #error
+ #endif
+
+ #include <windows.h>
+
+ MULTI_DEBUG_CHANNEL (emulator, osutil);
+
+ static HANDLE g_hMapFile;
+ static char *g_pBuf;
+
+
+ static qemu_timeval tv = { 0, 0 };
+ static time_t ti;
+ static char buf_time[64];
+ extern char tizen_target_img_path[];
- g_hFile = hFile;
+ static char g_sdcard[256] = {0,};
+
+ static const char *pactempfile = ".autoproxy";
+
+ void check_vm_lock_os(void)
+ {
+ uint32_t port;
+ char *base_port = NULL;
+ char *pBuf;
+ HANDLE hMapFile;
+
+ for (port = 26100; port < 26200; port += 10) {
+ base_port = g_strdup_printf("%d", port);
+ hMapFile = OpenFileMapping(FILE_MAP_READ, TRUE, base_port);
+ if (hMapFile == NULL) {
+ INFO("port %s is not used.\n", base_port);
+ continue;
+ } else {
+ pBuf = (char *)MapViewOfFile(hMapFile, FILE_MAP_READ, 0, 0, 50);
+ if (pBuf == NULL) {
+ ERR("Could not map view of file (%d).\n", GetLastError());
+ CloseHandle(hMapFile);
+ }
+
+ if (strcmp(pBuf, tizen_target_img_path) == 0) {
+ maru_register_exit_msg(MARU_EXIT_UNKNOWN,
+ "Can not execute this VM.\n"
+ "The same name is running now.");
+ UnmapViewOfFile(pBuf);
+ CloseHandle(hMapFile);
+ free(base_port);
+ exit(0);
+ } else {
+ UnmapViewOfFile(pBuf);
+ }
+ }
+
+ CloseHandle(hMapFile);
+ free(base_port);
+ }
+ }
+
+ void make_vm_lock_os(void)
+ {
+ char *port_in_use;
+ char *shared_memory;
+ int base_port;
+
+ base_port = get_emul_vm_base_port();
+ shared_memory = g_strdup_printf("%s", tizen_target_img_path);
+ port_in_use = g_strdup_printf("%d", base_port);
+ g_hMapFile = CreateFileMapping(
+ INVALID_HANDLE_VALUE, /* use paging file */
+ NULL, /* default security */
+ PAGE_READWRITE, /* read/write access */
+ 0, /* maximum object size (high-order DWORD) */
+ 50, /* maximum object size (low-order DWORD) */
+ port_in_use); /* name of mapping object */
+ if (g_hMapFile == NULL) {
+ ERR("Could not create file mapping object (%d).\n", GetLastError());
+ return;
+ }
+
+ g_pBuf = MapViewOfFile(g_hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, 50);
+ if (g_pBuf == NULL) {
+ ERR("Could not map view of file (%d).\n", GetLastError());
+ CloseHandle(g_hMapFile);
+ return;
+ }
+
+ CopyMemory((PVOID)g_pBuf, shared_memory, strlen(shared_memory));
+ free(port_in_use);
+ free(shared_memory);
+ }
+
+ void remove_vm_lock_os(void)
+ {
+ if (g_pBuf != NULL) {
+ UnmapViewOfFile(g_pBuf);
+ }
+ if (g_hMapFile != NULL) {
+ CloseHandle(g_hMapFile);
+ }
+ }
+
+
+ void set_bin_path_os(char const *const exec_argv)
+ {
+ gchar link_path[PATH_MAX] = { 0, };
+ gchar *file_name = NULL;
+
+ if (!GetModuleFileName(NULL, link_path, PATH_MAX)) {
+ return;
+ }
+
+ file_name = g_strrstr(link_path, "\\");
+ g_strlcpy(bin_path, link_path, strlen(link_path) - strlen(file_name) + 1);
+
+ g_strlcat(bin_path, "\\", PATH_MAX);
+ }
+
+ int get_number_of_processors(void)
+ {
+ SYSTEM_INFO sysi;
+ int num_processors = 0;
+
+ GetSystemInfo(&sysi);
+ TRACE("Processor type: %d, Core number: %d\n",
+ sysi.dwProcessorType, sysi.dwNumberOfProcessors);
+
+ num_processors = sysi.dwNumberOfProcessors;
+ if (num_processors < 1) {
+ num_processors = 1;
+ }
+
+ return num_processors;
+ }
+
+ void print_system_info_os(void)
+ {
+ INFO("* Windows\n");
+
+ INFO("* LibPNG Version : %s\n", PNG_LIBPNG_VER_STRING);
+
+ /* Retrieves information about the current os */
+ OSVERSIONINFO osvi;
+ ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
+ osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+
+ if (GetVersionEx(&osvi)) {
+ INFO("* MajorVersion : %d, MinorVersion : %d, BuildNumber : %d, "
+ "PlatformId : %d, CSDVersion : %s\n", osvi.dwMajorVersion,
+ osvi.dwMinorVersion, osvi.dwBuildNumber,
+ osvi.dwPlatformId, osvi.szCSDVersion);
+ }
+
+ /* Retrieves information about the current system */
+ SYSTEM_INFO sysi;
+ ZeroMemory(&sysi, sizeof(SYSTEM_INFO));
+
+ #if 0
+ GetSystemInfo(&sysi);
+ INFO("* Processor type : %d, Number of processors : %d\n",
+ sysi.dwProcessorType, sysi.dwNumberOfProcessors);
+ #endif
+ get_number_of_processors();
+
+ MEMORYSTATUSEX memInfo;
+ memInfo.dwLength = sizeof(MEMORYSTATUSEX);
+ GlobalMemoryStatusEx(&memInfo);
+ INFO("* Total Ram : %llu kB, Free: %lld kB\n",
+ memInfo.ullTotalPhys / 1024, memInfo.ullAvailPhys / 1024);
+ }
+
+ static int get_auto_proxy(BYTE *url, char *http_proxy, char *https_proxy, char *ftp_proxy, char *socks_proxy)
+ {
+ char type[DEFAULTBUFLEN];
+ char proxy[DEFAULTBUFLEN];
+ char line[DEFAULTBUFLEN];
+ FILE *fp_pacfile;
+ char *p = NULL;
+
+ INFO("pac address: %s\n", (char *)url);
+ download_url((char *)url);
+
+ fp_pacfile = fopen(pactempfile, "r");
+ if (fp_pacfile != NULL) {
+ while(fgets(line, DEFAULTBUFLEN, 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(pactempfile);
+
+ return 0;
+ }
+
+ void get_host_proxy_os(char *http_proxy, char *https_proxy, char *ftp_proxy, char *socks_proxy)
+ {
+ HKEY hKey;
+ int nRet;
+ LONG lRet;
+ BYTE *proxyenable, *proxyserver;
+ char *p;
+ char *real_proxy;
+ BYTE *url = NULL;
+
+ DWORD dwLength = 0;
+ nRet = RegOpenKeyEx(HKEY_CURRENT_USER,
+ "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
+ 0, KEY_QUERY_VALUE, &hKey);
+ if (nRet != ERROR_SUCCESS) {
+ ERR("Failed to open registry from %s\n",
+ "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings");
+ return;
+ }
+ //check auto proxy key exists
+ lRet = RegQueryValueEx(hKey, "AutoConfigURL", 0, NULL, NULL, &dwLength);
+ if (lRet != ERROR_SUCCESS && dwLength == 0) {
+ ERR("Failed to query value from %s\n",
+ "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\AutoConfigURL");
+ } else {
+ //if exists
+ url = (BYTE *)malloc(dwLength);
+ if (url == NULL) {
+ ERR("Failed to allocate a buffer\n");
+ } else {
+ memset(url, 0x00, dwLength);
+ lRet = RegQueryValueEx(hKey, "AutoConfigURL", 0, NULL, url, &dwLength);
+ if (lRet == ERROR_SUCCESS && dwLength != 0) {
+ get_auto_proxy(url, http_proxy, https_proxy, ftp_proxy, socks_proxy);
+ free(url);
+ RegCloseKey(hKey);
+ return;
+ }
+ }
+ free(url);
+ }
+ //check manual proxy key exists
+ lRet = RegQueryValueEx(hKey, "ProxyEnable", 0, NULL, NULL, &dwLength);
+ if (lRet != ERROR_SUCCESS && dwLength == 0) {
+ ERR("Failed to query value from %s\n",
+ "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ProxyEnable");
+ RegCloseKey(hKey);
+ return;
+ }
+ proxyenable = (BYTE*)malloc(dwLength);
+ if (proxyenable == NULL) {
+ ERR("Failed to allocate a buffer\n");
+ RegCloseKey(hKey);
+ return;
+ }
+
+ lRet = RegQueryValueEx(hKey, "ProxyEnable", 0, NULL, proxyenable, &dwLength);
+ if (lRet != ERROR_SUCCESS) {
+ free(proxyenable);
+ ERR("Failed to query value from %s\n",
+ "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ProxyEnable");
+ RegCloseKey(hKey);
+ return;
+ }
+ if (*(char *)proxyenable == 0) {
+ free(proxyenable);
+ RegCloseKey(hKey);
+ return;
+ }
+
+ dwLength = 0;
+ lRet = RegQueryValueEx(hKey, "ProxyServer", 0, NULL, NULL, &dwLength);
+ if (lRet != ERROR_SUCCESS && dwLength == 0) {
+ ERR("Failed to query value from from %s\n",
+ "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings");
+ RegCloseKey(hKey);
+ return;
+ }
+
+ proxyserver = (BYTE*)malloc(dwLength);
+ if (proxyserver == NULL) {
+ ERR("Failed to allocate a buffer\n");
+ RegCloseKey(hKey);
+ return;
+ }
+
+ memset(proxyserver, 0x00, dwLength);
+ lRet = RegQueryValueEx(hKey, "ProxyServer", 0, NULL, proxyserver, &dwLength);
+ if (lRet != ERROR_SUCCESS) {
+ free(proxyserver);
+ ERR("Failed to query value from from %s\n",
+ "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings");
+ RegCloseKey(hKey);
+ return;
+ }
+
+ INFO("proxy value: %s\n", (char *)proxyserver);
+ real_proxy = malloc(DEFAULTBUFLEN);
+ if (real_proxy == NULL) {
+ ERR("Failed to allocate a buffer\n");
+ free(proxyserver);
+ RegCloseKey(hKey);
+ return;
+ }
+
+ for (p = strtok((char *)proxyserver, ";"); p; p = strtok(NULL, ";")) {
+ if (strstr(p, HTTP_PROTOCOL)) {
+ remove_string(p, real_proxy, HTTP_PROTOCOL);
+ strcpy(http_proxy, real_proxy);
+ } else if (strstr(p, HTTPS_PROTOCOL)) {
+ remove_string(p, real_proxy, HTTPS_PROTOCOL);
+ strcpy(https_proxy, real_proxy);
+ } else if (strstr(p, FTP_PROTOCOL)) {
+ remove_string(p, real_proxy, FTP_PROTOCOL);
+ strcpy(ftp_proxy, real_proxy);
+ } else if (strstr(p, SOCKS_PROTOCOL)) {
+ remove_string(p, real_proxy, SOCKS_PROTOCOL);
+ strcpy(socks_proxy, real_proxy);
+ } else {
+ INFO("all protocol uses the same proxy server: %s\n", p);
+ strcpy(http_proxy, p);
+ strcpy(https_proxy, p);
+ strcpy(ftp_proxy, p);
+ strcpy(socks_proxy, p);
+ }
+ }
+ else {
+ INFO("proxy is null\n");
+ return;
+ }
+ free(real_proxy);
+ free(proxyserver);
+ RegCloseKey(hKey);
+ }
+
+ bool make_sdcard_lock_os(char *sdcard)
+ {
+ char *lock_file = g_strdup_printf("%s.lck", sdcard);
+
+ HANDLE hFile = CreateFile(lock_file, GENERIC_READ,
+ 0,
+ NULL,
+ CREATE_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+
+ if (hFile == INVALID_HANDLE_VALUE) {
+ ERR("file open error : (%d)\n", GetLastError());
+ if(GetLastError() == 32) {
+ if(strcmp(g_sdcard, sdcard) == 0) {
+ INFO("try to mount same sdcard!\n");
+ }
+ return false;
+ }
+ return true;
+ }
- CloseHandle(hFile);
+ INFO("Get file lock: %s\n", lock_file);
+ strncpy(g_sdcard, sdcard, strlen(sdcard));
- CloseHandle(g_hFile);
+ return true;
+
+ }
+
+ int remove_sdcard_lock_os(char *sdcard)
+ {
+ char *lock_file = g_strdup_printf("%s.lck", sdcard);
+ HANDLE hFile2;
+ BOOL fSuccess;
+ hFile2 = CreateFile(lock_file, GENERIC_READ,
+ 0,
+ NULL,
+ OPEN_EXISTING,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+
+ if (hFile2 == INVALID_HANDLE_VALUE) {
+ ERR("CreateFile() error : (%d)\n", GetLastError());
+ if (GetLastError() == 32) {
+ if (strncmp(g_sdcard, sdcard, strlen(sdcard)) != 0) {
+ INFO("not same sdcard!!!\n");
+ return ERR_UNLCK;
+ }
+
+ INFO("return ERR_SUCCESS\n");
- CloseHandle(g_hFile);
+ g_sdcard[0] = '\0';
+ fSuccess = DeleteFile(lock_file);
+ if (!fSuccess) {
+ // Handle the error.
+ ERR("DeleteFile failed (%d)\n", GetLastError());
+ return ERR_UNLCK;
+ }
+ return ERR_SUCCESS;
+ }
+ return ERR_NOENT;
+ }
+
+ hFile2 = CreateFile(lock_file, GENERIC_READ,
+ 0,
+ NULL,
+ CREATE_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+
+ if (hFile2 == INVALID_HANDLE_VALUE) {
+ ERR("CreateFile() error : (%d)\n", GetLastError());
+ return ERR_UNLCK;
+ }
+ CloseHandle(hFile2);
++ fSuccess = DeleteFile(lock_file);
++ if (!fSuccess) {
++ // Handle the error.
++ ERR("DeleteFile failed (%d)\n", GetLastError());
++ return ERR_UNLCK;
++ }
+ INFO("unlock success: %s\n", lock_file);
+ return ERR_SUCCESS;
+
+ }
--- /dev/null
-#ifndef CONFIG_WIN32
-static int g_fd;
-#endif
-inline size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream)
+ /*
+ * Emulator
+ *
+ * Copyright (C) 2012, 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * MunKyu Im <munkyu.im@samsung.com>
+ * GiWoong Kim <giwoong.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ * HyunJun Son
+ *
+ * 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 osutil.c
+ @brief Common functions for osutil
+ */
+
+ #include "osutil.h"
+ #include "debug_ch.h"
+
+ #include <curl/curl.h>
+ #include <string.h>
+
+ MULTI_DEBUG_CHANNEL(emulator, osutil);
+
+
+ const char *pac_tempfile = ".autoproxy";
-inline void remove_string(char *src, char *dst, const char *toremove)
++size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream)
+ {
+ size_t written;
+ written = fwrite(ptr, size, nmemb, stream);
+ return written;
+ }
+
+ void download_url(char *url)
+ {
+ CURL *curl;
+ FILE *fp;
+ CURLcode res;
+
+ curl = curl_easy_init();
+ if (curl) {
+ fp = fopen(pac_tempfile, "wb");
+ if(fp == NULL) {
+ ERR("failed to fopen(): %s\n", pac_tempfile);
+ return;
+ }
+ curl_easy_setopt(curl, CURLOPT_URL, url);
+ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
+ /* just in case network does not work */
+ curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, 3000);
+ curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
+
+ res = curl_easy_perform(curl);
+ if (res != 0) {
+ ERR("Fail to download pac file: %s\n", url);
+ }
+
+ curl_easy_cleanup(curl);
+ fclose(fp);
+ }
+
+ return;
+ }
+
- g_fd = fd;
- close(fd);
++void remove_string(char *src, char *dst, const char *toremove)
+ {
+ int len = strlen(toremove);
+ int i, j;
+ int max_len = strlen(src);
+
+ for(i = len, j = 0; i < max_len; i++)
+ {
+ dst[j++] = src[i];
+ }
+
+ dst[j] = '\0';
+ }
+
+ #ifndef CONFIG_WIN32
+ static int fd_lock(int fd)
+ {
+ struct flock lock;
+
+ lock.l_type = F_WRLCK;
+ lock.l_start = 0;
+ lock.l_whence = SEEK_SET;
+ lock.l_len = 0;
+ lock.l_pid = getpid();
+
+ return fcntl(fd, F_SETLK, &lock);
+ }
+
+ static int fd_unlock(int fd)
+ {
+ struct flock lock;
+
+ lock.l_type = F_UNLCK;
+ lock.l_start = 0;
+ lock.l_whence = SEEK_SET;
+ lock.l_len = 0;
+
+ return fcntl(fd, F_SETLK, &lock);
+ }
+
+ inline bool make_sdcard_lock_posix(char *sdcard)
+ {
+ char *lock_file = g_strdup_printf("%s.lck", sdcard);
+ int fd = open(lock_file, O_CREAT|O_RDWR, 0666);
+ if (fd == -1)
+ {
+ perror("file open error : ");
+ return false;
+ }
+ if (fd_lock(fd) == -1)
+ {
+ perror("file is lock ");
+ close(fd);
+ return false;
+ }
+
+ INFO("Get file lock: %s\n", lock_file);
- close(g_fd);
+ return true;
+
+ }
+
+ inline int remove_sdcard_lock_posix(char *sdcard)
+ {
+ errno = 0;
+ char *lock_file = g_strdup_printf("%s.lck", sdcard);
+ int fd = open(lock_file, O_RDWR, 0666);
+ if (fd == -1)
+ {
+ perror("file open error : ");
+ if(errno == ENOENT) {
+ return ERR_NOENT;
+ }
+ return ERR_UNLCK;
+ }
+
+ if (fd_unlock(fd) == -1)
+ {
+ perror("file unlock error ");
+ close(fd);
+ return ERR_UNLCK;
+ }
+
+ if (unlink(lock_file) < 0) {
+ perror("unlink error ");
+ close(fd);
+ return ERR_UNLCK;
+ }
+
+ INFO("unlock success: %s\n", lock_file);
+ close(fd);
+ return ERR_SUCCESS;
+ }
+ #endif
--- /dev/null
-
+ /*
+ * Emulator
+ *
+ * Copyright (C) 2011, 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * MunKyu Im <munkyu.im@samsung.com>
+ * GiWoong Kim <giwoong.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ * HyunJun Son
+ *
+ * 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 __OSUTIL_H__
+ #define __OSUTIL_H__
+
+ #include "qemu-common.h"
+
+ #define HTTP_PROTOCOL "http="
+ #define HTTP_PREFIX "http://"
+ #define HTTPS_PROTOCOL "https="
+ #define FTP_PROTOCOL "ftp="
+ #define SOCKS_PROTOCOL "socks="
+ #define DIRECT "DIRECT"
+ #define PROXY "PROXY"
+ #define MAXPORTLEN 6
+ #define DEFAULTBUFLEN 512
+
+ #define GNOME_PROXY_MODE 0
+ #define GNOME_PROXY_AUTOCONFIG_URL 1
+ #define GNOME_PROXY_HTTP_HOST 2
+ #define GNOME_PROXY_HTTP_PORT 3
+ #define GNOME_PROXY_HTTPS_HOST 4
+ #define GNOME_PROXY_HTTPS_PORT 5
+ #define GNOME_PROXY_FTP_HOST 6
+ #define GNOME_PROXY_FTP_PORT 7
+ #define GNOME_PROXY_SOCKS_HOST 8
+ #define GNOME_PROXY_SOCKS_PORT 9
+ #define GCONFTOOL 0
+ #define GSETTINGS 1
+
+ #define ERR_SUCCESS 0
+ #define ERR_UNLCK 4
+ #define ERR_LCK 5
+ #define ERR_NOENT 6
+
+ extern const char *pac_tempfile;
+
+ void check_vm_lock_os(void);
+ void make_vm_lock_os(void);
+ void remove_vm_lock_os(void);
+ bool make_sdcard_lock_os(char *sdcard);
+ int remove_sdcard_lock_os(char *sdcard);
+
+ void set_bin_path_os(char const *const);
+ #ifndef CONFIG_WIN32
+ bool make_sdcard_lock_posix(char *sdcard);
+ int remove_sdcard_lock_posix(char *sdcard);
+ #endif
+
+ void print_system_info_os(void);
+
+ void get_host_proxy_os(char *, char *, char *, char *);
+
+ void download_url(char *);
+ size_t write_data(void *, size_t, size_t, FILE *);
+ void remove_string(char *, char *, const char *);
+
+ #if defined(CONFIG_SPICE) && defined(CONFIG_LINUX)
+ void get_process_id(char const *process_name, char *first_param, int *pid, int *pscount);
+ void execute_websocket(int port);
+ void execute_nodejs(void);
+ void clean_websocket_port(int signal);
+ void nodejs_init(void);
+ void websocket_init(void);
+ #endif
+
+ static inline int get_timeofday(char *buf, size_t size)
+ {
+ qemu_timeval tv;
+ time_t ti;
+ struct tm *ptm = NULL;
+ int ret;
+
+ qemu_gettimeofday(&tv);
+ ti = tv.tv_sec;
+
+ /* In this case, localtime_r() function is not necessary. */
+ ptm = localtime(&ti);
+ ret = strftime(buf, size, "%H:%M:%S", ptm);
+
+ return ret + g_snprintf(buf + ret, size - ret, ".%06ld", (long)tv.tv_usec);
+ }
+
+ int get_number_of_processors(void);
+ #endif // __OS_UTIL_H__
+