- Timestamp:
- 2010-04-06T17:25:51Z (15 years ago)
- Branches:
- master
- Children:
- 0519b0a
- Parents:
- 62d2cfb
- Location:
- protocols/twitter
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/twitter/twitter.c
r62d2cfb r2abceca 35 35 struct im_connection *ic = data; 36 36 // 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 )) 38 40 return 0; 39 41 … … 55 57 set_t *s; 56 58 s = set_add( &acc->set, "use_groupchat", "false", set_eval_bool, acc ); 59 s->flags |= ACC_SET_OFFLINE_ONLY; 57 60 } 58 61 … … 72 75 ic->proto_data = td; 73 76 74 // Set the status to logged in.75 i c->flags = OPT_LOGGED_IN;77 imcb_log( ic, "Connecting to twitter" ); 78 imcb_connected(ic); 76 79 77 80 // Run this once. After this queue the main loop function. … … 79 82 80 83 // 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); 85 86 86 87 twitter_connections = g_slist_append( twitter_connections, ic ); … … 96 97 // Set the status to logged out. 97 98 ic->flags = 0; 99 100 // Remove the main_loop function from the function queue. 101 b_event_remove(td->main_loop_id); 98 102 99 103 if( td ) … … 149 153 static void twitter_chat_msg( struct groupchat *c, char *message, int flags ) 150 154 { 155 if( c && message ) 156 twitter_post_status(c->ic, message); 151 157 } 152 158 -
protocols/twitter/twitter.h
r62d2cfb r2abceca 38 38 char* pass; 39 39 guint64 home_timeline_id; 40 gint main_loop_id; 40 41 struct groupchat *home_timeline_gc; 41 42 }; -
protocols/twitter/twitter_http.c
r62d2cfb r2abceca 39 39 40 40 41 char *twitter_urlencode(const char *instr);42 41 char *twitter_url_append(char *url, char *key, char* value); 43 static int isurlchar(unsigned char c);44 42 45 43 /** … … 107 105 // Make the request. 108 106 request = g_strdup_printf( "%s %s HTTP/1.0\r\n" 109 110 111 107 "Host: %s\r\n" 108 "User-Agent: BitlBee " BITLBEE_VERSION " " ARCH "/" CPU "\r\n", 109 is_post ? "POST" : "GET", url->file, url->host ); 112 110 113 111 // If a pass and user are given we append them to the request. … … 146 144 char *twitter_url_append(char *url, char *key, char* value) 147 145 { 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 150 151 char *retval; 151 152 if (strlen(url) != 0) … … 159 160 return retval; 160 161 } 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 190 162 191 163 char *twitter_urldecode(const char *instr) … … 229 201 } 230 202 231 static int isurlchar(unsigned char c)232 {233 return (isalnum(c) || '-' == c || '_' == c);234 }235 -
protocols/twitter/twitter_lib.c
r62d2cfb r2abceca 65 65 g_free(txu->name); 66 66 g_free(txu->screen_name); 67 g_free(txu); 67 68 } 68 69 … … 76 77 g_free(txs->text); 77 78 txu_free(txs->user); 79 g_free(txs); 78 80 } 79 81 … … 131 133 { 132 134 // Do something with the cursor. 133 txl->next_cursor = atoi(node->text);135 txl->next_cursor = node->text != NULL ? atoi(node->text) : -1; 134 136 135 137 return XT_HANDLED; … … 153 155 { 154 156 // 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 )); 156 158 } 157 159 else if ( g_strcasecmp( "next_cursor", child->name ) == 0) … … 187 189 188 190 txl = g_new0(struct twitter_xml_list, 1); 189 txl->list = NULL;190 191 191 192 // Parse the data. … … 451 452 if (req->status_code != 200) { 452 453 // 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); 454 455 return; 455 456 } … … 488 489 struct xt_parser *parser; 489 490 struct twitter_xml_list *txl; 491 GSList *l = NULL; 492 struct twitter_xml_user *user; 490 493 491 494 // Check if the connection is still active. … … 496 499 if (req->status_code != 200) { 497 500 // 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); 499 502 return; 500 503 } … … 511 514 xt_free( parser ); 512 515 513 GSList *l = NULL;514 struct twitter_xml_user *user;515 516 // Add the users as buddies. 516 517 for ( l = txl->list; l ; l = g_slist_next(l) ) … … 559 560 if (req->status_code != 200) { 560 561 // 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); 563 563 return; 564 564 }
Note: See TracChangeset
for help on using the changeset viewer.