static void netsoul_got_photo (PurpleUtilFetchUrlData *url, void *user_data, const char *photo, size_t len, const char *error_msg) { PurpleBuddy *gb = user_data; PurpleAccount *account = purple_buddy_get_account (gb); // Check if connection is still existing PurpleConnection *gc = purple_account_get_connection (account); if (gc == NULL) return; purple_debug_info("netsoul", "netsoul_got_photo (size: %d) for %s\n", len, gb->name); /* Try to put the photo in , if there's one and is readable */ if (user_data && photo && len != 0) { if (strstr(photo, "400 Bad Request") || strstr(photo, "403 Forbidden") || strstr(photo, "404 Not Found")) purple_debug_info("netsoul", "netsoul_got_photo: error: %s\n", photo); else { PurpleStoredImage *img = purple_imgstore_add(g_memdup(photo, len), len, NULL); PurpleBuddyIcon *icon = purple_buddy_icon_new(account, gb->name, purple_imgstore_get_data(img), purple_imgstore_get_size(img), NULL); purple_buddy_set_icon(gb, icon); } } }
void purple_buddy_icon_update(PurpleBuddyIcon *icon) { PurpleConversation *conv; PurpleAccount *account; const char *username; PurpleBuddyIcon *icon_to_set; GSList *buddies; g_return_if_fail(icon != NULL); account = purple_buddy_icon_get_account(icon); username = purple_buddy_icon_get_username(icon); /* If no data exists (icon->img == NULL), then call the functions below * with NULL to unset the icon. They will then unref the icon and it should * be destroyed. The only way it wouldn't be destroyed is if someone * else is holding a reference to it, in which case they can kill * the icon when they realize it has no data. */ icon_to_set = icon->img ? icon : NULL; /* Ensure that icon remains valid throughout */ purple_buddy_icon_ref(icon); buddies = purple_find_buddies(account, username); while (buddies != NULL) { PurpleBuddy *buddy = (PurpleBuddy *)buddies->data; char *old_icon; purple_buddy_set_icon(buddy, icon_to_set); old_icon = g_strdup(purple_blist_node_get_string((PurpleBlistNode *)buddy, "buddy_icon")); if (icon->img && purple_buddy_icons_is_caching()) { const char *filename = purple_imgstore_get_filename(icon->img); purple_blist_node_set_string((PurpleBlistNode *)buddy, "buddy_icon", filename); if (icon->checksum && *icon->checksum) { purple_blist_node_set_string((PurpleBlistNode *)buddy, "icon_checksum", icon->checksum); } else { purple_blist_node_remove_setting((PurpleBlistNode *)buddy, "icon_checksum"); } ref_filename(filename); } else if (!icon->img) { purple_blist_node_remove_setting((PurpleBlistNode *)buddy, "buddy_icon"); purple_blist_node_remove_setting((PurpleBlistNode *)buddy, "icon_checksum"); } unref_filename(old_icon); g_free(old_icon); buddies = g_slist_delete_link(buddies, buddies); } conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, username, account); if (conv != NULL) purple_conv_im_set_icon(PURPLE_CONV_IM(conv), icon_to_set); /* icon's refcount was incremented above */ purple_buddy_icon_unref(icon); }