- Timestamp:
- 2010-05-01T13:53:59Z (15 years ago)
- Branches:
- master
- Children:
- f4b0911
- Parents:
- 85ef57f
- Location:
- protocols/twitter
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/twitter/twitter.c
r85ef57f rc2ecadc 28 28 #include "twitter_lib.h" 29 29 30 31 30 /** 32 31 * Main loop function … … 66 65 } 67 66 67 68 static struct oauth_service twitter_oauth = 69 { 70 "http://api.twitter.com/oauth/request_token", 71 "http://api.twitter.com/oauth/access_token", 72 "http://api.twitter.com/oauth/authorize", 73 .consumer_key = "xsDNKJuNZYkZyMcu914uEA", 74 .consumer_secret = "FCxqcr0pXKzsF9ajmP57S3VQ8V6Drk4o2QYtqMcOszo", 75 }; 76 68 77 static gboolean twitter_oauth_callback( struct oauth_info *info ); 69 78 … … 74 83 imcb_log( ic, "Requesting OAuth request token" ); 75 84 76 td->oauth_info = oauth_request_token( 77 TWITTER_OAUTH_REQUEST_TOKEN, twitter_oauth_callback, ic ); 85 td->oauth_info = oauth_request_token( &twitter_oauth, twitter_oauth_callback, ic ); 78 86 } 79 87 … … 100 108 sprintf( name, "twitter_%s", ic->acc->user ); 101 109 msg = g_strdup_printf( "To finish OAuth authentication, please visit " 102 "%s ?%sand respond with the resulting PIN code.",103 TWITTER_OAUTH_AUTHORIZE, info->auth_params);110 "%s and respond with the resulting PIN code.", 111 info->auth_url ); 104 112 imcb_buddy_msg( ic, name, msg, 0, 0 ); 105 113 g_free( msg ); … … 107 115 else if( info->stage == OAUTH_ACCESS_TOKEN ) 108 116 { 109 if( info-> access_token == NULL )117 if( info->token == NULL ) 110 118 { 111 119 imcb_error( ic, "OAuth error: %s", info->http->status_string ); … … 114 122 } 115 123 116 td->oauth = g_strdup( info->access_token );117 118 124 /* IM mods didn't do this so far and it's ugly but I should 119 125 be able to get away with it... */ 120 g_free( ic->acc->pass );121 ic->acc->pass = g_strdup( info->access_token );126 //g_free( ic->acc->pass ); 127 //ic->acc->pass = g_strdup( info->access_token ); 122 128 123 129 twitter_main_loop_start( ic ); … … 126 132 return TRUE; 127 133 } 134 128 135 129 136 static char *set_eval_mode( set_t *set, char *value ) … … 164 171 if( !set_getbool( &acc->set, "oauth" ) ) 165 172 td->pass = g_strdup( acc->pass ); 166 else if( strstr( acc->pass, "oauth_token=" ) )167 td->oauth = g_strdup( acc->pass );173 //else if( strstr( acc->pass, "oauth_token=" ) ) 174 // td->oauth = g_strdup( acc->pass ); 168 175 td->home_timeline_id = 0; 169 176 … … 172 179 imcb_buddy_status( ic, name, OPT_LOGGED_IN, NULL, NULL ); 173 180 174 if( td->pass || td->oauth )181 if( td->pass || td->oauth_info ) 175 182 twitter_main_loop_start( ic ); 176 183 else … … 197 204 { 198 205 oauth_info_free( td->oauth_info ); 199 200 206 g_free( td->pass ); 201 g_free( td->oauth );202 207 g_free( td ); 203 208 } … … 216 221 g_strcasecmp(who + 8, ic->acc->user) == 0) 217 222 { 218 if( set_getbool( &ic->acc->set, "oauth" ) && td->oauth_info ) 223 if( set_getbool( &ic->acc->set, "oauth" ) && 224 td->oauth_info && td->oauth_info->token == NULL ) 219 225 { 220 oauth_access_token( TWITTER_OAUTH_ACCESS_TOKEN, message, td->oauth_info ); 221 td->oauth_info = NULL; 226 if( !oauth_access_token( message, td->oauth_info ) ) 227 { 228 imcb_error( ic, "OAuth error: %s", "Failed to send access token request" ); 229 imc_logout( ic, TRUE ); 230 return FALSE; 231 } 222 232 } 223 233 else -
protocols/twitter/twitter.h
r85ef57f rc2ecadc 37 37 char* user; 38 38 char* pass; 39 char* oauth;40 39 struct oauth_info *oauth_info; 41 40 guint64 home_timeline_id; … … 52 51 GSList *twitter_connections; 53 52 54 #define TWITTER_OAUTH_REQUEST_TOKEN "http://api.twitter.com/oauth/request_token"55 #define TWITTER_OAUTH_ACCESS_TOKEN "http://api.twitter.com/oauth/access_token"56 #define TWITTER_OAUTH_AUTHORIZE "http://api.twitter.com/oauth/authorize"57 58 53 #endif //_TWITTER_H -
protocols/twitter/twitter_http.c
r85ef57f rc2ecadc 29 29 ****************************************************************************/ 30 30 31 #include "twitter_http.h"32 31 #include "twitter.h" 33 32 #include "bitlbee.h" … … 39 38 #include <errno.h> 40 39 40 #include "twitter_http.h" 41 41 42 42 43 char *twitter_url_append(char *url, char *key, char* value); … … 46 47 * This is actually pretty generic function... Perhaps it should move to the lib/http_client.c 47 48 */ 48 void *twitter_http(char *url_string, http_input_function func, gpointer data, int is_post, char* user, char* pass, char* oauth_token, char** arguments, int arguments_len)49 void *twitter_http(char *url_string, http_input_function func, gpointer data, int is_post, char* user, char* pass, struct oauth_info* oi, char** arguments, int arguments_len) 49 50 { 50 51 url_t *url = g_new0( url_t, 1 ); … … 111 112 112 113 // If a pass and user are given we append them to the request. 113 if (o auth_token)114 if (oi) 114 115 { 115 116 char *full_header; 116 117 117 full_header = oauth_http_header(oauth_token, 118 is_post ? "POST" : "GET", 118 full_header = oauth_http_header(oi, is_post ? "POST" : "GET", 119 119 url_string, url_arguments); 120 120 -
protocols/twitter/twitter_http.h
r85ef57f rc2ecadc 28 28 #include "http_client.h" 29 29 30 struct oauth_info; 31 30 32 void *twitter_http(char *url_string, http_input_function func, gpointer data, int is_post, 31 char* user, char* pass, char *oauth_token, char** arguments, int arguments_len);33 char* user, char* pass, struct oauth_info *oi, char** arguments, int arguments_len); 32 34 33 35 #endif //_TWITTER_HTTP_H -
protocols/twitter/twitter_lib.c
r85ef57f rc2ecadc 130 130 args[0] = "cursor"; 131 131 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 , 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); 133 133 134 134 g_free(args[1]); … … 396 396 } 397 397 398 twitter_http(TWITTER_HOME_TIMELINE_URL, twitter_http_get_home_timeline, ic, 0, td->user, td->pass, td->oauth , 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); 399 399 400 400 g_free(args[1]); … … 510 510 { 511 511 td->http_fails = 0; 512 if (! ic->flags & OPT_LOGGED_IN)512 if (!(ic->flags & OPT_LOGGED_IN)) 513 513 imcb_connected(ic); 514 514 } … … 620 620 args[1] = g_strdup_printf ("%d", next_cursor); 621 621 622 twitter_http(TWITTER_SHOW_FRIENDS_URL, twitter_http_get_statuses_friends, ic, 0, td->user, td->pass, td->oauth , 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); 623 623 624 624 g_free(args[1]); … … 654 654 args[0] = "status"; 655 655 args[1] = msg; 656 twitter_http(TWITTER_STATUS_UPDATE_URL, twitter_http_post_status, ic, 1, td->user, td->pass, td->oauth , args, 2);656 twitter_http(TWITTER_STATUS_UPDATE_URL, twitter_http_post_status, ic, 1, td->user, td->pass, td->oauth_info, args, 2); 657 657 // g_free(args[1]); 658 658 } … … 672 672 args[3] = msg; 673 673 // 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 , args, 4);674 twitter_http(TWITTER_DIRECT_MESSAGES_NEW_URL, twitter_http_post_status, ic, 1, td->user, td->pass, td->oauth_info, args, 4); 675 675 // g_free(args[1]); 676 676 // g_free(args[3]);
Note: See TracChangeset
for help on using the changeset viewer.