diff options
Diffstat (limited to 'protocols/jabber')
| -rw-r--r-- | protocols/jabber/jabber.c | 24 | ||||
| -rw-r--r-- | protocols/jabber/jabber.h | 2 | ||||
| -rw-r--r-- | protocols/jabber/jabber_util.c | 24 | 
3 files changed, 31 insertions, 19 deletions
| diff --git a/protocols/jabber/jabber.c b/protocols/jabber/jabber.c index 52a87d5d..c9c1d0a0 100644 --- a/protocols/jabber/jabber.c +++ b/protocols/jabber/jabber.c @@ -32,7 +32,6 @@  #include "bitlbee.h"  #include "jabber.h"  #include "md5.h" -#include "base64.h"  GSList *jabber_connections; @@ -240,24 +239,20 @@ static void jabber_login( account_t *acc )  	jabber_generate_id_hash( jd );  } +/* This generates an unfinished md5_state_t variable. Every time we generate +   an ID, we finish the state by adding a sequence number and take the hash. */  static void jabber_generate_id_hash( struct jabber_data *jd )  { -	md5_state_t id_hash; -	md5_byte_t binbuf[16]; +	md5_byte_t binbuf[4];  	char *s; -	md5_init( &id_hash ); -	md5_append( &id_hash, (unsigned char *) jd->username, strlen( jd->username ) ); -	md5_append( &id_hash, (unsigned char *) jd->server, strlen( jd->server ) ); +	md5_init( &jd->cached_id_prefix ); +	md5_append( &jd->cached_id_prefix, (unsigned char *) jd->username, strlen( jd->username ) ); +	md5_append( &jd->cached_id_prefix, (unsigned char *) jd->server, strlen( jd->server ) );  	s = set_getstr( &jd->ic->acc->set, "resource" ); -	md5_append( &id_hash, (unsigned char *) s, strlen( s ) ); -	random_bytes( binbuf, 16 ); -	md5_append( &id_hash, binbuf, 16 ); -	md5_finish( &id_hash, binbuf ); -	 -	s = base64_encode( binbuf, 9 ); -	jd->cached_id_prefix = g_strdup_printf( "%s%s", JABBER_CACHED_ID, s ); -	g_free( s ); +	md5_append( &jd->cached_id_prefix, (unsigned char *) s, strlen( s ) ); +	random_bytes( binbuf, 4 ); +	md5_append( &jd->cached_id_prefix, binbuf, 4 );  }  static void jabber_logout( struct im_connection *ic ) @@ -288,7 +283,6 @@ static void jabber_logout( struct im_connection *ic )  	xt_free( jd->xt ); -	g_free( jd->cached_id_prefix );  	g_free( jd->away_message );  	g_free( jd->username );  	g_free( jd ); diff --git a/protocols/jabber/jabber.h b/protocols/jabber/jabber.h index 023cf0f9..904bf0c4 100644 --- a/protocols/jabber/jabber.h +++ b/protocols/jabber/jabber.h @@ -85,7 +85,7 @@ struct jabber_data  	struct jabber_away_state *away_state;  	char *away_message; -	char *cached_id_prefix; +	md5_state_t cached_id_prefix;  	GHashTable *node_cache;  	GHashTable *buddies;  }; diff --git a/protocols/jabber/jabber_util.c b/protocols/jabber/jabber_util.c index 44dc5984..1bee5009 100644 --- a/protocols/jabber/jabber_util.c +++ b/protocols/jabber/jabber_util.c @@ -22,6 +22,8 @@  \***************************************************************************/  #include "jabber.h" +#include "md5.h" +#include "base64.h"  static unsigned int next_id = 1; @@ -133,11 +135,21 @@ void jabber_cache_add( struct im_connection *ic, struct xt_node *node, jabber_ca  {  	struct jabber_data *jd = ic->proto_data;  	struct jabber_cache_entry *entry = g_new0( struct jabber_cache_entry, 1 ); -	char *id; +	md5_state_t id_hash; +	md5_byte_t id_sum[16]; +	char *id, *asc_hash; -	id = g_strdup_printf( "%s%05x", jd->cached_id_prefix, ( next_id++ ) & 0xfffff ); +	next_id ++; +	 +	id_hash = jd->cached_id_prefix; +	md5_append( &id_hash, (md5_byte_t*) &next_id, sizeof( next_id ) ); +	md5_finish( &id_hash, id_sum ); +	asc_hash = base64_encode( id_sum, 12 ); +	 +	id = g_strdup_printf( "%s%s", JABBER_CACHED_ID, asc_hash );  	xt_add_attr( node, "id", id );  	g_free( id ); +	g_free( asc_hash );  	entry->node = node;  	entry->func = func; @@ -183,7 +195,7 @@ xt_status jabber_cache_handle_packet( struct im_connection *ic, struct xt_node *  	char *s;  	if( ( s = xt_find_attr( node, "id" ) ) == NULL || -	    strncmp( s, jd->cached_id_prefix, strlen( jd->cached_id_prefix ) ) != 0 ) +	    strncmp( s, JABBER_CACHED_ID, strlen( JABBER_CACHED_ID ) ) != 0 )  	{  		/* Silently ignore it, without an ID (or a non-cache  		   ID) we don't know how to handle the packet and we @@ -195,8 +207,14 @@ xt_status jabber_cache_handle_packet( struct im_connection *ic, struct xt_node *  	if( entry == NULL )  	{ +		/* +		There's no longer an easy way to see if we generated this +		one or someone else, and there's a ten-minute timeout anyway, +		so meh. +		  		imcb_log( ic, "Warning: Received %s-%s packet with unknown/expired ID %s!",  		              node->name, xt_find_attr( node, "type" ) ? : "(no type)", s ); +		*/  	}  	else if( entry->func )  	{ | 
