Mercurial > pidgin.yaz
comparison libpurple/proxy.c @ 23911:dd4df1a209b7
merge of '44b23c8bda2576a9bfcd3eaa90f9188c455df575'
and '7f16ff52262dcf6e66b6fd7796fca4bdd5de76bb'
author | Ka-Hing Cheung <khc@hxbc.us> |
---|---|
date | Wed, 27 Aug 2008 01:43:09 +0000 |
parents | 54eb782d4721 |
children | 4a1bbe955690 |
comparison
equal
deleted
inserted
replaced
23908:def8c164f557 | 23911:dd4df1a209b7 |
---|---|
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 *tmp; | 214 gboolean use_same_proxy = FALSE; |
215 gchar *tmp, *err; | |
215 | 216 |
216 tmp = g_find_program_in_path("gconftool-2"); | 217 tmp = g_find_program_in_path("gconftool-2"); |
217 if (tmp == NULL) | 218 if (tmp == NULL) |
218 return purple_global_proxy_get_info(); | 219 return purple_global_proxy_get_info(); |
219 | 220 |
220 g_free(tmp); | 221 g_free(tmp); |
221 | 222 |
222 /* Check whether to use a proxy. */ | 223 /* Check whether to use a proxy. */ |
223 if (!g_spawn_command_line_sync("gconftool-2 -g /system/proxy/mode", | 224 if (!g_spawn_command_line_sync("gconftool-2 -g /system/proxy/mode", |
224 &tmp, NULL, NULL, NULL)) | 225 &tmp, &err, NULL, NULL)) |
225 return purple_global_proxy_get_info(); | 226 return purple_global_proxy_get_info(); |
227 g_free(err); | |
226 | 228 |
227 if (!strcmp(tmp, "none\n")) { | 229 if (!strcmp(tmp, "none\n")) { |
228 info.type = PURPLE_PROXY_NONE; | 230 info.type = PURPLE_PROXY_NONE; |
229 g_free(tmp); | 231 g_free(tmp); |
230 return &info; | 232 return &info; |
236 return purple_global_proxy_get_info(); | 238 return purple_global_proxy_get_info(); |
237 } | 239 } |
238 | 240 |
239 g_free(tmp); | 241 g_free(tmp); |
240 | 242 |
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 */ | 243 /* Free the old fields */ |
245 if (info.host) { | 244 if (info.host) { |
246 g_free(info.host); | 245 g_free(info.host); |
247 info.host = NULL; | 246 info.host = NULL; |
248 } | 247 } |
253 if (info.password) { | 252 if (info.password) { |
254 g_free(info.password); | 253 g_free(info.password); |
255 info.password = NULL; | 254 info.password = NULL; |
256 } | 255 } |
257 | 256 |
258 if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/host", | 257 if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/use_same_proxy", |
259 &info.host, NULL, NULL, NULL)) | 258 &tmp, &err, NULL, NULL)) |
260 return purple_global_proxy_get_info(); | 259 return purple_global_proxy_get_info(); |
260 g_free(err); | |
261 | |
262 if (!strcmp(tmp, "true\n")) | |
263 use_same_proxy = TRUE; | |
264 g_free(tmp); | |
265 | |
266 if (!use_same_proxy && !g_spawn_command_line_sync("gconftool-2 -g /system/proxy/socks_host", | |
267 &info.host, &err, NULL, NULL)) | |
268 return purple_global_proxy_get_info(); | |
269 g_free(err); | |
261 g_strchomp(info.host); | 270 g_strchomp(info.host); |
262 if (*info.host == '\0') | 271 |
263 { | 272 if (!use_same_proxy && *info.host != '\0') { |
264 purple_debug_info("proxy", "Gnome proxy settings are set to " | 273 info.type = PURPLE_PROXY_SOCKS5; |
265 "'manual' but no proxy server is specified. Using " | 274 if (!g_spawn_command_line_sync("gconftool-2 -g /system/proxy/socks_port", |
266 "Pidgin's proxy settings instead.\n"); | 275 &tmp, &err, NULL, NULL)) |
276 { | |
277 g_free(info.host); | |
278 info.host = NULL; | |
279 g_free(info.username); | |
280 info.username = NULL; | |
281 g_free(info.password); | |
282 info.password = NULL; | |
283 return purple_global_proxy_get_info(); | |
284 } | |
285 g_free(err); | |
286 info.port = atoi(tmp); | |
287 g_free(tmp); | |
288 } else { | |
267 g_free(info.host); | 289 g_free(info.host); |
268 info.host = NULL; | 290 if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/host", |
269 return purple_global_proxy_get_info(); | 291 &info.host, &err, NULL, NULL)) |
270 } | 292 return purple_global_proxy_get_info(); |
271 | 293 g_free(err); |
272 if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/authentication_user", | 294 /* If we get this far then we know we're using an HTTP proxy */ |
273 &info.username, NULL, NULL, NULL)) | 295 info.type = PURPLE_PROXY_HTTP; |
274 { | 296 |
275 g_free(info.host); | 297 g_strchomp(info.host); |
276 info.host = NULL; | 298 if (*info.host == '\0') |
277 return purple_global_proxy_get_info(); | 299 { |
278 } | 300 purple_debug_info("proxy", "Gnome proxy settings are set to " |
279 g_strchomp(info.username); | 301 "'manual' but no suitable proxy server is specified. Using " |
280 | 302 "Pidgin's proxy settings instead.\n"); |
281 if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/authentication_password", | 303 g_free(info.host); |
282 &info.password, NULL, NULL, NULL)) | 304 info.host = NULL; |
283 { | 305 return purple_global_proxy_get_info(); |
284 g_free(info.host); | 306 } |
285 info.host = NULL; | 307 |
286 g_free(info.username); | 308 if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/authentication_user", |
287 info.username = NULL; | 309 &info.username, &err, NULL, NULL)) |
288 return purple_global_proxy_get_info(); | 310 { |
289 } | 311 g_free(info.host); |
290 g_strchomp(info.password); | 312 info.host = NULL; |
291 | 313 g_free(info.username); |
292 if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/port", | 314 info.username = NULL; |
293 &tmp, NULL, NULL, NULL)) | 315 return purple_global_proxy_get_info(); |
294 { | 316 } |
295 g_free(info.host); | 317 g_free(err); |
296 info.host = NULL; | 318 g_strchomp(info.username); |
297 g_free(info.username); | 319 |
298 info.username = NULL; | 320 if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/authentication_password", |
299 g_free(info.password); | 321 &info.password, &err, NULL, NULL)) |
300 info.password = NULL; | 322 { |
301 return purple_global_proxy_get_info(); | 323 g_free(info.host); |
302 } | 324 info.host = NULL; |
303 info.port = atoi(tmp); | 325 g_free(info.username); |
304 g_free(tmp); | 326 info.username = NULL; |
327 return purple_global_proxy_get_info(); | |
328 } | |
329 g_free(err); | |
330 g_strchomp(info.password); | |
331 | |
332 if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/port", | |
333 &tmp, &err, NULL, NULL)) | |
334 { | |
335 g_free(info.host); | |
336 info.host = NULL; | |
337 g_free(info.username); | |
338 info.username = NULL; | |
339 g_free(info.password); | |
340 info.password = NULL; | |
341 return purple_global_proxy_get_info(); | |
342 } | |
343 g_free(err); | |
344 info.port = atoi(tmp); | |
345 g_free(tmp); | |
346 } | |
305 | 347 |
306 return &info; | 348 return &info; |
307 } | 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 | |
308 /************************************************************************** | 487 /************************************************************************** |
309 * Proxy API | 488 * Proxy API |
310 **************************************************************************/ | 489 **************************************************************************/ |
311 | 490 |
312 /** | 491 /** |
1834 else | 2013 else |
1835 gpi = purple_global_proxy_get_info(); | 2014 gpi = purple_global_proxy_get_info(); |
1836 } | 2015 } |
1837 | 2016 |
1838 if (purple_proxy_info_get_type(gpi) == PURPLE_PROXY_USE_ENVVAR) { | 2017 if (purple_proxy_info_get_type(gpi) == PURPLE_PROXY_USE_ENVVAR) { |
1839 #ifdef _WIN32 | |
1840 wpurple_check_for_proxy_changes(); | |
1841 #endif | |
1842 if ((tmp = g_getenv("HTTP_PROXY")) != NULL || | 2018 if ((tmp = g_getenv("HTTP_PROXY")) != NULL || |
1843 (tmp = g_getenv("http_proxy")) != NULL || | 2019 (tmp = g_getenv("http_proxy")) != NULL || |
1844 (tmp = g_getenv("HTTPPROXY")) != NULL) { | 2020 (tmp = g_getenv("HTTPPROXY")) != NULL) { |
1845 char *proxyhost, *proxyuser, *proxypasswd; | 2021 char *proxyhost, *proxyuser, *proxypasswd; |
1846 int proxyport; | 2022 int proxyport; |
1878 (tmp = g_getenv("HTTPPROXYPASS")) != NULL) | 2054 (tmp = g_getenv("HTTPPROXYPASS")) != NULL) |
1879 purple_proxy_info_set_password(gpi, tmp); | 2055 purple_proxy_info_set_password(gpi, tmp); |
1880 | 2056 |
1881 } | 2057 } |
1882 } else { | 2058 } else { |
2059 #ifdef _WIN32 | |
2060 PurpleProxyInfo *wgpi; | |
2061 if ((wgpi = purple_win32_proxy_get_info()) != NULL) | |
2062 return wgpi; | |
2063 #endif | |
1883 /* no proxy environment variable found, don't use a proxy */ | 2064 /* no proxy environment variable found, don't use a proxy */ |
1884 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"); |
1885 gpi = tmp_none_proxy_info; | 2066 gpi = tmp_none_proxy_info; |
1886 } | 2067 } |
1887 | 2068 |