static void msn_session_sync_users(MsnSession *session) { PurpleBlistNode *gnode, *cnode, *bnode; PurpleConnection *gc = purple_account_get_connection(session->account); g_return_if_fail(gc != NULL); /* The core used to use msn_add_buddy to add all buddies before * being logged in. This no longer happens, so we manually iterate * over the whole buddy list to identify sync issues. */ for (gnode = purple_blist_get_root(); gnode; gnode = gnode->next) { PurpleGroup *group = (PurpleGroup *)gnode; const char *group_name = group->name; if(!PURPLE_BLIST_NODE_IS_GROUP(gnode)) continue; for(cnode = gnode->child; cnode; cnode = cnode->next) { if(!PURPLE_BLIST_NODE_IS_CONTACT(cnode)) continue; for(bnode = cnode->child; bnode; bnode = bnode->next) { PurpleBuddy *b; if(!PURPLE_BLIST_NODE_IS_BUDDY(bnode)) continue; b = (PurpleBuddy *)bnode; if(purple_buddy_get_account(b) == purple_connection_get_account(gc)) { MsnUser *remote_user; gboolean found = FALSE; remote_user = msn_userlist_find_user(session->userlist, purple_buddy_get_name(b)); if ((remote_user != NULL) && (remote_user->list_op & MSN_LIST_FL_OP)) { int group_id; GList *l; group_id = msn_userlist_find_group_id(remote_user->userlist, group_name); for (l = remote_user->group_ids; l != NULL; l = l->next) { if (group_id == GPOINTER_TO_INT(l->data)) { found = TRUE; break; } } } if (!found) { /* The user was not on the server list or not in that group * on the server list */ msn_show_sync_issue(session, purple_buddy_get_name(b), group_name); } } } } } }
void _purple_buddy_icons_blist_loaded_cb() { PurpleBlistNode *node = purple_blist_get_root(); const char *dirname = purple_buddy_icons_get_cache_dir(); /* Doing this once here saves having to check it inside a loop. */ if (old_icons_dir != NULL) { if (!g_file_test(dirname, G_FILE_TEST_IS_DIR)) { purple_debug_info("buddyicon", "Creating icon cache directory.\n"); if (g_mkdir(dirname, S_IRUSR | S_IWUSR | S_IXUSR) < 0) { purple_debug_error("buddyicon", "Unable to create directory %s: %s\n", dirname, g_strerror(errno)); } } } while (node != NULL) { if (PURPLE_BLIST_NODE_IS_BUDDY(node)) { const char *filename; filename = purple_blist_node_get_string(node, "buddy_icon"); if (filename != NULL) { if (old_icons_dir != NULL) { migrate_buddy_icon(node, "buddy_icon", dirname, filename); } else { char *path = g_build_filename(dirname, filename, NULL); if (!g_file_test(path, G_FILE_TEST_EXISTS)) { purple_blist_node_remove_setting(node, "buddy_icon"); purple_blist_node_remove_setting(node, "icon_checksum"); } else ref_filename(filename); g_free(path); } } } else if (PURPLE_BLIST_NODE_IS_CONTACT(node) || PURPLE_BLIST_NODE_IS_CHAT(node) || PURPLE_BLIST_NODE_IS_GROUP(node)) { const char *filename; filename = purple_blist_node_get_string(node, "custom_buddy_icon"); if (filename != NULL) { if (old_icons_dir != NULL) { migrate_buddy_icon(node, "custom_buddy_icon", dirname, filename); } else { char *path = g_build_filename(dirname, filename, NULL); if (!g_file_test(path, G_FILE_TEST_EXISTS)) { purple_blist_node_remove_setting(node, "custom_buddy_icon"); } else ref_filename(filename); g_free(path); } } } node = purple_blist_node_next(node, TRUE); } }
// // Callback that's invoked once the main JSON file is downloaded. // // If the SoupMessage returns a successful response then this callback will // trigger the processing of the users asynchronously. It will also register a // a callback that will process all new buddies that are added while Pidgin is // running. // static void budicons_got_json_response (SoupSession *session, SoupMessage *message, gpointer data) { BudiconsPlugin *plugin = (BudiconsPlugin *) data; { char *url = soup_uri_to_string(soup_message_get_uri(message), FALSE); g_print("Downloaded URL %s: %d\n", url, message->status_code); g_free(url); } if (! SOUP_STATUS_IS_SUCCESSFUL (message->status_code)) { g_print("SOUP Message was not successful (%d)\n", message->status_code); return; } const char *buffer = message->response_body->data; gsize length = (gsize) message->response_body->length; const char *mime = soup_message_headers_get_content_type(message->response_headers, NULL); if (! (EQ(mime, "application/json") || EQ(mime, "text/plain"))) { g_print("Got the wrong mime type (%s) for the JSON file\n", mime); return; } // Parse the JSON file GError *error = NULL; plugin->users = budicons_json_parse_users(buffer, length, &error); if (plugin->users == NULL) { char *url = soup_uri_to_string(soup_message_get_uri(message), FALSE); g_print("Failed to parse URL %s: %s\n", url, error->message); g_free(url); g_error_free(error); return; } // Register a callback for every new buddy added purple_signal_connect( purple_blist_get_handle(), "buddy-added", plugin->purple, PURPLE_CALLBACK(budicons_buddy_added_callback), plugin ); // Collect the buddies to process PurpleBuddyList *list = purple_get_blist(); if (list == NULL) {return;} plugin->buddies = NULL; for (PurpleBlistNode *group = list->root; group; group = group->next) { if (! PURPLE_BLIST_NODE_IS_GROUP(group)) {continue;} for (PurpleBlistNode *contact = group->child; contact; contact = contact->next) { if (! PURPLE_BLIST_NODE_IS_CONTACT(contact)) {continue;} for (PurpleBlistNode *blist = contact->child; blist; blist = blist->next) { if (! PURPLE_BLIST_NODE_IS_BUDDY(blist)) {continue;} PurpleBuddy *buddy = (PurpleBuddy *) blist; plugin->buddies = g_slist_prepend(plugin->buddies, buddy); } } } // Start a few workers that will process the buddies registered so far plugin->buddy_iter = plugin->buddies; guint workers = budicons_prefs_get_workers(); for (guint i = 0; i < workers; ++i) { // No more buddies to process if (plugin->buddy_iter == NULL) {break;} // Create a new worker BudiconsWorker *worker = g_new0(BudiconsWorker, 1); worker->plugin = plugin; worker->id = i; g_print("[%d] Started a new worker\n", worker->id); budicons_worker_iter(worker); } }