diff options
| -rw-r--r-- | protocols/jabber/iq.c | 34 | ||||
| -rw-r--r-- | protocols/jabber/jabber.h | 9 | ||||
| -rw-r--r-- | protocols/jabber/jabber_util.c | 19 | 
3 files changed, 49 insertions, 13 deletions
| diff --git a/protocols/jabber/iq.c b/protocols/jabber/iq.c index 8864e3fd..446a25bb 100644 --- a/protocols/jabber/iq.c +++ b/protocols/jabber/iq.c @@ -44,11 +44,12 @@ xt_status jabber_pkt_iq( struct xt_node *node, gpointer data )  	{  		struct jabber_cache_entry *entry; -		if( ( s = xt_find_attr( node, "id" ) ) == NULL ) +		if( ( s = xt_find_attr( node, "id" ) ) == NULL || +		    strncmp( s, JABBER_CACHED_ID, strlen( JABBER_CACHED_ID ) ) != 0 )  		{ -			/* Silently ignore it, without an ID we don't know -			   how to handle the packet, but it doesn't have -			   to be a serious problem. */ +			/* Silently ignore it, without an ID (or an non-cache +			   ID) we don't know how to handle the packet and we +			   probably don't have to. */  			return XT_HANDLED;  		} @@ -64,7 +65,7 @@ xt_status jabber_pkt_iq( struct xt_node *node, gpointer data )  		if( !( c = xt_find_node( node->children, "query" ) ) ||  		    !( s = xt_find_attr( c, "xmlns" ) ) )  		{ -			serv_got_crap( gc, "WARNING: Received incomplete IQ-get packet" ); +			serv_got_crap( gc, "WARNING: Received incomplete IQ-%s packet", type );  			return XT_HANDLED;  		} @@ -124,9 +125,26 @@ xt_status jabber_pkt_iq( struct xt_node *node, gpointer data )  	}  	else if( strcmp( type, "set" ) == 0 )  	{ -		xt_free_node( reply ); -		reply = jabber_make_error_packet( node, "feature-not-implemented", "cancel" ); -		pack = 0; +		if( !( c = xt_find_node( node->children, "query" ) ) || +		    !( s = xt_find_attr( c, "xmlns" ) ) ) +		{ +			serv_got_crap( gc, "WARNING: Received incomplete IQ-%s packet", type ); +			return XT_HANDLED; +		} +		 +		if( strcmp( s, "jabber:iq:roster" ) == 0 ) +		{ +			/* This is a roster push packet, probably. Here we +			   should check if the packet is legitimate by +			   checking if it really comes from the user's JID +			   and, if so, process it. */ +		} +		else +		{ +			xt_free_node( reply ); +			reply = jabber_make_error_packet( node, "feature-not-implemented", "cancel" ); +			pack = 0; +		}  	}  	/* If we recognized the xmlns and managed to generate a reply, diff --git a/protocols/jabber/jabber.h b/protocols/jabber/jabber.h index cd65d374..4bccd5ed 100644 --- a/protocols/jabber/jabber.h +++ b/protocols/jabber/jabber.h @@ -101,11 +101,18 @@ struct jabber_buddy  	char *away_message;  	time_t last_act; -	int flags; +	jabber_buddy_flag_t flags;  	struct jabber_buddy *next;  }; +/* Prefixes to use for packet IDs (mainly for IQ packets ATM). Usually the +   first one should be used, but when storing a packet in the cache, a +   "special" kind of ID is assigned to make it easier later to figure out +   if we have to do call an event handler for the response packet. */ +#define JABBER_PACKET_ID "BeeP" +#define JABBER_CACHED_ID "BeeC" +  /* iq.c */  xt_status jabber_pkt_iq( struct xt_node *node, gpointer data );  int jabber_init_iq_auth( struct gaim_connection *gc ); diff --git a/protocols/jabber/jabber_util.c b/protocols/jabber/jabber_util.c index d5d038cf..3f189300 100644 --- a/protocols/jabber/jabber_util.c +++ b/protocols/jabber/jabber_util.c @@ -23,7 +23,7 @@  #include "jabber.h" -static int next_id = 1; +static unsigned int next_id = 1;  char *set_eval_priority( set_t *set, char *value )  { @@ -82,6 +82,17 @@ struct xt_node *jabber_make_packet( char *name, char *type, char *to, struct xt_  	if( to )  		xt_add_attr( node, "to", to ); +	/* IQ packets should always have an ID, so let's generate one. It +	   might get overwritten by jabber_cache_add() if this packet has +	   to be saved until we receive a response. Cached packets get +	   slightly different IDs so we can recognize them. */ +	if( strcmp( name, "iq" ) == 0 ) +	{ +		char *id = g_strdup_printf( "%s%05x", JABBER_PACKET_ID, ( next_id++ ) & 0xfffff ); +		xt_add_attr( node, "id", id ); +		g_free( id ); +	} +	  	return node;  } @@ -115,13 +126,13 @@ struct xt_node *jabber_make_error_packet( struct xt_node *orig, char *err_cond,  	return node;  } -/* Cache a node/epacket for later use. Mainly useful for IQ packets if you need +/* Cache a node/packet for later use. Mainly useful for IQ packets if you need     them when you receive the response. Use this BEFORE sending the packet so -   it'll get an id= tag, and do NOT free() the packet after writing it! */ +   it'll get a new id= tag, and do NOT free() the packet after writing it! */  void jabber_cache_add( struct gaim_connection *gc, struct xt_node *node, jabber_cache_event func )  {  	struct jabber_data *jd = gc->proto_data; -	char *id = g_strdup_printf( "BeeX%04x", next_id++ ); +	char *id = g_strdup_printf( "%s%05x", JABBER_CACHED_ID, ( next_id++ ) & 0xfffff );  	struct jabber_cache_entry *entry = g_new0( struct jabber_cache_entry, 1 );  	xt_add_attr( node, "id", id ); | 
