diff options
author | Thomas Haller <thaller@redhat.com> | 2016-08-19 10:24:59 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2016-10-04 11:44:44 +0200 |
commit | ac8bf57f1b097989c34b7805317efcdef17894d0 (patch) | |
tree | d99e042152c58e9296a66acf3cf67ade53eb6b3c /src/nm-pacrunner-manager.c | |
parent | 931871995c63f008fbd9bb8fa57ce0803ae293ae (diff) | |
download | NetworkManager-ac8bf57f1b097989c34b7805317efcdef17894d0.tar.gz |
proxy: refactor NMProxyConfig to keep internal variables as strv
The API of NMProxyConfig exposes @proxies and @excludes as strv values.
There is no need to track those values internally as a GPtrArray and
then clone them in the getters (especially, since the entire NMProxyConfig
API is internal to core.
Thereby, fix a few memory leaks in add_proxy_config() and some
style fixes for { }.
Diffstat (limited to 'src/nm-pacrunner-manager.c')
-rw-r--r-- | src/nm-pacrunner-manager.c | 47 |
1 files changed, 22 insertions, 25 deletions
diff --git a/src/nm-pacrunner-manager.c b/src/nm-pacrunner-manager.c index 526408c541..d401e03afa 100644 --- a/src/nm-pacrunner-manager.c +++ b/src/nm-pacrunner-manager.c @@ -101,53 +101,50 @@ remove_data_destroy (struct remove_data *data) static void add_proxy_config (NMPacRunnerManager *self, GVariantBuilder *proxy_data, const NMProxyConfig *proxy_config) { - const char *pac = NULL, *filename = NULL; - char **servers = NULL, **excludes = NULL; - char *contents = NULL; + const char *pac_url, *pac_script; + const char *const*proxies; + const char *const*excludes; NMProxyConfigMethod method; method = nm_proxy_config_get_method (proxy_config); switch (method) { case NM_PROXY_CONFIG_METHOD_AUTO: - /* Extract Pac Url */ - pac = nm_proxy_config_get_pac_url (proxy_config); - if (pac) + pac_url = nm_proxy_config_get_pac_url (proxy_config); + if (pac_url) { g_variant_builder_add (proxy_data, "{sv}", "URL", - g_variant_new_string (pac)); + g_variant_new_string (pac_url)); + } + + pac_script = nm_proxy_config_get_pac_script (proxy_config); + if (pac_script) { + char *contents; - /* Extract Pac Script */ - filename = nm_proxy_config_get_pac_script (proxy_config); - if (filename) - if (g_file_get_contents (filename, &contents, NULL, NULL)) + if (g_file_get_contents (pac_script, &contents, NULL, NULL)) { g_variant_builder_add (proxy_data, "{sv}", "Script", - g_variant_new_string (contents)); + g_variant_new_take_string (contents)); + } + } break; case NM_PROXY_CONFIG_METHOD_MANUAL: - /* Extract Proxy servers */ - servers = nm_proxy_config_get_proxies (proxy_config); - if (servers && g_strv_length (servers)) + proxies = nm_proxy_config_get_proxies (proxy_config); + if (proxies && proxies[0]) { g_variant_builder_add (proxy_data, "{sv}", "Servers", - g_variant_new_strv ((const char *const *) servers, -1)); + g_variant_new_strv (proxies, -1)); + } - /* Extract Excludes */ excludes = nm_proxy_config_get_excludes (proxy_config); - if (excludes && g_strv_length (excludes)) + if (excludes && excludes[0]) { g_variant_builder_add (proxy_data, "{sv}", "Excludes", - g_variant_new_strv ((const char *const *) excludes, -1)); - - if (servers) - g_strfreev (servers); - if (excludes) - g_strfreev (excludes); + g_variant_new_strv (excludes, -1)); + } break; case NM_PROXY_CONFIG_METHOD_NONE: - /* Do Nothing */ break; } |