Mercurial > pidgin
comparison libpurple/proxy.c @ 23960:64585aab233a
Use SOCKS proxy if specified when running in GNOME
author | Stu Tomlinson <stu@nosnilmot.com> |
---|---|
date | Sun, 24 Aug 2008 16:51:19 +0000 |
parents | 5c70d953a497 |
children | 54eb782d4721 |
comparison
equal
deleted
inserted
replaced
23958:08c29b5b0ee8 | 23960:64585aab233a |
---|---|
209 | 209 |
210 static PurpleProxyInfo * | 210 static PurpleProxyInfo * |
211 purple_gnome_proxy_get_info(void) | 211 purple_gnome_proxy_get_info(void) |
212 { | 212 { |
213 static PurpleProxyInfo info = {0, NULL, 0, NULL, NULL}; | 213 static PurpleProxyInfo info = {0, NULL, 0, NULL, NULL}; |
214 gchar *tmp; | 214 gboolean use_same_proxy = FALSE; |
215 gchar *tmp, *err; | |
215 | 216 |
216 tmp = g_find_program_in_path("gconftool-2"); | 217 tmp = g_find_program_in_path("gconftool-2"); |
217 if (tmp == NULL) | 218 if (tmp == NULL) |
218 return purple_global_proxy_get_info(); | 219 return purple_global_proxy_get_info(); |
219 | 220 |
220 g_free(tmp); | 221 g_free(tmp); |
221 | 222 |
222 /* Check whether to use a proxy. */ | 223 /* Check whether to use a proxy. */ |
223 if (!g_spawn_command_line_sync("gconftool-2 -g /system/proxy/mode", | 224 if (!g_spawn_command_line_sync("gconftool-2 -g /system/proxy/mode", |
224 &tmp, NULL, NULL, NULL)) | 225 &tmp, &err, NULL, NULL)) |
225 return purple_global_proxy_get_info(); | 226 return purple_global_proxy_get_info(); |
227 g_free(err); | |
226 | 228 |
227 if (!strcmp(tmp, "none\n")) { | 229 if (!strcmp(tmp, "none\n")) { |
228 info.type = PURPLE_PROXY_NONE; | 230 info.type = PURPLE_PROXY_NONE; |
229 g_free(tmp); | 231 g_free(tmp); |
230 return &info; | 232 return &info; |
236 return purple_global_proxy_get_info(); | 238 return purple_global_proxy_get_info(); |
237 } | 239 } |
238 | 240 |
239 g_free(tmp); | 241 g_free(tmp); |
240 | 242 |
241 /* If we get this far then we know we're using an HTTP proxy */ | |
242 info.type = PURPLE_PROXY_HTTP; | |
243 | |
244 /* Free the old fields */ | 243 /* Free the old fields */ |
245 if (info.host) { | 244 if (info.host) { |
246 g_free(info.host); | 245 g_free(info.host); |
247 info.host = NULL; | 246 info.host = NULL; |
248 } | 247 } |
253 if (info.password) { | 252 if (info.password) { |
254 g_free(info.password); | 253 g_free(info.password); |
255 info.password = NULL; | 254 info.password = NULL; |
256 } | 255 } |
257 | 256 |
258 if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/host", | 257 if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/use_same_proxy", |
259 &info.host, NULL, NULL, NULL)) | 258 &tmp, &err, NULL, NULL)) |
260 return purple_global_proxy_get_info(); | 259 return purple_global_proxy_get_info(); |
260 g_free(err); | |
261 | |
262 if (!strcmp(tmp, "true\n")) | |
263 use_same_proxy = TRUE; | |
264 g_free(tmp); | |
265 | |
266 if (!use_same_proxy && !g_spawn_command_line_sync("gconftool-2 -g /system/proxy/socks_host", | |
267 &info.host, &err, NULL, NULL)) | |
268 return purple_global_proxy_get_info(); | |
269 g_free(err); | |
261 g_strchomp(info.host); | 270 g_strchomp(info.host); |
262 if (*info.host == '\0') | 271 |
263 { | 272 if (!use_same_proxy && *info.host != '\0') { |
264 purple_debug_info("proxy", "Gnome proxy settings are set to " | 273 info.type = PURPLE_PROXY_SOCKS5; |
265 "'manual' but no proxy server is specified. Using " | 274 if (!g_spawn_command_line_sync("gconftool-2 -g /system/proxy/socks_port", |
266 "Pidgin's proxy settings instead.\n"); | 275 &tmp, &err, NULL, NULL)) |
276 { | |
277 g_free(info.host); | |
278 info.host = NULL; | |
279 g_free(info.username); | |
280 info.username = NULL; | |
281 g_free(info.password); | |
282 info.password = NULL; | |
283 return purple_global_proxy_get_info(); | |
284 } | |
285 g_free(err); | |
286 info.port = atoi(tmp); | |
287 g_free(tmp); | |
288 } else { | |
267 g_free(info.host); | 289 g_free(info.host); |
268 info.host = NULL; | 290 if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/host", |
269 return purple_global_proxy_get_info(); | 291 &info.host, &err, NULL, NULL)) |
270 } | 292 return purple_global_proxy_get_info(); |
271 | 293 g_free(err); |
272 if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/authentication_user", | 294 /* If we get this far then we know we're using an HTTP proxy */ |
273 &info.username, NULL, NULL, NULL)) | 295 info.type = PURPLE_PROXY_HTTP; |
274 { | 296 |
275 g_free(info.host); | 297 g_strchomp(info.host); |
276 info.host = NULL; | 298 if (*info.host == '\0') |
277 return purple_global_proxy_get_info(); | 299 { |
278 } | 300 purple_debug_info("proxy", "Gnome proxy settings are set to " |
279 g_strchomp(info.username); | 301 "'manual' but no suitable proxy server is specified. Using " |
280 | 302 "Pidgin's proxy settings instead.\n"); |
281 if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/authentication_password", | 303 g_free(info.host); |
282 &info.password, NULL, NULL, NULL)) | 304 info.host = NULL; |
283 { | 305 return purple_global_proxy_get_info(); |
284 g_free(info.host); | 306 } |
285 info.host = NULL; | 307 |
286 g_free(info.username); | 308 if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/authentication_user", |
287 info.username = NULL; | 309 &info.username, &err, NULL, NULL)) |
288 return purple_global_proxy_get_info(); | 310 { |
289 } | 311 g_free(info.host); |
290 g_strchomp(info.password); | 312 info.host = NULL; |
291 | 313 g_free(info.username); |
292 if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/port", | 314 info.username = NULL; |
293 &tmp, NULL, NULL, NULL)) | 315 return purple_global_proxy_get_info(); |
294 { | 316 } |
295 g_free(info.host); | 317 g_free(err); |
296 info.host = NULL; | 318 g_strchomp(info.username); |
297 g_free(info.username); | 319 |
298 info.username = NULL; | 320 if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/authentication_password", |
299 g_free(info.password); | 321 &info.password, &err, NULL, NULL)) |
300 info.password = NULL; | 322 { |
301 return purple_global_proxy_get_info(); | 323 g_free(info.host); |
302 } | 324 info.host = NULL; |
303 info.port = atoi(tmp); | 325 g_free(info.username); |
304 g_free(tmp); | 326 info.username = NULL; |
327 return purple_global_proxy_get_info(); | |
328 } | |
329 g_free(err); | |
330 g_strchomp(info.password); | |
331 | |
332 if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/port", | |
333 &tmp, &err, NULL, NULL)) | |
334 { | |
335 g_free(info.host); | |
336 info.host = NULL; | |
337 g_free(info.username); | |
338 info.username = NULL; | |
339 g_free(info.password); | |
340 info.password = NULL; | |
341 return purple_global_proxy_get_info(); | |
342 } | |
343 g_free(err); | |
344 info.port = atoi(tmp); | |
345 g_free(tmp); | |
346 } | |
305 | 347 |
306 return &info; | 348 return &info; |
307 } | 349 } |
308 /************************************************************************** | 350 /************************************************************************** |
309 * Proxy API | 351 * Proxy API |