|
Evan@653
|
1 |
/** |
|
Evan@653
|
2 |
* @file proxy.h Proxy API |
|
Evan@653
|
3 |
* @ingroup core |
|
Evan@653
|
4 |
*/ |
|
Evan@653
|
5 |
|
|
Evan@653
|
6 |
/* purple |
|
Evan@653
|
7 |
* |
|
Evan@653
|
8 |
* Purple is the legal property of its developers, whose names are too numerous |
|
Evan@653
|
9 |
* to list here. Please refer to the COPYRIGHT file distributed with this |
|
Evan@653
|
10 |
* source distribution. |
|
Evan@653
|
11 |
* |
|
Evan@653
|
12 |
* This program is free software; you can redistribute it and/or modify |
|
Evan@653
|
13 |
* it under the terms of the GNU General Public License as published by |
|
Evan@653
|
14 |
* the Free Software Foundation; either version 2 of the License, or |
|
Evan@653
|
15 |
* (at your option) any later version. |
|
Evan@653
|
16 |
* |
|
Evan@653
|
17 |
* This program is distributed in the hope that it will be useful, |
|
Evan@653
|
18 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
Evan@653
|
19 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
Evan@653
|
20 |
* GNU General Public License for more details. |
|
Evan@653
|
21 |
* |
|
Evan@653
|
22 |
* You should have received a copy of the GNU General Public License |
|
Evan@653
|
23 |
* along with this program; if not, write to the Free Software |
|
Evan@653
|
24 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
|
Evan@653
|
25 |
*/ |
|
Evan@653
|
26 |
#ifndef _PURPLE_PROXY_H_ |
|
Evan@653
|
27 |
#define _PURPLE_PROXY_H_ |
|
Evan@653
|
28 |
|
|
Evan@653
|
29 |
#include <glib.h> |
|
Evan@653
|
30 |
#include "eventloop.h" |
|
Evan@653
|
31 |
|
|
Evan@653
|
32 |
/** |
|
Evan@653
|
33 |
* A type of proxy connection. |
|
Evan@653
|
34 |
*/ |
|
Evan@653
|
35 |
typedef enum |
|
Evan@653
|
36 |
{ |
|
Evan@653
|
37 |
PURPLE_PROXY_USE_GLOBAL = -1, /**< Use the global proxy information. */ |
|
Evan@653
|
38 |
PURPLE_PROXY_NONE = 0, /**< No proxy. */ |
|
Evan@653
|
39 |
PURPLE_PROXY_HTTP, /**< HTTP proxy. */ |
|
Evan@653
|
40 |
PURPLE_PROXY_SOCKS4, /**< SOCKS 4 proxy. */ |
|
Evan@653
|
41 |
PURPLE_PROXY_SOCKS5, /**< SOCKS 5 proxy. */ |
|
Evan@653
|
42 |
PURPLE_PROXY_USE_ENVVAR /**< Use environmental settings. */ |
|
Evan@653
|
43 |
|
|
Evan@653
|
44 |
} PurpleProxyType; |
|
Evan@653
|
45 |
|
|
Evan@653
|
46 |
/** |
|
Evan@653
|
47 |
* Information on proxy settings. |
|
Evan@653
|
48 |
*/ |
|
Evan@653
|
49 |
typedef struct |
|
Evan@653
|
50 |
{ |
|
Evan@653
|
51 |
PurpleProxyType type; /**< The proxy type. */ |
|
Evan@653
|
52 |
|
|
Evan@653
|
53 |
char *host; /**< The host. */ |
|
Evan@653
|
54 |
int port; /**< The port number. */ |
|
Evan@653
|
55 |
char *username; /**< The username. */ |
|
Evan@653
|
56 |
char *password; /**< The password. */ |
|
Evan@653
|
57 |
|
|
Evan@653
|
58 |
} PurpleProxyInfo; |
|
Evan@653
|
59 |
|
|
Evan@653
|
60 |
typedef struct _PurpleProxyConnectData PurpleProxyConnectData; |
|
Evan@653
|
61 |
|
|
Evan@653
|
62 |
typedef void (*PurpleProxyConnectFunction)(gpointer data, gint source, const gchar *error_message); |
|
Evan@653
|
63 |
|
|
Evan@653
|
64 |
|
|
Evan@653
|
65 |
#include "account.h" |
|
Evan@653
|
66 |
|
|
Evan@653
|
67 |
#ifdef __cplusplus |
|
Evan@653
|
68 |
extern "C" { |
|
Evan@653
|
69 |
#endif |
|
Evan@653
|
70 |
|
|
Evan@653
|
71 |
/**************************************************************************/ |
|
Evan@653
|
72 |
/** @name Proxy structure API */ |
|
Evan@653
|
73 |
/**************************************************************************/ |
|
Evan@653
|
74 |
/*@{*/ |
|
Evan@653
|
75 |
|
|
Evan@653
|
76 |
/** |
|
Evan@653
|
77 |
* Creates a proxy information structure. |
|
Evan@653
|
78 |
* |
|
Evan@653
|
79 |
* @return The proxy information structure. |
|
Evan@653
|
80 |
*/ |
|
Evan@653
|
81 |
PurpleProxyInfo *purple_proxy_info_new(void); |
|
Evan@653
|
82 |
|
|
Evan@653
|
83 |
/** |
|
Evan@653
|
84 |
* Destroys a proxy information structure. |
|
Evan@653
|
85 |
* |
|
Evan@653
|
86 |
* @param info The proxy information structure to destroy. |
|
Evan@653
|
87 |
*/ |
|
Evan@653
|
88 |
void purple_proxy_info_destroy(PurpleProxyInfo *info); |
|
Evan@653
|
89 |
|
|
Evan@653
|
90 |
/** |
|
Evan@653
|
91 |
* Sets the type of proxy. |
|
Evan@653
|
92 |
* |
|
Evan@653
|
93 |
* @param info The proxy information. |
|
Evan@653
|
94 |
* @param type The proxy type. |
|
Evan@653
|
95 |
*/ |
|
Evan@653
|
96 |
void purple_proxy_info_set_type(PurpleProxyInfo *info, PurpleProxyType type); |
|
Evan@653
|
97 |
|
|
Evan@653
|
98 |
/** |
|
Evan@653
|
99 |
* Sets the proxy host. |
|
Evan@653
|
100 |
* |
|
Evan@653
|
101 |
* @param info The proxy information. |
|
Evan@653
|
102 |
* @param host The host. |
|
Evan@653
|
103 |
*/ |
|
Evan@653
|
104 |
void purple_proxy_info_set_host(PurpleProxyInfo *info, const char *host); |
|
Evan@653
|
105 |
|
|
Evan@653
|
106 |
/** |
|
Evan@653
|
107 |
* Sets the proxy port. |
|
Evan@653
|
108 |
* |
|
Evan@653
|
109 |
* @param info The proxy information. |
|
Evan@653
|
110 |
* @param port The port. |
|
Evan@653
|
111 |
*/ |
|
Evan@653
|
112 |
void purple_proxy_info_set_port(PurpleProxyInfo *info, int port); |
|
Evan@653
|
113 |
|
|
Evan@653
|
114 |
/** |
|
Evan@653
|
115 |
* Sets the proxy username. |
|
Evan@653
|
116 |
* |
|
Evan@653
|
117 |
* @param info The proxy information. |
|
Evan@653
|
118 |
* @param username The username. |
|
Evan@653
|
119 |
*/ |
|
Evan@653
|
120 |
void purple_proxy_info_set_username(PurpleProxyInfo *info, const char *username); |
|
Evan@653
|
121 |
|
|
Evan@653
|
122 |
/** |
|
Evan@653
|
123 |
* Sets the proxy password. |
|
Evan@653
|
124 |
* |
|
Evan@653
|
125 |
* @param info The proxy information. |
|
Evan@653
|
126 |
* @param password The password. |
|
Evan@653
|
127 |
*/ |
|
Evan@653
|
128 |
void purple_proxy_info_set_password(PurpleProxyInfo *info, const char *password); |
|
Evan@653
|
129 |
|
|
Evan@653
|
130 |
/** |
|
Evan@653
|
131 |
* Returns the proxy's type. |
|
Evan@653
|
132 |
* |
|
Evan@653
|
133 |
* @param info The proxy information. |
|
Evan@653
|
134 |
* |
|
Evan@653
|
135 |
* @return The type. |
|
Evan@653
|
136 |
*/ |
|
Evan@653
|
137 |
PurpleProxyType purple_proxy_info_get_type(const PurpleProxyInfo *info); |
|
Evan@653
|
138 |
|
|
Evan@653
|
139 |
/** |
|
Evan@653
|
140 |
* Returns the proxy's host. |
|
Evan@653
|
141 |
* |
|
Evan@653
|
142 |
* @param info The proxy information. |
|
Evan@653
|
143 |
* |
|
Evan@653
|
144 |
* @return The host. |
|
Evan@653
|
145 |
*/ |
|
Evan@653
|
146 |
const char *purple_proxy_info_get_host(const PurpleProxyInfo *info); |
|
Evan@653
|
147 |
|
|
Evan@653
|
148 |
/** |
|
Evan@653
|
149 |
* Returns the proxy's port. |
|
Evan@653
|
150 |
* |
|
Evan@653
|
151 |
* @param info The proxy information. |
|
Evan@653
|
152 |
* |
|
Evan@653
|
153 |
* @return The port. |
|
Evan@653
|
154 |
*/ |
|
Evan@653
|
155 |
int purple_proxy_info_get_port(const PurpleProxyInfo *info); |
|
Evan@653
|
156 |
|
|
Evan@653
|
157 |
/** |
|
Evan@653
|
158 |
* Returns the proxy's username. |
|
Evan@653
|
159 |
* |
|
Evan@653
|
160 |
* @param info The proxy information. |
|
Evan@653
|
161 |
* |
|
Evan@653
|
162 |
* @return The username. |
|
Evan@653
|
163 |
*/ |
|
Evan@653
|
164 |
const char *purple_proxy_info_get_username(const PurpleProxyInfo *info); |
|
Evan@653
|
165 |
|
|
Evan@653
|
166 |
/** |
|
Evan@653
|
167 |
* Returns the proxy's password. |
|
Evan@653
|
168 |
* |
|
Evan@653
|
169 |
* @param info The proxy information. |
|
Evan@653
|
170 |
* |
|
Evan@653
|
171 |
* @return The password. |
|
Evan@653
|
172 |
*/ |
|
Evan@653
|
173 |
const char *purple_proxy_info_get_password(const PurpleProxyInfo *info); |
|
Evan@653
|
174 |
|
|
Evan@653
|
175 |
/*@}*/ |
|
Evan@653
|
176 |
|
|
Evan@653
|
177 |
/**************************************************************************/ |
|
Evan@653
|
178 |
/** @name Global Proxy API */ |
|
Evan@653
|
179 |
/**************************************************************************/ |
|
Evan@653
|
180 |
/*@{*/ |
|
Evan@653
|
181 |
|
|
Evan@653
|
182 |
/** |
|
Evan@653
|
183 |
* Returns purple's global proxy information. |
|
Evan@653
|
184 |
* |
|
Evan@653
|
185 |
* @return The global proxy information. |
|
Evan@653
|
186 |
*/ |
|
Evan@653
|
187 |
PurpleProxyInfo *purple_global_proxy_get_info(void); |
|
Evan@653
|
188 |
|
|
Evan@1427
|
189 |
/** |
|
Evan@1427
|
190 |
* Set purple's global proxy information. |
|
Evan@1427
|
191 |
* |
|
Evan@1427
|
192 |
* @param info The proxy information. |
|
Evan@1427
|
193 |
* @since 2.6.0 |
|
Evan@1427
|
194 |
*/ |
|
Evan@1427
|
195 |
void purple_global_proxy_set_info(PurpleProxyInfo *info); |
|
Evan@1427
|
196 |
|
|
Evan@653
|
197 |
/*@}*/ |
|
Evan@653
|
198 |
|
|
Evan@653
|
199 |
/**************************************************************************/ |
|
Evan@653
|
200 |
/** @name Proxy API */ |
|
Evan@653
|
201 |
/**************************************************************************/ |
|
Evan@653
|
202 |
/*@{*/ |
|
Evan@653
|
203 |
|
|
Evan@653
|
204 |
/** |
|
Evan@653
|
205 |
* Returns the proxy subsystem handle. |
|
Evan@653
|
206 |
* |
|
Evan@653
|
207 |
* @return The proxy subsystem handle. |
|
Evan@653
|
208 |
*/ |
|
Evan@653
|
209 |
void *purple_proxy_get_handle(void); |
|
Evan@653
|
210 |
|
|
Evan@653
|
211 |
/** |
|
Evan@653
|
212 |
* Initializes the proxy subsystem. |
|
Evan@653
|
213 |
*/ |
|
Evan@653
|
214 |
void purple_proxy_init(void); |
|
Evan@653
|
215 |
|
|
Evan@653
|
216 |
/** |
|
Evan@653
|
217 |
* Uninitializes the proxy subsystem. |
|
Evan@653
|
218 |
*/ |
|
Evan@653
|
219 |
void purple_proxy_uninit(void); |
|
Evan@653
|
220 |
|
|
Evan@653
|
221 |
/** |
|
Evan@653
|
222 |
* Returns configuration of a proxy. |
|
Evan@653
|
223 |
* |
|
Evan@653
|
224 |
* @param account The account for which the configuration is needed. |
|
Evan@653
|
225 |
* |
|
Evan@653
|
226 |
* @return The configuration of a proxy. |
|
Evan@653
|
227 |
*/ |
|
Evan@653
|
228 |
PurpleProxyInfo *purple_proxy_get_setup(PurpleAccount *account); |
|
Evan@653
|
229 |
|
|
Evan@653
|
230 |
/** |
|
Evan@653
|
231 |
* Makes a connection to the specified host and port. Note that this |
|
Evan@653
|
232 |
* function name can be misleading--although it is called "proxy |
|
Evan@653
|
233 |
* connect," it is used for establishing any outgoing TCP connection, |
|
Evan@653
|
234 |
* whether through a proxy or not. |
|
Evan@653
|
235 |
* |
|
Evan@653
|
236 |
* @param handle A handle that should be associated with this |
|
Evan@653
|
237 |
* connection attempt. The handle can be used |
|
Evan@653
|
238 |
* to cancel the connection attempt using the |
|
Evan@653
|
239 |
* purple_proxy_connect_cancel_with_handle() |
|
Evan@653
|
240 |
* function. |
|
Evan@653
|
241 |
* @param account The account making the connection. |
|
Evan@653
|
242 |
* @param host The destination host. |
|
Evan@653
|
243 |
* @param port The destination port. |
|
Evan@653
|
244 |
* @param connect_cb The function to call when the connection is |
|
Evan@653
|
245 |
* established. If the connection failed then |
|
Evan@653
|
246 |
* fd will be -1 and error message will be set |
|
Evan@653
|
247 |
* to something descriptive (hopefully). |
|
Evan@653
|
248 |
* @param data User-defined data. |
|
Evan@653
|
249 |
* |
|
Evan@653
|
250 |
* @return NULL if there was an error, or a reference to an |
|
Evan@653
|
251 |
* opaque data structure that can be used to cancel |
|
Evan@653
|
252 |
* the pending connection, if needed. |
|
Evan@653
|
253 |
*/ |
|
Evan@653
|
254 |
PurpleProxyConnectData *purple_proxy_connect(void *handle, |
|
Evan@653
|
255 |
PurpleAccount *account, |
|
Evan@653
|
256 |
const char *host, int port, |
|
Evan@653
|
257 |
PurpleProxyConnectFunction connect_cb, gpointer data); |
|
Evan@653
|
258 |
|
|
Evan@653
|
259 |
/** |
|
zacw@2490
|
260 |
* Makes a connection to the specified host and port. Note that this |
|
zacw@2490
|
261 |
* function name can be misleading--although it is called "proxy |
|
zacw@2490
|
262 |
* connect," it is used for establishing any outgoing UDP connection, |
|
zacw@2490
|
263 |
* whether through a proxy or not. |
|
zacw@2490
|
264 |
* |
|
zacw@2490
|
265 |
* @param handle A handle that should be associated with this |
|
zacw@2490
|
266 |
* connection attempt. The handle can be used |
|
zacw@2490
|
267 |
* to cancel the connection attempt using the |
|
zacw@2490
|
268 |
* purple_proxy_connect_cancel_with_handle() |
|
zacw@2490
|
269 |
* function. |
|
zacw@2490
|
270 |
* @param account The account making the connection. |
|
zacw@2490
|
271 |
* @param host The destination host. |
|
zacw@2490
|
272 |
* @param port The destination port. |
|
zacw@2490
|
273 |
* @param connect_cb The function to call when the connection is |
|
zacw@2490
|
274 |
* established. If the connection failed then |
|
zacw@2490
|
275 |
* fd will be -1 and error message will be set |
|
zacw@2490
|
276 |
* to something descriptive (hopefully). |
|
zacw@2490
|
277 |
* @param data User-defined data. |
|
zacw@2490
|
278 |
* |
|
zacw@2490
|
279 |
* @return NULL if there was an error, or a reference to an |
|
zacw@2490
|
280 |
* opaque data structure that can be used to cancel |
|
zacw@2490
|
281 |
* the pending connection, if needed. |
|
zacw@2490
|
282 |
*/ |
|
zacw@2490
|
283 |
PurpleProxyConnectData *purple_proxy_connect_udp(void *handle, |
|
zacw@2490
|
284 |
PurpleAccount *account, |
|
zacw@2490
|
285 |
const char *host, int port, |
|
zacw@2490
|
286 |
PurpleProxyConnectFunction connect_cb, gpointer data); |
|
zacw@2490
|
287 |
|
|
zacw@2490
|
288 |
/** |
|
Evan@653
|
289 |
* Makes a connection through a SOCKS5 proxy. |
|
Evan@653
|
290 |
* |
|
Evan@653
|
291 |
* @param handle A handle that should be associated with this |
|
Evan@653
|
292 |
* connection attempt. The handle can be used |
|
Evan@653
|
293 |
* to cancel the connection attempt using the |
|
Evan@653
|
294 |
* purple_proxy_connect_cancel_with_handle() |
|
Evan@653
|
295 |
* function. |
|
Evan@653
|
296 |
* @param gpi The PurpleProxyInfo specifying the proxy settings |
|
Evan@653
|
297 |
* @param host The destination host. |
|
Evan@653
|
298 |
* @param port The destination port. |
|
Evan@653
|
299 |
* @param connect_cb The function to call when the connection is |
|
Evan@653
|
300 |
* established. If the connection failed then |
|
Evan@653
|
301 |
* fd will be -1 and error message will be set |
|
Evan@653
|
302 |
* to something descriptive (hopefully). |
|
Evan@653
|
303 |
* @param data User-defined data. |
|
Evan@653
|
304 |
* |
|
Evan@653
|
305 |
* @return NULL if there was an error, or a reference to an |
|
Evan@653
|
306 |
* opaque data structure that can be used to cancel |
|
Evan@653
|
307 |
* the pending connection, if needed. |
|
Evan@653
|
308 |
*/ |
|
Evan@653
|
309 |
PurpleProxyConnectData *purple_proxy_connect_socks5(void *handle, |
|
Evan@653
|
310 |
PurpleProxyInfo *gpi, |
|
Evan@653
|
311 |
const char *host, int port, |
|
Evan@653
|
312 |
PurpleProxyConnectFunction connect_cb, gpointer data); |
|
Evan@653
|
313 |
|
|
Evan@653
|
314 |
/** |
|
Evan@653
|
315 |
* Cancel an in-progress connection attempt. This should be called |
|
Evan@653
|
316 |
* by the PRPL if the user disables an account while it is still |
|
Evan@653
|
317 |
* performing the initial sign on. Or when establishing a file |
|
Evan@653
|
318 |
* transfer, if we attempt to connect to a remote user but they |
|
Evan@653
|
319 |
* are behind a firewall then the PRPL can cancel the connection |
|
Evan@653
|
320 |
* attempt early rather than just letting the OS's TCP/IP stack |
|
Evan@653
|
321 |
* time-out the connection. |
|
Evan@653
|
322 |
*/ |
|
Evan@653
|
323 |
void purple_proxy_connect_cancel(PurpleProxyConnectData *connect_data); |
|
Evan@653
|
324 |
|
|
Evan@653
|
325 |
/* |
|
Evan@653
|
326 |
* Closes all proxy connections registered with the specified handle. |
|
Evan@653
|
327 |
* |
|
Evan@653
|
328 |
* @param handle The handle. |
|
Evan@653
|
329 |
*/ |
|
Evan@653
|
330 |
void purple_proxy_connect_cancel_with_handle(void *handle); |
|
Evan@653
|
331 |
|
|
Evan@653
|
332 |
/*@}*/ |
|
Evan@653
|
333 |
|
|
Evan@653
|
334 |
#ifdef __cplusplus |
|
Evan@653
|
335 |
} |
|
Evan@653
|
336 |
#endif |
|
Evan@653
|
337 |
|
|
Evan@653
|
338 |
#endif /* _PURPLE_PROXY_H_ */ |