Ignore:
Timestamp:
2012-09-22T12:12:12Z (12 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
11ec078
Parents:
55ccc9a0
Message:

Little cleanup. Use xt_from_string() where possible.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/twitter/twitter_lib.c

    r55ccc9a0 rd0752e8  
    168168{
    169169        static char *ret = NULL;
    170         struct xt_parser *xp = NULL;
    171         struct xt_node *node, *err;
     170        struct xt_node *root, *node, *err;
    172171
    173172        g_free(ret);
     
    175174
    176175        if (req->body_size > 0) {
    177                 xp = xt_new(NULL, NULL);
    178                 xt_feed(xp, req->reply_body, req->body_size);
     176                root = xt_from_string(req->reply_body, req->body_size);
    179177               
    180                 for (node = xp->root; node; node = node->next)
     178                for (node = root; node; node = node->next)
    181179                        if ((err = xt_find_node(node->children, "error")) && err->text_len > 0) {
    182180                                ret = g_strdup_printf("%s (%s)", req->status_string, err->text);
     
    184182                        }
    185183
    186                 xt_free(xp);
     184                xt_free_node(root);
    187185        }
    188186
     
    256254{
    257255        struct im_connection *ic;
    258         struct xt_parser *parser;
     256        struct xt_node *parsed;
    259257        struct twitter_xml_list *txl;
    260258        struct twitter_data *td;
     
    292290
    293291        // Parse the data.
    294         parser = xt_new(NULL, txl);
    295         xt_feed(parser, req->reply_body, req->body_size);
    296         twitter_xt_get_friends_id_list(parser->root, txl);
    297         xt_free(parser);
     292        parsed = xt_from_string(req->reply_body, req->body_size);
     293        twitter_xt_get_friends_id_list(parsed, txl);
     294        xt_free_node(parsed);
    298295
    299296        td->follow_ids = txl->list;
     
    352349        struct im_connection *ic = req->data;
    353350        struct twitter_data *td;
    354         struct xt_parser *parser;
     351        struct xt_node *parsed;
    355352        struct twitter_xml_list *txl;
    356353        GSList *l = NULL;
     
    377374
    378375        // Parse the data.
    379         parser = xt_new(NULL, txl);
    380         xt_feed(parser, req->reply_body, req->body_size);
     376        parsed = xt_from_string(req->reply_body, req->body_size);
    381377
    382378        // Get the user list from the parsed xml feed.
    383         twitter_xt_get_users(parser->root, txl);
    384         xt_free(parser);
     379        twitter_xt_get_users(parsed, txl);
     380        xt_free_node(parsed);
    385381
    386382        // Add the users as buddies.
     
    886882        struct im_connection *ic = req->data;
    887883        struct twitter_data *td;
    888         struct xt_parser *parser;
     884        struct xt_node *parsed;
    889885        struct twitter_xml_list *txl;
    890886
     
    913909
    914910        // Parse the data.
    915         parser = xt_new(NULL, txl);
    916         xt_feed(parser, req->reply_body, req->body_size);
     911        parsed = xt_from_string(req->reply_body, req->body_size);
    917912        // The root <statuses> node should hold the list of statuses <status>
    918         twitter_xt_get_status_list(ic, parser->root, txl);
    919         xt_free(parser);
     913        twitter_xt_get_status_list(ic, parsed, txl);
     914        xt_free_node(parsed);
    920915
    921916        td->home_timeline_obj = txl;
     
    934929        struct im_connection *ic = req->data;
    935930        struct twitter_data *td;
    936         struct xt_parser *parser;
     931        struct xt_node *parsed;
    937932        struct twitter_xml_list *txl;
    938933
     
    961956
    962957        // Parse the data.
    963         parser = xt_new(NULL, txl);
    964         xt_feed(parser, req->reply_body, req->body_size);
     958        parsed = xt_from_string(req->reply_body, req->body_size);
    965959        // The root <statuses> node should hold the list of statuses <status>
    966         twitter_xt_get_status_list(ic, parser->root, txl);
    967         xt_free(parser);
     960        twitter_xt_get_status_list(ic, parsed, txl);
     961        xt_free_node(parsed);
    968962
    969963        td->mentions_obj = txl;
     
    999993
    1000994        if (req->body_size > 0) {
    1001                 struct xt_parser *xp = NULL;
    1002                 struct xt_node *node;
    1003 
    1004                 xp = xt_new(NULL, NULL);
    1005                 xt_feed(xp, req->reply_body, req->body_size);
    1006 
    1007                 if ((node = xt_find_node(xp->root, "status")) &&
     995                struct xt_node *parsed, *node;
     996
     997                parsed = xt_from_string(req->reply_body, req->body_size);
     998
     999                if ((node = xt_find_node(parsed, "status")) &&
    10081000                    (node = xt_find_node(node->children, "id")) && node->text)
    10091001                        td->last_status_id = g_ascii_strtoull(node->text, NULL, 10);
    10101002
    1011                 xt_free(xp);
     1003                xt_free_node(parsed);
    10121004        }
    10131005}
Note: See TracChangeset for help on using the changeset viewer.