aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--protocols/jabber/conference.c48
-rw-r--r--protocols/jabber/jabber.c4
-rw-r--r--protocols/jabber/jabber.h2
-rw-r--r--protocols/jabber/jabber_util.c23
-rw-r--r--protocols/jabber/presence.c9
5 files changed, 57 insertions, 29 deletions
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. :-) */
diff --git a/protocols/jabber/jabber.c b/protocols/jabber/jabber.c
index 6ee10a38..817d1487 100644
--- a/protocols/jabber/jabber.c
+++ b/protocols/jabber/jabber.c
@@ -269,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 );
@@ -396,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 bee5cb73..94d017d6 100644
--- a/protocols/jabber/jabber.h
+++ b/protocols/jabber/jabber.h
@@ -207,7 +207,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 );
@@ -230,6 +229,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 453e5930..9d84e099 100644
--- a/protocols/jabber/jabber_util.c
+++ b/protocols/jabber/jabber_util.c
@@ -613,23 +613,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;
@@ -681,10 +664,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;