Update hooks
authorMyhailo Danylenko <isbear@ukrpost.net>
Thu, 25 Mar 2010 20:46:24 +0200
changeset 26 fec515d07dd2
parent 25 6ad07b1d4e7f
child 27 c641ef370d18
Update hooks
avatar.c
--- a/avatar.c	Mon Mar 15 00:53:11 2010 +0200
+++ b/avatar.c	Thu Mar 25 20:46:24 2010 +0200
@@ -60,7 +60,7 @@
 
 static module_info_t info_avatar_experimental = {
 	.branch      = "experimental",
-	.api         = 8,
+	.api         = 10,
 	.version     = PROJECT_VERSION,
 	.description = DESCRIPTION,
 	.requires    = deps,
@@ -71,7 +71,7 @@
 
 module_info_t info_avatar = {
 	.branch      = "dev",
-	.api         = 7,
+	.api         = 11,
 	.version     = PROJECT_VERSION,
 	.description = DESCRIPTION,
 	.requires    = deps,
@@ -86,7 +86,9 @@
 #define NS_AVATAR_METADATA        ( "urn:xmpp:avatar:metadata"        )
 #define NS_AVATAR_METADATA_NOTIFY ( "urn:xmpp:avatar:metadata+notify" )
 
-static guint avatar_cid = 0;
+static guint avatar_cid            = 0;
+static guint avatar_hid_connect    = 0;
+static guint avatar_hid_disconnect = 0;
 
 static GSList *reply_handlers = NULL;
 
@@ -506,7 +508,7 @@
 	
 	unlink (jfile);
 	if (symlink (file, jfile) == -1)
-		scr_LogPrint (LPRINT_LOGNORM, "avatar: Cannot symlink jid-file to avatar: %s.", strerror (errno));
+		scr_log_print (LPRINT_LOGNORM, "avatar: Cannot symlink jid-file to avatar: %s.", strerror (errno));
 }
 
 // reply handler for metadata publish request
@@ -531,7 +533,7 @@
 			else
 				reason = "undefined";
 	
-			scr_LogPrint (LPRINT_LOGNORM, "avatar: Metadata publishing failed: %s - %s.", type, reason);
+			scr_log_print (LPRINT_LOGNORM, "avatar: Metadata publishing failed: %s - %s.", type, reason);
 		}
 
 		break;
@@ -561,7 +563,7 @@
 			lm_connection_send_with_reply (connection, request, avatar_metadata_reply_handler, &error);
 
 			if (error) {
-				scr_LogPrint (LPRINT_DEBUG, "avatar: Metadata publication error: %s.", error -> message);
+				scr_log_print (LPRINT_DEBUG, "avatar: Metadata publication error: %s.", error -> message);
 				g_error_free (error);
 			}
 
@@ -584,7 +586,7 @@
 			else
 				reason = "undefined";
 
-			scr_LogPrint (LPRINT_LOGNORM, "avatar: Data publishing failed: %s - %s.", type, reason);
+			scr_log_print (LPRINT_LOGNORM, "avatar: Data publishing failed: %s - %s.", type, reason);
 		}
 
 		break;
@@ -618,13 +620,13 @@
 			LmMessageNode *node;
 
 			if (!xmpp_is_online ()) {
-				scr_LogPrint (LPRINT_NORMAL, "avatar: You are not online, request not sent.");
+				scr_log_print (LPRINT_NORMAL, "avatar: You are not online, request not sent.");
 				return FALSE;
 			}
 
 			bjid = jidtodisp (jid);
 
-			scr_WriteIncomingMessage (bjid, "No avatar for this buddy yet, sending request.", 0, HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG, 0); // NO conversion from utf-8
+			scr_write_incoming_message (bjid, "No avatar for this buddy yet, sending request.", 0, HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG, 0); // NO conversion from utf-8
 
 			// create data request
 			request = lm_message_new_with_sub_type (bjid, LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_GET);
@@ -643,7 +645,7 @@
 				lm_connection_send (lconnection, request, &error);
 
 				if (error) {
-					scr_LogPrint (LPRINT_DEBUG, "avatar: Request sending error: %s.", error -> message);
+					scr_log_print (LPRINT_DEBUG, "avatar: Request sending error: %s.", error -> message);
 					g_error_free (error);
 				}
 			}
@@ -661,7 +663,7 @@
 	}
 
 	if (!row_pointers) {
-		scr_LogPrint (LPRINT_LOGNORM, "avatar: Cannot decode png data from file %s.", file);
+		scr_log_print (LPRINT_LOGNORM, "avatar: Cannot decode png data from file %s.", file);
 		return FALSE;
 	}
 
@@ -689,7 +691,7 @@
 	g_free (row_pointers);
 
 	if (!avatar) {
-		scr_LogPrint (LPRINT_LOGNORM, "avatar: Error converting image to ascii.");
+		scr_log_print (LPRINT_LOGNORM, "avatar: Error converting image to ascii.");
 		return FALSE;
 	}
 
@@ -701,7 +703,7 @@
 		else
 			mesg = g_strdup_printf ("Avatar:\n%s", avatar);
 
-		scr_WriteIncomingMessage (bjid, mesg, 0, HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG, 0); // NO conversion from utf-8
+		scr_write_incoming_message (bjid, mesg, 0, HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG, 0); // NO conversion from utf-8
 
 		g_free (bjid);
 		g_free (mesg);
@@ -769,7 +771,7 @@
 								int fd = open (file, O_WRONLY|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
 
 								if (fd == -1) {
-									scr_LogPrint (LPRINT_LOGNORM, "avatar: Cannot create file: %s.", strerror (errno));
+									scr_log_print (LPRINT_LOGNORM, "avatar: Cannot create file: %s.", strerror (errno));
 									g_free (png);
 									g_free (file);
 									continue;
@@ -810,7 +812,7 @@
 			else
 				reason = "undefined";
 
-			scr_LogPrint (LPRINT_LOGNORM, "avatar: Obtaining avatar data for %s failed: %s - %s.", from, type, reason);
+			scr_log_print (LPRINT_LOGNORM, "avatar: Obtaining avatar data for %s failed: %s - %s.", from, type, reason);
 		}
 
 		break;
@@ -835,7 +837,7 @@
 	GError           *error       = NULL;
 
 	if (!xmpp_is_online ()) {
-		scr_LogPrint (LPRINT_DEBUG, "avatar: Not connected, delaying publish.");
+		scr_log_print (LPRINT_DEBUG, "avatar: Not connected, delaying publish.");
 
 		g_free (publish_data);
 
@@ -913,7 +915,7 @@
 		lm_connection_send_with_reply (lconnection, request, avatar_metadata_reply_handler, &error);
 	
 	if (error) {
-		scr_LogPrint (LPRINT_DEBUG, "avatar: Publish request sending error: %s.", error -> message);
+		scr_log_print (LPRINT_DEBUG, "avatar: Publish request sending error: %s.", error -> message);
 		g_error_free (error);
 	}
 
@@ -965,7 +967,7 @@
 
 				text = g_string_free (mesg, FALSE);
 
-				scr_WriteIncomingMessage (jid, text, 0, HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG, 0); // NO conversion from utf-8
+				scr_write_incoming_message (jid, text, 0, HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG, 0); // NO conversion from utf-8
 
 				g_free (text);
 			}
@@ -981,13 +983,13 @@
 					struct stat  buf;
 
 					if (!file) {
-						scr_LogPrint (LPRINT_LOGNORM, "avatar: Cannot obtain filename to save file, probably avatar_directory is not set.");
+						scr_log_print (LPRINT_LOGNORM, "avatar: Cannot obtain filename to save file, probably avatar_directory is not set.");
 						g_free (jid);
 						continue;
 					}
 					
 					if (stat (file, &buf) != -1) {
-						scr_WriteIncomingMessage (jid, "Avatar file exists, will not download.", 0, HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG, 0);
+						scr_write_incoming_message (jid, "Avatar file exists, will not download.", 0, HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG, 0);
 						// link jid to this file
 						set_jid_avatar (jid, file);
 						g_free (file);
@@ -1022,7 +1024,7 @@
 					lm_connection_send_with_reply (lconnection, request, dhandler, &error);
 
 					if (error) {
-						scr_LogPrint (LPRINT_DEBUG, "avatar: Data request sending error: %s.", error -> message);
+						scr_log_print (LPRINT_DEBUG, "avatar: Data request sending error: %s.", error -> message);
 						g_error_free (error);
 					}
 				}
@@ -1048,7 +1050,7 @@
 		const gchar *jid = CURRENT_JID;
 
 		if (!jid) {
-			scr_LogPrint (LPRINT_NORMAL, "This item cannot have avatar.");
+			scr_log_print (LPRINT_NORMAL, "This item cannot have avatar.");
 			return;
 		}
 
@@ -1075,7 +1077,7 @@
 		int      fd           = open (fname, O_RDONLY);
 
 		if (!fd) {
-			scr_LogPrint (LPRINT_NORMAL, "Cannot open file '%s': %s.", fname, strerror (errno));
+			scr_log_print (LPRINT_NORMAL, "Cannot open file '%s': %s.", fname, strerror (errno));
 			g_free (fname);
 			return;
 		}
@@ -1124,17 +1126,18 @@
 }
 
 // release handlers before reconnect
-static void avatar_hh (guint32 hid, hk_arg_t *args, gpointer userdata)
+static guint avatar_hdh (const gchar *hid, hk_arg_t *args, gpointer userdata)
 {
-	if (hid == HOOK_PRE_DISCONNECT)
+	avatar_free_reply_handlers ();
+	return HOOK_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
+}
 
-		avatar_free_reply_handlers ();
-
-	else if (hid == HOOK_POST_CONNECT && publish_delayed) {
-
+static guint avatar_hch (const gchar *hid, hk_arg_t *args, gpointer userdata)
+{
+	if (publish_data) {
 		char *tmp_data = publish_data;
 
-		scr_LogPrint (LPRINT_DEBUG, "avatar: Publishing delayed data.");
+		scr_log_print (LPRINT_DEBUG, "avatar: Publishing delayed data.");
 
 		publish_data    = NULL;
 		publish_delayed = FALSE;
@@ -1143,6 +1146,8 @@
 
 		g_free (tmp_data);
 	}
+
+	return HOOK_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
 }
 
 static void avatar_init (void)
@@ -1152,7 +1157,8 @@
 
 	cmd_add ("avatar", "", COMPL_FILENAME, 0, do_avatar, NULL);
 
-	hk_add_handler (avatar_hh, HOOK_PRE_DISCONNECT | HOOK_POST_CONNECT, NULL);
+	avatar_hid_connect    = hk_add_handler (avatar_hch, HOOK_POST_CONNECT, G_PRIORITY_DEFAULT, NULL);
+	avatar_hid_disconnect = hk_add_handler (avatar_hdh, HOOK_PRE_DISCONNECT, G_PRIORITY_DEFAULT, NULL);
 
 	xmpp_add_feature (NS_AVATAR_METADATA);
 	xmpp_add_feature (NS_AVATAR_METADATA_NOTIFY);
@@ -1163,7 +1169,8 @@
 	xmpp_del_feature (NS_AVATAR_METADATA);
 	xmpp_del_feature (NS_AVATAR_METADATA_NOTIFY);
 
-	hk_del_handler (avatar_hh, NULL);
+	hk_del_handler (HOOK_POST_CONNECT, avatar_hid_connect);
+	hk_del_handler (HOOK_PRE_DISCONNECT, avatar_hid_disconnect);
 
 	cmd_del ("avatar");