[Pkg-privacy-commits] [irssi-plugin-otr] 35/267: added /set otr_policy and otr_ignore and changed some log levels.

Ximin Luo infinity0 at moszumanska.debian.org
Sat Aug 22 12:41:25 UTC 2015


This is an automated email from the git hooks/post-receive script.

infinity0 pushed a commit to branch debian
in repository irssi-plugin-otr.

commit 029d5705a61fdd5442deb95dd78bde308cabf36d
Author: Uli Meis <a.sporto+bee at gmail.com>
Date:   Mon Jan 19 15:50:21 2009 +0100

    added /set otr_policy and otr_ignore and changed some log levels.
---
 ChangeLog   |  8 +++++++
 formats.txt |  2 --
 otr.c       | 24 +++++++++++++++----
 otr.h       | 16 +++++++++++++
 otr_ops.c   | 38 ++++++++++++++++++++++++-----
 otrutil.c   | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 6 files changed, 153 insertions(+), 14 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index e9e16c0..7ecc1ab 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Version 0.3
+	* added settings otr_policy and otr_ignore
+	* fixed two segfault sources
+	* key generation now operates on a temp file
+	* commands now take an optional nick at server argument
+	  (for single message window users)
+	* changed loglevel of otr_log (heartbeats) and otr_finish
+
 Version 0.2
 
 	* fixed multiple server problem.
diff --git a/formats.txt b/formats.txt
index 87c80aa..19a19cf 100644
--- a/formats.txt
+++ b/formats.txt
@@ -81,8 +81,6 @@ ctx_fps_no	%s %rnot authenticated%n
 ctx_fps_smp	%s %gauthenticated%n via shared secret (SMP)
 ctx_fps_man	%s %gauthenticated%n manually
 ctx_noctxs	No active OTR contexts found
-Nickignore
-nickignore	xmlconsole[0-9]*
 Statusbar
 st_plaintext	{sb plaintext}
 st_untrusted	{sb %rOTR(not auth'ed)%n}
diff --git a/otr.c b/otr.c
index dc3c5f9..1fc626e 100644
--- a/otr.c
+++ b/otr.c
@@ -22,7 +22,7 @@
 int debug = FALSE;
 
 #ifdef HAVE_GREGEX_H
-GRegex *regex_nickignore;
+GRegex *regex_nickignore = NULL;
 #endif
 
 /*
@@ -268,15 +268,22 @@ static void otr_statusbar(SBAR_ITEM_REC *item, int get_size_only)
 		formatnum ? formats[formatnum].def : ""," ",FALSE);
 }
 
+static void read_settings(void)
+{
+	otr_setpolicies(settings_get_str("otr_policy"));
+#ifdef HAVE_GREGEX_H
+	if (regex_nickignore)
+		g_regex_unref(regex_nickignore);
+	regex_nickignore = g_regex_new(settings_get_str("otr_ignore"),0,0,NULL);
+#endif
+
+}
+
 /*
  * irssi init()
  */
 void otr_init(void)
 {
-#ifdef HAVE_GREGEX_H
-	regex_nickignore = g_regex_new(formats[TXT_NICKIGNORE].def,0,0,NULL);
-#endif
-
 	module_register(MODULE_NAME, "core");
 
 	theme_register(formats);
@@ -299,6 +306,11 @@ void otr_init(void)
 	command_bind("otr contexts", NULL, (SIGNAL_FUNC) cmd_contexts);
 	command_bind("otr version", NULL, (SIGNAL_FUNC) cmd_version);
 
+	settings_add_str("otr", "otr_policy","*@localhost opportunistic,*@im.bitlbee.org opportunistic");
+	settings_add_str("otr", "otr_ignore","xmlconsole[0-9]*");
+	read_settings();
+	signal_add("setup changed", (SIGNAL_FUNC) read_settings);
+
 	statusbar_item_register("otr", NULL, otr_statusbar);
 
 	statusbar_items_redraw("window");
@@ -329,6 +341,8 @@ void otr_deinit(void)
 	command_unbind("otr contexts", (SIGNAL_FUNC) cmd_contexts);
 	command_unbind("otr version", (SIGNAL_FUNC) cmd_version);
 
+	signal_remove("setup changed", (SIGNAL_FUNC) read_settings);
+
 	statusbar_item_unregister("otr");
 
 	otrlib_deinit();
diff --git a/otr.h b/otr.h
index 8f2fca3..0f0bd76 100644
--- a/otr.h
+++ b/otr.h
@@ -39,6 +39,7 @@
 #include <fe-common/core/fe-windows.h>
 #include <fe-common/core/module-formats.h>
 #include <core/modules.h>
+#include <core/settings.h>
 
 /* copied over, see FS#535 */
 #include <fe-text/statusbar.h>
@@ -99,6 +100,14 @@ struct ctxlist_ {
 	struct ctxlist_ *next;
 };
 
+/* policy list generated from /set otr_policy */
+
+struct plistentry {
+	char *user;
+	char *server;
+	OtrlPolicy policy;
+};
+
 /* used by the logging functions below */
 extern int debug;
 
@@ -107,6 +116,7 @@ extern int debug;
 int otrlib_init();
 void otrlib_deinit();
 void otr_initops();
+void otr_setpolicies(const char *policies);
 
 /* basic send/receive/status stuff */
 
@@ -148,6 +158,12 @@ void otr_writefps();
 #define otr_notice(server,nick,formatnum,...) \
 	printformat(server,nick,MSGLEVEL_MSGS, formatnum, ## __VA_ARGS__)
 
+#define otr_infost(formatnum,...) \
+	printformat(NULL,NULL,MSGLEVEL_CRAP, formatnum, ## __VA_ARGS__)
+
+#define otr_info(server,nick,formatnum,...) \
+	printformat(server,nick,MSGLEVEL_CRAP, formatnum, ## __VA_ARGS__)
+
 #define otr_debug(server,nick,formatnum,...) { \
 	if (debug) \
 		printformat(server,nick, \
diff --git a/otr_ops.c b/otr_ops.c
index 7943941..cc87836 100644
--- a/otr_ops.c
+++ b/otr_ops.c
@@ -21,17 +21,43 @@
 
 OtrlMessageAppOps otr_ops;
 extern OtrlUserState otr_state;
+extern GSList *plist;
+
+OtrlPolicy IO_DEFAULT_POLICY =
+	OTRL_POLICY_MANUAL|OTRL_POLICY_WHITESPACE_START_AKE;
 
 /*
- * Policy is currently fixed as OTR lib default (meaning opportunistic).
+ * Return policy for given context based on the otr_policy /setting
  */
 OtrlPolicy ops_policy(void *opdata, ConnContext *context)
 {
 	struct co_info *coi = context->app_data;
+	char *server = strchr(context->accountname,'@')+1;
+	OtrlPolicy op = IO_DEFAULT_POLICY;
+	GSList *pl = plist;
+
+	if (!plist)
+		return op;
+
+	do {
+		struct plistentry *ple = pl->data;
+
+		if (!(*ple->user=='*')&&
+		    (strcmp(ple->user,context->username)!=0))
+			continue;
+		if (!(*ple->server=='*')&&
+		    (strcmp(ple->server,server)!=0))
+			continue;
 
-	return coi && coi->finished ?
-		OTRL_POLICY_MANUAL|OTRL_POLICY_WHITESPACE_START_AKE : 
-		OTRL_POLICY_DEFAULT;
+		op = ple->policy;
+
+	} while ((pl = g_slist_next(pl)));
+
+	if (coi && coi->finished &&
+	    (op == OTRL_POLICY_OPPORTUNISTIC ||
+	     op == OTRL_POLICY_ALWAYS))
+		op = OTRL_POLICY_MANUAL|OTRL_POLICY_WHITESPACE_START_AKE;
+	return op;
 }
 
 /*
@@ -120,7 +146,7 @@ int ops_display_msg(void *opdata, const char *accountname,
 		    const char *protocol, const char *username, 
 		    const char *msg)
 {
-	ConnContext *co = otr_getcontext(accountname,username,FALSE,NULL);
+	ConnContext *co = otr_getcontext(accountname,username,FALSE,opdata);
 	SERVER_REC *server = opdata;
 	struct co_info *coi;
 
@@ -197,7 +223,7 @@ void ops_still_secure(void *opdata, ConnContext *context, int is_reply)
  */
 void ops_log(void *opdata, const char *message)
 {
-	otr_noticest(TXT_OPS_LOG,message);
+	otr_infost(TXT_OPS_LOG,message);
 }
 
 /*
diff --git a/otrutil.c b/otrutil.c
index f0f531a..17262ae 100644
--- a/otrutil.c
+++ b/otrutil.c
@@ -24,6 +24,11 @@
 OtrlUserState otr_state = NULL;
 extern OtrlMessageAppOps otr_ops;
 static int otrinited = FALSE;
+GSList *plist = NULL;
+
+#ifdef HAVE_GREGEX_H
+GRegex *regex_policies;
+#endif
 
 /*
  * init otr lib.
@@ -45,6 +50,12 @@ int otrlib_init()
 
 	otr_initops();
 
+#ifdef HAVE_GREGEX_H
+	regex_policies = 
+		g_regex_new("([^ @]*@[^ @]*) (never|manual|handlews|opportunistic|always)"
+			    "(,|$)",0,0,NULL);
+#endif
+
 	return otr_state==NULL;
 }
 
@@ -60,6 +71,13 @@ void otrlib_deinit()
 	}
 
 	keygen_abort(TRUE);
+
+	otr_setpolicies("");
+
+#ifdef HAVE_GREGEX_H
+	g_regex_unref(regex_policies);
+#endif
+
 }
 
 
@@ -324,7 +342,7 @@ void otr_finish(SERVER_REC *server, char *nick, const char *peername, int inquer
 	otrl_message_disconnect(otr_state,&otr_ops,server,accname,
 				PROTOCOLID,nick);
 
-	otr_notice(inquery ? server : NULL,
+	otr_info(inquery ? server : NULL,
 		   inquery ? nick : NULL,
 		   TXT_CMD_FINISH,nick);
 
@@ -702,3 +720,62 @@ char *otr_receive(SERVER_REC *server, const char *msg,const char *from)
 
 	return newmessage ? : (char*)msg;
 }
+
+void otr_setpolicies(const char *policies)
+{
+#ifdef HAVE_GREGEX_H
+	GMatchInfo *match_info;
+
+	if (plist) {
+		GSList *p = plist;
+		do {
+			struct plistentry *ple = p->data;
+			g_free(ple->user);
+			g_free(p->data);
+		} while ((p = g_slist_next(p)));
+
+		g_slist_free(plist);
+		plist = NULL;
+	}
+
+	g_regex_match(regex_policies,policies,0,&match_info);
+
+	while(g_match_info_matches(match_info)) {
+		struct plistentry *ple = (struct plistentry *)g_malloc0(sizeof(struct plistentry));
+		char *name = g_match_info_fetch(match_info, 1);
+		char *pol = g_match_info_fetch(match_info, 2);
+		char *server = strchr(name,'@');
+
+		*server++ = '\0';
+
+		ple->user = name;
+		ple->server = server;
+		
+		switch (*pol) {
+		case 'n':
+			ple->policy = OTRL_POLICY_NEVER;
+			break;
+		case 'm':
+			ple->policy = OTRL_POLICY_MANUAL;
+			break;
+		case 'h':
+			ple->policy = OTRL_POLICY_MANUAL|OTRL_POLICY_WHITESPACE_START_AKE;
+			break;
+		case 'o':
+			ple->policy = OTRL_POLICY_OPPORTUNISTIC;
+			break;
+		case 'a':
+			ple->policy = OTRL_POLICY_ALWAYS;
+			break;
+		}
+
+		plist = g_slist_append(plist,ple);
+
+		g_free(pol);
+
+		g_match_info_next(match_info, NULL);
+	}
+
+	g_match_info_free(match_info);
+#endif
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/irssi-plugin-otr.git



More information about the Pkg-privacy-commits mailing list