Ignore:
Timestamp:
2010-07-11T17:21:21Z (14 years ago)
Author:
Sven Moritz Hallberg <pesco@…>
Branches:
master
Children:
be999a5
Parents:
3759849 (diff), 00540d4 (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:

merge with upstraem bitlbee 1.2.8

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/twitter/twitter_lib.c

    r3759849 reb6df6a  
    4242struct twitter_xml_list {
    4343        int type;
    44         int next_cursor;
     44        gint64 next_cursor;
    4545        GSList *list;
    4646        gpointer data;
     
    5858        guint64 id;
    5959};
     60
     61static void twitter_groupchat_init(struct im_connection *ic);
    6062
    6163/**
     
    153155 * Get the friends ids.
    154156 */
    155 void twitter_get_friends_ids(struct im_connection *ic, int next_cursor)
     157void twitter_get_friends_ids(struct im_connection *ic, gint64 next_cursor)
    156158{
    157159        // Primitive, but hey! It works...     
    158160        char* args[2];
    159161        args[0] = "cursor";
    160         args[1] = g_strdup_printf ("%d", next_cursor);
     162        args[1] = g_strdup_printf ("%lld", (long long) next_cursor);
    161163        twitter_http(ic, TWITTER_FRIENDS_IDS_URL, twitter_http_get_friends_ids, ic, 0, args, 2);
    162164
     
    169171static xt_status twitter_xt_next_cursor( struct xt_node *node, struct twitter_xml_list *txl )
    170172{
    171         // Do something with the cursor.
    172         txl->next_cursor = node->text != NULL ? atoi(node->text) : -1;
     173        char *end = NULL;
     174       
     175        if( node->text )
     176                txl->next_cursor = g_ascii_strtoll( node->text, &end, 10 );
     177        if( end == NULL )
     178                txl->next_cursor = -1;
    173179
    174180        return XT_HANDLED;
     
    413419 * Get the timeline.
    414420 */
    415 void twitter_get_home_timeline(struct im_connection *ic, int next_cursor)
     421void twitter_get_home_timeline(struct im_connection *ic, gint64 next_cursor)
    416422{
    417423        struct twitter_data *td = ic->proto_data;
     
    419425        char* args[4];
    420426        args[0] = "cursor";
    421         args[1] = g_strdup_printf ("%d", next_cursor);
     427        args[1] = g_strdup_printf ("%lld", (long long) next_cursor);
    422428        if (td->home_timeline_id) {
    423429                args[2] = "since_id";
     
    431437                g_free(args[3]);
    432438        }
     439}
     440
     441static void twitter_groupchat_init(struct im_connection *ic)
     442{
     443        char *name_hint;
     444        struct groupchat *gc;
     445        struct twitter_data *td = ic->proto_data;
     446       
     447        td->home_timeline_gc = gc = imcb_chat_new( ic, "home/timeline" );
     448       
     449        name_hint = g_strdup_printf( "Twitter_%s", ic->acc->user );
     450        imcb_chat_name_hint( gc, name_hint );
     451        g_free( name_hint );
    433452}
    434453
     
    445464        // Create a new groupchat if it does not exsist.
    446465        if (!td->home_timeline_gc)
    447         {   
    448                 char *name_hint = g_strdup_printf( "Twitter_%s", ic->acc->user );
    449                 td->home_timeline_gc = gc = imcb_chat_new( ic, "home/timeline" );
    450                 imcb_chat_name_hint( gc, name_hint );
    451                 g_free( name_hint );
    452                 // Add the current user to the chat...
     466                twitter_groupchat_init(ic);
     467       
     468        gc = td->home_timeline_gc;
     469        if (!gc->joined)
    453470                imcb_chat_add_buddy( gc, ic->acc->user );
    454         }
    455         else
    456         {   
    457                 gc = td->home_timeline_gc;
    458         }
    459471
    460472        for ( l = list; l ; l = g_slist_next(l) )
     
    604616       
    605617        // Check if the HTTP request went well.
    606         if (req->status_code != 200) {
     618        if (req->status_code == 401)
     619        {
     620                imcb_error( ic, "Authentication failure" );
     621                imc_logout( ic, FALSE );
     622                return;
     623        } else if (req->status_code != 200) {
    607624                // It didn't go well, output the error and return.
    608                 if (++td->http_fails >= 5)
    609                         imcb_error(ic, "Could not retrieve " TWITTER_SHOW_FRIENDS_URL ": %s", twitter_parse_error(req));
    610                
     625                imcb_error(ic, "Could not retrieve " TWITTER_SHOW_FRIENDS_URL ": %s", twitter_parse_error(req));
     626                imc_logout( ic, TRUE );
    611627                return;
    612628        } else {
    613629                td->http_fails = 0;
    614630        }
     631       
     632        if( !td->home_timeline_gc &&
     633            g_strcasecmp( set_getstr( &ic->acc->set, "mode" ), "chat" ) == 0 )
     634                twitter_groupchat_init( ic );
    615635
    616636        txl = g_new0(struct twitter_xml_list, 1);
     
    634654        // if the next_cursor is set to something bigger then 0 there are more friends to gather.
    635655        if (txl->next_cursor > 0)
     656        {
    636657                twitter_get_statuses_friends(ic, txl->next_cursor);
    637 
     658        }
     659        else
     660        {
     661                td->flags |= TWITTER_HAVE_FRIENDS;
     662                twitter_login_finish(ic);
     663        }
     664       
    638665        // Free the structure.
    639666        txl_free(txl);
     
    644671 * Get the friends.
    645672 */
    646 void twitter_get_statuses_friends(struct im_connection *ic, int next_cursor)
     673void twitter_get_statuses_friends(struct im_connection *ic, gint64 next_cursor)
    647674{
    648675        char* args[2];
    649676        args[0] = "cursor";
    650         args[1] = g_strdup_printf ("%d", next_cursor);
     677        args[1] = g_strdup_printf ("%lld", (long long) next_cursor);
    651678
    652679        twitter_http(ic, TWITTER_SHOW_FRIENDS_URL, twitter_http_get_statuses_friends, ic, 0, args, 2);
Note: See TracChangeset for help on using the changeset viewer.