emul_state: refined getter function of http proxy address
authorSeokYeon Hwang <syeon.hwang@samsung.com>
Fri, 29 May 2015 10:47:39 +0000 (19:47 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Mon, 1 Jun 2015 05:19:53 +0000 (14:19 +0900)
Change-Id: I1e8a161b7751c7960623d34a9489bc41cdef22e9
Signed-off-by: SeokYeon Hwang <syeon.hwang@samsung.com>
tizen/src/emul_state.c
tizen/src/emul_state.h
tizen/src/emulator.c
tizen/src/emulator_legacy.c
tizen/src/skin/maruskin_client.c
tizen/src/ui/menu/contextmenu.cpp

index fc1d87f8d6e44d09bd2ff48f80b231d71d3dda20..ba14a681538320f752485f76459a76302a795633 100644 (file)
@@ -32,6 +32,7 @@
 #include "emul_state.h"
 
 #include <libgen.h>
+#include "sysemu/sysemu.h"
 #include "emulator_common.h"
 
 #if defined(CONFIG_LINUX)
@@ -429,7 +430,7 @@ const char* get_drive_image_file(void)
     BlockBackend *bb = blk_by_name("drive");
     if (bb) {
         BlockDriverState *bs = blk_bs(bb);
-        set_variable("drive_image_file", bs->filename, true);
+        set_variable("drive_image_file", bs->filename, false);
 
         return bs->filename;
     }
@@ -459,32 +460,34 @@ const char* get_emul_vm_name(void)
 }
 
 /* http proxy */
-void set_emul_http_proxy_addr(char *addr)
+const char* get_http_proxy_addr(void)
 {
-    strncpy(_emul_info.http_proxy_addr, addr, sizeof(_emul_info.http_proxy_addr));
-}
-
-char* get_emul_http_proxy_addr(void)
-{
-    if (strlen(_emul_info.http_proxy_addr) > 0) {
-        return _emul_info.http_proxy_addr;
-    } else {
-        return NULL;
+    const char *http_proxy_addr = get_variable("http_proxy_addr");
+    if (http_proxy_addr) {
+        return http_proxy_addr;
     }
-}
 
-void set_emul_http_proxy_port(char *port)
-{
-    strncpy(_emul_info.http_proxy_port, port, sizeof(_emul_info.http_proxy_port));
-}
+    const char *kernel_cmdline = qemu_opt_get(qemu_get_machine_opts(), "append");
 
-char* get_emul_http_proxy_port(void)
-{
-    if (strlen(_emul_info.http_proxy_port) > 0) {
-        return _emul_info.http_proxy_port;
-    } else {
-        return NULL;
+    // kernel cmdline always contains proxy information
+    char *buf = g_strstr_len(kernel_cmdline, -1, HTTP_PROXY_PREFIX);
+    if (buf) {
+        char **token = g_strsplit_set(buf, "= ", 3);
+        if (token[0] && token[1] && g_strcmp0(token[1], "")) {
+            LOG_INFO("HTTP proxy address : %s\n", token[1]);
+            set_variable("http_proxy_addr", token[1], false);
+            g_strfreev(token);
+
+            http_proxy_addr = get_variable("http_proxy_addr");
+
+            return http_proxy_addr;
+        }
+        g_strfreev(token);
     }
+
+    LOG_INFO("HTTP proxy address is not set.\n");
+
+    return NULL;
 }
 
 void set_emul_hds_attached(bool attached)
index e2b94f9d0ba999a8095a1c826888da6a62c3e892..a8454b3dad10b9900925de3d5c9f1f2a9ac43f67 100644 (file)
@@ -163,8 +163,6 @@ 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_tap_enable(bool enable);
-void set_emul_http_proxy_addr(char *addr);
-void set_emul_http_proxy_port(char *port);
 void set_emul_hds_attached(bool attached);
 void set_emul_hds_path(const char *path);
 void set_emul_hds_guest_path(const char *path);
@@ -203,16 +201,16 @@ int get_emul_num_lock_state(void);
 char* get_emul_guest_ip(void);
 char* get_emul_host_ip(void);
 bool is_emul_tap_enable(void);
-char* get_emul_http_proxy_addr(void);
-char* get_emul_http_proxy_port(void);
 
 bool get_emul_hds_attached(void);
 char* get_emul_hds_path(void);
 char* get_emul_hds_guest_path(void);
 char* get_emul_profile(void);
+
 bool get_emuld_connection(void);
 bool get_sdb_connection(void);
 const char* get_drive_image_file(void);
+const char* get_http_proxy_addr(void);
 
 /* multi-touch */
 MultiTouchState *get_emul_multi_touch_state(void);
index e9cb1b7b3364d0f1b065a68b1b5719331d69ff9c..fb025c6bb040579d4ff2fd7c199a034421acb788 100644 (file)
@@ -173,43 +173,6 @@ static void print_options_info(void)
     fflush(stdout);
 }
 
-static void http_proxy_setup(gchar * const kernel_cmdline)
-{
-#ifdef SUPPORT_LEGACY_ARGS
-    char *buf = strstr(kernel_cmdline, HTTP_PROXY_PREFIX);
-#else
-    char *buf = get_variable("network_proxy");
-#endif
-    gchar** proxy;
-    if (buf) {
-        char http_proxy[MAXLEN] = {0,};
-        int len = strlen(HTTP_PROXY_PREFIX);
-        int i, j;
-        int max_len = strlen(buf);
-        for(i = len, j = 0; i < max_len; i++) {
-            if (buf[i] == ' ')
-                break;
-            http_proxy[j++] = buf[i];
-        }
-
-        http_proxy[j] = '\0';
-        proxy = g_strsplit(http_proxy, ":", -1);
-        if (g_strv_length(proxy) > 1) {
-            if (proxy[0] != NULL && proxy[1] != NULL) {
-                LOG_INFO("http_proxy information= addr: %s, port: %s\n", proxy[0], proxy[1]);
-                set_emul_http_proxy_addr(proxy[0]);
-                set_emul_http_proxy_port(proxy[1]);
-            }
-        } else {
-            LOG_INFO("http proxy is NULL\n");
-        }
-
-        if (proxy != NULL) {
-            g_strfreev(proxy);
-        }
-    }
-}
-
 #define PROXY_BUFFER_LEN  128
 static void prepare_basic_features(gchar * const kernel_cmdline)
 {
@@ -220,7 +183,6 @@ static void prepare_basic_features(gchar * const kernel_cmdline)
             " vm_resolution=%dx%d", get_emul_vm_base_port(),
             get_emul_resolution_width(), get_emul_resolution_height());
     set_emul_host_ip(kernel_cmdline);
-    http_proxy_setup(kernel_cmdline);
     g_strlcat(kernel_cmdline, tmp_str, LEN_MARU_KERNEL_CMDLINE);
     g_free(tmp_str);
 }
index 9472223beedcd529f286996ac7022f8cfab002e1..ffbc70dda3faa98796b0b88c25007a9b0f8d380e 100644 (file)
@@ -145,7 +145,6 @@ static void set_image_and_log_path(char *qemu_argv)
 
     set_emul_vm_data_path(tizen_target_path);
     set_variable("vm_name", g_path_get_basename(tizen_target_path), true);
-
     set_variable("drive_image_file", path, true);
     free(path);
 
index ec0dacd22e3e2c41e9ec308fd76476f90658b303..7b6f93af80d288eac84b0423c5369d68d67496f1 100644 (file)
@@ -139,15 +139,20 @@ static void *run_skin_client(void *arg)
     gchar const* proxy_addr;
     int proxy_addr_len = 0;
 
-    if (get_emul_http_proxy_addr() == NULL) {
+    const char *http_proxy = get_http_proxy_addr();
+    if (http_proxy == NULL) {
         proxy_addr = g_strdup_printf("%s= %s=",
                 OPT_PROXY_ADDR, OPT_PROXY_PORT);
         proxy_addr_len = (int)strlen(proxy_addr);
     } else {
-        proxy_addr = g_strdup_printf("%s=%s %s=%s",
-                OPT_PROXY_ADDR, get_emul_http_proxy_addr(),
-                OPT_PROXY_PORT, get_emul_http_proxy_port());
-        proxy_addr_len = (int)strlen(proxy_addr);
+        char **proxy = g_strsplit(http_proxy, ":", 2);
+        if (proxy[0] && proxy[1]) {
+            proxy_addr = g_strdup_printf("%s=%s %s=%s",
+                    OPT_PROXY_ADDR, proxy[0],
+                    OPT_PROXY_PORT, proxy[1]);
+            proxy_addr_len = (int)strlen(proxy_addr);
+        }
+        g_strfreev(proxy);
     }
     gchar const* tap_enabled = g_strdup_printf("%s=%s", OPT_USE_TAP, is_emul_tap_enable() ? "true" : "false");
     int tap_opt_len = (int)strlen(tap_enabled);
index efc25dab4f75e01ce456905f66756a6307a5b71d..16d643b364585d7b9fbf3f06d540aecb30f393e9 100644 (file)
@@ -675,9 +675,14 @@ void ContextMenu::slotControlPanel()
 #endif
     QString httpProxyAddr;
     QString httpProxyPort;
-    if (get_emul_http_proxy_addr()) {
-        httpProxyAddr = "-Dhttp.proxyHost=" + QString(get_emul_http_proxy_addr());
-        httpProxyPort = "-Dhttp.proxyPort=" + QString(get_emul_http_proxy_port());
+    const char *http_proxy_addr = get_http_proxy_addr();
+    if (http_proxy_addr) {
+        char **proxy = g_strsplit(http_proxy_addr, ":", 2);
+        if (proxy[0] && proxy[1]) {
+            httpProxyAddr = "-Dhttp.proxyHost=" + QString(proxy[0]);
+            httpProxyPort = "-Dhttp.proxyPort=" + QString(proxy[1]);
+        }
+        g_strfreev(proxy);
     }
 
     if (httpProxyAddr != NULL && httpProxyPort != NULL) {