changeset 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 43d123a4b4d7
children f5d4300aeed8
files plugins/ChangeLog.API src/protocols/gg/gg.c src/proxy.c src/proxy.h
diffstat 4 files changed, 104 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/ChangeLog.API	Tue Mar 14 14:43:41 2006 +0000
+++ b/plugins/ChangeLog.API	Tue Mar 14 23:56:57 2006 +0000
@@ -282,6 +282,7 @@
 	* gaim_gtk_set_cursor()
 	* gaim_gtk_clear_cursor()
 	* GAIM_MESSAGE_ACTIVE_ONLY
+	* gaim_proxy_get_setup()
 
 	Signals - Changed:  (See the Doxygen docs for details on all signals.)
 	* Signal propagation now stops after a handler returns a non-NULL value.
--- a/src/protocols/gg/gg.c	Tue Mar 14 14:43:41 2006 +0000
+++ b/src/protocols/gg/gg.c	Tue Mar 14 23:56:57 2006 +0000
@@ -54,6 +54,42 @@
 
 /* ----- HELPERS -------------------------------------------------------- */
 
+/**
+ * Set up libgadu's proxy.
+ *
+ * @param account Account for which to set up the proxy.
+ *
+ * @return Zero if proxy setup is valid, otherwise -1.
+ */
+/* static int ggp_setup_proxy(GaimAccount *account) {{{ */
+static int ggp_setup_proxy(GaimAccount *account)
+{
+	GaimProxyInfo *gpi;
+
+	gpi = gaim_proxy_get_setup(account);
+
+	if ((gaim_proxy_info_get_type(gpi) != GAIM_PROXY_NONE) &&
+	    (gaim_proxy_info_get_host(gpi) == NULL ||
+	     gaim_proxy_info_get_port(gpi) <= 0)) {
+
+		gg_proxy_enabled = 0;
+		gaim_notify_error(NULL, NULL, _("Invalid proxy settings"),
+				  _("Either the host name or port number specified for your given proxy type is invalid."));
+		return -1;
+	} else if (gaim_proxy_info_get_type(gpi) != GAIM_PROXY_NONE) {
+		gg_proxy_enabled = 1;
+		gg_proxy_host = g_strdup(gaim_proxy_info_get_host(gpi));
+		gg_proxy_port = gaim_proxy_info_get_port(gpi);
+		gg_proxy_username = g_strdup(gaim_proxy_info_get_username(gpi));
+		gg_proxy_password = g_strdup(gaim_proxy_info_get_password(gpi));
+	} else {
+		gg_proxy_enabled = 0;
+	}
+
+	return 0;
+}
+/* }}} */
+
 /*
  */
 /* static void ggp_async_token_handler(gpointer _gc, gint fd, GaimInputCondition cond) {{{ */
@@ -66,7 +102,6 @@
 
 	struct gg_token *t = NULL;
 
-	gaim_debug_info("gg", "token_handler: token->req->fd = %d\n", token->req->fd);
 	gaim_debug_info("gg", "token_handler: token->req: check = %d; state = %d;\n",
 			token->req->check, token->req->state);
 
@@ -129,11 +164,19 @@
 /* static void ggp_token_request(GaimConnection *gc, GGPTokenCallback cb) {{{ */
 static void ggp_token_request(GaimConnection *gc, GGPTokenCallback cb)
 {
-	GGPInfo *info = gc->proto_data;
+	GaimAccount *account;
 	struct gg_http *req;
+	GGPInfo *info;
+
+	account = gaim_connection_get_account(gc);
+
+	if (ggp_setup_proxy(account) == -1)
+		return;
+
+	info = gc->proto_data;
 
 	if ((req = gg_token(1)) == NULL) {
-		gaim_notify_error(gaim_connection_get_account(gc),
+		gaim_notify_error(account,
 				  _("Token Error"),
 				  _("Unable to fetch the token.\n"), NULL);
 		return;
@@ -1502,9 +1545,16 @@
 /* static void ggp_login(GaimAccount *account) {{{ */
 static void ggp_login(GaimAccount *account)
 {
-	GaimConnection *gc = gaim_account_get_connection(account);
-	struct gg_login_params *glp = g_new0(struct gg_login_params, 1);
-	GGPInfo *info = g_new0(GGPInfo, 1);
+	GaimConnection *gc;
+	struct gg_login_params *glp;
+	GGPInfo *info;
+
+	if (ggp_setup_proxy(account) == -1)
+		return;
+
+	gc = gaim_account_get_connection(account);
+	glp = g_new0(struct gg_login_params, 1);
+	info = g_new0(GGPInfo, 1);
 
 	/* Probably this should be moved to *_new() function. */
 	info->session = NULL;
--- 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)) {
--- a/src/proxy.h	Tue Mar 14 14:43:41 2006 +0000
+++ b/src/proxy.h	Tue Mar 14 23:56:57 2006 +0000
@@ -201,6 +201,15 @@
 void gaim_proxy_init(void);
 
 /**
+ * Returns configuration of a proxy.
+ *
+ * @param account The account for which the configuration is needed.
+ *
+ * @return The configuration of a proxy.
+ */
+GaimProxyInfo *gaim_proxy_get_setup(GaimAccount *account);
+
+/**
  * Makes a connection to the specified host and port.
  *
  * @param account The account making the connection.