[Pkg-privacy-commits] [irssi-plugin-otr] 94/267: Refactor otr.c operation
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 0a7d604e388cbc234f7a5d6c96cbfc45deb0d630
Author: David Goulet <dgoulet at ev0ke.net>
Date: Fri Nov 2 20:11:23 2012 -0400
Refactor otr.c operation
Basically drop support for libotr3 and change the *cluster fuck* of code
standard and weird functions.
Signed-off-by: David Goulet <dgoulet at ev0ke.net>
---
src/irssi_otr.h | 1 -
src/key.c | 2 +-
src/key.h | 2 +-
src/module.c | 31 ++--
src/otr-ops.c | 2 +-
src/otr.c | 499 +++++++++++++++++++++++---------------------------------
src/otr.h | 17 +-
7 files changed, 236 insertions(+), 318 deletions(-)
diff --git a/src/irssi_otr.h b/src/irssi_otr.h
index 4756ea1..a2e50ff 100644
--- a/src/irssi_otr.h
+++ b/src/irssi_otr.h
@@ -33,7 +33,6 @@
#include <src/core/settings.h>
#include <src/irc/core/irc.h>
#include <src/irc/core/irc-queries.h>
-
#include <src/fe-text/statusbar-item.h>
#define IRC_CTX SERVER_REC
diff --git a/src/key.c b/src/key.c
index 5caf431..4964c3c 100644
--- a/src/key.c
+++ b/src/key.c
@@ -243,7 +243,7 @@ end:
/*
* Write fingerprints to file.
*/
-void otr_writefps(IOUSTATE *ioustate)
+void key_write_fingerprints(IOUSTATE *ioustate)
{
gcry_error_t err;
char *filename = g_strconcat(get_client_config_dir(), FPSFILE, NULL);
diff --git a/src/key.h b/src/key.h
index 7afcfef..ae89382 100644
--- a/src/key.h
+++ b/src/key.h
@@ -27,7 +27,7 @@ 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 otr_writefps(IOUSTATE *ioustate);
+void key_write_fingerprints(IOUSTATE *ioustate);
void otr_writeinstags(IOUSTATE *ioustate);
void instag_load(IOUSTATE *ioustate);
diff --git a/src/module.c b/src/module.c
index 8545681..4711aef 100644
--- a/src/module.c
+++ b/src/module.c
@@ -53,6 +53,7 @@ void irc_send_message(IRC_CTX *ircctx, const char *recipient, char *msg)
static void sig_server_sendmsg(SERVER_REC *server, const char *target,
const char *msg, void *target_type_p)
{
+ int ret;
char *otrmsg;
if (GPOINTER_TO_INT(target_type_p) != SEND_TARGET_NICK) {
@@ -65,15 +66,17 @@ static void sig_server_sendmsg(SERVER_REC *server, const char *target,
}
#endif
- otrmsg = otr_send(server,msg,target);
- if (otrmsg && (otrmsg != msg)) {
- signal_continue(4, server, target, otrmsg, target_type_p);
- otrl_message_free(otrmsg);
- } else if (!otrmsg) {
+ /* Critical section. On error, message MUST NOT be sent */
+ ret = otr_send(server, msg, target, &otrmsg);
+ if (ret) {
signal_stop();
+ goto end;
}
+ signal_continue(4, server, target, otrmsg, target_type_p);
+
end:
+ otrl_message_free(otrmsg);
return;
}
@@ -83,7 +86,8 @@ end:
static void sig_message_private(SERVER_REC *server, const char *msg,
const char *nick, const char *address)
{
- char *newmsg;
+ int ret;
+ char *new_msg;
#ifdef HAVE_GREGEX_H
if (g_regex_match(regex_nickignore, nick, 0, NULL)) {
@@ -91,15 +95,16 @@ static void sig_message_private(SERVER_REC *server, const char *msg,
}
#endif
- newmsg = otr_receive(server,msg,nick);
- if (newmsg && (newmsg != msg)) {
- signal_continue(4, server, newmsg, nick, address);
- otrl_message_free(newmsg);
- } else if (!newmsg) {
+ ret = otr_receive(server, msg, nick, &new_msg);
+ if (ret) {
signal_stop();
+ goto end;
}
+ signal_continue(4, server, new_msg, nick, address);
+
end:
+ otrl_message_free(new_msg);
return;
}
@@ -263,9 +268,9 @@ void otr_deinit(void)
otr_finishall(ioustate);
}
- otr_deinit_user(ioustate);
+ otr_free_user(ioustate);
- otrlib_deinit();
+ otr_lib_uninit();
theme_unregister();
}
diff --git a/src/otr-ops.c b/src/otr-ops.c
index 0f29721..c9d3df3 100644
--- a/src/otr-ops.c
+++ b/src/otr-ops.c
@@ -284,7 +284,7 @@ static void ops_write_fingerprints(void *data)
{
IRC_CTX *ircctx __attribute__((unused)) = data;
- otr_writefps(IRCCTX_IO_US(ircctx));
+ key_write_fingerprints(IRCCTX_IO_US(ircctx));
}
static int ops_is_logged_in(void *opdata, const char *accountname,
diff --git a/src/otr.c b/src/otr.c
index 3751200..f7d80b3 100644
--- a/src/otr.c
+++ b/src/otr.c
@@ -35,26 +35,26 @@ IOUSTATE *otr_init_user(char *user)
ioustate->otr_state = otrl_userstate_create();
- /* load keys and fingerprints */
-
#ifndef LIBOTR3
instag_load(ioustate);
#endif
+ /* Load keys and fingerprints. */
key_load(ioustate);
key_load_fingerprints(ioustate);
return ioustate;
}
-void otr_deinit_user(IOUSTATE *ioustate)
+void otr_free_user(IOUSTATE *ioustate)
{
key_generation_abort(ioustate, TRUE);
if (ioustate->otr_state) {
- otr_writefps(ioustate);
+ key_write_fingerprints(ioustate);
otrl_userstate_free(ioustate->otr_state);
ioustate->otr_state = NULL;
}
+
otr_setpolicies(ioustate, "", FALSE);
otr_setpolicies(ioustate, "", TRUE);
}
@@ -76,7 +76,7 @@ void otr_lib_init()
/*
* deinit otr lib.
*/
-void otrlib_deinit()
+void otr_lib_uninit()
{
#ifdef HAVE_GREGEX_H
g_regex_unref(regex_policies);
@@ -102,28 +102,34 @@ void context_free_app_info(void *data)
}
/*
- * Add app data to context.
- * See struct co_info for details.
+ * Add app data to context. See struct co_info for details.
*/
-void context_add_app_info(void *data, ConnContext *co)
+static void context_add_app_info(void *data, ConnContext *co)
{
IRC_CTX *ircctx = IRCCTX_DUP(data);
- struct co_info *coi = g_malloc(sizeof(struct co_info));
+ struct co_info *coi;
+
+ coi = g_malloc0(sizeof(struct co_info));
+ if (coi == NULL) {
+ goto end;
+ }
- memset(coi, 0, sizeof(struct co_info));
co->app_data = coi;
co->app_data_free = context_free_app_info;
coi->ircctx = ircctx;
- sprintf(coi->better_msg_two, formats[TXT_OTR_BETTER_TWO].def,
- co->accountname);
+ snprintf(coi->better_msg_two, sizeof(coi->better_msg_two),
+ formats[TXT_OTR_BETTER_TWO].def, co->accountname);
+
+end:
+ return;
}
/*
* Get a context from a pair.
*/
ConnContext *otr_getcontext(const char *accname, const char *nick,
- int create, IRC_CTX *ircctx)
+ int create, IRC_CTX *ircctx)
{
ConnContext *co = otrl_context_find(
IRCCTX_IO_US(ircctx)->otr_state,
@@ -137,81 +143,43 @@ ConnContext *otr_getcontext(const char *accname, const char *nick,
NULL,
context_add_app_info,
ircctx);
-
/* context came from a fingerprint */
- if (co && ircctx && !co->app_data)
+ if (co && ircctx && !co->app_data) {
context_add_app_info(ircctx, co);
+ }
return co;
}
/*
* Hand the given message to OTR.
- * Returns NULL if OTR handled the message and
- * the original message otherwise.
+ *
+ * Return 0 if the message was successfully handled or else a negative value.
*/
-char *otr_send(IRC_CTX *ircctx, const char *msg, const char *to)
+int otr_send(IRC_CTX *ircctx, const char *msg, const char *to, char **otr_msg)
{
gcry_error_t err;
- char *newmessage = NULL;
ConnContext *co;
char accname[256];
IRCCTX_ACCNAME(accname, ircctx);
- otr_logst(MSGLEVEL_CRAP, "%d: send...", time(NULL));
- err = otrl_message_sending(
- IRCCTX_IO_US(ircctx)->otr_state,
- &otr_ops,
- ircctx,
- accname,
- PROTOCOLID,
- to,
-#ifndef LIBOTR3
- OTRL_INSTAG_BEST,
-#endif
- msg,
- NULL,
- &newmessage,
-#ifndef LIBOTR3
- OTRL_FRAGMENT_SEND_ALL,
- &co,
-#endif
- context_add_app_info,
- ircctx);
- otr_logst(MSGLEVEL_CRAP, "%d: sent", time(NULL));
+ otr_logst(MSGLEVEL_CRAP, "%d: sending msg", time(NULL));
- if (err != 0) {
+ err = otrl_message_sending(IRCCTX_IO_US(ircctx)->otr_state, &otr_ops,
+ ircctx, accname, PROTOCOLID, 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);
- return NULL;
- }
-
- if (newmessage == NULL)
- return (char*)msg;
-
- /* OTR message. Need to do fragmentation */
-
-#ifdef LIBOTR3
- if (!(co = otr_getcontext(accname, to, FALSE, ircctx))) {
- otr_notice(ircctx, to, TXT_SEND_CHANGE);
- return NULL;
+ goto error;
}
- err = otrl_message_fragment_and_send(
- &otr_ops,
- ircctx,
- co,
- newmessage,
- OTRL_FRAGMENT_SEND_ALL,
- NULL);
+ otr_logst(MSGLEVEL_CRAP, "%d: sent", time(NULL));
- if (err != 0) {
- otr_notice(ircctx, to, TXT_SEND_FRAGMENT, msg);
- } else
- otr_debug(ircctx, to, TXT_SEND_CONVERTED, newmessage);
-#endif
+ return 0;
- return NULL;
+error:
+ return -1;
}
struct ctxlist_ *otr_contexts(IOUSTATE *ioustate)
@@ -225,49 +193,58 @@ struct ctxlist_ *otr_contexts(IOUSTATE *ioustate)
int i;
for (context = ioustate->otr_state->context_root; context;
- context = context->next) {
- if (!ctxlist)
+ context = context->next) {
+ if (!ctxlist) {
ctxhead = ctxlist = g_malloc0(sizeof(struct ctxlist_));
- else
- ctxlist = ctxlist->next = g_malloc0(sizeof(struct
- ctxlist_));
+ } else {
+ ctxlist = ctxlist->next = g_malloc0(sizeof(struct ctxlist_));
+ }
+
switch (context->msgstate) {
- case OTRL_MSGSTATE_PLAINTEXT: ctxlist->state = STUNENCRYPTED;
+ case OTRL_MSGSTATE_PLAINTEXT:
+ ctxlist->state = STUNENCRYPTED;
+ break;
+ case OTRL_MSGSTATE_ENCRYPTED:
+ ctxlist->state = STENCRYPTED;
break;
- case OTRL_MSGSTATE_ENCRYPTED: ctxlist->state = STENCRYPTED;
+ case OTRL_MSGSTATE_FINISHED:
+ ctxlist->state = STFINISHED;
break;
- case OTRL_MSGSTATE_FINISHED: ctxlist->state = STFINISHED;
+ default:
+ ctxlist->state = STUNKNOWN;
break;
- default: ctxlist->state = STUNKNOWN; break;
}
+
ctxlist->username = context->username;
ctxlist->accountname = context->accountname;
fplist = fphead = NULL;
for (fprint = context->fingerprint_root.next; fprint;
- fprint = fprint->next) {
- if (!fplist)
- fphead = fplist = g_malloc0(sizeof(struct
- fplist_));
- else
- fplist = fplist->next =
- g_malloc0(sizeof(struct
- fplist_));
+ fprint = fprint->next) {
+ if (!fplist) {
+ fphead = fplist = g_malloc0(sizeof(struct fplist_));
+ } else {
+ fplist = fplist->next = g_malloc0(sizeof(struct fplist_));
+ }
+
trust = fprint->trust ? : "";
- for (i = 0; i < 20; ++i)
- sprintf(fp + i * 2, "%02x",
- fprint->fingerprint[i]);
+
+ for (i = 0; i < 20; ++i) {
+ sprintf(fp + i * 2, "%02x", fprint->fingerprint[i]);
+ }
fplist->fp = g_strdup(fp);
- if (*trust == '\0')
+ if (*trust == '\0') {
fplist->authby = NOAUTH;
- else if (strcmp(trust, "smp") == 0)
+ } else if (strcmp(trust, "smp") == 0) {
fplist->authby = AUTHSMP;
- else
+ } else {
fplist->authby = AUTHMAN;
+ }
}
ctxlist->fplist = fphead;
}
+
return ctxhead;
}
@@ -336,8 +313,7 @@ int otr_getstatus(IRC_CTX *ircctx, const char *nick)
/*
* Finish the conversation.
*/
-void otr_finish(IRC_CTX *ircctx, char *nick, const char *peername,
- int inquery)
+void otr_finish(IRC_CTX *ircctx, char *nick, const char *peername, int inquery)
{
ConnContext *co;
char accname[128];
@@ -347,33 +323,27 @@ void otr_finish(IRC_CTX *ircctx, char *nick, const char *peername,
if (peername) {
nick = nickbuf;
ircctx = ircctx_by_peername(peername, nick);
- if (!ircctx)
- return;
+ if (!ircctx) {
+ goto end;
+ }
}
IRCCTX_ACCNAME(accname, ircctx);
if (!(co = otr_getcontext(accname, nick, FALSE, ircctx))) {
- if (inquery)
- otr_noticest(TXT_CTX_NOT_FOUND,
- accname, nick);
- return;
- }
-
- otrl_message_disconnect(IRCCTX_IO_US(ircctx)->otr_state,
- &otr_ops, ircctx, accname,
- PROTOCOLID,
-#ifdef LIBOTR3
- nick);
-#else
- nick, co->their_instance);
-#endif
+ if (inquery) {
+ otr_noticest(TXT_CTX_NOT_FOUND, accname, nick);
+ }
+ goto end;
+ }
+
+ otrl_message_disconnect(IRCCTX_IO_US(ircctx)->otr_state, &otr_ops, ircctx,
+ accname, PROTOCOLID, nick, co->their_instance);
otr_status_change(ircctx, nick, IO_STC_FINISHED);
if (inquery) {
- otr_info(ircctx, nick, TXT_CMD_FINISH, nick,
- IRCCTX_ADDR(ircctx));
+ otr_info(ircctx, nick, TXT_CMD_FINISH, nick, IRCCTX_ADDR(ircctx));
} else {
otr_infost(TXT_CMD_FINISH, nick, IRCCTX_ADDR(ircctx));
}
@@ -382,25 +352,19 @@ void otr_finish(IRC_CTX *ircctx, char *nick, const char *peername,
/* finish if /otr finish has been issued. Reset if
* we're called cause the query window has been closed. */
- if (coi)
+ if (coi) {
coi->finished = inquery;
+ }
-#ifndef LIBOTR3
- // 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);
- coi = co->app_data;
- if (coi)
- coi->finished = inquery;
-#endif
+ /* 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);
+ if (co) {
+ coi = co->app_data;
+ }
+
+end:
+ return;
}
void otr_finishall(IOUSTATE *ioustate)
@@ -409,32 +373,26 @@ void otr_finishall(IOUSTATE *ioustate)
int finished = 0;
for (context = ioustate->otr_state->context_root; context;
- context = context->next) {
+ context = context->next) {
struct co_info *coi = context->app_data;
- if (context->msgstate != OTRL_MSGSTATE_ENCRYPTED)
+ if (context->msgstate != OTRL_MSGSTATE_ENCRYPTED) {
continue;
+ }
- otrl_message_disconnect(ioustate->otr_state, &otr_ops,
- coi->ircctx,
- context->accountname,
- PROTOCOLID,
-#ifdef LIBOTR3
- context->username);
-#else
- context->username,
+ otrl_message_disconnect(ioustate->otr_state, &otr_ops, coi->ircctx,
+ context->accountname, PROTOCOLID, context->username,
context->their_instance);
-#endif
- otr_status_change(coi->ircctx, context->username,
- IO_STC_FINISHED);
+ otr_status_change(coi->ircctx, context->username, IO_STC_FINISHED);
otr_infost(TXT_CMD_FINISH, context->username,
- IRCCTX_ADDR(coi->ircctx));
+ IRCCTX_ADDR(coi->ircctx));
finished++;
}
- if (!finished)
+ if (!finished) {
otr_infost(TXT_CMD_FINISHALL_NONE);
+ }
}
/*
@@ -450,16 +408,16 @@ void otr_trust(IRC_CTX *ircctx, char *nick, const char *peername)
if (peername) {
nick = nickbuf;
ircctx = ircctx_by_peername(peername, nick);
- if (!ircctx)
- return;
+ if (!ircctx) {
+ goto end;
+ }
}
IRCCTX_ACCNAME(accname, ircctx);
if (!(co = otr_getcontext(accname, nick, FALSE, ircctx))) {
- otr_noticest(TXT_CTX_NOT_FOUND,
- accname, nick);
- return;
+ otr_noticest(TXT_CTX_NOT_FOUND, accname, nick);
+ goto end;
}
otrl_context_set_trust(co->active_fingerprint, "manual");
@@ -469,6 +427,9 @@ void otr_trust(IRC_CTX *ircctx, char *nick, const char *peername)
coi->smp_failed = FALSE;
otr_notice(ircctx, nick, TXT_FP_TRUST, nick);
+
+end:
+ return;
}
/*
@@ -483,13 +444,11 @@ void otr_abort_auth(ConnContext *co, IRC_CTX *ircctx, const char *nick)
coi->received_smp_init = FALSE;
otr_notice(ircctx, nick,
- co->smstate->nextExpected != OTRL_SMP_EXPECT1 ?
- TXT_AUTH_ABORTED_ONGOING :
- TXT_AUTH_ABORTED);
+ 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);
+ otrl_message_abort_smp(IRCCTX_IO_US(ircctx)->otr_state, &otr_ops,
+ ircctx, co);
otr_status_change(ircctx, nick, IO_STC_SMP_ABORT);
}
@@ -505,26 +464,29 @@ void otr_authabort(IRC_CTX *ircctx, char *nick, const char *peername)
if (peername) {
nick = nickbuf;
ircctx = ircctx_by_peername(peername, nick);
- if (!ircctx)
- return;
+ if (!ircctx) {
+ goto end;
+ }
}
IRCCTX_ACCNAME(accname, ircctx);
if (!(co = otr_getcontext(accname, nick, FALSE, ircctx))) {
- otr_noticest(TXT_CTX_NOT_FOUND,
- accname, nick);
- return;
+ otr_noticest(TXT_CTX_NOT_FOUND, accname, nick);
+ goto end;
}
otr_abort_auth(co, ircctx, nick);
+
+end:
+ return;
}
/*
* Initiate or respond to SMP authentication.
*/
void otr_auth(IRC_CTX *ircctx, char *nick, const char *peername,
- const char *question, const char *secret)
+ const char *question, const char *secret)
{
ConnContext *co;
char accname[128];
@@ -534,28 +496,29 @@ void otr_auth(IRC_CTX *ircctx, char *nick, const char *peername,
if (peername) {
nick = nickbuf;
ircctx = ircctx_by_peername(peername, nick);
- if (!ircctx)
- return;
+ if (!ircctx) {
+ goto end;
+ }
}
IRCCTX_ACCNAME(accname, ircctx);
if (!(co = otr_getcontext(accname, nick, FALSE, ircctx))) {
- otr_noticest(TXT_CTX_NOT_FOUND,
- accname, nick);
- return;
+ otr_noticest(TXT_CTX_NOT_FOUND, accname, nick);
+ goto end;
}
if (co->msgstate != OTRL_MSGSTATE_ENCRYPTED) {
otr_notice(ircctx, nick, TXT_AUTH_NEEDENC);
- return;
+ goto end;
}
coi = co->app_data;
/* Aborting an ongoing auth */
- if (co->smstate->nextExpected != OTRL_SMP_EXPECT1)
+ if (co->smstate->nextExpected != OTRL_SMP_EXPECT1) {
otr_abort_auth(co, ircctx, nick);
+ }
coi->smp_failed = FALSE;
@@ -564,68 +527,51 @@ void otr_auth(IRC_CTX *ircctx, char *nick, const char *peername,
char *trust = co->active_fingerprint->trust;
if (trust && (*trust != '\0')) {
otrl_context_set_trust(co->active_fingerprint, "");
- otr_writefps(IRCCTX_IO_US(ircctx));
+ key_write_fingerprints(IRCCTX_IO_US(ircctx));
}
}
if (!coi->received_smp_init) {
-#ifndef LIBOTR3
- if (question)
- otrl_message_initiate_smp_q(
- IRCCTX_IO_US(ircctx)->otr_state,
- &otr_ops,
- ircctx,
- co,
- question,
- (unsigned char*)secret,
+ if (question) {
+ otrl_message_initiate_smp_q(IRCCTX_IO_US(ircctx)->otr_state,
+ &otr_ops, ircctx, co, question, (unsigned char *) secret,
strlen(secret));
- else
-#endif
- otrl_message_initiate_smp(
- IRCCTX_IO_US(ircctx)->otr_state,
- &otr_ops,
- ircctx,
- co,
- (unsigned char*)secret,
- strlen(secret));
-
+ } else {
+ otrl_message_initiate_smp(IRCCTX_IO_US(ircctx)->otr_state,
+ &otr_ops, ircctx, co, (unsigned char *) secret,
+ strlen(secret));
+ }
otr_status_change(ircctx, 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));
+ 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);
}
- otr_notice(ircctx, nick,
- coi->received_smp_init ?
- TXT_AUTH_RESPONDING :
- TXT_AUTH_INITIATED);
+ otr_notice(ircctx, nick, coi->received_smp_init ? TXT_AUTH_RESPONDING :
+ TXT_AUTH_INITIATED);
+
+end:
+ return;
}
/*
- * Handles incoming TLVs of the SMP authentication type. We're not only updating
- * our own state but also giving libotr a leg up so it gets through the auth.
+ * Handles incoming TLVs of the SMP authentication type. We're not only
+ * updating our own state but also giving libotr a leg up so it gets through
+ * the auth.
*/
-void otr_handle_tlvs(OtrlTLV *tlvs, ConnContext *co,
- struct co_info *coi,
- IRC_CTX *ircctx, const char *from)
+void otr_handle_tlvs(OtrlTLV *tlvs, ConnContext *co, struct co_info *coi,
+ IRC_CTX *ircctx, const char *from)
{
int abort = FALSE;
OtrlTLV *tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP1);
if (tlv) {
if (co->smstate->nextExpected != OTRL_SMP_EXPECT1) {
- otr_notice(ircctx, from, TXT_AUTH_HAVE_OLD,
- from);
+ otr_notice(ircctx, from, TXT_AUTH_HAVE_OLD, from);
abort = TRUE;
} else {
- otr_notice(ircctx, from, TXT_AUTH_PEER,
- from);
+ otr_notice(ircctx, from, TXT_AUTH_PEER, from);
coi->received_smp_init = TRUE;
otr_status_change(ircctx, from, IO_STC_SMP_INCOMING);
}
@@ -634,14 +580,10 @@ void otr_handle_tlvs(OtrlTLV *tlvs, ConnContext *co,
tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP2);
if (tlv) {
if (co->smstate->nextExpected != OTRL_SMP_EXPECT2) {
- otr_notice(ircctx, from,
- TXT_AUTH_PEER_REPLY_WRONG,
- from);
+ otr_notice(ircctx, from, TXT_AUTH_PEER_REPLY_WRONG, from);
abort = TRUE;
} else {
- otr_notice(ircctx, from,
- TXT_AUTH_PEER_REPLIED,
- from);
+ otr_notice(ircctx, from, TXT_AUTH_PEER_REPLIED, from);
co->smstate->nextExpected = OTRL_SMP_EXPECT4;
otr_status_change(ircctx, from, IO_STC_SMP_FINALIZE);
}
@@ -650,23 +592,17 @@ void otr_handle_tlvs(OtrlTLV *tlvs, ConnContext *co,
tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP3);
if (tlv) {
if (co->smstate->nextExpected != OTRL_SMP_EXPECT3) {
- otr_notice(ircctx, from,
- TXT_AUTH_PEER_WRONG_SMP3,
- from);
+ otr_notice(ircctx, from, TXT_AUTH_PEER_WRONG_SMP3, from);
abort = TRUE;
} else {
char *trust = co->active_fingerprint->trust;
if (trust && (*trust != '\0')) {
- otr_notice(ircctx, from,
- TXT_AUTH_SUCCESSFUL);
- otr_status_change(ircctx, from,
- IO_STC_SMP_SUCCESS);
+ otr_notice(ircctx, from, TXT_AUTH_SUCCESSFUL);
+ otr_status_change(ircctx, from, IO_STC_SMP_SUCCESS);
} else {
- otr_notice(ircctx, from,
- TXT_AUTH_FAILED);
+ otr_notice(ircctx, from, TXT_AUTH_FAILED);
coi->smp_failed = TRUE;
- otr_status_change(ircctx, from,
- IO_STC_SMP_FAILED);
+ otr_status_change(ircctx, from, IO_STC_SMP_FAILED);
}
co->smstate->nextExpected = OTRL_SMP_EXPECT1;
coi->received_smp_init = FALSE;
@@ -676,25 +612,19 @@ void otr_handle_tlvs(OtrlTLV *tlvs, ConnContext *co,
tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP4);
if (tlv) {
if (co->smstate->nextExpected != OTRL_SMP_EXPECT4) {
- otr_notice(ircctx, from,
- TXT_AUTH_PEER_WRONG_SMP4,
- from);
+ otr_notice(ircctx, from, TXT_AUTH_PEER_WRONG_SMP4, from);
abort = TRUE;
} else {
char *trust = co->active_fingerprint->trust;
if (trust && (*trust != '\0')) {
- otr_notice(ircctx, from,
- TXT_AUTH_SUCCESSFUL);
- otr_status_change(ircctx, from,
- IO_STC_SMP_SUCCESS);
+ 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);
+ otr_notice(ircctx, from, TXT_AUTH_FAILED);
coi->smp_failed = TRUE;
- otr_status_change(ircctx, from,
- IO_STC_SMP_FAILED);
+ otr_status_change(ircctx, from, IO_STC_SMP_FAILED);
}
co->smstate->nextExpected = OTRL_SMP_EXPECT1;
coi->received_smp_init = FALSE;
@@ -714,13 +644,13 @@ void otr_handle_tlvs(OtrlTLV *tlvs, ConnContext *co,
/*
* Hand the given message to OTR.
- * Returns NULL if its an OTR protocol message and
- * the (possibly) decrypted message otherwise.
+ *
+ * Returns 0 if its an OTR protocol message or else negative value.
*/
-char *otr_receive(IRC_CTX *ircctx, const char *msg, const char *from)
+int otr_receive(IRC_CTX *ircctx, const char *msg, const char *from,
+ char **new_msg)
{
- int ignore_message;
- char *newmessage = NULL;
+ int ret;
char accname[256];
ConnContext *co;
struct co_info *coi;
@@ -729,9 +659,8 @@ char *otr_receive(IRC_CTX *ircctx, const char *msg, const char *from)
IRCCTX_ACCNAME(accname, ircctx);
if (!(co = otr_getcontext(accname, from, TRUE, ircctx))) {
- otr_noticest(TXT_CTX_NOT_CREATE,
- accname, from);
- return NULL;
+ otr_noticest(TXT_CTX_NOT_CREATE, accname, from);
+ goto error;
}
coi = co->app_data;
@@ -740,9 +669,9 @@ char *otr_receive(IRC_CTX *ircctx, const char *msg, const char *from)
* way unless the IRC server would somehow mark continuation messages.
*/
if ((strcmp(msg, coi->better_msg_two) == 0) ||
- (strcmp(msg, formats[TXT_OTR_BETTER_THREE].def) == 0)) {
+ (strcmp(msg, formats[TXT_OTR_BETTER_THREE].def) == 0)) {
otr_debug(ircctx, from, TXT_RECEIVE_IGNORE_QUERY);
- return NULL;
+ goto error;
}
if (coi->msgqueue) { /* already something in the queue */
@@ -750,12 +679,12 @@ char *otr_receive(IRC_CTX *ircctx, const char *msg, const char *from)
/* wait for more? */
if ((strlen(msg) > OTR_MAX_MSG_SIZE) &&
- (msg[strlen(msg) - 1] != '.') &&
- (msg[strlen(msg) - 1] != ','))
- return NULL;
+ (msg[strlen(msg) - 1] != '.') &&
+ (msg[strlen(msg) - 1] != ',')) {
+ goto error;;
+ }
- otr_debug(ircctx, from, TXT_RECEIVE_DEQUEUED,
- strlen(coi->msgqueue));
+ otr_debug(ircctx, from, TXT_RECEIVE_DEQUEUED, strlen(coi->msgqueue));
msg = coi->msgqueue;
coi->msgqueue = NULL;
@@ -764,58 +693,43 @@ char *otr_receive(IRC_CTX *ircctx, const char *msg, const char *from)
* Currently ok since that just uses free().
*/
} else if (strstr(msg, "?OTR:") &&
- (strlen(msg) > OTR_MAX_MSG_SIZE) &&
- (msg[strlen(msg) - 1] != '.') &&
- (msg[strlen(msg) - 1] != ',')) {
+ (strlen(msg) > OTR_MAX_MSG_SIZE) &&
+ (msg[strlen(msg) - 1] != '.') &&
+ (msg[strlen(msg) - 1] != ',')) {
coi->msgqueue = malloc(4096 * sizeof(char));
strcpy(coi->msgqueue, msg);
otr_debug(ircctx, from, TXT_RECEIVE_QUEUED, strlen(msg));
- return NULL;
+ goto error;
}
- otr_logst(MSGLEVEL_CRAP, "%d: receive...", time(NULL));
- ignore_message = otrl_message_receiving(
- IRCCTX_IO_US(ircctx)->otr_state,
- &otr_ops,
- ircctx,
- accname,
- PROTOCOLID,
- from,
- msg,
- &newmessage,
- &tlvs,
-#ifdef LIBOTR3
- NULL,
- NULL);
-#else
- &co,
- context_add_app_info,
- ircctx);
-#endif
- otr_logst(MSGLEVEL_CRAP, "%d: received", time(NULL));
+ otr_logst(MSGLEVEL_CRAP, "%d: receiving...", time(NULL));
- if (tlvs) {
-#ifdef LIBOTR3
- otr_handle_tlvs(tlvs, co, coi, ircctx, from);
-#else
- 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);
+ ret = otrl_message_receiving(IRCCTX_IO_US(ircctx)->otr_state,
+ &otr_ops, ircctx, accname, PROTOCOLID, from, msg, new_msg, &tlvs,
+ &co, context_add_app_info, ircctx);
+ if (ret) {
+ otr_debug(ircctx, from, TXT_RECEIVE_IGNORE, strlen(msg), accname, from,
+ msg);
+ } else {
+ if (*new_msg) {
+ otr_debug(ircctx, from, TXT_RECEIVE_CONVERTED);
}
-#endif
}
- if (ignore_message) {
- otr_debug(ircctx, from,
- TXT_RECEIVE_IGNORE, strlen(msg), accname, from, msg);
- return NULL;
+ 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);
}
- if (newmessage)
- otr_debug(ircctx, from, TXT_RECEIVE_CONVERTED);
+ otrl_tlv_free(tlvs);
+
+ otr_logst(MSGLEVEL_CRAP, "%d: received", time(NULL));
+
+ return 0;
- return newmessage ? : (char*)msg;
+error:
+ return -1;
}
void otr_setpolicies(IOUSTATE *ioustate, const char *policies, int known)
@@ -840,12 +754,10 @@ void otr_setpolicies(IOUSTATE *ioustate, const char *policies, int known)
while (g_match_info_matches(match_info)) {
struct plistentry *ple =
- (struct plistentry*)g_malloc0(sizeof(struct
- plistentry));
+ (struct plistentry *) g_malloc0(sizeof(struct plistentry));
char *pol = g_match_info_fetch(match_info, 2);
- ple->namepat =
- g_pattern_spec_new(g_match_info_fetch(match_info, 1));
+ ple->namepat = g_pattern_spec_new(g_match_info_fetch(match_info, 1));
switch (*pol) {
case 'n':
@@ -855,8 +767,7 @@ void otr_setpolicies(IOUSTATE *ioustate, const char *policies, int known)
ple->policy = OTRL_POLICY_MANUAL;
break;
case 'h':
- ple->policy = OTRL_POLICY_MANUAL |
- OTRL_POLICY_WHITESPACE_START_AKE;
+ ple->policy = OTRL_POLICY_MANUAL | OTRL_POLICY_WHITESPACE_START_AKE;
break;
case 'o':
ple->policy = OTRL_POLICY_OPPORTUNISTIC;
diff --git a/src/otr.h b/src/otr.h
index 5b7f179..7e44b6a 100644
--- a/src/otr.h
+++ b/src/otr.h
@@ -186,20 +186,23 @@ IRC_CTX *ircctx_by_peername(const char *peername, char *nick);
/* init stuff */
+IOUSTATE *otr_init_user(char *user);
+void otr_free_user(IOUSTATE *ioustate);
+
void otr_lib_init();
-void otrlib_deinit();
-void otr_initops();
+void otr_lib_uninit();
+
void otr_setpolicies(IOUSTATE *ioustate, const char *policies, int known);
-IOUSTATE *otr_init_user(char *user);
-void otr_deinit_user(IOUSTATE *ioustate);
/* basic send/receive/status stuff */
-char *otr_send(IRC_CTX *server, const char *msg, const char *to);
-char *otr_receive(IRC_CTX *server, const char *msg, const char *from);
+int otr_send(IRC_CTX *server, const char *msg, const char *to, char **otr_msg);
+int otr_receive(IRC_CTX *server, const char *msg, const char *from,
+ char **new_msg);
+
int otr_getstatus(IRC_CTX *ircctx, const char *nick);
ConnContext *otr_getcontext(const char *accname, const char *nick, int create,
- IRC_CTX *ircctx);
+ IRC_CTX *ircctx);
/* user interaction */
--
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