# HG changeset patch # User Elliott Sales de Andrade # Date 1338604249 0 # Node ID 2c6510167895c7d60e2ab650e2b48556f3532630 # Parent 01ff09d4a463577b4cfa3234c46b347932a627ef# Parent 071a0e568ac5d69101bd1957a17e0926325a0f94 propagate from branch 'im.pidgin.pidgin.2.x.y' (head 3315c5dfbd0ad16511bdcf865e5b07c02d07df24) to branch 'im.pidgin.pidgin' (head cbd1eda6bcbf0565ae7766396bb8f6f419cb6a9a) diff -r 071a0e568ac5 -r 2c6510167895 COPYRIGHT --- a/COPYRIGHT Thu May 31 06:20:22 2012 +0000 +++ b/COPYRIGHT Sat Jun 02 02:30:49 2012 +0000 @@ -478,6 +478,7 @@ Torrey Searle Peter Seebach Don Seiler +Mihai Serban Leonardo Serra Matteo Settenvini Colin Seymour diff -r 071a0e568ac5 -r 2c6510167895 ChangeLog --- a/ChangeLog Thu May 31 06:20:22 2012 +0000 +++ b/ChangeLog Sat Jun 02 02:30:49 2012 +0000 @@ -48,6 +48,9 @@ was an offline message. (Flavius Anton) (#2497) version 2.10.5: + libpurple: + * Add support for GNOME3 proxy settings. (Mihai Serban) (#15054) + Pidgin: * Fix a crash that may occur when trying to ignore a user who is not in the current chat room. (#15139) diff -r 071a0e568ac5 -r 2c6510167895 libpurple/protocols/msn/contact.c diff -r 071a0e568ac5 -r 2c6510167895 libpurple/proxy.c --- a/libpurple/proxy.c Thu May 31 06:20:22 2012 +0000 +++ b/libpurple/proxy.c Sat Jun 02 02:30:49 2012 +0000 @@ -232,41 +232,105 @@ global_proxy_info = info; } + +/* index in gproxycmds below, keep them in sync */ +#define GNOME_PROXY_MODE 0 +#define GNOME_PROXY_USE_SAME_PROXY 1 +#define GNOME_PROXY_SOCKS_HOST 2 +#define GNOME_PROXY_SOCKS_PORT 3 +#define GNOME_PROXY_HTTP_HOST 4 +#define GNOME_PROXY_HTTP_PORT 5 +#define GNOME_PROXY_HTTP_USER 6 +#define GNOME_PROXY_HTTP_PASS 7 +#define GNOME2_CMDS 0 +#define GNOME3_CMDS 1 + +/* detect proxy settings for gnome2/gnome3 */ +static const char* gproxycmds[][2] = { + { "gconftool-2 -g /system/proxy/mode" , "gsettings get org.gnome.system.proxy mode" }, + { "gconftool-2 -g /system/http_proxy/use_same_proxy", "gsettings get org.gnome.system.proxy use-same-proxy" }, + { "gconftool-2 -g /system/proxy/socks_host", "gsettings get org.gnome.system.proxy.socks host" }, + { "gconftool-2 -g /system/proxy/socks_port", "gsettings get org.gnome.system.proxy.socks port" }, + { "gconftool-2 -g /system/http_proxy/host", "gsettings get org.gnome.system.proxy.http host" }, + { "gconftool-2 -g /system/http_proxy/port", "gsettings get org.gnome.system.proxy.http port"}, + { "gconftool-2 -g /system/http_proxy/authentication_user", "gsettings get org.gnome.system.proxy.http authentication-user" }, + { "gconftool-2 -g /system/http_proxy/authentication_password", "gsettings get org.gnome.system.proxy.http authentication-password" }, +}; + +/** + * This is a utility function used to retrieve proxy parameter values from + * GNOME 2/3 environment. + * + * @param parameter One of the GNOME_PROXY_x constants defined above + * @param gnome_version GNOME2_CMDS or GNOME3_CMDS + * + * @return The value of requested proxy parameter + */ +static char * +purple_gnome_proxy_get_parameter(guint8 parameter, guint8 gnome_version) +{ + gchar *param, *err; + size_t param_len; + + if (parameter > GNOME_PROXY_HTTP_PASS) + return NULL; + if (gnome_version > GNOME3_CMDS) + return NULL; + + if (!g_spawn_command_line_sync(gproxycmds[parameter][gnome_version], + ¶m, &err, NULL, NULL)) + return NULL; + g_free(err); + + g_strstrip(param); + if (param[0] == '\'' || param[0] == '\"') { + param_len = strlen(param); + memmove(param, param + 1, param_len); /* copy last \0 too */ + --param_len; + if (param_len > 0 && (param[param_len - 1] == '\'' || param[param_len - 1] == '\"')) + param[param_len - 1] = '\0'; + g_strstrip(param); + } + + return param; +} + static PurpleProxyInfo * purple_gnome_proxy_get_info(void) { static PurpleProxyInfo info = {0, NULL, 0, NULL, NULL}; gboolean use_same_proxy = FALSE; - gchar *tmp, *err = NULL; - - tmp = g_find_program_in_path("gconftool-2"); + gchar *tmp; + guint8 gnome_version = GNOME3_CMDS; + + tmp = g_find_program_in_path("gsettings"); + if (tmp == NULL) { + tmp = g_find_program_in_path("gconftool-2"); + gnome_version = GNOME2_CMDS; + } if (tmp == NULL) return purple_global_proxy_get_info(); g_free(tmp); - tmp = NULL; /* Check whether to use a proxy. */ - if (!g_spawn_command_line_sync("gconftool-2 -g /system/proxy/mode", - &tmp, &err, NULL, NULL)) + tmp = purple_gnome_proxy_get_parameter(GNOME_PROXY_MODE, gnome_version); + if (!tmp) return purple_global_proxy_get_info(); - g_free(err); - err = NULL; - - if (purple_strequal(tmp, "none\n")) { + + if (purple_strequal(tmp, "none")) { info.type = PURPLE_PROXY_NONE; g_free(tmp); return &info; } - if (!purple_strequal(tmp, "manual\n")) { + if (!purple_strequal(tmp, "manual")) { /* Unknown setting. Fallback to using our global proxy settings. */ g_free(tmp); return purple_global_proxy_get_info(); } g_free(tmp); - tmp = NULL; /* Free the old fields */ if (info.host) { @@ -282,52 +346,40 @@ info.password = NULL; } - if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/use_same_proxy", - &tmp, &err, NULL, NULL)) + tmp = purple_gnome_proxy_get_parameter(GNOME_PROXY_USE_SAME_PROXY, gnome_version); + if (!tmp) return purple_global_proxy_get_info(); - g_free(err); - err = NULL; - - if (purple_strequal(tmp, "true\n")) + + if (purple_strequal(tmp, "true")) use_same_proxy = TRUE; + g_free(tmp); - tmp = NULL; if (!use_same_proxy) { - if (!g_spawn_command_line_sync("gconftool-2 -g /system/proxy/socks_host", - &info.host, &err, NULL, NULL)) + info.host = purple_gnome_proxy_get_parameter(GNOME_PROXY_SOCKS_HOST, gnome_version); + if (!info.host) return purple_global_proxy_get_info(); - g_free(err); - err = NULL; } - if(info.host != NULL) - g_strchomp(info.host); - if (!use_same_proxy && (info.host != NULL) && (*info.host != '\0')) { info.type = PURPLE_PROXY_SOCKS5; - if (!g_spawn_command_line_sync("gconftool-2 -g /system/proxy/socks_port", - &tmp, &err, NULL, NULL)) - { + tmp = purple_gnome_proxy_get_parameter(GNOME_PROXY_SOCKS_PORT, gnome_version); + if (!tmp) { g_free(info.host); info.host = NULL; return purple_global_proxy_get_info(); } - g_free(err); info.port = atoi(tmp); g_free(tmp); } else { g_free(info.host); - if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/host", - &info.host, &err, NULL, NULL)) + info.host = purple_gnome_proxy_get_parameter(GNOME_PROXY_HTTP_HOST, gnome_version); + if (!info.host) return purple_global_proxy_get_info(); - g_free(err); - err = NULL; /* If we get this far then we know we're using an HTTP proxy */ info.type = PURPLE_PROXY_HTTP; - g_strchomp(info.host); if (*info.host == '\0') { purple_debug_info("proxy", "Gnome proxy settings are set to " @@ -338,19 +390,16 @@ return purple_global_proxy_get_info(); } - if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/authentication_user", - &info.username, &err, NULL, NULL)) + info.username = purple_gnome_proxy_get_parameter(GNOME_PROXY_HTTP_USER, gnome_version); + if (!info.username) { g_free(info.host); info.host = NULL; return purple_global_proxy_get_info(); } - g_free(err); - err = NULL; - g_strchomp(info.username); - - if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/authentication_password", - &info.password, &err, NULL, NULL)) + + info.password = purple_gnome_proxy_get_parameter(GNOME_PROXY_HTTP_PASS, gnome_version); + if (!info.password) { g_free(info.host); info.host = NULL; @@ -358,12 +407,9 @@ info.username = NULL; return purple_global_proxy_get_info(); } - g_free(err); - err = NULL; - g_strchomp(info.password); - - if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/port", - &tmp, &err, NULL, NULL)) + + tmp = purple_gnome_proxy_get_parameter(GNOME_PROXY_HTTP_PORT, gnome_version); + if (!tmp) { g_free(info.host); info.host = NULL; @@ -373,7 +419,6 @@ info.password = NULL; return purple_global_proxy_get_info(); } - g_free(err); info.port = atoi(tmp); g_free(tmp); }