Mercurial > pidgin
changeset 30835:56ef12440d52
Move queue logic in requesting user display out of slp code.
author | masca@cpw.pidgin.im |
---|---|
date | Tue, 29 Jun 2010 23:33:52 +0000 |
parents | 25a8e3ad7e30 |
children | 237e2c2874e6 |
files | libpurple/protocols/msn/slp.c libpurple/protocols/msn/slp.h libpurple/protocols/msn/user.c libpurple/protocols/msn/userlist.c libpurple/protocols/msn/userlist.h |
diffstat | 5 files changed, 144 insertions(+), 140 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/protocols/msn/slp.c Tue Jun 29 22:25:24 2010 +0000 +++ b/libpurple/protocols/msn/slp.c Tue Jun 29 23:33:52 2010 +0000 @@ -40,8 +40,6 @@ /* seconds to delay between sending buddy icon requests to the server. */ #define BUDDY_ICON_DELAY 20 -static void request_user_display(MsnUser *user); - /************************************************************************** * SLP Control @@ -91,72 +89,6 @@ * Msg Callbacks **************************************************************************/ -static gboolean -buddy_icon_cached(PurpleConnection *gc, MsnObject *obj) -{ - PurpleAccount *account; - PurpleBuddy *buddy; - const char *old; - const char *new; - - g_return_val_if_fail(obj != NULL, FALSE); - - account = purple_connection_get_account(gc); - - buddy = purple_find_buddy(account, msn_object_get_creator(obj)); - if (buddy == NULL) - return FALSE; - - old = purple_buddy_icons_get_checksum_for_user(buddy); - new = msn_object_get_sha1(obj); - - if (new == NULL) - return FALSE; - - /* If the old and new checksums are the same, and the file actually exists, - * then return TRUE */ - if (old != NULL && !strcmp(old, new)) - return TRUE; - - return FALSE; -} - -static void -msn_release_buddy_icon_request(MsnUserList *userlist) -{ - MsnUser *user; - - g_return_if_fail(userlist != NULL); - - if (purple_debug_is_verbose()) - purple_debug_info("msn", "Releasing buddy icon request\n"); - - if (userlist->buddy_icon_window > 0) - { - GQueue *queue; - PurpleAccount *account; - const char *username; - - queue = userlist->buddy_icon_requests; - - if (g_queue_is_empty(userlist->buddy_icon_requests)) - return; - - user = g_queue_pop_head(queue); - - account = userlist->session->account; - username = user->passport; - - userlist->buddy_icon_window--; - request_user_display(user); - - if (purple_debug_is_verbose()) - purple_debug_info("msn", - "msn_release_buddy_icon_request(): buddy_icon_window-- yields =%d\n", - userlist->buddy_icon_window); - } -} - /* * Called on a timeout from end_user_display(). Frees a buddy icon window slow and dequeues the next * buddy icon request if there is one. @@ -177,43 +109,6 @@ return FALSE; } -void -msn_queue_buddy_icon_request(MsnUser *user) -{ - PurpleAccount *account; - MsnObject *obj; - GQueue *queue; - - g_return_if_fail(user != NULL); - - account = user->userlist->session->account; - - obj = msn_user_get_object(user); - - if (obj == NULL) - { - purple_buddy_icons_set_for_user(account, user->passport, NULL, 0, NULL); - return; - } - - if (!buddy_icon_cached(account->gc, obj)) - { - MsnUserList *userlist; - - userlist = user->userlist; - queue = userlist->buddy_icon_requests; - - if (purple_debug_is_verbose()) - purple_debug_info("msn", "Queueing buddy icon request for %s (buddy_icon_window = %i)\n", - user->passport, userlist->buddy_icon_window); - - g_queue_push_tail(queue, user); - - if (userlist->buddy_icon_window > 0) - msn_release_buddy_icon_request(userlist); - } -} - static void got_user_display(MsnSlpCall *slpcall, const guchar *data, gsize size) @@ -282,7 +177,43 @@ } static void -request_user_display(MsnUser *user) +request_own_user_display(MsnUser *user) +{ + PurpleAccount *account; + MsnSession *session; + MsnObject *my_obj = NULL; + gconstpointer data = NULL; + const char *info; + size_t len = 0; + + if (purple_debug_is_verbose()) + purple_debug_info("msn", "Requesting our own user display\n"); + + session = user->userlist->session; + account = session->account; + my_obj = msn_user_get_object(user); + + if (my_obj != NULL) { + PurpleStoredImage *img = msn_object_get_image(my_obj); + data = purple_imgstore_get_data(img); + len = purple_imgstore_get_size(img); + info = msn_object_get_sha1(my_obj); + } + + purple_buddy_icons_set_for_user(account, user->passport, g_memdup(data, len), len, info); + + /* Free one window slot */ + session->userlist->buddy_icon_window++; + + if (purple_debug_is_verbose()) + purple_debug_info("msn", "msn_request_user_display(): buddy_icon_window++ yields =%d\n", + session->userlist->buddy_icon_window); + + msn_release_buddy_icon_request(session->userlist); +} + +void +msn_request_user_display(MsnUser *user) { PurpleAccount *account; MsnSession *session; @@ -300,40 +231,11 @@ info = msn_object_get_sha1(obj); if (g_ascii_strcasecmp(user->passport, - purple_account_get_username(account))) - { + purple_account_get_username(account))) msn_slplink_request_object(slplink, info, got_user_display, - end_user_display, obj); - } + end_user_display, obj); else - { - MsnObject *my_obj = NULL; - gconstpointer data = NULL; - size_t len = 0; - - if (purple_debug_is_verbose()) - purple_debug_info("msn", "Requesting our own user display\n"); - - my_obj = msn_user_get_object(session->user); - - if (my_obj != NULL) - { - PurpleStoredImage *img = msn_object_get_image(my_obj); - data = purple_imgstore_get_data(img); - len = purple_imgstore_get_size(img); - } - - purple_buddy_icons_set_for_user(account, user->passport, g_memdup(data, len), len, info); - - /* Free one window slot */ - session->userlist->buddy_icon_window++; - - if (purple_debug_is_verbose()) - purple_debug_info("msn", "request_user_display(): buddy_icon_window++ yields =%d\n", - session->userlist->buddy_icon_window); - - msn_release_buddy_icon_request(session->userlist); - } + request_own_user_display(user); } static void
--- a/libpurple/protocols/msn/slp.h Tue Jun 29 22:25:24 2010 +0000 +++ b/libpurple/protocols/msn/slp.h Tue Jun 29 23:33:52 2010 +0000 @@ -63,7 +63,7 @@ void send_bye(MsnSlpCall *slpcall, const char *type); -void msn_queue_buddy_icon_request(MsnUser *user); +void msn_request_user_display(MsnUser *user); void msn_request_ft(PurpleXfer *xfer);
--- a/libpurple/protocols/msn/user.c Tue Jun 29 22:25:24 2010 +0000 +++ b/libpurple/protocols/msn/user.c Tue Jun 29 23:33:52 2010 +0000 @@ -507,6 +507,71 @@ user->networkid = network; } +static gboolean +buddy_icon_cached(PurpleConnection *gc, MsnObject *obj) +{ + PurpleAccount *account; + PurpleBuddy *buddy; + const char *old; + const char *new; + + g_return_val_if_fail(obj != NULL, FALSE); + + account = purple_connection_get_account(gc); + + buddy = purple_find_buddy(account, msn_object_get_creator(obj)); + if (buddy == NULL) + return FALSE; + + old = purple_buddy_icons_get_checksum_for_user(buddy); + new = msn_object_get_sha1(obj); + + if (new == NULL) + return FALSE; + + /* If the old and new checksums are the same, and the file actually exists, + * then return TRUE */ + if (old != NULL && !strcmp(old, new)) + return TRUE; + + return FALSE; +} + +static void +queue_buddy_icon_request(MsnUser *user) +{ + PurpleAccount *account; + MsnObject *obj; + GQueue *queue; + + g_return_if_fail(user != NULL); + + account = user->userlist->session->account; + + obj = msn_user_get_object(user); + + if (obj == NULL) { + purple_buddy_icons_set_for_user(account, user->passport, NULL, 0, NULL); + return; + } + + if (!buddy_icon_cached(account->gc, obj)) { + MsnUserList *userlist; + + userlist = user->userlist; + queue = userlist->buddy_icon_requests; + + if (purple_debug_is_verbose()) + purple_debug_info("msn", "Queueing buddy icon request for %s (buddy_icon_window = %i)\n", + user->passport, userlist->buddy_icon_window); + + g_queue_push_tail(queue, user); + + if (userlist->buddy_icon_window > 0) + msn_release_buddy_icon_request(userlist); + } +} + void msn_user_set_object(MsnUser *user, MsnObject *obj) { @@ -518,7 +583,7 @@ user->msnobj = obj; if (user != user->userlist->session->user && user->list_op & MSN_LIST_FL_OP) - msn_queue_buddy_icon_request(user); + queue_buddy_icon_request(user); } void
--- a/libpurple/protocols/msn/userlist.c Tue Jun 29 22:25:24 2010 +0000 +++ b/libpurple/protocols/msn/userlist.c Tue Jun 29 23:33:52 2010 +0000 @@ -687,6 +687,42 @@ msn_add_contact_to_group(userlist->session, state, who, new_group_id); } +void +msn_release_buddy_icon_request(MsnUserList *userlist) +{ + MsnUser *user; + + g_return_if_fail(userlist != NULL); + + if (purple_debug_is_verbose()) + purple_debug_info("msn", "Releasing buddy icon request\n"); + + if (userlist->buddy_icon_window > 0) { + GQueue *queue; + PurpleAccount *account; + const char *username; + + queue = userlist->buddy_icon_requests; + + if (g_queue_is_empty(userlist->buddy_icon_requests)) + return; + + user = g_queue_pop_head(queue); + + account = userlist->session->account; + username = user->passport; + + userlist->buddy_icon_window--; + + msn_request_user_display(user); + + if (purple_debug_is_verbose()) + purple_debug_info("msn", + "msn_release_buddy_icon_request(): buddy_icon_window-- yields =%d\n", + userlist->buddy_icon_window); + } +} + /*load userlist from the Blist file cache*/ void msn_userlist_load(MsnSession *session)
--- a/libpurple/protocols/msn/userlist.h Tue Jun 29 22:25:24 2010 +0000 +++ b/libpurple/protocols/msn/userlist.h Tue Jun 29 23:33:52 2010 +0000 @@ -105,6 +105,7 @@ MsnListId list_id); void msn_userlist_rem_buddy_from_list(MsnUserList *userlist, const char *who, MsnListId list_id); +void msn_release_buddy_icon_request(MsnUserList *userlist); void msn_userlist_load(MsnSession *session);