2 * @file proxy.h Proxy API
8 * Purple is the legal property of its developers, whose names are too numerous
9 * to list here. Please refer to the COPYRIGHT file distributed with this
10 * source distribution.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
26 #ifndef _PURPLE_PROXY_H_
27 #define _PURPLE_PROXY_H_
30 #include "eventloop.h"
33 * A type of proxy connection.
37 PURPLE_PROXY_USE_GLOBAL = -1, /**< Use the global proxy information. */
38 PURPLE_PROXY_NONE = 0, /**< No proxy. */
39 PURPLE_PROXY_HTTP, /**< HTTP proxy. */
40 PURPLE_PROXY_SOCKS4, /**< SOCKS 4 proxy. */
41 PURPLE_PROXY_SOCKS5, /**< SOCKS 5 proxy. */
42 PURPLE_PROXY_USE_ENVVAR /**< Use environmental settings. */
47 * Information on proxy settings.
51 PurpleProxyType type; /**< The proxy type. */
53 char *host; /**< The host. */
54 int port; /**< The port number. */
55 char *username; /**< The username. */
56 char *password; /**< The password. */
60 typedef struct _PurpleProxyConnectData PurpleProxyConnectData;
62 typedef void (*PurpleProxyConnectFunction)(gpointer data, gint source, const gchar *error_message);
71 /**************************************************************************/
72 /** @name Proxy structure API */
73 /**************************************************************************/
77 * Creates a proxy information structure.
79 * @return The proxy information structure.
81 PurpleProxyInfo *purple_proxy_info_new(void);
84 * Destroys a proxy information structure.
86 * @param info The proxy information structure to destroy.
88 void purple_proxy_info_destroy(PurpleProxyInfo *info);
91 * Sets the type of proxy.
93 * @param info The proxy information.
94 * @param type The proxy type.
96 void purple_proxy_info_set_type(PurpleProxyInfo *info, PurpleProxyType type);
99 * Sets the proxy host.
101 * @param info The proxy information.
102 * @param host The host.
104 void purple_proxy_info_set_host(PurpleProxyInfo *info, const char *host);
107 * Sets the proxy port.
109 * @param info The proxy information.
110 * @param port The port.
112 void purple_proxy_info_set_port(PurpleProxyInfo *info, int port);
115 * Sets the proxy username.
117 * @param info The proxy information.
118 * @param username The username.
120 void purple_proxy_info_set_username(PurpleProxyInfo *info, const char *username);
123 * Sets the proxy password.
125 * @param info The proxy information.
126 * @param password The password.
128 void purple_proxy_info_set_password(PurpleProxyInfo *info, const char *password);
131 * Returns the proxy's type.
133 * @param info The proxy information.
137 PurpleProxyType purple_proxy_info_get_type(const PurpleProxyInfo *info);
140 * Returns the proxy's host.
142 * @param info The proxy information.
146 const char *purple_proxy_info_get_host(const PurpleProxyInfo *info);
149 * Returns the proxy's port.
151 * @param info The proxy information.
155 int purple_proxy_info_get_port(const PurpleProxyInfo *info);
158 * Returns the proxy's username.
160 * @param info The proxy information.
162 * @return The username.
164 const char *purple_proxy_info_get_username(const PurpleProxyInfo *info);
167 * Returns the proxy's password.
169 * @param info The proxy information.
171 * @return The password.
173 const char *purple_proxy_info_get_password(const PurpleProxyInfo *info);
177 /**************************************************************************/
178 /** @name Global Proxy API */
179 /**************************************************************************/
183 * Returns purple's global proxy information.
185 * @return The global proxy information.
187 PurpleProxyInfo *purple_global_proxy_get_info(void);
190 * Set purple's global proxy information.
192 * @param info The proxy information.
195 void purple_global_proxy_set_info(PurpleProxyInfo *info);
199 /**************************************************************************/
200 /** @name Proxy API */
201 /**************************************************************************/
205 * Returns the proxy subsystem handle.
207 * @return The proxy subsystem handle.
209 void *purple_proxy_get_handle(void);
212 * Initializes the proxy subsystem.
214 void purple_proxy_init(void);
217 * Uninitializes the proxy subsystem.
219 void purple_proxy_uninit(void);
222 * Returns configuration of a proxy.
224 * @param account The account for which the configuration is needed.
226 * @return The configuration of a proxy.
228 PurpleProxyInfo *purple_proxy_get_setup(PurpleAccount *account);
231 * Makes a connection to the specified host and port. Note that this
232 * function name can be misleading--although it is called "proxy
233 * connect," it is used for establishing any outgoing TCP connection,
234 * whether through a proxy or not.
236 * @param handle A handle that should be associated with this
237 * connection attempt. The handle can be used
238 * to cancel the connection attempt using the
239 * purple_proxy_connect_cancel_with_handle()
241 * @param account The account making the connection.
242 * @param host The destination host.
243 * @param port The destination port.
244 * @param connect_cb The function to call when the connection is
245 * established. If the connection failed then
246 * fd will be -1 and error message will be set
247 * to something descriptive (hopefully).
248 * @param data User-defined data.
250 * @return NULL if there was an error, or a reference to an
251 * opaque data structure that can be used to cancel
252 * the pending connection, if needed.
254 PurpleProxyConnectData *purple_proxy_connect(void *handle,
255 PurpleAccount *account,
256 const char *host, int port,
257 PurpleProxyConnectFunction connect_cb, gpointer data);
260 * Makes a connection to the specified host and port. Note that this
261 * function name can be misleading--although it is called "proxy
262 * connect," it is used for establishing any outgoing UDP connection,
263 * whether through a proxy or not.
265 * @param handle A handle that should be associated with this
266 * connection attempt. The handle can be used
267 * to cancel the connection attempt using the
268 * purple_proxy_connect_cancel_with_handle()
270 * @param account The account making the connection.
271 * @param host The destination host.
272 * @param port The destination port.
273 * @param connect_cb The function to call when the connection is
274 * established. If the connection failed then
275 * fd will be -1 and error message will be set
276 * to something descriptive (hopefully).
277 * @param data User-defined data.
279 * @return NULL if there was an error, or a reference to an
280 * opaque data structure that can be used to cancel
281 * the pending connection, if needed.
283 PurpleProxyConnectData *purple_proxy_connect_udp(void *handle,
284 PurpleAccount *account,
285 const char *host, int port,
286 PurpleProxyConnectFunction connect_cb, gpointer data);
289 * Makes a connection through a SOCKS5 proxy.
291 * @param handle A handle that should be associated with this
292 * connection attempt. The handle can be used
293 * to cancel the connection attempt using the
294 * purple_proxy_connect_cancel_with_handle()
296 * @param gpi The PurpleProxyInfo specifying the proxy settings
297 * @param host The destination host.
298 * @param port The destination port.
299 * @param connect_cb The function to call when the connection is
300 * established. If the connection failed then
301 * fd will be -1 and error message will be set
302 * to something descriptive (hopefully).
303 * @param data User-defined data.
305 * @return NULL if there was an error, or a reference to an
306 * opaque data structure that can be used to cancel
307 * the pending connection, if needed.
309 PurpleProxyConnectData *purple_proxy_connect_socks5(void *handle,
310 PurpleProxyInfo *gpi,
311 const char *host, int port,
312 PurpleProxyConnectFunction connect_cb, gpointer data);
315 * Cancel an in-progress connection attempt. This should be called
316 * by the PRPL if the user disables an account while it is still
317 * performing the initial sign on. Or when establishing a file
318 * transfer, if we attempt to connect to a remote user but they
319 * are behind a firewall then the PRPL can cancel the connection
320 * attempt early rather than just letting the OS's TCP/IP stack
321 * time-out the connection.
323 void purple_proxy_connect_cancel(PurpleProxyConnectData *connect_data);
326 * Closes all proxy connections registered with the specified handle.
328 * @param handle The handle.
330 void purple_proxy_connect_cancel_with_handle(void *handle);
338 #endif /* _PURPLE_PROXY_H_ */