aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--protocols/jabber/iq.c2
-rw-r--r--protocols/jabber/jabber.c28
-rw-r--r--protocols/jabber/jabber.h5
-rw-r--r--protocols/jabber/jabber_util.c3
4 files changed, 35 insertions, 3 deletions
diff --git a/protocols/jabber/iq.c b/protocols/jabber/iq.c
index 40897639..595718fb 100644
--- a/protocols/jabber/iq.c
+++ b/protocols/jabber/iq.c
@@ -49,7 +49,7 @@ xt_status jabber_pkt_iq( struct xt_node *node, gpointer data )
struct jabber_cache_entry *entry;
if( ( s = xt_find_attr( node, "id" ) ) == NULL ||
- strncmp( s, JABBER_CACHED_ID, strlen( JABBER_CACHED_ID ) ) != 0 )
+ strncmp( s, jd->cached_id_prefix, strlen( jd->cached_id_prefix ) ) != 0 )
{
/* Silently ignore it, without an ID (or a non-cache
ID) we don't know how to handle the packet and we
diff --git a/protocols/jabber/jabber.c b/protocols/jabber/jabber.c
index e7be63fd..b0651a59 100644
--- a/protocols/jabber/jabber.c
+++ b/protocols/jabber/jabber.c
@@ -31,6 +31,8 @@
#include "xmltree.h"
#include "bitlbee.h"
#include "jabber.h"
+#include "md5.h"
+#include "base64.h"
static void jabber_init( account_t *acc )
{
@@ -59,6 +61,8 @@ static void jabber_init( account_t *acc )
s->flags |= ACC_SET_OFFLINE_ONLY;
}
+static void jabber_generate_id_hash( struct jabber_data *jd );
+
static void jabber_login( account_t *acc )
{
struct im_connection *ic = imcb_new( acc );
@@ -199,6 +203,30 @@ static void jabber_login( account_t *acc )
I think this shouldn't break anything. */
imcb_add_buddy( ic, JABBER_XMLCONSOLE_HANDLE, NULL );
}
+
+ jabber_generate_id_hash( jd );
+}
+
+static void jabber_generate_id_hash( struct jabber_data *jd )
+{
+ md5_state_t id_hash;
+ md5_byte_t binbuf[16];
+ 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 ) );
+ 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 );
+
+ printf( "%s\n", jd->cached_id_prefix );
}
static void jabber_logout( struct im_connection *ic )
diff --git a/protocols/jabber/jabber.h b/protocols/jabber/jabber.h
index e26c3899..fc9d2fc4 100644
--- a/protocols/jabber/jabber.h
+++ b/protocols/jabber/jabber.h
@@ -77,6 +77,7 @@ struct jabber_data
struct jabber_away_state *away_state;
char *away_message;
+ char *cached_id_prefix;
GHashTable *node_cache;
GHashTable *buddies;
};
@@ -131,7 +132,9 @@ struct jabber_chat
/* 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. */
+ if we have to do call an event handler for the response packet. Also
+ we'll append a hash to make sure we won't trigger on cached packets from
+ other BitlBee users. :-) */
#define JABBER_PACKET_ID "BeeP"
#define JABBER_CACHED_ID "BeeC"
diff --git a/protocols/jabber/jabber_util.c b/protocols/jabber/jabber_util.c
index 56491c4f..43b91fe3 100644
--- a/protocols/jabber/jabber_util.c
+++ b/protocols/jabber/jabber_util.c
@@ -132,9 +132,10 @@ struct xt_node *jabber_make_error_packet( struct xt_node *orig, char *err_cond,
void jabber_cache_add( struct im_connection *ic, struct xt_node *node, jabber_cache_event func )
{
struct jabber_data *jd = ic->proto_data;
- 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 );
+ char *id;
+ id = g_strdup_printf( "%s%05x", jd->cached_id_prefix, ( next_id++ ) & 0xfffff );
xt_add_attr( node, "id", id );
g_free( id );