Mercurial > pidgin
comparison libpurple/proxy.c @ 32672:3828a61c44da
A boring and large patch so I can merge heads.
author | Elliott Sales de Andrade <qulogic@pidgin.im> |
---|---|
date | Fri, 23 Dec 2011 08:21:58 +0000 |
parents | 5498ee1aa30b |
children |
comparison
equal
deleted
inserted
replaced
32671:0e69949b3e61 | 32672:3828a61c44da |
---|---|
39 #include "ntlm.h" | 39 #include "ntlm.h" |
40 #include "prefs.h" | 40 #include "prefs.h" |
41 #include "proxy.h" | 41 #include "proxy.h" |
42 #include "util.h" | 42 #include "util.h" |
43 | 43 |
44 struct _PurpleProxyInfo | |
45 { | |
46 PurpleProxyType type; /**< The proxy type. */ | |
47 | |
48 char *host; /**< The host. */ | |
49 int port; /**< The port number. */ | |
50 char *username; /**< The username. */ | |
51 char *password; /**< The password. */ | |
52 }; | |
53 | |
44 struct _PurpleProxyConnectData { | 54 struct _PurpleProxyConnectData { |
45 void *handle; | 55 void *handle; |
46 PurpleProxyConnectFunction connect_cb; | 56 PurpleProxyConnectFunction connect_cb; |
47 gpointer data; | 57 gpointer data; |
48 gchar *host; | 58 gchar *host; |
1367 | 1377 |
1368 connect_data->inpa = purple_input_add(connect_data->fd, PURPLE_INPUT_WRITE, proxy_do_write, connect_data); | 1378 connect_data->inpa = purple_input_add(connect_data->fd, PURPLE_INPUT_WRITE, proxy_do_write, connect_data); |
1369 | 1379 |
1370 proxy_do_write(connect_data, connect_data->fd, PURPLE_INPUT_WRITE); | 1380 proxy_do_write(connect_data, connect_data->fd, PURPLE_INPUT_WRITE); |
1371 } else { | 1381 } else { |
1372 connect_data->query_data = purple_dnsquery_a_account( | 1382 connect_data->query_data = purple_dnsquery_a( |
1373 connect_data->account, connect_data->host, | 1383 connect_data->account, connect_data->host, |
1374 connect_data->port, s4_host_resolved, connect_data); | 1384 connect_data->port, s4_host_resolved, connect_data); |
1375 | 1385 |
1376 if (connect_data->query_data == NULL) { | 1386 if (connect_data->query_data == NULL) { |
1377 purple_debug_error("proxy", "dns query failed unexpectedly.\n"); | 1387 purple_debug_error("proxy", "dns query failed unexpectedly.\n"); |
2012 error = errno; | 2022 error = errno; |
2013 purple_proxy_connect_data_disconnect(connect_data, g_strerror(error)); | 2023 purple_proxy_connect_data_disconnect(connect_data, g_strerror(error)); |
2014 return; | 2024 return; |
2015 } | 2025 } |
2016 | 2026 |
2017 i = 0; | |
2018 buf[0] = 0x05; /* SOCKS version 5 */ | 2027 buf[0] = 0x05; /* SOCKS version 5 */ |
2019 | 2028 |
2020 if (purple_proxy_info_get_username(connect_data->gpi) != NULL) { | 2029 if (purple_proxy_info_get_username(connect_data->gpi) != NULL) { |
2021 buf[1] = 0x03; /* three methods */ | 2030 buf[1] = 0x03; /* three methods */ |
2022 buf[2] = 0x00; /* no authentication */ | 2031 buf[2] = 0x00; /* no authentication */ |
2086 } | 2095 } |
2087 } | 2096 } |
2088 | 2097 |
2089 /** | 2098 /** |
2090 * This function attempts to connect to the next IP address in the list | 2099 * This function attempts to connect to the next IP address in the list |
2091 * of IP addresses returned to us by purple_dnsquery_a() and attemps | 2100 * of IP addresses returned to us by purple_dnsquery_a() and attempts |
2092 * to connect to each one. This is called after the hostname is | 2101 * to connect to each one. This is called after the hostname is |
2093 * resolved, and each time a connection attempt fails (assuming there | 2102 * resolved, and each time a connection attempt fails (assuming there |
2094 * is another IP address to try). | 2103 * is another IP address to try). |
2095 */ | 2104 */ |
2096 #ifndef INET6_ADDRSTRLEN | 2105 #ifndef INET6_ADDRSTRLEN |
2315 purple_proxy_info_get_type(connect_data->gpi)); | 2324 purple_proxy_info_get_type(connect_data->gpi)); |
2316 purple_proxy_connect_data_destroy(connect_data); | 2325 purple_proxy_connect_data_destroy(connect_data); |
2317 return NULL; | 2326 return NULL; |
2318 } | 2327 } |
2319 | 2328 |
2320 connect_data->query_data = purple_dnsquery_a_account(account, connecthost, | 2329 connect_data->query_data = purple_dnsquery_a(account, connecthost, |
2321 connectport, connection_host_resolved, connect_data); | 2330 connectport, connection_host_resolved, connect_data); |
2322 if (connect_data->query_data == NULL) | 2331 if (connect_data->query_data == NULL) |
2323 { | 2332 { |
2324 purple_debug_error("proxy", "dns query failed unexpectedly.\n"); | 2333 purple_debug_error("proxy", "dns query failed unexpectedly.\n"); |
2325 purple_proxy_connect_data_destroy(connect_data); | 2334 purple_proxy_connect_data_destroy(connect_data); |
2383 purple_proxy_info_get_type(connect_data->gpi)); | 2392 purple_proxy_info_get_type(connect_data->gpi)); |
2384 purple_proxy_connect_data_destroy(connect_data); | 2393 purple_proxy_connect_data_destroy(connect_data); |
2385 return NULL; | 2394 return NULL; |
2386 } | 2395 } |
2387 | 2396 |
2388 connect_data->query_data = purple_dnsquery_a_account(account, connecthost, | 2397 connect_data->query_data = purple_dnsquery_a(account, connecthost, |
2389 connectport, connection_host_resolved, connect_data); | 2398 connectport, connection_host_resolved, connect_data); |
2390 if (connect_data->query_data == NULL) | 2399 if (connect_data->query_data == NULL) |
2391 { | 2400 { |
2392 purple_proxy_connect_data_destroy(connect_data); | 2401 purple_proxy_connect_data_destroy(connect_data); |
2393 return NULL; | 2402 return NULL; |
2395 | 2404 |
2396 handles = g_slist_prepend(handles, connect_data); | 2405 handles = g_slist_prepend(handles, connect_data); |
2397 | 2406 |
2398 return connect_data; | 2407 return connect_data; |
2399 } | 2408 } |
2400 | |
2401 PurpleProxyConnectData * | |
2402 purple_proxy_connect_socks5(void *handle, PurpleProxyInfo *gpi, | |
2403 const char *host, int port, | |
2404 PurpleProxyConnectFunction connect_cb, | |
2405 gpointer data) | |
2406 { | |
2407 return purple_proxy_connect_socks5_account(NULL, handle, gpi, | |
2408 host, port, connect_cb, data); | |
2409 } | |
2410 | |
2411 | 2409 |
2412 /* This is called when we connect to the SOCKS5 proxy server (through any | 2410 /* This is called when we connect to the SOCKS5 proxy server (through any |
2413 * relevant account proxy) | 2411 * relevant account proxy) |
2414 */ | 2412 */ |
2415 static void socks5_connected_to_proxy(gpointer data, gint source, | 2413 static void socks5_connected_to_proxy(gpointer data, gint source, |