osutil: Add gsettings to get proxy to support multiple host OS
authorDongxing Liu <dongxingx.liu@intel.com>
Tue, 9 Jul 2013 02:25:11 +0000 (10:25 +0800)
committerJinhyung Choi <jinhyung2.choi@samsung.com>
Tue, 6 Aug 2013 03:00:04 +0000 (12:00 +0900)
Signed-off-by: Dongxing Liu <dongxingx.liu@intel.com>
tizen/src/osutil-linux.c
tizen/src/osutil.h

index 8d8656c30603170e71b10cc85e39346f3448edc0..fba3ba8fd8e83d589c839dfca3139e76c88ec2a5 100644 (file)
@@ -59,6 +59,21 @@ extern char tizen_target_img_path[];
 extern int tizen_base_port;
 int g_shmid;
 char *g_shared_memory;
+int gproxytool = GCONFTOOL;
+
+/* 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" },
+};
 
 void check_vm_lock_os(void)
 {
@@ -193,6 +208,18 @@ void print_system_info_os(void)
     }
 }
 
+static void process_string(char *buf)
+{
+    char tmp_buf[MAXLEN];
+
+    /* remove single quotes of strings gotten by gsettings */
+    if (gproxytool == GSETTINGS) {
+        remove_string(buf, tmp_buf, "\'");
+        memset(buf, 0, MAXLEN);
+        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[MAXLEN];
@@ -203,8 +230,9 @@ static int get_auto_proxy(char *http_proxy, char *https_proxy, char *ftp_proxy,
     FILE *output;
     char buf[MAXLEN];
 
-    output = popen("gconftool-2 --get /system/proxy/autoconfig_url", "r");
+    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);
     }
@@ -260,13 +288,14 @@ static void get_proxy(char *http_proxy, char *https_proxy, char *ftp_proxy, char
     FILE *output;
     int MAXPROXYLEN = MAXLEN + MAXPORTLEN;
 
-    output = popen("gconftool-2 --get /system/http_proxy/host", "r");
+    output = popen(gproxycmds[GNOME_PROXY_HTTP_HOST][gproxytool], "r");
     if(fscanf(output, "%s", buf) > 0) {
+        process_string(buf);
         snprintf(buf_proxy, MAXLEN, "%s", buf);
     }
     pclose(output);
     
-    output = popen("gconftool-2 --get /system/http_proxy/port", "r");
+    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");
@@ -294,13 +323,14 @@ static void get_proxy(char *http_proxy, char *https_proxy, char *ftp_proxy, char
 
     memset(buf, 0, MAXLEN);
 
-    output = popen("gconftool-2 --get /system/proxy/secure_host", "r");
+    output = popen(gproxycmds[GNOME_PROXY_HTTPS_HOST][gproxytool], "r");
     if(fscanf(output, "%s", buf) > 0) {
+        process_string(buf);
         snprintf(buf_proxy, MAXLEN, "%s", buf);
     }
     pclose(output);
 
-    output = popen("gconftool-2 --get /system/proxy/secure_port", "r");
+    output = popen(gproxycmds[GNOME_PROXY_HTTPS_PORT][gproxytool], "r");
     if(fscanf(output, "%s", buf) > 0) {
         snprintf(https_proxy, MAXPROXYLEN, "%s:%s", buf_proxy, buf);
     }
@@ -309,13 +339,14 @@ static void get_proxy(char *http_proxy, char *https_proxy, char *ftp_proxy, char
     memset(buf_proxy, 0, MAXLEN);
     INFO("https_proxy : %s\n", https_proxy);
 
-    output = popen("gconftool-2 --get /system/proxy/ftp_host", "r");
+    output = popen(gproxycmds[GNOME_PROXY_FTP_HOST][gproxytool], "r");
     if(fscanf(output, "%s", buf) > 0) {
+        process_string(buf);
         snprintf(buf_proxy, MAXLEN, "%s", buf);
     }
     pclose(output);
 
-    output = popen("gconftool-2 --get /system/proxy/ftp_port", "r");
+    output = popen(gproxycmds[GNOME_PROXY_FTP_PORT][gproxytool], "r");
     if(fscanf(output, "%s", buf) > 0) {
         snprintf(ftp_proxy, MAXPROXYLEN, "%s:%s", buf_proxy, buf);
     }
@@ -324,13 +355,14 @@ static void get_proxy(char *http_proxy, char *https_proxy, char *ftp_proxy, char
     memset(buf_proxy, 0, MAXLEN);
     INFO("ftp_proxy : %s\n", ftp_proxy);
 
-    output = popen("gconftool-2 --get /system/proxy/socks_host", "r");
+    output = popen(gproxycmds[GNOME_PROXY_SOCKS_HOST][gproxytool], "r");
     if(fscanf(output, "%s", buf) > 0) {
+        process_string(buf);
         snprintf(buf_proxy, MAXLEN, "%s", buf);
     }
     pclose(output);
 
-    output = popen("gconftool-2 --get /system/proxy/socks_port", "r");
+    output = popen(gproxycmds[GNOME_PROXY_SOCKS_PORT][gproxytool], "r");
     if(fscanf(output, "%s", buf) > 0) {
         snprintf(socks_proxy, MAXPROXYLEN, "%s:%s", buf_proxy, buf);
     }
@@ -343,9 +375,19 @@ void get_host_proxy_os(char *http_proxy, char *https_proxy, char *ftp_proxy, cha
 {
     char buf[MAXLEN];
     FILE *output;
-
-    output = popen("gconftool-2 --get /system/proxy/mode", "r");
-    if(fscanf(output, "%s", buf) > 0) {
+    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");
index a9e9704a5e942a4bee99aaa18947fd6b21cf6421..b4214780fc92a5e08af16f6084b77c4b9d4c5e30 100644 (file)
 #define PROXY "PROXY"
 #define MAXPORTLEN 6
 
+#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 check_vm_lock_os(void);