changeset 6859:17514a2f976a

[gaim-migrate @ 7404] The old MSN Get Info code was messy, and I'm a neat-freak when it comes to code. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Tue, 16 Sep 2003 04:13:59 +0000
parents 885c6528843b
children 82607477da69
files src/protocols/msn/msn.c
diffstat 1 files changed, 157 insertions(+), 80 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/msn/msn.c	Tue Sep 16 03:56:54 2003 +0000
+++ b/src/protocols/msn/msn.c	Tue Sep 16 04:13:59 2003 +0000
@@ -1193,132 +1193,209 @@
 static void
 msn_got_info(gpointer data, char *url_text, unsigned long len)
 {
-	char *stripped,*p,*q;
+	char *stripped, *p, *q;
 	char buf[1024];
 	char *user_url = NULL;
+	gboolean found;
 
-	if (!url_text || !strcmp(url_text,"")) {
+	if (url_text == NULL || strcmp(url_text,"") == 0)
+	{
 		g_show_info_text(NULL, NULL, 2,
-				_("<html><body><b>Error retrieving profile</b></body></html>"), NULL);
+				_("<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
+	/* 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 )
+	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);
+
+		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';
+	/*
+	 * 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';
 	}
 
-	/* 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';
+	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) {
+	while ((p = strstr(url_text, "&#39;")) != NULL)
+	{
 		*p = '\'';
-		memmove(p+1, p+5, strlen(p+5));
-		url_text[strlen(url_text)-4] = '\0';
+		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 */
+	/* 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 */
+	/* 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 */
+	/* Extract their Name and put it in */
 	info_extract_field(stripped, url_text, "\tName", 0, "\t", '\n',
-			"Undisclosed", _("Name"), 0, NULL);
+					   "Undisclosed", _("Name"), 0, NULL);
 
-	/* extract their Age and put it in */
+	/* Extract their Age and put it in */
 	info_extract_field(stripped, url_text, "\tAge", 0, "\t", '\n',
-			"Undisclosed", _("Age"), 0, NULL);
+					   "Undisclosed", _("Age"), 0, NULL);
 
-	/* extract their Gender and put it in */
+	/* Extract their Gender and put it in */
 	info_extract_field(stripped, url_text, "\tGender", 6, "\t", '\n',
-			"Undisclosed", _("Gender"), 0, NULL);
+					   "Undisclosed", _("Gender"), 0, NULL);
 
-	/* extract their MaritalStatus and put it in */
+	/* Extract their MaritalStatus and put it in */
 	info_extract_field(stripped, url_text, "\tMaritalStatus", 0, "\t", '\n',
-			"Undisclosed", _("Marital Status"), 0, NULL);
+					   "Undisclosed", _("Marital Status"), 0, NULL);
 
-	/* extract their Location and put it in */
+	/* Extract their Location and put it in */
 	info_extract_field(stripped, url_text, "\tLocation", 0, "\t", '\n',
-			"Undisclosed", _("Location"), 0, NULL);
+					   "Undisclosed", _("Location"), 0, NULL);
 
-	/* extract their Occupation and put it in */
+	/* Extract their Occupation and put it in */
 	info_extract_field(stripped, url_text, "\t Occupation", 6, "\t", '\n',
-			"Undisclosed", _("Occupation"), 0, NULL);
+					   "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.
+	/*
+	 * 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 A Little About Me */
+	found = info_extract_field(stripped, url_text, "\tA Little About Me",
+							   1, "Favorite Things", '\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);
+	if (!found)
+	{
+		found = info_extract_field(stripped, url_text,
+								   "\tA Little About Me", 1,
+								   "Hobbies and Interests", '\n', NULL,
+								   _("A Little About Me"), 0, NULL);
+	}
+
+	if (!found)
+	{
+		found = info_extract_field(stripped, url_text,
+								   "\tA Little About Me", 1,
+								   "Favorite Quote", '\n', NULL,
+								   _("A Little About Me"), 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);
+	if (!found)
+	{
+		found = info_extract_field(stripped, url_text,
+								   "\tA Little About Me", 1,
+								   "My Homepage\tTake a look", '\n', NULL,
+								   _("A Little About Me"), 0, NULL);
+	}
+
+	if (!found)
+	{
+		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 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);
+	/* Check if they have Favorite Things */
+	found = info_extract_field(stripped, url_text, "Favorite Things", 1,
+							   "Hobbies and Interests", '\n', NULL,
+							   _("Favorite Things"), 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 (!found)
+	{
+		found = info_extract_field(stripped, url_text, "Favorite Things", 1,
+								   "Favorite Quote", '\n', NULL,
+								   "Favorite Things", 0, NULL);
+	}
 
-	/* if we were able to fetch a homepage url earlier, stick it in there */
-	if(user_url)
+	if (!found)
 	{
-		g_snprintf(buf,sizeof(buf),"<b>%s:</b><br><a href=\"%s\">%s</a><br>\n",_("Homepage"),user_url,user_url);
-		strcat(url_text,buf);
+		found = info_extract_field(stripped, url_text, "Favorite Things", 1,
+								   "My Homepage\tTake a look", '\n', NULL,
+								   _("Favorite Things"), 0, NULL);
 	}
 
-	/* finish it off, and show it to them */
+	if (!found)
+	{
+		info_extract_field(stripped, url_text, "Favorite Things", 1,
+						   "last updated", '\n', NULL,
+						   _("Favorite Things"), 0, NULL);
+	}
+
+	/* Check if they have Hobbies and Interests */
+	found = info_extract_field(stripped, url_text, "Hobbies and Interests",
+							   1, "Favorite Quote", '\n', NULL,
+							   _("Hobbies and Interests"), 0, NULL);
+
+	if (!found)
+	{
+		found = info_extract_field(stripped, url_text,
+								   "Hobbies and Interests", 1,
+								   "My Homepage\tTake a look", '\n', NULL,
+								   _("Hobbies and Interests"), 0, NULL);
+	}
+
+	if (!found)
+	{
+		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 */
+	found = info_extract_field(stripped, url_text, "Favorite Quote", 1,
+							   "My Homepage\tTake a look", '\n', NULL,
+							   _("Favorite Quote"), 0, NULL);
+
+	if (!found)
+	{
+		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 != NULL)
+	{
+		g_snprintf(buf, sizeof(buf),
+				   "<b>%s:</b><br><a href=\"%s\">%s</a><br>\n",
+				   _("Homepage"), 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);