From 67ca168f6f6adefb41cc5ca3d7b4e1d857522e33 Mon Sep 17 00:00:00 2001 From: Leif Middelschulte Date: Tue, 26 Sep 2017 12:26:18 -0400 Subject: [PATCH] support proxy settings provided by Connman. Summary: This implements support for Connman's proxy configuration. The 'all_proxy', 'http_proxy', 'https_proxy' environment variables are set to the first value of the 'proxy_servers' set. The 'no_proxy' environment variable is set to a concatenated string of all the 'proxy_exclude' values. Reviewers: zmike! Subscribers: cedric Maniphest Tasks: T5442 Differential Revision: https://phab.enlightenment.org/D4833 modified by zmike --- src/modules/connman/e_connman.c | 87 +++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/src/modules/connman/e_connman.c b/src/modules/connman/e_connman.c index fb6fcf959..464a578c2 100644 --- a/src/modules/connman/e_connman.c +++ b/src/modules/connman/e_connman.c @@ -196,6 +196,93 @@ static void _service_parse_prop_changed(struct Connman_Service *cs, _dbus_str_array_to_eina(value, &cs->security, 2); DBG("New security count: %d", eina_array_count(cs->security)); } + else if (strcmp(prop_name, "Proxy") == 0) + { + Eldbus_Message_Iter* proxy_dict = NULL; + const char* method = "direct"; + Eina_Array *proxy_servers = NULL, *proxy_excludes = NULL; + Eldbus_Message_Iter* proxy_dict_entry = NULL; + + // 'Proxy': {'Excludes': [], 'Method': 'manual', 'Servers': []} + if (!eldbus_message_iter_arguments_get(value, "a{sv}", &proxy_dict)) + { + ERR("Error getting arguments."); + return; + } + + while (eldbus_message_iter_get_and_next(proxy_dict, 'e', + &proxy_dict_entry)) + { + Eldbus_Message_Iter* proxy_dict_entry_val = NULL; + char* proxy_dict_entry_key = NULL; + if (!eldbus_message_iter_arguments_get(proxy_dict_entry, "sv", + &proxy_dict_entry_key, + &proxy_dict_entry_val)) + continue; + if (strcmp(proxy_dict_entry_key, "Excludes") == 0) + { + _dbus_str_array_to_eina(proxy_dict_entry_val, &proxy_excludes, 4); + } + else if (strcmp(proxy_dict_entry_key, "Method") == 0) + { + EINA_SAFETY_ON_FALSE_RETURN(eldbus_message_iter_arguments_get( + proxy_dict_entry_val, "s", &method)); + } + else if (strcmp(proxy_dict_entry_key, "Servers") == 0) + { + _dbus_str_array_to_eina(proxy_dict_entry_val, &proxy_servers, 4); + } + } + + if (strcmp(method, "manual") == 0) + { + if (eina_array_count(proxy_servers) > 0) + { + DBG("New {all,http{,s}}_proxy: %s", + (const char*)eina_array_data_get(proxy_servers, 0)); + e_env_set("all_proxy", eina_array_data_get(proxy_servers, 0)); + e_env_set("http_proxy", eina_array_data_get(proxy_servers, 0)); + e_env_set("https_proxy", eina_array_data_get(proxy_servers, 0)); + } + if (eina_array_count(proxy_excludes) > 0) + { + char buf[256], concatinated_proxy_exceptions[256]; + size_t concatinated_string_length; + concatinated_proxy_exceptions[0] = '\0'; + for (unsigned int i = 0; i < eina_array_count(proxy_excludes); i++) + { + snprintf(buf, (sizeof(buf) - 1), "%s ", + (const char*)eina_array_data_get(proxy_excludes, i)); + concatinated_string_length = eina_strlcat(concatinated_proxy_exceptions, buf, + sizeof(concatinated_proxy_exceptions)); + } + if ((concatinated_string_length < sizeof(concatinated_proxy_exceptions)) && (concatinated_string_length > 0)) + { + concatinated_proxy_exceptions[concatinated_string_length - 1] = '\0'; + } + DBG("New no_proxy: %s", (const char*)concatinated_proxy_exceptions); + e_env_set("no_proxy", concatinated_proxy_exceptions); + } + } + else if (strcmp(method, "direct") == 0) + { + e_env_unset("all_proxy"); + e_env_unset("http_proxy"); + e_env_unset("https_proxy"); + e_env_unset("no_proxy"); + } + + if (proxy_excludes) + { + _eina_str_array_clean(proxy_excludes); + eina_array_free(proxy_excludes); + } + if (proxy_servers) + { + _eina_str_array_clean(proxy_servers); + eina_array_free(proxy_servers); + } + } } static void _service_prop_dict_changed(struct Connman_Service *cs,