diff options
| -rw-r--r-- | protocols/jabber/conference.c | 3 | ||||
| -rw-r--r-- | protocols/jabber/iq.c | 26 | ||||
| -rw-r--r-- | protocols/jabber/jabber.c | 11 | ||||
| -rw-r--r-- | protocols/jabber/jabber.h | 2 | ||||
| -rw-r--r-- | protocols/jabber/jabber_util.c | 18 | 
5 files changed, 48 insertions, 12 deletions
| diff --git a/protocols/jabber/conference.c b/protocols/jabber/conference.c index 0c2db0b3..74561d24 100644 --- a/protocols/jabber/conference.c +++ b/protocols/jabber/conference.c @@ -210,6 +210,7 @@ void jabber_chat_pkt_presence( struct im_connection *ic, struct jabber_buddy *bu  	struct groupchat *chat;  	struct xt_node *c;  	char *type = xt_find_attr( node, "type" ); +	struct jabber_data *jd = ic->proto_data;  	struct jabber_chat *jc;  	char *s; @@ -251,7 +252,7 @@ void jabber_chat_pkt_presence( struct im_connection *ic, struct jabber_buddy *bu  		{  			if( bud == jc->me )  			{ -				bud->ext_jid = jabber_normalize( ic->acc->user ); +				bud->ext_jid = g_strdup( jd->me );  			}  			else  			{ diff --git a/protocols/jabber/iq.c b/protocols/jabber/iq.c index 0c5671d0..2cdc681e 100644 --- a/protocols/jabber/iq.c +++ b/protocols/jabber/iq.c @@ -30,6 +30,7 @@ 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; @@ -169,10 +170,10 @@ xt_status jabber_pkt_iq( struct xt_node *node, gpointer data )  		/* This is a roster push. XMPP servers send this when someone  		   was added to (or removed from) the buddy list. AFAIK they're  		   sent even if we added this buddy in our own session. */ -			int bare_len = strlen( ic->acc->user ); +			int bare_len = strlen( jd->me );  			if( ( s = xt_find_attr( node, "from" ) ) == NULL || -			    ( strncmp( s, ic->acc->user, bare_len ) == 0 && +			    ( strncmp( s, jd->me, bare_len ) == 0 &&  			      ( s[bare_len] == 0 || s[bare_len] == '/' ) ) )  			{  				jabber_parse_roster( ic, node, NULL ); @@ -342,8 +343,25 @@ xt_status jabber_pkt_bind_sess( struct im_connection *ic, struct xt_node *node,  	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 ) +		if( !c || !c->text ) +		{ +			/* Server is crap, but this is no disaster. */ +		} +		else if( strncmp( jd->me, c->text, strlen( jd->me ) ) != 0 ) +		{ +			s = strchr( c->text, '/' ); +			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 = '/'; +		} +		else 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 );  	} diff --git a/protocols/jabber/jabber.c b/protocols/jabber/jabber.c index 50ee6f2d..f631a74e 100644 --- a/protocols/jabber/jabber.c +++ b/protocols/jabber/jabber.c @@ -110,8 +110,7 @@ static void jabber_login( account_t *acc )  	jd->ic = ic;  	ic->proto_data = jd; -	jd->username = g_strdup( acc->user ); -	jd->server = strchr( jd->username, '@' ); +	jabber_set_me( ic, acc->user );  	jd->fd = jd->r_inpa = jd->w_inpa = -1; @@ -122,10 +121,6 @@ static void jabber_login( account_t *acc )  		return;  	} -	/* So don't think of free()ing jd->server.. :-) */ -	*jd->server = 0; -	jd->server ++; -	  	if( ( s = strchr( jd->server, '/' ) ) )  	{  		*s = 0; @@ -313,6 +308,7 @@ static void jabber_logout( struct im_connection *ic )  	g_free( jd->oauth2_access_token );  	g_free( jd->away_message );  	g_free( jd->username ); +	g_free( jd->me );  	g_free( jd );  	jabber_connections = g_slist_remove( jabber_connections, ic ); @@ -494,11 +490,12 @@ static void jabber_chat_leave_( struct groupchat *c )  static void jabber_chat_invite_( struct groupchat *c, char *who, char *msg )  { +	struct jabber_data *jd = c->ic->proto_data;  	struct jabber_chat *jc = c->data;  	gchar *msg_alt = NULL;  	if( msg == NULL ) -		msg_alt = g_strdup_printf( "%s invited you to %s", c->ic->acc->user, jc->name ); +		msg_alt = g_strdup_printf( "%s invited you to %s", jd->me, jc->name );  	if( c && who )  		jabber_chat_invite( c, who, msg ? msg : msg_alt ); diff --git a/protocols/jabber/jabber.h b/protocols/jabber/jabber.h index 57f01695..85bcfafe 100644 --- a/protocols/jabber/jabber.h +++ b/protocols/jabber/jabber.h @@ -93,6 +93,7 @@ struct jabber_data  	char *username;		/* USERNAME@server */  	char *server;		/* username@SERVER -=> server/domain, not hostname */ +	char *me;		/* bare jid */  	const struct oauth2_service *oauth2_service;  	char *oauth2_access_token; @@ -307,6 +308,7 @@ void jabber_buddy_remove_all( struct im_connection *ic );  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 ); +gboolean jabber_set_me( struct im_connection *ic, const char *me );  extern const struct jabber_away_state jabber_away_state_list[]; diff --git a/protocols/jabber/jabber_util.c b/protocols/jabber/jabber_util.c index e6b13659..d181b904 100644 --- a/protocols/jabber/jabber_util.c +++ b/protocols/jabber/jabber_util.c @@ -760,3 +760,21 @@ void jabber_error_free( struct jabber_error *err )  {  	g_free( err );  } + +gboolean jabber_set_me( struct im_connection *ic, const char *me ) +{ +	struct jabber_data *jd = ic->proto_data; +	 +	if( strchr( me, '@' ) == NULL ) +		return FALSE; +	 +	g_free( jd->username ); +	g_free( jd->me ); +	 +	jd->me = jabber_normalize( me ); +	jd->server = strchr( jd->me, '@' ); +	jd->username = g_strndup( jd->me, jd->server - jd->me ); +	jd->server ++; +	 +	return TRUE; +} | 
