# HG changeset patch # User Tobias Markmann # Date 1215249779 0 # Node ID e61603ab10c635399a09d6670f14d369a91a5680 # Parent a85f9b85a7fb091371e22673806588d445a10abf * correctly calculating own features and factor in is_enabled() of features diff -r a85f9b85a7fb -r e61603ab10c6 libpurple/protocols/jabber/caps.c --- a/libpurple/protocols/jabber/caps.c Fri Jul 04 19:11:09 2008 +0000 +++ b/libpurple/protocols/jabber/caps.c Sat Jul 05 09:22:59 2008 +0000 @@ -444,7 +444,7 @@ // clean up return; } - + printf("\n\tfrom: %s", xmlnode_get_attrib(packet, "from")); printf("\n\tnode: %s", xmlnode_get_attrib(query, "node")); printf("\n\tcalculated key: %s", hash); @@ -532,12 +532,13 @@ key->node = (char *)node; key->ver = (char *)ver; + key->hash = (char*)hash; client = g_hash_table_lookup(capstable, key); g_free(key); -// if(!client) { + if(!client) { JabberIq *iq = jabber_iq_new_query(js,JABBER_IQ_GET,"http://jabber.org/protocol/disco#info"); xmlnode *query = xmlnode_get_child_with_namespace(iq->node,"query","http://jabber.org/protocol/disco#info"); char *nodever = g_strdup_printf("%s#%s", node, ver); @@ -547,6 +548,7 @@ jabber_iq_set_callback(iq,jabber_caps_client_iqcb,userdata); jabber_iq_send(iq); + } #if 0 } else { GList *iter; @@ -646,7 +648,6 @@ aformtype = jabber_caps_get_formtype(aformtypefield); - bformtype = jabber_caps_get_formtype(bformtypefield); result = strcmp(aformtype, bformtype); @@ -797,7 +798,7 @@ } g_list_free(fields); } - + /* generate hash */ context = purple_cipher_context_new_by_name(hash, NULL); if (context == NULL) { @@ -816,67 +817,41 @@ g_free(verification); verification = purple_base64_encode(checksum, checksum_size); - if (caps_hash != 0) g_free(caps_hash); return verification; } -void jabber_caps_calculate_own_hash() { - gchar *verification = 0; - gchar *free_verification; - gchar *identity_string, *feature_string; - GList *identities, *features; - PurpleCipherContext *context; - guint8 checksum[20]; - gsize checksum_size = 20; +void jabber_caps_calculate_own_hash(JabberStream *js) { + JabberCapsClientInfo *info; + GList *iter = 0; + GList *features = 0; /* sort identities */ - jabber_identities = g_list_sort(jabber_identities, jabber_caps_jabber_identity_compare); - - /* concat identities to the verification string */ - for(identities = jabber_identities; identities; identities = identities->next) { - JabberIdentity *ident = (JabberIdentity*)identities->data; - identity_string = g_strdup_printf("%s/%s//%s<", ident->category, ident->type, ident->name); - free_verification = verification; - if(verification == 0) verification = g_strdup(identity_string); - else verification = g_strconcat(verification, identity_string, NULL); - g_free(identity_string); - if(free_verification) g_free(free_verification); + if (jabber_identities == 0 && jabber_features == 0) return; + if (jabber_identities) { + for (iter = jabber_identities; iter; iter = iter->next) { + JabberIdentity *ident = iter->data; + } } /* sort features */ - jabber_features = g_list_sort(jabber_features, jabber_caps_jabber_feature_compare); - - /* concat features to the verification string */ - for(features = jabber_features; features; features = features->next) { - JabberFeature *feat = (JabberFeature*)features->data; - feature_string = g_strdup_printf("%s<", feat->namespace); - free_verification = verification; - if(verification == 0) g_strdup(feature_string); - else verification = g_strconcat(verification, feature_string, NULL); - g_free(feature_string); - if(free_verification) g_free(free_verification); - } + if (jabber_features) { + for (iter = jabber_features; iter; iter = iter->next) { + JabberFeature *feat = iter->data; + if(feat->is_enabled == NULL || feat->is_enabled(js, feat->namespace) == TRUE) { + features = g_list_append(features, feat->namespace); + } + } + } + + info = g_new0(JabberCapsClientInfo, 1); + info->features = features; + info->identities = jabber_identities; + info->forms = 0; - /* generate SHA-1 hash */ - context = purple_cipher_context_new_by_name("sha1", NULL); - if (context == NULL) { - purple_debug_error("jabber", "Could not find sha1 cipher\n"); - return; - } - purple_cipher_context_append(context, verification, strlen(verification)); - - if (!purple_cipher_context_digest(context, strlen(verification), checksum, &checksum_size)) { - purple_debug_error("util", "Failed to get SHA-1 digest.\n"); - } - purple_cipher_context_destroy(context); - - /* apply Base64 on hash */ - - g_free(verification); - verification = purple_base64_encode(checksum, checksum_size); // for 2.0 compability - - if (caps_hash != 0) g_free(caps_hash); - caps_hash = verification; + if (caps_hash) g_free(caps_hash); + caps_hash = jabber_caps_calcualte_hash(info, "sha1"); + g_free(info); + g_list_free(features); } const gchar* jabber_caps_get_own_hash() { diff -r a85f9b85a7fb -r e61603ab10c6 libpurple/protocols/jabber/libxmpp.c --- a/libpurple/protocols/jabber/libxmpp.c Fri Jul 04 19:11:09 2008 +0000 +++ b/libpurple/protocols/jabber/libxmpp.c Sat Jul 05 09:22:59 2008 +0000 @@ -259,9 +259,8 @@ jabber_iq_init(); jabber_pep_init(); - + jabber_caps_init(); jabber_tune_init(); - jabber_caps_init(); #warning implement adding and retrieving own features via IPC API diff -r a85f9b85a7fb -r e61603ab10c6 libpurple/protocols/jabber/presence.c --- a/libpurple/protocols/jabber/presence.c Fri Jul 04 19:11:09 2008 +0000 +++ b/libpurple/protocols/jabber/presence.c Sat Jul 05 09:22:59 2008 +0000 @@ -261,6 +261,9 @@ } /* JEP-0115 */ + /* calculate hash */ + jabber_caps_calculate_own_hash(js); + /* create xml */ c = xmlnode_new_child(presence, "c"); xmlnode_set_namespace(c, "http://jabber.org/protocol/caps"); xmlnode_set_attrib(c, "node", CAPS0115_NODE);