示例#1
0
文件: twitter.c 项目: mrdon/bitlbee
static void twitter_main_loop_start(struct im_connection *ic)
{
	struct twitter_data *td = ic->proto_data;

	/* Create the room now that we "logged in". */
	if (td->flags & TWITTER_MODE_CHAT)
		twitter_groupchat_init(ic);

	imcb_log(ic, "Getting initial statuses");

	// Run this once. After this queue the main loop function (or open the
	// stream if available).
	twitter_main_loop(ic, -1, 0);
	
	if (set_getbool(&ic->acc->set, "stream")) {
		/* That fetch was just to get backlog, the stream will give
		   us the rest. \o/ */
		twitter_open_stream(ic);
		
		/* Stream sends keepalives (empty lines) or actual data at
		   least twice a minute. Disconnect if this stops. */
		ic->flags |= OPT_PONGS;
	} else {
		/* Not using the streaming API, so keep polling the old-
		   fashioned way. :-( */
		td->main_loop_id =
		    b_timeout_add(set_getint(&ic->acc->set, "fetch_interval") * 1000,
		                  twitter_main_loop, ic);
	}
}
示例#2
0
/**
 * 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);
}