From bb08bb384d054f429e7a48f0acb35e86b1b71989 Mon Sep 17 00:00:00 2001 From: Tomasz Bursztyka Date: Fri, 14 Jun 2013 10:24:45 +0300 Subject: manual: Interpret url's protocol relevantly when generating proxy list Protocols are also reordered so they appear in the list in a specific order. --- src/manual.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/manual.c b/src/manual.c index 98e30ff..ca83de0 100644 --- a/src/manual.c +++ b/src/manual.c @@ -40,9 +40,9 @@ enum pacrunner_manual_protocol { PACRUNNER_PROTOCOL_HTTP = 1, PACRUNNER_PROTOCOL_HTTPS = 2, PACRUNNER_PROTOCOL_FTP = 3, - PACRUNNER_PROTOCOL_SOCKS4 = 4, - PACRUNNER_PROTOCOL_SOCKS5 = 5, - PACRUNNER_PROTOCOL_SOCKS = 6, + PACRUNNER_PROTOCOL_SOCKS = 4, + PACRUNNER_PROTOCOL_SOCKS4 = 5, + PACRUNNER_PROTOCOL_SOCKS5 = 6, PACRUNNER_PROTOCOL_MAXIMUM_NUMBER = 7, PACRUNNER_PROTOCOL_UNKNOWN = 8, }; @@ -293,12 +293,12 @@ static enum pacrunner_manual_protocol get_protocol_from_string(const char *proto return PACRUNNER_PROTOCOL_HTTPS; if (g_strcmp0(protocol, "ftp") == 0) return PACRUNNER_PROTOCOL_FTP; + if (g_strcmp0(protocol, "socks") == 0) + return PACRUNNER_PROTOCOL_SOCKS; if (g_strcmp0(protocol, "socks4") == 0) return PACRUNNER_PROTOCOL_SOCKS4; if (g_strcmp0(protocol, "socks5") == 0) return PACRUNNER_PROTOCOL_SOCKS5; - if (g_strcmp0(protocol, "socks") == 0) - return PACRUNNER_PROTOCOL_SOCKS; return PACRUNNER_PROTOCOL_UNKNOWN; } @@ -591,8 +591,11 @@ static inline char *append_servers_to_proxy_string(char *prev_result, static char *generate_proxy_string(GList **servers, enum pacrunner_manual_protocol proto) { + enum pacrunner_manual_protocol i; char *result = NULL; + /* if the protocol is known, we will prefer to set same + * protocol-based proxies first, if any... */ if (proto >= PACRUNNER_PROTOCOL_HTTP && proto < PACRUNNER_PROTOCOL_MAXIMUM_NUMBER) { if (servers[proto] != NULL) @@ -609,9 +612,17 @@ static char *generate_proxy_string(GList **servers, } } - if (servers[PACRUNNER_PROTOCOL_ALL] != NULL) - result = append_servers_to_proxy_string(result, - servers[PACRUNNER_PROTOCOL_ALL]); + /* And/or we add the rest in the list */ + for (i = 0; i < PACRUNNER_PROTOCOL_MAXIMUM_NUMBER; i++) { + if (i == proto || (proto == PACRUNNER_PROTOCOL_SOCKS && + (i == PACRUNNER_PROTOCOL_SOCKS4 || + i == PACRUNNER_PROTOCOL_SOCKS5))) + continue; + + if (servers[i] != NULL) + result = append_servers_to_proxy_string(result, + servers[i]); + } return result; } -- cgit 1.2.3-korg