Changeset 2abceca


Ignore:
Timestamp:
2010-04-06T17:25:51Z (14 years ago)
Author:
Geert Mulders <g.c.w.m.mulders@…>
Branches:
master
Children:
0519b0a
Parents:
62d2cfb
Message:

Updates made as a result to the comments on the review.

Location:
protocols/twitter
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • protocols/twitter/twitter.c

    r62d2cfb r2abceca  
    3535        struct im_connection *ic = data;
    3636        // Check if we are still logged in...
    37         if ((ic->flags & OPT_LOGGED_IN) != OPT_LOGGED_IN)
     37        // We are logged in if the flag says so and the connection is still in the connections list.
     38        if ((ic->flags & OPT_LOGGED_IN) != OPT_LOGGED_IN
     39                        && !g_slist_find( twitter_connections, ic ))
    3840                return 0;
    3941
     
    5557        set_t *s;
    5658        s = set_add( &acc->set, "use_groupchat", "false", set_eval_bool, acc );
     59        s->flags |= ACC_SET_OFFLINE_ONLY;
    5760}
    5861
     
    7275        ic->proto_data = td;
    7376
    74         // Set the status to logged in.
    75         ic->flags = OPT_LOGGED_IN;
     77        imcb_log( ic, "Connecting to twitter" );
     78        imcb_connected(ic);
    7679
    7780        // Run this once. After this queue the main loop function.
     
    7982
    8083        // Queue the main_loop
    81         b_timeout_add(60000, twitter_main_loop, ic);
    82 
    83         imcb_log( ic, "Connecting to twitter" );
    84         imcb_connected(ic);
     84        // Save the return value, so we can remove the timeout on logout.
     85        td->main_loop_id = b_timeout_add(60000, twitter_main_loop, ic);
    8586
    8687        twitter_connections = g_slist_append( twitter_connections, ic );
     
    9697        // Set the status to logged out.
    9798        ic->flags = 0;
     99
     100        // Remove the main_loop function from the function queue.
     101        b_event_remove(td->main_loop_id);
    98102
    99103        if( td )
     
    149153static void twitter_chat_msg( struct groupchat *c, char *message, int flags )
    150154{
     155        if( c && message )
     156                twitter_post_status(c->ic, message);
    151157}
    152158
  • protocols/twitter/twitter.h

    r62d2cfb r2abceca  
    3838        char* pass;
    3939        guint64 home_timeline_id;
     40        gint main_loop_id;
    4041        struct groupchat *home_timeline_gc;
    4142};
  • protocols/twitter/twitter_http.c

    r62d2cfb r2abceca  
    3939
    4040
    41 char *twitter_urlencode(const char *instr);
    4241char *twitter_url_append(char *url, char *key, char* value);
    43 static int isurlchar(unsigned char c);
    4442
    4543/**
     
    107105        // Make the request.
    108106        request = g_strdup_printf(  "%s %s HTTP/1.0\r\n"
    109                                                                 "Host: %s\r\n"
    110                                                                 "User-Agent: BitlBee " BITLBEE_VERSION " " ARCH "/" CPU "\r\n",
    111                                                                 is_post ? "POST" : "GET", url->file, url->host );
     107                                    "Host: %s\r\n"
     108                                    "User-Agent: BitlBee " BITLBEE_VERSION " " ARCH "/" CPU "\r\n",
     109                                    is_post ? "POST" : "GET", url->file, url->host );
    112110
    113111        // If a pass and user are given we append them to the request.
     
    146144char *twitter_url_append(char *url, char *key, char* value)
    147145{
    148         char *key_encoded = twitter_urlencode(key);
    149         char *value_encoded = twitter_urlencode(value);
     146        char *key_encoded = g_strndup(key, 3 * strlen(key));
     147        http_encode(key_encoded);
     148        char *value_encoded = g_strndup(value, 3 * strlen(value));
     149        http_encode(value_encoded);
     150
    150151        char *retval;
    151152        if (strlen(url) != 0)
     
    159160        return retval;
    160161}
    161 
    162 char *twitter_urlencode(const char *instr)
    163 {
    164         int ipos=0, bpos=0;
    165         char *str = NULL;
    166         int len = strlen(instr);
    167 
    168         if(!(str = g_new(char, 3*len + 1) ))
    169                 return "";
    170 
    171         while(instr[ipos]) {
    172                 while(isurlchar(instr[ipos]))
    173                         str[bpos++] = instr[ipos++];
    174                 if(!instr[ipos])
    175                         break;
    176 
    177                 g_snprintf(&str[bpos], 4, "%%%.2x", instr[ipos]);
    178                 bpos+=3;
    179                 ipos++;
    180         }
    181         str[bpos]='\0';
    182 
    183         /* free extra alloc'ed mem. */
    184         len = strlen(str);
    185         str = g_renew(char, str, len+1);
    186 
    187         return (str);
    188 }
    189 
    190162
    191163char *twitter_urldecode(const char *instr)
     
    229201}
    230202
    231 static int isurlchar(unsigned char c)
    232 {
    233         return (isalnum(c) || '-' == c || '_' == c);
    234 }
    235 
  • protocols/twitter/twitter_lib.c

    r62d2cfb r2abceca  
    6565        g_free(txu->name);
    6666        g_free(txu->screen_name);
     67        g_free(txu);
    6768}
    6869
     
    7677        g_free(txs->text);
    7778        txu_free(txs->user);
     79        g_free(txs);
    7880}
    7981
     
    131133{
    132134        // Do something with the cursor.
    133         txl->next_cursor = atoi(node->text);
     135        txl->next_cursor = node->text != NULL ? atoi(node->text) : -1;
    134136
    135137        return XT_HANDLED;
     
    153155                {
    154156                        // Add the item to the list.
    155                         txl->list = g_slist_append (txl->list, g_memdup( node->text, node->text_len + 1 ));
     157                        txl->list = g_slist_append (txl->list, g_memdup( child->text, child->text_len + 1 ));
    156158                }
    157159                else if ( g_strcasecmp( "next_cursor", child->name ) == 0)
     
    187189
    188190        txl = g_new0(struct twitter_xml_list, 1);
    189         txl->list = NULL;
    190191
    191192        // Parse the data.
     
    451452        if (req->status_code != 200) {
    452453                // It didn't go well, output the error and return.
    453                 imcb_error(ic, "Could not retrieve home/timeline. HTTP STATUS: %d", req->status_code);
     454                imcb_error(ic, "Could not retrieve " TWITTER_HOME_TIMELINE_URL ". HTTP STATUS: %d", req->status_code);
    454455                return;
    455456        }
     
    488489        struct xt_parser *parser;
    489490        struct twitter_xml_list *txl;
     491        GSList *l = NULL;
     492        struct twitter_xml_user *user;
    490493
    491494        // Check if the connection is still active.
     
    496499        if (req->status_code != 200) {
    497500                // It didn't go well, output the error and return.
    498                 imcb_error(ic, "Could not retrieve home/timeline. HTTP STATUS: %d", req->status_code);
     501                imcb_error(ic, "Could not retrieve " TWITTER_SHOW_FRIENDS_URL " HTTP STATUS: %d", req->status_code);
    499502                return;
    500503        }
     
    511514        xt_free( parser );
    512515
    513         GSList *l = NULL;
    514         struct twitter_xml_user *user;
    515516        // Add the users as buddies.
    516517        for ( l = txl->list; l ; l = g_slist_next(l) )
     
    559560        if (req->status_code != 200) {
    560561                // It didn't go well, output the error and return.
    561                 imcb_error(ic, "Could not post tweed... HTTP STATUS: %d", req->status_code);
    562                 imcb_error(ic, req->reply_body);
     562                imcb_error(ic, "Could not post tweet... HTTP STATUS: %d", req->status_code);
    563563                return;
    564564        }
Note: See TracChangeset for help on using the changeset viewer.