/** * Callback for getting the friends ids. */ static void twitter_http_get_friends_ids(struct http_request *req) { struct im_connection *ic; struct xt_parser *parser; struct twitter_xml_list *txl; struct twitter_data *td; ic = req->data; // Check if the connection is still active. if (!g_slist_find(twitter_connections, ic)) return; td = ic->proto_data; // Check if the HTTP request went well. More strict checks as this is // the first request we do in a session. if (req->status_code == 401) { imcb_error(ic, "Authentication failure"); imc_logout(ic, FALSE); return; } else if (req->status_code != 200) { // It didn't go well, output the error and return. imcb_error(ic, "Could not retrieve %s: %s", TWITTER_FRIENDS_IDS_URL, twitter_parse_error(req)); imc_logout(ic, TRUE); return; } else { td->http_fails = 0; } /* Create the room now that we "logged in". */ if (!td->timeline_gc && g_strcasecmp(set_getstr(&ic->acc->set, "mode"), "chat") == 0) twitter_groupchat_init(ic); txl = g_new0(struct twitter_xml_list, 1); txl->list = td->follow_ids; // Parse the data. parser = xt_new(NULL, txl); xt_feed(parser, req->reply_body, req->body_size); twitter_xt_get_friends_id_list(parser->root, txl); xt_free(parser); td->follow_ids = txl->list; if (txl->next_cursor) /* These were just numbers. Up to 4000 in a response AFAIK so if we get here we may be using a spammer account. \o/ */ twitter_get_friends_ids(ic, txl->next_cursor); else /* Now to convert all those numbers into names.. */ twitter_get_users_lookup(ic); txl->list = NULL; txl_free(txl); }
void twitter_login_finish(struct im_connection *ic) { struct twitter_data *td = ic->proto_data; td->flags &= ~TWITTER_DOING_TIMELINE; if (set_getbool(&ic->acc->set, "oauth") && !td->oauth_info) twitter_oauth_start(ic); else if (!(td->flags & TWITTER_MODE_ONE) && !(td->flags & TWITTER_HAVE_FRIENDS)) { imcb_log(ic, "Getting contact list"); twitter_get_friends_ids(ic, -1); } else twitter_main_loop_start(ic); }