[Pkg-privacy-commits] [irssi-plugin-otr] 41/267: Added rudimentary xchat support.
Ximin Luo
infinity0 at moszumanska.debian.org
Sat Aug 22 12:41:26 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 f5f2dec5b4345e3e28f03e0d17669e51eeb97904
Author: Uli Meis <a.sporto+bee at gmail.com>
Date: Fri Jan 23 20:44:46 2009 +0100
Added rudimentary xchat support.
---
CMakeLists.txt | 40 ++++++++-
irssi_otr.h | 1 +
makeformats.py | 14 ++++
otr.h | 9 +-
otr_util.c | 2 +-
xchat_otr.c | 256 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
xchat_otr.h | 55 +++++++++++++
7 files changed, 371 insertions(+), 6 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2064f95..cad74b8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -112,9 +112,9 @@ FIND_PATH(IRSSI_INCLUDE_DIR NAMES irssi/src/core/module.h)
MARK_AS_ADVANCED(IRSSI_INCLUDE_DIR)
IF(NOT IRSSI_INCLUDE_DIR)
- MESSAGE(FATAL_ERROR "Couldn't find irssi headers, "
- "usually installed in /usr/include/irssi")
+ MESSAGE(STATUS "*** no irssi found ***")
ELSE(NOT IRSSI_INCLUDE_DIR)
+ MESSAGE(STATUS "*** building for irssi ***")
SET(HAVE_IRSSI 1)
SET(IRSSIOTR_INCLUDE_DIRS
${IRSSIOTR_INCLUDE_DIRS}
@@ -149,6 +149,19 @@ ELSE(NOT IRSSI_INCLUDE_DIR)
ENDIF(NOT IRSSI_INCLUDE_DIR)
+FIND_PATH(XCHAT_INCLUDE_DIR NAMES xchat/xchat-plugin.h)
+MARK_AS_ADVANCED(XCHAT_INCLUDE_DIR)
+
+IF(NOT XCHAT_INCLUDE_DIR)
+ MESSAGE(STATUS "*** no xchat found ***")
+ELSE(NOT XCHAT_INCLUDE_DIR)
+ MESSAGE(STATUS "*** building for xchat ***")
+ SET(HAVE_XCHAT 1)
+ SET(IRSSIOTR_INCLUDE_DIRS
+ ${IRSSIOTR_INCLUDE_DIRS}
+ ${XCHAT_INCLUDE_DIR}/xchat)
+ENDIF(NOT XCHAT_INCLUDE_DIR)
+
include_directories(${IRSSIOTR_INCLUDE_DIRS})
SET(CMAKE_REQUIRED_INCLUDES ${IRSSIOTR_INCLUDE_DIRS})
SET(CMAKE_REQUIRED_DEFINITIONS -DHAVE_CONFIG_H ${LIBGCRYPT_CFLAGS})
@@ -186,7 +199,9 @@ ENDIF(NOT DOCDIR)
# generate otr-formats.{c,h}
-ADD_CUSTOM_COMMAND(OUTPUT ${PROJECT_BINARY_DIR}/otr-formats.c
+ADD_CUSTOM_COMMAND(OUTPUT
+ ${PROJECT_BINARY_DIR}/otr-formats.c
+ ${PROJECT_BINARY_DIR}/xchat-formats.c
DEPENDS makeformats.py formats.txt README
COMMAND
${PYTHON_EXECUTABLE}
@@ -219,6 +234,18 @@ IF(HAVE_IRSSI)
ENDIF(APPLE)
ENDIF(HAVE_IRSSI)
+IF(HAVE_XCHAT)
+ ADD_LIBRARY(xchatotr SHARED xchat_otr.c otr_util.c otr_ops.c otr_key.c ${PROJECT_BINARY_DIR}/xchat-formats.c)
+ TARGET_LINK_LIBRARIES(xchatotr ${GLIB_LIBRARIES} ${LIBOTR_LIBRARIES})
+ SET_TARGET_PROPERTIES(xchatotr PROPERTIES
+ COMPILE_FLAGS -DTARGET_XCHAT
+ OUTPUT_NAME "xchatotr"
+ LINK_FLAGS "${MAIN_LDFLAGS}")
+ IF(APPLE)
+ SET_TARGET_PROPERTIES(xchatotr PROPERTIES SUFFIX ".so")
+ ENDIF(APPLE)
+ENDIF(HAVE_XCHAT)
+
# cscope
FILE(GLOB CSANDHS *.c *.h)
@@ -231,7 +258,12 @@ IF(CMAKE_INSTALL_TYPE MATCHES "package-.*")
ELSEIF(CMAKE_INSTALL_TYPE MATCHES "home")
INSTALL(TARGETS irssiotr DESTINATION "$ENV{HOME}/.irssi/modules")
ELSE(CMAKE_INSTALL_TYPE MATCHES "package-.*")
- INSTALL(TARGETS irssiotr DESTINATION lib${LIB_SUFFIX}/irssi/modules)
+ IF(HAVE_IRSSI)
+ INSTALL(TARGETS irssiotr DESTINATION lib${LIB_SUFFIX}/irssi/modules)
+ ENDIF(HAVE_IRSSI)
+ IF(HAVE_XCHAT)
+ INSTALL(TARGETS xchatotr DESTINATION lib${LIB_SUFFIX}/xchat/plugins)
+ ENDIF(HAVE_XCHAT)
INSTALL(FILES README LICENSE DESTINATION ${DOCDIR})
ENDIF(CMAKE_INSTALL_TYPE MATCHES "package-.*")
diff --git a/irssi_otr.h b/irssi_otr.h
index e3c85e1..53a64d1 100644
--- a/irssi_otr.h
+++ b/irssi_otr.h
@@ -19,6 +19,7 @@
#define IRCCTX_DUP(ircctx) ircctx
#define IRCCTX_ADDR(ircctx) ircctx->connrec->address
#define IRCCTX_NICK(ircctx) ircctx->nick
+#define IRCCTX_FREE(ircctx) ;
#define otr_noticest(formatnum,...) \
printformat(NULL,NULL,MSGLEVEL_MSGS, formatnum, ## __VA_ARGS__)
diff --git a/makeformats.py b/makeformats.py
index c63003f..c8c9145 100755
--- a/makeformats.py
+++ b/makeformats.py
@@ -11,8 +11,10 @@ lines = map(lambda x: x.strip(),open(sys.argv[1],"r").readlines())
hdr = open("otr-formats.h","w")
src = open("otr-formats.c","w")
+srcx = open("xchat-formats.c","w")
src.write('#include "otr.h"\n');
+srcx.write('#include "otr.h"\n');
src.write("""char *otr_help = "%s";\n""" % "\\n".join(
["%9- OTR help -%9"]+
@@ -25,8 +27,10 @@ src.write("""char *otr_help = "%s";\n""" % "\\n".join(
))
src.write('FORMAT_REC formats[] = {\n')
+srcx.write('FORMAT_REC formats[] = {\n')
src.write('{ MODULE_NAME, "otr", 0}\n')
+srcx.write('{ MODULE_NAME, "otr", 0}\n')
hdr.write("extern char *otr_help;\n\n");
@@ -40,6 +44,7 @@ section = None
for line in lines:
src.write(",\n")
+ srcx.write(",\n")
e = line.split("\t")
@@ -47,6 +52,7 @@ for line in lines:
# Section name
section = e[0]
src.write("""{ NULL, "%s", 0 }\n""" % (e[0]))
+ srcx.write("""{ NULL, "%s", 0 }\n""" % (e[0]))
hdr.write(",\nTXT_OTR_FILL_%d" % fills)
@@ -59,6 +65,7 @@ for line in lines:
new = ""
last=0
i=0
+ srcx.write("""{ "%s", "%s", 0""" % (e[0],fo.replace("%%9","").replace("%9","").replace("%g","").replace("%n","")))
for m in re.finditer("(^|[^%])%([0-9]*)[ds]",fo):
if m.group()[-1]=='d':
params += ['1']
@@ -87,6 +94,7 @@ for line in lines:
src.write(", { %s }" % ", ".join(params))
src.write("}")
+ srcx.write("}")
hdr.write(",\n")
@@ -103,5 +111,11 @@ src.write(""",
};
""")
+srcx.write(""",
+{ NULL, NULL, 0 }
+};
+""")
+
hdr.close()
src.close()
+srcx.close()
diff --git a/otr.h b/otr.h
index 60bbca8..7dc73e8 100644
--- a/otr.h
+++ b/otr.h
@@ -40,6 +40,12 @@
#include <irssi_otr.h>
#endif
+/* xchat */
+
+#ifdef TARGET_XCHAT
+#include <xchat_otr.h>
+#endif
+
/* log stuff */
#define LOGMAX 1024
@@ -56,11 +62,12 @@ void otr_log(IRC_CTX *server, const char *to,
/* own */
#include "io-config.h"
-#include "otr-formats.h"
/* irssi module name */
#define MODULE_NAME "otr"
+#include "otr-formats.h"
+
/*
* maybe this should be configurable?
* I believe bitlbee has something >500.
diff --git a/otr_util.c b/otr_util.c
index 75ae683..f9e89b5 100644
--- a/otr_util.c
+++ b/otr_util.c
@@ -93,7 +93,7 @@ void context_free_app_info(void *data)
g_free(coi->msgqueue);
}
if (coi->ircctx)
- g_free(coi->ircctx);
+ IRCCTX_FREE(coi->ircctx);
}
/*
diff --git a/xchat_otr.c b/xchat_otr.c
new file mode 100644
index 0000000..e3cf9f6
--- /dev/null
+++ b/xchat_otr.c
@@ -0,0 +1,256 @@
+#include "otr.h"
+
+int debug = 0;
+
+#ifdef HAVE_GREGEX_H
+GRegex *regex_nickignore = NULL;
+#endif
+
+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;
+
+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);
+}
+
+int cmd_otr(char *word[], char *word_eol[], void *userdata)
+{
+ const char *own_nick = xchat_get_info(ph, "nick");
+ char *target = (char*)xchat_get_info(ph, "channel");
+ const char *server = xchat_get_info(ph, "server");
+ IRC_CTX ircctxs = {
+ .nick = (char*)own_nick,
+ .address = (char*)server },
+ *ircctx = &ircctxs;
+
+ 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,IRSSIOTR_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 {
+ xchat_printf(ph, "policy: %s\n"
+ "policy_known: %s\nignore: %s\n",
+ set_policy,set_policy_known,set_ignore);
+ }
+
+ }
+
+ return XCHAT_EAT_ALL;
+}
+
+int hook_outgoing(char *word[], char *word_eol[], void *userdata)
+{
+ const char *own_nick = xchat_get_info(ph, "nick");
+ const char *channel = xchat_get_info(ph, "channel");
+ const char *server = xchat_get_info(ph, "server");
+ char newmsg[512];
+ char *otrmsg;
+ IRC_CTX ircctx = {
+ .nick = (char*)own_nick,
+ .address = (char*)server };
+
+ if ((*channel == '&')||(*channel == '#'))
+ return XCHAT_EAT_NONE;
+
+#ifdef HAVE_GREGEX_H
+ if (g_regex_match(regex_nickignore,channel,0,NULL))
+ return XCHAT_EAT_NONE;
+#endif
+ otrmsg = otr_send(&ircctx,word_eol[1],channel);
+
+ if (otrmsg==word_eol[1])
+ return XCHAT_EAT_NONE;
+
+ xchat_emit_print(ph, "Your Message", own_nick, word_eol[1], NULL, NULL);
+
+ if (!otrmsg)
+ return XCHAT_EAT_ALL;
+
+ snprintf(newmsg, 511, "PRIVMSG %s :%s", channel, otrmsg);
+
+ otrl_message_free(otrmsg);
+ xchat_command(ph, newmsg);
+
+ return XCHAT_EAT_ALL;
+}
+
+int hook_privmsg(char *word[], char *word_eol[], void *userdata)
+{
+ char nick[256];
+ char *newmsg;
+ const char *server = xchat_get_info(ph, "server");
+ const char *own_nick = xchat_get_info(ph, "nick");
+ IRC_CTX ircctx = {
+ .nick = (char*)own_nick,
+ .address = (char*)server };
+
+ if (!extract_nick(nick,word[1]))
+ return XCHAT_EAT_NONE;
+
+#ifdef HAVE_GREGEX_H
+ if (g_regex_match(regex_nickignore,nick,0,NULL))
+ return XCHAT_EAT_NONE;
+#endif
+
+ newmsg = otr_receive(&ircctx,word_eol[2],nick);
+
+ if (!newmsg) {
+ return XCHAT_EAT_ALL;
+ }
+
+ if (newmsg==word_eol[2]) {
+ return XCHAT_EAT_NONE;
+ }
+
+ xchat_emit_print(ph, "Private Message", nick, newmsg, NULL, NULL);
+
+ otrl_message_free(newmsg);
+
+ return XCHAT_EAT_ALL;
+}
+
+void xchat_plugin_get_info(char **name, char **desc, char **version, void **reserved)
+{
+ *name = PNAME;
+ *desc = PDESC;
+ *version = PVERSION;
+}
+
+int xchat_plugin_init(xchat_plugin *plugin_handle,
+ char **plugin_name,
+ char **plugin_desc,
+ char **plugin_version,
+ char *arg)
+{
+ ph = plugin_handle;
+
+ *plugin_name = PNAME;
+ *plugin_desc = PDESC;
+ *plugin_version = PVERSION;
+
+ if (otrlib_init())
+ return 0;
+
+ 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);
+
+#ifdef HAVE_GREGEX_H
+ if (regex_nickignore)
+ g_regex_unref(regex_nickignore);
+ regex_nickignore = g_regex_new(IO_DEFAULT_IGNORE,0,0,NULL);
+#endif
+
+ xchat_print(ph, "xchat-otr loaded successfully!\n");
+
+ return 1;
+}
+
+void printformat(IRC_CTX *ircctx, const char *nick, int lvl, int fnum, ...)
+{
+ va_list params;
+ va_start( params, fnum );
+ char msg[LOGMAX], *s = msg;
+ xchat_context *find_query_ctx;
+ char *server = NULL;
+
+ if (ircctx)
+ server = ircctx->address;
+
+ find_query_ctx = xchat_find_context(ph, server, nick);
+
+ if(find_query_ctx==NULL)
+ { // no query window yet, lets open one
+ xchat_commandf(ph, "query %s", nick);
+ find_query_ctx = xchat_find_context(ph, server, nick);
+ }
+
+ xchat_set_context(ph, find_query_ctx);
+
+ if( vsnprintf( s, LOGMAX, formats[fnum].def, params ) < 0 )
+ sprintf( s, "internal error parsing error string (BUG)" );
+ va_end( params );
+ xchat_printf(ph, "OTR: %s", s);
+}
+
+IRC_CTX *server_find_address(char *address)
+{
+ static IRC_CTX ircctx;
+
+ ircctx.address = address;
+
+ return &ircctx;
+}
diff --git a/xchat_otr.h b/xchat_otr.h
new file mode 100644
index 0000000..afea3f9
--- /dev/null
+++ b/xchat_otr.h
@@ -0,0 +1,55 @@
+#include "xchat-plugin.h"
+
+#define PNAME "xchat-otr"
+#define PDESC "Off-The-Record Messaging for xchat"
+#define PVERSION IRSSIOTR_VERSION
+
+#define MAX_FORMAT_PARAMS 10
+
+
+struct _IRC_CTX {
+ char *nick;
+ char *address;
+};
+
+typedef struct _IRC_CTX IRC_CTX;
+struct _FORMAT_REC {
+ char *tag;
+ char *def;
+
+ int params;
+ int paramtypes[MAX_FORMAT_PARAMS];
+};
+
+typedef struct _FORMAT_REC FORMAT_REC;
+
+enum { MSGLEVEL_CRAP, MSGLEVEL_MSGS } lvls;
+
+extern xchat_plugin *ph; /* plugin handle */
+
+#define statusbar_items_redraw(name) ;
+#define get_irssi_dir() xchat_get_info(ph,"xchatdir")
+
+void printformat(IRC_CTX *ircctx, const char *nick, int lvl, int fnum, ...);
+
+#define otr_noticest(formatnum,...) \
+ printformat(NULL,NULL,MSGLEVEL_MSGS, formatnum, ## __VA_ARGS__)
+
+#define otr_notice(server,nick,formatnum,...) \
+ printformat(server,nick,MSGLEVEL_MSGS, formatnum, ## __VA_ARGS__)
+
+#define otr_infost(formatnum,...) \
+ printformat(NULL,NULL,MSGLEVEL_CRAP, formatnum, ## __VA_ARGS__)
+
+#define otr_info(server,nick,formatnum,...) \
+ printformat(server,nick,MSGLEVEL_CRAP, formatnum, ## __VA_ARGS__)
+
+#define otr_debug(server,nick,formatnum,...) { \
+ if (debug) \
+ printformat(server,nick, \
+ MSGLEVEL_MSGS, formatnum, ## __VA_ARGS__); \
+}
+#define IRCCTX_DUP(ircctx) g_memdup(ircctx,sizeof(IRC_CTX));
+#define IRCCTX_ADDR(ircctx) ircctx->address
+#define IRCCTX_NICK(ircctx) ircctx->nick
+#define IRCCTX_FREE(ircctx) g_free(ircctx)
--
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