[Pkg-privacy-commits] [irssi-plugin-otr] 71/267: Better status change handling and thereby a signal for irssi.

Ximin Luo infinity0 at moszumanska.debian.org
Sat Aug 22 12:41:29 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 0bf59375eedd9040262ad866a4e18c01f9fcce7f
Author: Uli Meis <a.sporto+bee at gmail.com>
Date:   Fri Feb 20 19:26:33 2009 +0100

    Better status change handling and thereby a signal for irssi.
---
 formats.txt           |  5 ++---
 io_util.c             | 52 ++++++++++++++++++++++++++++++++++++++++++
 irssi/irssi_otr.c     | 16 ++++++++++++-
 otr.h                 | 39 ++++++++++++++++++++++++++++++++
 otr_ops.c             |  4 +++-
 otr_util.c            | 62 ++++++++++++++++++++++++++++++++++++---------------
 weechat/weechat_otr.h |  1 -
 xchat/xchat_otr.h     |  1 -
 8 files changed, 155 insertions(+), 25 deletions(-)

diff --git a/formats.txt b/formats.txt
index e953a22..9778174 100644
--- a/formats.txt
+++ b/formats.txt
@@ -88,9 +88,8 @@ st_plaintext	{sb plaintext}
 st_untrusted	{sb %rOTR(not auth'ed)%n}
 st_trust_smp	{sb %gOTR%n}
 st_trust_manual	{sb %gOTR%n}
-st_smp_wait_2	{sb {hilight awaiting auth reply...}}
-st_smp_have_2	{sb {hilight finalizing auth... (won't happen with libotr 3.1(bug), ask the other guy to initiate)}}
-st_smp_failed	{sb {hilight auth failed}}
+st_smp_incoming	{sb {hilight incoming auth request...}}
+st_smp_outgoing	{sb {hilight awaiting auth reply...}}
 st_smp_finalize	{sb {hilight finalizing auth...}}
 st_smp_unknown	{sb {hilight unknown auth state!}}
 st_finished	{sb finished}
diff --git a/io_util.c b/io_util.c
index e2548b1..323b91a 100644
--- a/io_util.c
+++ b/io_util.c
@@ -19,6 +19,24 @@
 
 #include "otr.h"
 
+char *otr_status_txt[] = {
+	"FINISHED",
+	"TRUST_MANUAL",
+	"TRUST_SMP",
+	"SMP_ABORT",
+	"SMP_STARTED",
+	"SMP_RESPONDED",
+	"SMP_INCOMING",
+	"SMP_FINALIZE",
+	"SMP_ABORTED",
+	"SMP_PEER_FINISHED",
+	"SMP_FAILED",
+	"SMP_SUCCESS",
+	"GONE_SECURE",
+	"GONE_INSECURE",
+	"CTX_UPDATE"
+};
+
 int extract_nick(char *nick, char *line)
 {
 	char *excl;
@@ -215,3 +233,37 @@ void io_explode_args(const char *args, char ***argvp, char ***argv_eolp, int *ar
 	*argv_eolp = argv_eol;
 	*argcp = argc;
 }
+
+/*
+ * Get a format describing the OTR status of this conversation.
+ */
+int otr_getstatus_format(IRC_CTX *ircctx, char *nick)
+{
+	int status = otr_getstatus(ircctx,nick);
+
+	if (status&(IO_ST_SMP_ONGOING)) {
+		/* we don't care about the trust level in that case */
+		status = status & IO_ST_SMP_ONGOING;
+	}
+
+	switch (status) {
+	case IO_ST_PLAINTEXT:
+		return TXT_ST_PLAINTEXT;
+	case IO_ST_FINISHED:
+		return TXT_ST_FINISHED;
+	case IO_ST_UNTRUSTED:
+		return TXT_ST_UNTRUSTED;
+	case IO_ST_SMP_INCOMING:
+		return TXT_ST_SMP_INCOMING;
+	case IO_ST_SMP_OUTGOING:
+		return TXT_ST_SMP_OUTGOING;
+	case IO_ST_SMP_FINALIZE:
+		return TXT_ST_SMP_FINALIZE;
+	case IO_ST_TRUST_MANUAL:
+		return TXT_ST_TRUST_MANUAL;
+	case IO_ST_TRUST_SMP:
+		return TXT_ST_TRUST_SMP;
+	default:
+		return TXT_ST_SMP_UNKNOWN;
+	}
+}
diff --git a/irssi/irssi_otr.c b/irssi/irssi_otr.c
index 7301d3d..1f0df0e 100644
--- a/irssi/irssi_otr.c
+++ b/irssi/irssi_otr.c
@@ -21,10 +21,17 @@
 
 int debug = FALSE;
 
+static const char *signal_args_otr_event[] = {
+	"iobject", "string", "string", "NULL" };
+
 #ifdef HAVE_GREGEX_H
 GRegex *regex_nickignore = NULL;
 #endif
 
+/* need this to decode arguments in perl signal handlers. Maybe irssi should
+ * install perl/perl-signals.h which is where this definition comes from? */
+void perl_signal_register(const char *signal, const char **args);
+
 static IOUSTATE *ioustate;
 
 void irc_send_message(IRC_CTX *ircctx, const char *recipient, char *msg) {
@@ -134,7 +141,7 @@ static void otr_statusbar(struct SBAR_ITEM_REC *item, int get_size_only)
 	int formatnum=0;
 
 	if (query&&query->server&&query->server->connrec)
-		formatnum = otr_getstatus(query->server,query->name);
+		formatnum = otr_getstatus_format(query->server,query->name);
 
 	statusbar_item_default_handler(
 		item, 
@@ -164,6 +171,12 @@ static void read_settings(void)
 
 }
 
+void otr_status_change(IRC_CTX *ircctx, const char *nick, int event)
+{
+	statusbar_items_redraw("otr");
+	signal_emit("otr event",3,ircctx,nick,otr_status_txt[event]);
+}
+
 /*
  * irssi init()
  */
@@ -198,6 +211,7 @@ void otr_init(void)
 
 	statusbar_items_redraw("window");
 
+	perl_signal_register("otr event",signal_args_otr_event);
 }
 
 /*
diff --git a/otr.h b/otr.h
index d8b91b3..81229be 100644
--- a/otr.h
+++ b/otr.h
@@ -140,6 +140,43 @@ struct ctxlist_ {
 	struct ctxlist_ *next;
 };
 
+/* returned by otr_getstatus */
+enum { 
+	IO_ST_PLAINTEXT,
+	IO_ST_FINISHED,
+	IO_ST_SMP_INCOMING,
+	IO_ST_SMP_OUTGOING,
+	IO_ST_SMP_FINALIZE,
+	IO_ST_UNKNOWN,
+	IO_ST_UNTRUSTED=32,
+	IO_ST_TRUST_MANUAL=64,
+	IO_ST_TRUST_SMP=128,
+	IO_ST_SMP_ONGOING=
+		IO_ST_SMP_INCOMING|IO_ST_SMP_OUTGOING|IO_ST_SMP_FINALIZE
+};
+
+/* given to otr_status_change */
+enum {
+	IO_STC_FINISHED,
+	IO_STC_TRUST_MANUAL,
+	IO_STC_TRUST_SMP,
+	IO_STC_SMP_ABORT,
+	IO_STC_SMP_STARTED,
+	IO_STC_SMP_RESPONDED,
+	IO_STC_SMP_INCOMING,
+	IO_STC_SMP_FINALIZE,
+	IO_STC_SMP_ABORTED,
+	IO_STC_SMP_PEER_FINISHED,
+	IO_STC_SMP_FAILED,
+	IO_STC_SMP_SUCCESS,
+	IO_STC_GONE_SECURE,
+	IO_STC_GONE_INSECURE,
+	IO_STC_CTX_UPDATE
+};
+
+/* the above as text for scripting */
+extern char *otr_status_txt[];
+
 /* policy list generated from /set otr_policy */
 
 struct plistentry {
@@ -151,6 +188,7 @@ struct plistentry {
 extern int debug;
 
 void irc_send_message(IRC_CTX *ircctx, const char *recipient, char *msg);
+void otr_status_change(IRC_CTX *ircctx, const char *nick, int event);
 IRC_CTX *ircctx_by_peername(const char *peername, char *nick);
 
 /* init stuff */
@@ -200,5 +238,6 @@ extern struct _cmds cmds[];
 
 int cmd_generic(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
 	    char *target);
+int otr_getstatus_format(IRC_CTX *ircctx, char *nick);
 
 void io_explode_args(const char *args, char ***argvp, char ***argv_eolp, int *argcp);
diff --git a/otr_ops.c b/otr_ops.c
index c3775e6..df7d24b 100644
--- a/otr_ops.c
+++ b/otr_ops.c
@@ -192,6 +192,7 @@ void ops_secure(void *opdata, ConnContext *context)
 
 	otr_notice(coi->ircctx,
 		   context->username,TXT_OPS_SEC);
+	otr_status_change(coi->ircctx,context->username,IO_STC_GONE_SECURE);
 	if (*trust!='\0')
 		return;
 
@@ -218,6 +219,7 @@ void ops_insecure(void *opdata, ConnContext *context)
 	struct co_info *coi = context->app_data;
 	otr_notice(coi->ircctx,
 		   context->username,TXT_OPS_INSEC);
+	otr_status_change(coi->ircctx,context->username,IO_STC_GONE_INSECURE);
 }
 
 /*
@@ -256,7 +258,7 @@ int ops_max_msg(void *opdata, ConnContext *context)
  */
 void ops_up_ctx_list(void *opdata)
 {
-	statusbar_items_redraw("otr");
+	otr_status_change(opdata,NULL,IO_STC_CTX_UPDATE);
 }
 
 /*
diff --git a/otr_util.c b/otr_util.c
index ddb08c3..62aeedc 100644
--- a/otr_util.c
+++ b/otr_util.c
@@ -277,37 +277,49 @@ int otr_getstatus(IRC_CTX *ircctx, char *nick)
 	IRCCTX_ACCNAME(accname,ircctx);
 
 	if (!(co = otr_getcontext(accname,nick,FALSE,ircctx))) {
-		return 0;
+		return IO_ST_PLAINTEXT;
 	}
 
 	coi = co->app_data;
 
 	switch (co->msgstate) {
 	case OTRL_MSGSTATE_PLAINTEXT:
-		return TXT_ST_PLAINTEXT;
+		return IO_ST_PLAINTEXT;
 	case OTRL_MSGSTATE_ENCRYPTED: {
 		char *trust = co->active_fingerprint->trust;
 		int ex = co->smstate->nextExpected;
-
-		if (trust&&(*trust!='\0'))
-			return strcmp(trust,"smp")==0 ? TXT_ST_TRUST_SMP : TXT_ST_TRUST_MANUAL;
+		int code=0;
 
 		switch (ex) {
 		case OTRL_SMP_EXPECT1:
-			return TXT_ST_UNTRUSTED;
+			if (coi->received_smp_init)
+				code = IO_ST_SMP_INCOMING;
+			break;
 		case OTRL_SMP_EXPECT2:
-			return TXT_ST_SMP_WAIT_2;
+			code = IO_ST_SMP_OUTGOING;
+			break;
 		case OTRL_SMP_EXPECT3: 
 		case OTRL_SMP_EXPECT4:
-			return TXT_ST_SMP_FINALIZE;
+			code = IO_ST_SMP_FINALIZE;
+			break;
 		default:
-			return TXT_ST_SMP_UNKNOWN;
+			otr_logst(MSGLEVEL_CRAP,"BUG Found! Please write us a mail and describe how you got here");
+			return IO_ST_UNKNOWN;
 		}
+
+		if (trust&&(*trust!='\0'))
+			code |= strcmp(trust,"smp")==0 ? IO_ST_TRUST_SMP :
+				IO_ST_TRUST_MANUAL;
+		else
+			code |= IO_ST_UNTRUSTED;
+
+		return code;
 	}
 	case OTRL_MSGSTATE_FINISHED:
-		return TXT_ST_FINISHED;
+		return IO_ST_FINISHED;
 	default:
-		return TXT_ST_UNKNOWN;
+		otr_logst(MSGLEVEL_CRAP,"BUG Found! Please write us a mail and describe how you got here");
+		return IO_ST_UNKNOWN;
 	}
 }
 
@@ -339,6 +351,7 @@ void otr_finish(IRC_CTX *ircctx, char *nick, const char *peername, int inquery)
 
 	otrl_message_disconnect(IRCCTX_IO_US(ircctx)->otr_state,&otr_ops,ircctx,accname,
 				PROTOCOLID,nick);
+	otr_status_change(ircctx,nick,IO_STC_FINISHED);
 
 	if (inquery) {
 		otr_info(ircctx,nick,TXT_CMD_FINISH,nick,IRCCTX_ADDR(ircctx));
@@ -370,6 +383,7 @@ void otr_finishall(IOUSTATE *ioustate)
 					context->accountname,
 					PROTOCOLID,
 					context->username);
+		otr_status_change(coi->ircctx,context->username,IO_STC_FINISHED);
 
 		otr_infost(TXT_CMD_FINISH,context->username,
 			   IRCCTX_ADDR(coi->ircctx));
@@ -406,6 +420,7 @@ void otr_trust(IRC_CTX *ircctx, char *nick, const char *peername)
 	}
 
 	otrl_context_set_trust(co->active_fingerprint,"manual");
+	otr_status_change(ircctx,nick,IO_STC_TRUST_MANUAL);
 
 	coi = co->app_data;
 	coi->smp_failed = FALSE;
@@ -431,6 +446,7 @@ void otr_abort_auth(ConnContext *co, IRC_CTX *ircctx, const char *nick)
 		   TXT_AUTH_ABORTED);
 
 	otrl_message_abort_smp(IRCCTX_IO_US(ircctx)->otr_state,&otr_ops,ircctx,co);
+	otr_status_change(ircctx,nick,IO_STC_SMP_ABORT);
 }
 
 /*
@@ -508,7 +524,7 @@ void otr_auth(IRC_CTX *ircctx, char *nick, const char *peername, const char *sec
 		}
 	}
 
-	if (!coi->received_smp_init)
+	if (!coi->received_smp_init) {
 		otrl_message_initiate_smp(
 			IRCCTX_IO_US(ircctx)->otr_state, 
 			&otr_ops,
@@ -516,7 +532,8 @@ void otr_auth(IRC_CTX *ircctx, char *nick, const char *peername, const char *sec
 			co,
 			(unsigned char*)secret,
 			strlen(secret));
-	else
+		otr_status_change(ircctx,nick,IO_STC_SMP_STARTED);
+	} else {
 		otrl_message_respond_smp(
 			IRCCTX_IO_US(ircctx)->otr_state,
 			&otr_ops,
@@ -524,14 +541,14 @@ void otr_auth(IRC_CTX *ircctx, char *nick, const char *peername, const char *sec
 			co,
 			(unsigned char*)secret,
 			strlen(secret));
+		otr_status_change(ircctx,nick,IO_STC_SMP_RESPONDED);
+	}
 
 	otr_notice(ircctx,nick,
 		   coi->received_smp_init ?
 		   TXT_AUTH_RESPONDING :
 		   TXT_AUTH_INITIATED);
 
-	statusbar_items_redraw("otr");
-
 }
 
 /* 
@@ -554,6 +571,7 @@ void otr_handle_tlvs(OtrlTLV *tlvs, ConnContext *co,
 			otr_notice(ircctx,from,TXT_AUTH_PEER,
 				   from);
 			coi->received_smp_init = TRUE;
+			otr_status_change(ircctx,from,IO_STC_SMP_INCOMING);
 		}
 	}
 
@@ -569,6 +587,7 @@ void otr_handle_tlvs(OtrlTLV *tlvs, ConnContext *co,
 				   TXT_AUTH_PEER_REPLIED,
 				   from);
 			co->smstate->nextExpected = OTRL_SMP_EXPECT4;
+			otr_status_change(ircctx,from,IO_STC_SMP_FINALIZE);
 		}
 	}
 
@@ -584,10 +603,12 @@ void otr_handle_tlvs(OtrlTLV *tlvs, ConnContext *co,
 			if (trust&&(*trust!='\0')) {
 				otr_notice(ircctx,from,
 					   TXT_AUTH_SUCCESSFUL);
+				otr_status_change(ircctx,from,IO_STC_SMP_SUCCESS);
 			} else {
 				otr_notice(ircctx,from,
 					   TXT_AUTH_FAILED);
 				coi->smp_failed = TRUE;
+				otr_status_change(ircctx,from,IO_STC_SMP_FAILED);
 			}
 			co->smstate->nextExpected = OTRL_SMP_EXPECT1;
 			coi->received_smp_init = FALSE;
@@ -606,25 +627,30 @@ void otr_handle_tlvs(OtrlTLV *tlvs, ConnContext *co,
 			if (trust&&(*trust!='\0')) {
 				otr_notice(ircctx,from,
 					   TXT_AUTH_SUCCESSFUL);
+				otr_status_change(ircctx,from,IO_STC_SMP_SUCCESS);
 			} else {
 				/* unreachable since 4 is never sent out on
 				 * error */
 				otr_notice(ircctx,from,
 					   TXT_AUTH_FAILED);
 				coi->smp_failed = TRUE;
+				otr_status_change(ircctx,from,IO_STC_SMP_FAILED);
 			}
 			co->smstate->nextExpected = OTRL_SMP_EXPECT1;
 			coi->received_smp_init = FALSE;
 		}
 	}
-	if (abort)
+	if (abort) {
 		otr_abort_auth(co,ircctx,from);
+		otr_status_change(ircctx,from,IO_STC_SMP_ABORTED);
+	}
 
 	tlv = otrl_tlv_find(tlvs, OTRL_TLV_DISCONNECTED);
-	if (tlv)
+	if (tlv) {
+		otr_status_change(ircctx,from,IO_STC_SMP_PEER_FINISHED);
 		otr_notice(ircctx,from,TXT_PEER_FINISHED,from);
+	}
 
-	statusbar_items_redraw("otr");
 }
 
 /*
diff --git a/weechat/weechat_otr.h b/weechat/weechat_otr.h
index b6ffc90..9e4574c 100644
--- a/weechat/weechat_otr.h
+++ b/weechat/weechat_otr.h
@@ -50,7 +50,6 @@ extern int set_finishonunload;
 void cmd_set(IOUSTATE *ioustate,IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
 	    char *target);
 
-#define statusbar_items_redraw(name) ;
 #define get_client_config_dir() weechat_info_get("weechat_dir",NULL)
 
 void printformat(IRC_CTX *ircctx, const char *nick, int lvl, int fnum, ...);
diff --git a/xchat/xchat_otr.h b/xchat/xchat_otr.h
index 9e54b4c..a8f3db3 100644
--- a/xchat/xchat_otr.h
+++ b/xchat/xchat_otr.h
@@ -54,7 +54,6 @@ extern int set_finishonunload;
 void cmd_set(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, 
 	     char *argv[], char *argv_eol[], char *target);
 
-#define statusbar_items_redraw(name) ;
 #define get_client_config_dir() xchat_get_info(ph,"xchatdir")
 
 void printformat(IRC_CTX *ircctx, const char *nick, int lvl, int fnum, ...);

-- 
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