Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/twitter/twitter_lib.c

    r3d93aed r7d53efb  
    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. */
    121 static 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 
    150119static void twitter_http_get_friends_ids(struct http_request *req);
    151120
     
    155124void twitter_get_friends_ids(struct im_connection *ic, int next_cursor)
    156125{
     126        struct twitter_data *td = ic->proto_data;
     127
    157128        // Primitive, but hey! It works...     
    158129        char* args[2];
    159130        args[0] = "cursor";
    160131        args[1] = g_strdup_printf ("%d", next_cursor);
    161         twitter_http(ic, TWITTER_FRIENDS_IDS_URL, twitter_http_get_friends_ids, ic, 0, args, 2);
     132        twitter_http(TWITTER_FRIENDS_IDS_URL, twitter_http_get_friends_ids, ic, 0, td->user, td->pass, td->oauth_info, args, 2);
    162133
    163134        g_free(args[1]);
     
    225196                // It didn't go well, output the error and return.
    226197                if (++td->http_fails >= 5)
    227                         imcb_error(ic, "Could not retrieve friends: %s", twitter_parse_error(req));
     198                        imcb_error(ic, "Could not retrieve friends. HTTP STATUS: %d", req->status_code);
    228199               
    229200                return;
     
    425396        }
    426397
    427         twitter_http(ic, TWITTER_HOME_TIMELINE_URL, twitter_http_get_home_timeline, ic, 0, args, td->home_timeline_id ? 4 : 2);
     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);
    428399
    429400        g_free(args[1]);
     
    463434                twitter_add_buddy(ic, status->user->screen_name, status->user->name);
    464435               
    465                 strip_html(status->text);
    466                
    467436                // Say it!
    468437                if (g_strcasecmp(td->user, status->user->screen_name) == 0)
     
    502471                status = l->data;
    503472               
    504                 strip_html( status->text );
    505473                if( mode_one )
    506474                        text = g_strdup_printf( "\002<\002%s\002>\002 %s",
     
    555523                // It didn't go well, output the error and return.
    556524                if (++td->http_fails >= 5)
    557                         imcb_error(ic, "Could not retrieve " TWITTER_HOME_TIMELINE_URL ": %s", twitter_parse_error(req));
     525                        imcb_error(ic, "Could not retrieve " TWITTER_HOME_TIMELINE_URL ". HTTP STATUS: %d", req->status_code);
    558526               
    559527                return;
     
    607575                // It didn't go well, output the error and return.
    608576                if (++td->http_fails >= 5)
    609                         imcb_error(ic, "Could not retrieve " TWITTER_SHOW_FRIENDS_URL ": %s", twitter_parse_error(req));
     577                        imcb_error(ic, "Could not retrieve " TWITTER_SHOW_FRIENDS_URL " HTTP STATUS: %d", req->status_code);
    610578               
    611579                return;
     
    646614void twitter_get_statuses_friends(struct im_connection *ic, int next_cursor)
    647615{
     616        struct twitter_data *td = ic->proto_data;
     617
    648618        char* args[2];
    649619        args[0] = "cursor";
    650620        args[1] = g_strdup_printf ("%d", next_cursor);
    651621
    652         twitter_http(ic, TWITTER_SHOW_FRIENDS_URL, twitter_http_get_statuses_friends, ic, 0, args, 2);
     622        twitter_http(TWITTER_SHOW_FRIENDS_URL, twitter_http_get_statuses_friends, ic, 0, td->user, td->pass, td->oauth_info, args, 2);
    653623
    654624        g_free(args[1]);
     
    656626
    657627/**
    658  * Callback after sending a new update to twitter.
    659  */
    660 static void twitter_http_post_status(struct http_request *req)
     628 * Callback to use after sending a post request to twitter.
     629 */
     630static void twitter_http_post(struct http_request *req)
    661631{
    662632        struct im_connection *ic = req->data;
     
    669639        if (req->status_code != 200) {
    670640                // It didn't go well, output the error and return.
    671                 imcb_error(ic, "Could not post message: %s", twitter_parse_error(req));
     641                imcb_error(ic, "HTTP Error... STATUS: %d", req->status_code);
    672642                return;
    673643        }
     
    679649void twitter_post_status(struct im_connection *ic, char* msg)
    680650{
     651        struct twitter_data *td = ic->proto_data;
     652
    681653        char* args[2];
    682654        args[0] = "status";
    683655        args[1] = msg;
    684         twitter_http(ic, TWITTER_STATUS_UPDATE_URL, twitter_http_post_status, ic, 1, args, 2);
     656        twitter_http(TWITTER_STATUS_UPDATE_URL, twitter_http_post, ic, 1, td->user, td->pass, td->oauth_info, args, 2);
    685657//      g_free(args[1]);
    686658}
     
    692664void twitter_direct_messages_new(struct im_connection *ic, char *who, char *msg)
    693665{
     666        struct twitter_data *td = ic->proto_data;
     667
    694668        char* args[4];
    695669        args[0] = "screen_name";
     
    698672        args[3] = msg;
    699673        // Use the same callback as for twitter_post_status, since it does basically the same.
    700         twitter_http(ic, TWITTER_DIRECT_MESSAGES_NEW_URL, twitter_http_post_status, ic, 1, args, 4);
     674        twitter_http(TWITTER_DIRECT_MESSAGES_NEW_URL, twitter_http_post, ic, 1, td->user, td->pass, td->oauth_info, args, 4);
    701675//      g_free(args[1]);
    702676//      g_free(args[3]);
    703677}
     678
     679void twitter_friendships_create_destroy(struct im_connection *ic, char *who, int create)
     680{
     681        struct twitter_data *td = ic->proto_data;
     682
     683        char* args[2];
     684        args[0] = "screen_name";
     685        args[1] = who;
     686        twitter_http(create ? TWITTER_FRIENDSHIPS_CREATE_URL : TWITTER_FRIENDSHIPS_DESTROY_URL, twitter_http_post, ic, 1, td->user, td->pass, td->oauth_info, args, 2);
     687}
     688
     689
     690
Note: See TracChangeset for help on using the changeset viewer.