| 37 #include "proxy.h" |
37 #include "proxy.h" |
| 38 #include "util.h" |
38 #include "util.h" |
| 39 |
39 |
| 40 struct _PurpleProxyInfo |
40 struct _PurpleProxyInfo |
| 41 { |
41 { |
| 42 PurpleProxyType type; /**< The proxy type. */ |
42 PurpleProxyType type; /* The proxy type. */ |
| 43 |
43 |
| 44 char *host; /**< The host. */ |
44 char *host; /* The host. */ |
| 45 int port; /**< The port number. */ |
45 int port; /* The port number. */ |
| 46 char *username; /**< The username. */ |
46 char *username; /* The username. */ |
| 47 char *password; /**< The password. */ |
47 char *password; /* The password. */ |
| 48 }; |
48 }; |
| 49 |
49 |
| 50 struct _PurpleProxyConnectData { |
50 struct _PurpleProxyConnectData { |
| 51 void *handle; |
51 void *handle; |
| 52 PurpleProxyConnectFunction connect_cb; |
52 PurpleProxyConnectFunction connect_cb; |
| 251 { "gconftool-2 -g /system/http_proxy/port", "gsettings get org.gnome.system.proxy.http port"}, |
251 { "gconftool-2 -g /system/http_proxy/port", "gsettings get org.gnome.system.proxy.http port"}, |
| 252 { "gconftool-2 -g /system/http_proxy/authentication_user", "gsettings get org.gnome.system.proxy.http authentication-user" }, |
252 { "gconftool-2 -g /system/http_proxy/authentication_user", "gsettings get org.gnome.system.proxy.http authentication-user" }, |
| 253 { "gconftool-2 -g /system/http_proxy/authentication_password", "gsettings get org.gnome.system.proxy.http authentication-password" }, |
253 { "gconftool-2 -g /system/http_proxy/authentication_password", "gsettings get org.gnome.system.proxy.http authentication-password" }, |
| 254 }; |
254 }; |
| 255 |
255 |
| 256 /** |
256 /* |
| |
257 * purple_gnome_proxy_get_parameter: |
| |
258 * @parameter: One of the GNOME_PROXY_x constants defined above |
| |
259 * @gnome_version: GNOME2_CMDS or GNOME3_CMDS |
| |
260 * |
| 257 * This is a utility function used to retrieve proxy parameter values from |
261 * This is a utility function used to retrieve proxy parameter values from |
| 258 * GNOME 2/3 environment. |
262 * GNOME 2/3 environment. |
| 259 * |
263 * |
| 260 * @param parameter One of the GNOME_PROXY_x constants defined above |
264 * Returns: The value of requested proxy parameter |
| 261 * @param gnome_version GNOME2_CMDS or GNOME3_CMDS |
|
| 262 * |
|
| 263 * @return The value of requested proxy parameter |
|
| 264 */ |
265 */ |
| 265 static char * |
266 static char * |
| 266 purple_gnome_proxy_get_parameter(guint8 parameter, guint8 gnome_version) |
267 purple_gnome_proxy_get_parameter(guint8 parameter, guint8 gnome_version) |
| 267 { |
268 { |
| 268 gchar *param, *err; |
269 gchar *param, *err; |
| 565 |
566 |
| 566 /************************************************************************** |
567 /************************************************************************** |
| 567 * Proxy API |
568 * Proxy API |
| 568 **************************************************************************/ |
569 **************************************************************************/ |
| 569 |
570 |
| 570 /** |
571 /* |
| 571 * Whoever calls this needs to have called |
572 * Whoever calls this needs to have called |
| 572 * purple_proxy_connect_data_disconnect() beforehand. |
573 * purple_proxy_connect_data_disconnect() beforehand. |
| 573 */ |
574 */ |
| 574 static void |
575 static void |
| 575 purple_proxy_connect_data_destroy(PurpleProxyConnectData *connect_data) |
576 purple_proxy_connect_data_destroy(PurpleProxyConnectData *connect_data) |
| 590 |
591 |
| 591 g_free(connect_data->host); |
592 g_free(connect_data->host); |
| 592 g_free(connect_data); |
593 g_free(connect_data); |
| 593 } |
594 } |
| 594 |
595 |
| 595 /** |
596 /* |
| |
597 * purple_proxy_connect_data_disconnect: |
| |
598 * @error_message: An error message explaining why the connection |
| |
599 * failed. This will be passed to the callback function |
| |
600 * specified in the call to purple_proxy_connect(). If the |
| |
601 * connection was successful then pass in null. |
| |
602 * |
| 596 * Free all information dealing with a connection attempt and |
603 * Free all information dealing with a connection attempt and |
| 597 * reset the connect_data to prepare for it to try to connect |
604 * reset the connect_data to prepare for it to try to connect |
| 598 * to another IP address. |
605 * to another IP address. |
| 599 * |
606 * |
| 600 * If an error message is passed in, then we know the connection |
607 * If an error message is passed in, then we know the connection |
| 601 * attempt failed. If the connection attempt failed and |
608 * attempt failed. If the connection attempt failed and |
| 602 * connect_data->hosts is not empty then we try the next IP address. |
609 * connect_data->hosts is not empty then we try the next IP address. |
| 603 * If the connection attempt failed and we have no more hosts |
610 * If the connection attempt failed and we have no more hosts |
| 604 * try try then we call the callback with the given error message, |
611 * try try then we call the callback with the given error message, |
| 605 * then destroy the connect_data. |
612 * then destroy the connect_data. |
| 606 * |
|
| 607 * @param error_message An error message explaining why the connection |
|
| 608 * failed. This will be passed to the callback function |
|
| 609 * specified in the call to purple_proxy_connect(). If the |
|
| 610 * connection was successful then pass in null. |
|
| 611 */ |
613 */ |
| 612 static void |
614 static void |
| 613 purple_proxy_connect_data_disconnect(PurpleProxyConnectData *connect_data, const gchar *error_message) |
615 purple_proxy_connect_data_disconnect(PurpleProxyConnectData *connect_data, const gchar *error_message) |
| 614 { |
616 { |
| 615 if (connect_data->child != NULL) |
617 if (connect_data->child != NULL) |
| 649 purple_proxy_connect_data_destroy(connect_data); |
651 purple_proxy_connect_data_destroy(connect_data); |
| 650 } |
652 } |
| 651 } |
653 } |
| 652 } |
654 } |
| 653 |
655 |
| 654 /** |
656 /* |
| 655 * This calls purple_proxy_connect_data_disconnect(), but it lets you |
657 * This calls purple_proxy_connect_data_disconnect(), but it lets you |
| 656 * specify the error_message using a printf()-like syntax. |
658 * specify the error_message using a printf()-like syntax. |
| 657 */ |
659 */ |
| 658 static void |
660 static void |
| 659 purple_proxy_connect_data_disconnect_formatted(PurpleProxyConnectData *connect_data, const char *format, ...) |
661 purple_proxy_connect_data_disconnect_formatted(PurpleProxyConnectData *connect_data, const char *format, ...) |
| 867 */ |
869 */ |
| 868 purple_timeout_add(10, clean_connect, connect_data); |
870 purple_timeout_add(10, clean_connect, connect_data); |
| 869 } |
871 } |
| 870 } |
872 } |
| 871 |
873 |
| 872 /** |
874 /* |
| 873 * This is a utility function used by the HTTP, SOCKS4 and SOCKS5 |
875 * This is a utility function used by the HTTP, SOCKS4 and SOCKS5 |
| 874 * connect functions. It writes data from a buffer to a socket. |
876 * connect functions. It writes data from a buffer to a socket. |
| 875 * When all the data is written it sets up a watcher to read a |
877 * When all the data is written it sets up a watcher to read a |
| 876 * response and call a specified function. |
878 * response and call a specified function. |
| 877 */ |
879 */ |
| 909 purple_input_remove(connect_data->inpa); |
911 purple_input_remove(connect_data->inpa); |
| 910 connect_data->inpa = purple_input_add(connect_data->fd, |
912 connect_data->inpa = purple_input_add(connect_data->fd, |
| 911 PURPLE_INPUT_READ, connect_data->read_cb, connect_data); |
913 PURPLE_INPUT_READ, connect_data->read_cb, connect_data); |
| 912 } |
914 } |
| 913 |
915 |
| 914 /** |
916 /* |
| 915 * We're using an HTTP proxy for a non-port 80 tunnel. Read the |
917 * We're using an HTTP proxy for a non-port 80 tunnel. Read the |
| 916 * response to the CONNECT request. |
918 * response to the CONNECT request. |
| 917 */ |
919 */ |
| 918 static void |
920 static void |
| 919 http_canread(gpointer data, gint source, PurpleInputCondition cond) |
921 http_canread(gpointer data, gint source, PurpleInputCondition cond) |
| 2150 |
2152 |
| 2151 s5_canwrite(connect_data, connect_data->fd, PURPLE_INPUT_WRITE); |
2153 s5_canwrite(connect_data, connect_data->fd, PURPLE_INPUT_WRITE); |
| 2152 } |
2154 } |
| 2153 } |
2155 } |
| 2154 |
2156 |
| 2155 /** |
2157 /* |
| 2156 * This function attempts to connect to the next IP address in the list |
2158 * This function attempts to connect to the next IP address in the list |
| 2157 * of IP addresses returned to us by purple_dnsquery_a() and attempts |
2159 * of IP addresses returned to us by purple_dnsquery_a() and attempts |
| 2158 * to connect to each one. This is called after the hostname is |
2160 * to connect to each one. This is called after the hostname is |
| 2159 * resolved, and each time a connection attempt fails (assuming there |
2161 * resolved, and each time a connection attempt fails (assuming there |
| 2160 * is another IP address to try). |
2162 * is another IP address to try). |