[Pkg-privacy-commits] [irssi-plugin-otr] 120/267: Fix: Make sure peer context is created for each OTR context

Ximin Luo infinity0 at moszumanska.debian.org
Sat Aug 22 12:41:34 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 e7bca255a26f925e6f8a4bbb04f42477d8aa8abb
Author: David Goulet <dgoulet at ev0ke.net>
Date:   Thu Nov 8 17:25:46 2012 -0500

    Fix: Make sure peer context is created for each OTR context
    
    Signed-off-by: David Goulet <dgoulet at ev0ke.net>
---
 src/cmd.c     |  8 +-------
 src/otr-ops.c | 18 +++++++-----------
 src/otr.c     | 36 +++++++++++++++++++++++++-----------
 3 files changed, 33 insertions(+), 29 deletions(-)

diff --git a/src/cmd.c b/src/cmd.c
index ef26176..bab2439 100644
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -223,17 +223,11 @@ static void _cmd_init(struct otr_user_state *ustate, SERVER_REC *irssi, int argc
 	char *msg;
 
 	/* No server object, just ignore the request */
-	if (!irssi) {
+	if (!irssi || !target) {
 		otr_noticest(TXT_CMD_QNOTFOUND);
 		goto end;
 	}
 
-	if (!target) {
-		IRSSI_WARN(irssi, irssi->nick, "%9OTR:%9 Use /otr init only in a "
-				"private message window.");
-		goto end;
-	}
-
 	msg = otrl_proto_default_query_msg(target, OTRL_POLICY_DEFAULT);
 	irssi_send_message(irssi, target, msg ? msg : "?OTRv23?");
 	free(msg);
diff --git a/src/otr-ops.c b/src/otr-ops.c
index 5b4ba29..c989495 100644
--- a/src/otr-ops.c
+++ b/src/otr-ops.c
@@ -311,14 +311,13 @@ static void ops_smp_event(void *opdata, OtrlSMPEvent smp_event,
 	const char *from = context->username;
 	struct otr_peer_context *opc = context->app_data;
 
-	if (!opc) {
-		IRSSI_DEBUG("%9OTR%9: SMP event cb. Unable to find peer context");
-		opc = otr_create_peer_context();
-		if (!opc) {
-			goto end;
-		}
-		context->app_data = opc;
-	}
+	/*
+	 * Without a peer context, we can't update the status bar. Code flow error
+	 * if none is found. This context is created automatically by an otrl_*
+	 * call or if non existent when returned from
+	 * otrl_message_sending/receiving.
+	 */
+	assert(opc);
 
 	opc->smp_event = smp_event;
 
@@ -353,9 +352,6 @@ static void ops_smp_event(void *opdata, OtrlSMPEvent smp_event,
 		otr_logst(MSGLEVEL_CRAP, "Received unknown SMP event");
 		break;
 	}
-
-end:
-	return;
 }
 
 /*
diff --git a/src/otr.c b/src/otr.c
index d96c57b..9e76add 100644
--- a/src/otr.c
+++ b/src/otr.c
@@ -106,6 +106,8 @@ static void destroy_peer_context_cb(void *data)
 	if (opc) {
 		free(opc);
 	}
+
+	IRSSI_DEBUG("%9OTR%9: Peer context freed");
 }
 
 static void add_peer_context_cb(void *data, ConnContext *context)
@@ -119,6 +121,8 @@ static void add_peer_context_cb(void *data, ConnContext *context)
 
 	context->app_data = opc;
 	context->app_data_free = destroy_peer_context_cb;
+
+	IRSSI_MSG("%9OTR%9: Peer context created for %s", context->username);
 }
 
 /*
@@ -215,6 +219,7 @@ int otr_send(SERVER_REC *irssi, const char *msg, const char *to, char **otr_msg)
 {
 	gcry_error_t err;
 	char *accname = NULL;
+	ConnContext *ctx = NULL;
 
 	assert(irssi);
 
@@ -227,7 +232,7 @@ int otr_send(SERVER_REC *irssi, const char *msg, const char *to, char **otr_msg)
 
 	err = otrl_message_sending(user_state_global->otr_state, &otr_ops,
 		irssi, accname, OTR_PROTOCOL_ID, to, OTRL_INSTAG_BEST, msg, NULL, otr_msg,
-		OTRL_FRAGMENT_SEND_ALL_BUT_LAST, NULL, add_peer_context_cb, NULL);
+		OTRL_FRAGMENT_SEND_ALL_BUT_LAST, &ctx, add_peer_context_cb, NULL);
 	if (err) {
 		IRSSI_NOTICE(irssi, to, "%9OTR:%9 Send failed.");
 		goto error;
@@ -235,6 +240,11 @@ int otr_send(SERVER_REC *irssi, const char *msg, const char *to, char **otr_msg)
 
 	IRSSI_DEBUG("%9OTR%9: Message sent...");
 
+	/* Add peer context to OTR context if non exists */
+	if (ctx && !ctx->app_data) {
+		add_peer_context_cb(NULL, ctx);
+	}
+
 	free(accname);
 	return 0;
 
@@ -507,16 +517,13 @@ void otr_auth(SERVER_REC *irssi, char *nick, const char *peername,
 	}
 
 	opc = ctx->app_data;
-	if (!opc) {
-		opc = otr_create_peer_context();
-		if (!opc) {
-			goto end;
-		}
-		ctx->app_data = opc;
-	}
+	/* Again, code flow error. */
+	assert(opc);
 
 	if (ctx->msgstate != OTRL_MSGSTATE_ENCRYPTED) {
-		otr_notice(irssi, nick, TXT_AUTH_NEEDENC);
+		IRSSI_NOTICE(irssi, nick,
+				"%9OTR%9: You need to establish an OTR session before you "
+				"can authenticate.");
 		goto end;
 	}
 
@@ -569,6 +576,7 @@ int otr_receive(SERVER_REC *irssi, const char *msg, const char *from,
 	int ret = -1;
 	char *accname = NULL;
 	OtrlTLV *tlvs;
+	ConnContext *ctx;
 
 	accname = create_account_name(irssi);
 	if (!accname) {
@@ -579,16 +587,22 @@ int otr_receive(SERVER_REC *irssi, const char *msg, const char *from,
 
 	ret = otrl_message_receiving(user_state_global->otr_state,
 		&otr_ops, irssi, accname, OTR_PROTOCOL_ID, from, msg, new_msg, &tlvs,
-		NULL, add_peer_context_cb, NULL);
+		&ctx, add_peer_context_cb, NULL);
 	if (ret) {
 		IRSSI_DEBUG("%9OTR%9: Ignoring message of length %d from %s to %s.\n"
-				"[%s]", strlen(msg), from, accname, msg);
+				"%9OTR%9: %s", strlen(msg), from, accname, msg);
 	} else {
 		if (*new_msg) {
 			IRSSI_DEBUG("%9OTR%9: Converted received message.");
 		}
 	}
 
+	/* Add peer context to OTR context if non exists */
+	if (ctx && !ctx->app_data) {
+		add_peer_context_cb(NULL, ctx);
+	}
+
+	/* Check for disconnected message */
 	OtrlTLV *tlv = otrl_tlv_find(tlvs, OTRL_TLV_DISCONNECTED);
 	if (tlv) {
 		otr_status_change(irssi, from, OTR_STATUS_PEER_FINISHED);

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