Mercurial > pidgin.yaz
diff libpurple/proxy.c @ 25635:efaecb71baad
propagate from branch 'im.pidgin.pidgin' (head 8ca6a80e2cd7fbbc59983f8ba370f7276e062db9)
to branch 'im.pidgin.pidgin.vv' (head 3ed39e8792f4a2e92ef5a3c7f4fb14251c9dae11)
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Sat, 15 Mar 2008 07:39:15 +0000 |
parents | 04b807c8b98d |
children | 3225c99785b8 |
line wrap: on
line diff
--- a/libpurple/proxy.c Sat Mar 15 07:37:03 2008 +0000 +++ b/libpurple/proxy.c Sat Mar 15 07:39:15 2008 +0000 @@ -211,67 +211,92 @@ purple_gnome_proxy_get_info(void) { static PurpleProxyInfo info = {0, NULL, 0, NULL, NULL}; - gchar *path; - if ((path = g_find_program_in_path("gconftool-2"))) { - gchar *tmp; - - g_free(path); + gchar *tmp; - /* See whether to use a proxy. */ - if (!g_spawn_command_line_sync("gconftool-2 -g /system/proxy/mode", &tmp, - NULL, NULL, NULL)) - return purple_global_proxy_get_info(); - if (!strcmp(tmp, "none\n")) { - info.type = PURPLE_PROXY_NONE; - g_free(tmp); - return &info; - } else if (strcmp(tmp, "manual\n")) { - g_free(tmp); - return purple_global_proxy_get_info(); - } + tmp = g_find_program_in_path("gconftool-2"); + if (tmp == NULL) + return purple_global_proxy_get_info(); - g_free(tmp); - info.type = PURPLE_PROXY_HTTP; + g_free(tmp); - /* Free the old fields */ - if (info.host) { - g_free(info.host); - info.host = NULL; - } - if (info.username) { - g_free(info.username); - info.username = NULL; - } - if (info.password) { - g_free(info.password); - info.password = NULL; - } + /* Check whether to use a proxy. */ + if (!g_spawn_command_line_sync("gconftool-2 -g /system/proxy/mode", + &tmp, NULL, NULL, NULL)) + return purple_global_proxy_get_info(); - /* Get the new ones */ - if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/host", &info.host, - NULL, NULL, NULL)) - return purple_global_proxy_get_info(); - g_strchomp(info.host); - - if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/authentication_user", &info.username, - NULL, NULL, NULL)) - return purple_global_proxy_get_info(); - g_strchomp(info.username); - - if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/authentication_password", &info.password, - NULL, NULL, NULL)) - return purple_global_proxy_get_info(); - g_strchomp(info.password); - - if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/port", &tmp, - NULL, NULL, NULL)) - return purple_global_proxy_get_info(); - info.port = atoi(tmp); + if (!strcmp(tmp, "none\n")) { + info.type = PURPLE_PROXY_NONE; g_free(tmp); - return &info; } - return purple_global_proxy_get_info(); + + if (strcmp(tmp, "manual\n")) { + /* Unknown setting. Fallback to using our global proxy settings. */ + g_free(tmp); + return purple_global_proxy_get_info(); + } + + g_free(tmp); + + /* If we get this far then we know we're using an HTTP proxy */ + info.type = PURPLE_PROXY_HTTP; + + /* Free the old fields */ + if (info.host) { + g_free(info.host); + info.host = NULL; + } + if (info.username) { + g_free(info.username); + info.username = NULL; + } + if (info.password) { + g_free(info.password); + info.password = NULL; + } + + if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/host", + &info.host, NULL, NULL, NULL)) + return purple_global_proxy_get_info(); + g_strchomp(info.host); + if (*info.host == '\0') + { + purple_debug_info("proxy", "Gnome proxy settings are set to " + "'manual' but no proxy server is specified. Using " + "Pidgin's proxy settings instead.\n"); + g_free(info.host); + return purple_global_proxy_get_info(); + } + + if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/authentication_user", + &info.username, NULL, NULL, NULL)) + { + g_free(info.host); + return purple_global_proxy_get_info(); + } + g_strchomp(info.username); + + if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/authentication_password", + &info.password, NULL, NULL, NULL)) + { + g_free(info.host); + g_free(info.username); + return purple_global_proxy_get_info(); + } + g_strchomp(info.password); + + if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/port", + &tmp, NULL, NULL, NULL)) + { + g_free(info.host); + g_free(info.username); + g_free(info.password); + return purple_global_proxy_get_info(); + } + info.port = atoi(tmp); + g_free(tmp); + + return &info; } /************************************************************************** * Proxy API @@ -737,6 +762,7 @@ proxy_do_write(connect_data, connect_data->fd, cond); return; } else if((ntlm = g_strrstr((const char *)connect_data->read_buffer, "Proxy-Authenticate: NTLM"))) { /* Empty message */ + gchar *ntlm_type1; gchar request[2048]; gchar *domain = (gchar*) purple_proxy_info_get_username(connect_data->gpi); gchar *username = NULL; @@ -759,11 +785,13 @@ connect_data->host, connect_data->port); g_return_if_fail(request_len < sizeof(request)); + ntlm_type1 = purple_ntlm_gen_type1(hostname, domain); request_len += g_snprintf(request + request_len, sizeof(request) - request_len, "Proxy-Authorization: NTLM %s\r\n" "Proxy-Connection: Keep-Alive\r\n\r\n", - purple_ntlm_gen_type1(hostname, domain)); + ntlm_type1); + g_free(ntlm_type1); *username = '\\'; purple_input_remove(connect_data->inpa); @@ -847,7 +875,7 @@ if (purple_proxy_info_get_username(connect_data->gpi) != NULL) { - char *t1, *t2; + char *t1, *t2, *ntlm_type1; char hostname[256]; ret = gethostname(hostname, sizeof(hostname)); @@ -864,11 +892,14 @@ t2 = purple_base64_encode((const guchar *)t1, strlen(t1)); g_free(t1); + ntlm_type1 = purple_ntlm_gen_type1(hostname, ""); + g_string_append_printf(request, "Proxy-Authorization: Basic %s\r\n" "Proxy-Authorization: NTLM %s\r\n" "Proxy-Connection: Keep-Alive\r\n", - t2, purple_ntlm_gen_type1(hostname, "")); + t2, ntlm_type1); + g_free(ntlm_type1); g_free(t2); }