net: set/get http_proxy
authorMunkyu Im <munkyu.im@samsung.com>
Tue, 14 Apr 2015 06:24:35 +0000 (15:24 +0900)
committerMunkyu Im <munkyu.im@samsung.com>
Mon, 27 Apr 2015 10:24:40 +0000 (19:24 +0900)
Emulator uses http_proxy for launching Emulator Control Panel.
It's used for displaying map on network tab.

Change-Id: I19418910bce04eb5d12bdeb694d8d449262b257d
Signed-off-by: Munkyu Im <munkyu.im@samsung.com>
tizen/src/emul_state.c
tizen/src/emul_state.h
tizen/src/emulator.c
tizen/src/emulator_common.h
tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkin.java
tizen/src/skin/client/src/org/tizen/emulator/skin/config/EmulatorConfig.java
tizen/src/skin/maruskin_client.c
tizen/src/ui/menu/contextmenu.cpp

index d56a5196a1499e93f5d302ba674253a0806307ba..66f80bded96a9981936d730db3e11ec8f354f16d 100644 (file)
@@ -387,6 +387,35 @@ char* get_emul_vm_name(void)
     return _emul_info.vm_name;
 }
 
+/* emualtor http proxy */
+void set_emul_http_proxy_addr(char *addr)
+{
+    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;
+    }
+}
+
+void set_emul_http_proxy_port(char *port)
+{
+    strncpy(_emul_info.http_proxy_port, port, sizeof(_emul_info.http_proxy_port));
+}
+
+char* get_emul_http_proxy_port(void)
+{
+    if (strlen(_emul_info.http_proxy_port) > 0) {
+        return _emul_info.http_proxy_port;
+    } else {
+        return NULL;
+    }
+}
+
 void set_emul_hds_attached(bool attached)
 {
     _emul_state.hds_attached = attached;
index b2146bc74243c318a8078af138c13ea807238dfd..3ec9160c63db16c65bcbf815a3678aab2036ee9c 100644 (file)
@@ -37,6 +37,8 @@
 #include "display/maru_finger.h"
 
 #define SUPPORT_LEGACY_ARGS
+#define MAX_ADDR_LEN    256
+#define MAX_PORT_LEN    256
 
 #define MAX_HDS_PATH    256
 #define MAX_PROFILE     256
@@ -97,6 +99,9 @@ typedef  struct EmulatorConfigInfo {
     int vm_base_port;
     int device_serial_number;
     int ecs_port;
+    char http_proxy_addr[MAX_ADDR_LEN];
+    char http_proxy_port[MAX_PORT_LEN];
+
     bool tap_enable;
     char guest_ip[16];
 
@@ -159,6 +164,8 @@ 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);
@@ -196,6 +203,8 @@ int get_emul_caps_lock_state(void);
 int get_emul_num_lock_state(void);
 char* get_emul_guest_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);
index bd4ef2e6304d7a28963010cb4e6f204f99ffc014..fab2129e9771ba2042c97473093ec10c62d61a7b 100644 (file)
@@ -172,6 +172,39 @@ static void print_options_info(void)
     fprintf(stdout, "\n====================================================\n");
 }
 
+static void http_proxy_setup(void)
+{
+    char *buf = get_variable("network_proxy");
+    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)
 {
@@ -192,6 +225,7 @@ static void prepare_basic_features(gchar * const kernel_cmdline)
     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());
+    http_proxy_setup();
 
     g_strlcat(kernel_cmdline, tmp_str, LEN_MARU_KERNEL_CMDLINE);
 
index 99821be7cb5f6a3ecbb3c6f62d4da5081351efb5..a29efff56f502111133750c65be5c0edb27fecec 100644 (file)
@@ -58,6 +58,9 @@
 #endif
 
 #define JAVA_MAX_COMMAND_LENGTH 1024
+#define MAXLEN  512
+#define HTTP_PROXY_PREFIX "http_proxy="
+
 
 #define JAR_SKINFILE "emulator-skin.jar"
 #define JAVA_LIBRARY_PATH "-Djava.library.path"
index a339ae0d7811a6e685a4266e63560e6d1c159f82..897aee75806d78d04a7a6532dfd1324fc089f70f 100644 (file)
@@ -1924,22 +1924,47 @@ public class EmulatorSkin {
                                        return;
                 }
 
-                String emulName = SkinUtil.getVmName(config);
-                int portSdb = config.getArgInt(ArgsConstants.VM_BASE_PORT);
+                               String emulName = SkinUtil.getVmName(config);
+                               int basePort = config.getArgInt(ArgsConstants.VM_BASE_PORT);
+                               String proxyAddr = config.getArg(ArgsConstants.PROXY_ADDR);
+                               String proxyPort = config.getArg(ArgsConstants.PROXY_PORT);
 
                                ProcessBuilder procEcp = new ProcessBuilder();
 
                                // FIXME: appropriate running binary setting is necessary.
                                if (SwtUtil.isWindowsPlatform()) {
-                                       procEcp.command("java.exe", "-jar", ecpPath, "vmname="
-                                                       + emulName, "base.port=" + portSdb);
+                                       if (proxyAddr != null && proxyPort != null) {
+                                               procEcp.command("java.exe", "-Dhttp.proxyHost="
+                                                               + proxyAddr, "-Dhttp.proxyPort=" + proxyPort,
+                                                               "-jar", ecpPath, "vmname=" + emulName,
+                                                               "base.port=" + basePort);
+                                       } else {
+                                               procEcp.command("java.exe", "-jar", ecpPath, "vmname="
+                                                               + emulName, "base.port=" + basePort);
+                                       }
                                } else if (SwtUtil.isMacPlatform()) {
-                                       procEcp.command("java", "-jar", "-XstartOnFirstThread",
-                                                       ecpPath, "vmname=" + emulName, "base.port="
-                                                                       + portSdb);
+                                       if (proxyAddr != null && proxyPort != null) {
+                                               procEcp.command("java",
+                                                               "-Dhttp.proxyHost=" + proxyAddr,
+                                                               "-Dhttp.proxyPort=" + proxyPort, "-jar",
+                                                               "-XstartOnFirstThread", ecpPath, "vmname="
+                                                                               + emulName, "base.port=" + basePort);
+                                       } else {
+                                               procEcp.command("java", "-jar", "-XstartOnFirstThread",
+                                                               ecpPath, "vmname=" + emulName, "base.port="
+                                                                               + basePort);
+                                       }
                                } else { /* Linux */
-                                       procEcp.command("java", "-jar", ecpPath, "vmname="
-                                                       + emulName, "base.port=" + portSdb);
+                                       if (proxyAddr != null && proxyPort != null) {
+                                               procEcp.command("java",
+                                                               "-Dhttp.proxyHost=" + proxyAddr,
+                                                               "-Dhttp.proxyPort=" + proxyPort, "-jar",
+                                                               ecpPath, "vmname=" + emulName, "base.port="
+                                                                               + basePort);
+                                       } else {
+                                               procEcp.command("java", "-jar", ecpPath, "vmname="
+                                                               + emulName, "base.port=" + basePort);
+                                       }
                                }
 
                                logger.info(procEcp.command().toString());
index 7e30c4439176b217d6b25ac2415f3fd51fd1e52b..ddd2848fc5076a880e5543b09c8951ddba2dae4e 100644 (file)
@@ -82,6 +82,8 @@ public class EmulatorConfig {
                public static final String INPUT_MOUSE = "input.mouse";
                public static final String INPUT_TOUCHSCREEN = "input.touch";
                public static final String INPUT_TOUCH_MAXPOINT = "input.touch.maxpoint";
+               public static final String PROXY_ADDR = "proxy.addr";
+               public static final String PROXY_PORT = "proxy.port";
        }
 
        public interface SkinPropertiesConstants {
index 589a2873212af248e5f2317833c49249c1855c1b..63f0f61dcf8d8308b515457519eb44027959b0ea 100644 (file)
@@ -66,6 +66,8 @@ MULTI_DEBUG_CHANNEL(qemu, skinclient);
 #define OPT_INPUT_MOUSE "input.mouse"
 #define OPT_INPUT_TOUCH "input.touch"
 #define OPT_MAX_TOUCHPOINT "input.touch.maxpoint"
+#define OPT_PROXY_ADDR "proxy.addr"
+#define OPT_PROXY_PORT "proxy.port"
 
 #define OPT_BOOLEAN_TRUE "true"
 #define OPT_BOOLEAN_FALSE "false"
@@ -103,9 +105,9 @@ static void *run_skin_client(void *arg)
     int skin_server_port = get_skin_server_port();
     int vm_base_port = get_emul_vm_base_port();
 
-    char buf_skin_server_port[16];
-    char buf_uid[16];
-    char buf_vm_base_port[16];
+    char buf_skin_server_port[16] = { 0, };
+    char buf_uid[16] = { 0, };
+    char buf_vm_base_port[16] = { 0, };
     sprintf(buf_skin_server_port, "%d", skin_server_port);
     sprintf(buf_uid, "%d", uid);
     sprintf(buf_vm_base_port, "%d", vm_base_port);
@@ -126,10 +128,17 @@ static void *run_skin_client(void *arg)
 
     /* input */
     char buf_input[12] = { 0, };
-    if (is_emul_input_mouse_enable() == true)
+    if (is_emul_input_mouse_enable() == true) {
         strcpy(buf_input, OPT_INPUT_MOUSE);
-    else
+    } else {
         strcpy(buf_input, OPT_INPUT_TOUCH);
+    }
+
+    /* network */
+    char buf_proxy_addr[MAX_ADDR_LEN] = { 0, };
+    char buf_proxy_port[MAX_PORT_LEN] = { 0, };
+    sprintf(buf_proxy_addr, "%s", get_emul_http_proxy_addr());
+    sprintf(buf_proxy_port, "%s", get_emul_http_proxy_port());
 
 #ifdef CONFIG_WIN32
     /* find java path in 64bit windows */
@@ -187,7 +196,11 @@ static void *run_skin_client(void *arg)
         strlen(buf_input) + EQUAL_LEN +
             strlen(OPT_BOOLEAN_TRUE) + SPACE_LEN +
         strlen(OPT_MAX_TOUCHPOINT) + EQUAL_LEN +
-            len_maxtouchpoint + SPACE_LEN + 1 +
+            len_maxtouchpoint + SPACE_LEN +
+        strlen(OPT_PROXY_ADDR) + EQUAL_LEN +
+            strlen(buf_proxy_addr) + SPACE_LEN +
+        strlen(OPT_PROXY_PORT) + EQUAL_LEN +
+            strlen(buf_proxy_port) + SPACE_LEN + 1 +
         strlen(argv);
 
     INFO("skin command length : %d\n", cmd_len);
@@ -207,6 +220,8 @@ static void *run_skin_client(void *arg)
 %s=%s \
 %s=%s \
 %s=%d \
+%s=%s \
+%s=%s \
 %s",
         JAVA_EXEFILE_PATH, JAVA_EXEOPTION, JAVA_LIBRARY_PATH,
 #ifdef CONFIG_WIN32
@@ -221,6 +236,8 @@ static void *run_skin_client(void *arg)
         OPT_DISPLAY_SHM, buf_display_shm,
         buf_input, OPT_BOOLEAN_TRUE,
         OPT_MAX_TOUCHPOINT, maxtouchpoint,
+        OPT_PROXY_ADDR, buf_proxy_addr,
+        OPT_PROXY_PORT, buf_proxy_port,
         argv);
 
     INFO("command for swt : %s\n", cmd);
index 07343712e82cee7339d02d05b2ccd437fcbc199c..1a768de99827b5a1fcde460c35b0770478b08a49 100644 (file)
@@ -673,6 +673,17 @@ void ContextMenu::slotControlPanel()
     /* SWT Display must be created on main thread due to Cocoa restrictions */
     arguments << "-XstartOnFirstThread";
 #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());
+    }
+
+    if (httpProxyAddr != NULL && httpProxyPort != NULL) {
+        arguments << httpProxyAddr << httpProxyPort;
+    }
+
     arguments << "-jar" << ecpPath << vmNameOpt << basePortOpt;
     qDebug() << command << arguments;