Mercurial > pidgin
comparison libpurple/protocols/msn/msn.c @ 30317:ea96292336f0
Save and cancel-on-exit any URL requests, instead of checking the
connection for validity when it might be gone.
author | Elliott Sales de Andrade <qulogic@pidgin.im> |
---|---|
date | Sat, 31 Jul 2010 20:47:31 +0000 |
parents | d6f9f4320bf1 |
children | 351d07aefb09 e53f81486d57 |
comparison
equal
deleted
inserted
replaced
30313:30f16cb2f736 | 30317:ea96292336f0 |
---|---|
2202 static void | 2202 static void |
2203 msn_got_info(PurpleUtilFetchUrlData *url_data, gpointer data, | 2203 msn_got_info(PurpleUtilFetchUrlData *url_data, gpointer data, |
2204 const gchar *url_text, size_t len, const gchar *error_message) | 2204 const gchar *url_text, size_t len, const gchar *error_message) |
2205 { | 2205 { |
2206 MsnGetInfoData *info_data = (MsnGetInfoData *)data; | 2206 MsnGetInfoData *info_data = (MsnGetInfoData *)data; |
2207 MsnSession *session; | |
2207 PurpleNotifyUserInfo *user_info; | 2208 PurpleNotifyUserInfo *user_info; |
2208 char *stripped, *p, *q, *tmp; | 2209 char *stripped, *p, *q, *tmp; |
2209 char *user_url = NULL; | 2210 char *user_url = NULL; |
2210 gboolean found; | 2211 gboolean found; |
2211 gboolean has_tooltip_text = FALSE; | 2212 gboolean has_tooltip_text = FALSE; |
2219 MsnGetInfoStepTwoData *info2_data = NULL; | 2220 MsnGetInfoStepTwoData *info2_data = NULL; |
2220 #endif | 2221 #endif |
2221 | 2222 |
2222 purple_debug_info("msn", "In msn_got_info,url_text:{%s}\n",url_text); | 2223 purple_debug_info("msn", "In msn_got_info,url_text:{%s}\n",url_text); |
2223 | 2224 |
2224 /* Make sure the connection is still valid */ | 2225 session = purple_connection_get_protocol_data(info_data->gc); |
2225 /* TODO: Instead of this, we should be canceling this when we disconnect */ | 2226 session->url_datas = g_slist_remove(session->url_datas, url_data); |
2226 if (g_list_find(purple_connections_get_all(), info_data->gc) == NULL) | |
2227 { | |
2228 purple_debug_warning("msn", "invalid connection. ignoring buddy info.\n"); | |
2229 g_free(info_data->name); | |
2230 g_free(info_data); | |
2231 return; | |
2232 } | |
2233 | 2227 |
2234 user_info = purple_notify_user_info_new(); | 2228 user_info = purple_notify_user_info_new(); |
2235 has_tooltip_text = msn_tooltip_extract_info_text(user_info, info_data); | 2229 has_tooltip_text = msn_tooltip_extract_info_text(user_info, info_data); |
2236 | 2230 |
2237 if (error_message != NULL || url_text == NULL || strcmp(url_text, "") == 0) | 2231 if (error_message != NULL || url_text == NULL || strcmp(url_text, "") == 0) |
2612 info2_data->photo_url_text = photo_url_text; | 2606 info2_data->photo_url_text = photo_url_text; |
2613 | 2607 |
2614 /* Try to put the photo in there too, if there's one */ | 2608 /* Try to put the photo in there too, if there's one */ |
2615 if (photo_url_text) | 2609 if (photo_url_text) |
2616 { | 2610 { |
2617 purple_util_fetch_url_len(photo_url_text, FALSE, NULL, FALSE, MAX_HTTP_BUDDYICON_BYTES, msn_got_photo, | 2611 url_data = purple_util_fetch_url_len(photo_url_text, FALSE, NULL, FALSE, |
2618 info2_data); | 2612 MAX_HTTP_BUDDYICON_BYTES, |
2613 msn_got_photo, info2_data); | |
2614 session->url_datas = g_slist_prepend(session->url_datas, url_data); | |
2619 } | 2615 } |
2620 else | 2616 else |
2621 { | 2617 { |
2622 /* Emulate a callback */ | 2618 /* Finish the Get Info and show the user something */ |
2623 /* TODO: Huh? */ | |
2624 msn_got_photo(NULL, info2_data, NULL, 0, NULL); | 2619 msn_got_photo(NULL, info2_data, NULL, 0, NULL); |
2625 } | 2620 } |
2626 } | 2621 } |
2627 | 2622 |
2628 static void | 2623 static void |
2637 char *stripped = info2_data->stripped; | 2632 char *stripped = info2_data->stripped; |
2638 char *url_buffer = info2_data->url_buffer; | 2633 char *url_buffer = info2_data->url_buffer; |
2639 PurpleNotifyUserInfo *user_info = info2_data->user_info; | 2634 PurpleNotifyUserInfo *user_info = info2_data->user_info; |
2640 char *photo_url_text = info2_data->photo_url_text; | 2635 char *photo_url_text = info2_data->photo_url_text; |
2641 | 2636 |
2642 /* Make sure the connection is still valid if we got here by fetching a photo url */ | 2637 if (url_data) { |
2643 /* TODO: Instead of this, we should be canceling this when we disconnect */ | 2638 MsnSession *session = purple_connection_get_protocol_data(info_data->gc); |
2644 if (url_text && (error_message != NULL || | 2639 session->url_datas = g_slist_remove(session->url_datas, url_data); |
2645 g_list_find(purple_connections_get_all(), info_data->gc) == NULL)) | 2640 } |
2641 | |
2642 if (url_text && error_message) | |
2646 { | 2643 { |
2647 purple_debug_warning("msn", "invalid connection. ignoring buddy photo info.\n"); | 2644 purple_debug_warning("msn", "invalid connection. ignoring buddy photo info.\n"); |
2648 g_free(stripped); | 2645 g_free(stripped); |
2649 g_free(url_buffer); | 2646 g_free(url_buffer); |
2650 purple_notify_user_info_destroy(user_info); | 2647 purple_notify_user_info_destroy(user_info); |
2695 } | 2692 } |
2696 | 2693 |
2697 static void | 2694 static void |
2698 msn_get_info(PurpleConnection *gc, const char *name) | 2695 msn_get_info(PurpleConnection *gc, const char *name) |
2699 { | 2696 { |
2697 MsnSession *session = purple_connection_get_protocol_data(gc); | |
2700 MsnGetInfoData *data; | 2698 MsnGetInfoData *data; |
2701 char *url; | 2699 char *url; |
2700 PurpleUtilFetchUrlData *url_data; | |
2702 | 2701 |
2703 data = g_new0(MsnGetInfoData, 1); | 2702 data = g_new0(MsnGetInfoData, 1); |
2704 data->gc = gc; | 2703 data->gc = gc; |
2705 data->name = g_strdup(name); | 2704 data->name = g_strdup(name); |
2706 | 2705 |
2707 url = g_strdup_printf("%s%s", PROFILE_URL, name); | 2706 url = g_strdup_printf("%s%s", PROFILE_URL, name); |
2708 | 2707 |
2709 purple_util_fetch_url(url, FALSE, | 2708 url_data = purple_util_fetch_url(url, FALSE, |
2710 "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)", | 2709 "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)", |
2711 TRUE, msn_got_info, data); | 2710 TRUE, msn_got_info, data); |
2711 session->url_datas = g_slist_prepend(session->url_datas, url_data); | |
2712 | 2712 |
2713 g_free(url); | 2713 g_free(url); |
2714 } | 2714 } |
2715 | 2715 |
2716 static gboolean msn_load(PurplePlugin *plugin) | 2716 static gboolean msn_load(PurplePlugin *plugin) |