[Pkg-privacy-commits] [irssi-plugin-otr] 69/267: Generalization for bitlbee support.
Ximin Luo
infinity0 at moszumanska.debian.org
Sat Aug 22 12:41:29 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 df75c9e1831ef9c9f1dab5f8849ff20a38d0ced6
Author: Uli Meis <a.sporto+bee at gmail.com>
Date: Thu Feb 19 14:33:24 2009 +0100
Generalization for bitlbee support.
---
CMakeLists.txt | 9 +++
formats.txt | 2 +-
io_set.c | 6 +-
io_util.c | 41 ++++++-----
irssi/irssi_otr.c | 36 +++++++---
irssi/irssi_otr.h | 22 ++++++
otr.h | 53 +++++++++-----
otr_key.c | 26 +++----
otr_ops.c | 21 +++---
otr_util.c | 190 +++++++++++++++++++++++---------------------------
weechat/weechat_otr.c | 19 ++---
weechat/weechat_otr.h | 6 +-
xchat/xchat_otr.c | 14 ++--
xchat/xchat_otr.h | 26 ++++++-
14 files changed, 284 insertions(+), 187 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e0146ff..7754ddd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -179,6 +179,8 @@ ELSEIF(CMAKE_SOURCE_DIR MATCHES "xchat-[^/]*$")
SET(W_XCHAT ON)
ELSEIF(CMAKE_SOURCE_DIR MATCHES "weechat-[^/]*$")
SET(W_WEECHAT ON)
+ELSEIF(CMAKE_SOURCE_DIR MATCHES "bitlbee-[^/]*$")
+ SET(W_BITLBEE ON)
ELSE(CMAKE_SOURCE_DIR MATCHES "irssi-[^/]*$")
IF(IRSSI_INCLUDE_DIR)
SET(W_IRSSI ON)
@@ -189,11 +191,15 @@ ELSE(CMAKE_SOURCE_DIR MATCHES "irssi-[^/]*$")
IF(WEECHAT_INCLUDE_DIR)
SET(W_WEECHAT ON)
ENDIF(WEECHAT_INCLUDE_DIR)
+ IF(BITLBEE_INCLUDE_DIR)
+ SET(W_BITLBEE ON)
+ ENDIF(BITLBEE_INCLUDE_DIR)
ENDIF(CMAKE_SOURCE_DIR MATCHES "irssi-[^/]*$")
OPTION(WANT_IRSSI "build irssi plugin" ${W_IRSSI})
OPTION(WANT_XCHAT "build xchat plugin" ${W_XCHAT})
OPTION(WANT_WEECHAT "build weechat plugin" ${W_WEECHAT})
+OPTION(WANT_BITLBEE "build bitlbee plugin" ${W_BITLBEE})
IF(WANT_IRSSI)
add_subdirectory(irssi)
@@ -204,6 +210,9 @@ ENDIF(WANT_XCHAT)
IF(WANT_WEECHAT)
add_subdirectory(weechat)
ENDIF(WANT_WEECHAT)
+IF(WANT_BITLBEE)
+ add_subdirectory(bitlbee)
+ENDIF(WANT_BITLBEE)
# cscope
diff --git a/formats.txt b/formats.txt
index 9c3a7ee..e953a22 100644
--- a/formats.txt
+++ b/formats.txt
@@ -72,7 +72,7 @@ cmd_debug_on Debug mode is on
cmd_debug_off Debug mode is off
cmd_finish Finished conversation with %s@%s.
cmd_finishall_none No conversations to finish.
-cmd_version This is irssi-otr version %s
+cmd_version This is irc-otr version %s
peer_finished %s has finished the OTR conversation. If you want to continue talking enter %9/otr finish%9 for plaintext or ?OTR? to restart OTR.
Contexts
ctx_ctx_unencrypted %%9%20s%%9 %30s plaintext
diff --git a/io_set.c b/io_set.c
index 5099a50..997e078 100644
--- a/io_set.c
+++ b/io_set.c
@@ -28,7 +28,7 @@ char set_policy_known[512] = IO_DEFAULT_POLICY_KNOWN;
char set_ignore[512] = IO_DEFAULT_IGNORE;
int set_finishonunload = TRUE;
-void cmd_set(IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
+void cmd_set(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
char *target) {
char *setting, *value;
@@ -44,10 +44,10 @@ void cmd_set(IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
set_policy,set_policy_known,set_ignore,
set_finishonunload ? "true" : "false");
} else if (strcmp(setting,"policy")==0) {
- otr_setpolicies(value,FALSE);
+ otr_setpolicies(ioustate,value,FALSE);
strcpy(set_policy,value);
} else if (strcmp(setting,"policy_known")==0) {
- otr_setpolicies(value,TRUE);
+ otr_setpolicies(ioustate,value,TRUE);
strcpy(set_policy_known,value);
} else if (strcmp(setting,"ignore")==0) {
#ifdef HAVE_GREGEX_H
diff --git a/io_util.c b/io_util.c
index 340b2f6..e2548b1 100644
--- a/io_util.c
+++ b/io_util.c
@@ -35,19 +35,26 @@ int extract_nick(char *nick, char *line)
}
-int cmd_generic(IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
+int cmd_generic(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
char *target)
{
- char *cmd = argv[0];
+ char *cmd;
+ struct _cmds *commands = cmds;
+
+ if (!argc) {
+ otr_noticest(TXT_CMD_OTR);
+ return TRUE;
+ }
+
+ cmd = argv[0];
+
argv++;
argv_eol++;
argc--;
- struct _cmds *commands = cmds;
-
do {
if (strcmp(commands->name,cmd)==0) {
- commands->cmdfunc(ircctx,argc,argv,argv_eol,target);
+ commands->cmdfunc(ioustate,ircctx,argc,argv,argv_eol,target);
return TRUE;
}
} while ((++commands)->name);
@@ -55,23 +62,23 @@ int cmd_generic(IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
return FALSE;
}
-void cmd_debug(IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
+void cmd_debug(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
char *target) {
debug = !debug;
otr_noticest(debug ? TXT_CMD_DEBUG_ON : TXT_CMD_DEBUG_OFF);
}
-void cmd_version(IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
+void cmd_version(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
char *target) {
otr_noticest(TXT_CMD_VERSION,IRCOTR_VERSION);
}
-void cmd_help(IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
+void cmd_help(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
char *target) {
otr_log(ircctx,target,MSGLEVEL_CRAP,otr_help);
}
-void cmd_finish(IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
+void cmd_finish(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
char *target) {
if (argc)
otr_finish(NULL,NULL,argv[0],TRUE);
@@ -82,7 +89,7 @@ void cmd_finish(IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
}
-void cmd_trust(IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
+void cmd_trust(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
char *target) {
if (argc)
otr_trust(NULL,NULL,argv[0]);
@@ -92,7 +99,7 @@ void cmd_trust(IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
otr_noticest(TXT_CMD_QNOTFOUND);
}
-void cmd_authabort(IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
+void cmd_authabort(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
char *target) {
if (argc)
otr_authabort(NULL,NULL,argv[0]);
@@ -102,13 +109,13 @@ void cmd_authabort(IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
otr_noticest(TXT_CMD_QNOTFOUND);
}
-void cmd_genkey(IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
+void cmd_genkey(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
char *target) {
if (argc) {
if (strcmp(argv[0],"abort")==0)
- keygen_abort(FALSE);
+ keygen_abort(ioustate,FALSE);
else if (strchr(argv[0],'@'))
- keygen_run(argv[0]);
+ keygen_run(ioustate,argv[0]);
else
otr_noticest(TXT_KG_NEEDACC);
} else {
@@ -116,7 +123,7 @@ void cmd_genkey(IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
}
}
-void cmd_auth(IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
+void cmd_auth(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
char *target) {
if (!argc) {
otr_notice(ircctx,target,
@@ -133,9 +140,9 @@ void cmd_auth(IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
/*
* /otr contexts
*/
-void cmd_contexts(IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
+void cmd_contexts(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
char *target) {
- struct ctxlist_ *ctxlist = otr_contexts(),*ctxnext = ctxlist;
+ struct ctxlist_ *ctxlist = otr_contexts(ioustate),*ctxnext = ctxlist;
struct fplist_ *fplist,*fpnext;
if (!ctxlist)
diff --git a/irssi/irssi_otr.c b/irssi/irssi_otr.c
index 4755c32..7301d3d 100644
--- a/irssi/irssi_otr.c
+++ b/irssi/irssi_otr.c
@@ -25,6 +25,8 @@ int debug = FALSE;
GRegex *regex_nickignore = NULL;
#endif
+static IOUSTATE *ioustate;
+
void irc_send_message(IRC_CTX *ircctx, const char *recipient, char *msg) {
ircctx->send_message(
ircctx,recipient,msg,GPOINTER_TO_INT(SEND_TARGET_NICK));
@@ -100,9 +102,9 @@ static void cmd_otr(const char *data,void *server,WI_ITEM_REC *item)
io_explode_args(data,&argv,&argv_eol,&argc);
if (query&&query->server&&query->server->connrec) {
- cmd_generic(query->server,argc,argv,argv_eol,query->name);
+ cmd_generic(ioustate,query->server,argc,argv,argv_eol,query->name);
} else {
- cmd_generic(NULL,argc,argv,argv_eol,NULL);
+ cmd_generic(ioustate,NULL,argc,argv,argv_eol,NULL);
}
statusbar_items_redraw("otr");
@@ -119,7 +121,7 @@ static void cmd_otr(const char *data,void *server,WI_ITEM_REC *item)
static void cmd_quit(const char *data, void *server, WI_ITEM_REC *item)
{
if (settings_get_bool("otr_finishonunload"))
- otr_finishall();
+ otr_finishall(ioustate);
}
/*
@@ -132,7 +134,7 @@ static void otr_statusbar(struct SBAR_ITEM_REC *item, int get_size_only)
int formatnum=0;
if (query&&query->server&&query->server->connrec)
- formatnum = otr_getstatus(query->server->nick,query->name,query->server->connrec->address);
+ formatnum = otr_getstatus(query->server,query->name);
statusbar_item_default_handler(
item,
@@ -152,8 +154,8 @@ void otr_query_create(SERVER_REC *server, const char *nick)
static void read_settings(void)
{
- otr_setpolicies(settings_get_str("otr_policy"),FALSE);
- otr_setpolicies(settings_get_str("otr_policy_known"),TRUE);
+ otr_setpolicies(ioustate,settings_get_str("otr_policy"),FALSE);
+ otr_setpolicies(ioustate,settings_get_str("otr_policy_known"),TRUE);
#ifdef HAVE_GREGEX_H
if (regex_nickignore)
g_regex_unref(regex_nickignore);
@@ -174,6 +176,8 @@ void otr_init(void)
if (otrlib_init())
return;
+ ioustate = otr_init_user("one to rule them all");
+
signal_add_first("server sendmsg", (SIGNAL_FUNC) sig_server_sendmsg);
signal_add_first("message private", (SIGNAL_FUNC) sig_message_private);
signal_add("query destroyed", (SIGNAL_FUNC) sig_query_destroyed);
@@ -218,19 +222,31 @@ void otr_deinit(void)
statusbar_item_unregister("otr");
if (settings_get_bool("otr_finishonunload"))
- otr_finishall();
+ otr_finishall(ioustate);
+
+ otr_deinit_user(ioustate);
otrlib_deinit();
theme_unregister();
}
-IRC_CTX *server_find_address(char *address)
+IRC_CTX *ircctx_by_peername(const char *peername, char *nick)
{
GSList *tmp;
+ char pname[256];
+ char *address;
+
+ strcpy(pname,peername);
+
+ address = strchr(pname,'@');
+
+ if (!address)
+ return NULL;
- g_return_val_if_fail(address != NULL, NULL);
- if (*address == '\0') return NULL;
+ *address = '\0';
+ strcpy(nick,pname);
+ *address++ = '@';
for (tmp = servers; tmp != NULL; tmp = tmp->next) {
SERVER_REC *server = tmp->data;
diff --git a/irssi/irssi_otr.h b/irssi/irssi_otr.h
index 81643c6..6b0eb5b 100644
--- a/irssi/irssi_otr.h
+++ b/irssi/irssi_otr.h
@@ -1,3 +1,22 @@
+/*
+ * Off-the-Record Messaging (OTR) module for the irssi IRC client
+ * Copyright (C) 2008 Uli Meis <a.sporto+bee at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA
+ */
+
#include <common.h>
#include <core/commands.h>
#include <core/modules.h>
@@ -38,6 +57,9 @@ 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 IO_CREATE_US(user) (&ioustate_uniq)
#define otr_noticest(formatnum,...) \
printformat(NULL,NULL,MSGLEVEL_MSGS, formatnum, ## __VA_ARGS__)
diff --git a/otr.h b/otr.h
index 468b349..d8b91b3 100644
--- a/otr.h
+++ b/otr.h
@@ -34,22 +34,41 @@
#include <glib/gprintf.h>
#include <glib/gstdio.h>
+/* 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
+
/* irssi */
#ifdef TARGET_IRSSI
-#include <irssi_otr.h>
+#include <irssi/irssi_otr.h>
#endif
/* xchat */
#ifdef TARGET_XCHAT
-#include <xchat_otr.h>
+#include <xchat/xchat_otr.h>
#endif
/* weechat */
#ifdef TARGET_WEECHAT
-#include <weechat_otr.h>
+#include <weechat/weechat_otr.h>
+#endif
+
+/* bitlbee */
+
+#ifdef TARGET_BITLBEE
+#include <bitlbee/bitlbee_otr.h>
#endif
/* log stuff */
@@ -132,21 +151,23 @@ struct plistentry {
extern int debug;
void irc_send_message(IRC_CTX *ircctx, const char *recipient, char *msg);
-IRC_CTX *server_find_address(char *address);
+IRC_CTX *ircctx_by_peername(const char *peername, char *nick);
/* init stuff */
int otrlib_init();
void otrlib_deinit();
void otr_initops();
-void otr_setpolicies(const char *policies, int known);
+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_getstatus(char *mynick, char *nick, char *server);
-ConnContext *otr_getcontext(const char *accname,const char *nick,int create,void *data);
+int otr_getstatus(IRC_CTX *ircctx, char *nick);
+ConnContext *otr_getcontext(const char *accname,const char *nick,int create,IRC_CTX *ircctx);
/* user interaction */
@@ -154,30 +175,30 @@ 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 *secret);
void otr_authabort(IRC_CTX *server, char *nick, const char *peername);
-struct ctxlist_ *otr_contexts();
-void otr_finishall();
+struct ctxlist_ *otr_contexts(IOUSTATE *ioustate);
+void otr_finishall(IOUSTATE *ioustate);
/* key/fingerprint stuff */
-void keygen_run(const char *accname);
-void keygen_abort();
-void key_load();
-void fps_load();
-void otr_writefps();
+void keygen_run(IOUSTATE *ioustate, const char *accname);
+void keygen_abort(IOUSTATE *ioustate,int ignoreidle);
+void key_load(IOUSTATE *ioustate);
+void fps_load(IOUSTATE *ioustate);
+void otr_writefps(IOUSTATE *ioustate);
int extract_nick(char *nick, char *line);
struct _cmds {
char *name;
- void (*cmdfunc)(IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[], char *target);
+ void (*cmdfunc)(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[], char *target);
};
/* see io_util.c */
#define CMDCOUNT 9
extern struct _cmds cmds[];
-int cmd_generic(IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
+int cmd_generic(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
char *target);
void io_explode_args(const char *args, char ***argvp, char ***argv_eolp, int *argcp);
diff --git a/otr_key.c b/otr_key.c
index 543adef..85e137f 100644
--- a/otr_key.c
+++ b/otr_key.c
@@ -27,8 +27,6 @@
#include <sys/poll.h>
#include <signal.h>
-extern OtrlUserState otr_state;
-
typedef enum { KEYGEN_NO, KEYGEN_RUNNING } keygen_status_t;
struct {
@@ -40,6 +38,7 @@ struct {
guint cpid;
guint cwid;
pid_t pid;
+ IOUSTATE *ioustate;
} kg_st = {.status = KEYGEN_NO };
void keygen_childwatch(GPid pid,gint status, gpointer data) {
@@ -80,7 +79,7 @@ void keygen_childwatch(GPid pid,gint status, gpointer data) {
} else if (ret==-1)
otr_noticest(TXT_KG_POLLERR,kg_st.accountname,strerror(errno));
- keygen_abort(FALSE);
+ keygen_abort(kg_st.ioustate,FALSE);
}
/*
@@ -115,7 +114,7 @@ gboolean keygen_complete(GIOChannel *source, GIOCondition condition,
time(NULL)-kg_st.started);
rename(tmpfilename,filename);
//otrl_privkey_forget_all(otr_state); <-- done by lib
- key_load();
+ key_load(kg_st.ioustate);
}
g_source_remove(kg_st.cwid);
@@ -135,7 +134,7 @@ gboolean keygen_complete(GIOChannel *source, GIOCondition condition,
* The other process will rewrite the key file, we shouldn't
* change anything till it's done and we've reloaded the keys.
*/
-void keygen_run(const char *accname)
+void keygen_run(IOUSTATE *ioustate, const char *accname)
{
gcry_error_t err;
int ret;
@@ -173,6 +172,7 @@ void keygen_run(const char *accname)
kg_st.ch[1] = g_io_channel_unix_new(fds[1]);
kg_st.accountname = g_strdup(accname);
+ kg_st.ioustate = ioustate;
kg_st.protocol = PROTOCOLID;
kg_st.started = time(NULL);
@@ -200,7 +200,7 @@ void keygen_run(const char *accname)
/* child */
- err = otrl_privkey_generate(otr_state,filename,accname,PROTOCOLID);
+ err = otrl_privkey_generate(ioustate->otr_state,filename,accname,PROTOCOLID);
write(fds[1],&err,sizeof(err));
//g_free(filename);
@@ -210,7 +210,7 @@ void keygen_run(const char *accname)
/*
* Abort ongoing key generation.
*/
-void keygen_abort(int ignoreidle)
+void keygen_abort(IOUSTATE *ioustate,int ignoreidle)
{
if (kg_st.status!=KEYGEN_RUNNING) {
if (!ignoreidle)
@@ -235,12 +235,12 @@ void keygen_abort(int ignoreidle)
/*
* Write fingerprints to file.
*/
-void otr_writefps()
+void otr_writefps(IOUSTATE *ioustate)
{
gcry_error_t err;
char *filename = g_strconcat(get_client_config_dir(),FPSFILE,NULL);
- err = otrl_privkey_write_fingerprints(otr_state,filename);
+ err = otrl_privkey_write_fingerprints(ioustate->otr_state,filename);
if (err == GPG_ERR_NO_ERROR) {
otr_noticest(TXT_FP_SAVED);
@@ -255,7 +255,7 @@ void otr_writefps()
/*
* Load private keys.
*/
-void key_load()
+void key_load(IOUSTATE *ioustate)
{
gcry_error_t err;
char *filename = g_strconcat(get_client_config_dir(),KEYFILE,NULL);
@@ -265,7 +265,7 @@ void key_load()
return;
}
- err = otrl_privkey_read(otr_state, filename);
+ err = otrl_privkey_read(ioustate->otr_state, filename);
if (err == GPG_ERR_NO_ERROR) {
otr_noticest(TXT_KEY_LOADED);
@@ -280,7 +280,7 @@ void key_load()
/*
* Load fingerprints.
*/
-void fps_load()
+void fps_load(IOUSTATE *ioustate)
{
gcry_error_t err;
char *filename = g_strconcat(get_client_config_dir(),FPSFILE,NULL);
@@ -290,7 +290,7 @@ void fps_load()
return;
}
- err = otrl_privkey_read_fingerprints(otr_state,filename,NULL,NULL);
+ err = otrl_privkey_read_fingerprints(ioustate->otr_state,filename,NULL,NULL);
if (err == GPG_ERR_NO_ERROR) {
otr_noticest(TXT_FP_LOADED);
diff --git a/otr_ops.c b/otr_ops.c
index 8da3800..c3775e6 100644
--- a/otr_ops.c
+++ b/otr_ops.c
@@ -20,8 +20,6 @@
#include "otr.h"
OtrlMessageAppOps otr_ops;
-extern OtrlUserState otr_state;
-extern GSList *plistunknown,*plistknown;
OtrlPolicy IO_DEFAULT_OTR_POLICY =
OTRL_POLICY_MANUAL|OTRL_POLICY_WHITESPACE_START_AKE;
@@ -36,13 +34,14 @@ OtrlPolicy ops_policy(void *opdata, ConnContext *context)
OtrlPolicy op = IO_DEFAULT_OTR_POLICY;
GSList *pl;
char fullname[1024];
+ IOUSTATE *ioustate = IRCCTX_IO_US(coi->ircctx);
sprintf(fullname, "%s@%s", context->username, server);
/* loop through otr_policy */
- if (plistunknown) {
- pl = plistunknown;
+ if (ioustate->plistunknown) {
+ pl = ioustate->plistunknown;
do {
struct plistentry *ple = pl->data;
@@ -52,8 +51,8 @@ OtrlPolicy ops_policy(void *opdata, ConnContext *context)
} while ((pl = g_slist_next(pl)));
}
- if (plistknown&&context->fingerprint_root.next) {
- pl = plistknown;
+ if (ioustate->plistknown&&context->fingerprint_root.next) {
+ pl = ioustate->plistknown;
/* loop through otr_policy_known */
@@ -82,7 +81,9 @@ OtrlPolicy ops_policy(void *opdata, ConnContext *context)
void ops_create_privkey(void *opdata, const char *accountname,
const char *protocol)
{
- keygen_run(accountname);
+ IRC_CTX *ircctx __attribute__((unused)) = opdata;
+
+ keygen_run(IRCCTX_IO_US(ircctx),accountname);
}
/*
@@ -201,7 +202,7 @@ void ops_secure(void *opdata, ConnContext *context)
context->active_fingerprint->fingerprint);
otr_notice(coi->ircctx,context->username,TXT_OPS_FPCOMP,
- otrl_privkey_fingerprint(otr_state,
+ otrl_privkey_fingerprint(IRCCTX_IO_US(coi->ircctx)->otr_state,
ownfp,
context->accountname,
PROTOCOLID),
@@ -263,7 +264,9 @@ void ops_up_ctx_list(void *opdata)
*/
void ops_writefps(void *data)
{
- otr_writefps();
+ IRC_CTX *ircctx __attribute__((unused)) = data;
+
+ otr_writefps(IRCCTX_IO_US(ircctx));
}
int ops_is_logged_in(void *opdata, const char *accountname,
diff --git a/otr_util.c b/otr_util.c
index bbffa46..ddb08c3 100644
--- a/otr_util.c
+++ b/otr_util.c
@@ -21,33 +21,59 @@
#include <gcrypt.h>
-OtrlUserState otr_state = NULL;
extern OtrlMessageAppOps otr_ops;
static int otrinited = FALSE;
-GSList *plistunknown = NULL;
-GSList *plistknown = NULL;
+
+#ifdef TARGET_BITLBEE
+GHashTable *ioustates;
+#else
+IOUSTATE ioustate_uniq = { 0,0,0 };
+#endif
#ifdef HAVE_GREGEX_H
GRegex *regex_policies;
#endif
+IOUSTATE *otr_init_user(char *user)
+{
+ IOUSTATE *ioustate = IO_CREATE_US(user);
+
+ ioustate->otr_state = otrl_userstate_create();
+
+ /* load keys and fingerprints */
+
+ key_load(ioustate);
+ fps_load(ioustate);
+
+ return ioustate;
+}
+
+void otr_deinit_user(IOUSTATE *ioustate)
+{
+ keygen_abort(ioustate,TRUE);
+
+ if (ioustate->otr_state) {
+ otr_writefps(ioustate);
+ otrl_userstate_free(ioustate->otr_state);
+ ioustate->otr_state = NULL;
+ }
+ otr_setpolicies(ioustate,"",FALSE);
+ otr_setpolicies(ioustate,"",TRUE);
+}
+
/*
* init otr lib.
*/
int otrlib_init()
{
-
if (!otrinited) {
OTRL_INIT;
otrinited = TRUE;
}
- otr_state = otrl_userstate_create();
-
- /* load keys and fingerprints */
-
- key_load();
- fps_load();
+#ifdef TARGET_BITLBEE
+ ioustates = g_hash_table_new_full(g_str_hash,g_str_equal,g_free,otr_deinit_user);
+#endif
otr_initops();
@@ -57,7 +83,7 @@ int otrlib_init()
"(,|$)",0,0,NULL);
#endif
- return otr_state==NULL;
+ return 0;
}
/*
@@ -65,21 +91,13 @@ int otrlib_init()
*/
void otrlib_deinit()
{
- if (otr_state) {
- otr_writefps();
- otrl_userstate_free(otr_state);
- otr_state = NULL;
- }
-
- keygen_abort(TRUE);
-
- otr_setpolicies("",FALSE);
- otr_setpolicies("",TRUE);
-
#ifdef HAVE_GREGEX_H
g_regex_unref(regex_policies);
#endif
+#ifdef TARGET_BITLBEE
+ g_hash_table_destroy(ioustates);
+#endif
}
@@ -117,21 +135,21 @@ void context_add_app_info(void *data,ConnContext *co)
* Get a context from a pair.
*/
ConnContext *otr_getcontext(const char *accname,const char *nick,
- int create,void *data)
+ int create,IRC_CTX *ircctx)
{
ConnContext *co = otrl_context_find(
- otr_state,
+ IRCCTX_IO_US(ircctx)->otr_state,
nick,
accname,
PROTOCOLID,
create,
NULL,
context_add_app_info,
- data);
+ ircctx);
/* context came from a fingerprint */
- if (co&&data&&!co->app_data)
- context_add_app_info(data,co);
+ if (co&&ircctx&&!co->app_data)
+ context_add_app_info(ircctx,co);
return co;
}
@@ -143,17 +161,15 @@ ConnContext *otr_getcontext(const char *accname,const char *nick,
*/
char *otr_send(IRC_CTX *ircctx, const char *msg,const char *to)
{
- const char *nick = IRCCTX_NICK(ircctx);
- const char *address = IRCCTX_ADDR(ircctx);
gcry_error_t err;
char *newmessage = NULL;
ConnContext *co;
char accname[256];
- sprintf(accname, "%s@%s", nick, address);
+ IRCCTX_ACCNAME(accname,ircctx);
err = otrl_message_sending(
- otr_state,
+ IRCCTX_IO_US(ircctx)->otr_state,
&otr_ops,
ircctx,
accname,
@@ -196,7 +212,8 @@ char *otr_send(IRC_CTX *ircctx, const char *msg,const char *to)
return NULL;
}
-struct ctxlist_ *otr_contexts() {
+struct ctxlist_ *otr_contexts(IOUSTATE *ioustate)
+{
ConnContext *context;
Fingerprint *fprint;
struct ctxlist_ *ctxlist = NULL, *ctxhead = NULL;
@@ -205,7 +222,7 @@ struct ctxlist_ *otr_contexts() {
char *trust;
int i;
- for(context = otr_state->context_root; context;
+ for(context = ioustate->otr_state->context_root; context;
context = context->next) {
if (!ctxlist)
ctxhead = ctxlist = g_malloc0(sizeof(struct ctxlist_));
@@ -251,15 +268,15 @@ struct ctxlist_ *otr_contexts() {
/*
* Get the OTR status of this conversation.
*/
-int otr_getstatus(char *mynick, char *nick, char *server)
+int otr_getstatus(IRC_CTX *ircctx, char *nick)
{
ConnContext *co;
char accname[128];
struct co_info *coi;
- sprintf(accname, "%s@%s", mynick, server);
+ IRCCTX_ACCNAME(accname,ircctx);
- if (!(co = otr_getcontext(accname,nick,FALSE,NULL))) {
+ if (!(co = otr_getcontext(accname,nick,FALSE,ircctx))) {
return 0;
}
@@ -302,31 +319,25 @@ void otr_finish(IRC_CTX *ircctx, char *nick, const char *peername, int inquery)
ConnContext *co;
char accname[128];
struct co_info *coi;
- char *pserver = NULL;
+ char nickbuf[128];
if (peername) {
- pserver = strchr(peername,'@');
- if (!pserver)
- return;
- ircctx = server_find_address(pserver+1);
+ nick = nickbuf;
+ ircctx = ircctx_by_peername(peername,nick);
if (!ircctx)
return;
- *pserver = '\0';
- nick = (char*)peername;
}
- sprintf((char*)accname, "%s@%s", IRCCTX_NICK(ircctx), IRCCTX_ADDR(ircctx));
+ IRCCTX_ACCNAME(accname,ircctx);
- if (!(co = otr_getcontext(accname,nick,FALSE,NULL))) {
+ if (!(co = otr_getcontext(accname,nick,FALSE,ircctx))) {
if (inquery)
otr_noticest(TXT_CTX_NOT_FOUND,
accname,nick);
- if (peername)
- *pserver = '@';
return;
}
- otrl_message_disconnect(otr_state,&otr_ops,ircctx,accname,
+ otrl_message_disconnect(IRCCTX_IO_US(ircctx)->otr_state,&otr_ops,ircctx,accname,
PROTOCOLID,nick);
if (inquery) {
@@ -341,24 +352,21 @@ void otr_finish(IRC_CTX *ircctx, char *nick, const char *peername, int inquery)
* we're called cause the query window has been closed. */
if (coi)
coi->finished = inquery;
-
- if (peername)
- *pserver = '@';
}
-void otr_finishall()
+void otr_finishall(IOUSTATE *ioustate)
{
ConnContext *context;
int finished=0;
- for(context = otr_state->context_root; context;
+ for(context = ioustate->otr_state->context_root; context;
context = context->next) {
struct co_info *coi = context->app_data;
if (context->msgstate!=OTRL_MSGSTATE_ENCRYPTED)
continue;
- otrl_message_disconnect(otr_state,&otr_ops,coi->ircctx,
+ otrl_message_disconnect(ioustate->otr_state,&otr_ops,coi->ircctx,
context->accountname,
PROTOCOLID,
context->username);
@@ -380,26 +388,20 @@ void otr_trust(IRC_CTX *ircctx, char *nick, const char *peername)
ConnContext *co;
char accname[128];
struct co_info *coi;
- char *pserver = NULL;
+ char nickbuf[128];
if (peername) {
- pserver = strchr(peername,'@');
- if (!pserver)
- return;
- ircctx = server_find_address(pserver+1);
+ nick = nickbuf;
+ ircctx = ircctx_by_peername(peername,nick);
if (!ircctx)
return;
- *pserver = '\0';
- nick = (char*)peername;
}
- sprintf((char*)accname, "%s@%s", IRCCTX_NICK(ircctx), IRCCTX_ADDR(ircctx));
+ IRCCTX_ACCNAME(accname,ircctx);
- if (!(co = otr_getcontext(accname,nick,FALSE,NULL))) {
+ if (!(co = otr_getcontext(accname,nick,FALSE,ircctx))) {
otr_noticest(TXT_CTX_NOT_FOUND,
accname,nick);
- if (peername)
- *pserver = '@';
return;
}
@@ -410,8 +412,6 @@ void otr_trust(IRC_CTX *ircctx, char *nick, const char *peername)
otr_notice(ircctx,nick,TXT_FP_TRUST,nick);
- if (peername)
- *pserver = '@';
}
/*
@@ -430,7 +430,7 @@ void otr_abort_auth(ConnContext *co, IRC_CTX *ircctx, const char *nick)
TXT_AUTH_ABORTED_ONGOING :
TXT_AUTH_ABORTED);
- otrl_message_abort_smp(otr_state,&otr_ops,ircctx,co);
+ otrl_message_abort_smp(IRCCTX_IO_US(ircctx)->otr_state,&otr_ops,ircctx,co);
}
/*
@@ -440,33 +440,25 @@ void otr_authabort(IRC_CTX *ircctx, char *nick, const char *peername)
{
ConnContext *co;
char accname[128];
- char *pserver = NULL;
+ char nickbuf[128];
if (peername) {
- pserver = strchr(peername,'@');
- if (!pserver)
- return;
- ircctx = server_find_address(pserver+1);
+ nick = nickbuf;
+ ircctx = ircctx_by_peername(peername,nick);
if (!ircctx)
return;
- *pserver = '\0';
- nick = (char*)peername;
}
- sprintf((char*)accname, "%s@%s", IRCCTX_NICK(ircctx), IRCCTX_ADDR(ircctx));
+ IRCCTX_ACCNAME(accname,ircctx);
- if (!(co = otr_getcontext(accname,nick,FALSE,NULL))) {
+ if (!(co = otr_getcontext(accname,nick,FALSE,ircctx))) {
otr_noticest(TXT_CTX_NOT_FOUND,
accname,nick);
- if (peername)
- *pserver = '@';
return;
}
otr_abort_auth(co,ircctx,nick);
- if (peername)
- *pserver = '@';
}
/*
@@ -477,26 +469,20 @@ void otr_auth(IRC_CTX *ircctx, char *nick, const char *peername, const char *sec
ConnContext *co;
char accname[128];
struct co_info *coi;
- char *pserver = NULL;
+ char nickbuf[128];
if (peername) {
- pserver = strchr(peername,'@');
- if (!pserver)
- return;
- ircctx = server_find_address(pserver+1);
+ nick = nickbuf;
+ ircctx = ircctx_by_peername(peername,nick);
if (!ircctx)
return;
- *pserver = '\0';
- nick = (char*)peername;
}
- sprintf((char*)accname, "%s@%s", IRCCTX_NICK(ircctx), IRCCTX_ADDR(ircctx));
+ IRCCTX_ACCNAME(accname,ircctx);
- if (!(co = otr_getcontext(accname,nick,FALSE,NULL))) {
+ if (!(co = otr_getcontext(accname,nick,FALSE,ircctx))) {
otr_noticest(TXT_CTX_NOT_FOUND,
accname,nick);
- if (peername)
- *pserver = '@';
return;
}
@@ -518,13 +504,13 @@ void otr_auth(IRC_CTX *ircctx, char *nick, const char *peername, const char *sec
char *trust = co->active_fingerprint->trust;
if (trust&&(*trust!='\0')) {
otrl_context_set_trust(co->active_fingerprint, "");
- otr_writefps();
+ otr_writefps(IRCCTX_IO_US(ircctx));
}
}
if (!coi->received_smp_init)
otrl_message_initiate_smp(
- otr_state,
+ IRCCTX_IO_US(ircctx)->otr_state,
&otr_ops,
ircctx,
co,
@@ -532,7 +518,7 @@ void otr_auth(IRC_CTX *ircctx, char *nick, const char *peername, const char *sec
strlen(secret));
else
otrl_message_respond_smp(
- otr_state,
+ IRCCTX_IO_US(ircctx)->otr_state,
&otr_ops,
ircctx,
co,
@@ -546,8 +532,6 @@ void otr_auth(IRC_CTX *ircctx, char *nick, const char *peername, const char *sec
statusbar_items_redraw("otr");
- if (peername)
- *pserver = '@';
}
/*
@@ -658,7 +642,7 @@ char *otr_receive(IRC_CTX *ircctx, const char *msg,const char *from)
struct co_info *coi;
OtrlTLV *tlvs;
- sprintf(accname, "%s@%s", IRCCTX_NICK(ircctx), IRCCTX_ADDR(ircctx));
+ IRCCTX_ACCNAME(accname,ircctx);
if (!(co = otr_getcontext(accname,from,TRUE,ircctx))) {
otr_noticest(TXT_CTX_NOT_CREATE,
@@ -714,7 +698,7 @@ char *otr_receive(IRC_CTX *ircctx, const char *msg,const char *from)
}
ignore_message = otrl_message_receiving(
- otr_state,
+ IRCCTX_IO_US(ircctx)->otr_state,
&otr_ops,
ircctx,
accname,
@@ -741,11 +725,11 @@ char *otr_receive(IRC_CTX *ircctx, const char *msg,const char *from)
return newmessage ? : (char*)msg;
}
-void otr_setpolicies(const char *policies, int known)
+void otr_setpolicies(IOUSTATE *ioustate, const char *policies, int known)
{
#ifdef HAVE_GREGEX_H
GMatchInfo *match_info;
- GSList *plist = known ? plistknown : plistunknown;
+ GSList *plist = known ? ioustate->plistknown : ioustate->plistunknown;
if (plist) {
GSList *p = plist;
@@ -795,8 +779,8 @@ void otr_setpolicies(const char *policies, int known)
g_match_info_free(match_info);
if (known)
- plistknown = plist;
+ ioustate->plistknown = plist;
else
- plistunknown = plist;
+ ioustate->plistunknown = plist;
#endif
}
diff --git a/weechat/weechat_otr.c b/weechat/weechat_otr.c
index 8feedd8..0ddae63 100644
--- a/weechat/weechat_otr.c
+++ b/weechat/weechat_otr.c
@@ -34,6 +34,8 @@ int debug = 0;
GRegex *regex_nickignore = NULL;
#endif
+static IOUSTATE *ioustate;
+
void printformatva(IRC_CTX *ircctx, const char *nick, const char *format, va_list params)
{
char msg[LOGMAX], *s = msg;
@@ -242,12 +244,7 @@ int cmd_otr(void *data, struct t_gui_buffer *buffer, int argc, char **word, char
word_eol++;
argc--;
- if (!argc) {
- otr_noticest(TXT_CMD_OTR);
- return WEECHAT_RC_OK;
- }
-
- cmd_generic(ircctx,argc,word,word_eol,target);
+ cmd_generic(ioustate,ircctx,argc,word,word_eol,target);
return WEECHAT_RC_OK;
}
@@ -263,8 +260,10 @@ int weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]
if (otrlib_init())
return WEECHAT_RC_ERROR;
- otr_setpolicies(IO_DEFAULT_POLICY,FALSE);
- otr_setpolicies(IO_DEFAULT_POLICY_KNOWN,TRUE);
+ ioustate = otr_init_user("one to rule them all");
+
+ otr_setpolicies(ioustate,IO_DEFAULT_POLICY,FALSE);
+ otr_setpolicies(ioustate,IO_DEFAULT_POLICY_KNOWN,TRUE);
#ifdef HAVE_GREGEX_H
if (regex_nickignore)
@@ -287,5 +286,9 @@ int weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]
int weechat_plugin_end (struct t_weechat_plugin *plugin)
{
+ otr_deinit_user(ioustate);
+
+ otrlib_deinit();
+
return WEECHAT_RC_OK;
}
diff --git a/weechat/weechat_otr.h b/weechat/weechat_otr.h
index 6b281de..b6ffc90 100644
--- a/weechat/weechat_otr.h
+++ b/weechat/weechat_otr.h
@@ -47,7 +47,7 @@ extern char set_policy[512];
extern char set_policy_known[512];
extern char set_ignore[512];
extern int set_finishonunload;
-void cmd_set(IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
+void cmd_set(IOUSTATE *ioustate,IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
char *target);
#define statusbar_items_redraw(name) ;
@@ -95,6 +95,10 @@ static void IRCCTX_FREE(IRC_CTX *ircctx)
free(ircctx);
}
+#define IRCCTX_ACCNAME(accname,ircctx) sprintf(accname, "%s@%s", ircctx->nick, ircctx->address)
+#define IRCCTX_IO_US(ircctx) (&ioustate_uniq)
+#define IO_CREATE_US(user) (&ioustate_uniq)
+
/* Don't look beyond this point. Ugly temporary hack. */
#define g_io_add_watch(pid,a,func,b) gioaddwatchfake(pid,func)
diff --git a/xchat/xchat_otr.c b/xchat/xchat_otr.c
index db051c1..60661af 100644
--- a/xchat/xchat_otr.c
+++ b/xchat/xchat_otr.c
@@ -25,6 +25,8 @@ int debug = 0;
GRegex *regex_nickignore = NULL;
#endif
+static IOUSTATE *ioustate;
+
xchat_plugin *ph;
void irc_send_message(IRC_CTX *ircctx, const char *recipient, char *msg) {
@@ -48,7 +50,7 @@ int cmd_otr(char *word[], char *word_eol[], void *userdata)
while (word[argc]&&*word[argc])
argc++;
- cmd_generic(ircctx,argc,word,word_eol,target);
+ cmd_generic(ioustate,ircctx,argc,word,word_eol,target);
return XCHAT_EAT_ALL;
}
@@ -152,12 +154,14 @@ int xchat_plugin_init(xchat_plugin *plugin_handle,
if (otrlib_init())
return 0;
+ ioustate = otr_init_user("one to rule them all");
+
xchat_hook_server(ph, "PRIVMSG", XCHAT_PRI_NORM, hook_privmsg, 0);
xchat_hook_command(ph, "", XCHAT_PRI_NORM, hook_outgoing, 0, 0);
xchat_hook_command(ph, "otr", XCHAT_PRI_NORM, cmd_otr, 0, 0);
- otr_setpolicies(IO_DEFAULT_POLICY,FALSE);
- otr_setpolicies(IO_DEFAULT_POLICY_KNOWN,TRUE);
+ otr_setpolicies(ioustate,IO_DEFAULT_POLICY,FALSE);
+ otr_setpolicies(ioustate,IO_DEFAULT_POLICY_KNOWN,TRUE);
#ifdef HAVE_GREGEX_H
if (regex_nickignore)
@@ -180,7 +184,9 @@ int xchat_plugin_deinit()
#endif
if (set_finishonunload)
- otr_finishall();
+ otr_finishall(ioustate);
+
+ otr_deinit_user(ioustate);
otrlib_deinit();
diff --git a/xchat/xchat_otr.h b/xchat/xchat_otr.h
index 32e962e..9e54b4c 100644
--- a/xchat/xchat_otr.h
+++ b/xchat/xchat_otr.h
@@ -1,3 +1,22 @@
+/*
+ * Off-the-Record Messaging (OTR) modules for IRC
+ * Copyright (C) 2009 Uli Meis <a.sporto+bee at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA
+ */
+
#include "xchat-plugin.h"
#define PNAME "xchat-otr"
@@ -32,8 +51,8 @@ extern char set_policy[512];
extern char set_policy_known[512];
extern char set_ignore[512];
extern int set_finishonunload;
-void cmd_set(IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
- char *target);
+void cmd_set(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc,
+ char *argv[], char *argv_eol[], char *target);
#define statusbar_items_redraw(name) ;
#define get_client_config_dir() xchat_get_info(ph,"xchatdir")
@@ -61,3 +80,6 @@ void printformat(IRC_CTX *ircctx, const char *nick, int lvl, int fnum, ...);
#define IRCCTX_ADDR(ircctx) ircctx->address
#define IRCCTX_NICK(ircctx) ircctx->nick
#define IRCCTX_FREE(ircctx) g_free(ircctx)
+#define IRCCTX_ACCNAME(accname,ircctx) sprintf(accname, "%s@%s", ircctx->nick, ircctx->address)
+#define IRCCTX_IO_US(ircctx) (&ioustate_uniq)
+#define IO_CREATE_US(user) (&ioustate_uniq)
--
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