changeset 22807:0b11895cc564

Leak fixes. Avoid creating an unnecessary parallel data structure to YahooFriend.
author Daniel Atallah <daniel.atallah@gmail.com>
date Sat, 03 May 2008 21:03:13 +0000
parents f15d9ded0c45
children f62a4a7fe365
files libpurple/protocols/yahoo/yahoo.c libpurple/protocols/yahoo/yahoo_aliases.c libpurple/protocols/yahoo/yahoo_aliases.h libpurple/protocols/yahoo/yahoo_friend.c libpurple/protocols/yahoo/yahoo_friend.h
diffstat 5 files changed, 46 insertions(+), 51 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/yahoo/yahoo.c	Sat May 03 19:45:15 2008 +0000
+++ b/libpurple/protocols/yahoo/yahoo.c	Sat May 03 21:03:13 2008 +0000
@@ -3483,9 +3483,12 @@
 {
 	PurpleConnection *gc = user_data;
 	gboolean set_cookie = FALSE;
-	char *url;
+	gchar *url;
+	struct yahoo_data *yd = gc->proto_data;
 
 	g_return_if_fail(PURPLE_CONNECTION_IS_VALID(gc));
+	
+	yd->url_datas = g_slist_remove(yd->url_datas, url_data);
 
 	if (error_message != NULL)
 		purple_debug_error("yahoo", "Requesting mail login token failed: %s\n", error_message);
@@ -3500,7 +3503,6 @@
 	}
 
 	if (!set_cookie) {
-		struct yahoo_data *yd = gc->proto_data;
 		purple_debug_error("yahoo", "No mail login token; forwarding to login screen.\n");
 		url = g_strdup(yd->jp ? YAHOOJP_MAIL_URL : YAHOO_MAIL_URL);
 	}
@@ -3541,7 +3543,9 @@
 
 	g_free(request);
 
-	if (url_data == NULL) {
+	if (url_data != NULL)
+		yd->url_datas = g_slist_prepend(yd->url_datas, url_data);
+	else {
 		const char *yahoo_mail_url = (yd->jp ? YAHOOJP_MAIL_URL : YAHOO_MAIL_URL);
 		purple_debug_error("yahoo",
 				   "Unable to request mail login token; forwarding to login screen.");
--- a/libpurple/protocols/yahoo/yahoo_aliases.c	Sat May 03 19:45:15 2008 +0000
+++ b/libpurple/protocols/yahoo/yahoo_aliases.c	Sat May 03 21:03:13 2008 +0000
@@ -32,6 +32,7 @@
 #include "version.h"
 #include "yahoo.h"
 #include "yahoo_aliases.h"
+#include "yahoo_friend.h"
 #include "yahoo_packet.h"
 
 /* I hate hardcoding this stuff, but Yahoo never sends us anything to use.  Someone in the know may be able to tweak this URL */
@@ -70,7 +71,8 @@
 	} else {
 		gchar *full_name, *nick_name, *alias;
 		const char *yid, *id, *fn, *ln, *nn;
-		PurpleBuddy *b = NULL;
+		YahooFriend *f;
+		PurpleBuddy *b;
 		xmlnode *item, *contacts;
 
 		/* Put our web response into a xmlnode for easy management */
@@ -108,19 +110,12 @@
 					alias = full_name;  /* If no Yahoo nickname, we can use the full_name created above */
 
 				/*  Find the local buddy that matches */
+				f = yahoo_friend_find(cb->gc, yid);
 				b = purple_find_buddy(cb->gc->account, yid);
 
 				/*  If we don't find a matching buddy, ignore the alias !!  */
-				if (b != NULL) {
-					/* Create an object that we can attach to the buddies proto_data pointer */
-					struct YahooUser *yu;
-					yu = g_new0(struct YahooUser, 1);
-					yu->id = g_strdup(id);
-					yu->firstname = g_strdup(fn);
-					yu->lastname = g_strdup(ln);
-					yu->nickname = g_strdup(nn);
-					/* TODO: Isn't there a possiblity that b->proto_data is already set? */
-					b->proto_data=yu;
+				if (f != NULL && b != NULL) {
+					yahoo_friend_set_alias_id(f, id);
 
 					/* Finally, if we received an alias, we better update the buddy list */
 					if (alias != NULL) {
@@ -237,14 +232,13 @@
 yahoo_update_alias(PurpleConnection *gc, const char *who, const char *alias)
 {
 	struct yahoo_data *yd;
-	struct YahooUser *yu;
 	char *content, *url, *request, *webpage, *webaddress, *strtmp;
 	char *escaped_alias, *alias_jp, *converted_alias_jp;
 	int inttmp;
 	struct callback_data *cb;
-	PurpleBuddy *buddy;
 	PurpleUtilFetchUrlData *url_data;
 	gboolean use_whole_url = FALSE;
+	YahooFriend *f;
 
 	/* use whole URL if using HTTP Proxy */
 	if ((gc->account->proxy_info) && (gc->account->proxy_info->type == PURPLE_PROXY_HTTP))
@@ -254,20 +248,19 @@
 	g_return_if_fail(who != NULL);
 	g_return_if_fail(gc != NULL);
 
-	purple_debug_info("yahoo", "Sending '%s' as new alias for user '%s'.\n",alias, who);
+	purple_debug_info("yahoo", "Sending '%s' as new alias for user '%s'.\n", alias, who);
 
-	buddy = purple_find_buddy(gc->account, who);
-	if (buddy == NULL || buddy->proto_data == NULL) {
+	f = yahoo_friend_find(gc, who);
+	if (f == NULL) {
 		purple_debug_info("yahoo", "Missing proto_data (get_yahoo_aliases must have failed), bailing out\n");
 		return;
 	}
 
 	yd = gc->proto_data;
-	yu = buddy->proto_data;
 
 	/* Using callback_data so I have access to gc in the callback function */
 	cb = g_new0(struct callback_data, 1);
-	cb->id = g_strdup(yu->id);
+	cb->id = g_strdup(yahoo_friend_get_alias_id(f));
 	cb->gc = gc;
 
 	/*  Build all the info to make the web request */
@@ -279,7 +272,7 @@
 		converted_alias_jp = yahoo_convert_to_numeric(alias_jp);
 		content = g_strdup_printf("<ab k=\"%s\" cc=\"1\">\n"
 		                          "<ct e=\"1\"  yi='%s' id='%s' nn='%s' pr='0' />\n</ab>\r\n",
-		                          gc->account->username, who, yu->id, converted_alias_jp);
+		                          gc->account->username, who, yahoo_friend_get_alias_id(f), converted_alias_jp);
 		free(converted_alias_jp);
 		g_free(alias_jp);
 	}
@@ -287,7 +280,7 @@
 		escaped_alias = g_markup_escape_text(alias, strlen(alias));
 		content = g_strdup_printf("<?xml version=\"1.0\" encoding=\"utf-8\"?><ab k=\"%s\" cc=\"1\">\n"
 		                          "<ct e=\"1\"  yi='%s' id='%s' nn='%s' pr='0' />\n</ab>\r\n",
-		                          gc->account->username, who, yu->id, escaped_alias);
+		                          gc->account->username, who, yahoo_friend_get_alias_id(f), escaped_alias);
 		g_free(escaped_alias);
 	}
 
--- a/libpurple/protocols/yahoo/yahoo_aliases.h	Sat May 03 19:45:15 2008 +0000
+++ b/libpurple/protocols/yahoo/yahoo_aliases.h	Sat May 03 21:03:13 2008 +0000
@@ -33,18 +33,6 @@
 #include "yahoo.h"
 #include "yahoo_packet.h"
 
-
-/**
- * The additional protocol specific info attached to each buddy.  We need
- * to store the unique numeric id number to allow us to push alias changes.
- */
-struct YahooUser
-{
-    const char *id;             /* The yahoo accountid for this buddy (not YahooID but numeric value) */
-    char *firstname;            /* Storing this information for no real reason, just because */
-    char *lastname;             /* Storing this information for no real reason, just because */
-    char *nickname;             /* Storing this information for no real reason, just because */
-};
-
 void yahoo_update_alias(PurpleConnection *gc, const char *who, const char *alias);
 void yahoo_fetch_aliases(PurpleConnection *gc);
+
--- a/libpurple/protocols/yahoo/yahoo_friend.c	Sat May 03 19:45:15 2008 +0000
+++ b/libpurple/protocols/yahoo/yahoo_friend.c	Sat May 03 21:03:13 2008 +0000
@@ -76,8 +76,7 @@
 
 void yahoo_friend_set_ip(YahooFriend *f, const char *ip)
 {
-	if (f->ip)
-		g_free(f->ip);
+	g_free(f->ip);
 	f->ip = g_strdup(ip);
 }
 
@@ -88,8 +87,7 @@
 
 void yahoo_friend_set_game(YahooFriend *f, const char *game)
 {
-	if (f->game)
-		g_free(f->game);
+	g_free(f->game);
 
 	if (game)
 		f->game = g_strdup(game);
@@ -104,8 +102,7 @@
 
 void yahoo_friend_set_status_message(YahooFriend *f, char *msg)
 {
-	if (f->msg)
-		g_free(f->msg);
+	g_free(f->msg);
 
 	f->msg = msg;
 }
@@ -125,15 +122,24 @@
 	return !f->bicon_sent_request;
 }
 
+void yahoo_friend_set_alias_id(YahooFriend *f, const char *alias_id)
+{
+	g_free(f->alias_id);
+	f->alias_id = g_strdup(alias_id);
+}
+
+const char *yahoo_friend_get_alias_id(YahooFriend *f)
+{
+	return f->alias_id;
+}
+
 void yahoo_friend_free(gpointer p)
 {
 	YahooFriend *f = p;
-	if (f->msg)
-		g_free(f->msg);
-	if (f->game)
-		g_free(f->game);
-	if (f->ip)
-		g_free(f->ip);
+	g_free(f->msg);
+	g_free(f->game);
+	g_free(f->ip);
+	g_free(f->alias_id);
 	g_free(f);
 }
 
--- a/libpurple/protocols/yahoo/yahoo_friend.h	Sat May 03 19:45:15 2008 +0000
+++ b/libpurple/protocols/yahoo/yahoo_friend.h	Sat May 03 21:03:13 2008 +0000
@@ -39,16 +39,17 @@
  */
 typedef struct _YahooFriend {
 	enum yahoo_status status;
-	char *msg;
-	char *game;
+	gchar *msg;
+	gchar *game;
 	int idle;
 	int away;
 	gboolean sms;
-	char *ip;
+	gchar *ip;
 	gboolean bicon_sent_request;
 	YahooPresenceVisibility presence;
 	int protocol; /* 1=LCS, 2=MSN*/
 	long int version_id;
+	gchar *alias_id;
 } YahooFriend;
 
 YahooFriend *yahoo_friend_find(PurpleConnection *gc, const char *name);
@@ -63,6 +64,9 @@
 void yahoo_friend_set_status_message(YahooFriend *f, char *msg);
 const char *yahoo_friend_get_status_message(YahooFriend *f);
 
+void yahoo_friend_set_alias_id(YahooFriend *f, const char *alias_id);
+const char *yahoo_friend_get_alias_id(YahooFriend *f);
+
 void yahoo_friend_set_buddy_icon_need_request(YahooFriend *f, gboolean needs);
 gboolean yahoo_friend_get_buddy_icon_need_request(YahooFriend *f);