changeset 9227:9171e528d7e5

[gaim-migrate @ 10023] Patch by Don Seiler (aka rizzo) to add two additional parameters to gaim_url_parse(), which are used for storing the username and password from the URL, if they exist. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Mon, 07 Jun 2004 04:01:00 +0000
parents 7a00289f2ef1
children 3de4cb53762b
files src/protocols/jabber/oob.c src/protocols/yahoo/yahoo_filexfer.c src/protocols/yahoo/yahoochat.c src/proxy.c src/util.c src/util.h
diffstat 6 files changed, 52 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/jabber/oob.c	Sun Jun 06 20:56:54 2004 +0000
+++ b/src/protocols/jabber/oob.c	Mon Jun 07 04:01:00 2004 +0000
@@ -165,7 +165,7 @@
 	url = xmlnode_get_data(urlnode);
 
 	jox = g_new0(JabberOOBXfer, 1);
-	gaim_url_parse(url, &jox->address, &jox->port, &jox->page);
+	gaim_url_parse(url, &jox->address, &jox->port, &jox->page, NULL, NULL);
 	g_free(url);
 	jox->js = js;
 	jox->headers = g_string_new("");
--- a/src/protocols/yahoo/yahoo_filexfer.c	Sun Jun 06 20:56:54 2004 +0000
+++ b/src/protocols/yahoo/yahoo_filexfer.c	Mon Jun 07 04:01:00 2004 +0000
@@ -441,7 +441,7 @@
 	/* Setup the Yahoo-specific file transfer data */
 	xfer_data = g_new0(struct yahoo_xfer_data, 1);
 	xfer_data->gc = gc;
-	if (!gaim_url_parse(url, &(xfer_data->host), &(xfer_data->port), &(xfer_data->path))) {
+	if (!gaim_url_parse(url, &(xfer_data->host), &(xfer_data->port), &(xfer_data->path), NULL, NULL)) {
 		g_free(xfer_data);
 		return;
 	}
--- a/src/protocols/yahoo/yahoochat.c	Sun Jun 06 20:56:54 2004 +0000
+++ b/src/protocols/yahoo/yahoochat.c	Mon Jun 07 04:01:00 2004 +0000
@@ -1331,7 +1331,7 @@
 	rl = gaim_roomlist_new(gaim_connection_get_account(gc));
 	yrl->list = rl;
 
-	gaim_url_parse(url, &(yrl->host), NULL, &(yrl->path));
+	gaim_url_parse(url, &(yrl->host), NULL, &(yrl->path), NULL, NULL);
 	g_free(url);
 
 	f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_STRING, "", "room", TRUE);
@@ -1408,7 +1408,7 @@
 	yrl->cat = category;
 	list->proto_data = g_list_append(list->proto_data, yrl);
 
-	gaim_url_parse(url, &(yrl->host), NULL, &(yrl->path));
+	gaim_url_parse(url, &(yrl->host), NULL, &(yrl->path), NULL, NULL);
 	g_free(url);
 
 	yrl->ucat = gaim_roomlist_room_new(GAIM_ROOMLIST_ROOMTYPE_CATEGORY, _("User Rooms"), yrl->cat);
--- a/src/proxy.c	Sun Jun 06 20:56:54 2004 +0000
+++ b/src/proxy.c	Mon Jun 07 04:01:00 2004 +0000
@@ -1446,16 +1446,24 @@
 		if ((tmp = g_getenv("HTTP_PROXY")) != NULL ||
 			(tmp = g_getenv("http_proxy")) != NULL ||
 			(tmp= g_getenv("HTTPPROXY")) != NULL) {
-			char *proxyhost,*proxypath;
+			char *proxyhost,*proxypath,*proxyuser,*proxypasswd;
 			int proxyport;
 
 			/* http_proxy-format:
-			 * export http_proxy="http://your.proxy.server:port/"
+			 * export http_proxy="http://user:passwd@your.proxy.server:port/"
 			 */
-			if(gaim_url_parse(tmp, &proxyhost, &proxyport, &proxypath)) {
+			if(gaim_url_parse(tmp, &proxyhost, &proxyport, &proxypath, &proxyuser, &proxypasswd)) {
 				gaim_proxy_info_set_host(phb->gpi, proxyhost);
 				g_free(proxyhost);
 				g_free(proxypath);
+				if (proxyuser != NULL) {
+					gaim_proxy_info_set_username(phb->gpi, proxyuser);
+					g_free(proxyuser);
+				}
+				if (proxypasswd != NULL) {
+					gaim_proxy_info_set_password(phb->gpi, proxypasswd);
+					g_free(proxypasswd);
+				}
 
 				/* only for backward compatibility */
 				if (proxyport == 80 &&
@@ -1468,6 +1476,7 @@
 			}
 		}
 
+		/* 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)
--- a/src/util.c	Sun Jun 06 20:56:54 2004 +0000
+++ b/src/util.c	Mon Jun 07 04:01:00 2004 +0000
@@ -39,6 +39,8 @@
 
 	struct
 	{
+		char *user;
+		char *passwd;
 		char *address;
 		int port;
 		char *page;
@@ -2388,18 +2390,21 @@
  */
 gboolean
 gaim_url_parse(const char *url, char **ret_host, int *ret_port,
-			   char **ret_path)
+			   char **ret_path, char **ret_user, char **ret_passwd)
 {
 	char scan_info[255];
 	char port_str[6];
 	int f;
+	const char *at;
 	const char *turl;
-	char host[256], path[256];
+	char host[256], path[256], user[256], passwd[256];
 	int port = 0;
 	/* hyphen at end includes it in control set */
 	static char addr_ctrl[] = "A-Za-z0-9.-";
 	static char port_ctrl[] = "0-9";
 	static char page_ctrl[] = "A-Za-z0-9.~_/:*!@&%%?=+^-";
+	static char user_ctrl[] = "A-Za-z0-9.~_/*!&%%?=+^-";
+	static char passwd_ctrl[] = "A-Za-z0-9.~_/*!&%%?=+^-";
 
 	g_return_val_if_fail(url != NULL, FALSE);
 
@@ -2410,6 +2415,26 @@
 		url = turl;
 	}
 
+	/* parse out authentication information if supplied */
+	if (at = strchr(url, '@')) {
+		g_snprintf(scan_info, sizeof(scan_info),
+					"%%255[%s]:%%255[%s]^@", user_ctrl, passwd_ctrl);
+		f = sscanf(url, scan_info, user, passwd);
+
+		if (f ==1 ) {
+			/* No passwd, possibly just username supplied */
+			g_snprintf(scan_info, sizeof(scan_info),
+						"%%255[%s]^@", user_ctrl);
+			f = sscanf(url, scan_info, user);
+			*passwd = '\0';
+		}
+
+		url = strdup(at+1); /* move pointer after the @ char */
+	} else {
+		*user = '\0';
+		*passwd = '\0';
+	}
+
 	g_snprintf(scan_info, sizeof(scan_info),
 			   "%%255[%s]:%%5[%s]/%%255[%s]", addr_ctrl, port_ctrl, page_ctrl);
 
@@ -2432,6 +2457,8 @@
 	if (ret_host != NULL) *ret_host = g_strdup(host);
 	if (ret_port != NULL) *ret_port = port;
 	if (ret_path != NULL) *ret_path = g_strdup(path);
+	if (ret_user != NULL) *ret_user = g_strdup(user);
+	if (ret_passwd != NULL) *ret_passwd = g_strdup(passwd);
 
 	return TRUE;
 }
@@ -2444,6 +2471,8 @@
 	if (gfud->user_agent      != NULL) g_free(gfud->user_agent);
 	if (gfud->website.address != NULL) g_free(gfud->website.address);
 	if (gfud->website.page    != NULL) g_free(gfud->website.page);
+	if (gfud->website.user    != NULL) g_free(gfud->website.user);
+	if (gfud->website.passwd    != NULL) g_free(gfud->website.passwd);
 
 	g_free(gfud);
 }
@@ -2700,7 +2729,7 @@
 	gfud->full       = full;
 
 	gaim_url_parse(url, &gfud->website.address, &gfud->website.port,
-				   &gfud->website.page);
+				   &gfud->website.page, &gfud->website.user, &gfud->website.passwd);
 
 	if ((sock = gaim_proxy_connect(NULL, gfud->website.address,
 								   gfud->website.port, url_fetched_cb,
--- a/src/util.h	Sun Jun 06 20:56:54 2004 +0000
+++ b/src/util.h	Mon Jun 07 04:01:00 2004 +0000
@@ -576,7 +576,7 @@
 /*@{*/
 
 /**
- * Parses a URL, returning its host, port, and file path.
+ * Parses a URL, returning its host, port, file path, username and password.
  *
  * The returned data must be freed.
  *
@@ -584,9 +584,11 @@
  * @param ret_host The returned host.
  * @param ret_port The returned port.
  * @param ret_path The returned path.
+ * @param ret_user The returned username.
+ * @param ret_passwd The returned password.
  */
 gboolean gaim_url_parse(const char *url, char **ret_host, int *ret_port,
-						char **ret_path);
+						char **ret_path, char **ret_user, char **ret_passwd);
 
 /**
  * Fetches the data from a URL, and passes it to a callback function.