diff options
Diffstat (limited to 'protocols/jabber')
-rw-r--r-- | protocols/jabber/conference.c | 25 | ||||
-rw-r--r-- | protocols/jabber/io.c | 38 | ||||
-rw-r--r-- | protocols/jabber/iq.c | 36 | ||||
-rw-r--r-- | protocols/jabber/jabber.c | 24 | ||||
-rw-r--r-- | protocols/jabber/jabber.h | 11 | ||||
-rw-r--r-- | protocols/jabber/jabber_util.c | 13 | ||||
-rw-r--r-- | protocols/jabber/presence.c | 27 |
7 files changed, 97 insertions, 77 deletions
diff --git a/protocols/jabber/conference.c b/protocols/jabber/conference.c index 79fdd053..f434c58a 100644 --- a/protocols/jabber/conference.c +++ b/protocols/jabber/conference.c @@ -25,7 +25,7 @@ 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 groupchat *jabber_chat_join( struct im_connection *ic, const char *room, const char *nick, const char *password ) { struct jabber_chat *jc; struct xt_node *node; @@ -35,9 +35,9 @@ struct groupchat *jabber_chat_join( struct im_connection *ic, char *room, char * roomjid = g_strdup_printf( "%s/%s", room, nick ); node = xt_new_node( "x", NULL, NULL ); xt_add_attr( node, "xmlns", XMLNS_MUC ); - node = jabber_make_packet( "presence", NULL, roomjid, node ); if( password ) xt_add_child( node, xt_new_node( "password", password, NULL ) ); + node = jabber_make_packet( "presence", NULL, roomjid, node ); jabber_cache_add( ic, node, jabber_chat_join_failed ); if( !jabber_write_packet( ic, node ) ) @@ -233,8 +233,10 @@ void jabber_chat_pkt_presence( struct im_connection *ic, struct jabber_buddy *bu if( ( s = xt_find_attr( c, "xmlns" ) ) && ( strcmp( s, XMLNS_MUC_USER ) == 0 ) ) { - c = xt_find_node( c->children, "item" ); - if( ( s = xt_find_attr( c, "jid" ) ) ) + struct xt_node *item; + + item = xt_find_node( c->children, "item" ); + if( ( s = xt_find_attr( item, "jid" ) ) ) { /* Yay, found what we need. :-) */ bud->ext_jid = jabber_normalize( s ); @@ -282,12 +284,15 @@ void jabber_chat_pkt_presence( struct im_connection *ic, struct jabber_buddy *bu } else if( type ) /* type can only be NULL or "unavailable" in this function */ { - s = strchr( bud->ext_jid, '/' ); - if( s ) *s = 0; - imcb_chat_remove_buddy( chat, bud->ext_jid, NULL ); - if( bud != jc->me && bud->flags & JBFLAG_IS_ANONYMOUS ) - imcb_remove_buddy( ic, bud->ext_jid, NULL ); - if( s ) *s = '/'; + if( ( bud->flags & JBFLAG_IS_CHATROOM ) && bud->ext_jid ) + { + s = strchr( bud->ext_jid, '/' ); + if( s ) *s = 0; + imcb_chat_remove_buddy( chat, bud->ext_jid, NULL ); + if( bud != jc->me && bud->flags & JBFLAG_IS_ANONYMOUS ) + imcb_remove_buddy( ic, bud->ext_jid, NULL ); + if( s ) *s = '/'; + } if( bud == jc->me ) jabber_chat_free( chat ); diff --git a/protocols/jabber/io.c b/protocols/jabber/io.c index 10efad37..4a790f27 100644 --- a/protocols/jabber/io.c +++ b/protocols/jabber/io.c @@ -374,39 +374,23 @@ static xt_status jabber_pkt_features( struct xt_node *node, gpointer data ) } if( ( c = xt_find_node( node->children, "bind" ) ) ) - { - reply = xt_new_node( "bind", NULL, xt_new_node( "resource", set_getstr( &ic->acc->set, "resource" ), NULL ) ); - xt_add_attr( reply, "xmlns", XMLNS_BIND ); - reply = jabber_make_packet( "iq", "set", NULL, reply ); - jabber_cache_add( ic, reply, jabber_pkt_bind_sess ); - - if( !jabber_write_packet( ic, reply ) ) - return XT_ABORT; - - jd->flags |= JFLAG_WAIT_BIND; - } + jd->flags |= JFLAG_WANT_BIND; if( ( c = xt_find_node( node->children, "session" ) ) ) - { - reply = xt_new_node( "session", NULL, NULL ); - xt_add_attr( reply, "xmlns", XMLNS_SESSION ); - reply = jabber_make_packet( "iq", "set", NULL, reply ); - jabber_cache_add( ic, reply, jabber_pkt_bind_sess ); - - if( !jabber_write_packet( ic, reply ) ) - return XT_ABORT; - - jd->flags |= JFLAG_WAIT_SESSION; - } + jd->flags |= JFLAG_WANT_SESSION; /* This flag is already set if we authenticated via SASL, so now we can resume the session in the new stream, if we don't have to bind/initialize the session. */ - if( jd->flags & JFLAG_AUTHENTICATED && ( jd->flags & ( JFLAG_WAIT_BIND | JFLAG_WAIT_SESSION ) ) == 0 ) + if( jd->flags & JFLAG_AUTHENTICATED && ( jd->flags & ( JFLAG_WANT_BIND | JFLAG_WANT_SESSION ) ) == 0 ) { if( !jabber_get_roster( ic ) ) return XT_ABORT; } + else if( jd->flags & JFLAG_AUTHENTICATED ) + { + return jabber_pkt_bind_sess( ic, NULL, NULL ); + } return XT_HANDLED; } @@ -440,6 +424,7 @@ static xt_status jabber_pkt_proceed_tls( struct xt_node *node, gpointer data ) imcb_log( ic, "Converting stream to TLS" ); + jd->flags |= JFLAG_STARTTLS_DONE; jd->ssl = ssl_starttls( jd->fd, jabber_connected_ssl, ic ); return XT_HANDLED; @@ -530,9 +515,10 @@ gboolean jabber_start_stream( struct im_connection *ic ) if( jd->r_inpa <= 0 ) jd->r_inpa = b_input_add( jd->fd, GAIM_INPUT_READ, jabber_read_callback, ic ); - greet = g_strdup_printf( "<?xml version='1.0' ?>" - "<stream:stream to=\"%s\" xmlns=\"jabber:client\" " - "xmlns:stream=\"http://etherx.jabber.org/streams\" version=\"1.0\">", jd->server ); + greet = g_strdup_printf( "%s<stream:stream to=\"%s\" xmlns=\"jabber:client\" " + "xmlns:stream=\"http://etherx.jabber.org/streams\" version=\"1.0\">", + ( jd->flags & JFLAG_STARTTLS_DONE ) ? "" : "<?xml version='1.0' ?>", + jd->server ); st = jabber_write( ic, greet, strlen( greet ) ); diff --git a/protocols/jabber/iq.c b/protocols/jabber/iq.c index 38c5a5a9..21e52da6 100644 --- a/protocols/jabber/iq.c +++ b/protocols/jabber/iq.c @@ -50,10 +50,11 @@ xt_status jabber_pkt_iq( struct xt_node *node, gpointer data ) else if( strcmp( type, "get" ) == 0 ) { if( !( ( c = xt_find_node( node->children, "query" ) ) || - ( c = xt_find_node( node->children, "ping" ) ) ) || /* O_o WHAT is wrong with just <query/> ????? */ + ( c = xt_find_node( node->children, "ping" ) ) ) || !( s = xt_find_attr( c, "xmlns" ) ) ) { - imcb_log( ic, "Warning: Received incomplete IQ-%s packet", type ); + /* Sigh. Who decided to suddenly invent new elements + instead of just sticking with <query/>? */ return XT_HANDLED; } @@ -296,24 +297,43 @@ static xt_status jabber_finish_iq_auth( struct im_connection *ic, struct xt_node xt_status jabber_pkt_bind_sess( struct im_connection *ic, struct xt_node *node, struct xt_node *orig ) { struct jabber_data *jd = ic->proto_data; - struct xt_node *c; + struct xt_node *c, *reply = NULL; char *s; - if( ( c = xt_find_node( node->children, "bind" ) ) ) + if( node && ( c = xt_find_node( node->children, "bind" ) ) ) { c = xt_find_node( c->children, "jid" ); if( c && c->text_len && ( s = strchr( c->text, '/' ) ) && strcmp( s + 1, set_getstr( &ic->acc->set, "resource" ) ) != 0 ) imcb_log( ic, "Server changed session resource string to `%s'", s + 1 ); - jd->flags &= ~JFLAG_WAIT_BIND; + jd->flags &= ~JFLAG_WANT_BIND; } - else + else if( node && ( c = xt_find_node( node->children, "session" ) ) ) { - jd->flags &= ~JFLAG_WAIT_SESSION; + jd->flags &= ~JFLAG_WANT_SESSION; } - if( ( jd->flags & ( JFLAG_WAIT_BIND | JFLAG_WAIT_SESSION ) ) == 0 ) + if( jd->flags & JFLAG_WANT_BIND ) + { + reply = xt_new_node( "bind", NULL, xt_new_node( "resource", set_getstr( &ic->acc->set, "resource" ), NULL ) ); + xt_add_attr( reply, "xmlns", XMLNS_BIND ); + } + else if( jd->flags & JFLAG_WANT_SESSION ) + { + reply = xt_new_node( "session", NULL, NULL ); + xt_add_attr( reply, "xmlns", XMLNS_SESSION ); + } + + if( reply != NULL ) + { + reply = jabber_make_packet( "iq", "set", NULL, reply ); + jabber_cache_add( ic, reply, jabber_pkt_bind_sess ); + + if( !jabber_write_packet( ic, reply ) ) + return XT_ABORT; + } + else if( ( jd->flags & ( JFLAG_WANT_BIND | JFLAG_WANT_SESSION ) ) == 0 ) { if( !jabber_get_roster( ic ) ) return XT_ABORT; diff --git a/protocols/jabber/jabber.c b/protocols/jabber/jabber.c index c9c1d0a0..eca7d2d3 100644 --- a/protocols/jabber/jabber.c +++ b/protocols/jabber/jabber.c @@ -69,7 +69,7 @@ static void jabber_init( account_t *acc ) s = set_add( &acc->set, "resource_select", "priority", NULL, acc ); s = set_add( &acc->set, "server", NULL, set_eval_account, acc ); - s->flags |= ACC_SET_NOSAVE | ACC_SET_OFFLINE_ONLY; + s->flags |= ACC_SET_NOSAVE | ACC_SET_OFFLINE_ONLY | SET_NULL_OK; s = set_add( &acc->set, "ssl", "false", set_eval_bool, acc ); s->flags |= ACC_SET_OFFLINE_ONLY; @@ -79,6 +79,8 @@ static void jabber_init( account_t *acc ) s = set_add( &acc->set, "xmlconsole", "false", set_eval_bool, acc ); s->flags |= ACC_SET_OFFLINE_ONLY; + + acc->flags |= ACC_FLAG_AWAY_MESSAGE | ACC_FLAG_STATUS_MESSAGE; } static void jabber_generate_id_hash( struct jabber_data *jd ); @@ -363,10 +365,11 @@ static void jabber_get_info( struct im_connection *ic, char *who ) while( bud ) { - imcb_log( ic, "Buddy %s (%d) information:\nAway state: %s\nAway message: %s", - bud->full_jid, bud->priority, - bud->away_state ? bud->away_state->full_name : "(none)", - bud->away_message ? : "(none)" ); + imcb_log( ic, "Buddy %s (%d) information:", bud->full_jid, bud->priority ); + if( bud->away_state ) + imcb_log( ic, "Away state: %s", bud->away_state->full_name ); + imcb_log( ic, "Status message: %s", bud->away_message ? : "(none)" ); + bud = bud->next; } @@ -376,11 +379,12 @@ static void jabber_get_info( struct im_connection *ic, char *who ) static void jabber_set_away( struct im_connection *ic, char *state_txt, char *message ) { struct jabber_data *jd = ic->proto_data; - struct jabber_away_state *state; - /* Save all this info. We need it, for example, when changing the priority setting. */ - state = (void *) jabber_away_state_by_name( state_txt ); - jd->away_state = state ? state : (void *) jabber_away_state_list; /* Fall back to "Away" if necessary. */ + /* state_txt == NULL -> Not away. + Unknown state -> fall back to the first defined away state. */ + jd->away_state = state_txt ? jabber_away_state_by_name( state_txt ) + ? : jabber_away_state_list : NULL; + g_free( jd->away_message ); jd->away_message = ( message && *message ) ? g_strdup( message ) : NULL; @@ -424,7 +428,7 @@ static void jabber_remove_buddy( struct im_connection *ic, char *who, char *grou presence_send_request( ic, who, "unsubscribe" ); } -static struct groupchat *jabber_chat_join_( struct im_connection *ic, char *room, char *nick, char *password ) +static struct groupchat *jabber_chat_join_( struct im_connection *ic, const char *room, const char *nick, const char *password ) { if( strchr( room, '@' ) == NULL ) imcb_error( ic, "Invalid room name: %s", room ); diff --git a/protocols/jabber/jabber.h b/protocols/jabber/jabber.h index 61238a30..8e3bf036 100644 --- a/protocols/jabber/jabber.h +++ b/protocols/jabber/jabber.h @@ -26,9 +26,9 @@ #include <glib.h> -#include "xmltree.h" #include "bitlbee.h" #include "md5.h" +#include "xmltree.h" extern GSList *jabber_connections; @@ -39,12 +39,13 @@ typedef enum JFLAG_AUTHENTICATED = 2, /* Set when we're successfully authenticatd. */ JFLAG_STREAM_RESTART = 4, /* Set when we want to restart the stream (after SASL or TLS). */ - JFLAG_WAIT_SESSION = 8, /* Set if we sent a <session> tag and need a reply + JFLAG_WANT_SESSION = 8, /* Set if the server wants a <session/> tag before we continue. */ - JFLAG_WAIT_BIND = 16, /* ... for <bind> tag. */ + JFLAG_WANT_BIND = 16, /* ... for <bind> tag. */ JFLAG_WANT_TYPING = 32, /* Set if we ever sent a typing notification, this activates all XEP-85 related code. */ JFLAG_XMLCONSOLE = 64, /* If the user added an xmlconsole buddy. */ + JFLAG_STARTTLS_DONE = 128, /* If a plaintext session was converted to TLS. */ } jabber_flags_t; typedef enum @@ -83,7 +84,7 @@ struct jabber_data /* After changing one of these two (or the priority setting), call presence_send_update() to inform the server about the changes. */ - struct jabber_away_state *away_state; + const struct jabber_away_state *away_state; char *away_message; md5_state_t cached_id_prefix; @@ -240,7 +241,7 @@ xt_status sasl_pkt_result( struct xt_node *node, gpointer data ); 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_join( struct im_connection *ic, const char *room, const char *nick, const 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 ); diff --git a/protocols/jabber/jabber_util.c b/protocols/jabber/jabber_util.c index 1bee5009..185d3878 100644 --- a/protocols/jabber/jabber_util.c +++ b/protocols/jabber/jabber_util.c @@ -36,10 +36,10 @@ char *set_eval_priority( set_t *set, char *value ) { /* Priority is a signed 8-bit integer, according to RFC 3921. */ if( i < -128 || i > 127 ) - return NULL; + return SET_INVALID; } else - return NULL; + return SET_INVALID; /* Only run this stuff if the account is online ATM, and if the setting seems to be acceptable. */ @@ -227,10 +227,9 @@ xt_status jabber_cache_handle_packet( struct im_connection *ic, struct xt_node * const struct jabber_away_state jabber_away_state_list[] = { { "away", "Away" }, - { "chat", "Free for Chat" }, + { "chat", "Free for Chat" }, /* WTF actually uses this? */ { "dnd", "Do not Disturb" }, { "xa", "Extended Away" }, - { "", "Online" }, { "", NULL } }; @@ -238,6 +237,9 @@ const struct jabber_away_state *jabber_away_state_by_code( char *code ) { int i; + if( code == NULL ) + return NULL; + for( i = 0; jabber_away_state_list[i].full_name; i ++ ) if( g_strcasecmp( jabber_away_state_list[i].code, code ) == 0 ) return jabber_away_state_list + i; @@ -249,6 +251,9 @@ const struct jabber_away_state *jabber_away_state_by_name( char *name ) { int i; + if( name == NULL ) + return NULL; + for( i = 0; jabber_away_state_list[i].full_name; i ++ ) if( g_strcasecmp( jabber_away_state_list[i].full_name, name ) == 0 ) return jabber_away_state_list + i; diff --git a/protocols/jabber/presence.c b/protocols/jabber/presence.c index 6fc360b7..28aaea1b 100644 --- a/protocols/jabber/presence.c +++ b/protocols/jabber/presence.c @@ -48,8 +48,9 @@ xt_status jabber_pkt_presence( struct xt_node *node, gpointer data ) { if( !( bud = jabber_buddy_by_jid( ic, from, GET_BUDDY_EXACT | GET_BUDDY_CREAT ) ) ) { - if( set_getbool( &ic->irc->set, "debug" ) ) - imcb_log( ic, "Warning: Could not handle presence information from JID: %s", from ); + /* + imcb_log( ic, "Warning: Could not handle presence information from JID: %s", from ); + */ return XT_HANDLED; } @@ -105,8 +106,9 @@ xt_status jabber_pkt_presence( struct xt_node *node, gpointer data ) { if( ( bud = jabber_buddy_by_jid( ic, from, 0 ) ) == NULL ) { - if( set_getbool( &ic->irc->set, "debug" ) ) - imcb_log( ic, "Warning: Received presence information from unknown JID: %s", from ); + /* + imcb_log( ic, "Warning: Received presence information from unknown JID: %s", from ); + */ return XT_HANDLED; } @@ -187,13 +189,12 @@ xt_status jabber_pkt_presence( struct xt_node *node, gpointer data ) { int is_away = 0; - if( send_presence->away_state && !( *send_presence->away_state->code == 0 || - strcmp( send_presence->away_state->code, "chat" ) == 0 ) ) + if( send_presence->away_state && + strcmp( send_presence->away_state->code, "chat" ) != 0 ) is_away = OPT_AWAY; imcb_buddy_status( ic, send_presence->bare_jid, OPT_LOGGED_IN | is_away, - ( is_away && send_presence->away_state ) ? - send_presence->away_state->full_name : NULL, + is_away ? send_presence->away_state->full_name : NULL, send_presence->away_message ); } @@ -206,17 +207,15 @@ int presence_send_update( struct im_connection *ic ) { struct jabber_data *jd = ic->proto_data; struct xt_node *node, *cap; - char *show = jd->away_state->code; - char *status = jd->away_message; struct groupchat *c; int st; node = jabber_make_packet( "presence", NULL, NULL, NULL ); xt_add_child( node, xt_new_node( "priority", set_getstr( &ic->acc->set, "priority" ), NULL ) ); - if( show && *show ) - xt_add_child( node, xt_new_node( "show", show, NULL ) ); - if( status ) - xt_add_child( node, xt_new_node( "status", status, NULL ) ); + if( jd->away_state ) + xt_add_child( node, xt_new_node( "show", jd->away_state->code, NULL ) ); + if( jd->away_message ) + xt_add_child( node, xt_new_node( "status", jd->away_message, NULL ) ); /* This makes the packet slightly bigger, but clients interested in capabilities can now cache the discovery info. This reduces the |