diff src/proxy.c @ 13514:6ad9d666e824

[gaim-migrate @ 15890] * Exposed API to get the setup of a proxy. * Added proxy support to the GG PRPL. committer: Tailor Script <tailor@pidgin.im>
author Bartoz Oler <bartosz@pidgin.im>
date Tue, 14 Mar 2006 23:56:57 +0000
parents 95cc25e78ef6
children 2e10680b7545
line wrap: on
line diff
--- a/src/proxy.c	Tue Mar 14 14:43:41 2006 +0000
+++ b/src/proxy.c	Tue Mar 14 23:56:57 2006 +0000
@@ -2242,35 +2242,20 @@
 	try_connect(phb);
 }
 
-int
-gaim_proxy_connect(GaimAccount *account, const char *host, int port,
-				   GaimInputFunction func, gpointer data)
+GaimProxyInfo *
+gaim_proxy_get_setup(GaimAccount *account)
 {
-	const char *connecthost = host;
-	int connectport = port;
-	struct PHB *phb;
+	GaimProxyInfo *gpi;
 	const gchar *tmp;
 
-	g_return_val_if_fail(host != NULL, -1);
-	g_return_val_if_fail(port != 0 && port != -1, -1);
-	g_return_val_if_fail(func != NULL, -1);
-
-	phb = g_new0(struct PHB, 1);
-
 	if (account && gaim_account_get_proxy_info(account) != NULL)
-		phb->gpi = gaim_account_get_proxy_info(account);
+		gpi = gaim_account_get_proxy_info(account);
 	else if (gaim_running_gnome())
-		phb->gpi = gaim_gnome_proxy_get_info();
+		gpi = gaim_gnome_proxy_get_info();
 	else
-		phb->gpi = gaim_global_proxy_get_info();
+		gpi = gaim_global_proxy_get_info();
 
-	phb->func = func;
-	phb->data = data;
-	phb->host = g_strdup(host);
-	phb->port = port;
-	phb->account = account;
-
-	if (gaim_proxy_info_get_type(phb->gpi) == GAIM_PROXY_USE_ENVVAR) {
+	if (gaim_proxy_info_get_type(gpi) == GAIM_PROXY_USE_ENVVAR) {
 		if ((tmp = g_getenv("HTTP_PROXY")) != NULL ||
 			(tmp = g_getenv("http_proxy")) != NULL ||
 			(tmp = g_getenv("HTTPPROXY")) != NULL) {
@@ -2281,15 +2266,15 @@
 			 * export http_proxy="http://user:passwd@your.proxy.server:port/"
 			 */
 			if(gaim_url_parse(tmp, &proxyhost, &proxyport, &proxypath, &proxyuser, &proxypasswd)) {
-				gaim_proxy_info_set_host(phb->gpi, proxyhost);
+				gaim_proxy_info_set_host(gpi, proxyhost);
 				g_free(proxyhost);
 				g_free(proxypath);
 				if (proxyuser != NULL) {
-					gaim_proxy_info_set_username(phb->gpi, proxyuser);
+					gaim_proxy_info_set_username(gpi, proxyuser);
 					g_free(proxyuser);
 				}
 				if (proxypasswd != NULL) {
-					gaim_proxy_info_set_password(phb->gpi, proxypasswd);
+					gaim_proxy_info_set_password(gpi, proxypasswd);
 					g_free(proxypasswd);
 				}
 
@@ -2300,26 +2285,50 @@
 				     (tmp = g_getenv("HTTPPROXYPORT")) != NULL))
 				    proxyport = atoi(tmp);
 
-				gaim_proxy_info_set_port(phb->gpi, proxyport);
+				gaim_proxy_info_set_port(gpi, proxyport);
 			}
 		} else {
 			/* no proxy environment variable found, don't use a proxy */
 			gaim_debug_info("proxy", "No environment settings found, not using a proxy\n");
-			gaim_proxy_info_set_type(phb->gpi, GAIM_PROXY_NONE);
+			gaim_proxy_info_set_type(gpi, GAIM_PROXY_NONE);
 		}
 
 		/* XXX: Do we want to skip this step if user/password were part of url? */
 		if ((tmp = g_getenv("HTTP_PROXY_USER")) != NULL ||
 			(tmp = g_getenv("http_proxy_user")) != NULL ||
 			(tmp = g_getenv("HTTPPROXYUSER")) != NULL)
-			gaim_proxy_info_set_username(phb->gpi, tmp);
+			gaim_proxy_info_set_username(gpi, tmp);
 
 		if ((tmp = g_getenv("HTTP_PROXY_PASS")) != NULL ||
 			(tmp = g_getenv("http_proxy_pass")) != NULL ||
 			(tmp = g_getenv("HTTPPROXYPASS")) != NULL)
-			gaim_proxy_info_set_password(phb->gpi, tmp);
+			gaim_proxy_info_set_password(gpi, tmp);
 	}
 
+	return gpi;
+}
+
+int
+gaim_proxy_connect(GaimAccount *account, const char *host, int port,
+				   GaimInputFunction func, gpointer data)
+{
+	const char *connecthost = host;
+	int connectport = port;
+	struct PHB *phb;
+
+	g_return_val_if_fail(host != NULL, -1);
+	g_return_val_if_fail(port != 0 && port != -1, -1);
+	g_return_val_if_fail(func != NULL, -1);
+
+	phb = g_new0(struct PHB, 1);
+
+	phb->func = func;
+	phb->data = data;
+	phb->host = g_strdup(host);
+	phb->port = port;
+	phb->account = account;
+	phb->gpi = gaim_proxy_get_setup(account);
+
 	if ((gaim_proxy_info_get_type(phb->gpi) != GAIM_PROXY_NONE) &&
 		(gaim_proxy_info_get_host(phb->gpi) == NULL ||
 		 gaim_proxy_info_get_port(phb->gpi) <= 0)) {