[Pkg-privacy-commits] [irssi-plugin-otr] 109/267: Rename co_info to something meaningful
Ximin Luo
infinity0 at moszumanska.debian.org
Sat Aug 22 12:41:33 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 0a3899e06f5ecffe8e2c659de596f0c8e22e5134
Author: David Goulet <dgoulet at ev0ke.net>
Date: Tue Nov 6 12:19:49 2012 -0500
Rename co_info to something meaningful
Also remove unsused disabled code.
Add IRSSI_NOTICE so to move away from otr_notice/_debug which uses the
otr-formats.c/.h that makes the code a bit unclear and charged with enum
value that must match an array. This is error prone over time.
Signed-off-by: David Goulet <dgoulet at ev0ke.net>
---
src/irssi_otr.h | 43 ++++++------
src/otr-ops.c | 177 ++++++++++++++++-------------------------------
src/otr.c | 209 +++++++++++++++++++++++---------------------------------
src/otr.h | 13 +---
4 files changed, 170 insertions(+), 272 deletions(-)
diff --git a/src/irssi_otr.h b/src/irssi_otr.h
index 8393d34..89ff13a 100644
--- a/src/irssi_otr.h
+++ b/src/irssi_otr.h
@@ -39,16 +39,16 @@
#define get_client_config_dir get_irssi_dir
-static IRC_CTX *IRCCTX_DUP(IRC_CTX *ircctx) __attribute__ ((unused));
+static IRC_CTX *IRSSI_DUP(IRC_CTX *ircctx) __attribute__ ((unused));
-static IRC_CTX *IRCCTX_DUP(IRC_CTX *ircctx) {
+static IRC_CTX *IRSSI_DUP(IRC_CTX *ircctx) {
server_ref(ircctx);
return ircctx;
}
-static IRC_CTX *IRCCTX_FREE(IRC_CTX *ircctx) __attribute__ ((unused));
+static IRC_CTX *IRSSI_FREE(IRC_CTX *ircctx) __attribute__ ((unused));
-static IRC_CTX *IRCCTX_FREE(IRC_CTX *ircctx)
+static IRC_CTX *IRSSI_FREE(IRC_CTX *ircctx)
{
server_unref(ircctx);
return ircctx;
@@ -56,30 +56,35 @@ static IRC_CTX *IRCCTX_FREE(IRC_CTX *ircctx)
void otr_query_create(IRC_CTX *ircctx, const char *nick);
-#define IRCCTX_ADDR(ircctx) ircctx->connrec->address
-#define IRCCTX_NICK(ircctx) ircctx->nick
-#define IRCCTX_ACCNAME(accname,ircctx) sprintf(accname, "%s@%s", ircctx->nick, ircctx->connrec->address)
-#define IRCCTX_IO_US(ircctx) (&ioustate_uniq)
+#define IRSSI_CONN_ADDR(i) i->connrec->address
+#define IRSSI_NICK(i) i->nick
+#define IRSSI_ACCNAME(accname, i) sprintf(accname, "%s@%s", i->nick, IRSSI_CONN_ADDR(i))
+#define IRSSI_IO_US(i) (&ioustate_uniq)
#define IO_CREATE_US(user) (&ioustate_uniq)
#define otr_noticest(formatnum,...) \
printformat(NULL,NULL,MSGLEVEL_MSGS, formatnum, ## __VA_ARGS__)
-#define otr_notice(ircctx,nick,formatnum,...) { \
- otr_query_create(ircctx,nick); \
- printformat(ircctx,nick,MSGLEVEL_MSGS, formatnum, ## __VA_ARGS__);}
+#define otr_notice(irssi, nick, formatnum, ...) { \
+ otr_query_create(irssi, nick); \
+ printformat(irssi, nick, MSGLEVEL_MSGS, formatnum, ## __VA_ARGS__);}
#define otr_infost(formatnum,...) \
printformat(NULL,NULL,MSGLEVEL_CRAP, formatnum, ## __VA_ARGS__)
-#define otr_info(server,nick,formatnum,...) { \
- otr_query_create(ircctx,nick); \
- printformat(ircctx,nick,MSGLEVEL_CRAP, formatnum, ## __VA_ARGS__);}
+#define otr_info(server, nick, formatnum, ...) { \
+ otr_query_create(server, nick); \
+ printformat(server, nick, MSGLEVEL_CRAP, formatnum, ## __VA_ARGS__);}
-#define otr_debug(ircctx,nick,formatnum,...) { \
+#define otr_debug(irssi, nick, formatnum, ...) { \
if (debug) { \
- otr_query_create(ircctx,nick); \
- printformat(ircctx,nick,MSGLEVEL_MSGS, formatnum, ## __VA_ARGS__); } }
+ otr_query_create(irssi, nick); \
+ printformat(irssi, nick, MSGLEVEL_MSGS, formatnum, ## __VA_ARGS__); } }
-#define IRSSI_WARN(irssi_ctx, username, fmt, ...) \
- printtext(irssi_ctx, username, MSGLEVEL_HILIGHT, fmt, ## __VA_ARGS__);
+/*
+ * Irssi macros for printing text to console.
+ */
+#define IRSSI_NOTICE(irssi, username, fmt, ...) \
+ printtext(irssi, username, MSGLEVEL_MSGS, fmt, ## __VA_ARGS__);
+#define IRSSI_WARN(irssi, username, fmt, ...) \
+ printtext(irssi, username, MSGLEVEL_HILIGHT, fmt, ## __VA_ARGS__);
diff --git a/src/otr-ops.c b/src/otr-ops.c
index 2235d9f..89637c8 100644
--- a/src/otr-ops.c
+++ b/src/otr-ops.c
@@ -17,6 +17,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA
*/
+#include <assert.h>
+
#include "key.h"
static const char *otr_msg_event_txt[] = {
@@ -47,17 +49,16 @@ OtrlPolicy IO_DEFAULT_OTR_POLICY =
static OtrlPolicy ops_policy(void *opdata, ConnContext *context)
{
int ret;
- struct co_info *coi = context->app_data;
+ struct irssi_otr_context *ioc = context->app_data;
char *server = strchr(context->accountname, '@') + 1;
OtrlPolicy op = IO_DEFAULT_OTR_POLICY;
GSList *pl;
char fullname[1024];
- IOUSTATE *ioustate = IRCCTX_IO_US(coi->ircctx);
+ IOUSTATE *ioustate = IRSSI_IO_US(ioc->irssi);
ret = snprintf(fullname, sizeof(fullname), "%s@%s", context->username,
server);
if (ret < 0) {
- perror("snprintf ops policy");
/* Return default policy */
goto error;
}
@@ -87,7 +88,7 @@ static OtrlPolicy ops_policy(void *opdata, ConnContext *context)
} while ((pl = g_slist_next(pl)));
}
- if (coi && coi->finished &&
+ if (ioc && context->msgstate == OTRL_MSGSTATE_FINISHED &&
(op == OTRL_POLICY_OPPORTUNISTIC || op == OTRL_POLICY_ALWAYS)) {
op = OTRL_POLICY_MANUAL | OTRL_POLICY_WHITESPACE_START_AKE;
}
@@ -106,9 +107,9 @@ error:
static void ops_create_privkey(void *opdata, const char *accountname,
const char *protocol)
{
- IRC_CTX *ircctx __attribute__((unused)) = opdata;
+ IRC_CTX *irssi __attribute__((unused)) = opdata;
- key_generation_run(IRCCTX_IO_US(ircctx), accountname);
+ key_generation_run(IRSSI_IO_US(irssi), accountname);
}
/*
@@ -142,108 +143,47 @@ static void ops_inject_msg(void *opdata, const char *accountname,
g_free(msgcopy);
}
-#if 0
-/*
- * OTR notification. Haven't seen one yet.
- */
-static void ops_notify(void *opdata, OtrlNotifyLevel level, const char *accountname,
- const char *protocol, const char *username,
- const char *title, const char *primary,
- const char *secondary)
-{
- ConnContext *co = otr_getcontext(accountname, username, FALSE, NULL);
- IRC_CTX *server = opdata;
- struct co_info *coi;
- if (co) {
- coi = co->app_data;
- server = coi->ircctx;
- } else
- otr_notice(server, username, TXT_OPS_NOTIFY_BUG);
-
- otr_notice(server, username, TXT_OPS_NOTIFY,
- title, primary, secondary);
-}
-#endif /* disabled */
-
-#if 0
-#ifdef HAVE_GREGEX_H
-/* This is kind of messy. */
-const char *convert_otr_msg(const char *msg)
-{
- GRegex *regex_bold = g_regex_new("</?i([ /][^>]*)?>", 0, 0, NULL);
- GRegex *regex_del = g_regex_new("</?b([ /][^>]*)?>", 0, 0, NULL);
- gchar *msgnohtml = g_regex_replace_literal(regex_del, msg, -1, 0, "", 0,
- NULL);
-
- msg = g_regex_replace_literal(regex_bold, msgnohtml, -1, 0, "*", 0, NULL);
-
- g_free(msgnohtml);
- g_regex_unref(regex_del);
- g_regex_unref(regex_bold);
-
- return msg;
-}
-#endif /* HAVE_GREGEX_H */
-
-/*
- * OTR message. E.g. "following has been transmitted in clear: ...".
- * We're trying to kill the ugly HTML.
- */
-static 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, opdata);
- IRC_CTX *server = opdata;
- struct co_info *coi;
-
- if (co) {
- coi = co->app_data;
- server = coi->ircctx;
- } else
- otr_notice(server, username, TXT_OPS_DISPLAY_BUG);
-
-#ifdef HAVE_GREGEX_H
- msg = convert_otr_msg(msg);
- otr_notice(server, username, TXT_OPS_DISPLAY, msg);
- g_free((char*)msg);
-#else
- otr_notice(server, username, TXT_OPS_DISPLAY, msg);
-#endif
-
- return 0;
-}
-#endif /* disabled */
-
/*
* Gone secure.
*/
static void ops_secure(void *opdata, ConnContext *context)
{
- struct co_info *coi = context->app_data;
- char * trust = context->active_fingerprint->trust ? : "";
- char ownfp[45], peerfp[45];
+ int ret;
+ struct irssi_otr_context *ioc;
+ char ownfp[OTRL_PRIVKEY_FPRINT_HUMAN_LEN];
+ char peerfp[OTRL_PRIVKEY_FPRINT_HUMAN_LEN];
- otr_notice(coi->ircctx, context->username, TXT_OPS_SEC);
- otr_status_change(coi->ircctx, context->username, IO_STC_GONE_SECURE);
+ assert(context);
+ /* This should *really* not happened */
+ assert(context->msgstate == OTRL_MSGSTATE_FINISHED);
- //TODO: pull master context
- coi->finished = FALSE;
+ ioc = context->app_data;
- if (*trust != '\0') {
+ IRSSI_NOTICE(ioc->irssi, context->username, "%9OTR%9: Gone %9secure%9");
+ otr_status_change(ioc->irssi, context->username, IO_STC_GONE_SECURE);
+
+ ret = otrl_context_is_fingerprint_trusted(context->active_fingerprint);
+ if (ret) {
+ /* Secure and trusted */
goto end;
}
- /*
- * Not authenticated. Let's print out the fingerprints for comparison.
- */
+ /* Not authenticated. Let's print out the fingerprints for comparison. */
otrl_privkey_hash_to_human(peerfp,
context->active_fingerprint->fingerprint);
+ otrl_privkey_fingerprint(ioustate_uniq.otr_state, ownfp,
+ context->accountname, OTR_PROTOCOL_ID);
+
+ IRSSI_NOTICE(ioc->irssi, context->username, "%9OTR%9: Your peer is not "
+ "authenticated. To make sure you're talking to the right guy you can "
+ "either agree on a secret and use the authentication described in "
+ "%9/otr auth%9, or, recommended, use %9/otr authq [QUESTION] SECRET%9 "
+ "or use the traditional way and compare fingerprints "
+ "over a secure line (e.g. telephone) and subsequently enter %9/otr "
+ "trust%9.");
- otr_notice(coi->ircctx, context->username, TXT_OPS_FPCOMP,
- otrl_privkey_fingerprint(IRCCTX_IO_US(coi->ircctx)->otr_state,
- ownfp, context->accountname, OTR_PROTOCOL_ID), context->username,
- peerfp);
+ IRSSI_NOTICE("Your fingerprint is: %s.\n%s fingerprint is: %s", ownfp,
+ context->username, peerfp);
end:
return;
@@ -254,9 +194,9 @@ end:
*/
static 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);
+ struct irssi_otr_context *ioc = context->app_data;
+ otr_notice(ioc->irssi, context->username, TXT_OPS_INSEC);
+ otr_status_change(ioc->irssi, context->username, IO_STC_GONE_INSECURE);
}
/*
@@ -264,8 +204,8 @@ static void ops_insecure(void *opdata, ConnContext *context)
*/
static void ops_still_secure(void *opdata, ConnContext *context, int is_reply)
{
- struct co_info *coi = context->app_data;
- otr_notice(coi->ircctx, context->username,
+ struct irssi_otr_context *ioc = context->app_data;
+ otr_notice(ioc->irssi, context->username,
is_reply ? TXT_OPS_STILL_REPLY : TXT_OPS_STILL_NO_REPLY);
}
@@ -339,9 +279,9 @@ static void ops_up_ctx_list(void *opdata)
*/
static void ops_write_fingerprints(void *data)
{
- IRC_CTX *ircctx __attribute__((unused)) = data;
+ IRC_CTX *irssi __attribute__((unused)) = data;
- key_write_fingerprints(IRCCTX_IO_US(ircctx));
+ key_write_fingerprints(IRSSI_IO_US(irssi));
}
static int ops_is_logged_in(void *opdata, const char *accountname,
@@ -356,49 +296,48 @@ static int ops_is_logged_in(void *opdata, const char *accountname,
static void ops_create_instag(void *opdata, const char *accountname,
const char *protocol)
{
- otrl_instag_generate(IRCCTX_IO_US(ircctx)->otr_state, "/dev/null",
+ otrl_instag_generate(IRSSI_IO_US(irssi)->otr_state, "/dev/null",
accountname, protocol);
- otr_writeinstags(IRCCTX_IO_US(ircctx));
+ otr_writeinstags(IRSSI_IO_US(irssi));
}
static void ops_smp_event(void *opdata, OtrlSMPEvent smp_event,
ConnContext *context, unsigned short progress_percent, char *question)
{
- IRC_CTX *ircctx = (IRC_CTX *) opdata;
+ IRC_CTX *irssi = (IRC_CTX *) opdata;
const char *from = context->username;
- struct co_info *coi = context->app_data;
+ struct irssi_otr_context *ioc = context->app_data;
- coi->received_smp_init =
+ ioc->received_smp_init =
(smp_event == OTRL_SMPEVENT_ASK_FOR_SECRET) ||
(smp_event == OTRL_SMPEVENT_ASK_FOR_ANSWER);
switch (smp_event) {
case OTRL_SMPEVENT_ASK_FOR_SECRET:
- otr_notice(ircctx, from, TXT_AUTH_PEER, from);
- otr_status_change(ircctx, from, IO_STC_SMP_INCOMING);
+ otr_notice(irssi, from, TXT_AUTH_PEER, from);
+ otr_status_change(irssi, from, IO_STC_SMP_INCOMING);
break;
case OTRL_SMPEVENT_ASK_FOR_ANSWER:
- otr_notice(ircctx, from, TXT_AUTH_PEER_QA, from, question);
- otr_status_change(ircctx, from, IO_STC_SMP_INCOMING);
+ otr_notice(irssi, from, TXT_AUTH_PEER_QA, from, question);
+ otr_status_change(irssi, from, IO_STC_SMP_INCOMING);
break;
case OTRL_SMPEVENT_IN_PROGRESS:
- otr_notice(ircctx, from, TXT_AUTH_PEER_REPLIED, from);
- otr_status_change(ircctx, from, IO_STC_SMP_FINALIZE);
+ otr_notice(irssi, from, TXT_AUTH_PEER_REPLIED, from);
+ otr_status_change(irssi, from, IO_STC_SMP_FINALIZE);
break;
case OTRL_SMPEVENT_SUCCESS:
- otr_notice(ircctx, from, TXT_AUTH_SUCCESSFUL);
- otr_status_change(ircctx, from, IO_STC_SMP_SUCCESS);
+ otr_notice(irssi, from, TXT_AUTH_SUCCESSFUL);
+ otr_status_change(irssi, from, IO_STC_SMP_SUCCESS);
break;
case OTRL_SMPEVENT_ABORT:
- otr_abort_auth(context, ircctx, from);
- otr_status_change(ircctx, from, IO_STC_SMP_ABORTED);
+ otr_abort_auth(context, irssi, from);
+ otr_status_change(irssi, from, IO_STC_SMP_ABORTED);
break;
case OTRL_SMPEVENT_FAILURE:
case OTRL_SMPEVENT_CHEATED:
case OTRL_SMPEVENT_ERROR:
- otr_notice(ircctx, from, TXT_AUTH_FAILED);
- coi->smp_failed = TRUE;
- otr_status_change(ircctx, from, IO_STC_SMP_FAILED);
+ otr_notice(irssi, from, TXT_AUTH_FAILED);
+ otr_status_change(irssi, from, IO_STC_SMP_FAILED);
break;
default:
otr_logst(MSGLEVEL_CRAP, "Received unknown SMP event");
diff --git a/src/otr.c b/src/otr.c
index ec7655f..ab4cf6a 100644
--- a/src/otr.c
+++ b/src/otr.c
@@ -105,34 +105,29 @@ void otr_lib_uninit()
*/
static void context_free_app_info(void *data)
{
- struct co_info *coi = data;
- if (coi->msgqueue) {
- g_free(coi->msgqueue);
- }
- if (coi->ircctx) {
- IRCCTX_FREE(coi->ircctx);
+ struct irssi_otr_context *ioc = data;
+ if (ioc->irssi) {
+ IRSSI_FREE(ioc->irssi);
}
}
/*
- * Add app data to context. See struct co_info for details.
+ * Add app data to context. See struct irssi_otr_context for details.
*/
static void context_add_app_info(void *data, ConnContext *co)
{
- IRC_CTX *ircctx = IRCCTX_DUP(data);
- struct co_info *coi;
+ IRC_CTX *irssi = IRSSI_DUP(data);
+ struct irssi_otr_context *ioc;
- coi = g_malloc0(sizeof(struct co_info));
- if (coi == NULL) {
+ ioc = g_malloc0(sizeof(struct irssi_otr_context));
+ if (ioc == NULL) {
goto end;
}
- co->app_data = coi;
+ co->app_data = ioc;
co->app_data_free = context_free_app_info;
- coi->ircctx = ircctx;
- snprintf(coi->better_msg_two, sizeof(coi->better_msg_two),
- formats[TXT_OTR_BETTER_TWO].def, co->accountname);
+ ioc->irssi = irssi;
end:
return;
@@ -144,7 +139,7 @@ end:
static ConnContext *get_otrl_context(const char *accname, const char *nick,
int create, IRC_CTX *irssi_ctx)
{
- ConnContext *ctx = otrl_context_find(IRCCTX_IO_US(irssi_ctx)->otr_state,
+ ConnContext *ctx = otrl_context_find(IRSSI_IO_US(irssi_ctx)->otr_state,
nick, accname, OTR_PROTOCOL_ID, OTRL_INSTAG_BEST, create, NULL,
context_add_app_info, irssi_ctx);
@@ -156,20 +151,20 @@ static ConnContext *get_otrl_context(const char *accname, const char *nick,
*
* Return 0 if the message was successfully handled or else a negative value.
*/
-int otr_send(IRC_CTX *ircctx, const char *msg, const char *to, char **otr_msg)
+int otr_send(IRC_CTX *irssi, const char *msg, const char *to, char **otr_msg)
{
gcry_error_t err;
char accname[256];
- IRCCTX_ACCNAME(accname, ircctx);
+ IRSSI_ACCNAME(accname, irssi);
otr_logst(MSGLEVEL_CRAP, "%d: sending msg", time(NULL));
- err = otrl_message_sending(IRCCTX_IO_US(ircctx)->otr_state, &otr_ops,
- ircctx, accname, OTR_PROTOCOL_ID, to, OTRL_INSTAG_BEST, msg, NULL, otr_msg,
- OTRL_FRAGMENT_SEND_ALL_BUT_LAST, NULL, context_add_app_info, ircctx);
+ err = otrl_message_sending(IRSSI_IO_US(irssi)->otr_state, &otr_ops,
+ irssi, accname, OTR_PROTOCOL_ID, to, OTRL_INSTAG_BEST, msg, NULL, otr_msg,
+ OTRL_FRAGMENT_SEND_ALL_BUT_LAST, NULL, context_add_app_info, irssi);
if (err) {
- otr_notice(ircctx, to, TXT_SEND_FAILED, msg);
+ otr_notice(irssi, to, TXT_SEND_FAILED, msg);
goto error;
}
@@ -250,22 +245,19 @@ struct ctxlist_ *otr_contexts(IOUSTATE *ioustate)
/*
* Get the OTR status of this conversation.
*/
-int otr_getstatus(IRC_CTX *ircctx, const char *nick)
+int otr_getstatus(IRC_CTX *irssi, const char *nick)
{
int ret, code = 0;
ConnContext *ctx;
char accname[128];
- struct co_info *coi;
- IRCCTX_ACCNAME(accname, ircctx);
+ IRSSI_ACCNAME(accname, irssi);
- if (!(ctx = get_otrl_context(accname, nick, FALSE, ircctx))) {
+ if (!(ctx = get_otrl_context(accname, nick, FALSE, irssi))) {
code = IO_ST_PLAINTEXT;
goto end;
}
- coi = ctx->app_data;
-
switch (ctx->msgstate) {
case OTRL_MSGSTATE_PLAINTEXT:
code = IO_ST_PLAINTEXT;
@@ -276,9 +268,7 @@ int otr_getstatus(IRC_CTX *ircctx, const char *nick)
switch (ex) {
case OTRL_SMP_EXPECT1:
- if (coi->received_smp_init) {
- code = IO_ST_SMP_INCOMING;
- }
+ code = IO_ST_SMP_INCOMING;
break;
case OTRL_SMP_EXPECT2:
code = IO_ST_SMP_OUTGOING;
@@ -314,54 +304,38 @@ end:
/*
* Finish the conversation.
*/
-void otr_finish(IRC_CTX *ircctx, char *nick, const char *peername, int inquery)
+void otr_finish(IRC_CTX *irssi, char *nick, const char *peername, int inquery)
{
ConnContext *co;
char accname[128];
- struct co_info *coi;
char nickbuf[128];
if (peername) {
nick = nickbuf;
- ircctx = ircctx_by_peername(peername, nick);
- if (!ircctx) {
+ irssi = ircctx_by_peername(peername, nick);
+ if (!irssi) {
goto end;
}
}
- IRCCTX_ACCNAME(accname, ircctx);
+ IRSSI_ACCNAME(accname, irssi);
- if (!(co = get_otrl_context(accname, nick, FALSE, ircctx))) {
+ if (!(co = get_otrl_context(accname, nick, FALSE, irssi))) {
if (inquery) {
otr_noticest(TXT_CTX_NOT_FOUND, accname, nick);
}
goto end;
}
- otrl_message_disconnect(IRCCTX_IO_US(ircctx)->otr_state, &otr_ops, ircctx,
+ otrl_message_disconnect(IRSSI_IO_US(irssi)->otr_state, &otr_ops, irssi,
accname, OTR_PROTOCOL_ID, nick, co->their_instance);
- otr_status_change(ircctx, nick, IO_STC_FINISHED);
+ otr_status_change(irssi, nick, IO_STC_FINISHED);
if (inquery) {
- otr_info(ircctx, nick, TXT_CMD_FINISH, nick, IRCCTX_ADDR(ircctx));
+ otr_info(irssi, nick, TXT_CMD_FINISH, nick, IRSSI_CONN_ADDR(irssi));
} else {
- otr_infost(TXT_CMD_FINISH, nick, IRCCTX_ADDR(ircctx));
- }
-
- coi = co->app_data;
-
- /* finish if /otr finish has been issued. Reset if
- * we're called cause the query window has been closed. */
- if (coi) {
- coi->finished = inquery;
- }
-
- /* write the finished into the master as well */
- co = otrl_context_find(IRCCTX_IO_US(ircctx)->otr_state, nick, accname,
- OTR_PROTOCOL_ID, OTRL_INSTAG_MASTER, FALSE, NULL, NULL, NULL);
- if (co) {
- coi = co->app_data;
+ otr_infost(TXT_CMD_FINISH, nick, IRSSI_CONN_ADDR(irssi));
}
end:
@@ -375,19 +349,19 @@ void otr_finishall(IOUSTATE *ioustate)
for (context = ioustate->otr_state->context_root; context;
context = context->next) {
- struct co_info *coi = context->app_data;
+ struct irssi_otr_context *ioc = context->app_data;
if (context->msgstate != OTRL_MSGSTATE_ENCRYPTED) {
continue;
}
- otrl_message_disconnect(ioustate->otr_state, &otr_ops, coi->ircctx,
+ otrl_message_disconnect(ioustate->otr_state, &otr_ops, ioc->irssi,
context->accountname, OTR_PROTOCOL_ID, context->username,
context->their_instance);
- otr_status_change(coi->ircctx, context->username, IO_STC_FINISHED);
+ otr_status_change(ioc->irssi, context->username, IO_STC_FINISHED);
otr_infost(TXT_CMD_FINISH, context->username,
- IRCCTX_ADDR(coi->ircctx));
+ IRSSI_CONN_ADDR(ioc->irssi));
finished++;
}
@@ -399,35 +373,30 @@ void otr_finishall(IOUSTATE *ioustate)
/*
* Trust our peer.
*/
-void otr_trust(IRC_CTX *ircctx, char *nick, const char *peername)
+void otr_trust(IRC_CTX *irssi, char *nick, const char *peername)
{
ConnContext *co;
char accname[128];
- struct co_info *coi;
char nickbuf[128];
if (peername) {
nick = nickbuf;
- ircctx = ircctx_by_peername(peername, nick);
- if (!ircctx) {
+ irssi = ircctx_by_peername(peername, nick);
+ if (!irssi) {
goto end;
}
}
- IRCCTX_ACCNAME(accname, ircctx);
+ IRSSI_ACCNAME(accname, irssi);
- if (!(co = get_otrl_context(accname, nick, FALSE, ircctx))) {
+ if (!(co = get_otrl_context(accname, nick, FALSE, irssi))) {
otr_noticest(TXT_CTX_NOT_FOUND, accname, nick);
goto end;
}
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;
-
- otr_notice(ircctx, nick, TXT_FP_TRUST, nick);
+ otr_status_change(irssi, nick, IO_STC_TRUST_MANUAL);
+ otr_notice(irssi, nick, TXT_FP_TRUST, nick);
end:
return;
@@ -436,27 +405,21 @@ end:
/*
* Abort any ongoing SMP authentication.
*/
-void otr_abort_auth(ConnContext *co, IRC_CTX *ircctx, const char *nick)
+void otr_abort_auth(ConnContext *co, IRC_CTX *irssi, const char *nick)
{
- struct co_info *coi;
-
- coi = co->app_data;
-
- coi->received_smp_init = FALSE;
-
- otr_notice(ircctx, nick,
+ otr_notice(irssi, nick,
co->smstate->nextExpected != OTRL_SMP_EXPECT1 ?
TXT_AUTH_ABORTED_ONGOING : 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);
+ otrl_message_abort_smp(IRSSI_IO_US(irssi)->otr_state, &otr_ops,
+ irssi, co);
+ otr_status_change(irssi, nick, IO_STC_SMP_ABORT);
}
/*
* implements /otr authabort
*/
-void otr_authabort(IRC_CTX *ircctx, char *nick, const char *peername)
+void otr_authabort(IRC_CTX *irssi, char *nick, const char *peername)
{
ConnContext *co;
char accname[128];
@@ -464,20 +427,20 @@ void otr_authabort(IRC_CTX *ircctx, char *nick, const char *peername)
if (peername) {
nick = nickbuf;
- ircctx = ircctx_by_peername(peername, nick);
- if (!ircctx) {
+ irssi = ircctx_by_peername(peername, nick);
+ if (!irssi) {
goto end;
}
}
- IRCCTX_ACCNAME(accname, ircctx);
+ IRSSI_ACCNAME(accname, irssi);
- if (!(co = get_otrl_context(accname, nick, FALSE, ircctx))) {
+ if (!(co = get_otrl_context(accname, nick, FALSE, irssi))) {
otr_noticest(TXT_CTX_NOT_FOUND, accname, nick);
goto end;
}
- otr_abort_auth(co, ircctx, nick);
+ otr_abort_auth(co, irssi, nick);
end:
return;
@@ -486,70 +449,68 @@ end:
/*
* Initiate or respond to SMP authentication.
*/
-void otr_auth(IRC_CTX *ircctx, char *nick, const char *peername,
+void otr_auth(IRC_CTX *irssi, char *nick, const char *peername,
const char *question, const char *secret)
{
ConnContext *co;
+ struct irssi_otr_context *ioc;
char accname[128];
- struct co_info *coi;
char nickbuf[128];
if (peername) {
nick = nickbuf;
- ircctx = ircctx_by_peername(peername, nick);
- if (!ircctx) {
+ irssi = ircctx_by_peername(peername, nick);
+ if (!irssi) {
goto end;
}
}
- IRCCTX_ACCNAME(accname, ircctx);
+ IRSSI_ACCNAME(accname, irssi);
- if (!(co = get_otrl_context(accname, nick, FALSE, ircctx))) {
+ if (!(co = get_otrl_context(accname, nick, FALSE, irssi))) {
otr_noticest(TXT_CTX_NOT_FOUND, accname, nick);
goto end;
}
if (co->msgstate != OTRL_MSGSTATE_ENCRYPTED) {
- otr_notice(ircctx, nick, TXT_AUTH_NEEDENC);
+ otr_notice(irssi, nick, TXT_AUTH_NEEDENC);
goto end;
}
- coi = co->app_data;
+ ioc = co->app_data;
/* Aborting an ongoing auth */
if (co->smstate->nextExpected != OTRL_SMP_EXPECT1) {
- otr_abort_auth(co, ircctx, nick);
+ otr_abort_auth(co, irssi, nick);
}
- coi->smp_failed = FALSE;
-
/* reset trust level */
if (co->active_fingerprint) {
char *trust = co->active_fingerprint->trust;
if (trust && (*trust != '\0')) {
otrl_context_set_trust(co->active_fingerprint, "");
- key_write_fingerprints(IRCCTX_IO_US(ircctx));
+ key_write_fingerprints(IRSSI_IO_US(irssi));
}
}
- if (!coi->received_smp_init) {
+ if (!ioc->received_smp_init) {
if (question) {
- otrl_message_initiate_smp_q(IRCCTX_IO_US(ircctx)->otr_state,
- &otr_ops, ircctx, co, question, (unsigned char *) secret,
+ otrl_message_initiate_smp_q(IRSSI_IO_US(irssi)->otr_state,
+ &otr_ops, irssi, co, question, (unsigned char *) secret,
strlen(secret));
} else {
- otrl_message_initiate_smp(IRCCTX_IO_US(ircctx)->otr_state,
- &otr_ops, ircctx, co, (unsigned char *) secret,
+ otrl_message_initiate_smp(IRSSI_IO_US(irssi)->otr_state,
+ &otr_ops, irssi, co, (unsigned char *) secret,
strlen(secret));
}
- otr_status_change(ircctx, nick, IO_STC_SMP_STARTED);
+ otr_status_change(irssi, nick, IO_STC_SMP_STARTED);
} else {
- otrl_message_respond_smp(IRCCTX_IO_US(ircctx)->otr_state, &otr_ops,
- ircctx, co, (unsigned char *) secret, strlen(secret));
- otr_status_change(ircctx, nick, IO_STC_SMP_RESPONDED);
+ otrl_message_respond_smp(IRSSI_IO_US(irssi)->otr_state, &otr_ops,
+ irssi, co, (unsigned char *) secret, strlen(secret));
+ otr_status_change(irssi, nick, IO_STC_SMP_RESPONDED);
}
- otr_notice(ircctx, nick, coi->received_smp_init ? TXT_AUTH_RESPONDING :
+ otr_notice(irssi, nick, ioc->received_smp_init ? TXT_AUTH_RESPONDING :
TXT_AUTH_INITIATED);
end:
@@ -561,33 +522,33 @@ end:
*
* Returns 0 if its an OTR protocol message or else negative value.
*/
-int otr_receive(IRC_CTX *ircctx, const char *msg, const char *from,
+int otr_receive(IRC_CTX *irssi, const char *msg, const char *from,
char **new_msg)
{
int ret = -1;
char accname[256];
OtrlTLV *tlvs;
- IRCCTX_ACCNAME(accname, ircctx);
+ IRSSI_ACCNAME(accname, irssi);
otr_logst(MSGLEVEL_CRAP, "%d: receiving...", time(NULL));
- ret = otrl_message_receiving(IRCCTX_IO_US(ircctx)->otr_state,
- &otr_ops, ircctx, accname, OTR_PROTOCOL_ID, from, msg, new_msg, &tlvs,
- NULL, context_add_app_info, ircctx);
+ ret = otrl_message_receiving(IRSSI_IO_US(irssi)->otr_state,
+ &otr_ops, irssi, accname, OTR_PROTOCOL_ID, from, msg, new_msg, &tlvs,
+ NULL, context_add_app_info, irssi);
if (ret) {
- otr_debug(ircctx, from, TXT_RECEIVE_IGNORE, strlen(msg), accname, from,
+ otr_debug(irssi, from, TXT_RECEIVE_IGNORE, strlen(msg), accname, from,
msg);
} else {
if (*new_msg) {
- otr_debug(ircctx, from, TXT_RECEIVE_CONVERTED);
+ otr_debug(irssi, from, TXT_RECEIVE_CONVERTED);
}
}
OtrlTLV *tlv = otrl_tlv_find(tlvs, OTRL_TLV_DISCONNECTED);
if (tlv) {
- otr_status_change(ircctx, from, IO_STC_PEER_FINISHED);
- otr_notice(ircctx, from, TXT_PEER_FINISHED, from);
+ otr_status_change(irssi, from, IO_STC_PEER_FINISHED);
+ otr_notice(irssi, from, TXT_PEER_FINISHED, from);
}
otrl_tlv_free(tlvs);
@@ -661,9 +622,9 @@ void otr_setpolicies(IOUSTATE *ioustate, const char *policies, int known)
/*
* Get a format describing the OTR status of this conversation.
*/
-int otr_getstatus_format(IRC_CTX *ircctx, const char *nick)
+int otr_getstatus_format(IRC_CTX *irssi, const char *nick)
{
- int status = otr_getstatus(ircctx, nick);
+ int status = otr_getstatus(irssi, nick);
if (status & (IO_ST_SMP_ONGOING)) {
/* we don't care about the trust level in that case */
@@ -695,9 +656,9 @@ int otr_getstatus_format(IRC_CTX *ircctx, const char *nick)
/*
* Change status bar text for a given nickname.
*/
-void otr_status_change(IRC_CTX *ircctx, const char *nick,
+void otr_status_change(IRC_CTX *irssi, const char *nick,
enum statusbar_event event)
{
statusbar_items_redraw("otr");
- signal_emit("otr event", 3, ircctx, nick, statusbar_txt[event]);
+ signal_emit("otr event", 3, irssi, nick, statusbar_txt[event]);
}
diff --git a/src/otr.h b/src/otr.h
index c4e6d62..b75898b 100644
--- a/src/otr.h
+++ b/src/otr.h
@@ -72,16 +72,9 @@ typedef struct {
} IOUSTATE;
/* one for each OTR context (=communication pair) */
-struct co_info {
- char *msgqueue; /* holds partially reconstructed base64
- messages */
- IRC_CTX *ircctx; /* irssi server object for this peer */
- int received_smp_init; /* received SMP init msg */
- int smp_failed; /* last SMP failed */
- char better_msg_two[256]; /* what the second line of the "better"
- default query msg should like. Eat it
- up when it comes in */
- int finished; /* true after you've /otr finished */
+struct irssi_otr_context {
+ SERVER_REC *irssi; /* Irssi server object for this peer */
+ unsigned int received_smp_init; /* Do the SMP auth was received ? */
};
/* these are returned by /otr contexts */
--
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