changeset 6516:7c14b35bc984

[gaim-migrate @ 7033] reversed the last yahoo info patch and applied this one instead, which includes msn info support. ChipX86: if this messes you up, tell me and i'll switch it back. committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Wed, 20 Aug 2003 02:45:31 +0000
parents 785a272be6ce
children b533a102838c
files src/gtkprefs.c src/html.c src/html.h src/protocols/msn/msn.c src/protocols/msn/msn.h src/protocols/toc/toc.c src/protocols/yahoo/yahoo.c
diffstat 7 files changed, 181 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/gtkprefs.c	Wed Aug 20 01:55:25 2003 +0000
+++ b/src/gtkprefs.c	Wed Aug 20 02:45:31 2003 +0000
@@ -538,7 +538,7 @@
 
 			/* We'll check this just to make sure. This also lets us do something different on
 			 * other platforms, if need be */
-			grab_url(name, TRUE, theme_got_url, ".tgz");
+			grab_url(name, TRUE, theme_got_url, ".tgz", NULL, 0);
 		}
 
 		gtk_drag_finish(dc, TRUE, FALSE, t);
--- a/src/html.c	Wed Aug 20 01:55:25 2003 +0000
+++ b/src/html.c	Wed Aug 20 02:45:31 2003 +0000
@@ -81,7 +81,7 @@
 	/* hyphen at end includes it in control set */
 	char addr_ctrl[] = "A-Za-z0-9.-";
 	char port_ctrl[] = "0-9";
-	char page_ctrl[] = "A-Za-z0-9.~_/&%%?=+^-";
+	char page_ctrl[] = "A-Za-z0-9.~_/:*!@&%%?=+^-";
 
 	if((turl=strstr(url, "http://")) || (turl=strstr(url, "HTTP://")))
 		url=turl+=7;
@@ -111,6 +111,8 @@
 	struct g_url *website;
 	char *url;
 	gboolean full;
+	char *user_agent;
+	int http11;
 
 	int inpa;
 
@@ -167,13 +169,14 @@
 				   "Redirecting to %s\n", new_url);
 
 		/* Try again, with this new location. */
-		grab_url(new_url, full, gunk->callback, gunk->data);
+		grab_url(new_url, full, gunk->callback, gunk->data, gunk->user_agent, gunk->http11);
 
 		/* Free up. */
 		g_free(new_url);
 		g_free(gunk->webdata);
 		g_free(gunk->website);
 		g_free(gunk->url);
+		g_free(gunk->user_agent);
 		g_free(gunk);
 
 		return TRUE;
@@ -201,16 +204,31 @@
 		gunk->callback(gunk->data, NULL, 0);
 		g_free(gunk->website);
 		g_free(gunk->url);
+		g_free(gunk->user_agent);
 		g_free(gunk);
 		return;
 	}
 
 	if (!gunk->sentreq) {
-		char buf[256];
+		char buf[1024];
 
-		g_snprintf(buf, sizeof(buf), "GET %s%s HTTP/1.0\r\n\r\n", gunk->full ? "" : "/",
-			   gunk->full ? gunk->url : gunk->website->page);
+		if(gunk->user_agent) {
+			if(gunk->http11)
+				g_snprintf(buf, sizeof(buf), "GET %s%s HTTP/1.1\r\nUser-Agent: \"%s\"\r\nHost: %s\r\n\r\n", gunk->full ? "" : "/",
+						gunk->full ? gunk->url : gunk->website->page, gunk->user_agent, gunk->website->address);
+			else
+				g_snprintf(buf, sizeof(buf), "GET %s%s HTTP/1.0\r\nUser-Agent: \"%s\"\r\n\r\n", gunk->full ? "" : "/",
+						gunk->full ? gunk->url : gunk->website->page, gunk->user_agent);
+		}
+		else {
+			if(gunk->http11)
+				g_snprintf(buf, sizeof(buf), "GET %s%s HTTP/1.1\r\nHost: %s\r\n\r\n", gunk->full ? "" : "/",
+						gunk->full ? gunk->url : gunk->website->page, gunk->website->address);
+			else
+				g_snprintf(buf, sizeof(buf), "GET %s%s HTTP/1.0\r\n\r\n", gunk->full ? "" : "/",
+						gunk->full ? gunk->url : gunk->website->page);
 
+		}
 		gaim_debug(GAIM_DEBUG_MISC, "grab_url_callback",
 				   "Request: %s\n", buf);
 
@@ -288,6 +306,7 @@
 			g_free(gunk->webdata);
 		g_free(gunk->website);
 		g_free(gunk->url);
+		g_free(gunk->user_agent);
 		g_free(gunk);
 	} else {
 		gaim_input_remove(gunk->inpa);
@@ -297,11 +316,13 @@
 			g_free(gunk->webdata);
 		g_free(gunk->website);
 		g_free(gunk->url);
+		g_free(gunk->user_agent);
 		g_free(gunk);
 	}
 }
 
-void grab_url(char *url, gboolean full, void callback(gpointer, char *, unsigned long), gpointer data)
+void grab_url(char *url, gboolean full, void callback(gpointer, char *, unsigned long),
+		gpointer data, char *user_agent, int http11)
 {
 	int sock;
 	struct grab_url_data *gunk = g_new0(struct grab_url_data, 1);
@@ -309,6 +330,8 @@
 	gunk->callback = callback;
 	gunk->data = data;
 	gunk->url = g_strdup(url);
+	gunk->user_agent = (user_agent) ? g_strdup(user_agent) : NULL;
+	gunk->http11 = http11;
 	gunk->website = parse_url(url);
 	gunk->full = full;
 
@@ -317,6 +340,7 @@
 								   gunk)) < 0) {
 		g_free(gunk->website);
 		g_free(gunk->url);
+		g_free(gunk->user_agent);
 		g_free(gunk);
 		callback(data, g_strdup(_("g003: Error opening connection.\n")), 0);
 	}
--- a/src/html.h	Wed Aug 20 01:55:25 2003 +0000
+++ b/src/html.h	Wed Aug 20 02:45:31 2003 +0000
@@ -31,7 +31,7 @@
 
 void grab_url(char *url, gboolean full,
 			  void (*callback)(gpointer, char *, unsigned long),
-			  gpointer data);
+			  gpointer data, char *, int);
 
 gchar *strip_html(const gchar *text);
 void html_to_xhtml(const char *html, char **xhtml_out, char **plain_out);
--- a/src/protocols/msn/msn.c	Wed Aug 20 01:55:25 2003 +0000
+++ b/src/protocols/msn/msn.c	Wed Aug 20 02:45:31 2003 +0000
@@ -28,6 +28,7 @@
 #include "state.h"
 #include "utils.h"
 #include "multi.h"
+#include "html.h"
 
 #define BUDDY_ALIAS_MAXLEN 388
 
@@ -1157,6 +1158,150 @@
 	return buf;
 }
 
+static void
+msn_got_info(gpointer data, char *url_text, unsigned long len)
+{
+	char *stripped,*p,*q;
+	int count;
+	char buf[1024];
+	char *user_url = NULL;
+
+	if (!url_text || !strcmp(url_text,"")) {
+		g_show_info_text(NULL, NULL, 2,
+				"<html><body><b>Error retrieving profile</b></body></html>", NULL);
+		return;
+	}
+
+	/* if they have a homepage link, MSN masks it such that we need to
+	 * fetch the url out before strip_html() nukes it */
+	if((p = strstr(url_text, "Take a look at my </font><A class=viewDesc title=\"")) != NULL )
+	{
+		p += 50;
+		if((q = strchr(p, '"')) != NULL)
+			user_url = g_strndup(p,q-p);
+	}
+
+	/* strip_html() doesn't strip out character entities like &nbsp; and &#183; */
+	while ((p = strstr(url_text, "&nbsp;")) != NULL) {
+		memmove(p, p+6, strlen(p+6));
+		url_text[strlen(url_text)-6] = '\0';
+	}
+	while ((p = strstr(url_text, "&#183;")) != NULL) {
+		memmove(p, p+6, strlen(p+6));
+		url_text[strlen(url_text)-6] = '\0';
+	}
+
+	/* nuke the nasty \r's that just get in the way */
+	while ((p = strchr(url_text, '\r')) != NULL) {
+		memmove(p, p+1, strlen(p+1));
+		url_text[strlen(url_text)-1] = '\0';
+	}
+
+	/* MSN always puts in &#39; for apostrophies...replace them */
+	while ((p = strstr(url_text, "&#39;")) != NULL) {
+		*p = '\'';
+		memmove(p+1, p+5, strlen(p+5));
+		url_text[strlen(url_text)-4] = '\0';
+	}
+
+	/* nuke the html, it's easier than trying to parse the horrid stuff */
+	stripped = strip_html(url_text);
+
+	/* gonna re-use the memory we've already got for url_text */
+	strcpy(url_text, "<html><body>\n");
+
+	/* extract their Name and put it in */
+	info_extract_field(stripped, url_text, "\tName", 0, "\t", '\n',
+			"Undisclosed", "Name", 0, NULL);
+
+	/* extract their Age and put it in */
+	info_extract_field(stripped, url_text, "\tAge", 0, "\t", '\n',
+			"Undisclosed", "Age", 0, NULL);
+
+	/* extract their Gender and put it in */
+	info_extract_field(stripped, url_text, "\tGender", 6, "\t", '\n',
+			"Undisclosed", "Gender", 0, NULL);
+
+	/* extract their MaritalStatus and put it in */
+	info_extract_field(stripped, url_text, "\tMaritalStatus", 0, "\t", '\n',
+			"Undisclosed", "Marital Status", 0, NULL);
+
+	/* extract their Location and put it in */
+	info_extract_field(stripped, url_text, "\tLocation", 0, "\t", '\n',
+			"Undisclosed", "Location", 0, NULL);
+
+	/* extract their Occupation and put it in */
+	info_extract_field(stripped, url_text, "\t Occupation", 6, "\t", '\n',
+			"Undisclosed", "Occupation", 0, NULL);
+
+	/* the fields, 'A Little About Me', 'Favorite Things', 'Hobbies and Interests',
+	 * 'Favorite Quote', and 'My Homepage' may or may not appear, in any combination.
+	 * however, they do appear in certain order, so we can successively search to
+	 * pin down the distinct values.
+	 */
+
+	/* check if they have A Little About Me */
+	if(!info_extract_field(stripped, url_text, "\tA Little About Me", 1, "Favorite Things", '\n',
+				NULL, "A Little About Me", 0, NULL))
+		if(!info_extract_field(stripped, url_text, "\tA Little About Me", 1, "Hobbies and Interests", '\n',
+					NULL, "A Little About Me", 0, NULL))
+			if(!info_extract_field(stripped, url_text, "\tA Little About Me", 1, "Favorite Quote", '\n',
+						NULL, "A Little About Me", 0, NULL))
+				if(!info_extract_field(stripped, url_text, "\tA Little About Me", 1, "My Homepage\tTake a look", '\n',
+							NULL, "A Little About Me", 0, NULL))
+					info_extract_field(stripped, url_text, "\tA Little About Me", 1, "last updated", '\n',
+							NULL, "A Little About Me", 0, NULL);
+
+	/* check if they have Favorite Things */
+	if(!info_extract_field(stripped, url_text, "Favorite Things", 1, "Hobbies and Interests", '\n',
+				NULL, "Favorite Things", 0, NULL))
+		if(!info_extract_field(stripped, url_text, "Favorite Things", 1, "Favorite Quote", '\n',
+					NULL, "Favorite Things", 0, NULL))
+			if(info_extract_field(stripped, url_text, "Favorite Things", 1, "My Homepage\tTake a look", '\n',
+						NULL, "Favorite Things", 0, NULL))
+				info_extract_field(stripped, url_text, "Favorite Things", 1, "last updated", '\n',
+						NULL, "Favorite Things", 0, NULL);
+
+	/* check if they have Hobbies and Interests */
+	if(!info_extract_field(stripped, url_text, "Hobbies and Interests", 1, "Favorite Quote", '\n',
+				NULL, "Hobbies and Interests", 0, NULL))
+		if(info_extract_field(stripped, url_text, "Hobbies and Interests", 1, "My Homepage\tTake a look", '\n',
+					NULL, "Hobbies and Interests", 0, NULL))
+			info_extract_field(stripped, url_text, "Hobbies and Interests", 1, "last updated", '\n',
+					NULL, "Hobbies and Interests", 0, NULL);
+
+	/* check if they have Favorite Quote */
+	if(!info_extract_field(stripped, url_text, "Favorite Quote", 1, "My Homepage\tTake a look", '\n',
+				NULL, "Favorite Quote", 0, NULL))
+		info_extract_field(stripped, url_text, "Favorite Quote", 1, "last updated", '\n',
+				NULL, "Favorite Quote", 0, NULL);
+
+	/* extract the last updated date and put it in */
+	info_extract_field(stripped, url_text, "\tlast updated:", 1, "\n", '\n',
+			NULL, "Last Updated", 0, NULL);
+
+	/* if we were able to fetch a homepage url earlier, stick it in there */
+	if(user_url)
+	{
+		g_snprintf(buf,sizeof(buf),"<b>Home Page:</b><br><a href=\"%s\">%s</a><br>\n",user_url,user_url);
+		strcat(url_text,buf);
+	}
+
+	/* finish it off, and show it to them */
+	strcat(url_text, "</body></html>\n");
+	g_show_info_text(NULL, NULL, 2, url_text, NULL);
+	g_free(stripped);
+}
+
+static void
+msn_get_info(GaimConnection *gc, const char *name)
+{
+	/* MsnSession *session = (MsnSession *)gc->proto_data; */
+	char url[256];
+	g_snprintf(url, sizeof url, "%s%s", PROFILE_URL, name);
+	grab_url(url, FALSE, msn_got_info, NULL,"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)",1);
+}
+
 static GaimPluginProtocolInfo prpl_info =
 {
 	GAIM_PROTO_MSN,
@@ -1176,7 +1321,7 @@
 	msn_send_im,
 	NULL,
 	msn_send_typing,
-	NULL,
+	msn_get_info,
 	msn_set_away,
 	NULL,
 	NULL,
--- a/src/protocols/msn/msn.h	Wed Aug 20 01:55:25 2003 +0000
+++ b/src/protocols/msn/msn.h	Wed Aug 20 02:45:31 2003 +0000
@@ -59,6 +59,7 @@
 
 #define HOTMAIL_URL "http://www.hotmail.com/cgi-bin/folders"
 #define PASSPORT_URL "http://lc1.law13.hotmail.passport.com/cgi-bin/dologin?login="
+#define PROFILE_URL "http://members.msn.com/"
 
 #define USEROPT_HOTMAIL 0
 
--- a/src/protocols/toc/toc.c	Wed Aug 20 01:55:25 2003 +0000
+++ b/src/protocols/toc/toc.c	Wed Aug 20 02:45:31 2003 +0000
@@ -898,7 +898,7 @@
 		g_snprintf(tmp, sizeof(tmp), "http://%s:%d/%s", tdt->toc_ip,
 				gaim_account_get_int(gc->account, "port", TOC_PORT),
 				url);
-		grab_url(tmp, FALSE, toc_got_info, NULL);
+		grab_url(tmp, FALSE, toc_got_info, NULL, NULL, 0);
 	} else if (!g_ascii_strcasecmp(c, "DIR_STATUS")) {
 	} else if (!g_ascii_strcasecmp(c, "ADMIN_NICK_STATUS")) {
 	} else if (!g_ascii_strcasecmp(c, "ADMIN_PASSWD_STATUS")) {
--- a/src/protocols/yahoo/yahoo.c	Wed Aug 20 01:55:25 2003 +0000
+++ b/src/protocols/yahoo/yahoo.c	Wed Aug 20 02:45:31 2003 +0000
@@ -1541,7 +1541,7 @@
 	/* struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; */
 	char url[256];
 	g_snprintf(url, sizeof url, "%s%s", YAHOO_PROFILE_URL, name);
-	grab_url(url, FALSE, yahoo_got_info, NULL);
+	grab_url(url, FALSE, yahoo_got_info, NULL, NULL, 0);
 }
 
 static GaimPlugin *my_protocol = NULL;