libpurple/proxy.c

changeset 41318
56092ffeae95
parent 41211
2e804c9c0919
child 41657
c68748c1f42e
equal deleted inserted replaced
41317:fa45763d9c71 41318:56092ffeae95
31 #include "util.h" 31 #include "util.h"
32 32
33 #include <gio/gio.h> 33 #include <gio/gio.h>
34 #include <libsoup/soup.h> 34 #include <libsoup/soup.h>
35 35
36 struct _PurpleProxyInfo
37 {
38 PurpleProxyType type; /* The proxy type. */
39
40 char *host; /* The host. */
41 int port; /* The port number. */
42 char *username; /* The username. */
43 char *password; /* The password. */
44 };
45
46 static PurpleProxyInfo *global_proxy_info = NULL; 36 static PurpleProxyInfo *global_proxy_info = NULL;
47
48 /**************************************************************************
49 * Proxy structure API
50 **************************************************************************/
51 PurpleProxyInfo *
52 purple_proxy_info_new(void)
53 {
54 return g_new0(PurpleProxyInfo, 1);
55 }
56
57 static PurpleProxyInfo *
58 purple_proxy_info_copy(PurpleProxyInfo *info)
59 {
60 PurpleProxyInfo *copy;
61
62 g_return_val_if_fail(info != NULL, NULL);
63
64 copy = purple_proxy_info_new();
65 copy->type = info->type;
66 copy->host = g_strdup(info->host);
67 copy->port = info->port;
68 copy->username = g_strdup(info->username);
69 copy->password = g_strdup(info->password);
70
71 return copy;
72 }
73
74 void
75 purple_proxy_info_destroy(PurpleProxyInfo *info)
76 {
77 g_return_if_fail(info != NULL);
78
79 g_free(info->host);
80 g_free(info->username);
81 g_free(info->password);
82
83 g_free(info);
84 }
85
86 void
87 purple_proxy_info_set_proxy_type(PurpleProxyInfo *info, PurpleProxyType type)
88 {
89 g_return_if_fail(info != NULL);
90
91 info->type = type;
92 }
93
94 void
95 purple_proxy_info_set_host(PurpleProxyInfo *info, const char *host)
96 {
97 g_return_if_fail(info != NULL);
98
99 g_free(info->host);
100 info->host = g_strdup(host);
101 }
102
103 void
104 purple_proxy_info_set_port(PurpleProxyInfo *info, int port)
105 {
106 g_return_if_fail(info != NULL);
107
108 info->port = port;
109 }
110
111 void
112 purple_proxy_info_set_username(PurpleProxyInfo *info, const char *username)
113 {
114 g_return_if_fail(info != NULL);
115
116 g_free(info->username);
117 info->username = g_strdup(username);
118 }
119
120 void
121 purple_proxy_info_set_password(PurpleProxyInfo *info, const char *password)
122 {
123 g_return_if_fail(info != NULL);
124
125 g_free(info->password);
126 info->password = g_strdup(password);
127 }
128
129 PurpleProxyType
130 purple_proxy_info_get_proxy_type(const PurpleProxyInfo *info)
131 {
132 g_return_val_if_fail(info != NULL, PURPLE_PROXY_NONE);
133
134 return info->type;
135 }
136
137 const char *
138 purple_proxy_info_get_host(const PurpleProxyInfo *info)
139 {
140 g_return_val_if_fail(info != NULL, NULL);
141
142 return info->host;
143 }
144
145 int
146 purple_proxy_info_get_port(const PurpleProxyInfo *info)
147 {
148 g_return_val_if_fail(info != NULL, 0);
149
150 return info->port;
151 }
152
153 const char *
154 purple_proxy_info_get_username(const PurpleProxyInfo *info)
155 {
156 g_return_val_if_fail(info != NULL, NULL);
157
158 return info->username;
159 }
160
161 const char *
162 purple_proxy_info_get_password(const PurpleProxyInfo *info)
163 {
164 g_return_val_if_fail(info != NULL, NULL);
165
166 return info->password;
167 }
168
169 G_DEFINE_BOXED_TYPE(PurpleProxyInfo, purple_proxy_info,
170 purple_proxy_info_copy, purple_proxy_info_destroy);
171 37
172 /************************************************************************** 38 /**************************************************************************
173 * Global Proxy API 39 * Global Proxy API
174 **************************************************************************/ 40 **************************************************************************/
175 PurpleProxyInfo * 41 PurpleProxyInfo *
181 void 47 void
182 purple_global_proxy_set_info(PurpleProxyInfo *info) 48 purple_global_proxy_set_info(PurpleProxyInfo *info)
183 { 49 {
184 g_return_if_fail(info != NULL); 50 g_return_if_fail(info != NULL);
185 51
186 purple_proxy_info_destroy(global_proxy_info); 52 g_clear_object(&global_proxy_info);
187 53
188 global_proxy_info = info; 54 global_proxy_info = info;
189 } 55 }
190
191
192 /* index in gproxycmds below, keep them in sync */
193 #define GNOME_PROXY_MODE 0
194 #define GNOME_PROXY_USE_SAME_PROXY 1
195 #define GNOME_PROXY_SOCKS_HOST 2
196 #define GNOME_PROXY_SOCKS_PORT 3
197 #define GNOME_PROXY_HTTP_HOST 4
198 #define GNOME_PROXY_HTTP_PORT 5
199 #define GNOME_PROXY_HTTP_USER 6
200 #define GNOME_PROXY_HTTP_PASS 7
201 #define GNOME2_CMDS 0
202 #define GNOME3_CMDS 1
203
204 /* detect proxy settings for gnome2/gnome3 */
205 static const char* gproxycmds[][2] = {
206 { "gconftool-2 -g /system/proxy/mode" , "gsettings get org.gnome.system.proxy mode" },
207 { "gconftool-2 -g /system/http_proxy/use_same_proxy", "gsettings get org.gnome.system.proxy use-same-proxy" },
208 { "gconftool-2 -g /system/proxy/socks_host", "gsettings get org.gnome.system.proxy.socks host" },
209 { "gconftool-2 -g /system/proxy/socks_port", "gsettings get org.gnome.system.proxy.socks port" },
210 { "gconftool-2 -g /system/http_proxy/host", "gsettings get org.gnome.system.proxy.http host" },
211 { "gconftool-2 -g /system/http_proxy/port", "gsettings get org.gnome.system.proxy.http port"},
212 { "gconftool-2 -g /system/http_proxy/authentication_user", "gsettings get org.gnome.system.proxy.http authentication-user" },
213 { "gconftool-2 -g /system/http_proxy/authentication_password", "gsettings get org.gnome.system.proxy.http authentication-password" },
214 };
215
216 /*
217 * purple_gnome_proxy_get_parameter:
218 * @parameter: One of the GNOME_PROXY_x constants defined above
219 * @gnome_version: GNOME2_CMDS or GNOME3_CMDS
220 *
221 * This is a utility function used to retrieve proxy parameter values from
222 * GNOME 2/3 environment.
223 *
224 * Returns: The value of requested proxy parameter
225 */
226 static char *
227 purple_gnome_proxy_get_parameter(guint8 parameter, guint8 gnome_version)
228 {
229 gchar *param, *err;
230 size_t param_len;
231
232 if (parameter > GNOME_PROXY_HTTP_PASS)
233 return NULL;
234 if (gnome_version > GNOME3_CMDS)
235 return NULL;
236
237 if (!g_spawn_command_line_sync(gproxycmds[parameter][gnome_version],
238 &param, &err, NULL, NULL))
239 return NULL;
240 g_free(err);
241
242 g_strstrip(param);
243 if (param[0] == '\'' || param[0] == '\"') {
244 param_len = strlen(param);
245 memmove(param, param + 1, param_len); /* copy last \0 too */
246 --param_len;
247 if (param_len > 0 && (param[param_len - 1] == '\'' || param[param_len - 1] == '\"'))
248 param[param_len - 1] = '\0';
249 g_strstrip(param);
250 }
251
252 return param;
253 }
254
255 static PurpleProxyInfo *
256 purple_gnome_proxy_get_info(void)
257 {
258 static PurpleProxyInfo info = {0, NULL, 0, NULL, NULL};
259 gboolean use_same_proxy = FALSE;
260 gchar *tmp;
261 guint8 gnome_version = GNOME3_CMDS;
262
263 tmp = g_find_program_in_path("gsettings");
264 if (tmp == NULL) {
265 tmp = g_find_program_in_path("gconftool-2");
266 gnome_version = GNOME2_CMDS;
267 }
268 if (tmp == NULL)
269 return purple_global_proxy_get_info();
270
271 g_free(tmp);
272
273 /* Check whether to use a proxy. */
274 tmp = purple_gnome_proxy_get_parameter(GNOME_PROXY_MODE, gnome_version);
275 if (!tmp)
276 return purple_global_proxy_get_info();
277
278 if (purple_strequal(tmp, "none")) {
279 info.type = PURPLE_PROXY_NONE;
280 g_free(tmp);
281 return &info;
282 }
283
284 if (!purple_strequal(tmp, "manual")) {
285 /* Unknown setting. Fallback to using our global proxy settings. */
286 g_free(tmp);
287 return purple_global_proxy_get_info();
288 }
289
290 g_free(tmp);
291
292 /* Free the old fields */
293 g_free(info.host);
294 info.host = NULL;
295 g_free(info.username);
296 info.username = NULL;
297 g_free(info.password);
298 info.password = NULL;
299
300 tmp = purple_gnome_proxy_get_parameter(GNOME_PROXY_USE_SAME_PROXY, gnome_version);
301 if (!tmp)
302 return purple_global_proxy_get_info();
303
304 if (purple_strequal(tmp, "true"))
305 use_same_proxy = TRUE;
306
307 g_free(tmp);
308
309 if (!use_same_proxy) {
310 info.host = purple_gnome_proxy_get_parameter(GNOME_PROXY_SOCKS_HOST, gnome_version);
311 if (!info.host)
312 return purple_global_proxy_get_info();
313 }
314
315 if (!use_same_proxy && (info.host != NULL) && (*info.host != '\0')) {
316 info.type = PURPLE_PROXY_SOCKS5;
317 tmp = purple_gnome_proxy_get_parameter(GNOME_PROXY_SOCKS_PORT, gnome_version);
318 if (!tmp) {
319 g_free(info.host);
320 info.host = NULL;
321 return purple_global_proxy_get_info();
322 }
323 info.port = atoi(tmp);
324 g_free(tmp);
325 } else {
326 g_free(info.host);
327 info.host = purple_gnome_proxy_get_parameter(GNOME_PROXY_HTTP_HOST, gnome_version);
328 if (!info.host)
329 return purple_global_proxy_get_info();
330
331 /* If we get this far then we know we're using an HTTP proxy */
332 info.type = PURPLE_PROXY_HTTP;
333
334 if (*info.host == '\0')
335 {
336 purple_debug_info("proxy", "Gnome proxy settings are set to "
337 "'manual' but no suitable proxy server is specified. Using "
338 "Pidgin's proxy settings instead.\n");
339 g_free(info.host);
340 info.host = NULL;
341 return purple_global_proxy_get_info();
342 }
343
344 info.username = purple_gnome_proxy_get_parameter(GNOME_PROXY_HTTP_USER, gnome_version);
345 if (!info.username)
346 {
347 g_free(info.host);
348 info.host = NULL;
349 return purple_global_proxy_get_info();
350 }
351
352 info.password = purple_gnome_proxy_get_parameter(GNOME_PROXY_HTTP_PASS, gnome_version);
353 if (!info.password)
354 {
355 g_free(info.host);
356 info.host = NULL;
357 g_free(info.username);
358 info.username = NULL;
359 return purple_global_proxy_get_info();
360 }
361
362 tmp = purple_gnome_proxy_get_parameter(GNOME_PROXY_HTTP_PORT, gnome_version);
363 if (!tmp)
364 {
365 g_free(info.host);
366 info.host = NULL;
367 g_free(info.username);
368 info.username = NULL;
369 g_free(info.password);
370 info.password = NULL;
371 return purple_global_proxy_get_info();
372 }
373 info.port = atoi(tmp);
374 g_free(tmp);
375 }
376
377 return &info;
378 }
379
380 #ifdef _WIN32
381
382 typedef BOOL (CALLBACK* LPFNWINHTTPGETIEPROXYCONFIG)(/*IN OUT*/ WINHTTP_CURRENT_USER_IE_PROXY_CONFIG* pProxyConfig);
383
384 /* This modifies "host" in-place evilly */
385 static void
386 _proxy_fill_hostinfo(PurpleProxyInfo *info, char *host, int default_port)
387 {
388 int port = default_port;
389 char *d;
390
391 d = g_strrstr(host, ":");
392 if (d) {
393 *d = '\0';
394
395 d++;
396 if (*d)
397 sscanf(d, "%d", &port);
398
399 if (port == 0)
400 port = default_port;
401 }
402
403 purple_proxy_info_set_host(info, host);
404 purple_proxy_info_set_port(info, port);
405 }
406
407 static PurpleProxyInfo *
408 purple_win32_proxy_get_info(void)
409 {
410 static LPFNWINHTTPGETIEPROXYCONFIG MyWinHttpGetIEProxyConfig = NULL;
411 static gboolean loaded = FALSE;
412 static PurpleProxyInfo info = {0, NULL, 0, NULL, NULL};
413
414 WINHTTP_CURRENT_USER_IE_PROXY_CONFIG ie_proxy_config;
415
416 if (!loaded) {
417 loaded = TRUE;
418 MyWinHttpGetIEProxyConfig = (LPFNWINHTTPGETIEPROXYCONFIG)
419 wpurple_find_and_loadproc("winhttp.dll", "WinHttpGetIEProxyConfigForCurrentUser");
420 if (!MyWinHttpGetIEProxyConfig)
421 purple_debug_warning("proxy", "Unable to read Windows Proxy Settings.\n");
422 }
423
424 if (!MyWinHttpGetIEProxyConfig)
425 return NULL;
426
427 ZeroMemory(&ie_proxy_config, sizeof(ie_proxy_config));
428 if (!MyWinHttpGetIEProxyConfig(&ie_proxy_config)) {
429 purple_debug_error("proxy", "Error reading Windows Proxy Settings(%lu).\n", GetLastError());
430 return NULL;
431 }
432
433 /* We can't do much if it is autodetect*/
434 if (ie_proxy_config.fAutoDetect) {
435 purple_debug_error("proxy", "Windows Proxy Settings set to autodetect (not supported).\n");
436
437 /* TODO: For 3.0.0 we'll revisit this (maybe)*/
438
439 return NULL;
440
441 } else if (ie_proxy_config.lpszProxy) {
442 gchar *proxy_list = g_utf16_to_utf8(ie_proxy_config.lpszProxy, -1,
443 NULL, NULL, NULL);
444
445 /* We can't do anything about the bypass list, as we don't have the url */
446 /* TODO: For 3.0.0 we'll revisit this*/
447
448 /* There are proxy settings for several protocols */
449 if (proxy_list && *proxy_list) {
450 char *specific = NULL, *tmp;
451
452 /* If there is only a global proxy, which means "HTTP" */
453 if (!strchr(proxy_list, ';') || (specific = g_strstr_len(proxy_list, -1, "http=")) != NULL) {
454
455 if (specific) {
456 specific += strlen("http=");
457 tmp = strchr(specific, ';');
458 if (tmp)
459 *tmp = '\0';
460 /* specific now points the proxy server (and port) */
461 } else
462 specific = proxy_list;
463
464 purple_proxy_info_set_proxy_type(&info, PURPLE_PROXY_HTTP);
465 _proxy_fill_hostinfo(&info, specific, 80);
466 /* TODO: is there a way to set the username/password? */
467 purple_proxy_info_set_username(&info, NULL);
468 purple_proxy_info_set_password(&info, NULL);
469
470 purple_debug_info("proxy", "Windows Proxy Settings: HTTP proxy: '%s:%d'.\n",
471 purple_proxy_info_get_host(&info),
472 purple_proxy_info_get_port(&info));
473
474 } else if ((specific = g_strstr_len(proxy_list, -1, "socks=")) != NULL) {
475
476 specific += strlen("socks=");
477 tmp = strchr(specific, ';');
478 if (tmp)
479 *tmp = '\0';
480 /* specific now points the proxy server (and port) */
481
482 purple_proxy_info_set_proxy_type(&info, PURPLE_PROXY_SOCKS5);
483 _proxy_fill_hostinfo(&info, specific, 1080);
484 /* TODO: is there a way to set the username/password? */
485 purple_proxy_info_set_username(&info, NULL);
486 purple_proxy_info_set_password(&info, NULL);
487
488 purple_debug_info("proxy", "Windows Proxy Settings: SOCKS5 proxy: '%s:%d'.\n",
489 purple_proxy_info_get_host(&info),
490 purple_proxy_info_get_port(&info));
491
492 } else {
493
494 purple_debug_info("proxy", "Windows Proxy Settings: No supported proxy specified.\n");
495
496 purple_proxy_info_set_proxy_type(&info, PURPLE_PROXY_NONE);
497
498 }
499 }
500
501 /* TODO: Fix API to be able look at proxy bypass settings */
502
503 g_free(proxy_list);
504 } else {
505 purple_debug_info("proxy", "No Windows proxy set.\n");
506 purple_proxy_info_set_proxy_type(&info, PURPLE_PROXY_NONE);
507 }
508
509 if (ie_proxy_config.lpszAutoConfigUrl)
510 GlobalFree(ie_proxy_config.lpszAutoConfigUrl);
511 if (ie_proxy_config.lpszProxy)
512 GlobalFree(ie_proxy_config.lpszProxy);
513 if (ie_proxy_config.lpszProxyBypass)
514 GlobalFree(ie_proxy_config.lpszProxyBypass);
515
516 return &info;
517 }
518 #endif
519
520 56
521 /************************************************************************** 57 /**************************************************************************
522 * Proxy API 58 * Proxy API
523 **************************************************************************/ 59 **************************************************************************/
524 60
530 66
531 /* This is used as a fallback so we don't overwrite the selected proxy type */ 67 /* This is used as a fallback so we don't overwrite the selected proxy type */
532 static PurpleProxyInfo *tmp_none_proxy_info = NULL; 68 static PurpleProxyInfo *tmp_none_proxy_info = NULL;
533 if (!tmp_none_proxy_info) { 69 if (!tmp_none_proxy_info) {
534 tmp_none_proxy_info = purple_proxy_info_new(); 70 tmp_none_proxy_info = purple_proxy_info_new();
535 purple_proxy_info_set_proxy_type(tmp_none_proxy_info, PURPLE_PROXY_NONE); 71 purple_proxy_info_set_proxy_type(tmp_none_proxy_info, PURPLE_PROXY_TYPE_NONE);
536 } 72 }
537 73
538 if (account && purple_account_get_proxy_info(account) != NULL) { 74 if (account && purple_account_get_proxy_info(account) != NULL) {
539 gpi = purple_account_get_proxy_info(account); 75 gpi = purple_account_get_proxy_info(account);
540 if (purple_proxy_info_get_proxy_type(gpi) == PURPLE_PROXY_USE_GLOBAL) 76 if (purple_proxy_info_get_proxy_type(gpi) == PURPLE_PROXY_TYPE_USE_GLOBAL)
541 gpi = NULL; 77 gpi = NULL;
542 } 78 }
543 if (gpi == NULL) { 79 if (gpi == NULL) {
544 if (purple_running_gnome()) 80 gpi = purple_global_proxy_get_info();
545 gpi = purple_gnome_proxy_get_info(); 81 }
546 else 82
547 gpi = purple_global_proxy_get_info(); 83 if (purple_proxy_info_get_proxy_type(gpi) == PURPLE_PROXY_TYPE_USE_ENVVAR) {
548 }
549
550 if (purple_proxy_info_get_proxy_type(gpi) == PURPLE_PROXY_USE_ENVVAR) {
551 if ((tmp = g_getenv("HTTP_PROXY")) != NULL || 84 if ((tmp = g_getenv("HTTP_PROXY")) != NULL ||
552 (tmp = g_getenv("http_proxy")) != NULL || 85 (tmp = g_getenv("http_proxy")) != NULL ||
553 (tmp = g_getenv("HTTPPROXY")) != NULL) 86 (tmp = g_getenv("HTTPPROXY")) != NULL)
554 { 87 {
555 gchar *scheme, *host, *username, *password; 88 gchar *scheme, *host, *username, *password;
573 g_free(password); 106 g_free(password);
574 g_free(host); 107 g_free(host);
575 return gpi; 108 return gpi;
576 } 109 }
577 110
578 purple_proxy_info_set_host(gpi, host); 111 purple_proxy_info_set_hostname(gpi, host);
112 purple_proxy_info_set_port(gpi, port);
579 purple_proxy_info_set_username(gpi, username); 113 purple_proxy_info_set_username(gpi, username);
580 purple_proxy_info_set_password(gpi, password); 114 purple_proxy_info_set_password(gpi, password);
581 purple_proxy_info_set_port(gpi, port);
582 115
583 g_free(host); 116 g_free(host);
584 g_free(username); 117 g_free(username);
585 g_free(password); 118 g_free(password);
586 119
598 if ((tmp = g_getenv("HTTP_PROXY_PORT")) != NULL || 131 if ((tmp = g_getenv("HTTP_PROXY_PORT")) != NULL ||
599 (tmp = g_getenv("http_proxy_port")) != NULL || 132 (tmp = g_getenv("http_proxy_port")) != NULL ||
600 (tmp = g_getenv("HTTPPROXYPORT")) != NULL) 133 (tmp = g_getenv("HTTPPROXYPORT")) != NULL)
601 purple_proxy_info_set_port(gpi, atoi(tmp)); 134 purple_proxy_info_set_port(gpi, atoi(tmp));
602 } else { 135 } else {
603 #ifdef _WIN32
604 PurpleProxyInfo *wgpi;
605 if ((wgpi = purple_win32_proxy_get_info()) != NULL)
606 return wgpi;
607 #endif
608 /* no proxy environment variable found, don't use a proxy */ 136 /* no proxy environment variable found, don't use a proxy */
609 purple_debug_info("proxy", "No environment settings found, not using a proxy\n"); 137 purple_debug_info("proxy", "No environment settings found, not using a proxy\n");
610 gpi = tmp_none_proxy_info; 138 gpi = tmp_none_proxy_info;
611 } 139 }
612 140
624 const gchar *password; 152 const gchar *password;
625 gchar *auth; 153 gchar *auth;
626 gchar *proxy; 154 gchar *proxy;
627 GProxyResolver *resolver; 155 GProxyResolver *resolver;
628 156
629 if (purple_proxy_info_get_proxy_type(info) == PURPLE_PROXY_NONE) { 157 if (purple_proxy_info_get_proxy_type(info) == PURPLE_PROXY_TYPE_NONE) {
630 /* Return an empty simple resolver, which will resolve on direct 158 /* Return an empty simple resolver, which will resolve on direct
631 * connection. */ 159 * connection. */
632 return g_simple_proxy_resolver_new(NULL, NULL); 160 return g_simple_proxy_resolver_new(NULL, NULL);
633 } 161 }
634 162
635 switch (purple_proxy_info_get_proxy_type(info)) 163 switch (purple_proxy_info_get_proxy_type(info))
636 { 164 {
637 /* PURPLE_PROXY_NONE already handled above */ 165 /* PURPLE_PROXY_NONE already handled above */
638 166
639 case PURPLE_PROXY_USE_ENVVAR: 167 case PURPLE_PROXY_TYPE_USE_ENVVAR:
640 /* Intentional passthrough */ 168 /* Intentional passthrough */
641 case PURPLE_PROXY_HTTP: 169 case PURPLE_PROXY_TYPE_HTTP:
642 protocol = "http"; 170 protocol = "http";
643 break; 171 break;
644 case PURPLE_PROXY_SOCKS4: 172 case PURPLE_PROXY_TYPE_SOCKS4:
645 protocol = "socks4"; 173 protocol = "socks4";
646 break; 174 break;
647 case PURPLE_PROXY_SOCKS5: 175 case PURPLE_PROXY_TYPE_SOCKS5:
648 /* Intentional passthrough */ 176 /* Intentional passthrough */
649 case PURPLE_PROXY_TOR: 177 case PURPLE_PROXY_TYPE_TOR:
650 protocol = "socks5"; 178 protocol = "socks5";
651 break; 179 break;
652 180
653 default: 181 default:
654 g_set_error(error, PURPLE_CONNECTION_ERROR, 182 g_set_error(error, PURPLE_CONNECTION_ERROR,
657 purple_proxy_info_get_proxy_type(info)); 185 purple_proxy_info_get_proxy_type(info));
658 return NULL; 186 return NULL;
659 } 187 }
660 188
661 189
662 if (purple_proxy_info_get_host(info) == NULL || 190 if (purple_proxy_info_get_hostname(info) == NULL ||
663 purple_proxy_info_get_port(info) <= 0) { 191 purple_proxy_info_get_port(info) <= 0) {
664 g_set_error_literal(error, PURPLE_CONNECTION_ERROR, 192 g_set_error_literal(error, PURPLE_CONNECTION_ERROR,
665 PURPLE_CONNECTION_ERROR_INVALID_SETTINGS, 193 PURPLE_CONNECTION_ERROR_INVALID_SETTINGS,
666 _("Either the host name or port number " 194 _("Either the host name or port number "
667 "specified for your given proxy type is " 195 "specified for your given proxy type is "
685 auth = NULL; 213 auth = NULL;
686 } 214 }
687 215
688 proxy = g_strdup_printf("%s://%s%s:%i", protocol, 216 proxy = g_strdup_printf("%s://%s%s:%i", protocol,
689 auth != NULL ? auth : "", 217 auth != NULL ? auth : "",
690 purple_proxy_info_get_host(info), 218 purple_proxy_info_get_hostname(info),
691 purple_proxy_info_get_port(info)); 219 purple_proxy_info_get_port(info));
692 g_free(auth); 220 g_free(auth);
693 221
694 resolver = g_simple_proxy_resolver_new(proxy, NULL); 222 resolver = g_simple_proxy_resolver_new(proxy, NULL);
695 g_free(proxy); 223 g_free(proxy);
706 if (purple_strequal(name, "/purple/proxy/type")) { 234 if (purple_strequal(name, "/purple/proxy/type")) {
707 int proxytype; 235 int proxytype;
708 const char *type = value; 236 const char *type = value;
709 237
710 if (purple_strequal(type, "none")) 238 if (purple_strequal(type, "none"))
711 proxytype = PURPLE_PROXY_NONE; 239 proxytype = PURPLE_PROXY_TYPE_NONE;
712 else if (purple_strequal(type, "http")) 240 else if (purple_strequal(type, "http"))
713 proxytype = PURPLE_PROXY_HTTP; 241 proxytype = PURPLE_PROXY_TYPE_HTTP;
714 else if (purple_strequal(type, "socks4")) 242 else if (purple_strequal(type, "socks4"))
715 proxytype = PURPLE_PROXY_SOCKS4; 243 proxytype = PURPLE_PROXY_TYPE_SOCKS4;
716 else if (purple_strequal(type, "socks5")) 244 else if (purple_strequal(type, "socks5"))
717 proxytype = PURPLE_PROXY_SOCKS5; 245 proxytype = PURPLE_PROXY_TYPE_SOCKS5;
718 else if (purple_strequal(type, "tor")) 246 else if (purple_strequal(type, "tor"))
719 proxytype = PURPLE_PROXY_TOR; 247 proxytype = PURPLE_PROXY_TYPE_TOR;
720 else if (purple_strequal(type, "envvar")) 248 else if (purple_strequal(type, "envvar"))
721 proxytype = PURPLE_PROXY_USE_ENVVAR; 249 proxytype = PURPLE_PROXY_TYPE_USE_ENVVAR;
722 else 250 else
723 proxytype = -1; 251 proxytype = -1;
724 252
725 purple_proxy_info_set_proxy_type(info, proxytype); 253 purple_proxy_info_set_proxy_type(info, proxytype);
726 } else if (purple_strequal(name, "/purple/proxy/host")) 254 } else if (purple_strequal(name, "/purple/proxy/host"))
727 purple_proxy_info_set_host(info, value); 255 purple_proxy_info_set_hostname(info, value);
728 else if (purple_strequal(name, "/purple/proxy/port")) 256 else if (purple_strequal(name, "/purple/proxy/port"))
729 purple_proxy_info_set_port(info, GPOINTER_TO_INT(value)); 257 purple_proxy_info_set_port(info, GPOINTER_TO_INT(value));
730 else if (purple_strequal(name, "/purple/proxy/username")) 258 else if (purple_strequal(name, "/purple/proxy/username"))
731 purple_proxy_info_set_username(info, value); 259 purple_proxy_info_set_username(info, value);
732 else if (purple_strequal(name, "/purple/proxy/password")) 260 else if (purple_strequal(name, "/purple/proxy/password"))
782 void 310 void
783 purple_proxy_uninit(void) 311 purple_proxy_uninit(void)
784 { 312 {
785 purple_prefs_disconnect_by_handle(purple_proxy_get_handle()); 313 purple_prefs_disconnect_by_handle(purple_proxy_get_handle());
786 314
787 purple_proxy_info_destroy(global_proxy_info); 315 g_clear_object(&global_proxy_info);
788 global_proxy_info = NULL; 316 }
789 }

mercurial