[Pkg-privacy-commits] [irssi-plugin-otr] 67/267: Generic cmd handler.
Ximin Luo
infinity0 at moszumanska.debian.org
Sat Aug 22 12:26:18 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 3afdbb3a93861d9e1e64e653ac69d26678115041
Author: Uli Meis <a.sporto+bee at gmail.com>
Date: Thu Feb 12 15:45:54 2009 +0100
Generic cmd handler.
---
io_set.c | 62 +++++++++++++++
io_util.c | 210 +++++++++++++++++++++++++++++++++++++++++++++++++
irssi/CMakeLists.txt | 2 +-
irssi/irssi_otr.c | 199 ++++------------------------------------------
otr.h | 15 ++++
weechat/CMakeLists.txt | 2 +-
weechat/weechat_otr.c | 110 +++++---------------------
weechat/weechat_otr.h | 8 ++
xchat/CMakeLists.txt | 2 +-
xchat/xchat_otr.c | 117 +++++++--------------------
xchat/xchat_otr.h | 8 ++
11 files changed, 369 insertions(+), 366 deletions(-)
diff --git a/io_set.c b/io_set.c
new file mode 100644
index 0000000..5099a50
--- /dev/null
+++ b/io_set.c
@@ -0,0 +1,62 @@
+/*
+ * 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 "otr.h"
+
+#ifdef HAVE_GREGEX_H
+extern GRegex *regex_nickignore;
+#endif
+
+char set_policy[512] = IO_DEFAULT_POLICY;
+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[],
+ char *target) {
+ char *setting, *value;
+
+ if (argc) {
+ setting = argv[0];
+ value = argv[1] ? : "";
+ }
+
+ if (!argc) {
+ otr_logst(MSGLEVEL_CRAP,"policy: %s\n"
+ "policy_known: %s\nignore: %s\n"
+ "finishonunload: %s\n",
+ set_policy,set_policy_known,set_ignore,
+ set_finishonunload ? "true" : "false");
+ } else if (strcmp(setting,"policy")==0) {
+ otr_setpolicies(value,FALSE);
+ strcpy(set_policy,value);
+ } else if (strcmp(setting,"policy_known")==0) {
+ otr_setpolicies(value,TRUE);
+ strcpy(set_policy_known,value);
+ } else if (strcmp(setting,"ignore")==0) {
+#ifdef HAVE_GREGEX_H
+ if (regex_nickignore)
+ g_regex_unref(regex_nickignore);
+ regex_nickignore = g_regex_new(value,0,0,NULL);
+ strcpy(set_ignore,value);
+#endif
+ } else if (strcmp(setting,"finishonunload")==0) {
+ set_finishonunload = (strcasecmp(value,"true")==0);
+ }
+}
diff --git a/io_util.c b/io_util.c
new file mode 100644
index 0000000..340b2f6
--- /dev/null
+++ b/io_util.c
@@ -0,0 +1,210 @@
+/*
+ * Off-the-Record Messaging (OTR) modules for IRC
+ * 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 "otr.h"
+
+int extract_nick(char *nick, char *line)
+{
+ char *excl;
+
+ if (*line++ != ':')
+ return FALSE;
+
+ strcpy(nick,line);
+
+ if ((excl = strchr(nick,'!')))
+ *excl = '\0';
+
+ return TRUE;
+
+}
+
+int cmd_generic(IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
+ char *target)
+{
+ char *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);
+ return TRUE;
+ }
+ } while ((++commands)->name);
+
+ return FALSE;
+}
+
+void cmd_debug(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[],
+ char *target) {
+ otr_noticest(TXT_CMD_VERSION,IRCOTR_VERSION);
+}
+
+void cmd_help(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[],
+ char *target) {
+ if (argc)
+ otr_finish(NULL,NULL,argv[0],TRUE);
+ else if (ircctx&&target)
+ otr_finish(ircctx,target,NULL,TRUE);
+ else
+ otr_noticest(TXT_CMD_QNOTFOUND);
+
+}
+
+void cmd_trust(IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
+ char *target) {
+ if (argc)
+ otr_trust(NULL,NULL,argv[0]);
+ else if (ircctx&&target)
+ otr_trust(ircctx,target,NULL);
+ else
+ otr_noticest(TXT_CMD_QNOTFOUND);
+}
+
+void cmd_authabort(IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
+ char *target) {
+ if (argc)
+ otr_authabort(NULL,NULL,argv[0]);
+ else if (ircctx&&target)
+ otr_authabort(ircctx,target,NULL);
+ else
+ otr_noticest(TXT_CMD_QNOTFOUND);
+}
+
+void cmd_genkey(IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
+ char *target) {
+ if (argc) {
+ if (strcmp(argv[0],"abort")==0)
+ keygen_abort(FALSE);
+ else if (strchr(argv[0],'@'))
+ keygen_run(argv[0]);
+ else
+ otr_noticest(TXT_KG_NEEDACC);
+ } else {
+ otr_noticest(TXT_KG_NEEDACC);
+ }
+}
+
+void cmd_auth(IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
+ char *target) {
+ if (!argc) {
+ otr_notice(ircctx,target,
+ TXT_CMD_AUTH);
+ } else if ((argc>1)&&strchr(argv[0],'@')) {
+ otr_auth(NULL,NULL,argv[0],argv[1]);
+ } else if (ircctx&&target) {
+ otr_auth(ircctx,target,NULL,argv_eol[0]);
+ } else {
+ otr_noticest(TXT_CMD_QNOTFOUND);
+ }
+}
+
+/*
+ * /otr contexts
+ */
+void cmd_contexts(IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
+ char *target) {
+ struct ctxlist_ *ctxlist = otr_contexts(),*ctxnext = ctxlist;
+ struct fplist_ *fplist,*fpnext;
+
+ if (!ctxlist)
+ otr_infost(TXT_CTX_NOCTXS);
+
+ while (ctxlist) {
+ otr_infost(TXT_CTX_CTX_UNENCRYPTED+ctxlist->state,
+ ctxlist->username,
+ ctxlist->accountname);
+
+ fplist = ctxlist->fplist;
+ while (fplist) {
+ otr_infost(TXT_CTX_FPS_NO+fplist->authby,
+ fplist->fp);
+ fplist = fplist->next;
+ }
+ ctxlist = ctxlist->next;
+ }
+ 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);
+ }
+}
+
+struct _cmds cmds[] = {
+ { "version", cmd_version },
+ { "debug", cmd_debug },
+ { "help", cmd_help },
+ { "finish", cmd_finish },
+ { "trust", cmd_trust },
+ { "authabort", cmd_authabort },
+ { "auth", cmd_auth },
+ { "genkey", cmd_genkey },
+ { "contexts", cmd_contexts },
+ { NULL, NULL },
+ { NULL, NULL }};
+
+void io_explode_args(const char *args, char ***argvp, char ***argv_eolp, int *argcp)
+{
+ char **argv, **argv_eol;
+ char *s = (char*)args;
+ int argc=1,i;
+
+ while ((s = strchr(s+1,' ')))
+ argc++;
+
+ argv = (char **)malloc(sizeof(char *)*argc);
+ argv_eol = (char **)malloc(sizeof(char *)*argc);
+
+ s = (char*)args;
+ argv_eol[0] = strdup(args);
+ i = 0;
+ while (++i<argc)
+ argv_eol[i] = strchr(argv_eol[i-1],' ')+1;
+
+ argv[0] = strtok(strdup(args)," ");
+ i = 1;
+ while (i<argc) {
+ argv[i++] = strtok(NULL," ");
+ otr_logst(MSGLEVEL_CRAP,"arg %d: %s",i,argv[i-1]);
+ }
+
+ *argvp = argv;
+ *argv_eolp = argv_eol;
+ *argcp = argc;
+}
diff --git a/irssi/CMakeLists.txt b/irssi/CMakeLists.txt
index b82466a..4459e35 100644
--- a/irssi/CMakeLists.txt
+++ b/irssi/CMakeLists.txt
@@ -43,7 +43,7 @@ IF (NOT HAVE_IRSSISBAR_H)
SET(HAVE_IRSSISBAR_H 1 CACHE INTERNAL "Having irssi headers" FORCE)
ENDIF (NOT HAVE_IRSSISBAR_H)
-ADD_LIBRARY(irssiotr SHARED irssi/irssi_otr.c otr_util.c otr_ops.c otr_key.c ${CMAKE_BINARY_DIR}/otr-formats.c)
+ADD_LIBRARY(irssiotr SHARED irssi/irssi_otr.c otr_util.c otr_ops.c otr_key.c io_util.c ${CMAKE_BINARY_DIR}/otr-formats.c)
TARGET_LINK_LIBRARIES(irssiotr ${GLIB_LIBRARIES} ${LIBOTR_LIBRARIES})
SET_TARGET_PROPERTIES(irssiotr PROPERTIES
COMPILE_FLAGS -DTARGET_IRSSI
diff --git a/irssi/irssi_otr.c b/irssi/irssi_otr.c
index 81d04c9..4755c32 100644
--- a/irssi/irssi_otr.c
+++ b/irssi/irssi_otr.c
@@ -88,179 +88,28 @@ static void sig_query_destroyed(QUERY_REC *query) {
*/
static void cmd_otr(const char *data,void *server,WI_ITEM_REC *item)
{
- if (*data == '\0')
- otr_noticest(TXT_CMD_OTR);
- else {
- command_runsub("otr", data, server, item);
- }
-}
-
-/* used to handle a bunch of commands */
-static void cmd_generic(const char *cmd, const char *args, WI_ITEM_REC *item)
-{
+ char **argv, **argv_eol;
+ int argc;
QUERY_REC *query = QUERY(item);
- if (*args == '\0')
- args = NULL;
-
- if (!(query&&query->server&&query->server->connrec))
- query = NULL;
-
- if (strcmp(cmd,"finish")==0) {
- if (args) {
- otr_finish(NULL,NULL,args,TRUE);
- statusbar_items_redraw("otr");
- } else if (query) {
- otr_finish(query->server,query->name,NULL,TRUE);
- statusbar_items_redraw("otr");
- } else
- otr_noticest(TXT_CMD_QNOTFOUND);
- } else if (strcmp(cmd,"trust")==0) {
- if (args) {
- otr_trust(NULL,NULL,args);
- statusbar_items_redraw("otr");
- } else if (query) {
- otr_trust(query->server,query->name,NULL);
- statusbar_items_redraw("otr");
- } else
- otr_noticest(TXT_CMD_QNOTFOUND);
- } else if (strcmp(cmd,"authabort")==0) {
- if (args) {
- otr_authabort(NULL,NULL,args);
- statusbar_items_redraw("otr");
- } else if (query) {
- otr_authabort(query->server,query->name,NULL);
- statusbar_items_redraw("otr");
- } else
- otr_noticest(TXT_CMD_QNOTFOUND);
- } else if (strcmp(cmd,"auth")==0) {
- if (args) {
- char *second = strchr(args,' ');
- char *add = strchr(args,'@');
- if (add&&second&&(add<second)&&(*(second+1))) {
- *second = '\0';
- otr_auth(NULL,NULL,args,second+1);
- *second = ' ';
- } else if (query) {
- otr_auth(query->server,query->name,NULL,args);
- } else {
- otr_noticest(TXT_CMD_QNOTFOUND);
- }
- } else if (query) {
- otr_notice(query->server,query->name,
- TXT_CMD_AUTH);
- } else {
- otr_noticest(TXT_CMD_AUTH);
- }
+ if (*data == '\0') {
+ otr_noticest(TXT_CMD_OTR);
+ return;
}
-}
-
-/*
- * /otr finish [peername]
- */
-static void cmd_finish(const char *data, void *server, WI_ITEM_REC *item)
-{
- cmd_generic("finish",data,item);
-}
-
-/*
- * /otr trust [peername]
- */
-static void cmd_trust(const char *data, void *server, WI_ITEM_REC *item)
-{
- cmd_generic("trust",data,item);
-}
-
-/*
- * /otr genkey nick at irc.server.com
- */
-static void cmd_genkey(const char *data, void *server, WI_ITEM_REC *item)
-{
- if (strcmp(data,"abort")==0)
- keygen_abort(FALSE);
- else if (strchr(data,'@'))
- keygen_run(data);
- else
- otr_noticest(TXT_KG_NEEDACC);
-}
-
-/*
- * /otr auth [peername] <secret>
- */
-static void cmd_auth(const char *data, void *server, WI_ITEM_REC *item)
-{
- cmd_generic("auth",data,item);
-}
-/*
- * /otr authabort [peername]
- */
-static void cmd_authabort(const char *data, void *server, WI_ITEM_REC *item)
-{
- cmd_generic("authabort",data,item);
-}
+ io_explode_args(data,&argv,&argv_eol,&argc);
-/*
- * /otr debug
- */
-static void cmd_debug(const char *data, void *server, WI_ITEM_REC *item)
-{
- debug = !debug;
- otr_noticest(debug ? TXT_CMD_DEBUG_ON : TXT_CMD_DEBUG_OFF);
-}
-
-/*
- * /otr help
- */
-static void cmd_help(const char *data, void *server, WI_ITEM_REC *item)
-{
- printtext(NULL,NULL,MSGLEVEL_CRAP,otr_help);
-}
+ if (query&&query->server&&query->server->connrec) {
+ cmd_generic(query->server,argc,argv,argv_eol,query->name);
+ } else {
+ cmd_generic(NULL,argc,argv,argv_eol,NULL);
+ }
-/*
- * /otr version
- */
-static void cmd_version(const char *data, void *server, WI_ITEM_REC *item)
-{
- otr_noticest(TXT_CMD_VERSION,IRCOTR_VERSION);
-}
+ statusbar_items_redraw("otr");
-/*
- * /otr contexts
- */
-static void cmd_contexts(const char *data, void *server, WI_ITEM_REC *item)
-{
- struct ctxlist_ *ctxlist = otr_contexts(),*ctxnext = ctxlist;
- struct fplist_ *fplist,*fpnext;
-
- if (!ctxlist)
- printformat(NULL,NULL,MSGLEVEL_CRAP,TXT_CTX_NOCTXS);
-
- while (ctxlist) {
- printformat(NULL,NULL,MSGLEVEL_CRAP,
- TXT_CTX_CTX_UNENCRYPTED+ctxlist->state,
- ctxlist->username,
- ctxlist->accountname);
-
- fplist = ctxlist->fplist;
- while (fplist) {
- printformat(NULL,NULL,MSGLEVEL_CRAP,
- TXT_CTX_FPS_NO+fplist->authby,
- fplist->fp);
- fplist = fplist->next;
- }
- ctxlist = ctxlist->next;
- }
- 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);
- }
+ g_free(argv_eol[0]);
+ g_free(argv_eol);
+ g_free(argv);
}
/*
@@ -330,15 +179,6 @@ void otr_init(void)
signal_add("query destroyed", (SIGNAL_FUNC) sig_query_destroyed);
command_bind("otr", NULL, (SIGNAL_FUNC) cmd_otr);
- command_bind("otr debug", NULL, (SIGNAL_FUNC) cmd_debug);
- command_bind("otr trust", NULL, (SIGNAL_FUNC) cmd_trust);
- command_bind("otr finish", NULL, (SIGNAL_FUNC) cmd_finish);
- command_bind("otr genkey", NULL, (SIGNAL_FUNC) cmd_genkey);
- command_bind("otr auth", NULL, (SIGNAL_FUNC) cmd_auth);
- command_bind("otr authabort", NULL, (SIGNAL_FUNC) cmd_authabort);
- command_bind("otr help", NULL, (SIGNAL_FUNC) cmd_help);
- command_bind("otr contexts", NULL, (SIGNAL_FUNC) cmd_contexts);
- command_bind("otr version", NULL, (SIGNAL_FUNC) cmd_version);
command_bind_first("quit", NULL, (SIGNAL_FUNC) cmd_quit);
@@ -370,15 +210,6 @@ void otr_deinit(void)
signal_remove("query destroyed", (SIGNAL_FUNC) sig_query_destroyed);
command_unbind("otr", (SIGNAL_FUNC) cmd_otr);
- command_unbind("otr debug", (SIGNAL_FUNC) cmd_debug);
- command_unbind("otr trust", (SIGNAL_FUNC) cmd_trust);
- command_unbind("otr finish", (SIGNAL_FUNC) cmd_finish);
- command_unbind("otr genkey", (SIGNAL_FUNC) cmd_genkey);
- command_unbind("otr auth", (SIGNAL_FUNC) cmd_auth);
- command_unbind("otr authabort", (SIGNAL_FUNC) cmd_authabort);
- command_unbind("otr help", (SIGNAL_FUNC) cmd_help);
- command_unbind("otr contexts", (SIGNAL_FUNC) cmd_contexts);
- command_unbind("otr version", (SIGNAL_FUNC) cmd_version);
command_unbind("quit", (SIGNAL_FUNC) cmd_quit);
diff --git a/otr.h b/otr.h
index c239241..468b349 100644
--- a/otr.h
+++ b/otr.h
@@ -166,3 +166,18 @@ void key_load();
void fps_load();
void otr_writefps();
+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);
+};
+
+/* see io_util.c */
+#define CMDCOUNT 9
+extern struct _cmds cmds[];
+
+int cmd_generic(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/weechat/CMakeLists.txt b/weechat/CMakeLists.txt
index 7e4fcc2..13d8680 100644
--- a/weechat/CMakeLists.txt
+++ b/weechat/CMakeLists.txt
@@ -11,7 +11,7 @@ SET(IRCOTR_INCLUDE_DIRS
INCLUDE_DIRECTORIES(${IRCOTR_INCLUDE_DIRS})
-ADD_LIBRARY(weechatotr SHARED weechat/weechat_otr.c otr_util.c otr_ops.c otr_key.c ${PROJECT_BINARY_DIR}/xchat-formats.c)
+ADD_LIBRARY(weechatotr SHARED weechat/weechat_otr.c otr_util.c otr_ops.c otr_key.c io_util.c io_set.c ${PROJECT_BINARY_DIR}/xchat-formats.c)
TARGET_LINK_LIBRARIES(weechatotr ${GLIB_LIBRARIES} ${LIBOTR_LIBRARIES})
SET_TARGET_PROPERTIES(weechatotr PROPERTIES
COMPILE_FLAGS -DTARGET_WEECHAT
diff --git a/weechat/weechat_otr.c b/weechat/weechat_otr.c
index 4cd3b55..8feedd8 100644
--- a/weechat/weechat_otr.c
+++ b/weechat/weechat_otr.c
@@ -34,12 +34,7 @@ int debug = 0;
GRegex *regex_nickignore = NULL;
#endif
-static char set_policy[512] = IO_DEFAULT_POLICY;
-static char set_policy_known[512] = IO_DEFAULT_POLICY_KNOWN;
-static char set_ignore[512] = IO_DEFAULT_IGNORE;
-static int set_finishonunload = TRUE;
-
-void printformatva(IRC_CTX *ircctx, const char *nick, char *format, va_list params)
+void printformatva(IRC_CTX *ircctx, const char *nick, const char *format, va_list params)
{
char msg[LOGMAX], *s = msg;
char *server = NULL;
@@ -80,7 +75,7 @@ void printformat(IRC_CTX *ircctx, const char *nick, int lvl, int fnum, ...)
printformatva(ircctx,nick,formats[fnum].def,params);
}
-void wc_printf(IRC_CTX *ircctx, const char *nick, char *format, ...)
+void otr_log(IRC_CTX *ircctx, const char *nick, int level, const char *format, ...)
{
va_list params;
va_start( params, format );
@@ -88,6 +83,9 @@ void wc_printf(IRC_CTX *ircctx, const char *nick, char *format, ...)
printformatva(ircctx,nick,format,params);
}
+#define wc_printf(server,nick,format,...) \
+ otr_log(server,nick,0,format, ## __VA_ARGS__)
+
#define wc_debug(server,nick,format,...) { \
if (debug) \
wc_printf(server,nick, \
@@ -111,22 +109,6 @@ IRC_CTX *server_find_address(char *address)
return &ircctx;
}
-int extract_nick(char *nick, char *line)
-{
- char *excl;
-
- if (*line++ != ':')
- return FALSE;
-
- strcpy(nick,line);
-
- if ((excl = strchr(nick,'!')))
- *excl = '\0';
-
- return TRUE;
-
-}
-
char *wc_modifier_privmsg_in(void *data, const char *modifier,
const char *modifier_data, const char *string)
{
@@ -256,79 +238,20 @@ int cmd_otr(void *data, struct t_gui_buffer *buffer, int argc, char **word, char
.address = (char*)server },
*ircctx = &ircctxs;
- char *cmd = argc > 1 ? word[1] : NULL;
- char *parm1 = argc > 2 ? word[2] : "";
- char *parm2 = argc > 3 ? word[3] : "";
-
- if (!cmd) {
- weechat_printf(buffer,otr_help);
- } else if (strcmp(cmd,"debug")==0) {
- debug = !debug;
- otr_noticest(debug ? TXT_CMD_DEBUG_ON : TXT_CMD_DEBUG_OFF);
- } else if (strcmp(cmd,"version")==0) {
- otr_noticest(TXT_CMD_VERSION,IRCOTR_VERSION);
- } else if (strcmp(cmd,"finish")==0) {
- if (parm1&&*parm1)
- otr_finish(NULL,NULL,parm1,TRUE);
- else
- otr_finish(ircctx,target,NULL,TRUE);
- } else if (strcmp(cmd,"trust")==0) {
- if (parm1&&*parm1)
- otr_trust(NULL,NULL,parm1);
- else
- otr_trust(ircctx,target,NULL);
- } else if (strcmp(cmd,"authabort")==0) {
- if (parm1&&*parm1)
- otr_authabort(NULL,NULL,parm1);
- else
- otr_authabort(ircctx,target,NULL);
- } else if (strcmp(cmd,"genkey")==0) {
- if (parm1&&*parm1) {
- if (strcmp(parm1,"abort")==0)
- keygen_abort(FALSE);
- else if (strchr(parm1,'@'))
- keygen_run(parm1);
- else
- otr_noticest(TXT_KG_NEEDACC);
- } else {
- otr_noticest(TXT_KG_NEEDACC);
- }
- } else if (strcmp(cmd,"auth")==0) {
- if (!parm1||!*parm1) {
- otr_notice(ircctx,target,
- TXT_CMD_AUTH);
- } else if (parm2&&*parm2&&strchr(parm1,'@'))
- otr_auth(NULL,NULL,word_eol[3],parm1);
- else
- otr_auth(ircctx,target,NULL,word_eol[2]);
- } else if (strcmp(cmd,"set")==0) {
- if (strcmp(parm1,"policy")==0) {
- otr_setpolicies(word_eol[3],FALSE);
- strcpy(set_policy,word_eol[3]);
- } else if (strcmp(parm1,"policy_known")==0) {
- otr_setpolicies(word_eol[3],TRUE);
- strcpy(set_policy_known,word_eol[3]);
- } else if (strcmp(parm1,"ignore")==0) {
-#ifdef HAVE_GREGEX_H
- if (regex_nickignore)
- g_regex_unref(regex_nickignore);
- regex_nickignore = g_regex_new(word_eol[3],0,0,NULL);
- strcpy(set_ignore,word_eol[3]);
-#endif
- } else if (strcmp(parm1,"finishonunload")==0) {
- set_finishonunload = (strcasecmp(parm2,"true")==0);
- } else {
- weechat_printf(buffer, "policy: %s\n"
- "policy_known: %s\nignore: %s\n"
- "finishonunload: %s\n",
- set_policy,set_policy_known,set_ignore,
- set_finishonunload ? "true" : "false");
- }
-
+ word++;
+ word_eol++;
+ argc--;
+
+ if (!argc) {
+ otr_noticest(TXT_CMD_OTR);
+ return WEECHAT_RC_OK;
}
+ cmd_generic(ircctx,argc,word,word_eol,target);
+
return WEECHAT_RC_OK;
}
+
int weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
{
@@ -356,6 +279,9 @@ int weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]
"",
&cmd_otr, NULL);
+ cmds[CMDCOUNT].name = "set";
+ cmds[CMDCOUNT].cmdfunc = cmd_set;
+
return WEECHAT_RC_OK;
}
diff --git a/weechat/weechat_otr.h b/weechat/weechat_otr.h
index 408d257..6b281de 100644
--- a/weechat/weechat_otr.h
+++ b/weechat/weechat_otr.h
@@ -42,6 +42,14 @@ typedef struct _FORMAT_REC FORMAT_REC;
enum { MSGLEVEL_CRAP, MSGLEVEL_MSGS } lvls;
+/* stuff from io_set.c */
+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);
+
#define statusbar_items_redraw(name) ;
#define get_client_config_dir() weechat_info_get("weechat_dir",NULL)
diff --git a/xchat/CMakeLists.txt b/xchat/CMakeLists.txt
index 19f79aa..71e688b 100644
--- a/xchat/CMakeLists.txt
+++ b/xchat/CMakeLists.txt
@@ -12,7 +12,7 @@ SET(IRCOTR_INCLUDE_DIRS
INCLUDE_DIRECTORIES(${IRCOTR_INCLUDE_DIRS})
-ADD_LIBRARY(xchatotr SHARED xchat/xchat_otr.c otr_util.c otr_ops.c otr_key.c ${PROJECT_BINARY_DIR}/xchat-formats.c)
+ADD_LIBRARY(xchatotr SHARED xchat/xchat_otr.c otr_util.c otr_ops.c otr_key.c io_util.c io_set.c ${PROJECT_BINARY_DIR}/xchat-formats.c)
TARGET_LINK_LIBRARIES(xchatotr ${GLIB_LIBRARIES} ${LIBOTR_LIBRARIES})
SET_TARGET_PROPERTIES(xchatotr PROPERTIES
COMPILE_FLAGS -DTARGET_XCHAT
diff --git a/xchat/xchat_otr.c b/xchat/xchat_otr.c
index 05dcd47..db051c1 100644
--- a/xchat/xchat_otr.c
+++ b/xchat/xchat_otr.c
@@ -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 "otr.h"
int debug = 0;
@@ -8,27 +27,6 @@ GRegex *regex_nickignore = NULL;
xchat_plugin *ph;
-static char set_policy[512] = IO_DEFAULT_POLICY;
-static char set_policy_known[512] = IO_DEFAULT_POLICY_KNOWN;
-static char set_ignore[512] = IO_DEFAULT_IGNORE;
-static int set_finishonunload = TRUE;
-
-int extract_nick(char *nick, char *line)
-{
- char *excl;
-
- if (*line++ != ':')
- return FALSE;
-
- strcpy(nick,line);
-
- if ((excl = strchr(nick,'!')))
- *excl = '\0';
-
- return TRUE;
-
-}
-
void irc_send_message(IRC_CTX *ircctx, const char *recipient, char *msg) {
xchat_commandf(ph, "PRIVMSG %s :%s", recipient, msg);
}
@@ -42,73 +40,15 @@ int cmd_otr(char *word[], char *word_eol[], void *userdata)
.nick = (char*)own_nick,
.address = (char*)server },
*ircctx = &ircctxs;
+ int argc=0;
- char *cmd = word[2];
-
- if (strcmp(cmd,"debug")==0) {
- debug = !debug;
- otr_noticest(debug ? TXT_CMD_DEBUG_ON : TXT_CMD_DEBUG_OFF);
- } else if (strcmp(cmd,"version")==0) {
- otr_noticest(TXT_CMD_VERSION,IRCOTR_VERSION);
- } else if (strcmp(cmd,"finish")==0) {
- if (word[3]&&*word[3])
- otr_finish(NULL,NULL,word[3],TRUE);
- else
- otr_finish(ircctx,target,NULL,TRUE);
- } else if (strcmp(cmd,"trust")==0) {
- if (word[3]&&*word[3])
- otr_trust(NULL,NULL,word[3]);
- else
- otr_trust(ircctx,target,NULL);
- } else if (strcmp(cmd,"authabort")==0) {
- if (word[3]&&*word[3])
- otr_authabort(NULL,NULL,word[3]);
- else
- otr_authabort(ircctx,target,NULL);
- } else if (strcmp(cmd,"genkey")==0) {
- if (word[3]&&*word[3]) {
- if (strcmp(word[3],"abort")==0)
- keygen_abort(FALSE);
- else if (strchr(word[3],'@'))
- keygen_run(word[3]);
- else
- otr_noticest(TXT_KG_NEEDACC);
- } else {
- otr_noticest(TXT_KG_NEEDACC);
- }
- } else if (strcmp(cmd,"auth")==0) {
- if (!word[3]||!*word[3]) {
- otr_notice(ircctx,target,
- TXT_CMD_AUTH);
- } else if (word[4]&&*word[4]&&strchr(word[3],'@'))
- otr_auth(NULL,NULL,word_eol[4],word[3]);
- else
- otr_auth(ircctx,target,NULL,word_eol[3]);
- } else if (strcmp(cmd,"set")==0) {
- if (strcmp(word[3],"policy")==0) {
- otr_setpolicies(word_eol[4],FALSE);
- strcpy(set_policy,word_eol[4]);
- } else if (strcmp(word[3],"policy_known")==0) {
- otr_setpolicies(word_eol[4],TRUE);
- strcpy(set_policy_known,word_eol[4]);
- } else if (strcmp(word[3],"ignore")==0) {
-#ifdef HAVE_GREGEX_H
- if (regex_nickignore)
- g_regex_unref(regex_nickignore);
- regex_nickignore = g_regex_new(word_eol[4],0,0,NULL);
- strcpy(set_ignore,word_eol[4]);
-#endif
- } else if (strcmp(word[3],"finishonunload")==0) {
- set_finishonunload = (strcasecmp(word[4],"true")==0);
- } else {
- xchat_printf(ph, "policy: %s\n"
- "policy_known: %s\nignore: %s\n"
- "finishonunload: %s\n",
- set_policy,set_policy_known,set_ignore,
- set_finishonunload ? "true" : "false");
- }
-
- }
+ word+=3;
+ word_eol+=3;
+
+ while (word[argc]&&*word[argc])
+ argc++;
+
+ cmd_generic(ircctx,argc,word,word_eol,target);
return XCHAT_EAT_ALL;
}
@@ -227,6 +167,9 @@ int xchat_plugin_init(xchat_plugin *plugin_handle,
xchat_print(ph, "xchat-otr loaded successfully!\n");
+ cmds[CMDCOUNT].name = "set";
+ cmds[CMDCOUNT].cmdfunc = cmd_set;
+
return 1;
}
diff --git a/xchat/xchat_otr.h b/xchat/xchat_otr.h
index a103efd..32e962e 100644
--- a/xchat/xchat_otr.h
+++ b/xchat/xchat_otr.h
@@ -27,6 +27,14 @@ enum { MSGLEVEL_CRAP, MSGLEVEL_MSGS } lvls;
extern xchat_plugin *ph; /* plugin handle */
+/* stuff from io_set.c */
+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);
+
#define statusbar_items_redraw(name) ;
#define get_client_config_dir() xchat_get_info(ph,"xchatdir")
--
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