aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--protocols/twitter/twitter.c37
-rw-r--r--protocols/twitter/twitter.h2
-rw-r--r--protocols/twitter/twitter_lib.c4
-rw-r--r--protocols/twitter/twitter_lib.h1
4 files changed, 35 insertions, 9 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;
}
-
diff --git a/protocols/twitter/twitter.h b/protocols/twitter/twitter.h
index e61d32be..b7e41fc5 100644
--- a/protocols/twitter/twitter.h
+++ b/protocols/twitter/twitter.h
@@ -52,6 +52,8 @@ struct twitter_data
int url_port;
char *url_host;
char *url_path;
+
+ char *prefix; /* Used to generate contact + channel name. */
};
/**
diff --git a/protocols/twitter/twitter_lib.c b/protocols/twitter/twitter_lib.c
index b4b460d3..1bf5257c 100644
--- a/protocols/twitter/twitter_lib.c
+++ b/protocols/twitter/twitter_lib.c
@@ -458,7 +458,7 @@ static void twitter_groupchat_init(struct im_connection *ic)
td->home_timeline_gc = gc = imcb_chat_new( ic, "home/timeline" );
- name_hint = g_strdup_printf( "Twitter_%s", ic->acc->user );
+ name_hint = g_strdup_printf( "%s_%s", td->prefix, ic->acc->user );
imcb_chat_name_hint( gc, name_hint );
g_free( name_hint );
}
@@ -518,7 +518,7 @@ static void twitter_private_message_chat(struct im_connection *ic, GSList *list)
if( mode_one )
{
- g_snprintf( from, sizeof( from ) - 1, "twitter_%s", ic->acc->user );
+ g_snprintf( from, sizeof( from ) - 1, "%s_%s", td->prefix, ic->acc->user );
from[MAX_STRING-1] = '\0';
}
diff --git a/protocols/twitter/twitter_lib.h b/protocols/twitter/twitter_lib.h
index 6b90f9bb..5a3c3f68 100644
--- a/protocols/twitter/twitter_lib.h
+++ b/protocols/twitter/twitter_lib.h
@@ -29,6 +29,7 @@
#include "twitter_http.h"
#define TWITTER_API_URL "http://twitter.com"
+#define IDENTICA_API_URL "http://identi.ca/api"
/* Status URLs */
#define TWITTER_STATUS_UPDATE_URL "/statuses/update.xml"