make check-proxy shows host proxy information.
set guest IP from emuld.
Change-Id: I3b0746eea02de6e4ec46a24deb0e09e1876242a7
Signed-off-by: Munkyu Im <munkyu.im@samsung.com>
check-cam.exe
check-gl
check-gl.exe
-
+check-proxy
+check-proxy.exe
include ../../config-host.mak
TARGET_EXE += util/check-cam$(EXESUF)
+TARGET_EXE += util/check-proxy$(EXESUF)
ifdef CONFIG_YAGL
TARGET_EXE += util/check-gl$(EXESUF)
endif
qemu_distclean:
cd ../../ && $(MAKE) distclean
+# Building check-proxy
+CHECK_PROXY_OBJS = util/check_proxy.o
+CHECK_PROXY_CFLAGS = -c $(GLIB_CFLAGS) $(CURL_CFLAGS)
+CHECK_PROXY_LDFLAGS =
+CHECK_PROXY_TARGET = util/check-proxy$(EXESUF)
+ifdef CONFIG_LINUX
+CHECK_PROXY_OBJS += util/check_proxy_linux.o
+CHECK_PROXY_LDFLAGS += ${CURL_LIBS} `pkg-config --libs glib-2.0`
+endif
+ifdef CONFIG_WIN32
+CHECK_PROXY_OBJS += util/check_proxy_win32.o
+CHECK_PROXY_LDFLAGS += ${CURL_LIBS} `pkg-config --libs glib-2.0`
+endif
+ifdef CONFIG_DARWIN
+CHECK_PROXY_OBJS += util/check_proxy_darwin.o
+CHECK_PROXY_LDFLAGS += -mmacosx-version-min=10.4 ${CURL_LIBS} -framework CoreFoundation -framework SystemConfiguration `pkg-config --libs glib-2.0`
+endif
+
+util/check-proxy$(EXESUF): $(CHECK_PROXY_OBJS)
+ $(CC) $(CHECK_PROXY_OBJS) $(CHECK_PROXY_LDFLAGS) -o $@
+$(CHECK_PROXY_OBJS): %.o: %.c
+ $(CC) $< $(CHECK_PROXY_CFLAGS) -o $@
+
# Building check-gl
CHECK_GL_OBJS = util/check_gl.o util/check_gl_core.o
CHECK_GL_CFLAGS = -c -I$(SRC_PATH)/hw/yagl/yagl_inc
clean: qemu_clean
- rm -f util/check-hax$(EXESUF) util/check-cam$(EXESUF) util/check-gl$(EXESUF)
+ rm -f util/check-hax$(EXESUF) util/check-cam$(EXESUF) util/check-gl$(EXESUF) util/check-proxy$(EXESUF)
distclean: clean qemu_distclean
install: all
endif
endif
-# check capabilities of OpenGL and Webcam
+# check capabilities of OpenGL, Webcam and proxy
cp -pP util/check-gl$(EXESUF) $(EMUL_DIR)/bin
cp -pP util/check-cam$(EXESUF) $(EMUL_DIR)/bin
+ cp -pP util/check-proxy$(EXESUF) $(EMUL_DIR)/bin
# Enable HW Virtualization on Linux
ifdef CONFIG_LINUX
endif
endif
-# check capabilities of OpenGL and Webcam
+# check capabilities of OpenGL, Webcam and proxy
+ cp -pP util/check-proxy$(EXESUF) $(DIBS_COMMON_DIR)/bin
cp -pP util/check-gl$(EXESUF) $(DIBS_COMMON_DIR)/bin
cp -pP util/check-cam$(EXESUF) $(DIBS_COMMON_DIR)/bin
#define MSG_TYPE_SIMUL_NFC "simul_nfc"
#define MSG_TYPE_SDCARD "sdcard"
#define MSG_TYPE_GUEST "guest"
+#define MSG_TYPE_GUESTIP "guest_ip"
#define MSG_GROUP_STATUS 15
#define MSG_GROUP_HDS 100
INFO("datalen: %d\n", dataLen);
char* sdcard_img_path = get_sdcard_img_path(dataBuf + 2, dataLen);
err_no = remove_sdcard_lock_os(sdcard_img_path);
- if (err_no == 0 && is_sdcard_attached()) {
+ if (errno == 0 && is_sdcard_attached()) {
do_hotplug(DETACH_SDCARD, NULL, 0);
} else {
ERR("failed to umount: %s\n", sdcard_img_path);
INFO("emuld connection is %d\n", action);
qemu_mutex_lock(&mutex_guest_connection);
guest_connection = action;
+ set_emuld_condition(guest_connection);
if (action == 1) {
+ LOG_INFO("emulator booting done.\n");
set_emulator_condition(BOOT_COMPLETED);
} else {
+ LOG_INFO("emulator closed.\n");
set_emulator_condition(RESET);
}
qemu_mutex_unlock(&mutex_guest_connection);
const char* ijdata = (data + catsize + 2 + 1 + 1);
TRACE("<< header cat = %s, length = %d, action=%d, group=%d\n", cat, length,action, group);
-
+ if (!strcmp(cat, MSG_TYPE_GUESTIP)) {
+ if (length > 0) {
+ INFO("guest ip: %s\n", (char*)ijdata);
+ set_emul_guest_ip((char*)ijdata);
+ return true;
+ } else {
+ ERR("guest ip is null!\n");
+ return false;
+ }
+ }
ECS__Master master = ECS__MASTER__INIT;
ECS__InjectorNtf ntf = ECS__INJECTOR_NTF__INIT;
return _emul_info.input_touch_enable;
}
+bool is_emul_tap_enable(void)
+{
+ return _emul_info.tap_enable;
+}
+
+void set_emul_tap_enable(bool enable)
+{
+ _emul_info.tap_enable = enable;
+}
+
+void set_emul_guest_ip(char *ip)
+{
+ strncpy(_emul_info.guest_ip, ip, strlen(ip));
+}
+
+char* get_emul_guest_ip(void)
+{
+ LOG_INFO("guest ip: %s\n", _emul_info.guest_ip);
+ return _emul_info.guest_ip;
+}
+
/* maximum number of touch point */
void set_emul_max_touch_point(int cnt)
{
void set_emul_vm_base_port(int port)
{
_emul_info.vm_base_port = port;
- _emul_info.device_serial_number = port + 1;
+ if (is_emul_tap_enable()) {
+ _emul_info.device_serial_number = 26101;
+ } else {
+ _emul_info.device_serial_number = port + 1;
+ }
_emul_info.ecs_port = port + 3;
_emul_info.serial_port = port + 4;
_emul_info.spice_port = port + 5;
return &(_emul_state.qemu_mts);
}
+void set_emuld_condition(int condition)
+{
+ _emul_state.emuld_condition = condition;
+}
+
+int get_emuld_condition(void)
+{
+ return _emul_state.emuld_condition;
+}
/* retrieves the status of the host lock key */
int get_host_lock_key_state(int key)
{
HOST_NUMLOCK_KEY = 2,
};
+enum {
+ EMULD_NOT_RUNNING = 0,
+ EMULD_RUNNING = 1,
+};
typedef struct EmulatorConfigInfo {
bool skin_enable;
int vm_base_port;
int device_serial_number;
int ecs_port;
+ bool tap_enable;
+ char guest_ip[16];
+
int spice_port;
int websocket_port;
char *vm_name;
typedef struct EmulatorConfigState {
int emulator_condition; //TODO : enum
+ int emuld_condition;
double scale_factor;
short rotation_type;
MultiTouchState qemu_mts;
void set_emul_max_touch_point(int cnt);
void set_emul_vm_base_port(int port);
void set_emul_ecs_port(int port);
+void set_emul_guest_ip(char *ip);
+void set_emul_vm_name(char *vm_name);
void set_emulator_condition(int state);
void set_emul_rotation(short rotation_type);
void set_emul_caps_lock_state(int state);
void set_emul_num_lock_state(int state);
-void set_emul_vm_name(char *vm_name);
+void set_emul_tap_enable(bool enable);
void set_emul_hds_attached(bool attached);
void set_emul_hds_path(const char *path);
void set_emul_hds_guest_path(const char *path);
int get_device_serial_number(void);
int get_emul_ecs_port(void);
int get_emul_serial_port(void);
+char* get_emul_vm_name(void);
int get_emul_spice_port(void);
int get_emul_websocket_port(void);
int get_host_lock_key_state_darwin(int key);
int get_emul_caps_lock_state(void);
int get_emul_num_lock_state(void);
-char* get_emul_vm_name(void);
+int get_emuld_condition(void);
+void set_emuld_condition(int condition);
+char* get_emul_guest_ip(void);
+bool is_emul_tap_enable(void);
+
bool get_emul_hds_attached(void);
char* get_emul_hds_path(void);
char* get_emul_hds_guest_path(void);
#define PROXY_BUFFER_LEN 128
static void prepare_basic_features(gchar * const kernel_cmdline)
{
- char http_proxy[PROXY_BUFFER_LEN] ={ 0, },
- https_proxy[PROXY_BUFFER_LEN] = { 0, },
- ftp_proxy[PROXY_BUFFER_LEN] = { 0, },
- socks_proxy[PROXY_BUFFER_LEN] = { 0, };
+ gchar * tmp_str;
set_base_port();
start_ecs();
- sdb_setup(get_device_serial_number() + SDB_UDP_SENSOR_INDEX);
+ start_sdb_noti_server(get_emul_vm_base_port() + SDB_UDP_SENSOR_INDEX);
- get_host_proxy_os(http_proxy, https_proxy, ftp_proxy, socks_proxy);
+ sdb_setup();
- gchar * const tmp_str = g_strdup_printf(" sdb_port=%d,"
- " http_proxy=%s https_proxy=%s ftp_proxy=%s socks_proxy=%s"
- " vm_resolution=%dx%d", get_emul_vm_base_port(),
- http_proxy, https_proxy, ftp_proxy, socks_proxy,
- get_emul_resolution_width(), get_emul_resolution_height());
+ tmp_str = g_strdup_printf(" sdb_port=%d,"
+ " vm_resolution=%dx%d", get_emul_vm_base_port(),
+ get_emul_resolution_width(), get_emul_resolution_height());
g_strlcat(kernel_cmdline, tmp_str, LEN_MARU_KERNEL_CMDLINE);
--- /dev/null
+/*
+ * Check proxy
+ *
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact:
+ * MunKyu Im <munkyu.im@samsung.com>
+ * Sangho Park <sangho1206.park@samsung.com>
+ *
+ * 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
+ *
+ */
+
+#include "check_proxy.h"
+
+#include <curl/curl.h>
+#include <string.h>
+
+const char *pac_tempfile = ".autoproxy";
+
+inline 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) {
+ fprintf(stderr, "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) {
+ fprintf(stderr, "Fail to download pac file: %s\n", url);
+ }
+
+ curl_easy_cleanup(curl);
+ fclose(fp);
+ }
+
+ return;
+}
+
+inline 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';
+}
+
+void main(int argc, char *argv[])
+{
+ get_host_proxy_os();
+}
--- /dev/null
+/*
+ * Check proxy
+ *
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact:
+ * MunKyu Im <munkyu.im@samsung.com>
+ * Sangho Park <sangho1206.park@samsung.com>
+ *
+ * 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 __CHECK_PROXY_H__
+#define __CHECK_PROXY_H__
+
+#include <string.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <glib.h>
+#include <glib/gstdio.h>
+#include <glib/gprintf.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
+
+extern const char *pac_tempfile;
+
+void get_host_proxy_os(void);
+
+void download_url(char *);
+size_t write_data(void *, size_t, size_t, FILE *);
+void remove_string(char *, char *, const char *);
+
+#endif
+
--- /dev/null
+/*
+ * Check proxy
+ *
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact:
+ * MunKyu Im <munkyu.im@samsung.com>
+ * Sangho Park <sangho1206.park@samsung.com>
+ *
+ * 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
+ *
+ */
+
+#include "check_proxy.h"
+#include <SystemConfiguration/SystemConfiguration.h>
+
+static 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;
+}
+
+
+static int get_auto_proxy(void)
+{
+ char type[DEFAULTBUFLEN];
+ char proxy[DEFAULTBUFLEN];
+ char line[DEFAULTBUFLEN];
+ FILE *fp_pacfile;
+ char *p = NULL;
+
+ CFStringRef pacURL = (CFStringRef)CFDictionaryGetValue(proxySettings,
+ kSCPropNetProxiesProxyAutoConfigURLString);
+ if (pacURL) {
+ char url[DEFAULTBUFLEN] = {};
+ CFStringGetCString(pacURL, url, sizeof url, kCFStringEncodingASCII);
+ fprintf(stderr, "pac address: %s\n", (char*)url);
+ download_url(url);
+ }
+
+ fp_pacfile = fopen(pac_tempfile, "r");
+ if (fp_pacfile != NULL) {
+ while (fgets(line, DEFAULTBUFLEN, fp_pacfile) != NULL) {
+ if ((strstr(line, "return") != NULL) && (strstr(line, "if") == NULL)) {
+ fprintf(stderr, "line found %s", line);
+ sscanf(line, "%*[^\"]\"%s %s", type, proxy);
+ }
+ }
+
+ if (g_str_has_prefix(type, DIRECT)) {
+ fprintf(stdout, "MODE:Auto\n");
+ fprintf(stdout, "http_proxy= http_proxy= ftp_proxy= socks_proxy=");
+ fclose(fp_pacfile);
+ } else if (g_str_has_prefix(type, PROXY)) {
+ p = strtok(proxy, "\";");
+ if (p != NULL) {
+ fprintf(stdout, "MODE:Auto\n");
+ fprintf(stdout, "http_proxy=%s http_proxy=%s ftp_proxy=%s socks_proxy=%s", p, p, p, p);
+ }
+ fclose(fp_pacfile);
+ } else {
+ fprintf(stderr, "pac file is not wrong! It could be the wrong pac address or pac file format\n");
+ fclose(fp_pacfile);
+ }
+ } else {
+ fprintf(stderr, "fail to get pacfile fp\n");
+ fprintf(stdout, "MODE:None\n");
+ return -1;
+ }
+
+ remove(pac_tempfile);
+ return 0;
+}
+
+static void get_proxy(void)
+{
+ char *hostname;
+ int port;
+ CFNumberRef isEnable;
+ CFStringRef proxyHostname;
+ CFNumberRef proxyPort;
+ CFDictionaryRef proxySettings;
+ proxySettings = SCDynamicStoreCopyProxies(NULL);
+ char http_proxy[DEFAULTBUFLEN] = {0,};
+ char https_proxy[DEFAULTBUFLEN] = {0,};
+ char ftp_proxy[DEFAULTBUFLEN] = {0,};
+ char socks_proxy[DEFAULTBUFLEN] = {0,};
+
+ 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, DEFAULTBUFLEN, "%s:%d", hostname, port);
+
+ free(hostname);
+ }
+
+ 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, DEFAULTBUFLEN, "%s:%d", hostname, port);
+
+ free(hostname);
+ }
+
+ 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, DEFAULTBUFLEN, "%s:%d", hostname, port);
+
+ free(hostname);
+ }
+
+ 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, DEFAULTBUFLEN, "%s:%d", hostname, port);
+
+ free(hostname);
+ }
+
+ fprintf(stdout, "http_proxy= %s https_proxy=%s ftp_proxy=%s socks_proxy=%s", http_proxy, https_proxy, ftp_proxy, socks_proxy);
+ CFRelease(proxySettings);
+}
+
+void get_host_proxy_os(void)
+{
+ proxySettings = SCDynamicStoreCopyProxies(NULL);
+ if (proxySettings) {
+ if (get_auto_proxy() < 0) {
+ fprintf(stdout, "MODE:Manual\n");
+ get_proxy();
+ }
+ }
+}
+
--- /dev/null
+/*
+ * Check proxy
+ *
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact:
+ * MunKyu Im <munkyu.im@samsung.com>
+ * Sangho Park <sangho1206.park@samsung.com>
+ *
+ * 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
+ *
+ */
+
+#include "check_proxy.h"
+
+static int gproxytool = GSETTINGS;
+static const char* gproxycmds[][2] = {
+ { "gconftool-2 -g /system/proxy/mode" , "gsettings get org.gnome.system.proxy mode" },
+ { "gconftool-2 -g /system/proxy/autoconfig_url", "gsettings get org.gnome.system.proxy autoconfig-url" },
+ { "gconftool-2 -g /system/http_proxy/host", "gsettings get org.gnome.system.proxy.http host" },
+ { "gconftool-2 -g /system/http_proxy/port", "gsettings get org.gnome.system.proxy.http port"},
+ { "gconftool-2 -g /system/proxy/secure_host", "gsettings get org.gnome.system.proxy.https host" },
+ { "gconftool-2 -g /system/proxy/secure_port", "gsettings get org.gnome.system.proxy.https port" },
+ { "gconftool-2 -g /system/proxy/ftp_host", "gsettings get org.gnome.system.proxy.ftp host" },
+ { "gconftool-2 -g /system/proxy/ftp_port", "gsettings get org.gnome.system.proxy.ftp port" },
+ { "gconftool-2 -g /system/proxy/socks_host", "gsettings get org.gnome.system.proxy.socks host" },
+ { "gconftool-2 -g /system/proxy/socks_port", "gsettings get org.gnome.system.proxy.socks port" },
+};
+
+static void process_string(char *buf)
+{
+ char tmp_buf[DEFAULTBUFLEN];
+
+ /* remove single quotes of strings gotten by gsettings */
+ if (gproxytool == GSETTINGS) {
+ remove_string(buf, tmp_buf, "\'");
+ memset(buf, 0, DEFAULTBUFLEN);
+ strncpy(buf, tmp_buf, strlen(tmp_buf)-1);
+ }
+}
+
+static int get_auto_proxy(void)
+{
+ char type[DEFAULTBUFLEN];
+ char proxy[DEFAULTBUFLEN];
+ char line[DEFAULTBUFLEN];
+ FILE *fp_pacfile;
+ char *p = NULL;
+ FILE *output;
+ char buf[DEFAULTBUFLEN];
+
+ output = popen(gproxycmds[GNOME_PROXY_AUTOCONFIG_URL][gproxytool], "r");
+ if (fscanf(output, "%s", buf) > 0) {
+ process_string(buf);
+ fprintf(stdout, "pac address: %s\n", buf);
+ download_url(buf);
+ }
+
+ pclose(output);
+ fp_pacfile = fopen(pac_tempfile, "r");
+ if (fp_pacfile != NULL) {
+ while (fgets(line, DEFAULTBUFLEN, fp_pacfile) != NULL) {
+ if ((strstr(line, "return") != NULL) && (strstr(line, "if") == NULL)) {
+ fprintf(stderr, "line found %s", line);
+ sscanf(line, "%*[^\"]\"%s %s", type, proxy);
+ }
+ }
+
+ if (g_str_has_prefix(type, DIRECT)) {
+ fprintf(stdout, "http_proxy= http_proxy= ftp_proxy= socks_proxy=");
+ fclose(fp_pacfile);
+ } else if (g_str_has_prefix(type, PROXY)) {
+ fprintf(stderr, "auto proxy is set to proxy mode\n");
+ fprintf(stderr, "type: %s, proxy: %s\n", type, proxy);
+
+ p = strtok(proxy, "\";");
+ if (p != NULL) {
+ fprintf(stdout, "http_proxy=%s https_proxy=%s ftp_proxy=%s socks_proxy=%s", p, p, p, p);
+ }
+ fclose(fp_pacfile);
+ } else {
+ fprintf(stderr, "pac file is not wrong! It could be the wrong pac address or pac file format\n");
+ fclose(fp_pacfile);
+ }
+ } else {
+ fprintf(stderr, "fail to get pacfile fp\n");
+ return -1;
+ }
+
+ if (remove(pac_tempfile) < 0) {
+ fprintf(stderr, "fail to remove the temporary pacfile\n");
+ }
+
+ return 0;
+}
+
+static void get_proxy(void)
+{
+ char buf[DEFAULTBUFLEN] = {0,};
+ char buf_port[MAXPORTLEN] = {0,};
+ char buf_proxy[DEFAULTBUFLEN] = {0,};
+ char *buf_proxy_bak;
+ char http_proxy[DEFAULTBUFLEN] = {0,};
+ char https_proxy[DEFAULTBUFLEN] = {0,};
+ char ftp_proxy[DEFAULTBUFLEN] = {0,};
+ char socks_proxy[DEFAULTBUFLEN] = {0,};
+ char *proxy;
+ FILE *output;
+ int MAXPROXYLEN = DEFAULTBUFLEN + MAXPORTLEN;
+
+ output = popen(gproxycmds[GNOME_PROXY_HTTP_HOST][gproxytool], "r");
+ if (fscanf(output, "%s", buf) > 0) {
+ process_string(buf);
+ snprintf(buf_proxy, DEFAULTBUFLEN, "%s", buf);
+ }
+ pclose(output);
+
+ output = popen(gproxycmds[GNOME_PROXY_HTTP_PORT][gproxytool], "r");
+ if (fscanf(output, "%s", buf_port) <= 0) {
+ //for abnormal case: if can't find the key of http port, get from environment value.
+ buf_proxy_bak = getenv("http_proxy");
+ fprintf(stderr, "http_proxy from env: %s\n", buf_proxy_bak);
+ if (buf_proxy_bak != NULL) {
+ proxy = malloc(DEFAULTBUFLEN);
+ remove_string(buf_proxy_bak, proxy, HTTP_PREFIX);
+ strncpy(http_proxy, proxy, strlen(proxy)-1);
+ free(proxy);
+ }
+ else {
+ fprintf(stderr, "http_proxy is not set on env.\n");
+ pclose(output);
+ return;
+ }
+
+ }
+ else {
+ snprintf(http_proxy, MAXPROXYLEN, "%s:%s", buf_proxy, buf_port);
+ memset(buf_proxy, 0, DEFAULTBUFLEN);
+ }
+ pclose(output);
+
+ memset(buf, 0, DEFAULTBUFLEN);
+
+ output = popen(gproxycmds[GNOME_PROXY_HTTPS_HOST][gproxytool], "r");
+ if (fscanf(output, "%s", buf) > 0) {
+ process_string(buf);
+ snprintf(buf_proxy, DEFAULTBUFLEN, "%s", buf);
+ }
+ pclose(output);
+
+ output = popen(gproxycmds[GNOME_PROXY_HTTPS_PORT][gproxytool], "r");
+ if(fscanf(output, "%s", buf) > 0) {
+ snprintf(https_proxy, MAXPROXYLEN, "%s:%s", buf_proxy, buf);
+ }
+ pclose(output);
+ memset(buf, 0, DEFAULTBUFLEN);
+ memset(buf_proxy, 0, DEFAULTBUFLEN);
+
+ output = popen(gproxycmds[GNOME_PROXY_FTP_HOST][gproxytool], "r");
+ if (fscanf(output, "%s", buf) > 0) {
+ process_string(buf);
+ snprintf(buf_proxy, DEFAULTBUFLEN, "%s", buf);
+ }
+ pclose(output);
+
+ output = popen(gproxycmds[GNOME_PROXY_FTP_PORT][gproxytool], "r");
+ if (fscanf(output, "%s", buf) > 0) {
+ snprintf(ftp_proxy, MAXPROXYLEN, "%s:%s", buf_proxy, buf);
+ }
+ pclose(output);
+ memset(buf, 0, DEFAULTBUFLEN);
+ memset(buf_proxy, 0, DEFAULTBUFLEN);
+
+ output = popen(gproxycmds[GNOME_PROXY_SOCKS_HOST][gproxytool], "r");
+ if (fscanf(output, "%s", buf) > 0) {
+ process_string(buf);
+ snprintf(buf_proxy, DEFAULTBUFLEN, "%s", buf);
+ }
+ pclose(output);
+
+ output = popen(gproxycmds[GNOME_PROXY_SOCKS_PORT][gproxytool], "r");
+ if (fscanf(output, "%s", buf) > 0) {
+ snprintf(socks_proxy, MAXPROXYLEN, "%s:%s", buf_proxy, buf);
+ }
+
+ fprintf(stdout, "http_proxy=%s https_proxy=%s ftp_proxy=%s socks_proxy=%s", http_proxy, https_proxy, ftp_proxy, socks_proxy);
+ pclose(output);
+}
+
+
+void get_host_proxy_os(void)
+{
+ char buf[DEFAULTBUFLEN];
+ FILE *output;
+ int ret;
+
+ output = popen(gproxycmds[GNOME_PROXY_MODE][gproxytool], "r");
+ ret = fscanf(output, "%s", buf);
+ if (ret <= 0) {
+ pclose(output);
+ fprintf(stderr, "Try to use gsettings to get proxy\n");
+ gproxytool = GSETTINGS;
+ output = popen(gproxycmds[GNOME_PROXY_MODE][gproxytool], "r");
+ ret = fscanf(output, "%s", buf);
+ }
+ if (ret > 0) {
+ process_string(buf);
+ //priority : auto > manual > none
+ if (strcmp(buf, "auto") == 0) {
+ fprintf(stdout, "MODE:Auto\n");
+ get_auto_proxy();
+ } else if (strcmp(buf, "manual") == 0) {
+ fprintf(stdout, "MODE:Manual\n");
+ get_proxy();
+ } else if (strcmp(buf, "none") == 0) {
+ fprintf(stdout, "MODE:None\n");
+ }
+ }
+ pclose(output);
+}
--- /dev/null
+/*
+ * Check proxy
+ *
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact:
+ * MunKyu Im <munkyu.im@samsung.com>
+ * Sangho Park <sangho1206.park@samsung.com>
+ *
+ * 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
+ *
+ */
+
+#include "check_proxy.h"
+#include <windows.h>
+
+static const char *pactempfile = ".autoproxy";
+
+static int get_auto_proxy(BYTE *url)
+{
+ char type[DEFAULTBUFLEN];
+ char proxy[DEFAULTBUFLEN];
+ char line[DEFAULTBUFLEN];
+ FILE *fp_pacfile;
+ char *p = NULL;
+
+ fprintf(stdout, "MODE:Auto\n");
+ fprintf(stdout, "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)) {
+ fprintf(stderr, "line found %s", line);
+ sscanf(line, "%*[^\"]\"%s %s", type, proxy);
+ }
+ }
+
+ if (g_str_has_prefix(type, DIRECT)) {
+ fprintf(stdout, "http_proxy= https_proxy= ftp_proxy= socks_proxy=");
+ fclose(fp_pacfile);
+ } else if (g_str_has_prefix(type, PROXY)) {
+ fprintf(stderr, "auto proxy is set to proxy mode\n");
+ fprintf(stderr, "type: %s, proxy: %s\n", type, proxy);
+ p = strtok(proxy, "\";");
+ if (p != NULL) {
+ fprintf(stdout, "http_proxy=%s https_proxy=%s ftp_proxy=%s socks_proxy=%s", p, p, p, p);
+ }
+ fclose(fp_pacfile);
+ } else {
+ fprintf(stderr, "pac file is not wrong! It could be the wrong pac address or pac file format\n");
+ fclose(fp_pacfile);
+ }
+ } else {
+ fprintf(stderr, "fail to get pacfile fp\n");
+ return -1;
+ }
+
+ remove(pactempfile);
+
+ return 0;
+}
+
+void get_host_proxy_os(void)
+{
+ HKEY hKey;
+ int nRet;
+ LONG lRet;
+ BYTE *proxyenable, *proxyserver;
+ char *p;
+ BYTE *url = NULL;
+ char http_proxy[DEFAULTBUFLEN] = {0,};
+ char https_proxy[DEFAULTBUFLEN] = {0,};
+ char ftp_proxy[DEFAULTBUFLEN] = {0,};
+ char socks_proxy[DEFAULTBUFLEN] = {0,};
+
+ 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;
+ }
+ //check auto proxy key exists
+ lRet = RegQueryValueEx(hKey, "AutoConfigURL", 0, NULL, NULL, &dwLength);
+ if (lRet != ERROR_SUCCESS && dwLength == 0) {
+ fprintf(stderr, "Failed to query value from %s\n",
+ "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\AutoConfigURL");
+ } else {
+ //if exists
+ url = (BYTE *)malloc(dwLength);
+ if (url == NULL) {
+ fprintf(stderr, "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);
+ 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) {
+ fprintf(stderr, "Failed to query value from %s\n",
+ "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ProxyEnable");
+ RegCloseKey(hKey);
+ return;
+ }
+ proxyenable = (BYTE*)malloc(dwLength);
+ if (proxyenable == NULL) {
+ fprintf(stderr, "Failed to allocate a buffer\n");
+ RegCloseKey(hKey);
+ return;
+ }
+
+ lRet = RegQueryValueEx(hKey, "ProxyEnable", 0, NULL, proxyenable, &dwLength);
+ if (lRet != ERROR_SUCCESS) {
+ free(proxyenable);
+ fprintf(stderr, "Failed to query value from %s\n",
+ "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ProxyEnable");
+ RegCloseKey(hKey);
+ return;
+ }
+ if (*(char *)proxyenable == 0) {
+ fprintf(stdout, "MODE:None\n");
+ free(proxyenable);
+ RegCloseKey(hKey);
+ return;
+ }
+
+ 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;
+ }
+
+ proxyserver = (BYTE*)malloc(dwLength);
+ if (proxyserver == NULL) {
+ fprintf(stderr, "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);
+ fprintf(stderr, "Failed to query value from from %s\n",
+ "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings");
+ RegCloseKey(hKey);
+ return;
+ }
+
+ //fprintf(stdout, "proxy value: %s\n", (char *)proxyserver);
+
+ fprintf(stdout, "MODE:Manual\n");
+ for (p = strtok((char *)proxyserver, ";"); p; p = strtok(NULL, ";")) {
+ if (strstr(p, HTTP_PROTOCOL)) {
+ remove_string(p, http_proxy, HTTP_PROTOCOL);
+ } else if (strstr(p, HTTPS_PROTOCOL)) {
+ remove_string(p, https_proxy, HTTPS_PROTOCOL);
+ } else if (strstr(p, FTP_PROTOCOL)) {
+ remove_string(p, ftp_proxy, FTP_PROTOCOL);
+ } else if (strstr(p, SOCKS_PROTOCOL)) {
+ remove_string(p, socks_proxy, SOCKS_PROTOCOL);
+ } else {
+ fprintf(stdout, "http_proxy=%s https_proxy=%s ftp_proxy=%s socks_proxy=%s", p, p, p, p);
+ free(p);
+ free(proxyserver);
+ RegCloseKey(hKey);
+ return;
+ }
+ }
+ free(p);
+ fprintf(stdout, "http_proxy=%s https_proxy=%s ftp_proxy=%s socks_proxy=%s", http_proxy, https_proxy, ftp_proxy, socks_proxy);
+ free(proxyserver);
+ RegCloseKey(hKey);
+}
+
#include "osutil.h"
#include "emulator.h"
#include "emul_state.h"
+#include "debug_ch.h"
#include "maru_err_table.h"
#include "sdb.h"
#include "emulator_options.h"
#include <unistd.h>
#include <sys/shm.h>
#include <sys/sysctl.h>
-#include <SystemConfiguration/SystemConfiguration.h>
-#include "debug_ch.h"
MULTI_DEBUG_CHANNEL(qemu, osutil);
static int g_shmid;
-static CFDictionaryRef proxySettings;
extern char tizen_target_img_path[];
-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;
-}
-
-static void check_vm_lock_os(void)
+void check_vm_lock_os(void)
{
/* TODO: */
}
{
char *shared_memory;
int base_port;
-
- check_vm_lock_os();
-
base_port = get_emul_vm_base_port();
g_shmid = shmget((key_t)base_port, getpagesize(), 0666|IPC_CREAT);
if (g_shmid == -1) {
}
}
-static int get_auto_proxy(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;
-
- CFStringRef pacURL = (CFStringRef)CFDictionaryGetValue(proxySettings,
- kSCPropNetProxiesProxyAutoConfigURLString);
- if (pacURL) {
- char url[DEFAULTBUFLEN] = {};
- 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, 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(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, DEFAULTBUFLEN, "%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, DEFAULTBUFLEN, "%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, DEFAULTBUFLEN, "%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, DEFAULTBUFLEN, "%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);
- }
- }
-}
-
bool make_sdcard_lock_os(char *sdcard)
{
return make_sdcard_lock_posix(sdcard);
#include "osutil.h"
#include "emulator.h"
#include "emul_state.h"
+#include "debug_ch.h"
#include "maru_err_table.h"
#include "sdb.h"
#include "emulator_options.h"
#include "hw/virtio/maru_virtio_evdi.h"
#endif
-#include "debug_ch.h"
MULTI_DEBUG_CHANNEL(emulator, osutil);
static int g_shmid;
static char *g_shared_memory;
-static int gproxytool = GSETTINGS;
extern char tizen_target_img_path[];
-/* Getting proxy commands */
-static const char* gproxycmds[][2] = {
- { "gconftool-2 -g /system/proxy/mode" , "gsettings get org.gnome.system.proxy mode" },
- { "gconftool-2 -g /system/proxy/autoconfig_url", "gsettings get org.gnome.system.proxy autoconfig-url" },
- { "gconftool-2 -g /system/http_proxy/host", "gsettings get org.gnome.system.proxy.http host" },
- { "gconftool-2 -g /system/http_proxy/port", "gsettings get org.gnome.system.proxy.http port"},
- { "gconftool-2 -g /system/proxy/secure_host", "gsettings get org.gnome.system.proxy.https host" },
- { "gconftool-2 -g /system/proxy/secure_port", "gsettings get org.gnome.system.proxy.https port" },
- { "gconftool-2 -g /system/proxy/ftp_host", "gsettings get org.gnome.system.proxy.ftp host" },
- { "gconftool-2 -g /system/proxy/ftp_port", "gsettings get org.gnome.system.proxy.ftp port" },
- { "gconftool-2 -g /system/proxy/socks_host", "gsettings get org.gnome.system.proxy.socks host" },
- { "gconftool-2 -g /system/proxy/socks_port", "gsettings get org.gnome.system.proxy.socks port" },
-};
-
-static void check_vm_lock_os(void)
+void check_vm_lock_os(void)
{
int shm_id;
void *shm_addr;
g_free(buffer);
}
-static void process_string(char *buf)
-{
- char tmp_buf[DEFAULTBUFLEN];
-
- /* remove single quotes of strings gotten by gsettings */
- if (gproxytool == GSETTINGS) {
- remove_string(buf, tmp_buf, "\'");
- memset(buf, 0, DEFAULTBUFLEN);
- strncpy(buf, tmp_buf, strlen(tmp_buf)-1);
- }
-}
-
-static int get_auto_proxy(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;
- FILE *output;
- char buf[DEFAULTBUFLEN];
-
- output = popen(gproxycmds[GNOME_PROXY_AUTOCONFIG_URL][gproxytool], "r");
- if (fscanf(output, "%s", buf) > 0) {
- process_string(buf);
- INFO("pac address: %s\n", buf);
- download_url(buf);
- }
-
- pclose(output);
- fp_pacfile = fopen(pac_tempfile, "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;
- }
-
- if (remove(pac_tempfile) < 0) {
- WARN("fail to remove the temporary pacfile\n");
- }
-
- return 0;
-}
-
-static void get_proxy(char *http_proxy, char *https_proxy, char *ftp_proxy, char *socks_proxy)
-{
- char buf[DEFAULTBUFLEN] = {0,};
- char buf_port[MAXPORTLEN] = {0,};
- char buf_proxy[DEFAULTBUFLEN] = {0,};
- char *buf_proxy_bak;
- char *proxy;
- FILE *output;
- int MAXPROXYLEN = DEFAULTBUFLEN + MAXPORTLEN;
-
- output = popen(gproxycmds[GNOME_PROXY_HTTP_HOST][gproxytool], "r");
- if(fscanf(output, "%s", buf) > 0) {
- process_string(buf);
- snprintf(buf_proxy, DEFAULTBUFLEN, "%s", buf);
- }
- pclose(output);
-
- output = popen(gproxycmds[GNOME_PROXY_HTTP_PORT][gproxytool], "r");
- if(fscanf(output, "%s", buf_port) <= 0) {
- //for abnormal case: if can't find the key of http port, get from environment value.
- buf_proxy_bak = getenv("http_proxy");
- INFO("http_proxy from env: %s\n", buf_proxy_bak);
- if(buf_proxy_bak != NULL) {
- proxy = malloc(DEFAULTBUFLEN);
- remove_string(buf_proxy_bak, proxy, HTTP_PREFIX);
- strncpy(http_proxy, proxy, strlen(proxy)-1);
- INFO("final http_proxy value: %s\n", http_proxy);
- free(proxy);
- }
- else {
- INFO("http_proxy is not set on env.\n");
- pclose(output);
- return;
- }
-
- }
- else {
- snprintf(http_proxy, MAXPROXYLEN, "%s:%s", buf_proxy, buf_port);
- memset(buf_proxy, 0, DEFAULTBUFLEN);
- INFO("http_proxy: %s\n", http_proxy);
- }
- pclose(output);
-
- memset(buf, 0, DEFAULTBUFLEN);
-
- output = popen(gproxycmds[GNOME_PROXY_HTTPS_HOST][gproxytool], "r");
- if(fscanf(output, "%s", buf) > 0) {
- process_string(buf);
- snprintf(buf_proxy, DEFAULTBUFLEN, "%s", buf);
- }
- pclose(output);
-
- output = popen(gproxycmds[GNOME_PROXY_HTTPS_PORT][gproxytool], "r");
- if(fscanf(output, "%s", buf) > 0) {
- snprintf(https_proxy, MAXPROXYLEN, "%s:%s", buf_proxy, buf);
- }
- pclose(output);
- memset(buf, 0, DEFAULTBUFLEN);
- memset(buf_proxy, 0, DEFAULTBUFLEN);
- INFO("https_proxy : %s\n", https_proxy);
-
- output = popen(gproxycmds[GNOME_PROXY_FTP_HOST][gproxytool], "r");
- if(fscanf(output, "%s", buf) > 0) {
- process_string(buf);
- snprintf(buf_proxy, DEFAULTBUFLEN, "%s", buf);
- }
- pclose(output);
-
- output = popen(gproxycmds[GNOME_PROXY_FTP_PORT][gproxytool], "r");
- if(fscanf(output, "%s", buf) > 0) {
- snprintf(ftp_proxy, MAXPROXYLEN, "%s:%s", buf_proxy, buf);
- }
- pclose(output);
- memset(buf, 0, DEFAULTBUFLEN);
- memset(buf_proxy, 0, DEFAULTBUFLEN);
- INFO("ftp_proxy : %s\n", ftp_proxy);
-
- output = popen(gproxycmds[GNOME_PROXY_SOCKS_HOST][gproxytool], "r");
- if(fscanf(output, "%s", buf) > 0) {
- process_string(buf);
- snprintf(buf_proxy, DEFAULTBUFLEN, "%s", buf);
- }
- pclose(output);
-
- output = popen(gproxycmds[GNOME_PROXY_SOCKS_PORT][gproxytool], "r");
- if(fscanf(output, "%s", buf) > 0) {
- snprintf(socks_proxy, MAXPROXYLEN, "%s:%s", buf_proxy, buf);
- }
- pclose(output);
- INFO("socks_proxy : %s\n", socks_proxy);
-}
-
-
-void get_host_proxy_os(char *http_proxy, char *https_proxy, char *ftp_proxy, char *socks_proxy)
-{
- char buf[DEFAULTBUFLEN];
- FILE *output;
- int ret;
-
- output = popen(gproxycmds[GNOME_PROXY_MODE][gproxytool], "r");
- ret = fscanf(output, "%s", buf);
- if (ret <= 0) {
- pclose(output);
- INFO("Try to use gsettings to get proxy\n");
- gproxytool = GSETTINGS;
- output = popen(gproxycmds[GNOME_PROXY_MODE][gproxytool], "r");
- ret = fscanf(output, "%s", buf);
- }
- if (ret > 0) {
- process_string(buf);
- //priority : auto > manual > none
- if (strcmp(buf, "auto") == 0) {
- INFO("AUTO PROXY MODE\n");
- get_auto_proxy(http_proxy, https_proxy, ftp_proxy, socks_proxy);
- }
- else if (strcmp(buf, "manual") == 0) {
- INFO("MANUAL PROXY MODE\n");
- get_proxy(http_proxy, https_proxy, ftp_proxy, socks_proxy);
- }
- else if (strcmp(buf, "none") == 0) {
- INFO("DIRECT PROXY MODE\n");
- }
- }
- pclose(output);
-}
-
#ifdef CONFIG_SPICE
#define PID_MAX_COUNT 256
#define countof(X) ( (size_t) ( sizeof(X)/sizeof*(X) ) )
extern char tizen_target_img_path[];
static char g_sdcard[256] = {0,};
static sdcard_info info;
-static const char *pactempfile = ".autoproxy";
-static void check_vm_lock_os(void)
+void check_vm_lock_os(void)
{
uint32_t port;
char *base_port = NULL;
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);
- }
- }
- 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,
FILE_SHARE_READ | FILE_SHARE_DELETE,
- NULL,
+ 0,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE,
NULL);
NULL);
/* to check if previous lock exists */
if (hFile2 == INVALID_HANDLE_VALUE) {
- INFO("CreateFile() return : (%d)\n", GetLastError());
+ ERR("CreateFile() error : (%d)\n", GetLastError());
if (GetLastError() == ERROR_SHARING_VIOLATION) {
if (strncmp(g_sdcard, sdcard, strlen(sdcard)) != 0) {
INFO("not same sdcard!!!\n");
INFO("unlock success: %s\n", lock_file);
g_sdcard[0] = '\0';
CloseHandle(info.handle);
+ return ERR_SUCCESS;
} else {
return ERR_UNLCK;
}
} else {
ERR("lockfile exists but, it is not locked.\n");
CloseHandle(hFile2);
+ return ERR_UNLCK;
}
- return ERR_SUCCESS;
}
#include <curl/curl.h>
#include <string.h>
-MULTI_DEBUG_CHANNEL(emulator, osutil);
-
-
-sdcard_info info;
-const char *pac_tempfile = ".autoproxy";
-
-inline 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;
-}
-
-inline 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
+MULTI_DEBUG_CHANNEL(emulator, osutil);
+static sdcard_info info;
+
static int fd_lock(int fd)
{
struct flock lock;
#define __OSUTIL_H__
#include "qemu-common.h"
-#include "emulator_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
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);
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);
return ret;
}
+#define ECS_INDEX 3
+#define SDB_GUEST_PORT 26101
+#define GDB_GUEST_PORT 26102
void set_base_port(void)
{
int tries = 10;
base_port = get_emul_vm_base_port();
- if(base_port == 0){
+ if (base_port == 0) {
for ( ; tries > 0; tries--, port += 10 ) {
- if(check_port_bind_listen(port + 1) < 0 )
+ if (check_port_bind_listen(port + ECS_INDEX) < 0)
continue;
success = 1;
}
base_port = port;
- INFO( "sdb port is %d\n", base_port);
+ INFO( "emulator base port is %d\n", base_port);
}
set_emul_vm_base_port(base_port);
}
+void sdb_setup(void)
+{
+ if (is_emul_tap_enable()) {
+ return;
+ }
+
+ int tries = 10;
+ int success = 0;
+ char buf_sdb[64] = {0,};
+ char buf_gdb[64] = {0,};
+ int number;
+
+ number = get_device_serial_number();
+
+ for ( ; tries > 0; tries--, number += 10 ) {
+ sprintf(buf_sdb, "tcp:%d::%d", number, SDB_GUEST_PORT);
+ sprintf(buf_gdb, "tcp:%d::%d", number + 1, GDB_GUEST_PORT);
+ if(net_slirp_redir((char*)buf_sdb) < 0 || net_slirp_redir((char*)buf_gdb) < 0)
+ continue;
+
+ INFO( "SDBD established on port %d\n", number);
+ success = 1;
+ break;
+ }
+
+ INFO("redirect [%s] success\n", buf_sdb);
+ INFO("redirect [%s] success\n", buf_gdb);
+ if (!success) {
+ INFO( "it seems too many emulator instances are running on this machine. Aborting\n" );
+ exit(1);
+ }
+
+ INFO( "Port(%d/tcp) listen for SDB\n", number);
+}
+
int sdb_loopback_client(int port, int type)
{
struct sockaddr_in addr;
struct sockaddr_in sock_addr;
int s, slen = sizeof(sock_addr);
int serial_len = 0;
- char buf [32];
+ char buf [64];
if ((s = socket(AF_INET, SOCK_STREAM, 0)) == -1){
INFO("socket creation error! %d\n", errno);
memset(&server_addr, '\0', sizeof(server_addr));
server_addr.sin_family = PF_INET;
- server_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
+ server_addr.sin_addr.s_addr = INADDR_ANY;
server_addr.sin_port = htons(port);
qemu_set_nonblock(server->server_fd);
static Notifier sdb_noti_server_exit = { .notify = sdb_noti_server_notify_exit };
-static void start_sdb_noti_server(int server_port)
+void start_sdb_noti_server(int server_port)
{
SDB_Noti_Server *server;
int ret;
emulator_add_exit_notifier(&sdb_noti_server_exit);
}
-void sdb_setup(int server_port)
-{
- int tries = 10;
- int success = 0;
- char buf[64] = {0,};
- int number;
-
- start_sdb_noti_server(server_port);
-
- number = get_device_serial_number();
-
- for ( ; tries > 0; tries--, number += 10 ) {
- sprintf(buf, "tcp:%d::%d", number, number);
- if(net_slirp_redir((char*)buf) < 0)
- continue;
-
- INFO( "SDBD established on port %d\n", number);
- success = 1;
- break;
- }
-
- INFO("redirect [%s] success\n", buf);
- if (!success) {
- INFO( "it seems too many emulator instances are running on this machine. Aborting\n" );
- exit(1);
- }
-
- INFO( "Port(%d/tcp) listen for SDB\n", number);
-}
-
#define SDB_TCP_EMULD_INDEX 2 /* emulator daemon port */
#define SDB_TCP_OPENGL_INDEX 3 /* opengl server port */
-#define SDB_UDP_SENSOR_INDEX 2 /* sensor server port */
+#define SDB_UDP_SENSOR_INDEX 3 /* sensor server port */
-void sdb_setup(int server_port);
+void sdb_setup(void);
void set_base_port(void);
int inet_strtoip(const char* str, uint32_t *ip);
int socket_send(int fd, const void* buf, int buflen);
void socket_close(int fd);
int check_port_bind_listen(uint32_t port);
int sdb_loopback_client(int port, int type);
+void start_sdb_noti_server(int server_port);
#define STATE_RUNNING 0
#define STATE_SUSPEND 1