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