aboutsummaryrefslogtreecommitdiffstats
path: root/protocols/twitter/twitter.c
diff options
context:
space:
mode:
authorWilmer van der Gaast <wilmer@gaast.net>2010-07-17 16:06:56 +0100
committerWilmer van der Gaast <wilmer@gaast.net>2010-07-17 16:06:56 +0100
commitffcdf1329ad0401ace5a0355160ac7c249869431 (patch)
tree33af5d2e84a7a4f810da33a912a45ce31d430927 /protocols/twitter/twitter.c
parent0d691eaca734902fb6c0f476ad2dbddb72e6ba66 (diff)
When using non-Twitter Twitter API services, prefix the channel and contact
name with that service name, not always Twitter. This is especially useful when having multiple accounts on different sites with the same username. Also adding an "identica" protocol entry for convenience. Based on a patch from kensanata, bug #648.
Diffstat (limited to 'protocols/twitter/twitter.c')
-rw-r--r--protocols/twitter/twitter.c37
1 files changed, 30 insertions, 7 deletions
diff --git a/protocols/twitter/twitter.c b/protocols/twitter/twitter.c
index f3fe8922..f718eeb7 100644
--- a/protocols/twitter/twitter.c
+++ b/protocols/twitter/twitter.c
@@ -118,7 +118,7 @@ static gboolean twitter_oauth_callback( struct oauth_info *info )
return FALSE;
}
- sprintf( name, "twitter_%s", ic->acc->user );
+ sprintf( name, "%s_%s", td->prefix, ic->acc->user );
msg = g_strdup_printf( "To finish OAuth authentication, please visit "
"%s and respond with the resulting PIN code.",
info->auth_url );
@@ -171,8 +171,21 @@ static gboolean twitter_length_check( struct im_connection *ic, gchar *msg )
static void twitter_init( account_t *acc )
{
set_t *s;
+ char *def_url;
+ char *def_oauth;
- s = set_add( &acc->set, "base_url", TWITTER_API_URL, NULL, acc );
+ if( strcmp( acc->prpl->name, "twitter" ) == 0 )
+ {
+ def_url = TWITTER_API_URL;
+ def_oauth = "true";
+ }
+ else /* if( strcmp( acc->prpl->name, "identica" ) == 0 ) */
+ {
+ def_url = IDENTICA_API_URL;
+ def_oauth = "false";
+ }
+
+ s = set_add( &acc->set, "base_url", def_url, NULL, acc );
s->flags |= ACC_SET_OFFLINE_ONLY;
s = set_add( &acc->set, "message_length", "140", set_eval_int, acc );
@@ -180,7 +193,7 @@ static void twitter_init( account_t *acc )
s = set_add( &acc->set, "mode", "one", set_eval_mode, acc );
s->flags |= ACC_SET_OFFLINE_ONLY;
- s = set_add( &acc->set, "oauth", "true", set_eval_bool, acc );
+ s = set_add( &acc->set, "oauth", def_oauth, set_eval_bool, acc );
}
/**
@@ -213,12 +226,16 @@ static void twitter_login( account_t *acc )
td->url_path = g_strdup( url.file );
else
td->url_path = g_strdup( "" );
+ if( g_str_has_suffix( url.host, ".com" ) )
+ td->prefix = g_strndup( url.host, strlen( url.host ) - 4 );
+ else
+ td->prefix = g_strdup( url.host );
td->user = acc->user;
if( strstr( acc->pass, "oauth_token=" ) )
td->oauth_info = oauth_from_string( acc->pass, &twitter_oauth );
- sprintf( name, "twitter_%s", acc->user );
+ sprintf( name, "%s_%s", td->prefix, acc->user );
imcb_add_buddy( ic, name, NULL );
imcb_buddy_status( ic, name, OPT_LOGGED_IN, NULL, NULL );
@@ -246,6 +263,7 @@ static void twitter_logout( struct im_connection *ic )
if( td )
{
oauth_info_free( td->oauth_info );
+ g_free( td->prefix );
g_free( td->url_host );
g_free( td->url_path );
g_free( td->pass );
@@ -261,9 +279,10 @@ static void twitter_logout( struct im_connection *ic )
static int twitter_buddy_msg( struct im_connection *ic, char *who, char *message, int away )
{
struct twitter_data *td = ic->proto_data;
+ int plen = strlen( td->prefix );
- if (g_strncasecmp(who, "twitter_", 8) == 0 &&
- g_strcasecmp(who + 8, ic->acc->user) == 0)
+ if (g_strncasecmp(who, td->prefix, plen) == 0 && who[plen] == '_' &&
+ g_strcasecmp(who + plen + 1, ic->acc->user) == 0)
{
if( set_getbool( &ic->acc->set, "oauth" ) &&
td->oauth_info && td->oauth_info->token == NULL )
@@ -415,10 +434,14 @@ void twitter_initmodule()
ret->rem_deny = twitter_rem_deny;
ret->send_typing = twitter_send_typing;
ret->handle_cmp = g_strcasecmp;
+
+ register_protocol(ret);
+ /* And an identi.ca variant: */
+ ret = g_memdup(ret, sizeof(struct prpl));
+ ret->name = "identica";
register_protocol(ret);
// Initialise the twitter_connections GSList.
twitter_connections = NULL;
}
-