pidgin: 7e1e376d: jabber: Cache incoming BoB object per JI...
malu at pidgin.im
malu at pidgin.im
Tue Mar 23 19:31:06 EDT 2010
-----------------------------------------------------------------
Revision: 7e1e376dfb1d794f80c1f29679e3e899208bd856
Ancestor: 4bc08b46766e0e90fc3cffefe00104882456b92f
Author: malu at pidgin.im
Date: 2010-03-23T22:17:34
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/7e1e376dfb1d794f80c1f29679e3e899208bd856
Modified files:
ChangeLog libpurple/protocols/jabber/data.c
libpurple/protocols/jabber/data.h
libpurple/protocols/jabber/message.c
ChangeLog:
jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
them when receiving an invalid or unrecognised hash. As per the MUC discussions.
-------------- next part --------------
============================================================
--- ChangeLog 567d7486ed772bb04e236a4eae697723b4eb2600
+++ ChangeLog 8ee601070a86d0956c036c717f63a28383b957e3
@@ -55,7 +55,9 @@ version 2.7.0 (??/??/????):
rjoly for testing)
* When sending data using in-band-bytestreams, interpret the block-size
attribute as the size of the BASE64-encoded representation of the data.
- * Validate the hash on incoming BoB data objects (for custom smileys etc.).
+ * Validate the hash on incoming BoB data objects (for custom smileys etc.),
+ cache based per JID when the CID is not a valid hash (as specified by the
+ BoB XEP).
Yahoo:
* Attempt to better handle transparent proxies interfering with HTTP-based
============================================================
--- libpurple/protocols/jabber/data.c 7c0bcd707f0753a62747ede29c95e53ca6eddaa5
+++ libpurple/protocols/jabber/data.c 336ba1a3ed3d29f33240b9fd5a75b45a3bdb08bb
@@ -54,58 +54,6 @@ jabber_data_create_from_data(gconstpoint
return data;
}
-
-static gboolean
-jabber_data_has_valid_hash(const JabberData *data)
-{
- const gchar *cid = jabber_data_get_cid(data);
- gchar **cid_parts = g_strsplit(cid, "@", -1);
- gchar **iter;
- int num_parts = 0;
-
- purple_debug_info("jabber", "validating BoB hash %s\n", cid);
-
- for (iter = cid_parts; *iter != NULL ; iter++) {
- num_parts++;
- }
-
- if (num_parts == 2 && purple_strequal(cid_parts[1], "bob.xmpp.org")) {
- gchar **sub_parts = g_strsplit(cid_parts[0], "+", -1);
-
- num_parts = 0;
- for (iter = sub_parts ; *iter != NULL ; iter++) {
- num_parts++;
- }
-
- if (num_parts == 2) {
- const gchar *hash_algo = sub_parts[0];
- const gchar *hash_value = sub_parts[1];
- gchar *digest =
- jabber_calculate_data_hash(jabber_data_get_data(data),
- jabber_data_get_size(data), hash_algo);
-
- purple_debug_info("jabber", "BoB expecting hash: %s\n", digest);
-
- if (digest) {
- gboolean result = purple_strequal(digest, hash_value);
-
- if (!result) {
- purple_debug_error("jabber", "invalid BoB hash\n");
- }
- g_free(digest);
- return result;
- } else {
- purple_debug_info("jabber", "unknown BoB hash algo\n");
- return FALSE;
- }
- } else {
- return TRUE;
- }
- } else {
- return TRUE;
- }
-}
-
static void
jabber_data_delete(gpointer cbdata)
{
@@ -159,11 +107,6 @@ jabber_data_create_from_xml(xmlnode *tag
data->cid = g_strdup(cid);
data->type = g_strdup(type);
- if (!jabber_data_has_valid_hash(data)) {
- jabber_data_delete(data);
- return NULL;
- }
-
return data;
}
@@ -233,7 +176,58 @@ jabber_data_get_xml_request(const gchar
return tag;
}
+static gboolean
+jabber_data_has_valid_hash(const JabberData *data)
+{
+ const gchar *cid = jabber_data_get_cid(data);
+ gchar **cid_parts = g_strsplit(cid, "@", -1);
+ gchar **iter;
+ int num_parts = 0;
+ purple_debug_info("jabber", "validating BoB hash %s\n", cid);
+
+ for (iter = cid_parts; *iter != NULL ; iter++) {
+ num_parts++;
+ }
+
+ if (num_parts == 2 && purple_strequal(cid_parts[1], "bob.xmpp.org")) {
+ gchar **sub_parts = g_strsplit(cid_parts[0], "+", -1);
+
+ num_parts = 0;
+ for (iter = sub_parts ; *iter != NULL ; iter++) {
+ num_parts++;
+ }
+
+ if (num_parts == 2) {
+ const gchar *hash_algo = sub_parts[0];
+ const gchar *hash_value = sub_parts[1];
+ gchar *digest =
+ jabber_calculate_data_hash(jabber_data_get_data(data),
+ jabber_data_get_size(data), hash_algo);
+
+ if (digest) {
+ gboolean result = purple_strequal(digest, hash_value);
+
+ purple_debug_info("jabber", "BoB expecting hash: %s\n", digest);
+
+ if (!result) {
+ purple_debug_error("jabber", "invalid BoB hash\n");
+ }
+ g_free(digest);
+ return result;
+ } else {
+ purple_debug_info("jabber", "unknown BoB hash algo\n");
+ return FALSE;
+ }
+ } else {
+ return FALSE;
+ }
+ } else {
+ return FALSE;
+ }
+}
+
+
typedef struct {
gpointer userdata;
gchar *alt;
@@ -258,17 +252,10 @@ jabber_data_request_cb(JabberStream *js,
if (data_element && type == JABBER_IQ_RESULT) {
JabberData *data = jabber_data_create_from_xml(data_element);
- if (data) {
- if (!ephemeral) {
- jabber_data_associate_remote(data);
- }
- cb(data, alt, userdata);
- } else {
- /* could not validate hash when creating data from XML */
- purple_debug_info("jabber",
- "hash validation failed on requested BoB object\n");
- cb(NULL, alt, userdata);
+ if (!ephemeral) {
+ jabber_data_associate_remote(js, from, data);
}
+ cb(data, alt, userdata);
} else if (item_not_found) {
purple_debug_info("jabber",
"Responder didn't recognize requested data\n");
@@ -316,11 +303,23 @@ const JabberData *
}
const JabberData *
-jabber_data_find_remote_by_cid(const gchar *cid)
+jabber_data_find_remote_by_cid(JabberStream *js, const gchar *who,
+ const gchar *cid)
{
+ const JabberData *data = g_hash_table_lookup(remote_data_by_cid, cid);
purple_debug_info("jabber", "lookup remote smiley with cid = %s\n", cid);
- return g_hash_table_lookup(remote_data_by_cid, cid);
+ if (data == NULL) {
+ gchar *jid_cid =
+ g_strdup_printf("%s@%s/%s%s%s", js->user->node, js->user->domain,
+ js->user->resource, who, cid);
+ purple_debug_info("jabber",
+ "didn't find BoB object by pure CID, try including JIDs: %s\n",
+ jid_cid);
+ data = g_hash_table_lookup(remote_data_by_cid, jid_cid);
+ g_free(jid_cid);
+ }
+ return data;
}
void
@@ -334,12 +333,21 @@ void
}
void
-jabber_data_associate_remote(JabberData *data)
+jabber_data_associate_remote(JabberStream *js, const gchar *who, JabberData *data)
{
- purple_debug_info("jabber", "associating remote smiley, cid = %s\n",
- jabber_data_get_cid(data));
- g_hash_table_insert(remote_data_by_cid, g_strdup(jabber_data_get_cid(data)),
- data);
+ gchar *cid;
+
+ if (jabber_data_has_valid_hash(data)) {
+ cid = g_strdup(jabber_data_get_cid(data));
+ } else {
+ cid = g_strdup_printf("%s@%s/%s%s%s", js->user->node, js->user->domain,
+ js->user->resource, who, jabber_data_get_cid(data));
+ }
+
+ purple_debug_info("jabber", "associating remote BoB object with cid = %s\n",
+ cid);
+
+ g_hash_table_insert(remote_data_by_cid, cid, data);
}
void
============================================================
--- libpurple/protocols/jabber/data.h 2eac9027496d99898c4382fa297a495c2e079791
+++ libpurple/protocols/jabber/data.h 456587544974d910f52a707f8ecf73bef80856ea
@@ -67,11 +67,13 @@ const JabberData *jabber_data_find_local
/* lookup functions */
const JabberData *jabber_data_find_local_by_alt(const gchar *alt);
const JabberData *jabber_data_find_local_by_cid(const gchar *cid);
-const JabberData *jabber_data_find_remote_by_cid(const gchar *cid);
+const JabberData *jabber_data_find_remote_by_cid(JabberStream *js,
+ const gchar *who, const gchar *cid);
/* store data objects */
void jabber_data_associate_local(JabberData *data, const gchar *alt);
-void jabber_data_associate_remote(JabberData *data);
+void jabber_data_associate_remote(JabberStream *js, const gchar *who,
+ JabberData *data);
/* handles iq requests */
void jabber_data_parse(JabberStream *js, const char *who, JabberIqType type,
============================================================
--- libpurple/protocols/jabber/message.c 4caeee14cbf11de04d3ff9565774b9581127f44f
+++ libpurple/protocols/jabber/message.c 44e1acf62aea2def28ce0c1047c25df63ec9698d
@@ -462,21 +462,22 @@ static void
}
static void
-jabber_message_add_remote_smileys(const xmlnode *message)
+jabber_message_add_remote_smileys(JabberStream *js, const gchar *who,
+ const xmlnode *message)
{
xmlnode *data_tag;
for (data_tag = xmlnode_get_child_with_namespace(message, "data", NS_BOB) ;
data_tag ;
data_tag = xmlnode_get_next_twin(data_tag)) {
const gchar *cid = xmlnode_get_attrib(data_tag, "cid");
- const JabberData *data = jabber_data_find_remote_by_cid(cid);
+ const JabberData *data = jabber_data_find_remote_by_cid(js, who, cid);
if (!data && cid != NULL) {
/* we haven't cached this already, let's add it */
JabberData *new_data = jabber_data_create_from_xml(data_tag);
if (new_data) {
- jabber_data_associate_remote(new_data);
+ jabber_data_associate_remote(js, who, new_data);
}
}
}
@@ -634,7 +635,7 @@ void jabber_message_parse(JabberStream *
}
/* process any newly provided smileys */
- jabber_message_add_remote_smileys(packet);
+ jabber_message_add_remote_smileys(js, to, packet);
}
/* reformat xhtml so that img tags with a "cid:" src gets
@@ -660,7 +661,7 @@ void jabber_message_parse(JabberStream *
if (purple_conv_custom_smiley_add(conv, alt, "cid", cid,
TRUE)) {
const JabberData *data =
- jabber_data_find_remote_by_cid(cid);
+ jabber_data_find_remote_by_cid(js, from, cid);
/* if data is already known, we write it immediatly */
if (data) {
purple_debug_info("jabber",
More information about the Commits
mailing list