Update hooks
authorMyhailo Danylenko <isbear@ukrpost.net>
Thu, 25 Mar 2010 21:00:46 +0200
changeset 20 744b8e669d85
parent 19 9ce7690c4dab
child 21 32ac35851254
Update hooks
TODO
pep.c
--- a/TODO	Sun Mar 14 18:13:31 2010 +0200
+++ b/TODO	Thu Mar 25 21:00:46 2010 +0200
@@ -1,4 +1,5 @@
 
 do we need to export functions in some special way?
 startup/shutdown hook to inform other modules, that they should free/register handlers?
+due to server bugs, some offline buddies are still notified on publication, causing error reply, that pep accepts as event. check message type/presence of error tag.
 
--- a/pep.c	Sun Mar 14 18:13:31 2010 +0200
+++ b/pep.c	Thu Mar 25 21:00:46 2010 +0200
@@ -37,7 +37,7 @@
 
 static module_info_t info_pep_experimental = {
 	.branch      = "experimental",
-	.api         = 5,
+	.api         = 10,
 	.version     = PROJECT_VERSION,
 	.description = DESCRIPTION,
 	.requires    = NULL,
@@ -48,7 +48,7 @@
 
 module_info_t info_pep = {
 	.branch      = "dev",
-	.api         = 4,
+	.api         = 11,
 	.version     = PROJECT_VERSION,
 	.description = DESCRIPTION,
 	.requires    = NULL,
@@ -68,6 +68,9 @@
 
 static GSList *pep_xmlns_handlers = NULL;
 
+static guint   pep_hid_connect    = 0;
+static guint   pep_hid_disconnect = 0;
+
 static LmMessageHandler *pep_message_handler = NULL;
 static LmMessageHandler *pep_iq_handler      = NULL;
 
@@ -187,12 +190,16 @@
 }
 
 // release handlers before reconnect
-static void pep_hh (guint32 hid, hk_arg_t *args, gpointer userdata)
+static guint pep_hch (const gchar *hid, hk_arg_t *args, gpointer userdata)
 {
-	if (hid == HOOK_POST_CONNECT)
-		pep_register_handlers ();
-	else if (hid == HOOK_PRE_DISCONNECT)
-		pep_unregister_handlers ();
+	pep_register_handlers ();
+	return HOOK_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
+}
+
+static guint pep_hdh (const gchar *hid, hk_arg_t *args, gpointer userdata)
+{
+	pep_unregister_handlers ();
+	return HOOK_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
 }
 
 static void pep_init (void)
@@ -202,7 +209,8 @@
 	pep_iq_handler      = lm_message_handler_new (pep_iq_pubsub_handler,     NULL, NULL);
 
 	// register hook handler
-	hk_add_handler (pep_hh, HOOK_POST_CONNECT | HOOK_PRE_DISCONNECT, NULL);
+	pep_hid_connect    = hk_add_handler (pep_hch, HOOK_POST_CONNECT, G_PRIORITY_DEFAULT, NULL);
+	pep_hid_disconnect = hk_add_handler (pep_hdh, HOOK_PRE_DISCONNECT, G_PRIORITY_DEFAULT, NULL);
 
 	// register handlers to connection
 	pep_register_handlers ();
@@ -214,7 +222,8 @@
 	pep_unregister_handlers ();
 
 	// remove hook
-	hk_del_handler (pep_hh, NULL);
+	hk_del_handler (HOOK_POST_CONNECT, pep_hid_connect);
+	hk_del_handler (HOOK_PRE_DISCONNECT, pep_hid_disconnect);
 
 	{ // unregister xmlns handlers
 		GSList *hel;