static gboolean twitter_oauth_callback(struct oauth_info *info) { struct im_connection *ic = info->data; struct twitter_data *td; if (!g_slist_find(twitter_connections, ic)) return FALSE; td = ic->proto_data; if (info->stage == OAUTH_REQUEST_TOKEN) { char *name, *msg; if (info->request_token == NULL) { imcb_error(ic, "OAuth error: %s", twitter_parse_error(info->http)); imc_logout(ic, TRUE); return FALSE; } name = g_strdup_printf("%s_%s", td->prefix, ic->acc->user); msg = g_strdup_printf("To finish OAuth authentication, please visit " "%s and respond with the resulting PIN code.", info->auth_url); imcb_buddy_msg(ic, name, msg, 0, 0); g_free(name); g_free(msg); } else if (info->stage == OAUTH_ACCESS_TOKEN) { const char *sn; if (info->token == NULL || info->token_secret == NULL) { imcb_error(ic, "OAuth error: %s", twitter_parse_error(info->http)); imc_logout(ic, TRUE); return FALSE; } if ((sn = oauth_params_get(&info->params, "screen_name"))) { if (ic->acc->prpl->handle_cmp(sn, ic->acc->user) != 0) imcb_log(ic, "Warning: You logged in via OAuth as %s " "instead of %s.", sn, ic->acc->user); g_free(td->user); td->user = g_strdup(sn); } /* IM mods didn't do this so far and it's ugly but I should be able to get away with it... */ g_free(ic->acc->pass); ic->acc->pass = oauth_to_string(info); twitter_login_finish(ic); } return TRUE; }
/** * 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); }
/** * Callback for getting (twitter)friends... * * Be afraid, be very afraid! This function will potentially add hundreds of "friends". "Who has * hundreds of friends?" you wonder? You probably not, since you are reading the source of * BitlBee... Get a life and meet new people! */ static void twitter_http_get_users_lookup(struct http_request *req) { struct im_connection *ic = req->data; struct twitter_data *td; struct xt_parser *parser; struct twitter_xml_list *txl; GSList *l = NULL; struct twitter_xml_user *user; // Check if the connection is still active. if (!g_slist_find(twitter_connections, ic)) return; td = ic->proto_data; if (req->status_code != 200) { // It didn't go well, output the error and return. imcb_error(ic, "Could not retrieve %s: %s", TWITTER_USERS_LOOKUP_URL, twitter_parse_error(req)); imc_logout(ic, TRUE); return; } else { td->http_fails = 0; } txl = g_new0(struct twitter_xml_list, 1); txl->list = NULL; // Parse the data. parser = xt_new(NULL, txl); xt_feed(parser, req->reply_body, req->body_size); // Get the user list from the parsed xml feed. twitter_xt_get_users(parser->root, txl); xt_free(parser); // Add the users as buddies. for (l = txl->list; l; l = g_slist_next(l)) { user = l->data; twitter_add_buddy(ic, user->screen_name, user->name); } // Free the structure. txl_free(txl); twitter_get_users_lookup(ic); }