Use new commands interface
authorMyhailo Danylenko <isbear@ukrpost.net>
Wed, 07 Apr 2010 21:00:17 +0300
changeset 29 378fc85f60f3
parent 28 bcee0de24664
child 30 5192b35e1327
Use new commands interface * Use id to delete command * Add /avatar to a list of safe commands
avatar.c
config.h.in
--- a/avatar.c	Sun Apr 04 16:40:20 2010 +0300
+++ b/avatar.c	Wed Apr 07 21:00:17 2010 +0300
@@ -61,7 +61,13 @@
 
 static module_info_t info_avatar_experimental = {
 	.branch      = "experimental",
-	.api         = 15,
+#ifndef HAVE_CMD_ID
+	.api         = 20,
+#elif defined HAVE_CMD_SAFE
+	.api         = 24,
+#else
+	.api         = 23,
+#endif
 	.version     = PROJECT_VERSION,
 	.description = DESCRIPTION,
 	.requires    = deps,
@@ -87,6 +93,13 @@
 #define NS_AVATAR_METADATA        ( "urn:xmpp:avatar:metadata"        )
 #define NS_AVATAR_METADATA_NOTIFY ( "urn:xmpp:avatar:metadata+notify" )
 
+#ifdef HAVE_CMD_ID
+static gpointer avatar_cmid = NULL;
+#ifdef HAVE_CMD_SAFE
+static gboolean avatar_set_safe = FALSE;
+#endif
+#endif
+
 static guint avatar_hid_connect    = 0;
 static guint avatar_hid_disconnect = 0;
 
@@ -1154,7 +1167,14 @@
 	pep_register_xmlns_handler (NS_AVATAR_METADATA, avatar_handler, NULL, NULL);
 	avatar_metadata_reply_handler = lm_message_handler_new (avatar_publish_metadata_reply_handler, NULL, NULL);
 
+#ifndef HAVE_CMD_ID
 	cmd_add ("avatar", "", COMPL_FILENAME, 0, do_avatar, NULL);
+#else
+	avatar_cmid = cmd_add ("avatar", "", COMPL_FILENAME, 0, do_avatar, NULL);
+#ifdef HAVE_CMD_SAFE
+	avatar_set_safe = cmd_set_safe ("avatar", TRUE);
+#endif
+#endif
 
 	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);
@@ -1171,7 +1191,16 @@
 	hk_del_handler (HOOK_POST_CONNECT, avatar_hid_connect);
 	hk_del_handler (HOOK_PRE_DISCONNECT, avatar_hid_disconnect);
 
+#ifndef HAVE_CMD_ID
 	cmd_del ("avatar");
+#else
+	if (avatar_cmid)
+		cmd_del (avatar_cmid);
+#ifdef HAVE_CMD_SAFE
+	if (avatar_set_safe)
+		cmd_set_safe ("avatar", FALSE);
+#endif
+#endif
 
 	pep_unregister_xmlns_handler (NS_AVATAR_METADATA);
 
--- a/config.h.in	Sun Apr 04 16:40:20 2010 +0300
+++ b/config.h.in	Wed Apr 07 21:00:17 2010 +0300
@@ -4,6 +4,15 @@
 
 #cmakedefine HAVE_LM_CONNECTION_UNREGISTER_REPLY_HANDLER
 
+#include <mcabber/config.h>
+
+#if MCABBER_BRANCH_EXPERIMENTAL && MCABBER_API_VERSION >= 23
+#  define HAVE_CMD_ID
+#  if MCABBER_API_VERSION >= 24
+#    define HAVE_CMD_SAFE
+#  endif
+#endif
+
 #define PROJECT_VERSION ( "${PROJECT_VERSION}" )
 
 #endif