Mercurial > pidgin
comparison libpurple/proxy.c @ 23970:54eb782d4721
Add support for reading SOCKS proxy information from the Windows proxy settings.
Fixes #1614
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Tue, 26 Aug 2008 04:36:29 +0000 |
parents | 64585aab233a |
children | 4a1bbe955690 |
comparison
equal
deleted
inserted
replaced
23969:4ecea8ae3d21 | 23970:54eb782d4721 |
---|---|
345 g_free(tmp); | 345 g_free(tmp); |
346 } | 346 } |
347 | 347 |
348 return &info; | 348 return &info; |
349 } | 349 } |
350 | |
351 #ifdef _WIN32 | |
352 | |
353 typedef BOOL (CALLBACK* LPFNWINHTTPGETIEPROXYCONFIG)(/*IN OUT*/ WINHTTP_CURRENT_USER_IE_PROXY_CONFIG* pProxyConfig); | |
354 | |
355 /* This modifies "host" in-place evilly */ | |
356 static void | |
357 _proxy_fill_hostinfo(PurpleProxyInfo *info, char *host, int default_port) | |
358 { | |
359 int port = default_port; | |
360 char *d; | |
361 | |
362 d = g_strrstr(host, ":"); | |
363 if (d) | |
364 *d = '\0'; | |
365 d++; | |
366 if (*d) | |
367 sscanf(d, "%d", &port); | |
368 | |
369 purple_proxy_info_set_host(info, host); | |
370 purple_proxy_info_set_port(info, port); | |
371 } | |
372 | |
373 static PurpleProxyInfo * | |
374 purple_win32_proxy_get_info(void) | |
375 { | |
376 static LPFNWINHTTPGETIEPROXYCONFIG MyWinHttpGetIEProxyConfig = NULL; | |
377 static gboolean loaded = FALSE; | |
378 static PurpleProxyInfo info = {0, NULL, 0, NULL, NULL}; | |
379 | |
380 WINHTTP_CURRENT_USER_IE_PROXY_CONFIG ie_proxy_config; | |
381 | |
382 if (!loaded) { | |
383 loaded = TRUE; | |
384 MyWinHttpGetIEProxyConfig = (LPFNWINHTTPGETIEPROXYCONFIG) | |
385 wpurple_find_and_loadproc("winhttp.dll", "WinHttpGetIEProxyConfigForCurrentUser"); | |
386 if (!MyWinHttpGetIEProxyConfig) | |
387 purple_debug_info("proxy", "Unable to read Windows Proxy Settings.\n"); | |
388 } | |
389 | |
390 if (!MyWinHttpGetIEProxyConfig) | |
391 return NULL; | |
392 | |
393 ZeroMemory(&ie_proxy_config, sizeof(ie_proxy_config)); | |
394 if (!MyWinHttpGetIEProxyConfig(&ie_proxy_config)) { | |
395 purple_debug_error("proxy", "Error reading Windows Proxy Settings(%lu).\n", GetLastError()); | |
396 return NULL; | |
397 } | |
398 | |
399 /* We can't do much if it is autodetect*/ | |
400 if (ie_proxy_config.fAutoDetect) { | |
401 purple_debug_error("proxy", "Windows Proxy Settings set to autodetect (not supported).\n"); | |
402 | |
403 /* TODO: For 3.0.0 we'll revisit this (maybe)*/ | |
404 | |
405 return NULL; | |
406 | |
407 } else if (ie_proxy_config.lpszProxy) { | |
408 gchar *proxy_list = g_utf16_to_utf8(ie_proxy_config.lpszProxy, -1, | |
409 NULL, NULL, NULL); | |
410 | |
411 /* We can't do anything about the bypass list, as we don't have the url */ | |
412 /* TODO: For 3.0.0 we'll revisit this*/ | |
413 | |
414 /* There are proxy settings for several protocols */ | |
415 if (proxy_list && *proxy_list) { | |
416 char *specific = NULL, *tmp; | |
417 | |
418 /* If there is only a global proxy, which means "HTTP" */ | |
419 if (!strchr(proxy_list, ';') || (specific = g_strstr_len(proxy_list, -1, "http=")) != NULL) { | |
420 | |
421 if (specific) { | |
422 specific += strlen("http="); | |
423 tmp = strchr(specific, ';'); | |
424 if (tmp) | |
425 *tmp = '\0'; | |
426 /* specific now points the proxy server (and port) */ | |
427 } else | |
428 specific = proxy_list; | |
429 | |
430 purple_proxy_info_set_type(&info, PURPLE_PROXY_HTTP); | |
431 _proxy_fill_hostinfo(&info, specific, 80); | |
432 /* TODO: is there a way to set the username/password? */ | |
433 purple_proxy_info_set_username(&info, NULL); | |
434 purple_proxy_info_set_password(&info, NULL); | |
435 | |
436 purple_debug_info("proxy", "Windows Proxy Settings: HTTP proxy: '%s:%d'.\n", | |
437 purple_proxy_info_get_host(&info), | |
438 purple_proxy_info_get_port(&info)); | |
439 | |
440 } else if ((specific = g_strstr_len(proxy_list, -1, "socks=")) != NULL) { | |
441 | |
442 specific += strlen("socks="); | |
443 tmp = strchr(specific, ';'); | |
444 if (tmp) | |
445 *tmp = '\0'; | |
446 /* specific now points the proxy server (and port) */ | |
447 | |
448 purple_proxy_info_set_type(&info, PURPLE_PROXY_SOCKS5); | |
449 _proxy_fill_hostinfo(&info, specific, 1080); | |
450 /* TODO: is there a way to set the username/password? */ | |
451 purple_proxy_info_set_username(&info, NULL); | |
452 purple_proxy_info_set_password(&info, NULL); | |
453 | |
454 purple_debug_info("proxy", "Windows Proxy Settings: SOCKS5 proxy: '%s:%d'.\n", | |
455 purple_proxy_info_get_host(&info), | |
456 purple_proxy_info_get_port(&info)); | |
457 | |
458 } else { | |
459 | |
460 purple_debug_info("proxy", "Windows Proxy Settings: No supported proxy specified.\n"); | |
461 | |
462 purple_proxy_info_set_type(&info, PURPLE_PROXY_NONE); | |
463 | |
464 } | |
465 } | |
466 | |
467 /* TODO: Fix API to be able look at proxy bypass settings */ | |
468 | |
469 g_free(proxy_list); | |
470 } else { | |
471 purple_debug_info("proxy", "No Windows proxy set.\n"); | |
472 purple_proxy_info_set_type(&info, PURPLE_PROXY_NONE); | |
473 } | |
474 | |
475 if (ie_proxy_config.lpszAutoConfigUrl) | |
476 GlobalFree(ie_proxy_config.lpszAutoConfigUrl); | |
477 if (ie_proxy_config.lpszProxy) | |
478 GlobalFree(ie_proxy_config.lpszProxy); | |
479 if (ie_proxy_config.lpszProxyBypass) | |
480 GlobalFree(ie_proxy_config.lpszProxyBypass); | |
481 | |
482 return &info; | |
483 } | |
484 #endif | |
485 | |
486 | |
350 /************************************************************************** | 487 /************************************************************************** |
351 * Proxy API | 488 * Proxy API |
352 **************************************************************************/ | 489 **************************************************************************/ |
353 | 490 |
354 /** | 491 /** |
1876 else | 2013 else |
1877 gpi = purple_global_proxy_get_info(); | 2014 gpi = purple_global_proxy_get_info(); |
1878 } | 2015 } |
1879 | 2016 |
1880 if (purple_proxy_info_get_type(gpi) == PURPLE_PROXY_USE_ENVVAR) { | 2017 if (purple_proxy_info_get_type(gpi) == PURPLE_PROXY_USE_ENVVAR) { |
1881 #ifdef _WIN32 | |
1882 wpurple_check_for_proxy_changes(); | |
1883 #endif | |
1884 if ((tmp = g_getenv("HTTP_PROXY")) != NULL || | 2018 if ((tmp = g_getenv("HTTP_PROXY")) != NULL || |
1885 (tmp = g_getenv("http_proxy")) != NULL || | 2019 (tmp = g_getenv("http_proxy")) != NULL || |
1886 (tmp = g_getenv("HTTPPROXY")) != NULL) { | 2020 (tmp = g_getenv("HTTPPROXY")) != NULL) { |
1887 char *proxyhost, *proxyuser, *proxypasswd; | 2021 char *proxyhost, *proxyuser, *proxypasswd; |
1888 int proxyport; | 2022 int proxyport; |
1920 (tmp = g_getenv("HTTPPROXYPASS")) != NULL) | 2054 (tmp = g_getenv("HTTPPROXYPASS")) != NULL) |
1921 purple_proxy_info_set_password(gpi, tmp); | 2055 purple_proxy_info_set_password(gpi, tmp); |
1922 | 2056 |
1923 } | 2057 } |
1924 } else { | 2058 } else { |
2059 #ifdef _WIN32 | |
2060 PurpleProxyInfo *wgpi; | |
2061 if ((wgpi = purple_win32_proxy_get_info()) != NULL) | |
2062 return wgpi; | |
2063 #endif | |
1925 /* no proxy environment variable found, don't use a proxy */ | 2064 /* no proxy environment variable found, don't use a proxy */ |
1926 purple_debug_info("proxy", "No environment settings found, not using a proxy\n"); | 2065 purple_debug_info("proxy", "No environment settings found, not using a proxy\n"); |
1927 gpi = tmp_none_proxy_info; | 2066 gpi = tmp_none_proxy_info; |
1928 } | 2067 } |
1929 | 2068 |