diff options
author | Wilmer van der Gaast <wilmer@gaast.net> | 2010-06-24 10:14:34 +0100 |
---|---|---|
committer | Wilmer van der Gaast <wilmer@gaast.net> | 2010-06-24 10:14:34 +0100 |
commit | 8b8def5854857248f66b6a2580ce2e5a8f5597c8 (patch) | |
tree | 36d6328e966fed589f46076936fc50ff8063ed50 /protocols | |
parent | 7cd2e8a6c0ba091f56e6ee8bc087c799faee3662 (diff) | |
parent | 38ff846b14f1d1f80983a0818b9bcf60581a2a34 (diff) |
Merging a few revisions from mainline.
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/jabber/iq.c | 4 | ||||
-rw-r--r-- | protocols/jabber/jabber.c | 5 | ||||
-rw-r--r-- | protocols/jabber/message.c | 2 | ||||
-rw-r--r-- | protocols/twitter/twitter.c | 33 | ||||
-rw-r--r-- | protocols/twitter/twitter.h | 8 | ||||
-rw-r--r-- | protocols/twitter/twitter_lib.c | 49 |
6 files changed, 71 insertions, 30 deletions
diff --git a/protocols/jabber/iq.c b/protocols/jabber/iq.c index 2930e75f..82c90d39 100644 --- a/protocols/jabber/iq.c +++ b/protocols/jabber/iq.c @@ -64,7 +64,7 @@ xt_status jabber_pkt_iq( struct xt_node *node, gpointer data ) /* Of course this is a very essential query to support. ;-) */ if( strcmp( s, XMLNS_VERSION ) == 0 ) { - xt_add_child( reply, xt_new_node( "name", "BitlBee", NULL ) ); + xt_add_child( reply, xt_new_node( "name", set_getstr( &ic->acc->set, "user_agent" ), NULL ) ); xt_add_child( reply, xt_new_node( "version", BITLBEE_VERSION, NULL ) ); xt_add_child( reply, xt_new_node( "os", ARCH, NULL ) ); } @@ -107,7 +107,7 @@ xt_status jabber_pkt_iq( struct xt_node *node, gpointer data ) c = xt_new_node( "identity", NULL, NULL ); xt_add_attr( c, "category", "client" ); xt_add_attr( c, "type", "pc" ); - xt_add_attr( c, "name", "BitlBee" ); + xt_add_attr( c, "name", set_getstr( &ic->acc->set, "user_agent" ) ); xt_add_child( reply, c ); for( f = features; *f; f ++ ) diff --git a/protocols/jabber/jabber.c b/protocols/jabber/jabber.c index d5948958..7147a628 100644 --- a/protocols/jabber/jabber.c +++ b/protocols/jabber/jabber.c @@ -81,6 +81,8 @@ static void jabber_init( account_t *acc ) s = set_add( &acc->set, "tls", "try", set_eval_tls, acc ); s->flags |= ACC_SET_OFFLINE_ONLY; + s = set_add( &acc->set, "user_agent", "BitlBee", NULL, acc ); + s = set_add( &acc->set, "xmlconsole", "false", set_eval_bool, acc ); s->flags |= ACC_SET_OFFLINE_ONLY; @@ -485,7 +487,8 @@ static void jabber_chat_invite_( struct groupchat *c, char *who, char *msg ) static void jabber_keepalive( struct im_connection *ic ) { /* Just any whitespace character is enough as a keepalive for XMPP sessions. */ - jabber_write( ic, "\n", 1 ); + if( !jabber_write( ic, "\n", 1 ) ) + return; /* This runs the garbage collection every minute, which means every packet is in the cache for about a minute (which should be enough AFAIK). */ diff --git a/protocols/jabber/message.c b/protocols/jabber/message.c index e8161029..fa915bd8 100644 --- a/protocols/jabber/message.c +++ b/protocols/jabber/message.c @@ -54,7 +54,7 @@ xt_status jabber_pkt_message( struct xt_node *node, gpointer data ) char *ns = xt_find_attr( c, "xmlns" ), *room; struct xt_node *inv, *reason; - if( strcmp( ns, XMLNS_MUC_USER ) == 0 && + if( ns && strcmp( ns, XMLNS_MUC_USER ) == 0 && ( inv = xt_find_node( c->children, "invite" ) ) ) { room = from; diff --git a/protocols/twitter/twitter.c b/protocols/twitter/twitter.c index db893e17..ca57e51e 100644 --- a/protocols/twitter/twitter.c +++ b/protocols/twitter/twitter.c @@ -39,11 +39,6 @@ gboolean twitter_main_loop(gpointer data, gint fd, b_input_condition cond) if (!g_slist_find( twitter_connections, ic )) return 0; - // If the user uses multiple private message windows we need to get the - // users buddies. - if (g_strcasecmp(set_getstr(&ic->acc->set, "mode"), "many") == 0) - twitter_get_statuses_friends(ic, -1); - // Do stuff.. twitter_get_home_timeline(ic, -1); @@ -55,7 +50,7 @@ static void twitter_main_loop_start( struct im_connection *ic ) { struct twitter_data *td = ic->proto_data; - imcb_log( ic, "Connecting to Twitter" ); + imcb_log( ic, "Getting initial statuses" ); // Run this once. After this queue the main loop function. twitter_main_loop(ic, -1, 0); @@ -65,6 +60,23 @@ static void twitter_main_loop_start( struct im_connection *ic ) td->main_loop_id = b_timeout_add(60000, twitter_main_loop, ic); } +static void twitter_oauth_start( struct im_connection *ic ); + +void twitter_login_finish( struct im_connection *ic ) +{ + struct twitter_data *td = ic->proto_data; + + if( set_getbool( &ic->acc->set, "oauth" ) && !td->oauth_info ) + twitter_oauth_start( ic ); + else if( g_strcasecmp( set_getstr( &ic->acc->set, "mode" ), "one" ) != 0 && + !( td->flags & TWITTER_HAVE_FRIENDS ) ) + { + imcb_log( ic, "Getting contact list" ); + twitter_get_statuses_friends( ic, -1 ); + } + else + twitter_main_loop_start( ic ); +} static const struct oauth_service twitter_oauth = { @@ -127,7 +139,7 @@ static gboolean twitter_oauth_callback( struct oauth_info *info ) g_free( ic->acc->pass ); ic->acc->pass = oauth_to_string( info ); - twitter_main_loop_start( ic ); + twitter_login_finish( ic ); } return TRUE; @@ -210,10 +222,9 @@ static void twitter_login( account_t *acc ) imcb_add_buddy( ic, name, NULL ); imcb_buddy_status( ic, name, OPT_LOGGED_IN, NULL, NULL ); - if( td->oauth_info || !set_getbool( &acc->set, "oauth" ) ) - twitter_main_loop_start( ic ); - else - twitter_oauth_start( ic ); + imcb_log( ic, "Connecting" ); + + twitter_login_finish( ic ); } /** diff --git a/protocols/twitter/twitter.h b/protocols/twitter/twitter.h index 614919f9..e61d32be 100644 --- a/protocols/twitter/twitter.h +++ b/protocols/twitter/twitter.h @@ -32,6 +32,11 @@ #define debug( text... ) #endif +typedef enum +{ + TWITTER_HAVE_FRIENDS = 1, +} twitter_flags_t; + struct twitter_data { char* user; @@ -41,6 +46,7 @@ struct twitter_data gint main_loop_id; struct groupchat *home_timeline_gc; gint http_fails; + twitter_flags_t flags; gboolean url_ssl; int url_port; @@ -55,4 +61,6 @@ struct twitter_data */ GSList *twitter_connections; +void twitter_login_finish( struct im_connection *ic ); + #endif //_TWITTER_H diff --git a/protocols/twitter/twitter_lib.c b/protocols/twitter/twitter_lib.c index 9b67442e..53928287 100644 --- a/protocols/twitter/twitter_lib.c +++ b/protocols/twitter/twitter_lib.c @@ -58,6 +58,8 @@ struct twitter_xml_status { guint64 id; }; +static void twitter_groupchat_init(struct im_connection *ic); + /** * Frees a twitter_xml_user struct. */ @@ -432,6 +434,19 @@ void twitter_get_home_timeline(struct im_connection *ic, int next_cursor) } } +static void twitter_groupchat_init(struct im_connection *ic) +{ + char *name_hint; + struct groupchat *gc; + struct twitter_data *td = ic->proto_data; + + td->home_timeline_gc = gc = imcb_chat_new( ic, "home/timeline" ); + + name_hint = g_strdup_printf( "Twitter_%s", ic->acc->user ); + imcb_chat_name_hint( gc, name_hint ); + g_free( name_hint ); +} + /** * Function that is called to see the statuses in a groupchat window. */ @@ -444,18 +459,11 @@ static void twitter_groupchat(struct im_connection *ic, GSList *list) // Create a new groupchat if it does not exsist. if (!td->home_timeline_gc) - { - char *name_hint = g_strdup_printf( "Twitter_%s", ic->acc->user ); - td->home_timeline_gc = gc = imcb_chat_new( ic, "home/timeline" ); - imcb_chat_name_hint( gc, name_hint ); - g_free( name_hint ); - // Add the current user to the chat... + twitter_groupchat_init(ic); + + gc = td->home_timeline_gc; + if (!gc->joined) imcb_chat_add_buddy( gc, ic->acc->user ); - } - else - { - gc = td->home_timeline_gc; - } for ( l = list; l ; l = g_slist_next(l) ) { @@ -603,15 +611,23 @@ static void twitter_http_get_statuses_friends(struct http_request *req) td = ic->proto_data; // Check if the HTTP request went well. - if (req->status_code != 200) { + if (req->status_code == 401) + { + imcb_error( ic, "Authentication failure" ); + imc_logout( ic, FALSE ); + return; + } else if (req->status_code != 200) { // It didn't go well, output the error and return. - if (++td->http_fails >= 5) - imcb_error(ic, "Could not retrieve " TWITTER_SHOW_FRIENDS_URL ": %s", twitter_parse_error(req)); - + imcb_error(ic, "Could not retrieve " TWITTER_SHOW_FRIENDS_URL ": %s", twitter_parse_error(req)); + imc_logout( ic, TRUE ); return; } else { td->http_fails = 0; } + + if( !td->home_timeline_gc && + g_strcasecmp( set_getstr( &ic->acc->set, "mode" ), "chat" ) == 0 ) + twitter_groupchat_init( ic ); txl = g_new0(struct twitter_xml_list, 1); txl->list = NULL; @@ -638,6 +654,9 @@ static void twitter_http_get_statuses_friends(struct http_request *req) // Free the structure. txl_free(txl); g_free(txl); + + td->flags |= TWITTER_HAVE_FRIENDS; + twitter_login_finish(ic); } /** |