From 5bd21df87b195af211c2280ca00391493a669895 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 2 Dec 2007 17:25:57 +0000 Subject: Handling of presence-error packets (only useful for groupchats now), moved jabber_chat_by_jid() (with the right name) to conference.c, I don't know what it was doing in jabber_util.c. --- protocols/jabber/conference.c | 48 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-) (limited to 'protocols/jabber/conference.c') diff --git a/protocols/jabber/conference.c b/protocols/jabber/conference.c index 008bbe63..72d7b5d8 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" ); + bud = jabber_buddy_by_jid( ic, room, 0 ); + + 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 ); + } + + if( bud ) + jabber_chat_free( jabber_chat_by_jid( ic, bud->bare_jid ) ); +} + +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. :-) */ -- cgit v1.2.3 From 80e9db97776bfd6c6192135d65027abd8f50887c Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 2 Dec 2007 23:14:49 +0000 Subject: Forgot to return something in jabber_chat_join_failed(). --- protocols/jabber/conference.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'protocols/jabber/conference.c') diff --git a/protocols/jabber/conference.c b/protocols/jabber/conference.c index 72d7b5d8..c5bc0e68 100644 --- a/protocols/jabber/conference.c +++ b/protocols/jabber/conference.c @@ -72,7 +72,8 @@ static xt_status jabber_chat_join_failed( struct im_connection *ic, struct xt_no char *room; room = xt_find_attr( orig, "to" ); - bud = jabber_buddy_by_jid( ic, room, 0 ); + 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 ) @@ -83,8 +84,7 @@ static xt_status jabber_chat_join_failed( struct im_connection *ic, struct xt_no jabber_error_free( err ); } - if( bud ) - jabber_chat_free( jabber_chat_by_jid( ic, bud->bare_jid ) ); + return XT_HANDLED; } struct groupchat *jabber_chat_by_jid( struct im_connection *ic, const char *name ) -- cgit v1.2.3