Mercurial > pidgin
changeset 32819:2c6510167895 default tip
propagate from branch 'im.pidgin.pidgin.2.x.y' (head 3315c5dfbd0ad16511bdcf865e5b07c02d07df24)
to branch 'im.pidgin.pidgin' (head cbd1eda6bcbf0565ae7766396bb8f6f419cb6a9a)
author | Elliott Sales de Andrade <qulogic@pidgin.im> |
---|---|
date | Sat, 02 Jun 2012 02:30:49 +0000 |
parents | 01ff09d4a463 (diff) 071a0e568ac5 (current diff) |
children | |
files | COPYRIGHT ChangeLog gaim-uninstalled.pc.in gaim.pc.in libpurple/gaim-compat.h libpurple/protocols/msn/contact.c libpurple/protocols/silc10/Makefile.am libpurple/protocols/silc10/Makefile.mingw libpurple/protocols/silc10/README libpurple/protocols/silc10/TODO libpurple/protocols/silc10/buddy.c libpurple/protocols/silc10/chat.c libpurple/protocols/silc10/ft.c libpurple/protocols/silc10/ops.c libpurple/protocols/silc10/pk.c libpurple/protocols/silc10/silc.c libpurple/protocols/silc10/silcpurple.h libpurple/protocols/silc10/util.c libpurple/protocols/silc10/wb.c libpurple/protocols/silc10/wb.h libpurple/proxy.c libpurple/purple-2-uninstalled.pc.in libpurple/purple-2.pc.in libpurple/purple-uninstalled.pc.in libpurple/purple.pc.in pidgin/gtkdocklet-gtk.c pidgin/gtkgaim-compat.h pidgin/pidgin-2-uninstalled.pc.in pidgin/pidgin-2.pc.in pidgin/pidgin-uninstalled.pc.in pidgin/pidgin.pc.in |
diffstat | 3 files changed, 99 insertions(+), 50 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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)
--- 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); }