Mercurial > pidgin.yaz
comparison 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 |
comparison
equal
deleted
inserted
replaced
25634:741a702033e0 | 25635:efaecb71baad |
---|---|
209 | 209 |
210 static PurpleProxyInfo * | 210 static PurpleProxyInfo * |
211 purple_gnome_proxy_get_info(void) | 211 purple_gnome_proxy_get_info(void) |
212 { | 212 { |
213 static PurpleProxyInfo info = {0, NULL, 0, NULL, NULL}; | 213 static PurpleProxyInfo info = {0, NULL, 0, NULL, NULL}; |
214 gchar *path; | 214 gchar *tmp; |
215 if ((path = g_find_program_in_path("gconftool-2"))) { | 215 |
216 gchar *tmp; | 216 tmp = g_find_program_in_path("gconftool-2"); |
217 | 217 if (tmp == NULL) |
218 g_free(path); | 218 return purple_global_proxy_get_info(); |
219 | 219 |
220 /* See whether to use a proxy. */ | 220 g_free(tmp); |
221 if (!g_spawn_command_line_sync("gconftool-2 -g /system/proxy/mode", &tmp, | 221 |
222 NULL, NULL, NULL)) | 222 /* Check whether to use a proxy. */ |
223 return purple_global_proxy_get_info(); | 223 if (!g_spawn_command_line_sync("gconftool-2 -g /system/proxy/mode", |
224 if (!strcmp(tmp, "none\n")) { | 224 &tmp, NULL, NULL, NULL)) |
225 info.type = PURPLE_PROXY_NONE; | 225 return purple_global_proxy_get_info(); |
226 g_free(tmp); | 226 |
227 return &info; | 227 if (!strcmp(tmp, "none\n")) { |
228 } else if (strcmp(tmp, "manual\n")) { | 228 info.type = PURPLE_PROXY_NONE; |
229 g_free(tmp); | |
230 return purple_global_proxy_get_info(); | |
231 } | |
232 | |
233 g_free(tmp); | 229 g_free(tmp); |
234 info.type = PURPLE_PROXY_HTTP; | 230 return &info; |
235 | 231 } |
236 /* Free the old fields */ | 232 |
237 if (info.host) { | 233 if (strcmp(tmp, "manual\n")) { |
238 g_free(info.host); | 234 /* Unknown setting. Fallback to using our global proxy settings. */ |
239 info.host = NULL; | |
240 } | |
241 if (info.username) { | |
242 g_free(info.username); | |
243 info.username = NULL; | |
244 } | |
245 if (info.password) { | |
246 g_free(info.password); | |
247 info.password = NULL; | |
248 } | |
249 | |
250 /* Get the new ones */ | |
251 if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/host", &info.host, | |
252 NULL, NULL, NULL)) | |
253 return purple_global_proxy_get_info(); | |
254 g_strchomp(info.host); | |
255 | |
256 if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/authentication_user", &info.username, | |
257 NULL, NULL, NULL)) | |
258 return purple_global_proxy_get_info(); | |
259 g_strchomp(info.username); | |
260 | |
261 if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/authentication_password", &info.password, | |
262 NULL, NULL, NULL)) | |
263 return purple_global_proxy_get_info(); | |
264 g_strchomp(info.password); | |
265 | |
266 if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/port", &tmp, | |
267 NULL, NULL, NULL)) | |
268 return purple_global_proxy_get_info(); | |
269 info.port = atoi(tmp); | |
270 g_free(tmp); | 235 g_free(tmp); |
271 | 236 return purple_global_proxy_get_info(); |
272 return &info; | 237 } |
273 } | 238 |
274 return purple_global_proxy_get_info(); | 239 g_free(tmp); |
240 | |
241 /* If we get this far then we know we're using an HTTP proxy */ | |
242 info.type = PURPLE_PROXY_HTTP; | |
243 | |
244 /* Free the old fields */ | |
245 if (info.host) { | |
246 g_free(info.host); | |
247 info.host = NULL; | |
248 } | |
249 if (info.username) { | |
250 g_free(info.username); | |
251 info.username = NULL; | |
252 } | |
253 if (info.password) { | |
254 g_free(info.password); | |
255 info.password = NULL; | |
256 } | |
257 | |
258 if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/host", | |
259 &info.host, NULL, NULL, NULL)) | |
260 return purple_global_proxy_get_info(); | |
261 g_strchomp(info.host); | |
262 if (*info.host == '\0') | |
263 { | |
264 purple_debug_info("proxy", "Gnome proxy settings are set to " | |
265 "'manual' but no proxy server is specified. Using " | |
266 "Pidgin's proxy settings instead.\n"); | |
267 g_free(info.host); | |
268 return purple_global_proxy_get_info(); | |
269 } | |
270 | |
271 if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/authentication_user", | |
272 &info.username, NULL, NULL, NULL)) | |
273 { | |
274 g_free(info.host); | |
275 return purple_global_proxy_get_info(); | |
276 } | |
277 g_strchomp(info.username); | |
278 | |
279 if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/authentication_password", | |
280 &info.password, NULL, NULL, NULL)) | |
281 { | |
282 g_free(info.host); | |
283 g_free(info.username); | |
284 return purple_global_proxy_get_info(); | |
285 } | |
286 g_strchomp(info.password); | |
287 | |
288 if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/port", | |
289 &tmp, NULL, NULL, NULL)) | |
290 { | |
291 g_free(info.host); | |
292 g_free(info.username); | |
293 g_free(info.password); | |
294 return purple_global_proxy_get_info(); | |
295 } | |
296 info.port = atoi(tmp); | |
297 g_free(tmp); | |
298 | |
299 return &info; | |
275 } | 300 } |
276 /************************************************************************** | 301 /************************************************************************** |
277 * Proxy API | 302 * Proxy API |
278 **************************************************************************/ | 303 **************************************************************************/ |
279 | 304 |
735 connect_data->inpa = purple_input_add(connect_data->fd, | 760 connect_data->inpa = purple_input_add(connect_data->fd, |
736 PURPLE_INPUT_WRITE, proxy_do_write, connect_data); | 761 PURPLE_INPUT_WRITE, proxy_do_write, connect_data); |
737 proxy_do_write(connect_data, connect_data->fd, cond); | 762 proxy_do_write(connect_data, connect_data->fd, cond); |
738 return; | 763 return; |
739 } else if((ntlm = g_strrstr((const char *)connect_data->read_buffer, "Proxy-Authenticate: NTLM"))) { /* Empty message */ | 764 } else if((ntlm = g_strrstr((const char *)connect_data->read_buffer, "Proxy-Authenticate: NTLM"))) { /* Empty message */ |
765 gchar *ntlm_type1; | |
740 gchar request[2048]; | 766 gchar request[2048]; |
741 gchar *domain = (gchar*) purple_proxy_info_get_username(connect_data->gpi); | 767 gchar *domain = (gchar*) purple_proxy_info_get_username(connect_data->gpi); |
742 gchar *username = NULL; | 768 gchar *username = NULL; |
743 int request_len; | 769 int request_len; |
744 | 770 |
757 "Host: %s:%d\r\n", | 783 "Host: %s:%d\r\n", |
758 connect_data->host, connect_data->port, | 784 connect_data->host, connect_data->port, |
759 connect_data->host, connect_data->port); | 785 connect_data->host, connect_data->port); |
760 | 786 |
761 g_return_if_fail(request_len < sizeof(request)); | 787 g_return_if_fail(request_len < sizeof(request)); |
788 ntlm_type1 = purple_ntlm_gen_type1(hostname, domain); | |
762 request_len += g_snprintf(request + request_len, | 789 request_len += g_snprintf(request + request_len, |
763 sizeof(request) - request_len, | 790 sizeof(request) - request_len, |
764 "Proxy-Authorization: NTLM %s\r\n" | 791 "Proxy-Authorization: NTLM %s\r\n" |
765 "Proxy-Connection: Keep-Alive\r\n\r\n", | 792 "Proxy-Connection: Keep-Alive\r\n\r\n", |
766 purple_ntlm_gen_type1(hostname, domain)); | 793 ntlm_type1); |
794 g_free(ntlm_type1); | |
767 *username = '\\'; | 795 *username = '\\'; |
768 | 796 |
769 purple_input_remove(connect_data->inpa); | 797 purple_input_remove(connect_data->inpa); |
770 g_free(connect_data->read_buffer); | 798 g_free(connect_data->read_buffer); |
771 connect_data->read_buffer = NULL; | 799 connect_data->read_buffer = NULL; |
845 connect_data->host, connect_data->port, | 873 connect_data->host, connect_data->port, |
846 connect_data->host, connect_data->port); | 874 connect_data->host, connect_data->port); |
847 | 875 |
848 if (purple_proxy_info_get_username(connect_data->gpi) != NULL) | 876 if (purple_proxy_info_get_username(connect_data->gpi) != NULL) |
849 { | 877 { |
850 char *t1, *t2; | 878 char *t1, *t2, *ntlm_type1; |
851 char hostname[256]; | 879 char hostname[256]; |
852 | 880 |
853 ret = gethostname(hostname, sizeof(hostname)); | 881 ret = gethostname(hostname, sizeof(hostname)); |
854 hostname[sizeof(hostname) - 1] = '\0'; | 882 hostname[sizeof(hostname) - 1] = '\0'; |
855 if (ret < 0 || hostname[0] == '\0') { | 883 if (ret < 0 || hostname[0] == '\0') { |
862 purple_proxy_info_get_password(connect_data->gpi) ? | 890 purple_proxy_info_get_password(connect_data->gpi) ? |
863 purple_proxy_info_get_password(connect_data->gpi) : ""); | 891 purple_proxy_info_get_password(connect_data->gpi) : ""); |
864 t2 = purple_base64_encode((const guchar *)t1, strlen(t1)); | 892 t2 = purple_base64_encode((const guchar *)t1, strlen(t1)); |
865 g_free(t1); | 893 g_free(t1); |
866 | 894 |
895 ntlm_type1 = purple_ntlm_gen_type1(hostname, ""); | |
896 | |
867 g_string_append_printf(request, | 897 g_string_append_printf(request, |
868 "Proxy-Authorization: Basic %s\r\n" | 898 "Proxy-Authorization: Basic %s\r\n" |
869 "Proxy-Authorization: NTLM %s\r\n" | 899 "Proxy-Authorization: NTLM %s\r\n" |
870 "Proxy-Connection: Keep-Alive\r\n", | 900 "Proxy-Connection: Keep-Alive\r\n", |
871 t2, purple_ntlm_gen_type1(hostname, "")); | 901 t2, ntlm_type1); |
902 g_free(ntlm_type1); | |
872 g_free(t2); | 903 g_free(t2); |
873 } | 904 } |
874 | 905 |
875 g_string_append(request, "\r\n"); | 906 g_string_append(request, "\r\n"); |
876 | 907 |