Mercurial > pidgin
comparison libpurple/proxy.c @ 32819:2c6510167895 default tip
propagate from branch 'im.pidgin.pidgin.2.x.y' (head 3315c5dfbd0ad16511bdcf865e5b07c02d07df24)
to branch 'im.pidgin.pidgin' (head cbd1eda6bcbf0565ae7766396bb8f6f419cb6a9a)
| author | Elliott Sales de Andrade <qulogic@pidgin.im> |
|---|---|
| date | Sat, 02 Jun 2012 02:30:49 +0000 |
| parents | 6fa0e854cfc6 fa666e7f747e |
| children |
comparison
equal
deleted
inserted
replaced
| 32818:01ff09d4a463 | 32819:2c6510167895 |
|---|---|
| 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; |
| 1420 | 1430 |
| 1421 connect_data->inpa = purple_input_add(connect_data->fd, PURPLE_INPUT_WRITE, proxy_do_write, connect_data); | 1431 connect_data->inpa = purple_input_add(connect_data->fd, PURPLE_INPUT_WRITE, proxy_do_write, connect_data); |
| 1422 | 1432 |
| 1423 proxy_do_write(connect_data, connect_data->fd, PURPLE_INPUT_WRITE); | 1433 proxy_do_write(connect_data, connect_data->fd, PURPLE_INPUT_WRITE); |
| 1424 } else { | 1434 } else { |
| 1425 connect_data->query_data = purple_dnsquery_a_account( | 1435 connect_data->query_data = purple_dnsquery_a( |
| 1426 connect_data->account, connect_data->host, | 1436 connect_data->account, connect_data->host, |
| 1427 connect_data->port, s4_host_resolved, connect_data); | 1437 connect_data->port, s4_host_resolved, connect_data); |
| 1428 | 1438 |
| 1429 if (connect_data->query_data == NULL) { | 1439 if (connect_data->query_data == NULL) { |
| 1430 purple_debug_error("proxy", "dns query failed unexpectedly.\n"); | 1440 purple_debug_error("proxy", "dns query failed unexpectedly.\n"); |
| 2065 error = errno; | 2075 error = errno; |
| 2066 purple_proxy_connect_data_disconnect(connect_data, g_strerror(error)); | 2076 purple_proxy_connect_data_disconnect(connect_data, g_strerror(error)); |
| 2067 return; | 2077 return; |
| 2068 } | 2078 } |
| 2069 | 2079 |
| 2070 i = 0; | |
| 2071 buf[0] = 0x05; /* SOCKS version 5 */ | 2080 buf[0] = 0x05; /* SOCKS version 5 */ |
| 2072 | 2081 |
| 2073 if (purple_proxy_info_get_username(connect_data->gpi) != NULL) { | 2082 if (purple_proxy_info_get_username(connect_data->gpi) != NULL) { |
| 2074 buf[1] = 0x03; /* three methods */ | 2083 buf[1] = 0x03; /* three methods */ |
| 2075 buf[2] = 0x00; /* no authentication */ | 2084 buf[2] = 0x00; /* no authentication */ |
| 2139 } | 2148 } |
| 2140 } | 2149 } |
| 2141 | 2150 |
| 2142 /** | 2151 /** |
| 2143 * This function attempts to connect to the next IP address in the list | 2152 * This function attempts to connect to the next IP address in the list |
| 2144 * of IP addresses returned to us by purple_dnsquery_a() and attemps | 2153 * of IP addresses returned to us by purple_dnsquery_a() and attempts |
| 2145 * to connect to each one. This is called after the hostname is | 2154 * to connect to each one. This is called after the hostname is |
| 2146 * resolved, and each time a connection attempt fails (assuming there | 2155 * resolved, and each time a connection attempt fails (assuming there |
| 2147 * is another IP address to try). | 2156 * is another IP address to try). |
| 2148 */ | 2157 */ |
| 2149 #ifndef INET6_ADDRSTRLEN | 2158 #ifndef INET6_ADDRSTRLEN |
| 2368 purple_proxy_info_get_type(connect_data->gpi)); | 2377 purple_proxy_info_get_type(connect_data->gpi)); |
| 2369 purple_proxy_connect_data_destroy(connect_data); | 2378 purple_proxy_connect_data_destroy(connect_data); |
| 2370 return NULL; | 2379 return NULL; |
| 2371 } | 2380 } |
| 2372 | 2381 |
| 2373 connect_data->query_data = purple_dnsquery_a_account(account, connecthost, | 2382 connect_data->query_data = purple_dnsquery_a(account, connecthost, |
| 2374 connectport, connection_host_resolved, connect_data); | 2383 connectport, connection_host_resolved, connect_data); |
| 2375 if (connect_data->query_data == NULL) | 2384 if (connect_data->query_data == NULL) |
| 2376 { | 2385 { |
| 2377 purple_debug_error("proxy", "dns query failed unexpectedly.\n"); | 2386 purple_debug_error("proxy", "dns query failed unexpectedly.\n"); |
| 2378 purple_proxy_connect_data_destroy(connect_data); | 2387 purple_proxy_connect_data_destroy(connect_data); |
| 2436 purple_proxy_info_get_type(connect_data->gpi)); | 2445 purple_proxy_info_get_type(connect_data->gpi)); |
| 2437 purple_proxy_connect_data_destroy(connect_data); | 2446 purple_proxy_connect_data_destroy(connect_data); |
| 2438 return NULL; | 2447 return NULL; |
| 2439 } | 2448 } |
| 2440 | 2449 |
| 2441 connect_data->query_data = purple_dnsquery_a_account(account, connecthost, | 2450 connect_data->query_data = purple_dnsquery_a(account, connecthost, |
| 2442 connectport, connection_host_resolved, connect_data); | 2451 connectport, connection_host_resolved, connect_data); |
| 2443 if (connect_data->query_data == NULL) | 2452 if (connect_data->query_data == NULL) |
| 2444 { | 2453 { |
| 2445 purple_proxy_connect_data_destroy(connect_data); | 2454 purple_proxy_connect_data_destroy(connect_data); |
| 2446 return NULL; | 2455 return NULL; |
| 2448 | 2457 |
| 2449 handles = g_slist_prepend(handles, connect_data); | 2458 handles = g_slist_prepend(handles, connect_data); |
| 2450 | 2459 |
| 2451 return connect_data; | 2460 return connect_data; |
| 2452 } | 2461 } |
| 2453 | |
| 2454 PurpleProxyConnectData * | |
| 2455 purple_proxy_connect_socks5(void *handle, PurpleProxyInfo *gpi, | |
| 2456 const char *host, int port, | |
| 2457 PurpleProxyConnectFunction connect_cb, | |
| 2458 gpointer data) | |
| 2459 { | |
| 2460 return purple_proxy_connect_socks5_account(handle, NULL, gpi, | |
| 2461 host, port, connect_cb, data); | |
| 2462 } | |
| 2463 | |
| 2464 | 2462 |
| 2465 /* This is called when we connect to the SOCKS5 proxy server (through any | 2463 /* This is called when we connect to the SOCKS5 proxy server (through any |
| 2466 * relevant account proxy) | 2464 * relevant account proxy) |
| 2467 */ | 2465 */ |
| 2468 static void socks5_connected_to_proxy(gpointer data, gint source, | 2466 static void socks5_connected_to_proxy(gpointer data, gint source, |
