[Pkg-privacy-commits] [irssi-plugin-otr] 96/267: Create cmd.c/.h for irssi commands

Ximin Luo infinity0 at moszumanska.debian.org
Sat Aug 22 12:26:21 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 9ec137170f3a3a522292eadc9ca76317cac0f927
Author: David Goulet <dgoulet at ev0ke.net>
Date:   Sat Nov 3 17:50:14 2012 -0400

    Create cmd.c/.h for irssi commands
    
    Move around code and rename to clarify things.
    
    Signed-off-by: David Goulet <dgoulet at ev0ke.net>
---
 src/Makefile.am        |   5 +-
 src/cmd.c              | 258 ++++++++++++++++++++++++++++++++++++
 src/{key.h => cmd.h}   |  25 ++--
 src/io_util.c          | 349 -------------------------------------------------
 src/module.c           |  10 +-
 src/otr-ops.c          |  20 +++
 src/otr.c              |  58 ++++++++
 src/otr.h              |  28 +---
 src/utils.c            |  71 ++++++++++
 src/{key.h => utils.h} |  23 ++--
 10 files changed, 441 insertions(+), 406 deletions(-)

diff --git a/src/Makefile.am b/src/Makefile.am
index dd5fec6..ec795e2 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -15,5 +15,6 @@ INCLUDES = -I$(top_srcdir)/src $(IRSSI_INCLUDE)
 
 lib_LTLIBRARIES = libotr.la
 
-libotr_la_SOURCES = key.c key.h otr.c otr-ops.c io_set.c io_util.c \
-					otr.h module.c irssi_otr.h otr-formats.c otr-formats.h
+libotr_la_SOURCES = key.c key.h cmd.c cmd.h otr.c otr-ops.c io_set.c \
+					utils.h utils.c otr.h module.c irssi_otr.h \
+					otr-formats.c otr-formats.h
diff --git a/src/cmd.c b/src/cmd.c
new file mode 100644
index 0000000..c198075
--- /dev/null
+++ b/src/cmd.c
@@ -0,0 +1,258 @@
+/*
+ * Off-the-Record Messaging (OTR) modules for IRC
+ *
+ * Copyright (C) 2008  Uli Meis <a.sporto+bee at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 51
+ * Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA
+ */
+
+#include "cmd.h"
+#include "key.h"
+
+/*
+ * /otr debug
+ */
+static void _cmd_debug(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[],
+		char *argv_eol[], char *target)
+{
+	debug = !debug;
+	otr_noticest(debug ? TXT_CMD_DEBUG_ON : TXT_CMD_DEBUG_OFF);
+}
+
+/*
+ * /otr version 
+ */
+static void _cmd_version(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[],
+		char *argv_eol[], char *target)
+{
+	otr_noticest(TXT_CMD_VERSION, IRCOTR_VERSION);
+}
+
+/*
+ * /otr help 
+ */
+static void _cmd_help(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[],
+		char *argv_eol[], char *target)
+{
+	otr_log(ircctx, target, MSGLEVEL_CRAP, otr_help);
+}
+
+/*
+ * /otr finish 
+ */
+static void _cmd_finish(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[],
+		char *argv_eol[], char *target)
+{
+	if (argc) {
+		otr_finish(NULL, NULL, argv[0], TRUE);
+	} else if (ircctx && target) {
+		otr_finish(ircctx, target, NULL, TRUE);
+	} else {
+		otr_noticest(TXT_CMD_QNOTFOUND);
+	}
+}
+
+/*
+ * /otr trust
+ */
+static void _cmd_trust(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[],
+		char *argv_eol[], char *target)
+{
+	if (argc) {
+		otr_trust(NULL, NULL, argv[0]);
+	} else if (ircctx && target) {
+		otr_trust(ircctx, target, NULL);
+	} else {
+		otr_noticest(TXT_CMD_QNOTFOUND);
+	}
+}
+
+/*
+ * /otr authabort
+ */
+static void _cmd_authabort(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc,
+		char *argv[], char *argv_eol[], char *target)
+{
+	if (argc) {
+		otr_authabort(NULL, NULL, argv[0]);
+	} else if (ircctx && target) {
+		otr_authabort(ircctx, target, NULL);
+	} else {
+		otr_noticest(TXT_CMD_QNOTFOUND);
+	}
+}
+
+/*
+ * /otr genkey
+ */
+static void _cmd_genkey(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[],
+		char *argv_eol[], char *target)
+{
+	if (argc) {
+		if (strcmp(argv[0], "abort") == 0) {
+			key_generation_abort(ioustate, FALSE);
+		} else if (strchr(argv[0], '@')) {
+			key_generation_run(ioustate, argv[0]);
+		} else {
+			otr_noticest(TXT_KG_NEEDACC);
+		}
+	} else {
+		otr_noticest(TXT_KG_NEEDACC);
+	}
+}
+
+/*
+ * Generic internal function for /otr auth command.
+ */
+static void _auth(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc,
+		char *argv[], char *argv_eol[], char *target, int qanda)
+{
+	char *accountname = NULL, *question = NULL, *secret;
+
+	/* have args? */
+	if (argc < (qanda ? 2 : 1)) {
+		otr_notice(ircctx, target, TXT_CMD_AUTH);
+		goto end;
+	}
+
+	/* have buddy? */
+	if (!(ircctx && target)) {
+		accountname = strchr(argv[0], '@');
+		if (!accountname) {
+			otr_noticest(TXT_CMD_QNOTFOUND);
+			goto end;
+		}
+		ircctx = NULL;
+		target = NULL;
+		argv++; argv_eol++; argc--;
+	}
+
+	/* have question? */
+	if (qanda) {
+		question = argv[0];
+		argv++; argv_eol++; argc--;
+	}
+
+	secret = argv_eol[0];
+
+	otr_auth(ircctx, target, accountname, question, secret);
+
+end:
+	return;
+}
+
+/*
+ * /otr authq (Authentication with a question)
+ */
+static void _cmd_authq(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc,
+		char *argv[], char *argv_eol[], char *target)
+{
+	_auth(ioustate, ircctx, argc, argv, argv_eol, target, TRUE);
+}
+
+/*
+ * /otr auth
+ */
+static void _cmd_auth(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[],
+		char *argv_eol[], char *target)
+{
+	_auth(ioustate, ircctx, argc, argv, argv_eol, target, FALSE);
+}
+
+/*
+ * /otr contexts
+ */
+static void _cmd_contexts(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc,
+		char *argv[], char *argv_eol[], char *target)
+{
+	struct ctxlist_ *ctxlist = otr_contexts(ioustate), *ctxnext = ctxlist;
+	struct fplist_ *fplist, *fpnext;
+
+	if (!ctxlist) {
+		otr_infost(TXT_CTX_NOCTXS);
+	}
+
+	while (ctxlist) {
+		otr_infost(TXT_CTX_CTX_UNENCRYPTED + ctxlist->state, ctxlist->username,
+				ctxlist->accountname);
+
+		fplist = ctxlist->fplist;
+		while (fplist) {
+			otr_infost(TXT_CTX_FPS_NO + fplist->authby, fplist->fp);
+			fplist = fplist->next;
+		}
+		ctxlist = ctxlist->next;
+	}
+	while ((ctxlist = ctxnext)) {
+		ctxnext = ctxlist->next;
+		fpnext = ctxlist->fplist;
+		while ((fplist = fpnext)) {
+			fpnext = fplist->next;
+			g_free(fplist->fp);
+			g_free(fplist);
+		}
+		g_free(ctxlist);
+	}
+}
+
+static struct irssi_commands cmds[] = {
+	{ "version", _cmd_version },
+	{ "debug", _cmd_debug },
+	{ "help", _cmd_help },
+	{ "finish", _cmd_finish },
+	{ "trust", _cmd_trust },
+	{ "authabort", _cmd_authabort },
+	{ "auth", _cmd_auth },
+	{ "authq", _cmd_authq },
+	{ "genkey", _cmd_genkey },
+	{ "contexts", _cmd_contexts },
+	{ NULL, NULL },
+	{ NULL, NULL }
+};
+
+/*
+ * Entry point for all other commands.
+ *
+ * Return TRUE if command exist and is executed else FALSE.
+ */
+int cmd_generic(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[],
+		char *argv_eol[], char *target)
+{
+	char *cmd;
+	struct irssi_commands *commands = cmds;
+
+	if (!argc) {
+		otr_noticest(TXT_CMD_OTR);
+		goto done;
+	}
+
+	cmd = argv[0];
+
+	argv++;
+	argv_eol++;
+	argc--;
+
+	do {
+		if (strncmp(commands->name, cmd, strlen(commands->name)) == 0) {
+			commands->func(ioustate, ircctx, argc, argv, argv_eol, target);
+			goto done;
+		}
+	} while ((++commands)->name);
+
+	return FALSE;
+
+done:
+	return TRUE;
+}
diff --git a/src/key.h b/src/cmd.h
similarity index 58%
copy from src/key.h
copy to src/cmd.h
index ae89382..5ff9c69 100644
--- a/src/key.h
+++ b/src/cmd.h
@@ -1,5 +1,7 @@
 /*
- * Copyright (C) 2012 - David Goulet <dgoulet at ev0ke.net>
+ * Off-the-Record Messaging (OTR) modules for IRC
+ *
+ * Copyright (C) 2008  Uli Meis <a.sporto+bee at gmail.com>
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the Free
@@ -16,19 +18,18 @@
  * Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA
  */
 
-#ifndef IRSSI_OTR_KEY_H
-#define IRSSI_OTR_KEY_H
+#ifndef IRSSI_OTR_CMD_H
+#define IRSSI_OTR_CMD_H
 
 #include "otr.h"
 
-typedef enum { KEYGEN_NO, KEYGEN_RUNNING } keygen_status_t;
+struct irssi_commands {
+	const char *name;
+	void (*func)(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[],
+			char *argv_eol[], char *target);
+};
 
-void key_generation_abort(IOUSTATE *ioustate, int ignoreidle);
-void key_generation_run(IOUSTATE *ioustate, const char *accname);
-void key_load(IOUSTATE *ioustate);
-void key_load_fingerprints(IOUSTATE *ioustate);
-void key_write_fingerprints(IOUSTATE *ioustate);
-void otr_writeinstags(IOUSTATE *ioustate);
-void instag_load(IOUSTATE *ioustate);
+int cmd_generic(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[],
+		char *argv_eol[], char *target);
 
-#endif /* IRSSI_OTR_KEY_H */
+#endif /* IRSSI_OTR_CMD_H */
diff --git a/src/io_util.c b/src/io_util.c
deleted file mode 100644
index 9e9627c..0000000
--- a/src/io_util.c
+++ /dev/null
@@ -1,349 +0,0 @@
-/*
- * Off-the-Record Messaging (OTR) modules for IRC
- * Copyright (C) 2008  Uli Meis <a.sporto+bee at gmail.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA
- */
-
-#include "key.h"
-
-char *otr_status_txt[] = {
-	"FINISHED",
-	"TRUST_MANUAL",
-	"TRUST_SMP",
-	"SMP_ABORT",
-	"SMP_STARTED",
-	"SMP_RESPONDED",
-	"SMP_INCOMING",
-	"SMP_FINALIZE",
-	"SMP_ABORTED",
-	"PEER_FINISHED",
-	"SMP_FAILED",
-	"SMP_SUCCESS",
-	"GONE_SECURE",
-	"GONE_INSECURE",
-	"CTX_UPDATE"
-};
-
-char *otr_msg_event_txt[] = {
-	"NONE",
-	"ENCRYPTION_REQUIRED",
-	"ENCRYPTION_ERROR",
-	"CONNECTION_ENDED",
-	"SETUP_ERROR",
-	"MSG_REFLECTED",
-	"MSG_RESENT",
-	"RCVDMSG_NOT_IN_PRIVATE",
-	"RCVDMSG_UNREADABLE",
-	"RCVDMSG_MALFORMED",
-	"LOG_HEARTBEAT_RCVD",
-	"LOG_HEARTBEAT_SENT",
-	"RCVDMSG_GENERAL_ERR",
-	"RCVDMSG_UNENCRYPTED",
-	"RCVDMSG_UNRECOGNIZED",
-	"RCVDMSG_FOR_OTHER_INSTANCE"
-};
-
-int extract_nick(char *nick, char *line)
-{
-	char *excl;
-
-	if (*line++ != ':')
-		return FALSE;
-
-	strcpy(nick, line);
-
-	if ((excl = strchr(nick, '!')))
-		*excl = '\0';
-
-	return TRUE;
-}
-
-int cmd_generic(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[],
-		char *argv_eol[],
-		char *target)
-{
-	char *cmd;
-	struct _cmds *commands = cmds;
-
-	if (!argc) {
-		otr_noticest(TXT_CMD_OTR);
-		return TRUE;
-	}
-
-	cmd = argv[0];
-
-	argv++;
-	argv_eol++;
-	argc--;
-
-	do {
-		if (strcmp(commands->name, cmd) == 0) {
-			commands->cmdfunc(ioustate, ircctx, argc, argv,
-					  argv_eol,
-					  target);
-			return TRUE;
-		}
-	} while ((++commands)->name);
-
-	return FALSE;
-}
-
-void cmd_debug(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[],
-	       char *argv_eol[],
-	       char *target)
-{
-	debug = !debug;
-	otr_noticest(debug ? TXT_CMD_DEBUG_ON : TXT_CMD_DEBUG_OFF);
-}
-
-void cmd_version(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[],
-		 char *argv_eol[],
-		 char *target)
-{
-	otr_noticest(TXT_CMD_VERSION, IRCOTR_VERSION);
-}
-
-void cmd_help(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[],
-	      char *argv_eol[],
-	      char *target)
-{
-	otr_log(ircctx, target, MSGLEVEL_CRAP, otr_help);
-}
-
-void cmd_finish(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[],
-		char *argv_eol[],
-		char *target)
-{
-	if (argc)
-		otr_finish(NULL, NULL, argv[0], TRUE);
-	else if (ircctx && target)
-		otr_finish(ircctx, target, NULL, TRUE);
-	else
-		otr_noticest(TXT_CMD_QNOTFOUND);
-}
-
-void cmd_trust(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[],
-	       char *argv_eol[],
-	       char *target)
-{
-	if (argc)
-		otr_trust(NULL, NULL, argv[0]);
-	else if (ircctx && target)
-		otr_trust(ircctx, target, NULL);
-	else
-		otr_noticest(TXT_CMD_QNOTFOUND);
-}
-
-void cmd_authabort(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc,
-		   char *argv[], char *argv_eol[],
-		   char *target)
-{
-	if (argc)
-		otr_authabort(NULL, NULL, argv[0]);
-	else if (ircctx && target)
-		otr_authabort(ircctx, target, NULL);
-	else
-		otr_noticest(TXT_CMD_QNOTFOUND);
-}
-
-void cmd_genkey(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[],
-		char *argv_eol[],
-		char *target)
-{
-	if (argc) {
-		if (strcmp(argv[0], "abort") == 0)
-			key_generation_abort(ioustate, FALSE);
-		else if (strchr(argv[0], '@'))
-			key_generation_run(ioustate, argv[0]);
-		else
-			otr_noticest(TXT_KG_NEEDACC);
-	} else {
-		otr_noticest(TXT_KG_NEEDACC);
-	}
-}
-
-void _cmd_auth(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[],
-	       char *argv_eol[],
-	       char *target,
-	       int qanda)
-{
-	char *accountname = NULL;
-	char *question = NULL;
-	char *secret;
-
-	/* have args? */
-	if (argc < (qanda ? 2 : 1)) {
-		otr_notice(ircctx, target,
-			   TXT_CMD_AUTH);
-		return;
-	}
-
-	/* have buddy? */
-	if (!(ircctx && target)) {
-		accountname = strchr(argv[0], '@');
-		if (!accountname) {
-			otr_noticest(TXT_CMD_QNOTFOUND);
-			return;
-		}
-		ircctx = NULL;
-		target = NULL;
-		argv++; argv_eol++; argc--;
-	}
-
-	/* have question? */
-	if (qanda) {
-		question = argv[0];
-		argv++; argv_eol++; argc--;
-	}
-
-	secret = argv_eol[0];
-
-	otr_auth(ircctx, target, accountname, question, secret);
-}
-
-void cmd_authq(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[],
-	       char *argv_eol[],
-	       char *target)
-{
-	_cmd_auth(ioustate, ircctx, argc, argv, argv_eol, target, TRUE);
-}
-
-void cmd_auth(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[],
-	      char *argv_eol[],
-	      char *target)
-{
-	_cmd_auth(ioustate, ircctx, argc, argv, argv_eol, target, FALSE);
-}
-
-/*
- * /otr contexts
- */
-void cmd_contexts(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[],
-		  char *argv_eol[],
-		  char *target)
-{
-	struct ctxlist_ *ctxlist = otr_contexts(ioustate), *ctxnext = ctxlist;
-	struct fplist_ *fplist, *fpnext;
-
-	if (!ctxlist)
-		otr_infost(TXT_CTX_NOCTXS);
-
-	while (ctxlist) {
-		otr_infost(TXT_CTX_CTX_UNENCRYPTED + ctxlist->state,
-			   ctxlist->username,
-			   ctxlist->accountname);
-
-		fplist = ctxlist->fplist;
-		while (fplist) {
-			otr_infost(TXT_CTX_FPS_NO + fplist->authby,
-				   fplist->fp);
-			fplist = fplist->next;
-		}
-		ctxlist = ctxlist->next;
-	}
-	while ((ctxlist = ctxnext)) {
-		ctxnext = ctxlist->next;
-		fpnext = ctxlist->fplist;
-		while ((fplist = fpnext)) {
-			fpnext = fplist->next;
-			g_free(fplist->fp);
-			g_free(fplist);
-		}
-		g_free(ctxlist);
-	}
-}
-
-struct _cmds cmds[] = {
-	{ "version", cmd_version },
-	{ "debug", cmd_debug },
-	{ "help", cmd_help },
-	{ "finish", cmd_finish },
-	{ "trust", cmd_trust },
-	{ "authabort", cmd_authabort },
-	{ "auth", cmd_auth },
-#ifndef LIBOTR3
-	{ "authq", cmd_authq },
-#endif
-	{ "genkey", cmd_genkey },
-	{ "contexts", cmd_contexts },
-	{ NULL, NULL },
-	{ NULL, NULL }
-};
-
-void io_explode_args(const char *args, char ***argvp, char ***argv_eolp,
-		     int *argcp)
-{
-	char **argv, **argv_eol;
-	char *s = (char*)args;
-	int argc = 1, i;
-
-	while ((s = strchr(s + 1, ' ')))
-		argc++;
-
-	argv = (char**)malloc(sizeof(char *) * argc);
-	argv_eol = (char**)malloc(sizeof(char *) * argc);
-
-	s = (char*)args;
-	argv_eol[0] = strdup(args);
-	i = 0;
-	while (++i < argc)
-		argv_eol[i] = strchr(argv_eol[i - 1], ' ') + 1;
-
-	argv[0] = strtok(strdup(args), " ");
-	i = 1;
-	while (i < argc) {
-		argv[i++] = strtok(NULL, " ");
-		otr_logst(MSGLEVEL_CRAP, "arg %d: %s", i, argv[i - 1]);
-	}
-
-	*argvp = argv;
-	*argv_eolp = argv_eol;
-	*argcp = argc;
-}
-
-/*
- * Get a format describing the OTR status of this conversation.
- */
-int otr_getstatus_format(IRC_CTX *ircctx, const 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/src/module.c b/src/module.c
index 4711aef..1f85301 100644
--- a/src/module.c
+++ b/src/module.c
@@ -19,7 +19,9 @@
  * Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA
  */
 
+#include "cmd.h"
 #include "otr.h"
+#include "utils.h"
 
 static const char *lvlstring[] = {
 	"NOTICE",
@@ -132,7 +134,7 @@ static void cmd_otr(const char *data, void *server, WI_ITEM_REC *item)
 		goto end;
 	}
 
-	io_explode_args(data, &argv, &argv_eol, &argc);
+	utils_io_explode_args(data, &argv, &argv_eol, &argc);
 
 	if (query && query->server && query->server->connrec) {
 		cmd_generic(ioustate, query->server, argc, argv, argv_eol, query->name);
@@ -202,12 +204,6 @@ static void read_settings(void)
 #endif
 }
 
-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()
  */
diff --git a/src/otr-ops.c b/src/otr-ops.c
index c9d3df3..436113e 100644
--- a/src/otr-ops.c
+++ b/src/otr-ops.c
@@ -19,6 +19,26 @@
 
 #include "key.h"
 
+static const char *otr_msg_event_txt[] = {
+	"NONE",
+	"ENCRYPTION_REQUIRED",
+	"ENCRYPTION_ERROR",
+	"CONNECTION_ENDED",
+	"SETUP_ERROR",
+	"MSG_REFLECTED",
+	"MSG_RESENT",
+	"RCVDMSG_NOT_IN_PRIVATE",
+	"RCVDMSG_UNREADABLE",
+	"RCVDMSG_MALFORMED",
+	"LOG_HEARTBEAT_RCVD",
+	"LOG_HEARTBEAT_SENT",
+	"RCVDMSG_GENERAL_ERR",
+	"RCVDMSG_UNENCRYPTED",
+	"RCVDMSG_UNRECOGNIZED",
+	"RCVDMSG_FOR_OTHER_INSTANCE"
+};
+
+
 OtrlPolicy IO_DEFAULT_OTR_POLICY =
 	OTRL_POLICY_MANUAL | OTRL_POLICY_WHITESPACE_START_AKE;
 
diff --git a/src/otr.c b/src/otr.c
index 2f703da..e9e4b63 100644
--- a/src/otr.c
+++ b/src/otr.c
@@ -23,12 +23,36 @@
 
 #include <gcrypt.h>
 
+static const char *otr_status_txt[] = {
+	"FINISHED",
+	"TRUST_MANUAL",
+	"TRUST_SMP",
+	"SMP_ABORT",
+	"SMP_STARTED",
+	"SMP_RESPONDED",
+	"SMP_INCOMING",
+	"SMP_FINALIZE",
+	"SMP_ABORTED",
+	"PEER_FINISHED",
+	"SMP_FAILED",
+	"SMP_SUCCESS",
+	"GONE_SECURE",
+	"GONE_INSECURE",
+	"CTX_UPDATE"
+};
+
 IOUSTATE ioustate_uniq = { 0, 0, 0 };
 
 #ifdef HAVE_GREGEX_H
 GRegex *regex_policies;
 #endif
 
+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]);
+}
+
 IOUSTATE *otr_init_user(char *user)
 {
 	IOUSTATE *ioustate = IO_CREATE_US(user);
@@ -791,3 +815,37 @@ void otr_setpolicies(IOUSTATE *ioustate, const char *policies, int known)
 		ioustate->plistunknown = plist;
 #endif
 }
+
+/*
+ * Get a format describing the OTR status of this conversation.
+ */
+int otr_getstatus_format(IRC_CTX *ircctx, const 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/src/otr.h b/src/otr.h
index 7e44b6a..7962b3e 100644
--- a/src/otr.h
+++ b/src/otr.h
@@ -17,6 +17,9 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA
  */
 
+#ifndef IRSSI_OTR_OTR_H
+#define IRSSI_OTR_OTR_H
+
 #include <stdlib.h>
 #include <unistd.h>
 #include <errno.h>
@@ -164,12 +167,6 @@ enum {
 	IO_STC_CTX_UPDATE
 };
 
-/* libotr4 handle_msg_event */
-extern char *otr_msg_event_txt[];
-
-/* the above as text for scripting */
-extern char *otr_status_txt[];
-
 /* policy list generated from /set otr_policy */
 
 struct plistentry {
@@ -218,20 +215,9 @@ void otr_finishall(IOUSTATE *ioustate);
 
 int extract_nick(char *nick, char *line);
 
-struct _cmds {
-	char *name;
-	void (*cmdfunc)(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc,
-			char *argv[], char *argv_eol[], char *target);
-};
-
-/* see io_util.c */
-#define CMDCOUNT 9
-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, const char *nick);
 
-void io_explode_args(const char *args, char ***argvp, char ***argv_eolp,
-		     int *argcp);
+void utils_io_explode_args(const char *args, char ***argvp, char ***argv_eolp,
+		int *argcp);
+
+#endif /* IRSSI_OTR_OTR_H */
diff --git a/src/utils.c b/src/utils.c
new file mode 100644
index 0000000..a03648a
--- /dev/null
+++ b/src/utils.c
@@ -0,0 +1,71 @@
+/*
+ * Off-the-Record Messaging (OTR) modules for IRC
+ *
+ * Copyright (C) 2008  Uli Meis <a.sporto+bee at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 51
+ * Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA
+ */
+
+#include <string.h>
+
+#include "otr.h"
+#include "utils.h"
+
+#if 0
+#define LOGMAX 1024
+
+#define otr_logst(level, format, args...) \
+	otr_log(NULL, NULL, level, format, ## __VA_ARGS__)
+
+/* used by the logging functions below */
+extern int debug;
+
+void otr_log(IRC_CTX *server, const char *to, int level,
+		const char *format, ...);
+#endif
+
+void utils_io_explode_args(const char *args, char ***argvp, char ***argv_eolp,
+		int *argcp)
+{
+	char **argv, **argv_eol;
+	char *s = (char *) args;
+	int argc = 1, i;
+
+	while ((s = strchr(s + 1, ' '))) {
+		argc++;
+	}
+
+	argv = (char **) malloc(argc * sizeof(char *));
+	argv_eol = (char **) malloc(argc * sizeof(char *));
+
+	s = (char *) args;
+	argv_eol[0] = strdup(args);
+	i = 0;
+
+	while (++i < argc) {
+		argv_eol[i] = strchr(argv_eol[i - 1], ' ') + 1;
+	}
+
+	argv[0] = strtok(strdup(args), " ");
+	i = 1;
+	while (i < argc) {
+		argv[i++] = strtok(NULL, " ");
+		otr_logst(MSGLEVEL_CRAP, "arg %d: %s", i, argv[i - 1]);
+	}
+
+	*argvp = argv;
+	*argv_eolp = argv_eol;
+	*argcp = argc;
+}
diff --git a/src/key.h b/src/utils.h
similarity index 56%
copy from src/key.h
copy to src/utils.h
index ae89382..76830cc 100644
--- a/src/key.h
+++ b/src/utils.h
@@ -1,5 +1,7 @@
 /*
- * Copyright (C) 2012 - David Goulet <dgoulet at ev0ke.net>
+ * Off-the-Record Messaging (OTR) modules for IRC
+ *
+ * Copyright (C) 2008  Uli Meis <a.sporto+bee at gmail.com>
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the Free
@@ -16,19 +18,10 @@
  * Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA
  */
 
-#ifndef IRSSI_OTR_KEY_H
-#define IRSSI_OTR_KEY_H
-
-#include "otr.h"
-
-typedef enum { KEYGEN_NO, KEYGEN_RUNNING } keygen_status_t;
+#ifndef IRSSI_OTR_UTILS_H
+#define IRSSI_OTR_UTILS_H
 
-void key_generation_abort(IOUSTATE *ioustate, int ignoreidle);
-void key_generation_run(IOUSTATE *ioustate, const char *accname);
-void key_load(IOUSTATE *ioustate);
-void key_load_fingerprints(IOUSTATE *ioustate);
-void key_write_fingerprints(IOUSTATE *ioustate);
-void otr_writeinstags(IOUSTATE *ioustate);
-void instag_load(IOUSTATE *ioustate);
+void utils_io_explode_args(const char *args, char ***argvp, char ***argv_eolp,
+		int *argcp);
 
-#endif /* IRSSI_OTR_KEY_H */
+#endif /* IRSSI_OTR_UTILS_H */

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