Add network interface information.
The below commands are added.
--proxy: lists host proxy information.
--interface-all: lists information of host ethernet adapters.
--bridge: lists information of host bridge.
Change-Id: I0d3992fd22053e00d8c845e22805860aaf36ab6b
Signed-off-by: Munkyu Im <munkyu.im@samsung.com>
check-cam.exe
check-gl
check-gl.exe
-check-proxy
-check-proxy.exe
+check-net
+check-net.exe
include ../../config-host.mak
TARGET_EXE += util/check-cam$(EXESUF)
-TARGET_EXE += util/check-proxy$(EXESUF)
+TARGET_EXE += util/check-net$(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)
+# Building check-net
+CHECK_NET_OBJS = util/check_net.o
+CHECK_NET_CFLAGS = -c $(GLIB_CFLAGS) $(CURL_CFLAGS)
+CHECK_NET_LDFLAGS =
+CHECK_NET_TARGET = util/check-net$(EXESUF)
ifdef CONFIG_LINUX
-CHECK_PROXY_OBJS += util/check_proxy_linux.o
-CHECK_PROXY_LDFLAGS += ${CURL_LIBS} `pkg-config --libs glib-2.0`
+CHECK_NET_OBJS += util/check_net_linux.o
+CHECK_NET_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`
+CHECK_NET_OBJS += util/check_net_win32.o
+CHECK_NET_LDFLAGS += -liphlpapi -lws2_32 ${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`
+CHECK_NET_OBJS += util/check_net_darwin.o
+CHECK_NET_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 $@
+util/check-net$(EXESUF): $(CHECK_NET_OBJS)
+ $(CC) $(CHECK_NET_OBJS) $(CHECK_NET_LDFLAGS) -o $@
+$(CHECK_NET_OBJS): %.o: %.c
+ $(CC) $< $(CHECK_NET_CFLAGS) -o $@
# Building check-gl
CHECK_GL_OBJS = util/check_gl.o util/check_gl_core.o
clean: qemu_clean
- rm -f util/check-hax$(EXESUF) util/check-cam$(EXESUF) util/check-gl$(EXESUF) util/check-proxy$(EXESUF)
+ rm -f util/check-hax$(EXESUF) util/check-cam$(EXESUF) util/check-gl$(EXESUF) util/check-net$(EXESUF)
distclean: clean qemu_distclean
install: all
endif
endif
-# check capabilities of OpenGL, Webcam and proxy
+# check capabilities of OpenGL, Webcam and net
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
+ cp -pP util/check-net$(EXESUF) $(EMUL_DIR)/bin
# Enable HW Virtualization on Linux
ifdef CONFIG_LINUX
endif
endif
-# check capabilities of OpenGL, Webcam and proxy
- cp -pP util/check-proxy$(EXESUF) $(DIBS_COMMON_DIR)/bin
+# check capabilities of OpenGL, Webcam and net
+ cp -pP util/check-net$(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
--- /dev/null
+/*
+ * Check Network status
+ *
+ * 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_net.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[])
+{
+ if (argc != 2) {
+ fprintf(stderr, " Usage: check-net --proxy\n");
+ fprintf(stderr, " check-net --interface-all\n");
+ fprintf(stderr, " check-net --bridge\n");
+ exit(1);
+ }
+ if (strcmp(argv[1], ARG_PROXY) == 0) {
+ get_host_proxy_os();
+ } else if (strcmp(argv[1], ARG_INTERFACE_ALL) == 0) {
+ get_host_interface_all_os();
+ } else if (strcmp(argv[1], ARG_BRIDGE) == 0) {
+ get_host_bridge_os();
+ }
+}
--- /dev/null
+/*
+ * Check Network status
+ *
+ * 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_NET_H__
+#define __CHECK_NET_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
+
+#define ARG_PROXY "--proxy"
+#define ARG_INTERFACE_ALL "--interface-all"
+#define ARG_BRIDGE "--bridge"
+#define PATH_IFCONFIG "/sbin/ifconfig"
+
+extern const char *pac_tempfile;
+
+void get_host_proxy_os(void);
+void get_host_interface_all_os(void);
+void get_host_bridge_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 Network status
+ *
+ * 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_net.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();
+ }
+ }
+}
+
+void get_host_interface_all_os(void)
+{
+ if (access(PATH_IFCONFIG, F_OK) != -1) {
+ system("/sbin/ifconfig -a");
+ } else {
+ fprintf(stderr, "ifconfig does not exist!\n");
+ exit(1);
+ }
+}
+
+void get_host_bridge_os(void)
+{
+ if (access(PATH_IFCONFIG, F_OK) != -1) {
+ system("/sbin/ifconfig br-tizen-vm-1");
+ } else {
+ fprintf(stderr, "ifconfig does not exist!\n");
+ exit(1);
+ }
+}
--- /dev/null
+/*
+ * Check Network status
+ *
+ * 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_net.h"
+#include <unistd.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);
+}
+
+void get_host_interface_all_os(void)
+{
+ if (access(PATH_IFCONFIG, F_OK) != -1) {
+ system("/sbin/ifconfig -a");
+ } else {
+ fprintf(stderr, "ifconfig does not exist!\n");
+ exit(1);
+ }
+}
+
+void get_host_bridge_os(void)
+{
+ if (access(PATH_IFCONFIG, F_OK) != -1) {
+ system("/sbin/ifconfig br-tizen-vm-1");
+ } else {
+ fprintf(stderr, "ifconfig does not exist!\n");
+ exit(1);
+ }
+}
--- /dev/null
+/*
+ * Check Network status
+ *
+ * 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
+ *
+ */
+#define _WIN32_WINNT 0x0601
+#include "check_net.h"
+#include <windows.h>
+#include <winsock2.h>
+#include <iphlpapi.h>
+
+#define ALL_INTERFACE 0
+#define BRIDGE_ONLY 1
+#define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x))
+#define FREE(x) HeapFree(GetProcessHeap(), 0, (x))
+#define WORKING_BUFFER_SIZE 15000
+#define MAX_TRIES 3
+
+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);
+}
+
+static print_interface(PIP_ADAPTER_INFO pAdapter, PIP_ADAPTER_ADDRESSES pAddresses)
+{
+ int i;
+ IP_ADAPTER_DNS_SERVER_ADDRESS *pDnServer = NULL;
+ struct sockaddr_in *pAddr;
+
+ fprintf(stdout, "Adapter Desc: %s\n", pAdapter->Description);
+ fprintf(stdout, "Index: %d\n", pAdapter->Index);
+ fprintf(stdout, "ClassID: %s\n", pAdapter->AdapterName);
+ /*
+ typedef enum {
+ IfOperStatusUp = 1,
+ IfOperStatusDown,
+ IfOperStatusTesting,
+ IfOperStatusUnknown,
+ IfOperStatusDormant,
+ IfOperStatusNotPresent,
+ IfOperStatusLowerLayerDown
+ } IF_OPER_STATUS;
+ */
+ fprintf(stdout, "Operating Status: %d\n", pAddresses->OperStatus);
+ fprintf(stdout, "Ethernet Address: ");
+ for (i = 0; i < pAdapter->AddressLength; i++) {
+ if (i == (pAdapter->AddressLength - 1))
+ fprintf(stdout, "%.2X\n", (int) pAdapter->Address[i]);
+ else
+ fprintf(stdout, "%.2X-", (int) pAdapter->Address[i]);
+ }
+ if (pAdapter->DhcpEnabled) {
+ fprintf(stdout, "Use DHCP Server: Yes\n");
+ // fprintf(stdout, "DHCP Server Address: %s\n", pAdapter->DhcpServer.IpAddress.String);
+ } else {
+ fprintf(stdout, "Use DHCP Server: No\n");
+ fprintf(stdout, "IP Address: %s\n", pAdapter->IpAddressList.IpAddress.String);
+ fprintf(stdout, "IP Mask: %s\n", pAdapter->IpAddressList.IpMask.String);
+ fprintf(stdout, "Gateway: %s\n", pAdapter->GatewayList.IpAddress.String);
+
+ }
+
+ pDnServer = pAddresses->FirstDnsServerAddress;
+ if (pDnServer) {
+ pAddr = (struct sockaddr_in*)pDnServer->Address.lpSockaddr;
+ fprintf(stdout, "DNS server address: %s\n", inet_ntoa(pAddr->sin_addr));
+ } else {
+ fprintf(stdout, "DNS server address: No\n");
+ }
+ // fprintf(stdout, "Friendly name: %wS\n", pAddresses->FriendlyName);
+ fprintf(stdout, "\n");
+}
+
+static void get_host_interface(int value)
+{
+ PIP_ADAPTER_ADDRESSES pAddresses = NULL;
+ PIP_ADAPTER_ADDRESSES pCurrAddresses = NULL;
+ DWORD dwRetAddressVal = 0;
+ ULONG flags = 0;
+
+ PIP_ADAPTER_INFO pAdapterInfo;
+ PIP_ADAPTER_INFO pCurrAdapter = NULL;
+ DWORD dwRetVal = 0;
+ UINT i;
+ ULONG Iterations = 0;
+
+ ULONG outBufLen = 0;
+ outBufLen = WORKING_BUFFER_SIZE;
+
+ do {
+
+ pAddresses = (IP_ADAPTER_ADDRESSES *) MALLOC(outBufLen);
+ if (pAddresses == NULL) {
+ fprintf(stderr, "Memory allocation failed for IP_ADAPTER_ADDRESSES struct\n");
+ exit(1);
+ }
+
+ dwRetAddressVal = GetAdaptersAddresses(AF_INET, flags, NULL, pAddresses, &outBufLen);
+
+ if (dwRetAddressVal == ERROR_BUFFER_OVERFLOW) {
+ FREE(pAddresses);
+ pAddresses = NULL;
+ } else {
+ break;
+ }
+
+ Iterations++;
+
+ } while ((dwRetAddressVal == ERROR_BUFFER_OVERFLOW) && (Iterations < MAX_TRIES));
+
+
+ ULONG ulOutBufLen = sizeof (IP_ADAPTER_INFO);
+ pAdapterInfo = (IP_ADAPTER_INFO *) MALLOC(sizeof (IP_ADAPTER_INFO));
+ if (pAdapterInfo == NULL) {
+ fprintf(stderr, "Error allocating memory needed to call GetAdaptersinfo\n");
+ exit(1);
+ }
+ if (GetAdaptersInfo(pAdapterInfo, &ulOutBufLen) == ERROR_BUFFER_OVERFLOW) {
+ FREE(pAdapterInfo);
+ pAdapterInfo = (IP_ADAPTER_INFO *) MALLOC(ulOutBufLen);
+ if (pAdapterInfo == NULL) {
+ fprintf(stderr, "Error allocating memory needed to call GetAdaptersinfo\n");
+ exit(1);
+ }
+ }
+ dwRetVal = GetAdaptersInfo(pAdapterInfo, &ulOutBufLen);
+ if (dwRetVal == NO_ERROR && dwRetAddressVal == NO_ERROR) {
+ pCurrAdapter = pAdapterInfo;
+ pCurrAddresses = pAddresses;
+ while (pCurrAdapter && pCurrAddresses) {
+ if (pCurrAdapter->Type == MIB_IF_TYPE_ETHERNET) {
+ if (value == ALL_INTERFACE) {
+ print_interface(pCurrAdapter, pCurrAddresses);
+ } else if (value == BRIDGE_ONLY) {
+ if (strcmp(pCurrAdapter->Description, "MAC Bridge Miniport") == 0 || strcmp(pCurrAdapter->Description, "Microsoft Network Adapter Multiplexor Driver") == 0) {
+ print_interface(pCurrAdapter, pCurrAddresses);
+ break;
+ }
+ }
+ }
+ pCurrAdapter = pCurrAdapter->Next;
+ pCurrAddresses = pCurrAddresses->Next;
+ }
+ } else {
+ fprintf(stderr, "GetAdaptersInfo failed with error: %d\n", dwRetVal);
+ exit(1);
+ }
+ if (pAdapterInfo)
+ FREE(pAdapterInfo);
+
+ exit(0);
+}
+
+void get_host_interface_all_os(void)
+{
+ get_host_interface(ALL_INTERFACE);
+}
+
+void get_host_bridge_os(void)
+{
+ get_host_interface(BRIDGE_ONLY);
+}
+++ /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);
-}
-