changeset 1984:b0470ef8669b

XEP 184: don't send receipts to buddies that have no presence subscription In order to not leak our presence, do not send message delivery receipts to senders who are not authorized to view our presence. (XEP-0184, section 8)
author Mikael Berthe <mikael@lilotux.net>
date Sun, 27 Mar 2011 12:45:41 +0200
parents 45e0b13a39e2
children 0870005f7efc
files mcabber/mcabber/xmpp.c
diffstat 1 files changed, 20 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/mcabber/xmpp.c	Sun Mar 27 10:43:13 2011 +0200
+++ b/mcabber/mcabber/xmpp.c	Sun Mar 27 12:45:41 2011 +0200
@@ -1203,7 +1203,7 @@
                                        LmMessage *m, gpointer user_data)
 {
   const char *p, *from=lm_message_get_from(m);
-  char *r, *s;
+  char *bjid, *res;
   LmMessageNode *x;
   const char *body = NULL;
   const char *enc = NULL;
@@ -1219,26 +1219,27 @@
   if (x && (p = lm_message_node_get_value(x)) != NULL)
     enc = p;
 
+  // Get the bare-JID/room (bjid) and the resource/nickname (res)
+  bjid = g_strdup(lm_message_get_from(m));
+  res = strchr(bjid, JID_RESOURCE_SEPARATOR);
+  if (res) *res++ = 0;
+
   p = lm_message_node_get_child_value(m->node, "subject");
   if (p != NULL) {
     if (mstype != LM_MESSAGE_SUB_TYPE_GROUPCHAT) {
       // Chat message
       subject = p;
-    } else {                                      // Room topic
+    } else {
+      // Room topic
       GSList *roombuddy;
       gchar *mbuf;
       const gchar *subj = p;
-      // Get the room (s) and the nickname (r)
-      s = g_strdup(lm_message_get_from(m));
-      r = strchr(s, JID_RESOURCE_SEPARATOR);
-      if (r) *r++ = 0;
-      else   r = s;
       // Set the new topic
-      roombuddy = roster_find(s, jidsearch, 0);
+      roombuddy = roster_find(bjid, jidsearch, 0);
       if (roombuddy)
         buddy_settopic(roombuddy->data, subj);
       // Display inside the room window
-      if (r == s) {
+      if (!res) {
         // No specific resource (this is certainly history)
         if (*subj)
           mbuf = g_strdup_printf("The topic has been set to: %s", subj);
@@ -1246,15 +1247,14 @@
           mbuf = g_strdup_printf("The topic has been cleared");
       } else {
         if (*subj)
-          mbuf = g_strdup_printf("%s has set the topic to: %s", r, subj);
+          mbuf = g_strdup_printf("%s has set the topic to: %s", res, subj);
         else
-          mbuf = g_strdup_printf("%s has cleared the topic", r);
+          mbuf = g_strdup_printf("%s has cleared the topic", res);
       }
-      scr_WriteIncomingMessage(s, mbuf, 0,
+      scr_WriteIncomingMessage(bjid, mbuf, 0,
                                HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG, 0);
       if (settings_opt_get_int("log_muc_conf"))
-        hlog_write_message(s, 0, -1, mbuf);
-      g_free(s);
+        hlog_write_message(bjid, 0, -1, mbuf);
       g_free(mbuf);
       // The topic is displayed in the chat status line, so refresh now.
       scr_update_chat_status(TRUE);
@@ -1275,11 +1275,14 @@
   } else {
     handle_state_events(from, m->node);
   }
+
   if (from && (body || subject))
     gotmessage(mstype, from, body, enc, subject, timestamp,
                lm_message_node_find_xmlns(m->node, NS_SIGNED));
-  // Report received message if message receipt was requested
-  if (lm_message_node_get_child(m->node, "request")) {
+
+  // Report received message if message delivery receipt was requested
+  if (lm_message_node_get_child(m->node, "request") &&
+      (roster_getsubscription(bjid) & sub_from)) {
     const gchar *mid;
     LmMessageNode *y;
     LmMessage *rcvd = lm_message_new(from, LM_MESSAGE_TYPE_MESSAGE);
@@ -1311,6 +1314,7 @@
     }
   }
 
+  g_free(bjid);
   return LM_HANDLER_RESULT_REMOVE_MESSAGE;
 }