Mercurial > pidgin.yaz
comparison libpurple/protocols/yahoo/yahoo_aliases.c @ 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 | 0d7ceae153bd |
children | 318905da6f8d |
comparison
equal
deleted
inserted
replaced
22806:f15d9ded0c45 | 22807:0b11895cc564 |
---|---|
30 #include "debug.h" | 30 #include "debug.h" |
31 #include "util.h" | 31 #include "util.h" |
32 #include "version.h" | 32 #include "version.h" |
33 #include "yahoo.h" | 33 #include "yahoo.h" |
34 #include "yahoo_aliases.h" | 34 #include "yahoo_aliases.h" |
35 #include "yahoo_friend.h" | |
35 #include "yahoo_packet.h" | 36 #include "yahoo_packet.h" |
36 | 37 |
37 /* I hate hardcoding this stuff, but Yahoo never sends us anything to use. Someone in the know may be able to tweak this URL */ | 38 /* I hate hardcoding this stuff, but Yahoo never sends us anything to use. Someone in the know may be able to tweak this URL */ |
38 #define YAHOO_ALIAS_FETCH_URL "http://address.yahoo.com/yab/us?v=XM&prog=ymsgr&.intl=us&diffs=1&t=0&tags=short&rt=0&prog-ver=8.1.0.249&useutf8=1&legenc=codepage-1252" | 39 #define YAHOO_ALIAS_FETCH_URL "http://address.yahoo.com/yab/us?v=XM&prog=ymsgr&.intl=us&diffs=1&t=0&tags=short&rt=0&prog-ver=8.1.0.249&useutf8=1&legenc=codepage-1252" |
39 #define YAHOO_ALIAS_UPDATE_URL "http://address.yahoo.com/yab/us?v=XM&prog=ymsgr&.intl=us&sync=1&tags=short&noclear=1&useutf8=1&legenc=codepage-1252" | 40 #define YAHOO_ALIAS_UPDATE_URL "http://address.yahoo.com/yab/us?v=XM&prog=ymsgr&.intl=us&sync=1&tags=short&noclear=1&useutf8=1&legenc=codepage-1252" |
68 purple_debug_info("yahoo", "No Aliases to process.%s%s\n", | 69 purple_debug_info("yahoo", "No Aliases to process.%s%s\n", |
69 error_message ? " Error:" : "", error_message ? error_message : ""); | 70 error_message ? " Error:" : "", error_message ? error_message : ""); |
70 } else { | 71 } else { |
71 gchar *full_name, *nick_name, *alias; | 72 gchar *full_name, *nick_name, *alias; |
72 const char *yid, *id, *fn, *ln, *nn; | 73 const char *yid, *id, *fn, *ln, *nn; |
73 PurpleBuddy *b = NULL; | 74 YahooFriend *f; |
75 PurpleBuddy *b; | |
74 xmlnode *item, *contacts; | 76 xmlnode *item, *contacts; |
75 | 77 |
76 /* Put our web response into a xmlnode for easy management */ | 78 /* Put our web response into a xmlnode for easy management */ |
77 contacts = xmlnode_from_str(url_text, -1); | 79 contacts = xmlnode_from_str(url_text, -1); |
78 | 80 |
106 alias = nick_name; /* If we have a nickname from Yahoo, let's use it */ | 108 alias = nick_name; /* If we have a nickname from Yahoo, let's use it */ |
107 else if (strlen(full_name) != 0) | 109 else if (strlen(full_name) != 0) |
108 alias = full_name; /* If no Yahoo nickname, we can use the full_name created above */ | 110 alias = full_name; /* If no Yahoo nickname, we can use the full_name created above */ |
109 | 111 |
110 /* Find the local buddy that matches */ | 112 /* Find the local buddy that matches */ |
113 f = yahoo_friend_find(cb->gc, yid); | |
111 b = purple_find_buddy(cb->gc->account, yid); | 114 b = purple_find_buddy(cb->gc->account, yid); |
112 | 115 |
113 /* If we don't find a matching buddy, ignore the alias !! */ | 116 /* If we don't find a matching buddy, ignore the alias !! */ |
114 if (b != NULL) { | 117 if (f != NULL && b != NULL) { |
115 /* Create an object that we can attach to the buddies proto_data pointer */ | 118 yahoo_friend_set_alias_id(f, id); |
116 struct YahooUser *yu; | |
117 yu = g_new0(struct YahooUser, 1); | |
118 yu->id = g_strdup(id); | |
119 yu->firstname = g_strdup(fn); | |
120 yu->lastname = g_strdup(ln); | |
121 yu->nickname = g_strdup(nn); | |
122 /* TODO: Isn't there a possiblity that b->proto_data is already set? */ | |
123 b->proto_data=yu; | |
124 | 119 |
125 /* Finally, if we received an alias, we better update the buddy list */ | 120 /* Finally, if we received an alias, we better update the buddy list */ |
126 if (alias != NULL) { | 121 if (alias != NULL) { |
127 serv_got_alias(cb->gc, yid, alias); | 122 serv_got_alias(cb->gc, yid, alias); |
128 purple_debug_info("yahoo","Fetched alias '%s' (%s)\n",alias,id); | 123 purple_debug_info("yahoo","Fetched alias '%s' (%s)\n",alias,id); |
235 | 230 |
236 void | 231 void |
237 yahoo_update_alias(PurpleConnection *gc, const char *who, const char *alias) | 232 yahoo_update_alias(PurpleConnection *gc, const char *who, const char *alias) |
238 { | 233 { |
239 struct yahoo_data *yd; | 234 struct yahoo_data *yd; |
240 struct YahooUser *yu; | |
241 char *content, *url, *request, *webpage, *webaddress, *strtmp; | 235 char *content, *url, *request, *webpage, *webaddress, *strtmp; |
242 char *escaped_alias, *alias_jp, *converted_alias_jp; | 236 char *escaped_alias, *alias_jp, *converted_alias_jp; |
243 int inttmp; | 237 int inttmp; |
244 struct callback_data *cb; | 238 struct callback_data *cb; |
245 PurpleBuddy *buddy; | |
246 PurpleUtilFetchUrlData *url_data; | 239 PurpleUtilFetchUrlData *url_data; |
247 gboolean use_whole_url = FALSE; | 240 gboolean use_whole_url = FALSE; |
241 YahooFriend *f; | |
248 | 242 |
249 /* use whole URL if using HTTP Proxy */ | 243 /* use whole URL if using HTTP Proxy */ |
250 if ((gc->account->proxy_info) && (gc->account->proxy_info->type == PURPLE_PROXY_HTTP)) | 244 if ((gc->account->proxy_info) && (gc->account->proxy_info->type == PURPLE_PROXY_HTTP)) |
251 use_whole_url = TRUE; | 245 use_whole_url = TRUE; |
252 | 246 |
253 g_return_if_fail(alias != NULL); | 247 g_return_if_fail(alias != NULL); |
254 g_return_if_fail(who != NULL); | 248 g_return_if_fail(who != NULL); |
255 g_return_if_fail(gc != NULL); | 249 g_return_if_fail(gc != NULL); |
256 | 250 |
257 purple_debug_info("yahoo", "Sending '%s' as new alias for user '%s'.\n",alias, who); | 251 purple_debug_info("yahoo", "Sending '%s' as new alias for user '%s'.\n", alias, who); |
258 | 252 |
259 buddy = purple_find_buddy(gc->account, who); | 253 f = yahoo_friend_find(gc, who); |
260 if (buddy == NULL || buddy->proto_data == NULL) { | 254 if (f == NULL) { |
261 purple_debug_info("yahoo", "Missing proto_data (get_yahoo_aliases must have failed), bailing out\n"); | 255 purple_debug_info("yahoo", "Missing proto_data (get_yahoo_aliases must have failed), bailing out\n"); |
262 return; | 256 return; |
263 } | 257 } |
264 | 258 |
265 yd = gc->proto_data; | 259 yd = gc->proto_data; |
266 yu = buddy->proto_data; | |
267 | 260 |
268 /* Using callback_data so I have access to gc in the callback function */ | 261 /* Using callback_data so I have access to gc in the callback function */ |
269 cb = g_new0(struct callback_data, 1); | 262 cb = g_new0(struct callback_data, 1); |
270 cb->id = g_strdup(yu->id); | 263 cb->id = g_strdup(yahoo_friend_get_alias_id(f)); |
271 cb->gc = gc; | 264 cb->gc = gc; |
272 | 265 |
273 /* Build all the info to make the web request */ | 266 /* Build all the info to make the web request */ |
274 url = yd->jp? YAHOOJP_ALIAS_UPDATE_URL: YAHOO_ALIAS_UPDATE_URL; | 267 url = yd->jp? YAHOOJP_ALIAS_UPDATE_URL: YAHOO_ALIAS_UPDATE_URL; |
275 purple_url_parse(url, &webaddress, &inttmp, &webpage, &strtmp, &strtmp); | 268 purple_url_parse(url, &webaddress, &inttmp, &webpage, &strtmp, &strtmp); |
277 if (yd->jp) { | 270 if (yd->jp) { |
278 alias_jp = g_convert(alias, strlen(alias), "EUC-JP", "UTF-8", NULL, NULL, NULL); | 271 alias_jp = g_convert(alias, strlen(alias), "EUC-JP", "UTF-8", NULL, NULL, NULL); |
279 converted_alias_jp = yahoo_convert_to_numeric(alias_jp); | 272 converted_alias_jp = yahoo_convert_to_numeric(alias_jp); |
280 content = g_strdup_printf("<ab k=\"%s\" cc=\"1\">\n" | 273 content = g_strdup_printf("<ab k=\"%s\" cc=\"1\">\n" |
281 "<ct e=\"1\" yi='%s' id='%s' nn='%s' pr='0' />\n</ab>\r\n", | 274 "<ct e=\"1\" yi='%s' id='%s' nn='%s' pr='0' />\n</ab>\r\n", |
282 gc->account->username, who, yu->id, converted_alias_jp); | 275 gc->account->username, who, yahoo_friend_get_alias_id(f), converted_alias_jp); |
283 free(converted_alias_jp); | 276 free(converted_alias_jp); |
284 g_free(alias_jp); | 277 g_free(alias_jp); |
285 } | 278 } |
286 else { | 279 else { |
287 escaped_alias = g_markup_escape_text(alias, strlen(alias)); | 280 escaped_alias = g_markup_escape_text(alias, strlen(alias)); |
288 content = g_strdup_printf("<?xml version=\"1.0\" encoding=\"utf-8\"?><ab k=\"%s\" cc=\"1\">\n" | 281 content = g_strdup_printf("<?xml version=\"1.0\" encoding=\"utf-8\"?><ab k=\"%s\" cc=\"1\">\n" |
289 "<ct e=\"1\" yi='%s' id='%s' nn='%s' pr='0' />\n</ab>\r\n", | 282 "<ct e=\"1\" yi='%s' id='%s' nn='%s' pr='0' />\n</ab>\r\n", |
290 gc->account->username, who, yu->id, escaped_alias); | 283 gc->account->username, who, yahoo_friend_get_alias_id(f), escaped_alias); |
291 g_free(escaped_alias); | 284 g_free(escaped_alias); |
292 } | 285 } |
293 | 286 |
294 request = g_strdup_printf("POST %s%s/%s HTTP/1.1\r\n" | 287 request = g_strdup_printf("POST %s%s/%s HTTP/1.1\r\n" |
295 "User-Agent: Mozilla/4.0 (compatible; MSIE 5.5)\r\n" | 288 "User-Agent: Mozilla/4.0 (compatible; MSIE 5.5)\r\n" |