changeset 9740:2bb5e2cd64bd

[gaim-migrate @ 10605] " A few days back, someone on #gaim was wondering how to block IM's from IRC, which isn't supported by gaim, as this isn't supported at a protocol level. I decided to implement gaim's privacy options (permit lists, deny lists, block all users, and permit people on buddy list) at a local level for IRC and Zephyr. Jabber, SILC, and Trepia don't seem to support deny or permit lists in Gaim, but I don't use the latter two protocols and wasn't sure about how to implemnt in in Jabber. When implementing it, I noticed that changes in privacy settings didn't automatically cause blist.xml to get scheduled for writing (even on exit). To fix this, I needed to make schedule_blist_save in blist.c non-static and call it from serv_set_permit_deny() in server.c, and gaim_privacy_{permit,deny}_{add,remove} in privacy.c ." --Arun A Tharuvai committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Wed, 11 Aug 2004 23:52:48 +0000
parents 35f22ba01bd7
children b10d4c6ac7eb
files src/blist.c src/privacy.c src/protocols/irc/irc.c src/protocols/irc/msgs.c src/protocols/zephyr/zephyr.c src/server.c
diffstat 6 files changed, 166 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/blist.c	Wed Aug 11 18:05:10 2004 +0000
+++ b/src/blist.c	Wed Aug 11 23:52:48 2004 +0000
@@ -165,7 +165,7 @@
 	return FALSE;
 }
 
-static void schedule_blist_save()
+void schedule_blist_save()
 {
 	if (blist_save_timer != 0)
 		gaim_timeout_remove(blist_save_timer);
--- a/src/privacy.c	Wed Aug 11 18:05:10 2004 +0000
+++ b/src/privacy.c	Wed Aug 11 23:52:48 2004 +0000
@@ -26,6 +26,8 @@
 #include "server.h"
 #include "util.h"
 
+extern void schedule_blist_save(void);
+
 static GaimPrivacyUiOps *privacy_ops = NULL;
 
 gboolean
@@ -58,6 +60,7 @@
 	if (privacy_ops != NULL && privacy_ops->permit_added != NULL)
 		privacy_ops->permit_added(account, who);
 
+	schedule_blist_save();
 	return TRUE;
 }
 
@@ -92,6 +95,7 @@
 	if (privacy_ops != NULL && privacy_ops->permit_removed != NULL)
 		privacy_ops->permit_removed(account, who);
 
+	schedule_blist_save();
 	return TRUE;
 }
 
@@ -125,6 +129,7 @@
 	if (privacy_ops != NULL && privacy_ops->deny_added != NULL)
 		privacy_ops->deny_added(account, who);
 
+	schedule_blist_save();
 	return TRUE;
 }
 
@@ -159,6 +164,7 @@
 	if (privacy_ops != NULL && privacy_ops->deny_removed != NULL)
 		privacy_ops->deny_removed(account, who);
 
+	schedule_blist_save();
 	return TRUE;
 }
 
--- a/src/protocols/irc/irc.c	Wed Aug 11 18:05:10 2004 +0000
+++ b/src/protocols/irc/irc.c	Wed Aug 11 23:52:48 2004 +0000
@@ -33,6 +33,7 @@
 #include "prpl.h"
 #include "plugin.h"
 #include "util.h"
+#include "privacy.h"
 
 #include "irc.h"
 
@@ -331,6 +332,35 @@
 	irc_cmd_whois(irc, "whois", NULL, args);
 }
 
+static void irc_add_deny(GaimConnection *gc, const char *who)
+{
+        gaim_privacy_deny_add(gc->account,who,1);
+}
+
+static void irc_rem_deny(GaimConnection *gc, const char *who)
+{
+        gaim_privacy_deny_remove(gc->account,who,1);
+}
+
+static void
+irc_add_permit(GaimConnection *gc, const char *who)
+{
+        gaim_privacy_permit_add(gc->account,who,1);
+}
+
+static void
+irc_rem_permit(GaimConnection *gc, const char *who)
+{
+        gaim_privacy_permit_remove(gc->account,who,1);
+}
+
+static void
+irc_set_permit_deny(GaimConnection *gc)
+{
+  /* This only has to exist */
+        return;
+}
+
 static void irc_set_away(GaimConnection *gc, const char *state, const char *msg)
 {
 	struct irc_conn *irc = gc->proto_data;
@@ -592,11 +622,11 @@
 	NULL,					/* add_buddies */
 	irc_remove_buddy,		/* remove_buddy */
 	NULL,					/* remove_buddies */
-	NULL,					/* add_permit */
-	NULL,					/* add_deny */
-	NULL,					/* rem_permit */
-	NULL,					/* rem_deny */
-	NULL,					/* set_permit_deny */
+	irc_add_permit,					/* add_permit */
+	irc_add_deny,					/* add_deny */
+	irc_rem_permit,					/* rem_permit */
+	irc_rem_deny,					/* rem_deny */
+	irc_set_permit_deny,					/* set_permit_deny */
 	NULL,					/* warn */
 	irc_chat_join,			/* join_chat */
 	NULL,					/* reject_chat */
--- a/src/protocols/irc/msgs.c	Wed Aug 11 18:05:10 2004 +0000
+++ b/src/protocols/irc/msgs.c	Wed Aug 11 23:52:48 2004 +0000
@@ -28,6 +28,7 @@
 #include "util.h"
 #include "debug.h"
 #include "irc.h"
+#include "privacy.h"
 
 #include <stdio.h>
 
@@ -846,6 +847,8 @@
 	GaimConversation *convo;
 	char *nick = irc_mask_nick(from), *tmp, *msg;
 	int notice = 0;
+	GSList* l;
+	gboolean in_deny=0;
 
 	if (!args || !args[0] || !args[1] || !gc) {
 		g_free(nick);
@@ -859,6 +862,40 @@
 		return;
 	}
 
+	 
+	switch (gc->account->perm_deny) {
+	case GAIM_PRIVACY_ALLOW_ALL: 
+		in_deny = 0; break;
+	case GAIM_PRIVACY_DENY_ALL: 
+		in_deny = 1; break;
+	case GAIM_PRIVACY_ALLOW_USERS: /* See if stripped_sender is in gc->account->permit and allow appropriately */
+		in_deny = 1;
+		for(l=gc->account->permit;l!=NULL;l=l->next) {
+			if (!gaim_utf8_strcasecmp(nick, gaim_normalize(gc->account, (char *)l->data))) {
+				in_deny=0;
+				break;
+			} 
+		}
+		break;
+	case GAIM_PRIVACY_DENY_USERS: /* See if nick is in gc->account->deny and deny if so */ 
+		in_deny = 0;
+		for(l=gc->account->deny;l!=NULL;l=l->next) {
+			if (!gaim_utf8_strcasecmp(nick, gaim_normalize(gc->account, (char *)l->data))) {
+				in_deny=1;
+				break;
+			} 
+		}
+		break;
+	case GAIM_PRIVACY_ALLOW_BUDDYLIST: 
+		in_deny = 1;
+		if (gaim_find_buddy(gc->account,nick)!=NULL) {
+			in_deny = 0;
+		}
+		break;
+	default: 
+		in_deny=0; break;
+	}
+	 
 	msg = gaim_escape_html(tmp);
 	g_free(tmp);
 
@@ -872,9 +909,13 @@
 	}
 
 	if (!gaim_utf8_strcasecmp(args[0], gaim_connection_get_display_name(gc))) {
+		if (!in_deny) {
 		serv_got_im(gc, nick, msg, 0, time(NULL));
+		}
 	} else if (notice) {
+		if(!in_deny) {
 		serv_got_im(gc, nick, msg, 0, time(NULL));
+		}
 	} else {
 		convo = gaim_find_conversation_with_account(args[0], irc->account);
 		if (convo)
--- a/src/protocols/zephyr/zephyr.c	Wed Aug 11 18:05:10 2004 +0000
+++ b/src/protocols/zephyr/zephyr.c	Wed Aug 11 23:52:48 2004 +0000
@@ -32,6 +32,7 @@
 #include "server.h"
 #include "util.h"
 #include "cmds.h"
+#include "privacy.h"
 
 #include "zephyr/zephyr.h"
 #include "internal.h"
@@ -691,10 +692,51 @@
 
 			if (!g_ascii_strcasecmp(notice.z_opcode,"PING"))
 				serv_got_typing(gc,stripped_sender,ZEPHYR_TYPING_RECV_TIMEOUT, GAIM_TYPING);
-			else 
-				serv_got_im(gc, stripped_sender, buf3, flags, time(NULL));
+			else {
+				GSList* l;
+				gboolean in_deny;
+					 
+				switch (gc->account->perm_deny) {
+				case GAIM_PRIVACY_ALLOW_ALL: 
+					in_deny = 0; break;
+				case GAIM_PRIVACY_DENY_ALL: 
+					in_deny = 1; break;
+				case GAIM_PRIVACY_ALLOW_USERS: /* See if stripped_sender is in gc->account->permit and allow appropriately */
+					in_deny = 1;
+					for(l=gc->account->permit;l!=NULL;l=l->next) {
+						if (!gaim_utf8_strcasecmp(stripped_sender, gaim_normalize(gc->account, (char *)l->data))) {
+							fprintf(stderr,"stripped sender %s l->data %sf\n",stripped_sender, (char *)l->data);
+							in_deny=0;
+							break;
+						} 
+					}
+					break;
+				case GAIM_PRIVACY_DENY_USERS: /* See if stripped_sender is in gc->account->deny and deny if so */ 
+					in_deny = 0;
+					for(l=gc->account->deny;l!=NULL;l=l->next) {
+						if (!gaim_utf8_strcasecmp(stripped_sender, gaim_normalize(gc->account, (char *)l->data))) {
+							fprintf(stderr,"stripped sender %s l->data %sf\n",stripped_sender, (char *)l->data);
+							in_deny=1;
+							break;
+						} 
+					}
+					break;
+				case GAIM_PRIVACY_ALLOW_BUDDYLIST: 
+					in_deny = 1;
+					if (gaim_find_buddy(gc->account,stripped_sender)!=NULL) {
+						in_deny = 0;
+					} 
+					break;
+				default: 
+					in_deny=0; break;
+				}
 
+				if (!in_deny) {
+					serv_got_im(gc, stripped_sender, buf3, flags, time(NULL));
+				}
+			}
 				g_free(stripped_sender);
+
 			} else {
 				zephyr_triple *zt1, *zt2;
                                 gchar *send_inst_utf8;
@@ -1731,6 +1773,36 @@
 }
 
 
+static void
+zephyr_add_deny(GaimConnection *gc, const char *who)
+{
+	gaim_privacy_deny_add(gc->account,who,1);
+}
+
+static void
+zephyr_remove_deny(GaimConnection *gc, const char *who)
+{
+	gaim_privacy_deny_remove(gc->account,who,1);
+}
+
+static void
+zephyr_add_permit(GaimConnection *gc, const char *who)
+{
+	gaim_privacy_permit_add(gc->account,who,1);
+}
+
+static void
+zephyr_remove_permit(GaimConnection *gc, const char *who)
+{
+	gaim_privacy_permit_remove(gc->account,who,1);
+}
+
+static void
+zephyr_set_permit_deny(GaimConnection *gc)
+{
+	/* This doesn't have to do anything, since really, we can just check account->perm_deny when deciding whether to di */
+	return;
+}
 static int zephyr_resubscribe(GaimConnection *gc)
 {
         /* Resubscribe to the in-memory list of subscriptions and also
@@ -1839,11 +1911,11 @@
 	NULL,					/* add_buddies */
 	NULL,					/* remove_buddy */
 	NULL,					/* remove_buddies */
-	NULL, /* add_permit -- not useful, since anyone can zephyr you by default*/
-	NULL, /* XXX add deny  -- maybe put an auto "I'm ignoring your zephyrs*/
-	NULL, /* remove_permit -- not useful, see add permit */
-	NULL, /* XXX remove deny -- remove above deny, */
-	NULL, /* ??? set permit deny */
+	zephyr_add_permit, /* add_permit -- not useful, since anyone can zephyr you by default*/
+	zephyr_add_deny, /* XXX add_deny  -- maybe put an auto "I'm ignoring your zephyrs*/
+	zephyr_remove_permit, /* remove_permit -- not useful, see add permit */
+	zephyr_remove_deny, /* XXX remove deny -- remove above deny, */
+	zephyr_set_permit_deny, /* ??? set permit deny */
 	NULL,  /* --- warn  */
 	zephyr_join_chat,		/* join_chat */
 	NULL,					/* reject_chat */
--- a/src/server.c	Wed Aug 11 18:05:10 2004 +0000
+++ b/src/server.c	Wed Aug 11 23:52:48 2004 +0000
@@ -40,6 +40,8 @@
 #include "gtkimhtml.h"
 #include "gtkutils.h"
 
+extern void schedule_blist_save(void);
+
 #define SECS_BEFORE_RESENDING_AUTORESPONSE 600
 #define SEX_BEFORE_RESENDING_AUTORESPONSE "Only after you're married"
 
@@ -656,6 +658,8 @@
 	 */
 	if (prpl_info && g_list_find(gaim_connections_get_all(), g) && prpl_info->set_permit_deny)
 		prpl_info->set_permit_deny(g);
+	
+	schedule_blist_save();
 }