Changes in / [23784065:f1b7711]
- Files:
-
- 2 deleted
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/user-guide/commands.xml
r23784065 rf1b7711 79 79 To send tweets yourself, send them to the twitter_(yourusername) contact, or just write in the groupchat channel if you enabled that option. 80 80 </para> 81 82 <para>83 Since Twitter now requires OAuth authentication, you should not enter your Twitter password into BitlBee. Just type a bogus password. The first time you log in, BitlBee will start OAuth authentication. (See <emphasis>help set oauth</emphasis>.)84 </para>85 81 </description> 86 82 </bitlbee-command> … … 707 703 </bitlbee-setting> 708 704 709 <bitlbee-setting name="oauth" type="boolean" scope="account">710 <default>true</default>711 712 <description>713 <para>714 This enables OAuth authentication for Twitter accounts. From June 2010 this will be mandatory.715 </para>716 717 <para>718 With OAuth enabled, you shouldn't tell BitlBee your Twitter password. Just add your account with a bogus password and type <emphasis>account on</emphasis>. BitlBee will then give you a URL to authenticate with Twitter. If this succeeds, Twitter will return a PIN code which you can give back to BitlBee to finish the process.719 </para>720 721 <para>722 The resulting access token will be saved permanently, so you have to do this only once.723 </para>724 </description>725 726 </bitlbee-setting>727 728 705 <bitlbee-setting name="ops" type="string" scope="global"> 729 706 <default>both</default> -
lib/Makefile
r23784065 rf1b7711 10 10 11 11 # [SH] Program variables 12 objects = arc.o base64.o $(EVENT_HANDLER) http_client.o ini.o md5.o misc.o oauth.oproxy.o sha1.o $(SSL_CLIENT) url.o xmltree.o12 objects = arc.o base64.o $(EVENT_HANDLER) http_client.o ini.o md5.o misc.o proxy.o sha1.o $(SSL_CLIENT) url.o xmltree.o 13 13 14 14 CFLAGS += -Wall -
lib/misc.c
r23784065 rf1b7711 306 306 for( i = j = 0; t[i]; i ++, j ++ ) 307 307 { 308 if( !isalnum( t[i] ) && !strchr( "._-~", t[i] ) ) 308 /* if( t[i] <= ' ' || ((unsigned char *)t)[i] >= 128 || t[i] == '%' ) */ 309 if( !isalnum( t[i] ) ) 309 310 { 310 311 sprintf( s + j, "%%%02X", ((unsigned char*)t)[i] ); -
lib/url.c
r23784065 rf1b7711 27 27 28 28 /* Convert an URL to a url_t structure */ 29 int url_set( url_t *url, c onst char *set_url )29 int url_set( url_t *url, char *set_url ) 30 30 { 31 31 char s[MAX_STRING+1]; -
lib/url.h
r23784065 rf1b7711 42 42 } url_t; 43 43 44 int url_set( url_t *url, c onst char *set_url );44 int url_set( url_t *url, char *set_url ); -
protocols/twitter/twitter.c
r23784065 rf1b7711 23 23 24 24 #include "nogaim.h" 25 #include "oauth.h"26 25 #include "twitter.h" 27 26 #include "twitter_http.h" … … 50 49 // If we are still logged in run this function again after timeout. 51 50 return (ic->flags & OPT_LOGGED_IN) == OPT_LOGGED_IN; 52 }53 54 static void twitter_main_loop_start( struct im_connection *ic )55 {56 struct twitter_data *td = ic->proto_data;57 58 imcb_log( ic, "Connecting to Twitter" );59 60 // Run this once. After this queue the main loop function.61 twitter_main_loop(ic, -1, 0);62 63 // Queue the main_loop64 // Save the return value, so we can remove the timeout on logout.65 td->main_loop_id = b_timeout_add(60000, twitter_main_loop, ic);66 }67 68 static gboolean twitter_oauth_callback( struct oauth_info *info );69 70 static void twitter_oauth_start( struct im_connection *ic )71 {72 struct twitter_data *td = ic->proto_data;73 74 imcb_log( ic, "Requesting OAuth request token" );75 76 td->oauth_info = oauth_request_token(77 TWITTER_OAUTH_REQUEST_TOKEN, twitter_oauth_callback, ic );78 }79 80 static gboolean twitter_oauth_callback( struct oauth_info *info )81 {82 struct im_connection *ic = info->data;83 struct twitter_data *td;84 85 if( !g_slist_find( twitter_connections, ic ) )86 return FALSE;87 88 td = ic->proto_data;89 if( info->stage == OAUTH_REQUEST_TOKEN )90 {91 char name[strlen(ic->acc->user)+9], *msg;92 93 if( info->request_token == NULL )94 {95 imcb_error( ic, "OAuth error: %s", info->http->status_string );96 imc_logout( ic, TRUE );97 return FALSE;98 }99 100 sprintf( name, "twitter_%s", ic->acc->user );101 msg = g_strdup_printf( "To finish OAuth authentication, please visit "102 "%s?%s and respond with the resulting PIN code.",103 TWITTER_OAUTH_AUTHORIZE, info->auth_params );104 imcb_buddy_msg( ic, name, msg, 0, 0 );105 g_free( msg );106 }107 else if( info->stage == OAUTH_ACCESS_TOKEN )108 {109 if( info->access_token == NULL )110 {111 imcb_error( ic, "OAuth error: %s", info->http->status_string );112 imc_logout( ic, TRUE );113 return FALSE;114 }115 116 td->oauth = g_strdup( info->access_token );117 118 /* IM mods didn't do this so far and it's ugly but I should119 be able to get away with it... */120 g_free( ic->acc->pass );121 ic->acc->pass = g_strdup( info->access_token );122 123 twitter_main_loop_start( ic );124 }125 126 return TRUE;127 51 } 128 52 … … 143 67 s = set_add( &acc->set, "mode", "one", set_eval_mode, acc ); 144 68 s->flags |= ACC_SET_OFFLINE_ONLY; 145 146 s = set_add( &acc->set, "oauth", "true", set_eval_bool, acc );147 69 } 148 70 … … 158 80 159 81 twitter_connections = g_slist_append( twitter_connections, ic ); 82 83 td->user = acc->user; 84 td->pass = acc->pass; 85 td->home_timeline_id = 0; 86 160 87 ic->proto_data = td; 161 162 td->user = acc->user; 163 if( !set_getbool( &acc->set, "oauth" ) ) 164 td->pass = g_strdup( acc->pass ); 165 else if( strstr( acc->pass, "oauth_token=" ) ) 166 td->oauth = g_strdup( acc->pass ); 167 td->home_timeline_id = 0; 88 89 imcb_log( ic, "Connecting to Twitter" ); 90 91 // Run this once. After this queue the main loop function. 92 twitter_main_loop(ic, -1, 0); 93 94 // Queue the main_loop 95 // Save the return value, so we can remove the timeout on logout. 96 td->main_loop_id = b_timeout_add(60000, twitter_main_loop, ic); 168 97 169 98 sprintf( name, "twitter_%s", acc->user ); 170 99 imcb_add_buddy( ic, name, NULL ); 171 100 imcb_buddy_status( ic, name, OPT_LOGGED_IN, NULL, NULL ); 172 173 if( td->pass || td->oauth )174 twitter_main_loop_start( ic );175 else176 twitter_oauth_start( ic );177 101 } 178 102 … … 195 119 if( td ) 196 120 { 197 oauth_info_free( td->oauth_info );198 199 g_free( td->pass );200 g_free( td->oauth );201 121 g_free( td ); 202 122 } … … 210 130 static int twitter_buddy_msg( struct im_connection *ic, char *who, char *message, int away ) 211 131 { 212 struct twitter_data *td = ic->proto_data;213 214 132 if (g_strncasecmp(who, "twitter_", 8) == 0 && 215 133 g_strcasecmp(who + 8, ic->acc->user) == 0) 216 { 217 if( set_getbool( &ic->acc->set, "oauth" ) && td->oauth_info ) 218 { 219 oauth_access_token( TWITTER_OAUTH_ACCESS_TOKEN, message, td->oauth_info ); 220 td->oauth_info = NULL; 221 } 222 else 223 twitter_post_status(ic, message); 224 } 134 twitter_post_status(ic, message); 225 135 else 226 {227 136 twitter_direct_messages_new(ic, who, message); 228 }137 229 138 return( 0 ); 230 139 } -
protocols/twitter/twitter.h
r23784065 rf1b7711 37 37 char* user; 38 38 char* pass; 39 char* oauth;40 struct oauth_info *oauth_info;41 39 guint64 home_timeline_id; 42 40 gint main_loop_id; … … 52 50 GSList *twitter_connections; 53 51 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 52 #endif //_TWITTER_H -
protocols/twitter/twitter_http.c
r23784065 rf1b7711 35 35 #include "misc.h" 36 36 #include "base64.h" 37 #include "oauth.h"38 37 #include <ctype.h> 39 38 #include <errno.h> … … 46 45 * This is actually pretty generic function... Perhaps it should move to the lib/http_client.c 47 46 */ 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)47 void *twitter_http(char *url_string, http_input_function func, gpointer data, int is_post, char* user, char* pass, char** arguments, int arguments_len) 49 48 { 50 49 url_t *url = g_new0( url_t, 1 ); … … 111 110 112 111 // If a pass and user are given we append them to the request. 113 if (oauth_token) 114 { 115 char *full_header; 116 117 full_header = oauth_http_header(oauth_token, 118 is_post ? "POST" : "GET", 119 url_string, url_arguments); 120 121 tmp = g_strdup_printf("%sAuthorization: %s\r\n", request, full_header); 122 g_free(request); 123 g_free(full_header); 124 request = tmp; 125 } 126 else if (userpass_base64) 112 if (userpass_base64) 127 113 { 128 114 tmp = g_strdup_printf("%sAuthorization: Basic %s\r\n", request, userpass_base64); -
protocols/twitter/twitter_http.h
r23784065 rf1b7711 29 29 30 30 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);31 char* user, char* pass, char** arguments, int arguments_len); 32 32 33 33 #endif //_TWITTER_HTTP_H -
protocols/twitter/twitter_lib.c
r23784065 rf1b7711 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, 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, args, td->home_timeline_id ? 4 : 2); 399 399 400 400 g_free(args[1]); … … 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, 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, 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, args, 4); 675 675 // g_free(args[1]); 676 676 // g_free(args[3]);
Note: See TracChangeset
for help on using the changeset viewer.