--- a/pep.c Mon Nov 02 05:00:21 2009 +0200
+++ b/pep.c Mon Nov 02 19:23:35 2009 +0200
@@ -25,7 +25,6 @@
#include <strings.h>
#include "xmpp.h"
-#include "xmpp_defines.h"
#include "hooks.h"
#include "pep.h"
@@ -33,14 +32,13 @@
static LmMessageHandler *pep_message_handler = NULL;
-static GSList *pep_reply_handlers = NULL;
-
static pep_handler_t *pep_find_handler (const gchar *xmlns)
{
GSList *hel;
for (hel = pep_xmlns_handlers; hel; hel = hel->next) {
pep_handler_t *handler = (pep_handler_t *) hel->data;
+
if (!strcmp (handler->xmlns, xmlns))
return handler;
}
@@ -52,31 +50,38 @@
{ // it is MESSAGE!
LmMessageNode *m = lm_message_get_node (message);
- LmMessageNode *event = lm_message_node_get_child (m, "event");
- if (!event)
+ LmMessageNode *node = lm_message_node_get_child (m, "event");
+ if (!node)
return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
- const gchar *xmlns = lm_message_node_get_attribute (event, "xmlns");
- if (strcmp (xmlns, NS_PUBSUB_EVENT))
- return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
+ {
+ const gchar *xmlns = lm_message_node_get_attribute (node, "xmlns");
+ if (strcmp (xmlns, NS_PUBSUB_EVENT))
+ return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
+ }
- LmMessageNode *items = lm_message_node_get_child (event, "items");
- if (!items)
+ node = lm_message_node_get_child (node, "items");
+ if (!node)
return LM_HANDLER_RESULT_REMOVE_MESSAGE; // XXX
- const gchar *from = lm_message_node_get_attribute (m, "from");
- const gchar *node = lm_message_node_get_attribute (items, "node");
+ {
+ LmMessageNode *item;
+ const gchar *from = lm_message_node_get_attribute (m, "from");
+ const gchar *inode = lm_message_node_get_attribute (node, "node");
+
+ for (item = node->children; item; item = item->next) {
+ const gchar *id = lm_message_node_get_attribute (item, "id");
+ LmMessageNode *n;
- LmMessageNode *item;
- for (item = items->children; item; item = item->next) {
- const gchar *id = lm_message_node_get_attribute (item, "id");
- LmMessageNode *n;
- for (n = item->children; n; n = n->next) {
- const gchar *xmlns = lm_message_node_get_attribute (n, "xmlns");
- if (xmlns) {
- pep_handler_t *handler = pep_find_handler (xmlns);
- if (handler)
- handler->handler (from, node, n, id, handler->data);
+ for (n = item->children; n; n = n->next) {
+ const gchar *xmlns = lm_message_node_get_attribute (n, "xmlns");
+
+ if (xmlns) {
+ pep_handler_t *handler = pep_find_handler (xmlns);
+
+ if (handler)
+ handler->handler (from, inode, n, id, handler->data);
+ }
}
}
}
@@ -113,27 +118,16 @@
{
if (!pep_message_handler)
pep_message_handler = lm_message_handler_new (pep_handler, NULL, NULL);
+ else if (lconnection) // XXX
+ lm_connection_unregister_message_handler (lconnection, pep_message_handler, LM_MESSAGE_TYPE_MESSAGE);
if (lconnection) // XXX
lm_connection_register_message_handler (lconnection, pep_message_handler, LM_MESSAGE_TYPE_MESSAGE, LM_HANDLER_PRIORITY_FIRST);
}
static void pep_unregister_handlers (void)
{
- GSList *hel;
-
- if (lconnection) { // XXX more checks?
- // let's hope, that after invalidation, lm will remove and free unreffed by us handler
- for (hel = pep_reply_handlers; hel; hel = hel->next) {
- LmMessageHandler *handler = (LmMessageHandler *) hel->data;
- lm_message_handler_invalidate (handler);
- }
- }
-
- g_slist_free (pep_reply_handlers);
- pep_reply_handlers = NULL;
-
if (pep_message_handler)
- lm_connection_unregister_handler (lconnection, pep_message_handler);
+ lm_connection_unregister_message_handler (lconnection, pep_message_handler, LM_MESSAGE_TYPE_MESSAGE);
}
// release handlers before reconnect
@@ -154,8 +148,6 @@
const gchar *g_module_check_init(GModule *module)
{
- pep_reply_handlers = NULL;
-
// register hook handler
hk_add_handler (pep_hh, HOOK_INTERNAL, NULL);