[PATCH 06/18] manual: full support of servers parsing

Tomasz Bursztyka tomasz.bursztyka at linux.intel.com
Thu Jan 19 23:47:04 PST 2012


The result is optimized via supporting a limited number of protocols schemes,
this will have an effect in manual proxy execution. Handled protocols are:
- http
- https
- ftp
- socks4
- socks5
---
 src/manual.c |   62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 60 insertions(+), 2 deletions(-)

diff --git a/src/manual.c b/src/manual.c
index fbf3aa8..c3cb7c9 100644
--- a/src/manual.c
+++ b/src/manual.c
@@ -35,6 +35,17 @@ enum pacrunner_manual_exclude_appliance {
 	PACRUNNER_MANUAL_EXCLUDE_ANY  = 2,
 };
 
+enum pacrunner_manual_protocol {
+	PACRUNNER_PROTOCOL_ALL            = 0,
+	PACRUNNER_PROTOCOL_HTTP           = 1,
+	PACRUNNER_PROTOCOL_HTTPS          = 2,
+	PACRUNNER_PROTOCOL_FTP            = 3,
+	PACRUNNER_PROTOCOL_SOCKS4         = 4,
+	PACRUNNER_PROTOCOL_SOCKS5         = 5,
+	PACRUNNER_PROTOCOL_MAXIMUM_NUMBER = 6,
+	PACRUNNER_PROTOCOL_UNKNOWN        = 7,
+};
+
 static int parse_uri(char *uri,
 			char **host,
 			char **protocol,
@@ -264,31 +275,78 @@ error:
 	return -EINVAL;
 }
 
+static enum pacrunner_manual_protocol get_protocol_from_string(const char *protocol)
+{
+	if (protocol == NULL)
+		return PACRUNNER_PROTOCOL_ALL;
+
+	if (g_strcmp0(protocol, "http") == 0)
+		return PACRUNNER_PROTOCOL_HTTP;
+	if (g_strcmp0(protocol, "https") == 0)
+		return PACRUNNER_PROTOCOL_HTTPS;
+	if (g_strcmp0(protocol, "ftp") == 0)
+		return PACRUNNER_PROTOCOL_FTP;
+	if (g_strcmp0(protocol, "socks4") == 0)
+		return PACRUNNER_PROTOCOL_SOCKS4;
+	if (g_strcmp0(protocol, "socks5") == 0)
+		return PACRUNNER_PROTOCOL_SOCKS5;
+
+	return PACRUNNER_PROTOCOL_UNKNOWN;
+}
+
 GList **__pacrunner_manual_parse_servers(char **servers)
 {
 	char *host, *protocol;
+	GList **result;
 	char **uri;
+	int proto;
 	int ret;
 
 	if (servers == NULL)
 		return NULL;
 
+	result = g_try_malloc0(PACRUNNER_PROTOCOL_MAXIMUM_NUMBER *
+							sizeof(GList *));
+	if (result == NULL)
+		return NULL;
+
 	for (uri = (char **)servers; *uri != NULL; uri++) {
 		ret = parse_uri(*uri, &host, &protocol, TRUE, FALSE);
 
 		if (ret < 0)
 			continue;
 
-		g_free(host);
+		proto = get_protocol_from_string(protocol);
+		if (proto == PACRUNNER_PROTOCOL_UNKNOWN)
+			goto error;
+
+		result[proto] = g_list_append(result[proto], host);
+
 		g_free(protocol);
 	}
 
+	return result;
+
+error:
+	g_free(host);
+	g_free(protocol);
+
+	__pacrunner_manual_destroy_servers(result);
+
 	return NULL;
 }
 
 void __pacrunner_manual_destroy_servers(GList **servers)
 {
-	return;
+	int i;
+
+	if (servers == NULL)
+		return;
+
+	for (i = 0; i < PACRUNNER_PROTOCOL_MAXIMUM_NUMBER; i++)
+		g_list_free_full(servers[i], g_free);
+
+	g_free(servers);
 }
 
 GList **__pacrunner_manual_parse_excludes(char **excludes)
-- 
1.7.8.3



More information about the connman mailing list