diff libpurple/protocols/jabber/pep.c @ 26987:cd78ea46e9bd

merge of '7c614b09b72037ebd86c03fbbeac7794a155547b' and 'af18689b86389686230fc6ce83cbba52690ce0cb'
author Paul Aurich <paul@darkrain42.org>
date Sat, 30 May 2009 00:32:50 +0000
parents 1dfa009f6db5
children 8c991e09efcb
line wrap: on
line diff
--- a/libpurple/protocols/jabber/pep.c	Sat May 30 00:21:37 2009 +0000
+++ b/libpurple/protocols/jabber/pep.c	Sat May 30 00:32:50 2009 +0000
@@ -24,8 +24,10 @@
 #include "pep.h"
 #include "iq.h"
 #include <string.h>
+#include "useravatar.h"
 #include "usermood.h"
 #include "usernick.h"
+#include "usertune.h"
 
 static GHashTable *pep_handlers = NULL;
 
@@ -34,20 +36,31 @@
 		pep_handlers = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
 
 		/* register PEP handlers */
+		jabber_avatar_init();
 		jabber_mood_init();
+		jabber_tune_init();
 		jabber_nick_init();
 	}
 }
 
+void jabber_pep_uninit(void) {
+	/* any PEP handlers that need to clean things up go here. The standard
+	 * cleanup of removing the handler and feature are handled here and by
+	 * jabber_features_destroy() in jabber.c
+	 */
+	g_hash_table_destroy(pep_handlers);
+	pep_handlers = NULL;
+}
+
 void jabber_pep_init_actions(GList **m) {
 	/* register the PEP-specific actions */
 	jabber_mood_init_action(m);
 	jabber_nick_init_action(m);
 }
 
-void jabber_pep_register_handler(const char *shortname, const char *xmlns, JabberPEPHandler handlerfunc) {
+void jabber_pep_register_handler(const char *xmlns, JabberPEPHandler handlerfunc) {
 	gchar *notifyns = g_strdup_printf("%s+notify", xmlns);
-	jabber_add_feature(shortname, notifyns, NULL); /* receiving PEPs is always supported */
+	jabber_add_feature(notifyns, NULL); /* receiving PEPs is always supported */
 	g_free(notifyns);
 	g_hash_table_replace(pep_handlers, g_strdup(xmlns), handlerfunc);
 }
@@ -57,12 +70,15 @@
                                 JabberIqType type, const char *id,
                                 xmlnode *packet, gpointer data)
 {
-	xmlnode *pubsub = xmlnode_get_child_with_namespace(packet,"pubsub","http://jabber.org/protocol/pubsub");
+	xmlnode *pubsub;
 	xmlnode *items = NULL;
 	JabberPEPHandler *cb = data;
 
-	if(pubsub)
-		items = xmlnode_get_child(pubsub, "items");
+	if (type == JABBER_IQ_RESULT) {
+		pubsub = xmlnode_get_child_with_namespace(packet, "pubsub", "http://jabber.org/protocol/pubsub");
+		if(pubsub)
+			items = xmlnode_get_child(pubsub, "items");
+	}
 
 	cb(js, from, items);
 }
@@ -88,7 +104,7 @@
 	jabber_iq_send(iq);
 }
 
-gboolean jabber_pep_namespace_only_when_pep_enabled_cb(JabberStream *js, const gchar *shortname, const gchar *namespace) {
+gboolean jabber_pep_namespace_only_when_pep_enabled_cb(JabberStream *js, const gchar *namespace) {
 	return js->pep;
 }
 
@@ -96,7 +112,12 @@
 	/* this may be called even when the own server doesn't support pep! */
 	JabberPEPHandler *jph;
 	GList *itemslist;
-	char *jid = jabber_get_bare_jid(jm->from);
+	char *jid;
+
+	if (jm->type != JABBER_MESSAGE_EVENT)
+		return;
+
+	jid = jabber_get_bare_jid(jm->from);
 
 	for(itemslist = jm->eventitems; itemslist; itemslist = itemslist->next) {
 		xmlnode *items = (xmlnode*)itemslist->data;
@@ -110,6 +131,25 @@
 	g_free(jid);
 }
 
+void jabber_pep_delete_node(JabberStream *js, const gchar *node)
+{
+	JabberIq *iq;
+	xmlnode *pubsub, *del;
+
+	g_return_if_fail(node != NULL);
+	g_return_if_fail(js->pep);
+
+	iq = jabber_iq_new(js, JABBER_IQ_SET);
+
+	pubsub = xmlnode_new_child(iq->node, "pubsub");
+	xmlnode_set_namespace(pubsub, "http://jabber.org/protocol/pubsub#owner");
+
+	del = xmlnode_new_child(pubsub, "delete");
+	xmlnode_set_attrib(del, "node", node);
+
+	jabber_iq_send(iq);
+}
+
 void jabber_pep_publish(JabberStream *js, xmlnode *publish) {
 	JabberIq *iq;
 	xmlnode *pubsub;