Ignore:
Timestamp:
2010-06-01T21:51:27Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
ad404ab
Parents:
3429b58 (diff), ba3233c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merging head.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/twitter/twitter_lib.c

    r3429b58 r704dd38  
    117117}
    118118
     119/* Warning: May return a malloc()ed value, which will be free()d on the next
     120   call. Only for short-term use. */
     121static char *twitter_parse_error(struct http_request *req)
     122{
     123        static char *ret = NULL;
     124        struct xt_parser *xp = NULL;
     125        struct xt_node *node;
     126       
     127        g_free(ret);
     128        ret = NULL;
     129       
     130        if (req->body_size > 0)
     131        {
     132                xp = xt_new(NULL, NULL);
     133                xt_feed(xp, req->reply_body, req->body_size);
     134               
     135                if ((node = xt_find_node(xp->root, "hash")) &&
     136                    (node = xt_find_node(node->children, "error")) &&
     137                    node->text_len > 0)
     138                {
     139                        ret = g_strdup_printf("%s (%s)", req->status_string, node->text);
     140                        xt_free(xp);
     141                        return ret;
     142                }
     143               
     144                xt_free(xp);
     145        }
     146       
     147        return req->status_string;
     148}
     149
    119150static void twitter_http_get_friends_ids(struct http_request *req);
    120151
     
    124155void twitter_get_friends_ids(struct im_connection *ic, int next_cursor)
    125156{
    126         struct twitter_data *td = ic->proto_data;
    127 
    128157        // Primitive, but hey! It works...     
    129158        char* args[2];
    130159        args[0] = "cursor";
    131160        args[1] = g_strdup_printf ("%d", next_cursor);
    132         twitter_http(TWITTER_FRIENDS_IDS_URL, twitter_http_get_friends_ids, ic, 0, td->user, td->pass, td->oauth_info, args, 2);
     161        twitter_http(ic, TWITTER_FRIENDS_IDS_URL, twitter_http_get_friends_ids, ic, 0, args, 2);
    133162
    134163        g_free(args[1]);
     
    196225                // It didn't go well, output the error and return.
    197226                if (++td->http_fails >= 5)
    198                         imcb_error(ic, "Could not retrieve friends. HTTP STATUS: %d", req->status_code);
     227                        imcb_error(ic, "Could not retrieve friends: %s", twitter_parse_error(req));
    199228               
    200229                return;
     
    396425        }
    397426
    398         twitter_http(TWITTER_HOME_TIMELINE_URL, twitter_http_get_home_timeline, ic, 0, td->user, td->pass, td->oauth_info, args, td->home_timeline_id ? 4 : 2);
     427        twitter_http(ic, TWITTER_HOME_TIMELINE_URL, twitter_http_get_home_timeline, ic, 0, args, td->home_timeline_id ? 4 : 2);
    399428
    400429        g_free(args[1]);
     
    434463                twitter_add_buddy(ic, status->user->screen_name, status->user->name);
    435464               
     465                strip_html(status->text);
     466               
    436467                // Say it!
    437468                if (g_strcasecmp(td->user, status->user->screen_name) == 0)
     
    471502                status = l->data;
    472503               
     504                strip_html( status->text );
    473505                if( mode_one )
    474506                        text = g_strdup_printf( "\002<\002%s\002>\002 %s",
     
    523555                // It didn't go well, output the error and return.
    524556                if (++td->http_fails >= 5)
    525                         imcb_error(ic, "Could not retrieve " TWITTER_HOME_TIMELINE_URL ". HTTP STATUS: %d", req->status_code);
     557                        imcb_error(ic, "Could not retrieve " TWITTER_HOME_TIMELINE_URL ": %s", twitter_parse_error(req));
    526558               
    527559                return;
     
    575607                // It didn't go well, output the error and return.
    576608                if (++td->http_fails >= 5)
    577                         imcb_error(ic, "Could not retrieve " TWITTER_SHOW_FRIENDS_URL " HTTP STATUS: %d", req->status_code);
     609                        imcb_error(ic, "Could not retrieve " TWITTER_SHOW_FRIENDS_URL ": %s", twitter_parse_error(req));
    578610               
    579611                return;
     
    614646void twitter_get_statuses_friends(struct im_connection *ic, int next_cursor)
    615647{
    616         struct twitter_data *td = ic->proto_data;
    617 
    618648        char* args[2];
    619649        args[0] = "cursor";
    620650        args[1] = g_strdup_printf ("%d", next_cursor);
    621651
    622         twitter_http(TWITTER_SHOW_FRIENDS_URL, twitter_http_get_statuses_friends, ic, 0, td->user, td->pass, td->oauth_info, args, 2);
     652        twitter_http(ic, TWITTER_SHOW_FRIENDS_URL, twitter_http_get_statuses_friends, ic, 0, args, 2);
    623653
    624654        g_free(args[1]);
     
    626656
    627657/**
    628  * Callback after sending a new update to twitter.
    629  */
    630 static void twitter_http_post_status(struct http_request *req)
     658 * Callback to use after sending a post request to twitter.
     659 */
     660static void twitter_http_post(struct http_request *req)
    631661{
    632662        struct im_connection *ic = req->data;
     
    639669        if (req->status_code != 200) {
    640670                // It didn't go well, output the error and return.
    641                 imcb_error(ic, "Could not post message... HTTP STATUS: %d", req->status_code);
     671                imcb_error(ic, "HTTP error: %s", twitter_parse_error(req));
    642672                return;
    643673        }
     
    649679void twitter_post_status(struct im_connection *ic, char* msg)
    650680{
    651         struct twitter_data *td = ic->proto_data;
    652 
    653681        char* args[2];
    654682        args[0] = "status";
    655683        args[1] = msg;
    656         twitter_http(TWITTER_STATUS_UPDATE_URL, twitter_http_post_status, ic, 1, td->user, td->pass, td->oauth_info, args, 2);
     684        twitter_http(ic, TWITTER_STATUS_UPDATE_URL, twitter_http_post, ic, 1, args, 2);
    657685//      g_free(args[1]);
    658686}
     
    664692void twitter_direct_messages_new(struct im_connection *ic, char *who, char *msg)
    665693{
    666         struct twitter_data *td = ic->proto_data;
    667 
    668694        char* args[4];
    669695        args[0] = "screen_name";
     
    672698        args[3] = msg;
    673699        // Use the same callback as for twitter_post_status, since it does basically the same.
    674         twitter_http(TWITTER_DIRECT_MESSAGES_NEW_URL, twitter_http_post_status, ic, 1, td->user, td->pass, td->oauth_info, args, 4);
     700        twitter_http(ic, TWITTER_DIRECT_MESSAGES_NEW_URL, twitter_http_post, ic, 1, args, 4);
    675701//      g_free(args[1]);
    676702//      g_free(args[3]);
    677703}
     704
     705void twitter_friendships_create_destroy(struct im_connection *ic, char *who, int create)
     706{
     707        char* args[2];
     708        args[0] = "screen_name";
     709        args[1] = who;
     710        twitter_http(ic, create ? TWITTER_FRIENDSHIPS_CREATE_URL : TWITTER_FRIENDSHIPS_DESTROY_URL, twitter_http_post, ic, 1, args, 2);
     711}
Note: See TracChangeset for help on using the changeset viewer.