diff options
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/jabber/conference.c | 48 | ||||
-rw-r--r-- | protocols/jabber/iq.c | 19 | ||||
-rw-r--r-- | protocols/jabber/jabber.c | 6 | ||||
-rw-r--r-- | protocols/jabber/jabber.h | 3 | ||||
-rw-r--r-- | protocols/jabber/jabber_util.c | 53 | ||||
-rw-r--r-- | protocols/jabber/presence.c | 9 | ||||
-rw-r--r-- | protocols/oscar/msgcookie.c | 15 |
7 files changed, 89 insertions, 64 deletions
diff --git a/protocols/jabber/conference.c b/protocols/jabber/conference.c index 008bbe63..c5bc0e68 100644 --- a/protocols/jabber/conference.c +++ b/protocols/jabber/conference.c @@ -23,6 +23,8 @@ #include "jabber.h" +static xt_status jabber_chat_join_failed( struct im_connection *ic, struct xt_node *node, struct xt_node *orig ); + struct groupchat *jabber_chat_join( struct im_connection *ic, char *room, char *nick, char *password ) { struct jabber_chat *jc; @@ -34,14 +36,13 @@ struct groupchat *jabber_chat_join( struct im_connection *ic, char *room, char * node = xt_new_node( "x", NULL, NULL ); xt_add_attr( node, "xmlns", XMLNS_MUC ); node = jabber_make_packet( "presence", NULL, roomjid, node ); + jabber_cache_add( ic, node, jabber_chat_join_failed ); if( !jabber_write_packet( ic, node ) ) { g_free( roomjid ); - xt_free_node( node ); return NULL; } - xt_free_node( node ); jc = g_new0( struct jabber_chat, 1 ); jc->name = jabber_normalize( room ); @@ -64,6 +65,45 @@ struct groupchat *jabber_chat_join( struct im_connection *ic, char *room, char * return c; } +static xt_status jabber_chat_join_failed( struct im_connection *ic, struct xt_node *node, struct xt_node *orig ) +{ + struct jabber_error *err; + struct jabber_buddy *bud; + char *room; + + room = xt_find_attr( orig, "to" ); + if( ( bud = jabber_buddy_by_jid( ic, room, 0 ) ) ) + jabber_chat_free( jabber_chat_by_jid( ic, bud->bare_jid ) ); + + err = jabber_error_parse( xt_find_node( node->children, "error" ), XMLNS_STANZA_ERROR ); + if( err ) + { + imcb_error( ic, "Error joining groupchat %s: %s%s%s", + bud->bare_jid, err->code, err->text ? ": " : "", + err->text ? err->text : "" ); + jabber_error_free( err ); + } + + return XT_HANDLED; +} + +struct groupchat *jabber_chat_by_jid( struct im_connection *ic, const char *name ) +{ + char *normalized = jabber_normalize( name ); + struct groupchat *ret; + struct jabber_chat *jc; + + for( ret = ic->groupchats; ret; ret = ret->next ) + { + jc = ret->data; + if( strcmp( normalized, jc->name ) == 0 ) + break; + } + g_free( normalized ); + + return ret; +} + void jabber_chat_free( struct groupchat *c ) { struct jabber_chat *jc = c->data; @@ -147,7 +187,7 @@ void jabber_chat_pkt_presence( struct im_connection *ic, struct jabber_buddy *bu struct jabber_chat *jc; char *s; - if( ( chat = jabber_chat_by_name( ic, bud->bare_jid ) ) == NULL ) + if( ( chat = jabber_chat_by_jid( ic, bud->bare_jid ) ) == NULL ) { /* How could this happen?? We could do kill( self, 11 ) now or just wait for the OS to do it. :-) */ @@ -249,7 +289,7 @@ void jabber_chat_pkt_message( struct im_connection *ic, struct jabber_buddy *bud return; } - else if( ( chat = jabber_chat_by_name( ic, bud->bare_jid ) ) == NULL ) + else if( ( chat = jabber_chat_by_jid( ic, bud->bare_jid ) ) == NULL ) { /* How could this happen?? We could do kill( self, 11 ) now or just wait for the OS to do it. :-) */ diff --git a/protocols/jabber/iq.c b/protocols/jabber/iq.c index 77def222..8cf6c7f1 100644 --- a/protocols/jabber/iq.c +++ b/protocols/jabber/iq.c @@ -30,7 +30,6 @@ static xt_status jabber_iq_display_vcard( struct im_connection *ic, struct xt_no xt_status jabber_pkt_iq( struct xt_node *node, gpointer data ) { struct im_connection *ic = data; - struct jabber_data *jd = ic->proto_data; struct xt_node *c, *reply = NULL; char *type, *s; int st, pack = 1; @@ -46,23 +45,7 @@ xt_status jabber_pkt_iq( struct xt_node *node, gpointer data ) if( strcmp( type, "result" ) == 0 || strcmp( type, "error" ) == 0 ) { - struct jabber_cache_entry *entry; - - if( ( s = xt_find_attr( node, "id" ) ) == NULL || - strncmp( s, jd->cached_id_prefix, strlen( jd->cached_id_prefix ) ) != 0 ) - { - /* Silently ignore it, without an ID (or a non-cache - ID) we don't know how to handle the packet and we - probably don't have to. */ - return XT_HANDLED; - } - - entry = g_hash_table_lookup( jd->node_cache, s ); - - if( entry == NULL ) - imcb_log( ic, "WARNING: Received IQ-%s packet with unknown/expired ID %s!", type, s ); - else if( entry->func ) - return entry->func( ic, node, entry->node ); + return jabber_cache_handle_packet( ic, node ); } else if( strcmp( type, "get" ) == 0 ) { diff --git a/protocols/jabber/jabber.c b/protocols/jabber/jabber.c index 1f4f42ea..98d2dadf 100644 --- a/protocols/jabber/jabber.c +++ b/protocols/jabber/jabber.c @@ -225,8 +225,6 @@ static void jabber_generate_id_hash( struct jabber_data *jd ) s = base64_encode( binbuf, 9 ); jd->cached_id_prefix = g_strdup_printf( "%s%s", JABBER_CACHED_ID, s ); g_free( s ); - - printf( "%s\n", jd->cached_id_prefix ); } static void jabber_logout( struct im_connection *ic ) @@ -271,7 +269,7 @@ static int jabber_buddy_msg( struct im_connection *ic, char *who, char *message, if( g_strcasecmp( who, JABBER_XMLCONSOLE_HANDLE ) == 0 ) return jabber_write( ic, message, strlen( message ) ); - if( ( s = strchr( who, '=' ) ) && jabber_chat_by_name( ic, s + 1 ) ) + if( ( s = strchr( who, '=' ) ) && jabber_chat_by_jid( ic, s + 1 ) ) bud = jabber_buddy_by_ext_jid( ic, who, 0 ); else bud = jabber_buddy_by_jid( ic, who, 0 ); @@ -398,7 +396,7 @@ static struct groupchat *jabber_chat_join_( struct im_connection *ic, char *room { if( strchr( room, '@' ) == NULL ) imcb_error( ic, "Invalid room name: %s", room ); - else if( jabber_chat_by_name( ic, room ) ) + else if( jabber_chat_by_jid( ic, room ) ) imcb_error( ic, "Already present in chat `%s'", room ); else return jabber_chat_join( ic, room, nick, password ); diff --git a/protocols/jabber/jabber.h b/protocols/jabber/jabber.h index 45082fee..c518f541 100644 --- a/protocols/jabber/jabber.h +++ b/protocols/jabber/jabber.h @@ -226,6 +226,7 @@ void jabber_cache_add( struct im_connection *ic, struct xt_node *node, jabber_ca struct xt_node *jabber_cache_get( struct im_connection *ic, char *id ); void jabber_cache_entry_free( gpointer entry ); void jabber_cache_clean( struct im_connection *ic ); +xt_status jabber_cache_handle_packet( struct im_connection *ic, struct xt_node *node ); const struct jabber_away_state *jabber_away_state_by_code( char *code ); const struct jabber_away_state *jabber_away_state_by_name( char *name ); void jabber_buddy_ask( struct im_connection *ic, char *handle ); @@ -248,7 +249,6 @@ struct jabber_buddy *jabber_buddy_by_jid( struct im_connection *ic, char *jid, g struct jabber_buddy *jabber_buddy_by_ext_jid( struct im_connection *ic, char *jid, get_buddy_flags_t flags ); int jabber_buddy_remove( struct im_connection *ic, char *full_jid ); int jabber_buddy_remove_bare( struct im_connection *ic, char *bare_jid ); -struct groupchat *jabber_chat_by_name( struct im_connection *ic, const char *name ); time_t jabber_get_timestamp( struct xt_node *xt ); struct jabber_error *jabber_error_parse( struct xt_node *node, char *xmlns ); void jabber_error_free( struct jabber_error *err ); @@ -271,6 +271,7 @@ gboolean sasl_supported( struct im_connection *ic ); /* conference.c */ struct groupchat *jabber_chat_join( struct im_connection *ic, char *room, char *nick, char *password ); +struct groupchat *jabber_chat_by_jid( struct im_connection *ic, const char *name ); void jabber_chat_free( struct groupchat *c ); int jabber_chat_msg( struct groupchat *ic, char *message, int flags ); int jabber_chat_topic( struct groupchat *c, char *topic ); diff --git a/protocols/jabber/jabber_util.c b/protocols/jabber/jabber_util.c index 6bb65878..7350eaf4 100644 --- a/protocols/jabber/jabber_util.c +++ b/protocols/jabber/jabber_util.c @@ -184,6 +184,36 @@ gboolean jabber_cache_clean_entry( gpointer key, gpointer entry_, gpointer nullp } } +xt_status jabber_cache_handle_packet( struct im_connection *ic, struct xt_node *node ) +{ + struct jabber_data *jd = ic->proto_data; + struct jabber_cache_entry *entry; + char *s; + + if( ( s = xt_find_attr( node, "id" ) ) == NULL || + strncmp( s, jd->cached_id_prefix, strlen( jd->cached_id_prefix ) ) != 0 ) + { + /* Silently ignore it, without an ID (or a non-cache + ID) we don't know how to handle the packet and we + probably don't have to. */ + return XT_HANDLED; + } + + entry = g_hash_table_lookup( jd->node_cache, s ); + + if( entry == NULL ) + { + imcb_log( ic, "WARNING: Received %s-%s packet with unknown/expired ID %s!", + node->name, xt_find_attr( node, "type" ) ? : "(no type)", s ); + } + else if( entry->func ) + { + return entry->func( ic, node, entry->node ); + } + + return XT_HANDLED; +} + const struct jabber_away_state jabber_away_state_list[] = { { "away", "Away" }, @@ -594,23 +624,6 @@ int jabber_buddy_remove_bare( struct im_connection *ic, char *bare_jid ) } } -struct groupchat *jabber_chat_by_name( struct im_connection *ic, const char *name ) -{ - char *normalized = jabber_normalize( name ); - struct groupchat *ret; - struct jabber_chat *jc; - - for( ret = ic->groupchats; ret; ret = ret->next ) - { - jc = ret->data; - if( strcmp( normalized, jc->name ) == 0 ) - break; - } - g_free( normalized ); - - return ret; -} - time_t jabber_get_timestamp( struct xt_node *xt ) { struct tm tp, utc; @@ -662,10 +675,14 @@ time_t jabber_get_timestamp( struct xt_node *xt ) struct jabber_error *jabber_error_parse( struct xt_node *node, char *xmlns ) { - struct jabber_error *err = g_new0( struct jabber_error, 1 ); + struct jabber_error *err; struct xt_node *c; char *s; + if( node == NULL ) + return NULL; + + err = g_new0( struct jabber_error, 1 ); err->type = xt_find_attr( node, "type" ); for( c = node->children; c; c = c->next ) diff --git a/protocols/jabber/presence.c b/protocols/jabber/presence.c index 5abdc449..c3d7dced 100644 --- a/protocols/jabber/presence.c +++ b/protocols/jabber/presence.c @@ -39,7 +39,7 @@ xt_status jabber_pkt_presence( struct xt_node *node, gpointer data ) if( ( s = strchr( from, '/' ) ) ) { *s = 0; - if( jabber_chat_by_name( ic, from ) ) + if( jabber_chat_by_jid( ic, from ) ) is_chat = 1; *s = '/'; } @@ -163,8 +163,10 @@ xt_status jabber_pkt_presence( struct xt_node *node, gpointer data ) } else if( strcmp( type, "error" ) == 0 ) { - struct jabber_error *err; + return jabber_cache_handle_packet( ic, node ); + /* + struct jabber_error *err; if( ( c = xt_find_node( node->children, "error" ) ) ) { err = jabber_error_parse( c, XMLNS_STANZA_ERROR ); @@ -172,8 +174,7 @@ xt_status jabber_pkt_presence( struct xt_node *node, gpointer data ) err->code, err->text ? ": " : "", err->text ? err->text : "" ); jabber_error_free( err ); - } - /* What else to do with it? */ + } */ } return XT_HANDLED; diff --git a/protocols/oscar/msgcookie.c b/protocols/oscar/msgcookie.c index d3c91a94..efeb8cbf 100644 --- a/protocols/oscar/msgcookie.c +++ b/protocols/oscar/msgcookie.c @@ -130,21 +130,6 @@ aim_msgcookie_t *aim_checkcookie(aim_session_t *sess, const guint8 *cookie, int return NULL; } -#if 0 /* debugging feature */ -int aim_dumpcookie(aim_msgcookie_t *cookie) -{ - - if (!cookie) - return -EINVAL; - - printf("\tCookie at %p: %d/%s with %p, next %p\n", - cookie, cookie->type, cookie->cookie, - cookie->data, cookie->next); - - return 0; -} -#endif - /** * aim_cookie_free - free an aim_msgcookie_t struct * @sess: session to remove the cookie from |