--- src/manual.c | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/pacrunner.h | 4 ++ src/proxy.c | 10 ++--- 3 files changed, 112 insertions(+), 6 deletions(-)
diff --git a/src/manual.c b/src/manual.c index 345e5ca..ff14095 100644 --- a/src/manual.c +++ b/src/manual.c @@ -275,3 +275,107 @@ struct pacrunner_manual_excludes *__pacrunner_manual_create_excludes(const char return rule_list; } + +static int is_host_matching(struct pacrunner_manual_excludes *rule, + const char *host) +{ + char *cur; + + DBG(" "); + + if (rule == NULL) + return 0; + + if (rule->host == NULL) + return 0; + + if (host == NULL) + return 0; + + cur = strstr(host, rule->host); + + if (cur == NULL) + return 0; + + switch (rule->appliance) { + case PACRUNNER_MANUAL_EXCLUDE_POST: + if (*(cur + rule->host_length) == '\0') + return 1; + break; + case PACRUNNER_MANUAL_EXCLUDE_PRE: + if (cur == host) + return 1; + break; + case PACRUNNER_MANUAL_EXCLUDE_ANY: + return 1; + } + + return 0; +} + +static int is_url_excluded(struct pacrunner_manual_excludes *excludes, + const char *host, const char *proto) +{ + struct pacrunner_manual_excludes *rule; + + DBG(" "); + + if (excludes == NULL) + return 0; + + for (rule = excludes; rule != NULL; rule = rule->next) { + if (rule->proto != NULL && rule->host != NULL) { + if (g_strcmp0(proto, rule->proto) == 0 && + is_host_matching(rule, host) != 0) + return 1; + } else if (rule->proto != NULL) { + if (g_strcmp0(proto, rule->proto) == 0) + return 1; + } else { + if (is_host_matching(rule, host) != 0) + return 1; + } + } + + return 0; +} + +const char *__pacrunner_manual_execute( + enum pacrunner_proxy_manual_context context, + struct pacrunner_manual_excludes *excludes, + char **servers, const char *url, const char *host) +{ + char **server; + char *proto, *cur; + + if (servers == NULL) + goto direct; + + DBG(" "); + + __pacrunner_manual_parse_uri(url, NULL, &proto, 0, 0); + + if (is_url_excluded(excludes, host, proto) != 0) + goto direct; + + switch (context) { + case PACRUNNER_PROXY_MANUAL_GENERIC: + /* We return - for now - first server entry */ + return servers[0]; + case PACRUNNER_PROXY_MANUAL_PROTOCOL_BASED: + if (proto == NULL) + break; + + for (server = servers; *server != NULL; server++) { + cur = strstr(*server, proto); + if (cur != NULL) + if (cur == *server) + return *server; + } + + break; + } + +direct: + return "DIRECT"; +} diff --git a/src/pacrunner.h b/src/pacrunner.h index 6439908..9b5a4df 100644 --- a/src/pacrunner.h +++ b/src/pacrunner.h @@ -108,3 +108,7 @@ int __pacrunner_manual_parse_uri(const char *uri, char **host, char **protocol, int no_path, int exclusion); void __pacrunner_manual_free_excludes(struct pacrunner_manual_excludes *excludes); struct pacrunner_manual_excludes *__pacrunner_manual_create_excludes(const char *excludes); +const char *__pacrunner_manual_execute( + enum pacrunner_proxy_manual_context context, + struct pacrunner_manual_excludes *excludes, + char **servers, const char *url, const char *host); diff --git a/src/proxy.c b/src/proxy.c index 391fa9f..36581d6 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -294,9 +294,6 @@ int pacrunner_proxy_set_manual(struct pacrunner_proxy *proxy, proxy->excludes = __pacrunner_manual_create_excludes(excludes); - g_free(proxy->result); - proxy->result = g_strdup(proxy->servers[0]); - pacrunner_proxy_enable(proxy); DBG("servers = %d - context %d, excludes %p", @@ -392,9 +389,10 @@ const char *pacrunner_proxy_lookup(const char *url, const char *host) case PACRUNNER_PROXY_METHOD_DIRECT: break; case PACRUNNER_PROXY_METHOD_MANUAL: - if (selected_proxy->result == NULL) - break; - return selected_proxy->result; + return __pacrunner_manual_execute(selected_proxy->context, + selected_proxy->excludes, + selected_proxy->servers, + url, host); case PACRUNNER_PROXY_METHOD_AUTO: return __pacrunner_mozjs_execute(url, host); } -- 1.7.1 _______________________________________________ connman mailing list connman@connman.net http://lists.connman.net/listinfo/connman