[Pkg-privacy-commits] [irssi-plugin-otr] 101/267: Cleanup otr.h and improve file structure

Ximin Luo infinity0 at moszumanska.debian.org
Sat Aug 22 12:41:32 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 02dcb35d93ce6c9d83574220aa256d6b9ac1f3eb
Author: David Goulet <dgoulet at ev0ke.net>
Date:   Sat Nov 3 18:27:39 2012 -0400

    Cleanup otr.h and improve file structure
    
    Signed-off-by: David Goulet <dgoulet at ev0ke.net>
---
 src/io_set.c  |  6 ++--
 src/key.c     | 22 +++++++--------
 src/module.c  | 10 +++++--
 src/otr-ops.c |  2 +-
 src/otr.c     | 12 ++++----
 src/otr.h     | 88 ++++++++++++++++++++++-------------------------------------
 6 files changed, 61 insertions(+), 79 deletions(-)

diff --git a/src/io_set.c b/src/io_set.c
index 997e078..477faa3 100644
--- a/src/io_set.c
+++ b/src/io_set.c
@@ -23,9 +23,9 @@
 extern GRegex *regex_nickignore;
 #endif
 
-char set_policy[512] = IO_DEFAULT_POLICY;
-char set_policy_known[512] = IO_DEFAULT_POLICY_KNOWN;
-char set_ignore[512] = IO_DEFAULT_IGNORE;
+char set_policy[512] = OTR_DEFAULT_POLICY;
+char set_policy_known[512] = OTR_DEFAULT_POLICY_KNOWN;
+char set_ignore[512] = OTR_DEFAULT_IGNORE;
 int set_finishonunload = TRUE;
 
 void cmd_set(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
diff --git a/src/key.c b/src/key.c
index ccf04f8..1fe0b2a 100644
--- a/src/key.c
+++ b/src/key.c
@@ -18,7 +18,7 @@
  */
 
 #define _GNU_SOURCE
-
+#include <glib/gstdio.h>
 #include <libgen.h>
 #include <sys/types.h>
 #include <sys/wait.h>
@@ -94,8 +94,8 @@ static gboolean keygen_complete(GIOChannel *source, GIOCondition condition,
 {
 	gcry_error_t err;
 	const char *clconfdir = get_client_config_dir();
-	char *filename = g_strconcat(clconfdir, KEYFILE, NULL);
-	char *tmpfilename = g_strconcat(clconfdir, TMPKEYFILE, NULL);
+	char *filename = g_strconcat(clconfdir, OTR_KEYFILE, NULL);
+	char *tmpfilename = g_strconcat(clconfdir, OTR_TMP_KEYFILE, NULL);
 
 	read(g_io_channel_unix_get_fd(kg_st.ch[0]), &err, sizeof(err));
 
@@ -139,7 +139,7 @@ void key_generation_run(IOUSTATE *ioustate, const char *accname)
 	gcry_error_t err;
 	int ret;
 	int fds[2];
-	char *filename = g_strconcat(get_client_config_dir(), TMPKEYFILE, NULL);
+	char *filename = g_strconcat(get_client_config_dir(), OTR_TMP_KEYFILE, NULL);
 	char *filenamedup = g_strdup(filename);
 	char *dir = dirname(filenamedup);
 
@@ -175,7 +175,7 @@ void key_generation_run(IOUSTATE *ioustate, const char *accname)
 
 	kg_st.accountname = g_strdup(accname);
 	kg_st.ioustate = ioustate;
-	kg_st.protocol = PROTOCOLID;
+	kg_st.protocol = OTR_PROTOCOL_ID;
 	kg_st.started = time(NULL);
 
 	if ((ret = fork())) {
@@ -200,7 +200,7 @@ void key_generation_run(IOUSTATE *ioustate, const char *accname)
 	/* child */
 
 	err = otrl_privkey_generate(ioustate->otr_state, filename, accname,
-			PROTOCOLID);
+			OTR_PROTOCOL_ID);
 	(void) write(fds[1], &err, sizeof(err));
 
 	g_free(filename);
@@ -247,7 +247,7 @@ end:
 void key_write_fingerprints(IOUSTATE *ioustate)
 {
 	gcry_error_t err;
-	char *filename = g_strconcat(get_client_config_dir(), FPSFILE, NULL);
+	char *filename = g_strconcat(get_client_config_dir(), OTR_FINGERPRINTS_FILE, NULL);
 
 	err = otrl_privkey_write_fingerprints(ioustate->otr_state, filename);
 	if (err == GPG_ERR_NO_ERROR) {
@@ -267,7 +267,7 @@ void key_write_fingerprints(IOUSTATE *ioustate)
 void otr_writeinstags(IOUSTATE *ioustate)
 {
 	gcry_error_t err;
-	char *filename = g_strconcat(get_client_config_dir(), INSTAGFILE, NULL);
+	char *filename = g_strconcat(get_client_config_dir(), OTR_INSTAG_FILE, NULL);
 
 	err = otrl_instag_write(ioustate->otr_state, filename);
 	if (err == GPG_ERR_NO_ERROR) {
@@ -287,7 +287,7 @@ void otr_writeinstags(IOUSTATE *ioustate)
 void key_load(IOUSTATE *ioustate)
 {
 	gcry_error_t err;
-	char *filename = g_strconcat(get_client_config_dir(), KEYFILE, NULL);
+	char *filename = g_strconcat(get_client_config_dir(), OTR_KEYFILE, NULL);
 
 	if (!g_file_test(filename, G_FILE_TEST_EXISTS)) {
 		otr_noticest(TXT_KEY_NOT_FOUND);
@@ -313,7 +313,7 @@ end:
 void key_load_fingerprints(IOUSTATE *ioustate)
 {
 	gcry_error_t err;
-	char *filename = g_strconcat(get_client_config_dir(), FPSFILE, NULL);
+	char *filename = g_strconcat(get_client_config_dir(), OTR_FINGERPRINTS_FILE, NULL);
 	if (!g_file_test(filename, G_FILE_TEST_EXISTS)) {
 		otr_noticest(TXT_FP_NOT_FOUND);
 		goto end;
@@ -340,7 +340,7 @@ end:
 void instag_load(IOUSTATE *ioustate)
 {
 	gcry_error_t err;
-	char *filename = g_strconcat(get_client_config_dir(), INSTAGFILE, NULL);
+	char *filename = g_strconcat(get_client_config_dir(), OTR_INSTAG_FILE, NULL);
 
 	if (!g_file_test(filename, G_FILE_TEST_EXISTS)) {
 		otr_noticest(TXT_INSTAG_NOT_FOUND);
diff --git a/src/module.c b/src/module.c
index 946db8a..7509b03 100644
--- a/src/module.c
+++ b/src/module.c
@@ -19,6 +19,10 @@
  * Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA
  */
 
+#include <glib.h>
+#include <glib/gprintf.h>
+#include <glib/gstdio.h>
+
 #include "cmd.h"
 #include "otr.h"
 #include "utils.h"
@@ -219,9 +223,9 @@ void otr_init(void)
 	command_bind("otr", NULL, (SIGNAL_FUNC) cmd_otr);
 	command_bind_first("quit", NULL, (SIGNAL_FUNC) cmd_quit);
 
-	settings_add_str("otr", "otr_policy", IO_DEFAULT_POLICY);
-	settings_add_str("otr", "otr_policy_known", IO_DEFAULT_POLICY_KNOWN);
-	settings_add_str("otr", "otr_ignore", IO_DEFAULT_IGNORE);
+	settings_add_str("otr", "otr_policy", OTR_DEFAULT_POLICY);
+	settings_add_str("otr", "otr_policy_known", OTR_DEFAULT_POLICY_KNOWN);
+	settings_add_str("otr", "otr_ignore", OTR_DEFAULT_IGNORE);
 	settings_add_bool("otr", "otr_finishonunload", TRUE);
 	settings_add_bool("otr", "otr_createqueries", TRUE);
 
diff --git a/src/otr-ops.c b/src/otr-ops.c
index 5a002b4..0cbec11 100644
--- a/src/otr-ops.c
+++ b/src/otr-ops.c
@@ -242,7 +242,7 @@ static void ops_secure(void *opdata, ConnContext *context)
 
 	otr_notice(coi->ircctx, context->username, TXT_OPS_FPCOMP,
 			otrl_privkey_fingerprint(IRCCTX_IO_US(coi->ircctx)->otr_state,
-				ownfp, context->accountname, PROTOCOLID), context->username,
+				ownfp, context->accountname, OTR_PROTOCOL_ID), context->username,
 			peerfp);
 
 end:
diff --git a/src/otr.c b/src/otr.c
index bb20f49..a55f276 100644
--- a/src/otr.c
+++ b/src/otr.c
@@ -152,7 +152,7 @@ ConnContext *otr_getcontext(const char *accname, const char *nick,
 		IRCCTX_IO_US(ircctx)->otr_state,
 		nick,
 		accname,
-		PROTOCOLID,
+		OTR_PROTOCOL_ID,
 #ifndef LIBOTR3
 		OTRL_INSTAG_BEST,
 #endif
@@ -184,7 +184,7 @@ int otr_send(IRC_CTX *ircctx, const char *msg, const char *to, char **otr_msg)
 	otr_logst(MSGLEVEL_CRAP, "%d: sending msg", time(NULL));
 
 	err = otrl_message_sending(IRCCTX_IO_US(ircctx)->otr_state, &otr_ops,
-		ircctx, accname, PROTOCOLID, to, OTRL_INSTAG_BEST, msg, NULL, otr_msg,
+		ircctx, accname, OTR_PROTOCOL_ID, to, OTRL_INSTAG_BEST, msg, NULL, otr_msg,
 		OTRL_FRAGMENT_SEND_ALL, &co, context_add_app_info, ircctx);
 	if (err) {
 		otr_notice(ircctx, to, TXT_SEND_FAILED, msg);
@@ -355,7 +355,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, co->their_instance);
+			accname, OTR_PROTOCOL_ID, nick, co->their_instance);
 
 	otr_status_change(ircctx, nick, IO_STC_FINISHED);
 
@@ -375,7 +375,7 @@ void otr_finish(IRC_CTX *ircctx, char *nick, const char *peername, int inquery)
 
 	/* write the finished into the master as well */
 	co = otrl_context_find(IRCCTX_IO_US(ircctx)->otr_state, nick, accname,
-		PROTOCOLID, OTRL_INSTAG_MASTER, FALSE, NULL, NULL, NULL);
+		OTR_PROTOCOL_ID, OTRL_INSTAG_MASTER, FALSE, NULL, NULL, NULL);
 	if (co) {
 		coi = co->app_data;
 	}
@@ -398,7 +398,7 @@ void otr_finishall(IOUSTATE *ioustate)
 		}
 
 		otrl_message_disconnect(ioustate->otr_state, &otr_ops, coi->ircctx,
-					context->accountname, PROTOCOLID, context->username,
+					context->accountname, OTR_PROTOCOL_ID, context->username,
 					context->their_instance);
 		otr_status_change(coi->ircctx, context->username, IO_STC_FINISHED);
 
@@ -722,7 +722,7 @@ int otr_receive(IRC_CTX *ircctx, const char *msg, const char *from,
 	otr_logst(MSGLEVEL_CRAP, "%d: receiving...", time(NULL));
 
 	ret = otrl_message_receiving(IRCCTX_IO_US(ircctx)->otr_state,
-		&otr_ops, ircctx, accname, PROTOCOLID, from, msg, new_msg, &tlvs,
+		&otr_ops, ircctx, accname, OTR_PROTOCOL_ID, from, msg, new_msg, &tlvs,
 		&co, context_add_app_info, ircctx);
 	if (ret) {
 		otr_debug(ircctx, from, TXT_RECEIVE_IGNORE, strlen(msg), accname, from,
diff --git a/src/otr.h b/src/otr.h
index 79c2aa4..c4e6d62 100644
--- a/src/otr.h
+++ b/src/otr.h
@@ -20,77 +20,56 @@
 #ifndef IRSSI_OTR_OTR_H
 #define IRSSI_OTR_OTR_H
 
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-
-/* OTR */
-
+/* Libotr */
 #include <libotr/proto.h>
-#include <libotr/context.h>
 #include <libotr/message.h>
+#include <libotr/context.h>
 #include <libotr/privkey.h>
 
-/* glib */
-
-#include <glib.h>
-#include <glib/gprintf.h>
-#include <glib/gstdio.h>
-
+#include "io-config.h"
 #include "irssi_otr.h"
 #include "utils.h"
 
-extern OtrlMessageAppOps otr_ops;
-
-/* user state */
-
-typedef struct {
-	OtrlUserState otr_state;
-	GSList *plistunknown;
-	GSList *plistknown;
-} IOUSTATE;
-
-#ifndef TARGET_BITLBEE
-/* there can be only one */
-extern IOUSTATE ioustate_uniq;
-#endif
-
-/* own */
-
-#include "io-config.h"
-
 /* irssi module name */
 #define MODULE_NAME "otr"
 
 #include "otr-formats.h"
 
 /*
- * maybe this should be configurable?
- * I believe bitlbee has something >500.
+ * XXX: Maybe this should be configurable?
  */
-#define OTR_MAX_MSG_SIZE 400
+#define OTR_MAX_MSG_SIZE              400
 
-/* otr protocol id */
-#define PROTOCOLID "IRC"
+/* OTR protocol id */
+#define OTR_PROTOCOL_ID               "IRC"
 
-#define KEYFILE    "/otr/otr.key"
-#define TMPKEYFILE "/otr/otr.key.tmp"
-#define FPSFILE    "/otr/otr.fp"
-#define INSTAGFILE "/otr/otr.instag"
+#define OTR_KEYFILE                   "/otr/otr.key"
+#define OTR_TMP_KEYFILE               "/otr/otr.key.tmp"
+#define OTR_FINGERPRINTS_FILE         "/otr/otr.fp"
+#define OTR_INSTAG_FILE               "/otr/otr.instag"
 
 /* some defaults */
-#define IO_DEFAULT_POLICY \
-	"*@localhost opportunistic,*bitlbee* opportunistic,*@im.* opportunistic, *serv at irc* never"
-#define IO_DEFAULT_POLICY_KNOWN "* always"
-#define IO_DEFAULT_IGNORE "xmlconsole[0-9]*"
+#define OTR_DEFAULT_POLICY \
+	"*@localhost opportunistic, *@im.* opportunistic, *serv at irc* never"
+
+#define OTR_DEFAULT_POLICY_KNOWN      "* always"
+#define OTR_DEFAULT_IGNORE            "xmlconsole[0-9]*"
 
 /* used as a prefix for /me messages.
  * This makes it readable and sensible for
  * people not on IRC (i.e. in case of a gateway
  * like bitlbee)
  */
-#define IRCACTIONMARK "/me "
-#define IRCACTIONMARKLEN 4
+#define IRCACTIONMARK                 "/me "
+#define IRCACTIONMARKLEN              4
+
+/* user state */
+
+typedef struct {
+	OtrlUserState otr_state;
+	GSList *plistunknown;
+	GSList *plistknown;
+} IOUSTATE;
 
 /* one for each OTR context (=communication pair) */
 struct co_info {
@@ -122,7 +101,7 @@ struct ctxlist_ {
 };
 
 /* returned by otr_getstatus */
-enum {
+enum otr_status {
 	IO_ST_PLAINTEXT,
 	IO_ST_FINISHED,
 	IO_ST_SMP_INCOMING,
@@ -162,7 +141,11 @@ struct plistentry {
 	OtrlPolicy policy;
 };
 
-/* used by the logging functions below */
+/* there can be only one */
+extern IOUSTATE ioustate_uniq;
+
+extern OtrlMessageAppOps otr_ops;
+
 extern int debug;
 
 void irc_send_message(IRC_CTX *ircctx, const char *recipient, char *msg);
@@ -197,17 +180,12 @@ void otr_trust(IRC_CTX *server, char *nick, const char *peername);
 void otr_finish(IRC_CTX *server, char *nick, const char *peername,
 		int inquery);
 void otr_auth(IRC_CTX *server, char *nick, const char *peername,
-	      const char *question, const char *secret);
+		const char *question, const char *secret);
 void otr_authabort(IRC_CTX *server, char *nick, const char *peername);
 void otr_abort_auth(ConnContext *co, IRC_CTX *ircctx, const char *nick);
 struct ctxlist_ *otr_contexts(IOUSTATE *ioustate);
 void otr_finishall(IOUSTATE *ioustate);
 
-int extract_nick(char *nick, char *line);
-
 int otr_getstatus_format(IRC_CTX *ircctx, const char *nick);
 
-void utils_io_explode_args(const char *args, char ***argvp, char ***argv_eolp,
-		int *argcp);
-
 #endif /* IRSSI_OTR_OTR_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