changeset 819:c2d7d9dd4193

New option 'block_unsubscribed'
author Mikael Berthe <mikael@lilotux.net>
date Sat, 22 Apr 2006 10:50:54 +0200
parents 55cd45481a07
children 80bd7f49075f
files mcabber/mcabberrc.example mcabber/src/jabglue.c mcabber/src/roster.c mcabber/src/roster.h
diffstat 4 files changed, 28 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/mcabberrc.example	Fri Apr 21 19:08:04 2006 +0200
+++ b/mcabber/mcabberrc.example	Sat Apr 22 10:50:54 2006 +0200
@@ -119,6 +119,11 @@
 # See 'message_autoaway' below.
 #set autoaway = 0
 
+# Message blocking
+# Set the 'block_unsubscribed' to 1 if you want to block (drop) incoming
+# messages from people you haven't authorized. (default: 0)
+#set block_unsubscribed = 0
+
 # Status messages
 # The "message" value will override all others, take care!
 #set message = Unique message status
--- a/mcabber/src/jabglue.c	Fri Apr 21 19:08:04 2006 +0200
+++ b/mcabber/src/jabglue.c	Sat Apr 22 10:50:54 2006 +0200
@@ -785,7 +785,16 @@
 
   rname = strchr(from, '/');
   if (rname) rname++;
-  hk_message_in(jid, rname, timestamp, body, type);
+
+  // We don't call the message_in hook if 'block_unsubscribed' is true and
+  // this is a regular message from an unsubscribed user.
+  if (!settings_opt_get_int("block_unsubscribed") ||
+      (roster_getsubscription(jid) & sub_from) ||
+      (type && strcmp(type, "chat"))) {
+    hk_message_in(jid, rname, timestamp, body, type);
+  } else {
+    scr_LogPrint(LPRINT_LOGNORM, "Blocked a message from <%s>", jid);
+  }
   g_free(jid);
 }
 
--- a/mcabber/src/roster.c	Fri Apr 21 19:08:04 2006 +0200
+++ b/mcabber/src/roster.c	Sat Apr 22 10:50:54 2006 +0200
@@ -630,6 +630,18 @@
   return roster_usr->type;
 }
 
+guint roster_getsubscription(const char *jid)
+{
+  GSList *sl_user;
+  roster *roster_usr;
+
+  if ((sl_user = roster_find(jid, jidsearch, 0)) == NULL)
+    return 0;
+
+  roster_usr = (roster*)sl_user->data;
+  return roster_usr->subscription;
+}
+
 //  roster_unsubscribed()
 // We have lost buddy's presence updates; this function clears the status
 // message, sets the buddy offline and frees the resources
--- a/mcabber/src/roster.h	Fri Apr 21 19:08:04 2006 +0200
+++ b/mcabber/src/roster.h	Sat Apr 22 10:50:54 2006 +0200
@@ -98,6 +98,7 @@
 enum imstatus roster_getstatus(const char *jid, const char *resname);
 const char   *roster_getstatusmsg(const char *jid, const char *resname);
 guint   roster_gettype(const char *jid);
+guint   roster_getsubscription(const char *jid);
 void    roster_unsubscribed(const char *jid);
 
 void    buddylist_build(void);