diff options
author | dequis <dx@dxzone.com.ar> | 2014-07-20 03:28:49 -0300 |
---|---|---|
committer | dequis <dx@dxzone.com.ar> | 2015-01-25 23:43:34 -0300 |
commit | be1efa31e01a96be922c7addba2d9207bfbdf5fc (patch) | |
tree | 7ed979bde6284ded3cf1f1c1a7a870b2a55e9d00 | |
parent | 8519f457c31139750b9f7497834ac90a57196d22 (diff) |
Add handle_is_self() prpl function to fix JID mismatch confusion bugs
When bee_chat needs to check for self messages, it can call this
function to let the protocol implementation do the comparison.
In the case of jabber, sometimes the server reports a different username
after login, this one is stored in jd->internal_jid, and the one that is
used for login isn't changed
-rw-r--r-- | protocols/bee_chat.c | 15 | ||||
-rw-r--r-- | protocols/jabber/iq.c | 4 | ||||
-rw-r--r-- | protocols/jabber/jabber.c | 9 | ||||
-rw-r--r-- | protocols/jabber/jabber.h | 1 | ||||
-rw-r--r-- | protocols/jabber/jabber_util.c | 4 | ||||
-rw-r--r-- | protocols/nogaim.h | 3 |
6 files changed, 28 insertions, 8 deletions
diff --git a/protocols/bee_chat.c b/protocols/bee_chat.c index 39110a10..e1d07925 100644 --- a/protocols/bee_chat.c +++ b/protocols/bee_chat.c @@ -79,6 +79,13 @@ void imcb_chat_free( struct groupchat *c ) g_free( c ); } +static gboolean handle_is_self( struct im_connection *ic, const char *handle ) +{ + return ( ic->acc->prpl->handle_is_self ) ? + ic->acc->prpl->handle_is_self( ic, handle ) : + ( ic->acc->prpl->handle_cmp( ic->acc->user, handle ) == 0 ); +} + void imcb_chat_msg( struct groupchat *c, const char *who, char *msg, uint32_t flags, time_t sent_at ) { struct im_connection *ic = c->ic; @@ -88,7 +95,7 @@ void imcb_chat_msg( struct groupchat *c, const char *who, char *msg, uint32_t fl char *s; /* Gaim sends own messages through this too. IRC doesn't want this, so kill them */ - if( g_strcasecmp( who, ic->acc->user ) == 0 ) + if( handle_is_self( ic, who ) ) return; bu = bee_user_by_handle( bee, ic, who ); @@ -138,7 +145,7 @@ void imcb_chat_topic( struct groupchat *c, char *who, char *topic, time_t set_at if( who == NULL) bu = NULL; - else if( g_strcasecmp( who, ic->acc->user ) == 0 ) + else if( handle_is_self( ic, who ) ) bu = bee->user; else bu = bee_user_by_handle( bee, ic, who ); @@ -160,7 +167,7 @@ void imcb_chat_add_buddy( struct groupchat *c, const char *handle ) if( set_getbool( &c->ic->bee->set, "debug" ) ) imcb_log( c->ic, "User %s added to conversation %p", handle, c ); - me = ic->acc->prpl->handle_cmp( handle, ic->acc->user ) == 0; + me = handle_is_self( ic, handle ); /* Most protocols allow people to join, even when they're not in your contact list. Try to handle that here */ @@ -188,7 +195,7 @@ void imcb_chat_remove_buddy( struct groupchat *c, const char *handle, const char imcb_log( ic, "User %s removed from conversation %p (%s)", handle, c, reason ? reason : "" ); /* It might be yourself! */ - if( g_strcasecmp( handle, ic->acc->user ) == 0 ) + if( handle_is_self( ic, handle ) ) { if( c->joined == 0 ) return; diff --git a/protocols/jabber/iq.c b/protocols/jabber/iq.c index 61417bcc..cf1ff298 100644 --- a/protocols/jabber/iq.c +++ b/protocols/jabber/iq.c @@ -357,10 +357,6 @@ xt_status jabber_pkt_bind_sess( struct im_connection *ic, struct xt_node *node, if( s ) *s = '\0'; jabber_set_me( ic, c->text ); - imcb_log( ic, "Server claims your JID is `%s' instead of `%s'. " - "This mismatch may cause problems with groupchats " - "and possibly other things.", - c->text, ic->acc->user ); if( s ) *s = '/'; } diff --git a/protocols/jabber/jabber.c b/protocols/jabber/jabber.c index 4b5cb3a1..ccc13f47 100644 --- a/protocols/jabber/jabber.c +++ b/protocols/jabber/jabber.c @@ -317,6 +317,7 @@ static void jabber_logout( struct im_connection *ic ) g_free( jd->oauth2_access_token ); g_free( jd->away_message ); + g_free( jd->internal_jid ); g_free( jd->username ); g_free( jd->me ); g_free( jd ); @@ -620,6 +621,13 @@ void *jabber_buddy_action( struct bee_user *bu, const char *action, char * const return NULL; } +gboolean jabber_handle_is_self( struct im_connection *ic, const char *who ) { + struct jabber_data *jd = ic->proto_data; + return ( ( g_strcasecmp( who, ic->acc->user ) == 0 ) || + ( jd->internal_jid && + g_strcasecmp( who, jd->internal_jid ) == 0 ) ); +} + void jabber_initmodule() { struct prpl *ret = g_new0( struct prpl, 1 ); @@ -647,6 +655,7 @@ void jabber_initmodule() ret->keepalive = jabber_keepalive; ret->send_typing = jabber_send_typing; ret->handle_cmp = g_strcasecmp; + ret->handle_is_self = jabber_handle_is_self; ret->transfer_request = jabber_si_transfer_request; ret->buddy_action_list = jabber_buddy_action_list; ret->buddy_action = jabber_buddy_action; diff --git a/protocols/jabber/jabber.h b/protocols/jabber/jabber.h index eb99f9ca..a5882767 100644 --- a/protocols/jabber/jabber.h +++ b/protocols/jabber/jabber.h @@ -96,6 +96,7 @@ struct jabber_data char *username; /* USERNAME@server */ char *server; /* username@SERVER -=> server/domain, not hostname */ char *me; /* bare jid */ + char *internal_jid; const struct oauth2_service *oauth2_service; char *oauth2_access_token; diff --git a/protocols/jabber/jabber_util.c b/protocols/jabber/jabber_util.c index d6396802..1a3d9fd4 100644 --- a/protocols/jabber/jabber_util.c +++ b/protocols/jabber/jabber_util.c @@ -823,6 +823,10 @@ gboolean jabber_set_me( struct im_connection *ic, const char *me ) jd->server = strchr( jd->me, '@' ); jd->username = g_strndup( jd->me, jd->server - jd->me ); jd->server ++; + + /* Set the "internal" account username, for groupchats */ + g_free( jd->internal_jid ); + jd->internal_jid = g_strdup( jd->me ); return TRUE; } diff --git a/protocols/nogaim.h b/protocols/nogaim.h index c236a0b5..d1711cde 100644 --- a/protocols/nogaim.h +++ b/protocols/nogaim.h @@ -262,6 +262,9 @@ struct prpl { GList *(* buddy_action_list) (struct bee_user *bu); void *(* buddy_action) (struct bee_user *bu, const char *action, char * const args[], void *data); + /* If null, equivalent to handle_cmp( ic->acc->user, who ) */ + gboolean (* handle_is_self) (struct im_connection *, const char *who); + /* Some placeholders so eventually older plugins may cooperate with newer BitlBees. */ void *resv1; void *resv2; |