[Pkg-privacy-commits] [irssi-plugin-otr] 151/267: Simplify otr contexts command
Ximin Luo
infinity0 at moszumanska.debian.org
Sat Aug 22 12:26:27 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 fe0619d848bec9b01b3e0316cd412978eab4ccf8
Author: David Goulet <dgoulet at ev0ke.net>
Date: Mon Nov 26 21:46:39 2012 -0500
Simplify otr contexts command
Signed-off-by: David Goulet <dgoulet at ev0ke.net>
---
src/cmd.c | 67 +---------------------------------------------------
src/otr.c | 80 ++++++++++++++++++++++++++++-----------------------------------
src/otr.h | 2 +-
3 files changed, 38 insertions(+), 111 deletions(-)
diff --git a/src/cmd.c b/src/cmd.c
index 7a8037a..dbcd939 100644
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -221,72 +221,7 @@ error:
static void _cmd_contexts(struct otr_user_state *ustate, SERVER_REC *irssi,
const char *target, const void *data)
{
- struct ctxlist_ *ctxlist = otr_contexts(ustate), *ctxnext = ctxlist;
- struct fplist_ *fplist, *fpnext;
-
- if (!ctxlist) {
- IRSSI_INFO(NULL, NULL, "No active OTR contexts found");
- goto end;
- }
-
- IRSSI_MSG("%UAccount%n - %UUser%n - %UStatus%n - "
- "%UFingerprint%n - %UTrust%n");
-
- while (ctxlist) {
- fplist = ctxlist->fplist;
-
- if (!fplist) {
- goto cleanup;
- }
-
- switch (ctxlist->state) {
- case STENCRYPTED:
- IRSSI_MSG("%9%s%9 - %B%s%n - %GEncrypted%n", ctxlist->accountname,
- ctxlist->username);
- break;
- case STUNENCRYPTED:
- IRSSI_MSG("%9%s%9 - %B%s%n - Plaintext", ctxlist->accountname,
- ctxlist->username);
- break;
- case STFINISHED:
- IRSSI_MSG("%9%s%9 - %B%s%n - %yFinished%n", ctxlist->accountname,
- ctxlist->username);
- break;
- case STUNKNOWN:
- IRSSI_MSG("%9%s%9 - %B%s%n - Unknown", ctxlist->accountname,
- ctxlist->username);
- break;
- };
-
- switch (fplist->authby) {
- case NOAUTH:
- IRSSI_MSG("%r%s%n - Unverified", fplist->fp);
- break;
- case AUTHSMP:
- IRSSI_MSG("%g%s%n - SMP", fplist->fp);
- break;
- case AUTHMAN:
- IRSSI_MSG("%g%s%n - Manual", fplist->fp);
- break;
- };
-
- ctxlist = ctxlist->next;
- }
-
-cleanup:
- 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);
- }
-
-end:
- return;
+ otr_contexts(ustate);
}
static void _cmd_init(struct otr_user_state *ustate, SERVER_REC *irssi,
diff --git a/src/otr.c b/src/otr.c
index 06575fe..489f225 100644
--- a/src/otr.c
+++ b/src/otr.c
@@ -333,68 +333,60 @@ error:
return -1;
}
-struct ctxlist_ *otr_contexts(struct otr_user_state *ustate)
+void otr_contexts(struct otr_user_state *ustate)
{
- ConnContext *context;
- Fingerprint *fprint;
- struct ctxlist_ *ctxlist = NULL, *ctxhead = NULL;
- struct fplist_ *fplist, *fphead;
- char fp[OTRL_PRIVKEY_FPRINT_HUMAN_LEN];
- char *trust;
+ char human_fp[OTRL_PRIVKEY_FPRINT_HUMAN_LEN], *trust;
+ ConnContext *ctx;
+ Fingerprint *fp;
- for (context = ustate->otr_state->context_root; context;
- context = context->next) {
- if (!ctxlist) {
- ctxhead = ctxlist = g_malloc0(sizeof(struct ctxlist_));
- } else {
- ctxlist = ctxlist->next = g_malloc0(sizeof(struct ctxlist_));
- }
+ assert(ustate);
- switch (context->msgstate) {
- case OTRL_MSGSTATE_PLAINTEXT:
- ctxlist->state = STUNENCRYPTED;
- break;
+ if (!ustate->otr_state->context_root) {
+ IRSSI_INFO(NULL, NULL, "No active OTR contexts found");
+ goto end;
+ }
+
+ IRSSI_MSG("%UAccount%n - %UUser%n - %UStatus%n - %UFingerprint%n - "
+ "%UTrust%n");
+
+ for (ctx = ustate->otr_state->context_root; ctx != NULL; ctx = ctx->next) {
+ /* Print accoun name, username and msgstate. */
+ switch (ctx->msgstate) {
case OTRL_MSGSTATE_ENCRYPTED:
- ctxlist->state = STENCRYPTED;
+ IRSSI_MSG("%9%s%9 - %B%s%n - %GEncrypted%n", ctx->accountname,
+ ctx->username);
+ break;
+ case OTRL_MSGSTATE_PLAINTEXT:
+ IRSSI_MSG("%9%s%9 - %B%s%n - Plaintext", ctx->accountname,
+ ctx->username);
break;
case OTRL_MSGSTATE_FINISHED:
- ctxlist->state = STFINISHED;
+ IRSSI_MSG("%9%s%9 - %B%s%n - %yFinished%n", ctx->accountname,
+ ctx->username);
break;
default:
- ctxlist->state = STUNKNOWN;
+ IRSSI_MSG("%9%s%9 - %B%s%n - Unknown", ctx->accountname,
+ ctx->username);
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_));
- }
-
- trust = fprint->trust ? : "";
+ };
- otrl_privkey_hash_to_human(fp, fprint->fingerprint);
+ for (fp = ctx->fingerprint_root.next; fp != NULL; fp = fp->next) {
+ /* Hash fingerprint to human. */
+ otrl_privkey_hash_to_human(human_fp, fp->fingerprint);
- fplist->fp = g_strdup(fp);
+ trust = fp->trust ? : '\0';
if (*trust == '\0') {
- fplist->authby = NOAUTH;
+ IRSSI_MSG("%r%s%n - Unverified", human_fp);
} else if (strncmp(trust, "smp", strlen("smp")) == 0) {
- fplist->authby = AUTHSMP;
+ IRSSI_MSG("%g%s%n - SMP", human_fp);
} else {
- fplist->authby = AUTHMAN;
+ IRSSI_MSG("%g%s%n - Manual", human_fp);
}
}
-
- ctxlist->fplist = fphead;
}
- return ctxhead;
+end:
+ return;
}
/*
diff --git a/src/otr.h b/src/otr.h
index 281f440..d905664 100644
--- a/src/otr.h
+++ b/src/otr.h
@@ -177,7 +177,7 @@ void otr_finish(SERVER_REC *irssi, const char *nick);
void otr_auth(SERVER_REC *irssi, const char *nick, const char *question,
const char *secret);
void otr_auth_abort(SERVER_REC *irssi, const char *nick);
-struct ctxlist_ *otr_contexts(struct otr_user_state *ustate);
+void otr_contexts(struct otr_user_state *ustate);
void otr_finishall(struct otr_user_state *ustate);
void otr_forget(SERVER_REC *irssi, const char *nick, char *str_fp,
struct otr_user_state *ustate);
--
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