Mercurial > pidgin
comparison libpurple/win32/win32dep.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 | 1cd99421c696 |
children | 6a3943412f2d |
comparison
equal
deleted
inserted
replaced
23969:4ecea8ae3d21 | 23970:54eb782d4721 |
---|---|
414 } | 414 } |
415 | 415 |
416 return result; | 416 return result; |
417 } | 417 } |
418 | 418 |
419 /* the winapi headers don't yet have winhttp.h, so we use the struct from msdn directly */ | |
420 typedef struct { | |
421 BOOL fAutoDetect; | |
422 LPWSTR lpszAutoConfigUrl; | |
423 LPWSTR lpszProxy; | |
424 LPWSTR lpszProxyBypass; | |
425 } WINHTTP_CURRENT_USER_IE_PROXY_CONFIG; | |
426 | |
427 typedef BOOL (CALLBACK* LPFNWINHTTPGETIEPROXYCONFIG)(/*IN OUT*/ WINHTTP_CURRENT_USER_IE_PROXY_CONFIG* pProxyConfig); | |
428 | |
429 gboolean wpurple_check_for_proxy_changes(void) { | |
430 static gboolean loaded = FALSE; | |
431 static LPFNWINHTTPGETIEPROXYCONFIG MyWinHttpGetIEProxyConfig = NULL; | |
432 | |
433 WINHTTP_CURRENT_USER_IE_PROXY_CONFIG ie_proxy_config; | |
434 char *tmp = NULL, *c = NULL; | |
435 gboolean changed = FALSE; | |
436 | |
437 if (!loaded) { | |
438 loaded = TRUE; | |
439 | |
440 if (getenv("HTTP_PROXY") || getenv("http_proxy") || getenv("HTTPPROXY")) { | |
441 purple_debug_info("wpurple", "HTTP_PROXY env. var already set. Ignoring win32 Internet Settings.\n"); | |
442 return FALSE; | |
443 } | |
444 | |
445 MyWinHttpGetIEProxyConfig = (LPFNWINHTTPGETIEPROXYCONFIG) | |
446 wpurple_find_and_loadproc("winhttp.dll", "WinHttpGetIEProxyConfigForCurrentUser"); | |
447 if (!MyWinHttpGetIEProxyConfig) | |
448 purple_debug_info("wpurple", "Unable to read Windows Proxy Settings.\n"); | |
449 } | |
450 | |
451 if (!MyWinHttpGetIEProxyConfig) | |
452 return FALSE; | |
453 | |
454 ZeroMemory(&ie_proxy_config, sizeof(ie_proxy_config)); | |
455 if (!MyWinHttpGetIEProxyConfig(&ie_proxy_config)) { | |
456 purple_debug_error("wpurple", "Error reading Windows Proxy Settings(%lu).\n", GetLastError()); | |
457 return FALSE; | |
458 } | |
459 | |
460 /* We can't do much if it is autodetect*/ | |
461 if (ie_proxy_config.fAutoDetect) | |
462 purple_debug_error("wpurple", "Windows Proxy Settings set to autodetect (not supported).\n"); | |
463 else if (ie_proxy_config.lpszProxy) { | |
464 tmp = g_utf16_to_utf8(ie_proxy_config.lpszProxy, -1, | |
465 NULL, NULL, NULL); | |
466 /* We can't do anything about the bypass list, as we don't have the url */ | |
467 } else | |
468 purple_debug_info("wpurple", "No Windows Proxy Set.\n"); | |
469 | |
470 if (ie_proxy_config.lpszAutoConfigUrl) | |
471 GlobalFree(ie_proxy_config.lpszAutoConfigUrl); | |
472 if (ie_proxy_config.lpszProxy) | |
473 GlobalFree(ie_proxy_config.lpszProxy); | |
474 if (ie_proxy_config.lpszProxyBypass) | |
475 GlobalFree(ie_proxy_config.lpszProxyBypass); | |
476 | |
477 /* There are proxy settings for several protocols */ | |
478 if (tmp && (c = g_strstr_len(tmp, strlen(tmp), "http="))) { | |
479 char *d; | |
480 c += strlen("http="); | |
481 d = strchr(c, ';'); | |
482 if (d) | |
483 *d = '\0'; | |
484 /* c now points the proxy server (and port) */ | |
485 /* There is only a global proxy */ | |
486 } else if (tmp && strlen(tmp) > 0 && !strchr(tmp, ';')) { | |
487 c = tmp; | |
488 } | |
489 | |
490 if (c && *c) { | |
491 const char *current = g_getenv("HTTP_PROXY"); | |
492 if (!current || strcmp(current, c)) { | |
493 purple_debug_info("wpurple", "Setting HTTP Proxy: 'http://%s'\n", c); | |
494 g_setenv("HTTP_PROXY", c, TRUE); | |
495 changed = TRUE; | |
496 } | |
497 } | |
498 /* If there previously was a proxy set and there isn't one now, clear it */ | |
499 else if (getenv("HTTP_PROXY")) { | |
500 purple_debug_info("wpurple", "Clearing HTTP Proxy\n"); | |
501 g_unsetenv("HTTP_PROXY"); | |
502 changed = TRUE; | |
503 } | |
504 | |
505 g_free(tmp); | |
506 | |
507 return changed; | |
508 } | |
509 | |
510 void wpurple_init(void) { | 419 void wpurple_init(void) { |
511 WORD wVersionRequested; | 420 WORD wVersionRequested; |
512 WSADATA wsaData; | 421 WSADATA wsaData; |
513 const char *perlenv; | 422 const char *perlenv; |
514 char *newenv; | 423 char *newenv; |
515 | 424 |
425 if (!g_thread_supported()) | |
426 g_thread_init(NULL); | |
427 | |
516 purple_debug_info("wpurple", "wpurple_init start\n"); | 428 purple_debug_info("wpurple", "wpurple_init start\n"); |
517 purple_debug_info("wpurple", "libpurple version: " DISPLAY_VERSION "\n"); | 429 purple_debug_info("wpurple", "libpurple version: " DISPLAY_VERSION "\n"); |
518 | |
519 | 430 |
520 purple_debug_info("wpurple", "Glib:%u.%u.%u\n", | 431 purple_debug_info("wpurple", "Glib:%u.%u.%u\n", |
521 glib_major_version, glib_minor_version, glib_micro_version); | 432 glib_major_version, glib_minor_version, glib_micro_version); |
522 | 433 |
523 /* Winsock init */ | 434 /* Winsock init */ |
542 wpurple_install_dir()); | 453 wpurple_install_dir()); |
543 if (!g_setenv("PERL5LIB", newenv, TRUE)) | 454 if (!g_setenv("PERL5LIB", newenv, TRUE)) |
544 purple_debug_warning("wpurple", "putenv failed for PERL5LIB\n"); | 455 purple_debug_warning("wpurple", "putenv failed for PERL5LIB\n"); |
545 g_free(newenv); | 456 g_free(newenv); |
546 | 457 |
547 if (!g_thread_supported()) | |
548 g_thread_init(NULL); | |
549 | |
550 purple_debug_info("wpurple", "wpurple_init end\n"); | 458 purple_debug_info("wpurple", "wpurple_init end\n"); |
551 } | 459 } |
552 | 460 |
553 /* Windows Cleanup */ | 461 /* Windows Cleanup */ |
554 | 462 |