# HG changeset patch # User Mikael Berthe # Date 1271505817 -7200 # Node ID 5d37cee8c6c66f0017e329c0158cc4047bd7a2b1 # Parent 68a4f8dda3e7a14894a359804510c61f2fd5f911 Add "hook-subscription" hook and hk_subscription() diff -r 68a4f8dda3e7 -r 5d37cee8c6c6 mcabber/doc/HOWTO_modules.txt --- a/mcabber/doc/HOWTO_modules.txt Sat Apr 17 12:31:35 2010 +0200 +++ b/mcabber/doc/HOWTO_modules.txt Sat Apr 17 14:03:37 2010 +0200 @@ -235,6 +235,11 @@ * attention - number of non-MUC buffers with the attention sign (!) * muc_unread - number of MUC buffers with the unread message flag * muc_attention - number of MUC buffers with the attention sign + - hook-subscription (HOOK_SUBSCRIPTION) + * type - the type of the subscription message received. Can be one + of subscribe, unsubscribe, subscribed, unsubscribed. + * jid - sender of the incoming subscription message + * message - optional message sent with the request ------------------------------------------------------------------------ diff -r 68a4f8dda3e7 -r 5d37cee8c6c6 mcabber/mcabber/api.h --- a/mcabber/mcabber/api.h Sat Apr 17 12:31:35 2010 +0200 +++ b/mcabber/mcabber/api.h Sat Apr 17 14:03:37 2010 +0200 @@ -3,7 +3,7 @@ #include // For MCABBER_BRANCH -#define MCABBER_API_VERSION 14 +#define MCABBER_API_VERSION 15 #define MCABBER_API_MIN 13 extern const gchar *mcabber_branch; diff -r 68a4f8dda3e7 -r 5d37cee8c6c6 mcabber/mcabber/hooks.c --- a/mcabber/mcabber/hooks.c Sat Apr 17 12:31:35 2010 +0200 +++ b/mcabber/mcabber/hooks.c Sat Apr 17 14:03:37 2010 +0200 @@ -709,6 +709,42 @@ g_free(str_unread); } +// hk_presence_subscription_request(jid, message) +// Return non-zero if mcabber should stop processing the subscription request +guint hk_subscription(LmMessageSubType mstype, const gchar *bjid, + const gchar *msg) +{ +#ifdef MODULES_ENABLE + guint h_result; + const char *stype; + + if (mstype == LM_MESSAGE_SUB_TYPE_SUBSCRIBE) + stype = "subscribe"; + else if (mstype == LM_MESSAGE_SUB_TYPE_UNSUBSCRIBE) + stype = "unsubscribe"; + else if (mstype == LM_MESSAGE_SUB_TYPE_SUBSCRIBED) + stype = "subscribed"; + else if (mstype == LM_MESSAGE_SUB_TYPE_UNSUBSCRIBED) + stype = "unsubscribed"; + else return 0; // Should not happen + + { + hk_arg_t args[] = { + { "type", stype }, + { "jid", bjid }, + { "message", msg ? msg : "" }, + { NULL, NULL }, + }; + h_result = hk_run_handlers(HOOK_SUBSCRIPTION, args); + } + if (h_result != HOOK_HANDLER_RESULT_ALLOW_MORE_HANDLERS) { + scr_LogPrint(LPRINT_DEBUG, "Subscription message ignored (hook result)."); + return h_result; + } +#endif + return 0; +} + /* External commands */ diff -r 68a4f8dda3e7 -r 5d37cee8c6c6 mcabber/mcabber/hooks.h --- a/mcabber/mcabber/hooks.h Sat Apr 17 12:31:35 2010 +0200 +++ b/mcabber/mcabber/hooks.h Sat Apr 17 14:03:37 2010 +0200 @@ -22,6 +22,7 @@ #define HOOK_POST_CONNECT "hook-post-connect" #define HOOK_PRE_DISCONNECT "hook-pre-disconnect" #define HOOK_UNREAD_LIST_CHANGE "hook-unread-list-change" +#define HOOK_SUBSCRIPTION "hook-subscription" typedef enum { HOOK_HANDLER_RESULT_ALLOW_MORE_HANDLERS = 0, @@ -62,6 +63,9 @@ void hk_unread_list_change(guint unread_count, guint attention_count, guint muc_unread, guint muc_attention); +guint hk_subscription(LmMessageSubType mstype, const gchar *bjid, + const gchar *msg); + void hk_ext_cmd_init(const char *command); void hk_ext_cmd(const char *bjid, guchar type, guchar info, const char *data); diff -r 68a4f8dda3e7 -r 5d37cee8c6c6 mcabber/mcabber/xmpp.c --- a/mcabber/mcabber/xmpp.c Sat Apr 17 12:31:35 2010 +0200 +++ b/mcabber/mcabber/xmpp.c Sat Apr 17 14:03:37 2010 +0200 @@ -1521,19 +1521,25 @@ char *r; char *buf; int newbuddy; + LmMessageSubType mstype; + guint hook_result; const char *from = lm_message_get_from(m); - LmMessageSubType mstype; + const char *msg = lm_message_node_get_child_value(m->node, "status"); r = jidtodisp(from); newbuddy = !roster_find(r, jidsearch, 0); mstype = lm_message_get_sub_type(m); + hook_result = hk_subscription(mstype, r, msg); + if (mstype == LM_MESSAGE_SUB_TYPE_SUBSCRIBE) { /* The sender wishes to subscribe to our presence */ - const char *msg; - msg = lm_message_node_get_child_value(m->node, "status"); + if (hook_result) { + g_free(r); + return LM_HANDLER_RESULT_REMOVE_MESSAGE; + } buf = g_strdup_printf("<%s> wants to subscribe to your presence updates", from);