changeset 7112:cc1d09631513

[gaim-migrate @ 7679] "ChipX86 recently fixed up the MSN user info code so that if no actual information is found, it will display an error message instead of simply giving a blank screen. Here is a patch for Yahoo which does the same thing." --Nathan Poznick committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Wed, 01 Oct 2003 22:14:54 +0000
parents b9664e6257b5
children 4072d989ecdf
files ChangeLog plugins/autorecon.c src/protocols/yahoo/yahoo.c
diffstat 3 files changed, 147 insertions(+), 52 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Oct 01 21:23:25 2003 +0000
+++ b/ChangeLog	Wed Oct 01 22:14:54 2003 +0000
@@ -10,6 +10,7 @@
 	  longer attempt to load the same, possibly incompatible plugins
 	  (Robert McQueen)
 	* Zepher formatting fixes (Arun A Tharuvai)
+	* Misc bug fix (Nathan Poznick)
 	* Fix sort by idle to behave as it did pre-contact support (David
 	  Smock)
 	* Chinese (Traditional) translation updated (Ambrose C. Li)
--- a/plugins/autorecon.c	Wed Oct 01 21:23:25 2003 +0000
+++ b/plugins/autorecon.c	Wed Oct 01 22:14:54 2003 +0000
@@ -32,7 +32,8 @@
 	gaim_account_connect(account);
 	gaim_debug(GAIM_DEBUG_INFO, "autorecon", "done calling gaim_account_connect\n");
 
-	info->timeout = 0;
+	if(info)
+		info->timeout = 0;
 
 	return FALSE;
 }
--- a/src/protocols/yahoo/yahoo.c	Wed Oct 01 21:23:25 2003 +0000
+++ b/src/protocols/yahoo/yahoo.c	Wed Oct 01 22:14:54 2003 +0000
@@ -41,6 +41,13 @@
 
 extern char *yahoo_crypt(const char *, const char *);
 
+typedef struct
+{
+	GaimConnection *gc;
+	char *name;
+} YahooGetInfoData;
+
+
 /* #define YAHOO_DEBUG */
 
 #define USEROPT_MAIL 0
@@ -2388,13 +2395,18 @@
 
 static void yahoo_got_info(void *data, const char *url_text, size_t len)
 {
+	YahooGetInfoData *info_data = (YahooGetInfoData *)data;
 	char *stripped, *p;
 	char buf[1024];
+	gboolean found;
+	gboolean has_info = FALSE;
 	char *url_buffer;
 
+	gaim_debug_info("yahoo", "In yahoo_got_info\n");
+
 	/* we failed to grab the profile URL */
-	if (!url_text) {
-		gaim_notify_formatted(data, NULL, _("Buddy Information"), NULL,
+	if (url_text == NULL || strcmp(url_text, "") == 0) {
+		gaim_notify_formatted(info_data->gc, NULL, _("Buddy Information"), NULL,
 			_("<html><body><b>Error retrieving profile</b></body></html>"),
 			  NULL, NULL);
 
@@ -2409,13 +2421,13 @@
 	 */
 	p = strstr(url_text, "Adult Profiles Warning Message");
 	if (p) {
-		strcpy(buf, _("<b>Sorry, profiles marked as containing adult content are not supported at this time.</b><br><br>\n"));
-		gaim_markup_extract_info_field(url_text, buf, ".idname=", 0, "%26", 0, NULL,
-				_("If you wish to view this profile, you will need to visit this link in your web browser"),
-				1, YAHOO_PROFILE_URL);
-		strcat(buf, "</body></html>\n");
-		gaim_notify_formatted(data, NULL, _("Buddy Information"), NULL,
-							  buf, NULL, NULL);
+		g_snprintf(buf, 1024, "<html><body>%s%s<a href=\"%s%s\">%s%s</a></body></html>",
+				_("<b>Sorry, profiles marked as containing adult content are not supported at this time.</b><br><br>\n"),
+				_("If you wish to view this profile, you will need to visit this link in your web browser<br>"),
+				YAHOO_PROFILE_URL, info_data->name, YAHOO_PROFILE_URL, info_data->name);
+
+		gaim_notify_formatted(info_data->gc, NULL, _("Buddy Information"), NULL,
+				buf, NULL, NULL);
 		return;
 	}
 
@@ -2426,19 +2438,21 @@
 	 */
 	p = strstr(url_text, "Last Updated:");
 	if (!p) {
-		strcpy(buf, _("<b>Sorry, non-English profiles are not supported at this time.</b><br><br>\n"));
-		gaim_markup_extract_info_field(url_text, buf, "<title>", 0, "'s Yahoo! Profile", 0, NULL,
-				_("If you wish to view this profile, you will need to visit this link in your web browser"),
-				1, YAHOO_PROFILE_URL);
-		strcat(buf, "</body></html>\n");
-		gaim_notify_formatted(data, NULL, _("Buddy Information"), NULL,
-							  buf, NULL, NULL);
+		g_snprintf(buf, 1024, "<html><body>%s%s<a href=\"%s%s\">%s%s</a></body></html>",
+				_("<b>Sorry, non-English profiles are not supported at this time.</b><br><br>\n"),
+				_("If you wish to view this profile, you will need to visit this link in your web browser<br>"),
+				YAHOO_PROFILE_URL, info_data->name, YAHOO_PROFILE_URL, info_data->name);
+
+		gaim_notify_formatted(info_data->gc, NULL, _("Buddy Information"), NULL,
+				buf, NULL, NULL);
 		return;
 	}
 
 	url_buffer = g_strdup(url_text);
 
-	/* gaim_markup_strip_html() doesn't strip out character entities like &nbsp; and &#183;
+	/*
+	 * gaim_markup_strip_html() doesn't strip out character entities like &nbsp;
+	 * and &#183;
 	*/
 	while ((p = strstr(url_buffer, "&nbsp;")) != NULL) {
 		memmove(p, p + 6, strlen(p + 6));
@@ -2458,44 +2472,65 @@
 	/* nuke the html, it's easier than trying to parse the horrid stuff */
 	stripped = gaim_markup_strip_html(url_buffer);
 
+	gaim_debug_misc("yahoo", "stripped = %p\n", stripped);
+	gaim_debug_misc("yahoo", "url_buffer = %p\n", url_buffer);
+
 	/* gonna re-use the memory we've already got for url_buffer */
 	strcpy(url_buffer, "<html><body>\n");
 
-	/* extract their Yahoo! ID and put it in */
-	gaim_markup_extract_info_field(stripped, url_buffer, "Yahoo! ID:", 2, "\n", 0,
+	/* extract their Yahoo! ID and put it in. Don't bother marking has_info as
+	 * true, since the Yahoo! ID will always be there */
+	found = gaim_markup_extract_info_field(stripped, url_buffer, "Yahoo! ID:", 2, "\n", 0,
 			NULL, _("Yahoo! ID"), 0, NULL);
 
+
 	/* extract their Email address and put it in */
-	gaim_markup_extract_info_field(stripped, url_buffer, "My Email", 5, "\n", 0,
+	found = gaim_markup_extract_info_field(stripped, url_buffer, "My Email", 5, "\n", 0,
 			"Private", _("Email"), 0, NULL);
+	if(found)
+		has_info = TRUE;
 
 	/* extract the Nickname if it exists */
-	gaim_markup_extract_info_field(stripped, url_buffer, "Nickname:", 1, "\n", '\n',
+	found = gaim_markup_extract_info_field(stripped, url_buffer, "Nickname:", 1, "\n", '\n',
 			NULL, _("Nickname"), 0, NULL);
+	if(found)
+		has_info = TRUE;
 
 	/* extract their RealName and put it in */
-	gaim_markup_extract_info_field(stripped, url_buffer, "RealName:", 1, "\n", '\n',
+	found = gaim_markup_extract_info_field(stripped, url_buffer, "RealName:", 1, "\n", '\n',
 			NULL, _("Realname"), 0, NULL);
+	if(found)
+		has_info = TRUE;
 
 	/* extract their Location and put it in */
-	gaim_markup_extract_info_field(stripped, url_buffer, "Location:", 2, "\n", '\n',
+	found = gaim_markup_extract_info_field(stripped, url_buffer, "Location:", 2, "\n", '\n',
 			NULL, _("Location"), 0, NULL);
+	if(found)
+		has_info = TRUE;
 
 	/* extract their Age and put it in */
-	gaim_markup_extract_info_field(stripped, url_buffer, "Age:", 3, "\n", '\n',
+	found = gaim_markup_extract_info_field(stripped, url_buffer, "Age:", 3, "\n", '\n',
 			NULL, _("Age"), 0, NULL);
+	if(found)
+		has_info = TRUE;
 
 	/* extract their MaritalStatus and put it in */
-	gaim_markup_extract_info_field(stripped, url_buffer, "MaritalStatus:", 3, "\n", '\n',
+	found = gaim_markup_extract_info_field(stripped, url_buffer, "MaritalStatus:", 3, "\n", '\n',
 			"No Answer", _("Marital Status"), 0, NULL);
+	if(found)
+		has_info = TRUE;
 
 	/* extract their Gender and put it in */
-	gaim_markup_extract_info_field(stripped, url_buffer, "Gender:", 3, "\n", '\n',
+	found = gaim_markup_extract_info_field(stripped, url_buffer, "Gender:", 3, "\n", '\n',
 			"No Answer", _("Gender"), 0, NULL);
+	if(found)
+		has_info = TRUE;
 
 	/* extract their Occupation and put it in */
-	gaim_markup_extract_info_field(stripped, url_buffer, "Occupation:", 2, "\n", '\n',
+	found = gaim_markup_extract_info_field(stripped, url_buffer, "Occupation:", 2, "\n", '\n',
 			NULL, _("Occupation"), 0, NULL);
+	if(found)
+		has_info = TRUE;
 
 	/* Hobbies, Latest News, and Favorite Quote are a bit different, since the
 	 * values can contain embedded newlines... but any or all of them can also
@@ -2504,25 +2539,53 @@
 	 * looking for the 'Links' heading, which is the next thing to follow this
 	 * bunch.
 	 */
-	if (!gaim_markup_extract_info_field(stripped, url_buffer, "Hobbies:", 1, "Latest News",
-				'\n', NULL, _("Hobbies"), 0, NULL))
-		if (!gaim_markup_extract_info_field(stripped, url_buffer, "Hobbies:", 1, "Favorite Quote",
-					'\n', NULL, _("Hobbies"), 0, NULL))
-			gaim_markup_extract_info_field(stripped, url_buffer, "Hobbies:", 1, "Links",
+
+	found = gaim_markup_extract_info_field(stripped, url_buffer, "Hobbies:", 1, "Latest News",
+			'\n', NULL, _("Hobbies"), 0, NULL);
+	if(!found)
+	{
+		found = gaim_markup_extract_info_field(stripped, url_buffer, "Hobbies:", 1, "Favorite Quote",
+				'\n', NULL, _("Hobbies"), 0, NULL);
+		if(!found)
+		{
+			found = gaim_markup_extract_info_field(stripped, url_buffer, "Hobbies:", 1, "Links",
 					'\n', NULL, _("Hobbies"), 0, NULL);
-	if (!gaim_markup_extract_info_field(stripped, url_buffer, "Latest News:", 1, "Favorite Quote",
-				'\n', NULL, _("Latest News"), 0, NULL))
-		gaim_markup_extract_info_field(stripped, url_buffer, "Latest News:", 1, "Links",
+			if(found)
+				has_info = TRUE;
+		}
+		else
+			has_info = TRUE;
+	}
+	else
+		has_info = TRUE;
+
+	found = gaim_markup_extract_info_field(stripped, url_buffer, "Latest News:", 1, "Favorite Quote",
+			'\n', NULL, _("Latest News"), 0, NULL);
+	if(!found)
+	{
+		found = gaim_markup_extract_info_field(stripped, url_buffer, "Latest News:", 1, "Links",
 				'\n', NULL, _("Latest News"), 0, NULL);
-	gaim_markup_extract_info_field(stripped, url_buffer, "Favorite Quote:", 0, "Links",
+		if(found)
+			has_info = TRUE;
+	}
+	else
+		has_info = TRUE;
+
+	found = gaim_markup_extract_info_field(stripped, url_buffer, "Favorite Quote:", 0, "Links",
 			'\n', NULL, _("Favorite Quote"), 0, NULL);
+	if(found)
+		has_info = TRUE;
 
 	/* Home Page will either be "No home page specified",
 	 * or "Home Page: " and a link. */
 	p = strstr(stripped, "No home page specified");
-	if (!p)
-		gaim_markup_extract_info_field(stripped, url_buffer, "Home Page:", 1, " ", 0, NULL,
+	if(!p)
+	{
+		found = gaim_markup_extract_info_field(stripped, url_buffer, "Home Page:", 1, " ", 0, NULL,
 				_("Home Page"), 1, NULL);
+		if(found)
+			has_info = TRUE;
+	}
 
 	/* Cool Link {1,2,3} is also different.  If "No cool link specified" exists,
 	 * then we have none.  If we have one however, we'll need to check and see if
@@ -2531,38 +2594,68 @@
 	 */
 	p = strstr(stripped,"No cool link specified");
 	if (!p)
-		if (gaim_markup_extract_info_field(stripped, url_buffer, "Cool Link 1:", 1, " ", 0, NULL,
-					_("Cool Link 1"), 1, NULL))
-			if (gaim_markup_extract_info_field(stripped, url_buffer, "Cool Link 2:", 1, " ", 0, NULL,
-						_("Cool Link 2"), 1, NULL))
+	{
+		found = gaim_markup_extract_info_field(stripped, url_buffer, "Cool Link 1:", 1, " ", 0, NULL,
+				_("Cool Link 1"), 1, NULL);
+		if(found)
+		{
+			has_info = TRUE;
+			found = gaim_markup_extract_info_field(stripped, url_buffer, "Cool Link 2:", 1, " ", 0, NULL,
+					_("Cool Link 2"), 1, NULL);
+			if(found)
 				gaim_markup_extract_info_field(stripped, url_buffer, "Cool Link 3:", 1, " ", 0, NULL,
 						_("Cool Link 3"), 1, NULL);
+		}
+	}
 
 	/* see if Member Since is there, and if so, extract it. */
-	gaim_markup_extract_info_field(stripped, url_buffer, "Member Since:", 1, "Last Updated:",
+	found = gaim_markup_extract_info_field(stripped, url_buffer, "Member Since:", 1, "Last Updated:",
 			'\n', NULL, _("Member Since"), 0, NULL);
+	if(found)
+		has_info = TRUE;
 
 	/* extract the Last Updated date and put it in */
-	gaim_markup_extract_info_field(stripped, url_buffer, "Last Updated:", 1, "\n", '\n', NULL,
+	found = gaim_markup_extract_info_field(stripped, url_buffer, "Last Updated:", 1, "\n", '\n', NULL,
 			_("Last Updated"), 0, NULL);
+	if(found)
+		has_info = TRUE;
 
 	/* finish off the html */
 	strcat(url_buffer, "</body></html>\n");
 	g_free(stripped);
 
-	/* show it to the user */
-	gaim_notify_formatted(data, NULL, _("Buddy Information"), NULL,
-						  url_buffer, NULL, NULL);
+	if(has_info)
+	{
+		/* show it to the user */
+		gaim_notify_formatted(info_data->gc, NULL, _("Buddy Information"), NULL,
+							  url_buffer, NULL, NULL);
+	}
+	else
+	{
+		char primary[256];
+		g_snprintf(primary, sizeof(primary),
+				_("User information for %s unavailable"), info_data->name);
+		gaim_notify_error(info_data->gc, NULL, primary,
+				_("The user's profile is empty."));			
+	}
 
 	g_free(url_buffer);
 }
 
 static void yahoo_get_info(GaimConnection *gc, const char *name)
 {
-	/* struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; */
-	char url[256];
-	g_snprintf(url, sizeof url, "%s%s", YAHOO_PROFILE_URL, name);
-	gaim_url_fetch(url, FALSE, NULL, FALSE, yahoo_got_info, gc);
+	YahooGetInfoData *data;
+	char *url;
+
+	data       = g_new0(YahooGetInfoData, 1);
+	data->gc   = gc;
+	data->name = g_strdup(name);
+
+	url = g_strdup_printf("%s%s", YAHOO_PROFILE_URL, name);
+
+	gaim_url_fetch(url, FALSE, NULL, FALSE, yahoo_got_info, data);
+
+	g_free(url);
 }
 
 static void yahoo_change_buddys_group(GaimConnection *gc, const char *who,