Last active
November 5, 2015 04:50
-
-
Save hirthwork/c9d5199ebcdcb82927d0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- a/mcabber/xmpp.c | |
+++ b/mcabber/xmpp.c | |
@@ -1538,7 +1538,9 @@ | |
{ | |
char *r; | |
char *buf; | |
+ GSList* roster_node; | |
int newbuddy; | |
+ guint subscription; | |
guint hook_result; | |
LmMessageSubType mstype = lm_message_get_sub_type(m); | |
const char *from = lm_message_get_from(m); | |
@@ -1556,14 +1558,21 @@ | |
} | |
r = jidtodisp(from); | |
- newbuddy = !roster_find(r, jidsearch, 0); | |
+ roster_node = roster_find(r, jidsearch, 0); | |
+ if (roster_node) { | |
+ newbuddy = 0; | |
+ subscription = buddy_getsubscription(roster_node->data); | |
+ } else { | |
+ newbuddy = 1; | |
+ subscription = 0; | |
+ } | |
hook_result = hk_subscription(mstype, r, msg); | |
if (mstype == LM_MESSAGE_SUB_TYPE_SUBSCRIBE) { | |
/* The sender wishes to subscribe to our presence */ | |
- if (hook_result) { | |
+ if (hook_result || (subscription & sub_from)) { | |
g_free(r); | |
return LM_HANDLER_RESULT_REMOVE_MESSAGE; | |
} | |
@@ -1600,6 +1609,11 @@ | |
scr_LogPrint(LPRINT_LOGNORM, "%s", buf); | |
g_free(buf); | |
} else if (mstype == LM_MESSAGE_SUB_TYPE_UNSUBSCRIBE) { | |
+ if (!(subscription & sub_from)) { | |
+ g_free(r); | |
+ return LM_HANDLER_RESULT_REMOVE_MESSAGE; | |
+ } | |
+ | |
/* The sender is unsubscribing from our presence */ | |
xmpp_send_s10n(from, LM_MESSAGE_SUB_TYPE_UNSUBSCRIBED); | |
buf = g_strdup_printf("<%s> is unsubscribing from your " | |
@@ -1608,6 +1622,11 @@ | |
scr_LogPrint(LPRINT_LOGNORM, "%s", buf); | |
g_free(buf); | |
} else if (mstype == LM_MESSAGE_SUB_TYPE_SUBSCRIBED) { | |
+ if (subscription & sub_to) { | |
+ g_free(r); | |
+ return LM_HANDLER_RESULT_REMOVE_MESSAGE; | |
+ } | |
+ | |
/* The sender has allowed us to receive their presence */ | |
buf = g_strdup_printf("<%s> has allowed you to receive their " | |
"presence updates", from); | |
@@ -1615,6 +1634,11 @@ | |
scr_LogPrint(LPRINT_LOGNORM, "%s", buf); | |
g_free(buf); | |
} else if (mstype == LM_MESSAGE_SUB_TYPE_UNSUBSCRIBED) { | |
+ if (!(subscription & sub_to)) { | |
+ g_free(r); | |
+ return LM_HANDLER_RESULT_REMOVE_MESSAGE; | |
+ } | |
+ | |
/* The subscription request has been denied or a previously-granted | |
subscription has been cancelled */ | |
roster_unsubscribed(from); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The patch looks good; what's annoying is that it is just a workaround for a server bug :/
Still, if we want a client-side solution, what about this slightly updated version?