soc.2008.xmpp: 5ad56756: * changed name of jabber_caps_calculate_...
tfar at soc.pidgin.im
tfar at soc.pidgin.im
Sun Jun 22 15:17:35 EDT 2008
-----------------------------------------------------------------
Revision: 5ad56756716f6c7193dd37fe4cd1fffcdbe37cc8
Ancestor: 11fbf67ad3ffe9ffc3c549950d226662a1e315cf
Author: tfar at soc.pidgin.im
Date: 2008-06-22T17:25:23
Branch: im.pidgin.soc.2008.xmpp
URL: http://d.pidgin.im/viewmtn/revision/info/5ad56756716f6c7193dd37fe4cd1fffcdbe37cc8
Modified files:
libpurple/protocols/jabber/caps.c
libpurple/protocols/jabber/caps.h
libpurple/protocols/jabber/disco.c
libpurple/protocols/jabber/presence.c
ChangeLog:
* changed name of jabber_caps_calculate_hash() to jabber_caps_calculate_own_hash()
* added function which parses a query node to internal caps structure
-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/caps.c cd4966b0100aaf98589103883ad4c342e58ee949
+++ libpurple/protocols/jabber/caps.c 4283d149172d8b482aefa8058cd91a1a4cecf92a
@@ -114,7 +114,7 @@ void jabber_caps_init(void) {
void jabber_caps_init(void) {
capstable = g_hash_table_new_full(jabber_caps_hash, jabber_caps_compare, jabber_caps_destroy_key, jabber_caps_destroy_value);
jabber_caps_load();
- jabber_caps_calculate_hash();
+ jabber_caps_calculate_own_hash();
}
static void jabber_caps_load(void) {
@@ -448,6 +448,7 @@ static void jabber_caps_client_iqcb(Jabb
/* TODO: Better error checking! */
if (query) {
+
JabberCapsValue *value = g_new0(JabberCapsValue, 1);
JabberCapsKey *key = g_new0(JabberCapsKey, 1);
@@ -512,12 +513,12 @@ void jabber_caps_get_info(JabberStream *
key->node = (char *)node;
key->ver = (char *)ver;
-
+
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);
@@ -527,6 +528,7 @@ void jabber_caps_get_info(JabberStream *
jabber_iq_set_callback(iq,jabber_caps_client_iqcb,userdata);
jabber_iq_send(iq);
+#if 0
} else {
GList *iter;
/* fetch unknown exts only */
@@ -560,6 +562,7 @@ void jabber_caps_get_info(JabberStream *
/* maybe we have all data available anyways? This is the ideal case where no network traffic is necessary */
jabber_caps_get_info_check_completion(userdata);
}
+#endif
}
static gint jabber_caps_jabber_identity_compare(gconstpointer a, gconstpointer b) {
@@ -587,8 +590,50 @@ static gint jabber_caps_jabber_feature_c
return strcmp(ac->namespace, bc->namespace);
}
+JabberCapsClientInfo *jabber_caps_parse_client_info(xmlnode *query) {
+ xmlnode *child;
+
+ if (!query) return 0;
+ if (strcmp(query->xmlns,"http://jabber.org/protocol/disco#info")) return 0;
+
+ JabberCapsClientInfo *info = g_new0(JabberCapsClientInfo, 1);
+
+ for(child = query->child; child; child = child->next) {
+ if (!strcmp(child->name,"identity")) {
+ /* parse identity */
+ const char *category = xmlnode_get_attrib(child, "category");
+ const char *type = xmlnode_get_attrib(child, "type");
+ const char *name = xmlnode_get_attrib(child, "name");
-void jabber_caps_calculate_hash() {
+ JabberCapsIdentity *id = g_new0(JabberCapsIdentity, 1);
+ id->category = g_strdup(category);
+ id->type = g_strdup(type);
+ id->name = g_strdup(name);
+
+ info->identities = g_list_append(info->identities, id);
+ } else if (!strcmp(child->name, "feature")) {
+ /* parse feature */
+ const char *var = xmlnode_get_attrib(child, "var");
+ if(!var)
+ continue;
+ info->features = g_list_append(info->features, g_strdup(var));
+ } else if (!strcmp(child->name, "x")) {
+ if (!strcmp(child->xmlns, "jabber:x:data")) {
+ /* x-data form */
+ xmlnode *dataform = xmlnode_copy(child);
+ info->forms = g_list_append(info->forms, dataform);
+ }
+ }
+ }
+ return info;
+}
+
+gchar *jabber_caps_calcualte_hash(JabberCapsClientInfo *info) {
+ if (!info) return 0;
+
+}
+
+void jabber_caps_calculate_own_hash() {
gchar *verification = 0;
gchar *free_verification;
gchar *identity_string, *feature_string;
@@ -650,7 +695,7 @@ void jabber_caps_calculate_hash() {
caps_hash = verification;
}
-const gchar* jabber_caps_get_hash() {
+const gchar* jabber_caps_get_own_hash() {
return caps_hash;
}
============================================================
--- libpurple/protocols/jabber/caps.h 108ac08b4fb4e733d7b53796e588a94251b02def
+++ libpurple/protocols/jabber/caps.h 2a972dbeb85d600bbda754a9a480debaaa3458d5
@@ -32,11 +32,13 @@ typedef struct _JabberCapsIdentity {
char *category;
char *type;
char *name;
+ char *lang;
} JabberCapsIdentity;
struct _JabberCapsClientInfo {
GList *identities; /* JabberCapsIdentity */
GList *features; /* char * */
+ GList *forms; /* xmlnode * */
};
typedef void (*jabber_caps_get_info_cb)(JabberCapsClientInfo *info, gpointer user_data);
@@ -46,12 +48,29 @@ void jabber_caps_free_clientinfo(JabberC
void jabber_caps_get_info(JabberStream *js, const char *who, const char *node, const char *ver, const char *ext, jabber_caps_get_info_cb cb, gpointer user_data);
void jabber_caps_free_clientinfo(JabberCapsClientInfo *clientinfo);
+/**
+ * Processes a query-node and returns a JabberCapsClientInfo object with all relevant info.
+ *
+ * @param query A query object.
+ * @return A JabberCapsClientInfo object.
+ */
+JabberCapsClientInfo *jabber_caps_parse_client_info(xmlnode *query);
-void jabber_caps_calculate_hash();
+/**
+ * Takes a JabberCapsClientInfo pointer and returns the caps hash according to
+ * XEP-0115 Version 1.5.
+ *
+ * @param info A JabberCapsClientInfo pointer.
+ * @return The base64 encoded SHA-1 hash; needs to be freed if not needed
+ * any furthermore.
+ */
+gchar *jabber_caps_calcualte_hash(JabberCapsClientInfo *info);
+void jabber_caps_calculate_own_hash();
+
/** Get the current caps hash.
* @ret hash
**/
-const gchar* jabber_caps_get_hash();
+const gchar* jabber_caps_get_own_hash();
#endif /* _PURPLE_JABBER_CAPS_H_ */
============================================================
--- libpurple/protocols/jabber/disco.c 9ed292e7e5bd84c7faf85c8e850164773b60ea85
+++ libpurple/protocols/jabber/disco.c d0bb79fe55c274bfe5af8ba79926bdbe1fdad904
@@ -91,7 +91,7 @@ void jabber_disco_info_parse(JabberStrea
const char *node_uri = NULL;
// create custom caps node URI
- node_uri = g_strconcat(CAPS0115_NODE, "#", jabber_caps_get_hash(), NULL);
+ node_uri = g_strconcat(CAPS0115_NODE, "#", jabber_caps_get_own_hash(), NULL);
if((in_query = xmlnode_get_child(packet, "query"))) {
node = xmlnode_get_attrib(in_query, "node");
============================================================
--- libpurple/protocols/jabber/presence.c 8153fc3bf0331f9de06b3c7940c1259485f4268b
+++ libpurple/protocols/jabber/presence.c 11c8ee00154a052f6c876f46bf3910aa38a8e0cb
@@ -265,7 +265,7 @@ xmlnode *jabber_presence_create_js(Jabbe
xmlnode_set_namespace(c, "http://jabber.org/protocol/caps");
xmlnode_set_attrib(c, "node", CAPS0115_NODE);
xmlnode_set_attrib(c, "hash", "sha-1");
- xmlnode_set_attrib(c, "ver", jabber_caps_get_hash());
+ xmlnode_set_attrib(c, "ver", jabber_caps_get_own_hash());
#if 0
if(js != NULL) {
More information about the Commits
mailing list