From 11ca73b2ea558fb162f6f4f361a73e67a1fcc4ac Mon Sep 17 00:00:00 2001 From: TingPing Date: Sat, 13 Dec 2014 04:50:58 -0500 Subject: [PATCH 01/49] Port to libotr4 --- otr_ops.c | 39 ++++++++++++++++++++++++++++----------- otr_util.c | 51 ++++++++++++++++++--------------------------------- 2 files changed, 46 insertions(+), 44 deletions(-) diff --git a/otr_ops.c b/otr_ops.c index 78fea75..48e842f 100644 --- a/otr_ops.c +++ b/otr_ops.c @@ -109,6 +109,8 @@ void ops_inject_msg(void *opdata, const char *accountname, g_free(msgcopy); } + +#if 0 /* * OTR notification. Haven't seen one yet. */ @@ -129,6 +131,7 @@ void ops_notify(void *opdata, OtrlNotifyLevel level, const char *accountname, otr_notice(server,username,TXT_OPS_NOTIFY, title,primary,secondary); } +#endif #ifdef HAVE_GREGEX_H @@ -151,6 +154,29 @@ const char *convert_otr_msg(const char *msg) #endif +void ops_handle_msg(void *opdata, OtrlMessageEvent msg_event, + ConnContext *co, const char *msg, + gcry_error_t err) +{ + IRC_CTX *server = opdata; + struct co_info *coi; + + if (co) { + coi = co->app_data; + server = coi->ircctx; + } else + otr_notice(server, co->username, TXT_OPS_DISPLAY_BUG); + +#ifdef HAVE_GREGEX_H + msg = convert_otr_msg(msg); + otr_notice(server, co->username, TXT_OPS_DISPLAY, msg); + g_free((char*)msg); +#else + otr_notice(server, co->username, TXT_OPS_DISPLAY, msg); +#endif +} + +#if 0 /* * OTR message. E.g. "following has been transmitted in clear: ...". * We're trying to kill the ugly HTML. @@ -179,6 +205,7 @@ int ops_display_msg(void *opdata, const char *accountname, return 0; } +#endif /* * Gone secure. @@ -231,14 +258,6 @@ void ops_still_secure(void *opdata, ConnContext *context, int is_reply) TXT_OPS_STILL_NO_REPLY); } -/* - * OTR log message. IIRC heartbeats are of this category. - */ -void ops_log(void *opdata, const char *message) -{ -// otr_infost(TXT_OPS_LOG,message); -} - /* * Really critical with IRC. * Unfortunately, we can't tell our peer which size to use. @@ -284,12 +303,10 @@ void otr_initops() { otr_ops.policy = ops_policy; otr_ops.create_privkey = ops_create_privkey; otr_ops.inject_message = ops_inject_msg; - otr_ops.notify = ops_notify; - otr_ops.display_otr_message = ops_display_msg; + otr_ops.handle_msg_event = ops_handle_msg; otr_ops.gone_secure = ops_secure; otr_ops.gone_insecure = ops_insecure; otr_ops.still_secure = ops_still_secure; - otr_ops.log_message = ops_log; otr_ops.max_message_size = ops_max_msg; otr_ops.update_context_list = ops_up_ctx_list; otr_ops.write_fingerprints = ops_writefps; diff --git a/otr_util.c b/otr_util.c index 5ed5720..1b8c5e5 100644 --- a/otr_util.c +++ b/otr_util.c @@ -124,8 +124,9 @@ ConnContext *otr_getcontext(const char *accname,const char *nick, nick, accname, PROTOCOLID, + OTRL_INSTAG_BEST, create, - NULL, + FALSE, context_add_app_info, data); @@ -152,16 +153,24 @@ char *otr_send(IRC_CTX *ircctx, const char *msg,const char *to) sprintf(accname, "%s@%s", nick, address); + if (!(co = otr_getcontext(accname,to,FALSE,ircctx))) { + otr_notice(ircctx,to,TXT_SEND_CHANGE); + return NULL; + } + err = otrl_message_sending( otr_state, &otr_ops, ircctx, accname, PROTOCOLID, - to, - msg, - NULL, - &newmessage, + to, + OTRL_INSTAG_BEST, + msg, + NULL, + &newmessage, + OTRL_FRAGMENT_SEND_ALL, + &co, context_add_app_info, ircctx); @@ -173,26 +182,6 @@ char *otr_send(IRC_CTX *ircctx, const char *msg,const char *to) if (newmessage==NULL) return (char*)msg; - /* OTR message. Need to do fragmentation */ - - if (!(co = otr_getcontext(accname,to,FALSE,ircctx))) { - otr_notice(ircctx,to,TXT_SEND_CHANGE); - return NULL; - } - - err = otrl_message_fragment_and_send( - &otr_ops, - ircctx, - co, - newmessage, - OTRL_FRAGMENT_SEND_ALL, - NULL); - - if (err != 0) { - otr_notice(ircctx,to,TXT_SEND_FRAGMENT,msg); - } else - otr_debug(ircctx,to,TXT_SEND_CONVERTED,newmessage); - return NULL; } @@ -255,7 +244,6 @@ int otr_getstatus(char *mynick, char *nick, char *server) { ConnContext *co; char accname[128]; - struct co_info *coi; sprintf(accname, "%s@%s", mynick, server); @@ -263,8 +251,6 @@ int otr_getstatus(char *mynick, char *nick, char *server) return 0; } - coi = co->app_data; - switch (co->msgstate) { case OTRL_MSGSTATE_PLAINTEXT: return TXT_ST_PLAINTEXT; @@ -327,7 +313,7 @@ void otr_finish(IRC_CTX *ircctx, char *nick, const char *peername, int inquery) } otrl_message_disconnect(otr_state,&otr_ops,ircctx,accname, - PROTOCOLID,nick); + PROTOCOLID,nick,OTRL_INSTAG_BEST); if (inquery) { otr_info(ircctx,nick,TXT_CMD_FINISH,nick,IRCCTX_ADDR(ircctx)); @@ -361,7 +347,8 @@ void otr_finishall() otrl_message_disconnect(otr_state,&otr_ops,coi->ircctx, context->accountname, PROTOCOLID, - context->username); + context->username, + OTRL_INSTAG_BEST); otr_infost(TXT_CMD_FINISH,context->username, IRCCTX_ADDR(coi->ircctx)); @@ -653,7 +640,6 @@ char *otr_receive(IRC_CTX *ircctx, const char *msg,const char *from) int ignore_message; char *newmessage = NULL; char accname[256]; - char *lastmsg; ConnContext *co; struct co_info *coi; OtrlTLV *tlvs; @@ -682,8 +668,6 @@ char *otr_receive(IRC_CTX *ircctx, const char *msg,const char *from) * in the message but it doesn't end with a ".", queue it and wait * for the rest. */ - lastmsg = co->app_data; - if (coi->msgqueue) { /* already something in the queue */ strcpy(coi->msgqueue+strlen(coi->msgqueue),msg); @@ -723,6 +707,7 @@ char *otr_receive(IRC_CTX *ircctx, const char *msg,const char *from) msg, &newmessage, &tlvs, + &co, NULL, NULL); From 52be5df4029b7c14d5b13e256a2b289cdfe111ed Mon Sep 17 00:00:00 2001 From: TingPing Date: Sat, 13 Dec 2014 06:04:31 -0500 Subject: [PATCH 02/49] Switch to autotools and remove old files Still need to remove the formats and all mentions of irssi --- .gitignore | 62 +++- CMakeLists.txt | 285 ---------------- ChangeLog | 16 - HOWTO_PACKAGE | 17 - INSTALL | 33 -- Makefile.am | 5 + Packaging-DEB.cmake | 7 - Packaging-RPM.cmake | 23 -- Packaging.cmake | 42 --- README | 84 ----- README.hexchat | 9 - README.irssi-headers | 3 - README.md | 33 -- README.xchat | 9 - autogen.sh | 22 ++ cmake-extensions/COPYING-CMAKE-SCRIPTS | 22 -- cmake-extensions/FindLibGcrypt.cmake | 52 --- cmake-extensions/FindLibOTR.cmake | 49 --- cmake-extensions/Git.cmake | 20 -- cmake-extensions/cscope.cmake | 17 - configure.ac | 57 ++++ io-config.h.in | 3 - irssi_otr.c | 441 ------------------------- irssi_otr.h | 57 ---- mksrcpackage.sh | 37 --- src/Makefile.am | 11 + formats.txt => src/formats.txt | 0 src/hexchat-formats.c | 112 +++++++ xchat_otr.c => src/hexchat_otr.c | 17 +- xchat_otr.h => src/hexchat_otr.h | 7 +- makeformats.py => src/makeformats.py | 2 +- src/otr-formats.h | 104 ++++++ otr.h => src/otr.h | 17 +- otr_key.c => src/otr_key.c | 0 otr_ops.c => src/otr_ops.c | 39 --- otr_util.c => src/otr_util.c | 11 +- tarballdefs.cmake | 2 - 37 files changed, 377 insertions(+), 1350 deletions(-) delete mode 100644 CMakeLists.txt delete mode 100644 ChangeLog delete mode 100644 HOWTO_PACKAGE delete mode 100644 INSTALL create mode 100644 Makefile.am delete mode 100644 Packaging-DEB.cmake delete mode 100644 Packaging-RPM.cmake delete mode 100644 Packaging.cmake delete mode 100644 README delete mode 100644 README.hexchat delete mode 100644 README.irssi-headers delete mode 100644 README.md delete mode 100644 README.xchat create mode 100755 autogen.sh delete mode 100644 cmake-extensions/COPYING-CMAKE-SCRIPTS delete mode 100644 cmake-extensions/FindLibGcrypt.cmake delete mode 100644 cmake-extensions/FindLibOTR.cmake delete mode 100644 cmake-extensions/Git.cmake delete mode 100644 cmake-extensions/cscope.cmake create mode 100644 configure.ac delete mode 100644 io-config.h.in delete mode 100644 irssi_otr.c delete mode 100644 irssi_otr.h delete mode 100755 mksrcpackage.sh create mode 100644 src/Makefile.am rename formats.txt => src/formats.txt (100%) create mode 100644 src/hexchat-formats.c rename xchat_otr.c => src/hexchat_otr.c (96%) rename xchat_otr.h => src/hexchat_otr.h (93%) rename makeformats.py => src/makeformats.py (98%) create mode 100644 src/otr-formats.h rename otr.h => src/otr.h (95%) rename otr_key.c => src/otr_key.c (100%) rename otr_ops.c => src/otr_ops.c (89%) rename otr_util.c => src/otr_util.c (99%) delete mode 100644 tarballdefs.cmake diff --git a/.gitignore b/.gitignore index 886bc2e..819d806 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,57 @@ +# C *.o +*.ko +*.obj +*.elf +*.gch +*.pch +*.lib +*.a +*.la +*.lo +*.dll *.so -term.h -statusbar.h -mainwindows.h -.exrc -*.swp -cscope.files -cscope.out +*.so.* +*.dylib +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex +*.tar.xz + +# Autotools +/autom4te.cache +/aclocal.m4 +/ar-lib +/compile +/configure +/depcomp +/install-sh +/ltmain.sh +/missing +/libtool +/test-driver +/config.* +/test/test-suite.log +.deps/ +.libs/ +stamp-h1 +stamp-it +Makefile +Makefile.in +Makefile.in.in + +# Gettext +/po/POTFILES +/po/.intltool-merge-cache +*.mo +*.gmo +*.pot + +# Misc +*~ +*.patch +*.diff + diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index 9a1a0a7..0000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,285 +0,0 @@ -# -# Off-the-Record Messaging (OTR) module for the irssi IRC client -# Copyright (C) 2008 Uli Meis -# -# 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 -# - -PROJECT(irssi-otr) - -CMAKE_MINIMUM_REQUIRED(VERSION 2.4) -IF(COMMAND cmake_policy) - cmake_policy(SET CMP0003 NEW) -ENDIF(COMMAND cmake_policy) - -SET(CMAKE_MODULE_PATH - ${PROJECT_SOURCE_DIR}/cmake-extensions/ - ${PROJECT_BINARY_DIR}) - -INCLUDE(cmake-extensions/cscope.cmake) -INCLUDE(cmake-extensions/Git.cmake) -INCLUDE(CheckFunctionExists) -INCLUDE(CheckIncludeFile) -INCLUDE(CheckIncludeFiles) -INCLUDE(tarballdefs.cmake OPTIONAL) - -# get version from git - -IF(NOT IRSSIOTR_VERSION) - IF(NOT EXISTS "${PROJECT_SOURCE_DIR}/.git") - MESSAGE(FATAL_ERROR "Cannot determine the irssi-otr version since this is " - "not a git checkout. Please set IRSSIOTR_VERSION, e.g. - cmake -DIRSSIOTR_VERSION=mydistro-0.1 - or - cmake -DIRSSIOTR_VERSION=mydistro-git-") - ENDIF(NOT EXISTS "${PROJECT_SOURCE_DIR}/.git") - FIND_GIT_TAGORCOMMIT(${PROJECT_SOURCE_DIR} IRSSIOTR_VERSION) - IF(NOT IRSSIOTR_VERSION) - MESSAGE(FATAL_ERROR - "Couldn't determine version. Please run cmake -DIRSSIOTR_VERSION=...") - ENDIF(NOT IRSSIOTR_VERSION) -ENDIF(NOT IRSSIOTR_VERSION) - -MESSAGE(STATUS "Building irssi-otr version ${IRSSIOTR_VERSION}") - -# PkgConfig. Only available since 2.4.7, fetch if unavailable so people with -# older cmake can run this - -FIND_PACKAGE(PkgConfig QUIET) - -IF(NOT PKG_CONFIG_FOUND) - MESSAGE(STATUS "Couldn't find the pkg-config cmake module. Seems you're - running cmake < 2.4.7. Will try to fetch the module from 2.4.7...") - FIND_PACKAGE(Wget REQUIRED) - EXECUTE_PROCESS(COMMAND "bash" "-c" - "${WGET_EXECUTABLE} '-O' '-' \\ - 'http://www.cmake.org/files/v2.4/cmake-2.4.7.tar.gz' | \\ - tar xz cmake-2.4.7/Modules/FindPkgConfig.cmake && \\ - mv cmake-2.4.7/Modules/FindPkgConfig.cmake . && \\ - rmdir -p cmake-2.4.7/Modules" - RESULT_VARIABLE PKGCONF_RET) - IF(NOT PKGCONF_RET EQUAL 0) - MESSAGE(FATAL_ERROR "Couldnt download cmake module for pkg-config") - ENDIF(NOT PKGCONF_RET EQUAL 0) - FIND_PACKAGE(PkgConfig REQUIRED) -ENDIF(NOT PKG_CONFIG_FOUND) - -# GLIB - -pkg_check_modules(GLIB REQUIRED glib-2.0) - -# Python - -FIND_PACKAGE(PythonInterp) -IF(NOT PYTHON_EXECUTABLE) - MESSAGE(FATAL_ERROR "Couldn't find a python interpreter") -ENDIF(NOT PYTHON_EXECUTABLE) - -# LIBOTR - -FIND_PACKAGE(LibOTR REQUIRED) -IF (LIBOTR_VERSION LESS "3.1.0") - MESSAGE(FATAL_ERROR "Need libotr version >= 3.1.0 (fragmentation)") -ENDIF (LIBOTR_VERSION LESS "3.1.0") - -# LIBGCRYPT. A dependency of libotr and therefore one of ours. - -FIND_PACKAGE(LibGcrypt REQUIRED) - -# includes - -SET(IRSSIOTR_INCLUDE_DIRS - ${PROJECT_SOURCE_DIR} - ${PROJECT_BINARY_DIR} - ${GLIB_INCLUDE_DIRS} - ${LIBOTR_INCLUDE_DIRS}) - -SET(CMAKE_REQUIRED_INCLUDES ${IRSSIOTR_INCLUDE_DIRS}) -SET(CMAKE_REQUIRED_DEFINITIONS -DHAVE_CONFIG_H ${LIBGCRYPT_CFLAGS}) - -# irssi public headers - -FIND_PATH(IRSSI_INCLUDE_DIR NAMES irssi/src/core/module.h) -MARK_AS_ADVANCED(IRSSI_INCLUDE_DIR) - -IF(NOT IRSSI_INCLUDE_DIR) - MESSAGE(STATUS "*** no irssi found ***") -ELSEIF(BUILDFOR AND NOT BUILDFOR STREQUAL "irssi") - MESSAGE(STATUS "*** not building for irssi ***") -ELSE(NOT IRSSI_INCLUDE_DIR) - MESSAGE(STATUS "*** building for irssi ***") - SET(HAVE_IRSSI 1) - SET(IRSSIOTR_INCLUDE_DIRS - ${IRSSIOTR_INCLUDE_DIRS} - ${IRSSI_INCLUDE_DIR}/irssi - ${IRSSI_INCLUDE_DIR}/irssi/src - ${IRSSI_INCLUDE_DIR}/irssi/src/core - ${PROJECT_BINARY_DIR}/irssi-headers - ${PROJECT_SOURCE_DIR}/irssi-headers) - - SET(CMAKE_REQUIRED_INCLUDES ${IRSSIOTR_INCLUDE_DIRS}) - - # irssi statusbar header - - CHECK_INCLUDE_FILES("glib.h;common.h;fe-text/statusbar-item.h" HAVE_IRSSISBAR_H) - - # Bad hack - - IF (NOT HAVE_IRSSISBAR_H) - MESSAGE(STATUS "Need to fetch irssi header statusbar-item.h (you don't have it yet)") - IF (NOT WGET_EXECUTABLE) - FIND_PACKAGE(Wget REQUIRED) - ENDIF (NOT WGET_EXECUTABLE) - EXECUTE_PROCESS(COMMAND "mkdir" -p irssi-headers/fe-text) - EXECUTE_PROCESS(COMMAND "bash" "-c" - "${WGET_EXECUTABLE} '--post-data=revision=4936&root=irssi' \\ - 'http://svn.irssi.org/cgi-bin/viewvc.cgi/irssi/trunk/src/fe-text/statusbar-item.h' || exit 1" - ${PROJECT_SOURCE_DIR} WORKING_DIRECTORY irssi-headers/fe-text - RESULT_VARIABLE IISBAR_RET) - IF(NOT IISBAR_RET EQUAL 0) - MESSAGE(FATAL_ERROR "Couldn't check out irssi headers from SVN") - ENDIF(NOT IISBAR_RET EQUAL 0) - SET(HAVE_IRSSISBAR_H 1 CACHE INTERNAL "Having irssi headers" FORCE) - ENDIF (NOT HAVE_IRSSISBAR_H) - -ENDIF(NOT IRSSI_INCLUDE_DIR) - -FIND_PATH(HEXCHAT_INCLUDE_DIR NAMES hexchat-plugin.h) -MARK_AS_ADVANCED(HEXCHAT_INCLUDE_DIR) - -IF(NOT HEXCHAT_INCLUDE_DIR) - MESSAGE(STATUS "*** no hexchat found ***") -ELSEIF(BUILDFOR AND NOT BUILDFOR STREQUAL "xchat") - MESSAGE(STATUS "*** not building for hexchat ***") -ELSE(NOT HEXCHAT_INCLUDE_DIR) - MESSAGE(STATUS "*** building for hexchat ***") - SET(HAVE_HEXCHAT 1) - SET(IRSSIOTR_INCLUDE_DIRS - ${IRSSIOTR_INCLUDE_DIRS} - ${HEXCHAT_INCLUDE_DIR}) -ENDIF(NOT HEXCHAT_INCLUDE_DIR) - -include_directories(${IRSSIOTR_INCLUDE_DIRS}) - -# gregex.h -# available since 2.13 AFAIK -# optional for html stripping and nick ignoring - -FIND_PATH(GREGEX_FILE "glib/gregex.h" ${GLIB_INCLUDE_DIRS} NO_DEFAULT_PATH) -IF(GREGEX_FILE) - CHECK_INCLUDE_FILE("glib.h" HAVE_GREGEX_H) -ELSE() - MESSAGE(FATAL_ERROR "gregex.h not found") -ENDIF() - -# check for strsignal - -CHECK_FUNCTION_EXISTS(strsignal HAVE_STRSIGNAL) - -# generate io-config.h - -CONFIGURE_FILE(io-config.h.in io-config.h) - -# defs - -IF(NOT CMAKE_BUILD_TYPE) - SET(CMAKE_BUILD_TYPE debug) -ENDIF(NOT CMAKE_BUILD_TYPE) -SET(CMAKE_C_FLAGS_DEBUG -g) - -MESSAGE(STATUS "This is a ${CMAKE_BUILD_TYPE} build") - -ADD_DEFINITIONS(-DHAVE_CONFIG_H -Wall ${LIBGCRYPT_CFLAGS}) - -# docdir - -IF(NOT DOCDIR) - SET(DOCDIR share/doc/${CMAKE_PROJECT_NAME}) -ENDIF(NOT DOCDIR) - -# generate otr-formats.{c,h} - -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} - ${PROJECT_SOURCE_DIR}/makeformats.py - ${PROJECT_SOURCE_DIR}/formats.txt - ${PROJECT_SOURCE_DIR}/README - ) - -# lib - -# Now that took some time to figure out... - -IF(APPLE) - SET(APPLE_LDFLAGS "-single_module -undefined dynamic_lookup") -ENDIF(APPLE) - -FOREACH(X ${LIBGCRYPT_LDFLAGS} ${GLIB_LDFLAGS} ${APPLE_LDFLAGS}) - SET(MAIN_LDFLAGS "${MAIN_LDFLAGS} ${X}") -ENDFOREACH(X ${LIBGCRYPT_LDFLAGS} ${GLIB_LDFLAGS} ${APPLE_LDFLAGS}) - -IF(HAVE_IRSSI) - ADD_LIBRARY(irssiotr SHARED irssi_otr.c otr_util.c otr_ops.c otr_key.c ${PROJECT_BINARY_DIR}/otr-formats.c) - TARGET_LINK_LIBRARIES(irssiotr ${GLIB_LIBRARIES} ${LIBOTR_LIBRARIES}) - SET_TARGET_PROPERTIES(irssiotr PROPERTIES - COMPILE_FLAGS -DTARGET_IRSSI - OUTPUT_NAME "otr" - LINK_FLAGS "${MAIN_LDFLAGS}") - IF(APPLE) - SET_TARGET_PROPERTIES(irssiotr PROPERTIES SUFFIX ".so") - ENDIF(APPLE) -ENDIF(HAVE_IRSSI) - -IF(HAVE_HEXCHAT) - ADD_LIBRARY(hexchatotr SHARED xchat_otr.c otr_util.c otr_ops.c otr_key.c ${PROJECT_BINARY_DIR}/xchat-formats.c) - TARGET_LINK_LIBRARIES(hexchatotr ${GLIB_LIBRARIES} ${LIBOTR_LIBRARIES}) - SET_TARGET_PROPERTIES(hexchatotr PROPERTIES - COMPILE_FLAGS -DTARGET_XCHAT - OUTPUT_NAME "hexchatotr" - LINK_FLAGS "${MAIN_LDFLAGS}") - IF(APPLE) - SET_TARGET_PROPERTIES(hexchatotr PROPERTIES SUFFIX ".so") - ENDIF(APPLE) -ENDIF(HAVE_HEXCHAT) - -# cscope - -FILE(GLOB CSANDHS *.c *.h) -ADD_CSCOPE_TARGET("${CSANDHS}" "${IRSSIOTR_INCLUDE_DIRS}") - -# Install / CPack - -IF(CMAKE_INSTALL_TYPE MATCHES "package-.*") - INCLUDE(Packaging.cmake) -ELSEIF(CMAKE_INSTALL_TYPE MATCHES "home") - INSTALL(TARGETS irssiotr DESTINATION "$ENV{HOME}/.irssi/modules") -ELSE(CMAKE_INSTALL_TYPE MATCHES "package-.*") - IF(HAVE_IRSSI) - INSTALL(TARGETS irssiotr DESTINATION lib${LIB_SUFFIX}/irssi/modules) - ENDIF(HAVE_IRSSI) - IF(HAVE_HEXCHAT) - INSTALL(TARGETS hexchatotr DESTINATION lib${LIB_SUFFIX}/hexchat/plugins) - ENDIF(HAVE_HEXCHAT) - INSTALL(FILES README LICENSE DESTINATION ${DOCDIR}) -ENDIF(CMAKE_INSTALL_TYPE MATCHES "package-.*") - -# Source tarball -ADD_CUSTOM_TARGET(src-tarball - ${PROJECT_SOURCE_DIR}/mksrcpackage.sh ${PROJECT_SOURCE_DIR} - ${IRSSIOTR_VERSION}) diff --git a/ChangeLog b/ChangeLog deleted file mode 100644 index 46b0eb8..0000000 --- a/ChangeLog +++ /dev/null @@ -1,16 +0,0 @@ -Version 0.3 - * create queries for OTR messages if otr_createqueries is set - * finish conversations on unload unless otr_finishonunload is off - * added settings otr_policy, otr_policy_known and otr_ignore - * fixed two segfault sources - * key generation now operates on a temp file - * the .irssi/otr dir now gets created with mode 700 - * commands now take an optional nick@server argument - (for single message window users) - * changed loglevel of otr_log (heartbeats) and otr_finish - * moved to the new public statusbar-item.h header - -Version 0.2 - - * fixed multiple server problem. - * fixed fragmentation problem (seen with pidgin over IRC). diff --git a/HOWTO_PACKAGE b/HOWTO_PACKAGE deleted file mode 100644 index 90334d5..0000000 --- a/HOWTO_PACKAGE +++ /dev/null @@ -1,17 +0,0 @@ -You can let cmake generate a package for you. But don't expect it to be in -full conformance with your distribution. - -You'll need cmake >= 2.6. In theory, all you should have to do is: - - $ cmake -DCMAKE_INSTALL_TYPE=package-deb /path/to/src - $ sudo make package - -For an RPM it should be package-rpm and for TGZ...you can imagine. - -I'm not sure yet if the RPMs/DEBs generated by cmake/CPack are 100% OK. You can -tweak the settings in Packaging-{RPM,DEB}.cmake. If you wanna see how CPack does -it and what variables affect it, check out: - - /usr/share/cmake/Modules/CPackDeb.cmake - /usr/share/cmake/Modules/CPackRPM.cmake - diff --git a/INSTALL b/INSTALL deleted file mode 100644 index 2cc0bd8..0000000 --- a/INSTALL +++ /dev/null @@ -1,33 +0,0 @@ ----------- INSTALL ---------- - -Usually the following will do: - - $ cmake /path/to/src - $ make - $ sudo make install - -If you want to install libotr.so into your home folder -(~/.irssi/modules/libotr.so) run - - $ cmake -DCMAKE_INSTALL_TYPE=home /path/to/src - -instead. - ----------- RUNTIME DEPENDENCIES ---------- - -* libotr >= 3.1.0. Fragmentation has been introduced in that version so - nothing smaller will work. - -* glib. Will work with < 2.13 but since there are no regexes available - HTML stripping (OTR spits out HTML sometimes) and nick ignoring and - setting otr_policy won't work. - -* irssi. Obviously ;) - ----------- BUILD-TIME ONLY DEPENDENCIES ---------- - -* cmake. Sry for that, but I'm not an autofoo fan. If you're running - < cmake-2.4.7 then configure will try to download a missing module - (pkgconfig) from the cmake-2.4.7 sources. Should work. - -* pkg-config, python and wget. diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..06b84a8 --- /dev/null +++ b/Makefile.am @@ -0,0 +1,5 @@ +ACLOCAL_AMFLAGS = -I m4 + +SUBDIRS = src + +EXTRA_DIST = autogen.sh LICENSE diff --git a/Packaging-DEB.cmake b/Packaging-DEB.cmake deleted file mode 100644 index 88cd52f..0000000 --- a/Packaging-DEB.cmake +++ /dev/null @@ -1,7 +0,0 @@ -INSTALL(TARGETS irssiotr DESTINATION lib${LIB_SUFFIX}/irssi/modules) -INSTALL(FILES README LICENSE DESTINATION ${DOCDIR}) - -SET(CPACK_GENERATOR DEB) -#SET(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64") -SET(CPACK_DEBIAN_PACKAGE_SECTION "net") -SET(CPACK_DEBIAN_PACKAGE_DEPENDS "irssi, libotr2 (>= 3.1.0)") diff --git a/Packaging-RPM.cmake b/Packaging-RPM.cmake deleted file mode 100644 index d560e81..0000000 --- a/Packaging-RPM.cmake +++ /dev/null @@ -1,23 +0,0 @@ -INSTALL(TARGETS irssiotr DESTINATION lib${LIB_SUFFIX}/irssi/modules) -INSTALL(FILES README DESTINATION ${DOCDIR}) - -SET(CPACK_GENERATOR RPM) -SET(CPACK_RPM_PACKAGE_DEBUG) -SET(CPACK_RPM_PACKAGE_LICENSE "GPLv2") -SET(CPACK_RPM_PACKAGE_DESCRIPTION ${CPACK_PACKAGE_DESCRIPTION_SUMMARY}) - -EXECUTE_PROCESS(COMMAND bash -c - "ARCH=`which arch` && $ARCH | tr -d '\n'" - OUTPUT_VARIABLE CPACK_RPM_PACKAGE_ARCHITECTURE) - -#IF(CMAKE_SIZEOF_VOID_P EQUAL 8) -# SET(CPACK_RPM_PACKAGE_ARCHITECTURE i386) -#ELSE -# SET(CPACK_RPM_PACKAGE_ARCHITECTURE i386) -#ENDIF(CMAKE_SIZEOF_VOID_P EQUAL 8) - -SET(CPACK_RPM_PACKAGE_RELEASE 1) -SET(CPACK_RPM_PACKAGE_GROUP "unknown") -SET(CPACK_RPM_FILE_NAME - ${CPACK_PACKAGE_FILE_NAME}-${CPACK_RPM_PACKAGE_RELEASE}.${CPACK_RPM_PACKAGE_ARCHITECTURE}) -SET(CPACK_PACKAGE_FILE_NAME ${CPACK_RPM_FILE_NAME}) diff --git a/Packaging.cmake b/Packaging.cmake deleted file mode 100644 index 3dfea56..0000000 --- a/Packaging.cmake +++ /dev/null @@ -1,42 +0,0 @@ -SET(CPACK_PACKAGE_CONTACT "Ulim ") -SET(CPACK_PACKAGE_VENDOR ${CPACK_PACKAGE_CONTACT}) - -SET(CPACK_RESOURCE_FILE_LICENSE ${PROJECT_SOURCE_DIR}/LICENSE) -SET(CPACK_RESOURCE_FILE_README ${PROJECT_SOURCE_DIR}/README) - -SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY - "Off-The-Record Messaging (OTR) for irssi") - -SET(CPACK_PACKAGE_FILE_NAME - ${CMAKE_PROJECT_NAME}-${IRSSIOTR_VERSION}) - -SET(CPACK_GENERATOR TGZ) - -SET(CPACK_PACKAGE_VERSION ${IRSSIOTR_VERSION}) - -IF(CMAKE_INSTALL_TYPE STREQUAL "package-rpm") - CMAKE_MINIMUM_REQUIRED(VERSION 2.6) - INCLUDE(Packaging-RPM.cmake) -ELSEIF(CMAKE_INSTALL_TYPE STREQUAL "package-deb") - CMAKE_MINIMUM_REQUIRED(VERSION 2.6) - INCLUDE(Packaging-DEB.cmake) -ELSEIF(CMAKE_INSTALL_TYPE STREQUAL "package-tgz") - INSTALL(TARGETS irssiotr DESTINATION irssi/lib/modules) - INSTALL(FILES README LICENSE DESTINATION ${DOCDIR}) -ELSE(CMAKE_INSTALL_TYPE STREQUAL "package-rpm") - MESSAGE(FATAL_ERROR "Unknown build type '${CMAKE_INSTALL_TYPE}'") -ENDIF(CMAKE_INSTALL_TYPE STREQUAL "package-rpm") - - - -#ENDIF(CMAKE_INSTALL_TYPE STREQUAL "package-tgz") -#ENDIF(CMAKE_INSTALL_TYPE STREQUAL "package-deb") - -#SET(CPACK_PACKAGE_DESCRIPTION_FILE ${PROJECT_SOURCE_DIR}/README) -#SET(CPACK_PACKAGE_VERSION_MAJOR "0") -#SET(CPACK_PACKAGE_VERSION_MINOR "1") -#SET(CPACK_PACKAGE_VERSION_PATCH "0") -#SET(CPACK_PACKAGE_FILE_NAME -# ${CMAKE_PROJECT_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}) - -INCLUDE(CPack) diff --git a/README b/README deleted file mode 100644 index 394d891..0000000 --- a/README +++ /dev/null @@ -1,84 +0,0 @@ -Quick start: Do "/load otr", write "?OTR?" to your OTR buddy, wait until the now -ongoing key generation finishs and write "?OTR?" again. You should "go secure". - -Key generation happens in a seperate process and its duration mainly depends on -the available entropy. On my desktop it takes about 6 Minutes, about 2 Minutes -if I run "du /" in parallel and on an idle server system it can even take an -hour. - -The default OTR policy of irssi-otr is now something between manual and -opportunistic. Manual means you have to start it yourself by issueing "?OTR?", -opportunistic means both peers send some magic whitespace and start OTR once -they receive this whitespace from the other side. irssi-otr uses a mode in -between where we are not sending whitespace as an announcement (as in -opportunistic) but we still handle whitespace if we see it from the other side -(I'm calling it handlews). Therefore if your peer uses opportunistic the -handshake should still start automatically once he writes something. - -You can now set the OTR policy per peer via the otr_policy /setting. It's a -comma seperated list of "@ " pairs where @ -is interpreted as a glob pattern, i.e. you can use wildcard "*" and joker "?" as -you would in a shell. The policy can be one of never, manual, handlews (the -default), opportunistic, and always. Be aware that the opportunistic policy -fails with some IRC servers since they strip off the whitespace. The always -policy has the nice side effect that the first line you type will already be -encrypted. - -If a fingerprint can be found for someone, i.e. someone you had an OTR -conversation with before, then the otr_policy_known setting applies after -otr_policy. It has the same syntax. The default is "* always", i.e. enforce OTR -with anyone you've used OTR with before. - -Should you finish an OTR session via "/otr finish" and should the active policy -be always or opportunistic then it will be temporarily set back to handlews. -Otherwise OTR would start again right away which is probably not what you want. -This is however reset once you close the query window. - -To make sure that you are actually talking to your buddy, you can agree on a -secret somehow and then one does "/otr auth ". Shortly afterwards the -other one will be asked to do the same and you're done. The traditional -alternative, comparing fingerprints over a secure line, can also be used. Use -"/otr trust" once you're sure they match. - -I also strongly recommend to do "/statusbar window add otr" so you're informed -about what's going on. - -In "~/.irssi/otr/otr.{key,fp}" you'll find the fingerprints and your private -keys(should you at any point be interested). - -Commands: - -/otr genkey nick@irc.server.com - Manually generate a key for the given account(also done on demand) -/otr auth [@] - Initiate or respond to an authentication challenge -/otr authabort [@] - Abort any ongoing authentication -/otr trust [@] - Trust the fingerprint of the user in the current window. - You should only do this after comparing fingerprints over a secure line -/otr debug - Switch debug mode on/off -/otr contexts - List all OTR contexts along with their fingerprints and status -/otr finish [@] - Finish an OTR conversation -/otr version - Display irssi-otr version. Might be a git commit - -Settings: - -otr_policy - Comma-separated list of "@ " pairs. See comments - above. -otr_policy_known - Same syntax as otr_policy. Only applied where a fingerprint is - available. -otr_ignore - Conversations with nicks that match this regular expression completely - bypass libotr. It is very unlikely that you need to touch this setting, - just use the OTR policy never to prevent OTR sessions with some nicks. -otr_finishonunload - If true running OTR sessions are finished on /unload and /quit. -otr_createqueries - If true queries are automatically created for OTR log messages. diff --git a/README.hexchat b/README.hexchat deleted file mode 100644 index 69d90af..0000000 --- a/README.hexchat +++ /dev/null @@ -1,9 +0,0 @@ -The README file is written for irssi but what's said there mostly applies to -Hexchat as well. The only difference is that Hexchat doesn't support -adding /settings, so in order to see and change the current settings you'll have -to use the "/otr set" command. Without arguments it will show the current -settings and if supplied with a setting name and a value it will change the -given setting. There is no persistence, i.e. each time you start Hexchat the -hardcoded defaults will be active. Please use standard Hexchat scripting magic -to change the defaults to your liking on startup. It seems overkill to have a -config parser/writer just for this plugin and it is fortunately not neccessary. diff --git a/README.irssi-headers b/README.irssi-headers deleted file mode 100644 index 2d7c9d7..0000000 --- a/README.irssi-headers +++ /dev/null @@ -1,3 +0,0 @@ -statusbar-item.h is an irssi header; -hence it is licensed under the same license as irssi (GPLv2). -If you want to know why it is here, check out irssi FS#535. diff --git a/README.md b/README.md deleted file mode 100644 index bd77718..0000000 --- a/README.md +++ /dev/null @@ -1,33 +0,0 @@ - -This is the XChat OTR plugin ported to Hexchat along with several bug fixes. - -It depends on libotr 3.2.1 which is no longer available in Debian Testing and -Ubuntu 14.04. You can download it from here - - https://otr.cypherpunks.ca/libotr-3.2.1.tar.gz - -If the link above doesn't work, you can clone it from my archive - - git clone https://github.com/adhux/libotr-3.2.1.git - -and install it with the following commands - - sudo apt-get install libgcrypt11-dev - cd libotr-3.2.1 - ./configure - make - sudo make install - -Then install hexchat-otr with these commands - - sudo apt-get install cmake libglib2.0-dev build-essential - git clone https://github.com/adhux/hexchat-otr.git - cd hexchat-otr - cmake . - make - cp libhexchatotr.so ~/.config/hexchat/addons/ - - -Future plans: fix the /me bug and add libotr 4.0.0 support. - - diff --git a/README.xchat b/README.xchat deleted file mode 100644 index e55029f..0000000 --- a/README.xchat +++ /dev/null @@ -1,9 +0,0 @@ -The README file is written for irssi but what's said there mostly applies to -xchat as well. The only difference is that xchat doesn't support adding -/settings, so in order to see and change the current settings you'll have to use -the "/otr set" command. Without arguments it will show the current settings and -if supplied with a setting name and a value it will change the given setting. -There is no persistence, i.e. each time you start xchat the hardcoded defaults -will be active. Please use standard xchat scripting magic to change the defaults -to your liking on startup. It seems overkill to have a config parser/writer just -for this plugin and it is fortunately not neccessary. diff --git a/autogen.sh b/autogen.sh new file mode 100755 index 0000000..6ae1ce2 --- /dev/null +++ b/autogen.sh @@ -0,0 +1,22 @@ +#!/bin/sh +# Run this to generate all the initial makefiles, etc. + +srcdir=`dirname $0` +test -z "$srcdir" && srcdir=. + +PKG_NAME="hexchat-otr" + +(test -f $srcdir/src/otr.h) || { + echo -n "**Error**: Directory "\`$srcdir\'" does not look like the" + echo " top-level $PKG_NAME directory" + exit 1 +} + +which gnome-autogen.sh || { + echo "You need to install gnome-common" + exit 1 +} + +. gnome-autogen.sh + +rm -rf autom4te.cache diff --git a/cmake-extensions/COPYING-CMAKE-SCRIPTS b/cmake-extensions/COPYING-CMAKE-SCRIPTS deleted file mode 100644 index 4b41776..0000000 --- a/cmake-extensions/COPYING-CMAKE-SCRIPTS +++ /dev/null @@ -1,22 +0,0 @@ -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: - -1. Redistributions of source code must retain the copyright - notice, this list of conditions and the following disclaimer. -2. Redistributions in binary form must reproduce the copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. -3. The name of the author may not be used to endorse or promote products - derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/cmake-extensions/FindLibGcrypt.cmake b/cmake-extensions/FindLibGcrypt.cmake deleted file mode 100644 index 9e5a245..0000000 --- a/cmake-extensions/FindLibGcrypt.cmake +++ /dev/null @@ -1,52 +0,0 @@ -# This is from KDE SVN, I just changed LIBGCRYPT_LIBRARIES to LIBGCRYPT_LDFLAGS -# cause that's what it is at least on my system - Uli - -# - Try to find the Gcrypt library -# Once run this will define -# -# LIBGCRYPT_FOUND - set if the system has the gcrypt library -# LIBGCRYPT_CFLAGS - the required gcrypt compilation flags -# LIBGCRYPT_LDFLAGS - the linker libraries needed to use the gcrypt library -# -# Copyright (c) 2006 Brad Hards -# -# Redistribution and use is allowed according to the terms of the BSD license. -# For details see the accompanying COPYING-CMAKE-SCRIPTS file. - -# libgcrypt is moving to pkg-config, but earlier version don't have it - -#search in typical paths for libgcrypt-config -FIND_PROGRAM(LIBGCRYPTCONFIG_EXECUTABLE NAMES libgcrypt-config) - -#reset variables -set(LIBGCRYPT_LDFLAGS) -set(LIBGCRYPT_CFLAGS) - -# if libgcrypt-config has been found -IF(LIBGCRYPTCONFIG_EXECUTABLE) - - EXEC_PROGRAM(${LIBGCRYPTCONFIG_EXECUTABLE} ARGS --libs RETURN_VALUE _return_VALUE OUTPUT_VARIABLE LIBGCRYPT_LDFLAGS) - - EXEC_PROGRAM(${LIBGCRYPTCONFIG_EXECUTABLE} ARGS --cflags RETURN_VALUE _return_VALUE OUTPUT_VARIABLE LIBGCRYPT_CFLAGS) - - IF(${LIBGCRYPT_CFLAGS} MATCHES "\n") - SET(LIBGCRYPT_CFLAGS " ") - ENDIF(${LIBGCRYPT_CFLAGS} MATCHES "\n") - - IF(LIBGCRYPT_LDFLAGS AND LIBGCRYPT_CFLAGS) - SET(LIBGCRYPT_FOUND TRUE) - ENDIF(LIBGCRYPT_LDFLAGS AND LIBGCRYPT_CFLAGS) - -ENDIF(LIBGCRYPTCONFIG_EXECUTABLE) - -if (LIBGCRYPT_FOUND) - if (NOT LibGcrypt_FIND_QUIETLY) - message(STATUS "Found libgcrypt: ${LIBGCRYPT_LDFLAGS}") - endif (NOT LibGcrypt_FIND_QUIETLY) -else (LIBGCRYPT_FOUND) - if (LibGcrypt_FIND_REQUIRED) - message(FATAL_ERROR "Could not find libgcrypt libraries") - endif (LibGcrypt_FIND_REQUIRED) -endif (LIBGCRYPT_FOUND) - -MARK_AS_ADVANCED(LIBGCRYPT_CFLAGS LIBGCRYPT_LDFLAGS) diff --git a/cmake-extensions/FindLibOTR.cmake b/cmake-extensions/FindLibOTR.cmake deleted file mode 100644 index 63624c9..0000000 --- a/cmake-extensions/FindLibOTR.cmake +++ /dev/null @@ -1,49 +0,0 @@ -# -# Uli Meis -# -# Mostly taken from cmake findcurl, version stuff from kopete -# -# - Find libotr -# Find the libotr headers and library. -# -# LIBOTR_INCLUDE_DIR -# LIBOTR_LIBRARIES -# LIBOTR_FOUND - -# Look for the header file. -FIND_PATH(LIBOTR_INCLUDE_DIR NAMES libotr/version.h) -MARK_AS_ADVANCED(LIBOTR_INCLUDE_DIR) - -# Look for the library. -FIND_LIBRARY(LIBOTR_LIBRARY NAMES otr) -MARK_AS_ADVANCED(LIBOTR_LIBRARY) - -# Copy the results to the output variables. -IF(LIBOTR_INCLUDE_DIR AND LIBOTR_LIBRARY) - SET(LIBOTR_FOUND 1) - SET(LIBOTR_LIBRARIES ${LIBOTR_LIBRARY}) - SET(LIBOTR_INCLUDE_DIRS ${LIBOTR_INCLUDE_DIR}) - EXECUTE_PROCESS(COMMAND grep "OTRL_VERSION" - "${LIBOTR_INCLUDE_DIR}/libotr/version.h" OUTPUT_VARIABLE output) - STRING(REGEX MATCH "OTRL_VERSION \"[0-9]+\\.[0-9]+\\.[0-9]+" - LIBOTR_VERSION "${output}") - STRING(REGEX REPLACE "^OTRL_VERSION \"" "" LIBOTR_VERSION "${LIBOTR_VERSION}") - MESSAGE(STATUS " found libotr, version ${LIBOTR_VERSION}" ) -ELSE(LIBOTR_INCLUDE_DIR AND LIBOTR_LIBRARY) - SET(LIBOTR_FOUND 0) - SET(LIBOTR_LIBRARIES) - SET(LIBOTR_INCLUDE_DIRS) -ENDIF(LIBOTR_INCLUDE_DIR AND LIBOTR_LIBRARY) - -# Report the results. -IF(NOT LIBOTR_FOUND) - SET(LIBOTR_DIR_MESSAGE - "LIBOTR was not found. Make sure LIBOTR_LIBRARY and LIBOTR_INCLUDE_DIR are set.") - IF(NOT LIBOTR_FIND_QUIETLY) - MESSAGE(STATUS "${LIBOTR_DIR_MESSAGE}") - ELSE(NOT LIBOTR_FIND_QUIETLY) - IF(LIBOTR_FIND_REQUIRED) - MESSAGE(FATAL_ERROR "${LIBOTR_DIR_MESSAGE}") - ENDIF(LIBOTR_FIND_REQUIRED) - ENDIF(NOT LIBOTR_FIND_QUIETLY) -ENDIF(NOT LIBOTR_FOUND) diff --git a/cmake-extensions/Git.cmake b/cmake-extensions/Git.cmake deleted file mode 100644 index d731c82..0000000 --- a/cmake-extensions/Git.cmake +++ /dev/null @@ -1,20 +0,0 @@ -# -# Uli Meis -# -# Handy macro for fetching current tag or commit of a git repo. -# -MACRO(FIND_GIT_TAGORCOMMIT GITDIR CMAKEVAR) - EXECUTE_PROCESS(COMMAND bash -c - "GITCOMMIT=`git log | head -n1 | cut -d' ' -f2`;\\ - if [ -z \"$GITCOMMIT\" ]; then exit 1;fi; \\ - GITTAG=`cd .git/refs/tags && grep $GITCOMMIT * | cut -d: -f1` ;\\ - if [ -n \"$GITTAG\" ]; then \\ - echo -n $GITTAG | tr -d v; else \\ - echo -n git-$GITCOMMIT;fi" - WORKING_DIRECTORY ${GITDIR} - OUTPUT_VARIABLE GIT_TAGORCOMMIT - RESULT_VARIABLE GIT_TAGORCOMMITRET) - IF(GIT_TAGORCOMMITRET EQUAL 0) - SET(${CMAKEVAR} ${GIT_TAGORCOMMIT}) - ENDIF(GIT_TAGORCOMMITRET EQUAL 0) -ENDMACRO(FIND_GIT_TAGORCOMMIT) diff --git a/cmake-extensions/cscope.cmake b/cmake-extensions/cscope.cmake deleted file mode 100644 index 59594b4..0000000 --- a/cmake-extensions/cscope.cmake +++ /dev/null @@ -1,17 +0,0 @@ -# -# Uli Meis -# -# Handy macro for generating the cscope database -# - -MACRO(ADD_CSCOPE_TARGET CSCOPE_SOURCES CSCOPE_INCLUDES) - ADD_CUSTOM_COMMAND( - OUTPUT cscope.out - DEPENDS ${CSCOPE_SOURCES} - WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} - COMMAND - echo '${CSCOPE_SOURCES}' | tr ' ' '\\n' >cscope.files - COMMAND - cscope -b `echo ${CSCOPE_INCLUDES} | xargs -n1 bash -c 'echo -I$$0'`) - ADD_CUSTOM_TARGET(cscope DEPENDS cscope.out) -ENDMACRO(ADD_CSCOPE_TARGET) diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..c03cc7f --- /dev/null +++ b/configure.ac @@ -0,0 +1,57 @@ +AC_PREREQ([2.69]) +AC_INIT([hexchat-otr], [0.1.0]) +AC_CONFIG_SRCDIR([src/otr.h]) +AC_CONFIG_HEADERS([config.h]) +AC_CONFIG_MACRO_DIR([m4]) +AC_PROG_CC +AC_PROG_INSTALL +AC_PATH_PROG([GCRYPT_CONFIG], [libgcrypt-config], [no]) + +AM_INIT_AUTOMAKE([1.11 silent-rules tar-pax dist-xz no-dist-gzip subdir-objects no-define foreign -Wall]) +AM_SILENT_RULES([yes]) +AM_PROG_AR + +LT_INIT + +PKG_CHECK_MODULES([GLIB], [glib-2.0]) +PKG_CHECK_MODULES([OTR], [libotr >= 4.0.0]) + +AC_MSG_CHECKING([for GCRYPT]) +if test "$GCRYPT_CONFIG" = "no"; then + AC_MSG_ERROR([no]) +else + GCRYPT_CFLAGS="`$GCRYPT_CONFIG --cflags`" + GCRYPT_LIBS="`$GCRYPT_CONFIG --libs`" + AC_SUBST([GCRYPT_CFLAGS]) + AC_SUBST([GCRYPT_LIBS]) + AC_MSG_RESULT([yes]) +fi + +AC_MSG_CHECKING([for hexchat's plugin path]) +if $PKG_CONFIG hexchat-plugin --exists; then + hexchatlibdir="`$PKG_CONFIG --variable=hexchatlibdir hexchat-plugin`" + AC_MSG_RESULT([$hexchatlibdir]) +else + hexchatlibdir="$libdir/hexchat/plugins" + AC_MSG_RESULT([not found, assuming $hexchatlibdir]) +fi +AC_SUBST([hexchatlibdir]) + +CFLAGS="$CFLAGS" +# TODO: Improve +if test "$CC" = "gcc" || test "$CC" = "clang"; then + CFLAGS="$CFLAGS -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers" +fi +AC_SUBST([CFLAGS]) + +AC_CONFIG_FILES([ + Makefile + src/Makefile +]) + +AC_OUTPUT +echo " + $PACKAGE $VERSION + + install location: ${hexchatlibdir} +" diff --git a/io-config.h.in b/io-config.h.in deleted file mode 100644 index 02dd318..0000000 --- a/io-config.h.in +++ /dev/null @@ -1,3 +0,0 @@ -#cmakedefine HAVE_STRSIGNAL -#cmakedefine HAVE_GREGEX_H -#define IRSSIOTR_VERSION "${IRSSIOTR_VERSION}" diff --git a/irssi_otr.c b/irssi_otr.c deleted file mode 100644 index 7687601..0000000 --- a/irssi_otr.c +++ /dev/null @@ -1,441 +0,0 @@ -/* - * Off-the-Record Messaging (OTR) module for the irssi IRC client - * Copyright (C) 2008 Uli Meis - * - * 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 = FALSE; - -#ifdef HAVE_GREGEX_H -GRegex *regex_nickignore = NULL; -#endif - -void irc_send_message(IRC_CTX *ircctx, const char *recipient, char *msg) { - ircctx->send_message( - ircctx,recipient,msg,GPOINTER_TO_INT(SEND_TARGET_NICK)); -} - -/* - * Pipes all outgoing private messages through OTR - */ -static void sig_server_sendmsg(SERVER_REC *server, const char *target, - const char *msg, void *target_type_p) -{ - if (GPOINTER_TO_INT(target_type_p)==SEND_TARGET_NICK) { - char *otrmsg; - -#ifdef HAVE_GREGEX_H - if (g_regex_match(regex_nickignore,target,0,NULL)) - return; -#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) - signal_stop(); - } -} - -/* - * Pipes all incoming private messages through OTR - */ -static void sig_message_private(SERVER_REC *server, const char *msg, - const char *nick, const char *address) -{ - char *newmsg; - -#ifdef HAVE_GREGEX_H - if (g_regex_match(regex_nickignore,nick,0,NULL)) - return; -#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==NULL) - signal_stop(); -} - -/* - * Finish an OTR conversation when its query is closed. - */ -static void sig_query_destroyed(QUERY_REC *query) { - if (query&&query->server&&query->server->connrec) { - otr_finish(query->server,query->name,NULL,FALSE); - } -} - -/* - * /otr - */ -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) -{ - 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&&(addserver,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); - } - } -} - -/* - * /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@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] - */ -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); -} - -/* - * /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); -} - -/* - * /otr version - */ -static void cmd_version(const char *data, void *server, WI_ITEM_REC *item) -{ - otr_noticest(TXT_CMD_VERSION,IRSSIOTR_VERSION); -} - -/* - * /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); - } -} - -/* - * Optionally finish conversations on /quit. We're already doing this on unload - * but the quit handler terminates irc connections before unloading. - */ -static void cmd_quit(const char *data, void *server, WI_ITEM_REC *item) -{ - if (settings_get_bool("otr_finishonunload")) - otr_finishall(); -} - -/* - * otr statusbar - */ -static void otr_statusbar(struct SBAR_ITEM_REC *item, int get_size_only) -{ - WI_ITEM_REC *wi = active_win->active; - QUERY_REC *query = QUERY(wi); - int formatnum=0; - - if (query&&query->server&&query->server->connrec) - formatnum = otr_getstatus(query->server->nick,query->name,query->server->connrec->address); - - statusbar_item_default_handler( - item, - get_size_only, - formatnum ? formats[formatnum].def : ""," ",FALSE); -} - -void otr_query_create(SERVER_REC *server, const char *nick) -{ - if (!server||!nick|| - !settings_get_bool("otr_createqueries")|| - query_find(server, nick)) - return; - - irc_query_create(server->tag, nick, TRUE); -} - -static void read_settings(void) -{ - otr_setpolicies(settings_get_str("otr_policy"),FALSE); - otr_setpolicies(settings_get_str("otr_policy_known"),TRUE); -#ifdef HAVE_GREGEX_H - if (regex_nickignore) - g_regex_unref(regex_nickignore); - regex_nickignore = g_regex_new(settings_get_str("otr_ignore"),0,0,NULL); -#endif - -} - -/* - * irssi init() - */ -void otr_init(void) -{ - module_register(MODULE_NAME, "core"); - - theme_register(formats); - - if (otrlib_init()) - return; - - 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); - - 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); - - settings_add_str("otr", "otr_policy",IO_DEFAULT_POLICY); - settings_add_str("otr", "otr_policy_known",IO_DEFAULT_POLICY_KNOWN); - settings_add_str("otr", "otr_ignore",IO_DEFAULT_IGNORE); - settings_add_bool("otr", "otr_finishonunload",TRUE); - settings_add_bool("otr", "otr_createqueries",TRUE); - read_settings(); - signal_add("setup changed", (SIGNAL_FUNC) read_settings); - - statusbar_item_register("otr", NULL, otr_statusbar); - - statusbar_items_redraw("window"); - -} - -/* - * irssi deinit() - */ -void otr_deinit(void) -{ -#ifdef HAVE_GREGEX_H - g_regex_unref(regex_nickignore); -#endif - - signal_remove("server sendmsg", (SIGNAL_FUNC) sig_server_sendmsg); - signal_remove("message private", (SIGNAL_FUNC) sig_message_private); - 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); - - signal_remove("setup changed", (SIGNAL_FUNC) read_settings); - - statusbar_item_unregister("otr"); - - if (settings_get_bool("otr_finishonunload")) - otr_finishall(); - - otrlib_deinit(); - - theme_unregister(); -} - -IRC_CTX *server_find_address(char *address) -{ - GSList *tmp; - - g_return_val_if_fail(address != NULL, NULL); - if (*address == '\0') return NULL; - - for (tmp = servers; tmp != NULL; tmp = tmp->next) { - SERVER_REC *server = tmp->data; - - if (g_strcasecmp(server->connrec->address, address) == 0) - return server; - } - - return NULL; -} - -char *lvlstring[] = { - "NOTICE", - "DEBUG" -}; - - -void otr_log(IRC_CTX *server, const char *nick, - int level, const char *format, ...) { - va_list params; - va_start( params, format ); - char msg[LOGMAX], *s = msg; - - if ((level==LVL_DEBUG)&&!debug) - return; - - s += sprintf(s,"%s","%9OTR%9"); - - if (level!=LVL_NOTICE) - s += sprintf(s,"(%s)",lvlstring[level]); - - s += sprintf(s,": "); - - if( vsnprintf( s, LOGMAX, format, params ) < 0 ) - sprintf( s, "internal error parsing error string (BUG)" ); - va_end( params ); - - printtext(server, nick, MSGLEVEL_MSGS, msg); -} diff --git a/irssi_otr.h b/irssi_otr.h deleted file mode 100644 index ca63c1c..0000000 --- a/irssi_otr.h +++ /dev/null @@ -1,57 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#define IRC_CTX SERVER_REC - -static IRC_CTX *IRCCTX_DUP(IRC_CTX *ircctx) __attribute__ ((unused)); - -static IRC_CTX *IRCCTX_DUP(IRC_CTX *ircctx) { - server_ref(ircctx); - return ircctx; -} - -static IRC_CTX *IRCCTX_FREE(IRC_CTX *ircctx) __attribute__ ((unused)); - -static IRC_CTX *IRCCTX_FREE(IRC_CTX *ircctx) -{ - server_unref(ircctx); - return ircctx; -} - -void otr_query_create(IRC_CTX *ircctx, const char *nick); - -#define IRCCTX_ADDR(ircctx) ircctx->connrec->address -#define IRCCTX_NICK(ircctx) ircctx->nick - -#define otr_noticest(formatnum,...) \ - printformat(NULL,NULL,MSGLEVEL_MSGS, formatnum, ## __VA_ARGS__) - -#define otr_notice(ircctx,nick,formatnum,...) { \ - otr_query_create(ircctx,nick); \ - printformat(ircctx,nick,MSGLEVEL_MSGS, formatnum, ## __VA_ARGS__);} - -#define otr_infost(formatnum,...) \ - printformat(NULL,NULL,MSGLEVEL_CRAP, formatnum, ## __VA_ARGS__) - -#define otr_info(server,nick,formatnum,...) { \ - otr_query_create(ircctx,nick); \ - printformat(ircctx,nick,MSGLEVEL_CRAP, formatnum, ## __VA_ARGS__);} - -#define otr_debug(ircctx,nick,formatnum,...) { \ - if (debug) { \ - otr_query_create(ircctx,nick); \ - printformat(ircctx,nick,MSGLEVEL_MSGS, formatnum, ## __VA_ARGS__); } } diff --git a/mksrcpackage.sh b/mksrcpackage.sh deleted file mode 100755 index af44b7d..0000000 --- a/mksrcpackage.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/bash -if [ -z "$2" ]; then echo "Syntax: $0 "; exit 1;fi -SDIR="$1" -#VER=`(cd "$SDIR/.git/refs/tags/" && ls -t)|head -n1|sed -e 's/.//'` -VER=$2 - -PKG=irc-otr-$VER.tar -HDIR=irc-otr-$VER -mkdir "$HDIR" &&\ -(cd "$SDIR" && git archive --format=tar --prefix=irc-otr-$VER/ HEAD )>$PKG &&\ -(cd "$HDIR" && ln -s ../irssi-headers &&\ - echo -e "SET(IRSSIOTR_VERSION $VER)" >tarballdefs.cmake) &&\ -tar rhf $PKG "$HDIR" &&\ -rm $HDIR/{irssi-headers,tarballdefs.cmake} &&\ -rmdir $HDIR &&\ -gzip $PKG - -PKG=irssi-otr-$VER.tar -HDIR=irssi-otr-$VER -mkdir "$HDIR" &&\ -(cd "$SDIR" && git archive --format=tar --prefix=irssi-otr-$VER/ HEAD )>$PKG &&\ -(cd "$HDIR" && ln -s ../irssi-headers &&\ - echo -e "SET(IRSSIOTR_VERSION $VER)\nSET(BUILDFOR irssi)" >tarballdefs.cmake) &&\ -tar rhf $PKG "$HDIR" &&\ -rm $HDIR/{irssi-headers,tarballdefs.cmake} &&\ -rmdir $HDIR &&\ -gzip $PKG - -PKG=xchat-otr-$VER.tar -HDIR=xchat-otr-$VER -mkdir "$HDIR" &&\ -(cd "$SDIR" && git archive --format=tar --prefix=xchat-otr-$VER/ HEAD )>$PKG &&\ -(cd "$HDIR" && echo -e "SET(IRSSIOTR_VERSION $VER)\nSET(BUILDFOR xchat)" >tarballdefs.cmake) &&\ -tar rhf $PKG "$HDIR" &&\ -rm $HDIR/tarballdefs.cmake &&\ -rmdir $HDIR &&\ -gzip $PKG diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..c52e75a --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,11 @@ + +libdir = $(hexchatlibdir) + +lib_LTLIBRARIES = otr.la +otr_la_SOURCES = otr_key.c otr_ops.c otr_util.c hexchat_otr.c hexchat-formats.c +otr_la_CFLAGS = $(OTR_CFLAGS) $(GLIB_CFLAGS) $(GCRYPT_CFLAGS) +otr_la_LIBADD = $(OTR_LIBS) $(GLIB_LIBS) $(GCRYPT_LIBS) +otr_la_LDFLAGS = -avoid-version -module + +EXTRA_DIST = formats.txt makeformats.py otr.h otr-formats.h hexchat_otr.h + diff --git a/formats.txt b/src/formats.txt similarity index 100% rename from formats.txt rename to src/formats.txt diff --git a/src/hexchat-formats.c b/src/hexchat-formats.c new file mode 100644 index 0000000..5866195 --- /dev/null +++ b/src/hexchat-formats.c @@ -0,0 +1,112 @@ +#include "otr.h" +FORMAT_REC formats[] = { +{ MODULE_NAME, "otr", 0} +, +{ NULL, "Keys", 0 } +, +{ "kg_failed", "Key generation for %s: failed: %s (%s)", 0}, +{ "kg_completed", "Key generation for %s: completed in %d seconds. Reloading keys", 0}, +{ "kg_aborted_dup", "Key generation for %s: aborted. Key generation for %s still in progress", 0}, +{ "kg_aborted_dir", "Key generation for %s: aborted, failed creating directory %s: %s", 0}, +{ "kg_mkdir", "created directory %s", 0}, +{ "kg_pipe", "Key generation for %s: error creating pipe: %s", 0}, +{ "kg_fork", "Key generation for %s: fork() error: %s", 0}, +{ "kg_initiated", "Key generation for %s: initiated. This might take several minutes or on some systems even an hour. If you wanna check that something is happening, see if there are two processes of your IRC client.", 0}, +{ "kg_exited", "Key generation for %s: child terminated for unknown reason", 0}, +{ "kg_exitsig", "Key generation for %s: child was killed by signal %s", 0}, +{ "kg_pollerr", "Key generation for %s: error poll()ing child: %s", 0}, +{ "kg_abort", "Key generation for %s: aborted", 0}, +{ "kg_needacc", "I need an account name. Try something like /otr genkey mynick@irc.server.net", 0}, +{ "kg_noabort", "No ongoing key generation to abort", 0}, +{ "key_not_found", "no private keys found", 0}, +{ "key_loaded", "private keys loaded", 0}, +{ "key_load_error", "Error loading private keys: %s (%s)", 0}, +{ NULL, "Fingerprints", 0 } +, +{ "fp_saved", "fingerprints saved", 0}, +{ "fp_save_error", "Error saving fingerprints: %s (%s)", 0}, +{ "fp_not_found", "no fingerprints found", 0}, +{ "fp_loaded", "fingerprints loaded", 0}, +{ "fp_load_error", "Error loading fingerprints: %s (%s)", 0}, +{ "fp_trust", "Trusting fingerprint from %s", 0}, +{ NULL, "Callbacks", 0 } +, +{ "ops_notify_bug", "BUG() in ops_notify", 0}, +{ "ops_notify", "title: %s prim: %s sec: %s", 0}, +{ "ops_display_bug", "BUG() in ops_display", 0}, +{ "ops_display", "msg: %s", 0}, +{ "ops_sec", "gone secure", 0}, +{ "ops_fpcomp", "Your peer is not authenticated. To make sure you're talking to the right guy you can either agree on a secret and use the authentication described in /otr auth, or use the traditional way and compare fingerprints over a secure line (e.g. telephone) and subsequently enter /otr trust. Your fingerprint is: %s. %s's fingerprint: %s", 0}, +{ "ops_insec", "gone insecure", 0}, +{ "ops_still_reply", "still secure (is reply)", 0}, +{ "ops_still_no_reply", "still secure (is not reply)", 0}, +{ "ops_log", "log msg: %s", 0}, +{ "ops_inject", "Couldn't inject message from %s for %s: %s", 0}, +{ NULL, "SendingReceiving", 0 } +, +{ "send_failed", "send failed: msg=%s", 0}, +{ "send_change", "couldn't find context also OTR changed the outgoing message(BUG?)", 0}, +{ "send_fragment", "failed to fragment message: msg=%s", 0}, +{ "send_converted", "OTR converted sent message to %s", 0}, +{ "receive_ignore_query", "ignoring rest of OTR default query msg", 0}, +{ "receive_dequeued", "dequeued msg of length %d", 0}, +{ "receive_queued", "queued msg of length %d", 0}, +{ "receive_ignore", "ignoring protocol message of length %d, acc=%s, from=%s: %s", 0}, +{ "receive_converted", "OTR converted received message", 0}, +{ "otr_better_two", "%s has requested an Off-the-Record private conversation. However, you do not have a plugin to support that.", 0}, +{ "otr_better_three", "See http://otr.cypherpunks.ca/ for more information.", 0}, +{ NULL, "Context", 0 } +, +{ "ctx_not_found", "couldn't find context: acc=%s nick=%s", 0}, +{ "ctx_not_create", "couldn't create/find context: acc=%s from=%s", 0}, +{ NULL, "Authentication", 0 } +, +{ "auth_aborted_ongoing", "Ongoing authentication aborted", 0}, +{ "auth_aborted", "Authentication aborted", 0}, +{ "auth_responding", "Responding to authentication request...", 0}, +{ "auth_initiated", "Initiated authentication...", 0}, +{ "auth_have_old", "%s wanted to authenticate but an old authentication was still ongoing. Old authentication will be aborted, please try again.", 0}, +{ "auth_peer", "%s wants to authenticate. Type /otr auth to complete.", 0}, +{ "auth_peer_reply_wrong", "%s replied to an auth we didn't start.", 0}, +{ "auth_peer_replied", "%s replied to our auth request...", 0}, +{ "auth_peer_wrong_smp3", "%s sent a wrong authentication message (SMP3).", 0}, +{ "auth_peer_wrong_smp4", "%s sent a wrong authentication message (SMP4).", 0}, +{ "auth_successful", "Authentication successful!", 0}, +{ "auth_failed", "Authentication failed!", 0}, +{ "auth_needenc", "You need to establish an OTR session before you can authenticate.", 0}, +{ NULL, "Commands", 0 } +, +{ "cmd_otr", "We're alive", 0}, +{ "cmd_qnotfound", "Failed: Can't get nick and server of current query window. (Or maybe you're doing this in the status window?)", 0}, +{ "cmd_auth", "Please agree on a secret with your peer and then initiate the authentication with /otr auth or let him initiate. Should you initiate your peer will after a little while be instructed to enter the secret as well. Once he has done so the authentication will finish up. Should you have both typed in the same secret the authentication should be successful.", 0}, +{ "cmd_debug_on", "Debug mode is on", 0}, +{ "cmd_debug_off", "Debug mode is off", 0}, +{ "cmd_finish", "Finished conversation with %s@%s.", 0}, +{ "cmd_finishall_none", "No conversations to finish.", 0}, +{ "cmd_version", "This is irssi-otr version %s", 0}, +{ "peer_finished", "%s has finished the OTR conversation. If you want to continue talking enter /otr finish for plaintext or ?OTR? to restart OTR.", 0}, +{ NULL, "Contexts", 0 } +, +{ "ctx_ctx_unencrypted", "%20s %30s plaintext", 0}, +{ "ctx_ctx_encrypted", "%20s %30s encrypted", 0}, +{ "ctx_ctx_finished", "%20s %30s finished", 0}, +{ "ctx_ctx_unknown", "%20s %30s unknown state(BUG?)", 0}, +{ "ctx_fps_no", "%s %rnot authenticated", 0}, +{ "ctx_fps_smp", "%s authenticated via shared secret (SMP)", 0}, +{ "ctx_fps_man", "%s authenticated manually", 0}, +{ "ctx_noctxs", "No active OTR contexts found", 0}, +{ NULL, "Statusbar", 0 } +, +{ "st_plaintext", "{sb plaintext}", 0}, +{ "st_untrusted", "{sb %rOTR(not auth'ed)}", 0}, +{ "st_trust_smp", "{sb OTR}", 0}, +{ "st_trust_manual", "{sb OTR}", 0}, +{ "st_smp_wait_2", "{sb {hilight awaiting auth reply...}}", 0}, +{ "st_smp_have_2", "{sb {hilight finalizing auth... (won't happen with libotr 3.1(bug), ask the other guy to initiate)}}", 0}, +{ "st_smp_failed", "{sb {hilight auth failed}}", 0}, +{ "st_smp_finalize", "{sb {hilight finalizing auth...}}", 0}, +{ "st_smp_unknown", "{sb {hilight unknown auth state!}}", 0}, +{ "st_finished", "{sb finished}", 0}, +{ "st_unknown", "{sb {hilight state unknown (BUG!)}}", 0}, +{ NULL, NULL, 0 } +}; diff --git a/xchat_otr.c b/src/hexchat_otr.c similarity index 96% rename from xchat_otr.c rename to src/hexchat_otr.c index f1111ab..bb4ce5b 100644 --- a/xchat_otr.c +++ b/src/hexchat_otr.c @@ -2,10 +2,7 @@ int debug = 0; -#ifdef HAVE_GREGEX_H GRegex *regex_nickignore = NULL; -#endif - hexchat_plugin *ph; static char set_policy[512] = IO_DEFAULT_POLICY; @@ -49,7 +46,7 @@ int cmd_otr(char *word[], char *word_eol[], void *userdata) 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); + otr_noticest(TXT_CMD_VERSION,PVERSION); } else if (strcmp(cmd,"finish")==0) { if (word[3]&&*word[3]) otr_finish(NULL,NULL,word[3],TRUE); @@ -92,12 +89,10 @@ int cmd_otr(char *word[], char *word_eol[], void *userdata) 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 { @@ -127,10 +122,8 @@ int hook_outgoing(char *word[], char *word_eol[], void *userdata) if ((*channel == '&')||(*channel == '#')) return HEXCHAT_EAT_NONE; -#ifdef HAVE_GREGEX_H if (g_regex_match(regex_nickignore,channel,0,NULL)) return HEXCHAT_EAT_NONE; -#endif otrmsg = otr_send(&ircctx,word_eol[1],channel); if (otrmsg==word_eol[1]) @@ -166,10 +159,8 @@ int hook_privmsg(char *word[], char *word_eol[], void *userdata) if (!extract_nick(nick,word[1])) return HEXCHAT_EAT_NONE; -#ifdef HAVE_GREGEX_H if (g_regex_match(regex_nickignore,nick,0,NULL)) return HEXCHAT_EAT_NONE; -#endif newmsg = otr_receive(&ircctx,word_eol[2],nick); @@ -187,7 +178,6 @@ int hook_privmsg(char *word[], char *word_eol[], void *userdata) query_ctx = hexchat_find_context(ph, server, nick); } -#ifdef HAVE_GREGEX_H GRegex *regex_quot = g_regex_new(""",0,0,NULL); GRegex *regex_amp = g_regex_new("&",0,0,NULL); GRegex *regex_lt = g_regex_new("<",0,0,NULL); @@ -202,7 +192,6 @@ int hook_privmsg(char *word[], char *word_eol[], void *userdata) g_regex_unref(regex_amp); g_regex_unref(regex_lt); g_regex_unref(regex_gt); -#endif if (query_ctx) hexchat_set_context(ph, query_ctx); @@ -244,11 +233,9 @@ int hexchat_plugin_init(hexchat_plugin *plugin_handle, 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 hexchat_print(ph, "Hexchat OTR loaded successfully!\n"); @@ -257,9 +244,7 @@ int hexchat_plugin_init(hexchat_plugin *plugin_handle, int hexchat_plugin_deinit() { -#ifdef HAVE_GREGEX_H g_regex_unref(regex_nickignore); -#endif if (set_finishonunload) otr_finishall(); diff --git a/xchat_otr.h b/src/hexchat_otr.h similarity index 93% rename from xchat_otr.h rename to src/hexchat_otr.h index b225dad..a1dfeb8 100644 --- a/xchat_otr.h +++ b/src/hexchat_otr.h @@ -1,8 +1,11 @@ +#include "config.h" #include "hexchat-plugin.h" -#define PNAME "Hexchat OTR" +#define MODULE_NAME "otr" + +#define PNAME "OTR" #define PDESC "Off-The-Record Messaging for Hexchat" -#define PVERSION IRSSIOTR_VERSION +#define PVERSION PACKAGE_VERSION #define MAX_FORMAT_PARAMS 10 diff --git a/makeformats.py b/src/makeformats.py similarity index 98% rename from makeformats.py rename to src/makeformats.py index 744c51c..20170d2 100755 --- a/makeformats.py +++ b/src/makeformats.py @@ -11,7 +11,7 @@ hdr = open("otr-formats.h","w") src = open("otr-formats.c","w") -srcx = open("xchat-formats.c","w") +srcx = open("hexchat-formats.c","w") src.write('#include "otr.h"\n'); srcx.write('#include "otr.h"\n'); diff --git a/src/otr-formats.h b/src/otr-formats.h new file mode 100644 index 0000000..9546f62 --- /dev/null +++ b/src/otr-formats.h @@ -0,0 +1,104 @@ +extern char *otr_help; + +enum { +TXT_OTR_MODULE_NAME, +TXT_OTR_FILL_0, +TXT_KG_FAILED, +TXT_KG_COMPLETED, +TXT_KG_ABORTED_DUP, +TXT_KG_ABORTED_DIR, +TXT_KG_MKDIR, +TXT_KG_PIPE, +TXT_KG_FORK, +TXT_KG_INITIATED, +TXT_KG_EXITED, +TXT_KG_EXITSIG, +TXT_KG_POLLERR, +TXT_KG_ABORT, +TXT_KG_NEEDACC, +TXT_KG_NOABORT, +TXT_KEY_NOT_FOUND, +TXT_KEY_LOADED, +TXT_KEY_LOAD_ERROR, +TXT_OTR_FILL_1, +TXT_FP_SAVED, +TXT_FP_SAVE_ERROR, +TXT_FP_NOT_FOUND, +TXT_FP_LOADED, +TXT_FP_LOAD_ERROR, +TXT_FP_TRUST, +TXT_OTR_FILL_2, +TXT_OPS_NOTIFY_BUG, +TXT_OPS_NOTIFY, +TXT_OPS_DISPLAY_BUG, +TXT_OPS_DISPLAY, +TXT_OPS_SEC, +TXT_OPS_FPCOMP, +TXT_OPS_INSEC, +TXT_OPS_STILL_REPLY, +TXT_OPS_STILL_NO_REPLY, +TXT_OPS_LOG, +TXT_OPS_INJECT, +TXT_OTR_FILL_3, +TXT_SEND_FAILED, +TXT_SEND_CHANGE, +TXT_SEND_FRAGMENT, +TXT_SEND_CONVERTED, +TXT_RECEIVE_IGNORE_QUERY, +TXT_RECEIVE_DEQUEUED, +TXT_RECEIVE_QUEUED, +TXT_RECEIVE_IGNORE, +TXT_RECEIVE_CONVERTED, +TXT_OTR_BETTER_TWO, +TXT_OTR_BETTER_THREE, +TXT_OTR_FILL_4, +TXT_CTX_NOT_FOUND, +TXT_CTX_NOT_CREATE, +TXT_OTR_FILL_5, +TXT_AUTH_ABORTED_ONGOING, +TXT_AUTH_ABORTED, +TXT_AUTH_RESPONDING, +TXT_AUTH_INITIATED, +TXT_AUTH_HAVE_OLD, +TXT_AUTH_PEER, +TXT_AUTH_PEER_REPLY_WRONG, +TXT_AUTH_PEER_REPLIED, +TXT_AUTH_PEER_WRONG_SMP3, +TXT_AUTH_PEER_WRONG_SMP4, +TXT_AUTH_SUCCESSFUL, +TXT_AUTH_FAILED, +TXT_AUTH_NEEDENC, +TXT_OTR_FILL_6, +TXT_CMD_OTR, +TXT_CMD_QNOTFOUND, +TXT_CMD_AUTH, +TXT_CMD_DEBUG_ON, +TXT_CMD_DEBUG_OFF, +TXT_CMD_FINISH, +TXT_CMD_FINISHALL_NONE, +TXT_CMD_VERSION, +TXT_PEER_FINISHED, +TXT_OTR_FILL_7, +TXT_CTX_CTX_UNENCRYPTED, +TXT_CTX_CTX_ENCRYPTED, +TXT_CTX_CTX_FINISHED, +TXT_CTX_CTX_UNKNOWN, +TXT_CTX_FPS_NO, +TXT_CTX_FPS_SMP, +TXT_CTX_FPS_MAN, +TXT_CTX_NOCTXS, +TXT_OTR_FILL_8, +TXT_ST_PLAINTEXT, +TXT_ST_UNTRUSTED, +TXT_ST_TRUST_SMP, +TXT_ST_TRUST_MANUAL, +TXT_ST_SMP_WAIT_2, +TXT_ST_SMP_HAVE_2, +TXT_ST_SMP_FAILED, +TXT_ST_SMP_FINALIZE, +TXT_ST_SMP_UNKNOWN, +TXT_ST_FINISHED, +TXT_ST_UNKNOWN +}; + +extern FORMAT_REC formats[]; diff --git a/otr.h b/src/otr.h similarity index 95% rename from otr.h rename to src/otr.h index bb7fb02..35af5e3 100644 --- a/otr.h +++ b/src/otr.h @@ -34,17 +34,9 @@ #include #include -/* irssi */ +/* hexchat */ -#ifdef TARGET_IRSSI -#include -#endif - -/* xchat */ - -#ifdef TARGET_XCHAT -#include -#endif +#include /* log stuff */ @@ -61,10 +53,7 @@ void otr_log(IRC_CTX *server, const char *to, /* own */ -#include "io-config.h" - -/* irssi module name */ -#define MODULE_NAME "otr" +#include "config.h" #include "otr-formats.h" diff --git a/otr_key.c b/src/otr_key.c similarity index 100% rename from otr_key.c rename to src/otr_key.c diff --git a/otr_ops.c b/src/otr_ops.c similarity index 89% rename from otr_ops.c rename to src/otr_ops.c index 48e842f..fd81cb1 100644 --- a/otr_ops.c +++ b/src/otr_ops.c @@ -133,8 +133,6 @@ void ops_notify(void *opdata, OtrlNotifyLevel level, const char *accountname, } #endif -#ifdef HAVE_GREGEX_H - /* This is kind of messy. */ const char *convert_otr_msg(const char *msg) { @@ -152,8 +150,6 @@ const char *convert_otr_msg(const char *msg) return msg; } -#endif - void ops_handle_msg(void *opdata, OtrlMessageEvent msg_event, ConnContext *co, const char *msg, gcry_error_t err) @@ -167,45 +163,10 @@ void ops_handle_msg(void *opdata, OtrlMessageEvent msg_event, } else otr_notice(server, co->username, TXT_OPS_DISPLAY_BUG); -#ifdef HAVE_GREGEX_H msg = convert_otr_msg(msg); otr_notice(server, co->username, TXT_OPS_DISPLAY, msg); g_free((char*)msg); -#else - otr_notice(server, co->username, TXT_OPS_DISPLAY, msg); -#endif -} - -#if 0 -/* - * OTR message. E.g. "following has been transmitted in clear: ...". - * We're trying to kill the ugly HTML. - */ -int ops_display_msg(void *opdata, const char *accountname, - const char *protocol, const char *username, - const char *msg) -{ - ConnContext *co = otr_getcontext(accountname,username,FALSE,opdata); - IRC_CTX *server = opdata; - struct co_info *coi; - - if (co) { - coi = co->app_data; - server = coi->ircctx; - } else - otr_notice(server,username,TXT_OPS_DISPLAY_BUG); - -#ifdef HAVE_GREGEX_H - msg = convert_otr_msg(msg); - otr_notice(server,username,TXT_OPS_DISPLAY,msg); - g_free((char*)msg); -#else - otr_notice(server,username,TXT_OPS_DISPLAY,msg); -#endif - - return 0; } -#endif /* * Gone secure. diff --git a/otr_util.c b/src/otr_util.c similarity index 99% rename from otr_util.c rename to src/otr_util.c index 1b8c5e5..69db20d 100644 --- a/otr_util.c +++ b/src/otr_util.c @@ -26,10 +26,7 @@ extern OtrlMessageAppOps otr_ops; static int otrinited = FALSE; GSList *plistunknown = NULL; GSList *plistknown = NULL; - -#ifdef HAVE_GREGEX_H -GRegex *regex_policies; -#endif +GRegex *regex_policies = NULL; /* * init otr lib. @@ -51,11 +48,9 @@ int otrlib_init() otr_initops(); -#ifdef HAVE_GREGEX_H regex_policies = g_regex_new("([^,]+) (never|manual|handlews|opportunistic|always)" "(,|$)",0,0,NULL); -#endif return otr_state==NULL; } @@ -76,10 +71,7 @@ void otrlib_deinit() otr_setpolicies("",FALSE); otr_setpolicies("",TRUE); -#ifdef HAVE_GREGEX_H g_regex_unref(regex_policies); -#endif - } @@ -728,7 +720,6 @@ char *otr_receive(IRC_CTX *ircctx, const char *msg,const char *from) void otr_setpolicies(const char *policies, int known) { -#ifdef HAVE_GREGEX_H GMatchInfo *match_info; GSList *plist = known ? plistknown : plistunknown; diff --git a/tarballdefs.cmake b/tarballdefs.cmake deleted file mode 100644 index 34e6f00..0000000 --- a/tarballdefs.cmake +++ /dev/null @@ -1,2 +0,0 @@ -SET(IRSSIOTR_VERSION 0.3) -SET(BUILDFOR xchat) From 09f7e1ddc9e6cd149c8dc8809d1e86b635a08c93 Mon Sep 17 00:00:00 2001 From: TingPing Date: Sat, 13 Dec 2014 06:11:10 -0500 Subject: [PATCH 03/49] Add new readme --- Readme.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Readme.md diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..d1e9198 --- /dev/null +++ b/Readme.md @@ -0,0 +1,23 @@ +HexChat OTR +=========== + +Adds off the record support to HexChat. + +Originally forked from irssi-otr and still a work in progress. + +Installation +------------ + +### Dependencies + +- glib +- gcrypt +- libotr4 +- hexchat + +```sh +./autogen.sh +make -s +sudo make install +``` + From 29f46f631ef7d22de3abd417ae4f79cdb324ca70 Mon Sep 17 00:00:00 2001 From: TingPing Date: Sat, 13 Dec 2014 06:14:05 -0500 Subject: [PATCH 04/49] Remove extra #endif --- src/otr_util.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/otr_util.c b/src/otr_util.c index 69db20d..9f179f7 100644 --- a/src/otr_util.c +++ b/src/otr_util.c @@ -774,5 +774,4 @@ void otr_setpolicies(const char *policies, int known) plistknown = plist; else plistunknown = plist; -#endif } From 6b844d3e3b36627ad9a98730f2433fe037cb36a1 Mon Sep 17 00:00:00 2001 From: TingPing Date: Sat, 13 Dec 2014 07:36:54 -0500 Subject: [PATCH 05/49] Mass reformat --- .clang-format | 6 + src/hexchat-formats.c | 208 +++++++-------- src/hexchat_otr.c | 357 ++++++++++++++----------- src/hexchat_otr.h | 49 ++-- src/otr-formats.h | 199 +++++++------- src/otr.h | 99 ++++--- src/otr_key.c | 296 +++++++++++---------- src/otr_ops.c | 167 ++++++------ src/otr_util.c | 604 +++++++++++++++++++++++------------------- 9 files changed, 1063 insertions(+), 922 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..f99012d --- /dev/null +++ b/.clang-format @@ -0,0 +1,6 @@ +BasedOnStyle: Webkit +BreakBeforeBraces: Allman +UseTab: Always +TabWidth: 4 +SpaceBeforeParens: Always +PointerAlignment: Right diff --git a/src/hexchat-formats.c b/src/hexchat-formats.c index 5866195..2c54098 100644 --- a/src/hexchat-formats.c +++ b/src/hexchat-formats.c @@ -1,112 +1,102 @@ #include "otr.h" FORMAT_REC formats[] = { -{ MODULE_NAME, "otr", 0} -, -{ NULL, "Keys", 0 } -, -{ "kg_failed", "Key generation for %s: failed: %s (%s)", 0}, -{ "kg_completed", "Key generation for %s: completed in %d seconds. Reloading keys", 0}, -{ "kg_aborted_dup", "Key generation for %s: aborted. Key generation for %s still in progress", 0}, -{ "kg_aborted_dir", "Key generation for %s: aborted, failed creating directory %s: %s", 0}, -{ "kg_mkdir", "created directory %s", 0}, -{ "kg_pipe", "Key generation for %s: error creating pipe: %s", 0}, -{ "kg_fork", "Key generation for %s: fork() error: %s", 0}, -{ "kg_initiated", "Key generation for %s: initiated. This might take several minutes or on some systems even an hour. If you wanna check that something is happening, see if there are two processes of your IRC client.", 0}, -{ "kg_exited", "Key generation for %s: child terminated for unknown reason", 0}, -{ "kg_exitsig", "Key generation for %s: child was killed by signal %s", 0}, -{ "kg_pollerr", "Key generation for %s: error poll()ing child: %s", 0}, -{ "kg_abort", "Key generation for %s: aborted", 0}, -{ "kg_needacc", "I need an account name. Try something like /otr genkey mynick@irc.server.net", 0}, -{ "kg_noabort", "No ongoing key generation to abort", 0}, -{ "key_not_found", "no private keys found", 0}, -{ "key_loaded", "private keys loaded", 0}, -{ "key_load_error", "Error loading private keys: %s (%s)", 0}, -{ NULL, "Fingerprints", 0 } -, -{ "fp_saved", "fingerprints saved", 0}, -{ "fp_save_error", "Error saving fingerprints: %s (%s)", 0}, -{ "fp_not_found", "no fingerprints found", 0}, -{ "fp_loaded", "fingerprints loaded", 0}, -{ "fp_load_error", "Error loading fingerprints: %s (%s)", 0}, -{ "fp_trust", "Trusting fingerprint from %s", 0}, -{ NULL, "Callbacks", 0 } -, -{ "ops_notify_bug", "BUG() in ops_notify", 0}, -{ "ops_notify", "title: %s prim: %s sec: %s", 0}, -{ "ops_display_bug", "BUG() in ops_display", 0}, -{ "ops_display", "msg: %s", 0}, -{ "ops_sec", "gone secure", 0}, -{ "ops_fpcomp", "Your peer is not authenticated. To make sure you're talking to the right guy you can either agree on a secret and use the authentication described in /otr auth, or use the traditional way and compare fingerprints over a secure line (e.g. telephone) and subsequently enter /otr trust. Your fingerprint is: %s. %s's fingerprint: %s", 0}, -{ "ops_insec", "gone insecure", 0}, -{ "ops_still_reply", "still secure (is reply)", 0}, -{ "ops_still_no_reply", "still secure (is not reply)", 0}, -{ "ops_log", "log msg: %s", 0}, -{ "ops_inject", "Couldn't inject message from %s for %s: %s", 0}, -{ NULL, "SendingReceiving", 0 } -, -{ "send_failed", "send failed: msg=%s", 0}, -{ "send_change", "couldn't find context also OTR changed the outgoing message(BUG?)", 0}, -{ "send_fragment", "failed to fragment message: msg=%s", 0}, -{ "send_converted", "OTR converted sent message to %s", 0}, -{ "receive_ignore_query", "ignoring rest of OTR default query msg", 0}, -{ "receive_dequeued", "dequeued msg of length %d", 0}, -{ "receive_queued", "queued msg of length %d", 0}, -{ "receive_ignore", "ignoring protocol message of length %d, acc=%s, from=%s: %s", 0}, -{ "receive_converted", "OTR converted received message", 0}, -{ "otr_better_two", "%s has requested an Off-the-Record private conversation. However, you do not have a plugin to support that.", 0}, -{ "otr_better_three", "See http://otr.cypherpunks.ca/ for more information.", 0}, -{ NULL, "Context", 0 } -, -{ "ctx_not_found", "couldn't find context: acc=%s nick=%s", 0}, -{ "ctx_not_create", "couldn't create/find context: acc=%s from=%s", 0}, -{ NULL, "Authentication", 0 } -, -{ "auth_aborted_ongoing", "Ongoing authentication aborted", 0}, -{ "auth_aborted", "Authentication aborted", 0}, -{ "auth_responding", "Responding to authentication request...", 0}, -{ "auth_initiated", "Initiated authentication...", 0}, -{ "auth_have_old", "%s wanted to authenticate but an old authentication was still ongoing. Old authentication will be aborted, please try again.", 0}, -{ "auth_peer", "%s wants to authenticate. Type /otr auth to complete.", 0}, -{ "auth_peer_reply_wrong", "%s replied to an auth we didn't start.", 0}, -{ "auth_peer_replied", "%s replied to our auth request...", 0}, -{ "auth_peer_wrong_smp3", "%s sent a wrong authentication message (SMP3).", 0}, -{ "auth_peer_wrong_smp4", "%s sent a wrong authentication message (SMP4).", 0}, -{ "auth_successful", "Authentication successful!", 0}, -{ "auth_failed", "Authentication failed!", 0}, -{ "auth_needenc", "You need to establish an OTR session before you can authenticate.", 0}, -{ NULL, "Commands", 0 } -, -{ "cmd_otr", "We're alive", 0}, -{ "cmd_qnotfound", "Failed: Can't get nick and server of current query window. (Or maybe you're doing this in the status window?)", 0}, -{ "cmd_auth", "Please agree on a secret with your peer and then initiate the authentication with /otr auth or let him initiate. Should you initiate your peer will after a little while be instructed to enter the secret as well. Once he has done so the authentication will finish up. Should you have both typed in the same secret the authentication should be successful.", 0}, -{ "cmd_debug_on", "Debug mode is on", 0}, -{ "cmd_debug_off", "Debug mode is off", 0}, -{ "cmd_finish", "Finished conversation with %s@%s.", 0}, -{ "cmd_finishall_none", "No conversations to finish.", 0}, -{ "cmd_version", "This is irssi-otr version %s", 0}, -{ "peer_finished", "%s has finished the OTR conversation. If you want to continue talking enter /otr finish for plaintext or ?OTR? to restart OTR.", 0}, -{ NULL, "Contexts", 0 } -, -{ "ctx_ctx_unencrypted", "%20s %30s plaintext", 0}, -{ "ctx_ctx_encrypted", "%20s %30s encrypted", 0}, -{ "ctx_ctx_finished", "%20s %30s finished", 0}, -{ "ctx_ctx_unknown", "%20s %30s unknown state(BUG?)", 0}, -{ "ctx_fps_no", "%s %rnot authenticated", 0}, -{ "ctx_fps_smp", "%s authenticated via shared secret (SMP)", 0}, -{ "ctx_fps_man", "%s authenticated manually", 0}, -{ "ctx_noctxs", "No active OTR contexts found", 0}, -{ NULL, "Statusbar", 0 } -, -{ "st_plaintext", "{sb plaintext}", 0}, -{ "st_untrusted", "{sb %rOTR(not auth'ed)}", 0}, -{ "st_trust_smp", "{sb OTR}", 0}, -{ "st_trust_manual", "{sb OTR}", 0}, -{ "st_smp_wait_2", "{sb {hilight awaiting auth reply...}}", 0}, -{ "st_smp_have_2", "{sb {hilight finalizing auth... (won't happen with libotr 3.1(bug), ask the other guy to initiate)}}", 0}, -{ "st_smp_failed", "{sb {hilight auth failed}}", 0}, -{ "st_smp_finalize", "{sb {hilight finalizing auth...}}", 0}, -{ "st_smp_unknown", "{sb {hilight unknown auth state!}}", 0}, -{ "st_finished", "{sb finished}", 0}, -{ "st_unknown", "{sb {hilight state unknown (BUG!)}}", 0}, -{ NULL, NULL, 0 } + { MODULE_NAME, "otr", 0 }, + { NULL, "Keys", 0 }, + { "kg_failed", "Key generation for %s: failed: %s (%s)", 0 }, + { "kg_completed", "Key generation for %s: completed in %d seconds. Reloading keys", 0 }, + { "kg_aborted_dup", "Key generation for %s: aborted. Key generation for %s still in progress", 0 }, + { "kg_aborted_dir", "Key generation for %s: aborted, failed creating directory %s: %s", 0 }, + { "kg_mkdir", "created directory %s", 0 }, + { "kg_pipe", "Key generation for %s: error creating pipe: %s", 0 }, + { "kg_fork", "Key generation for %s: fork() error: %s", 0 }, + { "kg_initiated", "Key generation for %s: initiated. This might take several minutes or on some systems even an hour. If you wanna check that something is happening, see if there are two processes of your IRC client.", 0 }, + { "kg_exited", "Key generation for %s: child terminated for unknown reason", 0 }, + { "kg_exitsig", "Key generation for %s: child was killed by signal %s", 0 }, + { "kg_pollerr", "Key generation for %s: error poll()ing child: %s", 0 }, + { "kg_abort", "Key generation for %s: aborted", 0 }, + { "kg_needacc", "I need an account name. Try something like /otr genkey mynick@irc.server.net", 0 }, + { "kg_noabort", "No ongoing key generation to abort", 0 }, + { "key_not_found", "no private keys found", 0 }, + { "key_loaded", "private keys loaded", 0 }, + { "key_load_error", "Error loading private keys: %s (%s)", 0 }, + { NULL, "Fingerprints", 0 }, + { "fp_saved", "fingerprints saved", 0 }, + { "fp_save_error", "Error saving fingerprints: %s (%s)", 0 }, + { "fp_not_found", "no fingerprints found", 0 }, + { "fp_loaded", "fingerprints loaded", 0 }, + { "fp_load_error", "Error loading fingerprints: %s (%s)", 0 }, + { "fp_trust", "Trusting fingerprint from %s", 0 }, + { NULL, "Callbacks", 0 }, + { "ops_notify_bug", "BUG() in ops_notify", 0 }, + { "ops_notify", "title: %s prim: %s sec: %s", 0 }, + { "ops_display_bug", "BUG() in ops_display", 0 }, + { "ops_display", "msg: %s", 0 }, + { "ops_sec", "gone secure", 0 }, + { "ops_fpcomp", "Your peer is not authenticated. To make sure you're talking to the right guy you can either agree on a secret and use the authentication described in /otr auth, or use the traditional way and compare fingerprints over a secure line (e.g. telephone) and subsequently enter /otr trust. Your fingerprint is: %s. %s's fingerprint: %s", 0 }, + { "ops_insec", "gone insecure", 0 }, + { "ops_still_reply", "still secure (is reply)", 0 }, + { "ops_still_no_reply", "still secure (is not reply)", 0 }, + { "ops_log", "log msg: %s", 0 }, + { "ops_inject", "Couldn't inject message from %s for %s: %s", 0 }, + { NULL, "SendingReceiving", 0 }, + { "send_failed", "send failed: msg=%s", 0 }, + { "send_change", "couldn't find context also OTR changed the outgoing message(BUG?)", 0 }, + { "send_fragment", "failed to fragment message: msg=%s", 0 }, + { "send_converted", "OTR converted sent message to %s", 0 }, + { "receive_ignore_query", "ignoring rest of OTR default query msg", 0 }, + { "receive_dequeued", "dequeued msg of length %d", 0 }, + { "receive_queued", "queued msg of length %d", 0 }, + { "receive_ignore", "ignoring protocol message of length %d, acc=%s, from=%s: %s", 0 }, + { "receive_converted", "OTR converted received message", 0 }, + { "otr_better_two", "%s has requested an Off-the-Record private conversation. However, you do not have a plugin to support that.", 0 }, + { "otr_better_three", "See http://otr.cypherpunks.ca/ for more information.", 0 }, + { NULL, "Context", 0 }, + { "ctx_not_found", "couldn't find context: acc=%s nick=%s", 0 }, + { "ctx_not_create", "couldn't create/find context: acc=%s from=%s", 0 }, + { NULL, "Authentication", 0 }, + { "auth_aborted_ongoing", "Ongoing authentication aborted", 0 }, + { "auth_aborted", "Authentication aborted", 0 }, + { "auth_responding", "Responding to authentication request...", 0 }, + { "auth_initiated", "Initiated authentication...", 0 }, + { "auth_have_old", "%s wanted to authenticate but an old authentication was still ongoing. Old authentication will be aborted, please try again.", 0 }, + { "auth_peer", "%s wants to authenticate. Type /otr auth to complete.", 0 }, + { "auth_peer_reply_wrong", "%s replied to an auth we didn't start.", 0 }, + { "auth_peer_replied", "%s replied to our auth request...", 0 }, + { "auth_peer_wrong_smp3", "%s sent a wrong authentication message (SMP3).", 0 }, + { "auth_peer_wrong_smp4", "%s sent a wrong authentication message (SMP4).", 0 }, + { "auth_successful", "Authentication successful!", 0 }, + { "auth_failed", "Authentication failed!", 0 }, + { "auth_needenc", "You need to establish an OTR session before you can authenticate.", 0 }, + { NULL, "Commands", 0 }, + { "cmd_otr", "We're alive", 0 }, + { "cmd_qnotfound", "Failed: Can't get nick and server of current query window. (Or maybe you're doing this in the status window?)", 0 }, + { "cmd_auth", "Please agree on a secret with your peer and then initiate the authentication with /otr auth or let him initiate. Should you initiate your peer will after a little while be instructed to enter the secret as well. Once he has done so the authentication will finish up. Should you have both typed in the same secret the authentication should be successful.", 0 }, + { "cmd_debug_on", "Debug mode is on", 0 }, + { "cmd_debug_off", "Debug mode is off", 0 }, + { "cmd_finish", "Finished conversation with %s@%s.", 0 }, + { "cmd_finishall_none", "No conversations to finish.", 0 }, + { "cmd_version", "This is irssi-otr version %s", 0 }, + { "peer_finished", "%s has finished the OTR conversation. If you want to continue talking enter /otr finish for plaintext or ?OTR? to restart OTR.", 0 }, + { NULL, "Contexts", 0 }, + { "ctx_ctx_unencrypted", "%20s %30s plaintext", 0 }, + { "ctx_ctx_encrypted", "%20s %30s encrypted", 0 }, + { "ctx_ctx_finished", "%20s %30s finished", 0 }, + { "ctx_ctx_unknown", "%20s %30s unknown state(BUG?)", 0 }, + { "ctx_fps_no", "%s %rnot authenticated", 0 }, + { "ctx_fps_smp", "%s authenticated via shared secret (SMP)", 0 }, + { "ctx_fps_man", "%s authenticated manually", 0 }, + { "ctx_noctxs", "No active OTR contexts found", 0 }, + { NULL, "Statusbar", 0 }, + { "st_plaintext", "{sb plaintext}", 0 }, + { "st_untrusted", "{sb %rOTR(not auth'ed)}", 0 }, + { "st_trust_smp", "{sb OTR}", 0 }, + { "st_trust_manual", "{sb OTR}", 0 }, + { "st_smp_wait_2", "{sb {hilight awaiting auth reply...}}", 0 }, + { "st_smp_have_2", "{sb {hilight finalizing auth... (won't happen with libotr 3.1(bug), ask the other guy to initiate)}}", 0 }, + { "st_smp_failed", "{sb {hilight auth failed}}", 0 }, + { "st_smp_finalize", "{sb {hilight finalizing auth...}}", 0 }, + { "st_smp_unknown", "{sb {hilight unknown auth state!}}", 0 }, + { "st_finished", "{sb finished}", 0 }, + { "st_unknown", "{sb {hilight state unknown (BUG!)}}", 0 }, + { NULL, NULL, 0 } }; diff --git a/src/hexchat_otr.c b/src/hexchat_otr.c index bb4ce5b..6c8287b 100644 --- a/src/hexchat_otr.c +++ b/src/hexchat_otr.c @@ -10,212 +10,246 @@ 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) +int extract_nick (char *nick, char *line) { char *excl; if (*line++ != ':') return FALSE; - strcpy(nick,line); - - if ((excl = strchr(nick,'!'))) + strcpy (nick, line); + + if ((excl = strchr (nick, '!'))) *excl = '\0'; return TRUE; - } -void irc_send_message(IRC_CTX *ircctx, const char *recipient, char *msg) { - hexchat_commandf(ph, "PRIVMSG %s :%s", recipient, msg); +void irc_send_message (IRC_CTX *ircctx, const char *recipient, char *msg) +{ + hexchat_commandf (ph, "PRIVMSG %s :%s", recipient, msg); } -int cmd_otr(char *word[], char *word_eol[], void *userdata) +int cmd_otr (char *word[], char *word_eol[], void *userdata) { - const char *own_nick = hexchat_get_info(ph, "nick"); - char *target = (char*)hexchat_get_info(ph, "channel"); - const char *server = hexchat_get_info(ph, "server"); - IRC_CTX ircctxs = { - .nick = (char*)own_nick, - .address = (char*)server }, - *ircctx = &ircctxs; + const char *own_nick = hexchat_get_info (ph, "nick"); + char *target = (char *)hexchat_get_info (ph, "channel"); + const char *server = hexchat_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) { + 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,PVERSION); - } else if (strcmp(cmd,"finish")==0) { - if (word[3]&&*word[3]) - otr_finish(NULL,NULL,word[3],TRUE); + otr_noticest (debug ? TXT_CMD_DEBUG_ON : TXT_CMD_DEBUG_OFF); + } + else if (strcmp (cmd, "version") == 0) + { + otr_noticest (TXT_CMD_VERSION, PVERSION); + } + 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]); + 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]); + 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]); + 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); + 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) { + } + 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) + { 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]); - } else if (strcmp(word[3],"finishonunload")==0) { - set_finishonunload = (strcasecmp(word[4],"true")==0); - } else { - hexchat_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"); + g_regex_unref (regex_nickignore); + regex_nickignore = g_regex_new (word_eol[4], 0, 0, NULL); + strcpy (set_ignore, word_eol[4]); + } + else if (strcmp (word[3], "finishonunload") == 0) + { + set_finishonunload = (strcasecmp (word[4], "true") == 0); + } + else + { + hexchat_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"); } - } return HEXCHAT_EAT_ALL; } -int hook_outgoing(char *word[], char *word_eol[], void *userdata) +int hook_outgoing (char *word[], char *word_eol[], void *userdata) { - const char *own_nick = hexchat_get_info(ph, "nick"); - const char *channel = hexchat_get_info(ph, "channel"); - const char *server = hexchat_get_info(ph, "server"); + const char *own_nick = hexchat_get_info (ph, "nick"); + const char *channel = hexchat_get_info (ph, "channel"); + const char *server = hexchat_get_info (ph, "server"); char newmsg[512]; char *otrmsg; - IRC_CTX ircctx = { - .nick = (char*)own_nick, - .address = (char*)server }; + IRC_CTX ircctx = { + .nick = (char *)own_nick, + .address = (char *)server + }; - if ((*channel == '&')||(*channel == '#')) + if ((*channel == '&') || (*channel == '#')) return HEXCHAT_EAT_NONE; - if (g_regex_match(regex_nickignore,channel,0,NULL)) + if (g_regex_match (regex_nickignore, channel, 0, NULL)) return HEXCHAT_EAT_NONE; - otrmsg = otr_send(&ircctx,word_eol[1],channel); + otrmsg = otr_send (&ircctx, word_eol[1], channel); - if (otrmsg==word_eol[1]) + if (otrmsg == word_eol[1]) return HEXCHAT_EAT_NONE; - hexchat_emit_print(ph, "Your Message", own_nick, word_eol[1], NULL, NULL); + hexchat_emit_print (ph, "Your Message", own_nick, word_eol[1], NULL, NULL); if (!otrmsg) return HEXCHAT_EAT_ALL; - snprintf(newmsg, 511, "PRIVMSG %s :%s", channel, otrmsg); + snprintf (newmsg, 511, "PRIVMSG %s :%s", channel, otrmsg); - otrl_message_free(otrmsg); - hexchat_command(ph, newmsg); + otrl_message_free (otrmsg); + hexchat_command (ph, newmsg); return HEXCHAT_EAT_ALL; } -int hook_privmsg(char *word[], char *word_eol[], void *userdata) +int hook_privmsg (char *word[], char *word_eol[], void *userdata) { char nick[256]; char *newmsg; - const char *server = hexchat_get_info(ph, "server"); - const char *own_nick = hexchat_get_info(ph, "nick"); - IRC_CTX ircctx = { - .nick = (char*)own_nick, - .address = (char*)server }; + const char *server = hexchat_get_info (ph, "server"); + const char *own_nick = hexchat_get_info (ph, "nick"); + IRC_CTX ircctx = { + .nick = (char *)own_nick, + .address = (char *)server + }; hexchat_context *query_ctx; char *chanmsg = word[3]; - if ((*chanmsg == '&')||(*chanmsg == '#')) + if ((*chanmsg == '&') || (*chanmsg == '#')) return HEXCHAT_EAT_NONE; - if (!extract_nick(nick,word[1])) + if (!extract_nick (nick, word[1])) return HEXCHAT_EAT_NONE; - if (g_regex_match(regex_nickignore,nick,0,NULL)) + if (g_regex_match (regex_nickignore, nick, 0, NULL)) return HEXCHAT_EAT_NONE; - newmsg = otr_receive(&ircctx,word_eol[2],nick); + newmsg = otr_receive (&ircctx, word_eol[2], nick); - if (!newmsg) { + if (!newmsg) + { return HEXCHAT_EAT_ALL; } - if (newmsg==word_eol[2]) { + if (newmsg == word_eol[2]) + { return HEXCHAT_EAT_NONE; } - query_ctx = hexchat_find_context(ph, server, nick); - if(query_ctx==NULL) { - hexchat_commandf(ph, "query %s", nick); - query_ctx = hexchat_find_context(ph, server, nick); + query_ctx = hexchat_find_context (ph, server, nick); + if (query_ctx == NULL) + { + hexchat_commandf (ph, "query %s", nick); + query_ctx = hexchat_find_context (ph, server, nick); } - GRegex *regex_quot = g_regex_new(""",0,0,NULL); - GRegex *regex_amp = g_regex_new("&",0,0,NULL); - GRegex *regex_lt = g_regex_new("<",0,0,NULL); - GRegex *regex_gt = g_regex_new(">",0,0,NULL); - char *quotfix = g_regex_replace_literal(regex_quot,newmsg,-1,0,"\"",0,NULL); - char *ampfix = g_regex_replace_literal(regex_amp,quotfix,-1,0,"&",0,NULL); - char *ltfix = g_regex_replace_literal(regex_lt,ampfix,-1,0,"<",0,NULL); - char *gtfix = g_regex_replace_literal(regex_gt,ltfix,-1,0,">",0,NULL); - newmsg = gtfix; - - g_regex_unref(regex_quot); - g_regex_unref(regex_amp); - g_regex_unref(regex_lt); - g_regex_unref(regex_gt); + GRegex *regex_quot = g_regex_new (""", 0, 0, NULL); + GRegex *regex_amp = g_regex_new ("&", 0, 0, NULL); + GRegex *regex_lt = g_regex_new ("<", 0, 0, NULL); + GRegex *regex_gt = g_regex_new (">", 0, 0, NULL); + char *quotfix = g_regex_replace_literal (regex_quot, newmsg, -1, 0, "\"", 0, NULL); + char *ampfix = g_regex_replace_literal (regex_amp, quotfix, -1, 0, "&", 0, NULL); + char *ltfix = g_regex_replace_literal (regex_lt, ampfix, -1, 0, "<", 0, NULL); + char *gtfix = g_regex_replace_literal (regex_gt, ltfix, -1, 0, ">", 0, NULL); + newmsg = gtfix; + + g_regex_unref (regex_quot); + g_regex_unref (regex_amp); + g_regex_unref (regex_lt); + g_regex_unref (regex_gt); if (query_ctx) - hexchat_set_context(ph, query_ctx); + hexchat_set_context (ph, query_ctx); - hexchat_emit_print(ph, "Private Message", nick, newmsg, NULL, NULL); + hexchat_emit_print (ph, "Private Message", nick, newmsg, NULL, NULL); - hexchat_command(ph, "GUI COLOR 2"); - otrl_message_free(newmsg); + hexchat_command (ph, "GUI COLOR 2"); + otrl_message_free (newmsg); return HEXCHAT_EAT_ALL; } -void hexchat_plugin_get_info(char **name, char **desc, char **version, void **reserved) +void hexchat_plugin_get_info (char **name, char **desc, char **version, void **reserved) { - *name = PNAME; - *desc = PDESC; - *version = PVERSION; + *name = PNAME; + *desc = PDESC; + *version = PVERSION; } -int hexchat_plugin_init(hexchat_plugin *plugin_handle, - char **plugin_name, - char **plugin_desc, - char **plugin_version, - char *arg) +int hexchat_plugin_init (hexchat_plugin *plugin_handle, + char **plugin_name, + char **plugin_desc, + char **plugin_version, + char *arg) { ph = plugin_handle; @@ -223,41 +257,41 @@ int hexchat_plugin_init(hexchat_plugin *plugin_handle, *plugin_desc = PDESC; *plugin_version = PVERSION; - if (otrlib_init()) + if (otrlib_init ()) return 0; - hexchat_hook_server(ph, "PRIVMSG", HEXCHAT_PRI_NORM, hook_privmsg, 0); - hexchat_hook_command(ph, "", HEXCHAT_PRI_NORM, hook_outgoing, 0, 0); - hexchat_hook_command(ph, "otr", HEXCHAT_PRI_NORM, cmd_otr, 0, 0); + hexchat_hook_server (ph, "PRIVMSG", HEXCHAT_PRI_NORM, hook_privmsg, 0); + hexchat_hook_command (ph, "", HEXCHAT_PRI_NORM, hook_outgoing, 0, 0); + hexchat_hook_command (ph, "otr", HEXCHAT_PRI_NORM, cmd_otr, 0, 0); - otr_setpolicies(IO_DEFAULT_POLICY,FALSE); - otr_setpolicies(IO_DEFAULT_POLICY_KNOWN,TRUE); + otr_setpolicies (IO_DEFAULT_POLICY, FALSE); + otr_setpolicies (IO_DEFAULT_POLICY_KNOWN, TRUE); if (regex_nickignore) - g_regex_unref(regex_nickignore); - regex_nickignore = g_regex_new(IO_DEFAULT_IGNORE,0,0,NULL); + g_regex_unref (regex_nickignore); + regex_nickignore = g_regex_new (IO_DEFAULT_IGNORE, 0, 0, NULL); - hexchat_print(ph, "Hexchat OTR loaded successfully!\n"); + hexchat_print (ph, "Hexchat OTR loaded successfully!\n"); return 1; } -int hexchat_plugin_deinit() +int hexchat_plugin_deinit () { - g_regex_unref(regex_nickignore); + g_regex_unref (regex_nickignore); if (set_finishonunload) - otr_finishall(); + otr_finishall (); - otrlib_deinit(); + otrlib_deinit (); return 1; } -void printformat(IRC_CTX *ircctx, const char *nick, int lvl, int fnum, ...) +void printformat (IRC_CTX *ircctx, const char *nick, int lvl, int fnum, ...) { va_list params; - va_start( params, fnum ); + va_start (params, fnum); char msg[LOGMAX], *s = msg; hexchat_context *find_query_ctx; char *server = NULL; @@ -265,35 +299,38 @@ void printformat(IRC_CTX *ircctx, const char *nick, int lvl, int fnum, ...) if (ircctx) server = ircctx->address; - if (server&&nick) { - find_query_ctx = hexchat_find_context(ph, server, nick); - if(find_query_ctx==NULL) { + if (server && nick) + { + find_query_ctx = hexchat_find_context (ph, server, nick); + if (find_query_ctx == NULL) + { // no query window yet, let's open one - hexchat_commandf(ph, "query %s", nick); - find_query_ctx = hexchat_find_context(ph, server, nick); + hexchat_commandf (ph, "query %s", nick); + find_query_ctx = hexchat_find_context (ph, server, nick); } - } else { - find_query_ctx = hexchat_find_context(ph, - NULL, - hexchat_get_info(ph, - "network") ? - : - hexchat_get_info(ph,"server")); + } + else + { + find_query_ctx = hexchat_find_context (ph, + NULL, + hexchat_get_info (ph, + "network") + ?: hexchat_get_info (ph, "server")); } - hexchat_set_context(ph, find_query_ctx); + hexchat_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 ); - hexchat_printf(ph, "OTR: %s", s); + if (vsnprintf (s, LOGMAX, formats[fnum].def, params) < 0) + sprintf (s, "internal error parsing error string (BUG)"); + va_end (params); + hexchat_printf (ph, "OTR: %s", s); } -IRC_CTX *server_find_address(char *address) +IRC_CTX *server_find_address (char *address) { static IRC_CTX ircctx; ircctx.address = address; - return &ircctx; + return &ircctx; } diff --git a/src/hexchat_otr.h b/src/hexchat_otr.h index a1dfeb8..dffaeb6 100644 --- a/src/hexchat_otr.h +++ b/src/hexchat_otr.h @@ -9,15 +9,16 @@ #define MAX_FORMAT_PARAMS 10 - -struct _IRC_CTX { +struct _IRC_CTX +{ char *nick; char *address; }; typedef struct _IRC_CTX IRC_CTX; -struct _FORMAT_REC { +struct _FORMAT_REC +{ char *tag; char *def; @@ -27,33 +28,37 @@ struct _FORMAT_REC { typedef struct _FORMAT_REC FORMAT_REC; -enum { MSGLEVEL_CRAP, MSGLEVEL_MSGS } lvls; +enum +{ + MSGLEVEL_CRAP, + MSGLEVEL_MSGS +} lvls; -extern hexchat_plugin *ph; /* plugin handle */ +extern hexchat_plugin *ph; /* plugin handle */ #define statusbar_items_redraw(name) ; -#define get_irssi_dir() hexchat_get_info(ph,"configdir") +#define get_irssi_dir() hexchat_get_info (ph, "configdir") -void printformat(IRC_CTX *ircctx, const char *nick, int lvl, int fnum, ...); +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_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_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_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_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 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) +#define IRCCTX_FREE(ircctx) g_free (ircctx) diff --git a/src/otr-formats.h b/src/otr-formats.h index 9546f62..649c2c0 100644 --- a/src/otr-formats.h +++ b/src/otr-formats.h @@ -1,104 +1,105 @@ extern char *otr_help; -enum { -TXT_OTR_MODULE_NAME, -TXT_OTR_FILL_0, -TXT_KG_FAILED, -TXT_KG_COMPLETED, -TXT_KG_ABORTED_DUP, -TXT_KG_ABORTED_DIR, -TXT_KG_MKDIR, -TXT_KG_PIPE, -TXT_KG_FORK, -TXT_KG_INITIATED, -TXT_KG_EXITED, -TXT_KG_EXITSIG, -TXT_KG_POLLERR, -TXT_KG_ABORT, -TXT_KG_NEEDACC, -TXT_KG_NOABORT, -TXT_KEY_NOT_FOUND, -TXT_KEY_LOADED, -TXT_KEY_LOAD_ERROR, -TXT_OTR_FILL_1, -TXT_FP_SAVED, -TXT_FP_SAVE_ERROR, -TXT_FP_NOT_FOUND, -TXT_FP_LOADED, -TXT_FP_LOAD_ERROR, -TXT_FP_TRUST, -TXT_OTR_FILL_2, -TXT_OPS_NOTIFY_BUG, -TXT_OPS_NOTIFY, -TXT_OPS_DISPLAY_BUG, -TXT_OPS_DISPLAY, -TXT_OPS_SEC, -TXT_OPS_FPCOMP, -TXT_OPS_INSEC, -TXT_OPS_STILL_REPLY, -TXT_OPS_STILL_NO_REPLY, -TXT_OPS_LOG, -TXT_OPS_INJECT, -TXT_OTR_FILL_3, -TXT_SEND_FAILED, -TXT_SEND_CHANGE, -TXT_SEND_FRAGMENT, -TXT_SEND_CONVERTED, -TXT_RECEIVE_IGNORE_QUERY, -TXT_RECEIVE_DEQUEUED, -TXT_RECEIVE_QUEUED, -TXT_RECEIVE_IGNORE, -TXT_RECEIVE_CONVERTED, -TXT_OTR_BETTER_TWO, -TXT_OTR_BETTER_THREE, -TXT_OTR_FILL_4, -TXT_CTX_NOT_FOUND, -TXT_CTX_NOT_CREATE, -TXT_OTR_FILL_5, -TXT_AUTH_ABORTED_ONGOING, -TXT_AUTH_ABORTED, -TXT_AUTH_RESPONDING, -TXT_AUTH_INITIATED, -TXT_AUTH_HAVE_OLD, -TXT_AUTH_PEER, -TXT_AUTH_PEER_REPLY_WRONG, -TXT_AUTH_PEER_REPLIED, -TXT_AUTH_PEER_WRONG_SMP3, -TXT_AUTH_PEER_WRONG_SMP4, -TXT_AUTH_SUCCESSFUL, -TXT_AUTH_FAILED, -TXT_AUTH_NEEDENC, -TXT_OTR_FILL_6, -TXT_CMD_OTR, -TXT_CMD_QNOTFOUND, -TXT_CMD_AUTH, -TXT_CMD_DEBUG_ON, -TXT_CMD_DEBUG_OFF, -TXT_CMD_FINISH, -TXT_CMD_FINISHALL_NONE, -TXT_CMD_VERSION, -TXT_PEER_FINISHED, -TXT_OTR_FILL_7, -TXT_CTX_CTX_UNENCRYPTED, -TXT_CTX_CTX_ENCRYPTED, -TXT_CTX_CTX_FINISHED, -TXT_CTX_CTX_UNKNOWN, -TXT_CTX_FPS_NO, -TXT_CTX_FPS_SMP, -TXT_CTX_FPS_MAN, -TXT_CTX_NOCTXS, -TXT_OTR_FILL_8, -TXT_ST_PLAINTEXT, -TXT_ST_UNTRUSTED, -TXT_ST_TRUST_SMP, -TXT_ST_TRUST_MANUAL, -TXT_ST_SMP_WAIT_2, -TXT_ST_SMP_HAVE_2, -TXT_ST_SMP_FAILED, -TXT_ST_SMP_FINALIZE, -TXT_ST_SMP_UNKNOWN, -TXT_ST_FINISHED, -TXT_ST_UNKNOWN +enum +{ + TXT_OTR_MODULE_NAME, + TXT_OTR_FILL_0, + TXT_KG_FAILED, + TXT_KG_COMPLETED, + TXT_KG_ABORTED_DUP, + TXT_KG_ABORTED_DIR, + TXT_KG_MKDIR, + TXT_KG_PIPE, + TXT_KG_FORK, + TXT_KG_INITIATED, + TXT_KG_EXITED, + TXT_KG_EXITSIG, + TXT_KG_POLLERR, + TXT_KG_ABORT, + TXT_KG_NEEDACC, + TXT_KG_NOABORT, + TXT_KEY_NOT_FOUND, + TXT_KEY_LOADED, + TXT_KEY_LOAD_ERROR, + TXT_OTR_FILL_1, + TXT_FP_SAVED, + TXT_FP_SAVE_ERROR, + TXT_FP_NOT_FOUND, + TXT_FP_LOADED, + TXT_FP_LOAD_ERROR, + TXT_FP_TRUST, + TXT_OTR_FILL_2, + TXT_OPS_NOTIFY_BUG, + TXT_OPS_NOTIFY, + TXT_OPS_DISPLAY_BUG, + TXT_OPS_DISPLAY, + TXT_OPS_SEC, + TXT_OPS_FPCOMP, + TXT_OPS_INSEC, + TXT_OPS_STILL_REPLY, + TXT_OPS_STILL_NO_REPLY, + TXT_OPS_LOG, + TXT_OPS_INJECT, + TXT_OTR_FILL_3, + TXT_SEND_FAILED, + TXT_SEND_CHANGE, + TXT_SEND_FRAGMENT, + TXT_SEND_CONVERTED, + TXT_RECEIVE_IGNORE_QUERY, + TXT_RECEIVE_DEQUEUED, + TXT_RECEIVE_QUEUED, + TXT_RECEIVE_IGNORE, + TXT_RECEIVE_CONVERTED, + TXT_OTR_BETTER_TWO, + TXT_OTR_BETTER_THREE, + TXT_OTR_FILL_4, + TXT_CTX_NOT_FOUND, + TXT_CTX_NOT_CREATE, + TXT_OTR_FILL_5, + TXT_AUTH_ABORTED_ONGOING, + TXT_AUTH_ABORTED, + TXT_AUTH_RESPONDING, + TXT_AUTH_INITIATED, + TXT_AUTH_HAVE_OLD, + TXT_AUTH_PEER, + TXT_AUTH_PEER_REPLY_WRONG, + TXT_AUTH_PEER_REPLIED, + TXT_AUTH_PEER_WRONG_SMP3, + TXT_AUTH_PEER_WRONG_SMP4, + TXT_AUTH_SUCCESSFUL, + TXT_AUTH_FAILED, + TXT_AUTH_NEEDENC, + TXT_OTR_FILL_6, + TXT_CMD_OTR, + TXT_CMD_QNOTFOUND, + TXT_CMD_AUTH, + TXT_CMD_DEBUG_ON, + TXT_CMD_DEBUG_OFF, + TXT_CMD_FINISH, + TXT_CMD_FINISHALL_NONE, + TXT_CMD_VERSION, + TXT_PEER_FINISHED, + TXT_OTR_FILL_7, + TXT_CTX_CTX_UNENCRYPTED, + TXT_CTX_CTX_ENCRYPTED, + TXT_CTX_CTX_FINISHED, + TXT_CTX_CTX_UNKNOWN, + TXT_CTX_FPS_NO, + TXT_CTX_FPS_SMP, + TXT_CTX_FPS_MAN, + TXT_CTX_NOCTXS, + TXT_OTR_FILL_8, + TXT_ST_PLAINTEXT, + TXT_ST_UNTRUSTED, + TXT_ST_TRUST_SMP, + TXT_ST_TRUST_MANUAL, + TXT_ST_SMP_WAIT_2, + TXT_ST_SMP_HAVE_2, + TXT_ST_SMP_FAILED, + TXT_ST_SMP_FINALIZE, + TXT_ST_SMP_UNKNOWN, + TXT_ST_FINISHED, + TXT_ST_UNKNOWN }; extern FORMAT_REC formats[]; diff --git a/src/otr.h b/src/otr.h index 35af5e3..bea1417 100644 --- a/src/otr.h +++ b/src/otr.h @@ -42,14 +42,14 @@ #define LOGMAX 1024 -#define LVL_NOTICE 0 -#define LVL_DEBUG 1 +#define LVL_NOTICE 0 +#define LVL_DEBUG 1 -#define otr_logst(level,format,...) \ - otr_log(NULL,NULL,level,format, ## __VA_ARGS__) +#define otr_logst(level, format, ...) \ + otr_log (NULL, NULL, level, format, ##__VA_ARGS__) -void otr_log(IRC_CTX *server, const char *to, - int level, const char *format, ...); +void otr_log (IRC_CTX *server, const char *to, + int level, const char *format, ...); /* own */ @@ -66,9 +66,9 @@ void otr_log(IRC_CTX *server, const char *to, /* otr protocol id */ #define PROTOCOLID "IRC" -#define KEYFILE "/otr/otr.key" +#define KEYFILE "/otr/otr.key" #define TMPKEYFILE "/otr/otr.key.tmp" -#define FPSFILE "/otr/otr.fp" +#define FPSFILE "/otr/otr.fp" /* some defaults */ #define IO_DEFAULT_POLICY "*@localhost opportunistic,*bitlbee* opportunistic,*@im.* opportunistic, *serv@irc* never" @@ -76,37 +76,52 @@ void otr_log(IRC_CTX *server, const char *to, #define IO_DEFAULT_IGNORE "xmlconsole[0-9]*" /* one for each OTR context (=communication pair) */ -struct co_info { - char *msgqueue; /* holds partially reconstructed base64 +struct co_info +{ + char *msgqueue; /* holds partially reconstructed base64 messages */ - IRC_CTX *ircctx; /* irssi server object for this peer */ - int received_smp_init; /* received SMP init msg */ - int smp_failed; /* last SMP failed */ - char better_msg_two[256]; /* what the second line of the "better" + IRC_CTX *ircctx; /* irssi server object for this peer */ + int received_smp_init; /* received SMP init msg */ + int smp_failed; /* last SMP failed */ + char better_msg_two[256]; /* what the second line of the "better" default query msg should like. Eat it up when it comes in */ - int finished; /* true after you've /otr finished */ + int finished; /* true after you've /otr finished */ }; /* these are returned by /otr contexts */ -struct fplist_ { +struct fplist_ +{ char *fp; - enum { NOAUTH,AUTHSMP,AUTHMAN } authby; + enum + { + NOAUTH, + AUTHSMP, + AUTHMAN + } authby; struct fplist_ *next; }; -struct ctxlist_ { +struct ctxlist_ +{ char *username; char *accountname; - enum { STUNENCRYPTED,STENCRYPTED,STFINISHED,STUNKNOWN } state; + enum + { + STUNENCRYPTED, + STENCRYPTED, + STFINISHED, + STUNKNOWN + } state; struct fplist_ *fplist; struct ctxlist_ *next; }; /* policy list generated from /set otr_policy */ -struct plistentry { +struct plistentry +{ GPatternSpec *namepat; OtrlPolicy policy; }; @@ -114,38 +129,36 @@ struct plistentry { /* used by the logging functions below */ extern int debug; -void irc_send_message(IRC_CTX *ircctx, const char *recipient, char *msg); -IRC_CTX *server_find_address(char *address); +void irc_send_message (IRC_CTX *ircctx, const char *recipient, char *msg); +IRC_CTX *server_find_address (char *address); /* init stuff */ -int otrlib_init(); -void otrlib_deinit(); -void otr_initops(); -void otr_setpolicies(const char *policies, int known); +int otrlib_init (); +void otrlib_deinit (); +void otr_initops (); +void otr_setpolicies (const char *policies, int known); /* 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); +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); /* user interaction */ -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(); - +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 (); /* key/fingerprint stuff */ -void keygen_run(const char *accname); -void keygen_abort(); -void key_load(); -void fps_load(); -void otr_writefps(); - +void keygen_run (const char *accname); +void keygen_abort (); +void key_load (); +void fps_load (); +void otr_writefps (); diff --git a/src/otr_key.c b/src/otr_key.c index 9e32158..2f22bdf 100644 --- a/src/otr_key.c +++ b/src/otr_key.c @@ -29,101 +29,112 @@ extern OtrlUserState otr_state; -typedef enum { KEYGEN_NO, KEYGEN_RUNNING } keygen_status_t; +typedef enum +{ + KEYGEN_NO, + KEYGEN_RUNNING +} keygen_status_t; -struct { +struct +{ keygen_status_t status; char *accountname; char *protocol; time_t started; GIOChannel *ch[2]; - guint cpid,cwid; + guint cpid, cwid; pid_t pid; -} kg_st = {.status = KEYGEN_NO }; +} kg_st = { .status = KEYGEN_NO }; -void keygen_childwatch(GPid pid,gint status, gpointer data) { - struct pollfd pfd = { - .fd = g_io_channel_unix_get_fd(kg_st.ch[0]), - .events = POLLIN }; +void keygen_childwatch (GPid pid, gint status, gpointer data) +{ + struct pollfd pfd = { + .fd = g_io_channel_unix_get_fd (kg_st.ch[0]), + .events = POLLIN + }; int ret; /* nothing to do if keygen_complete has already been called */ - if (data) + if (data) return; kg_st.pid = 0; - ret = poll(&pfd,1,0); + ret = poll (&pfd, 1, 0); /* data is there, let's wait for keygen_complete to be called */ if (ret == 1) return; /* no data, report error and reset kg_st */ - if (ret==0) { - if (WIFSIGNALED(status)) { + if (ret == 0) + { + if (WIFSIGNALED (status)) + { char sigstr[16]; - sprintf(sigstr, + sprintf (sigstr, #ifndef HAVE_STRSIGNAL - "%d",WTERMSIG(status)); + "%d", WTERMSIG (status)); #else - "%s",strsignal(WTERMSIG(status))); + "%s", strsignal (WTERMSIG (status))); #endif - otr_noticest(TXT_KG_EXITSIG, - kg_st.accountname, - sigstr); + otr_noticest (TXT_KG_EXITSIG, + kg_st.accountname, + sigstr); } else - otr_noticest(TXT_KG_EXITED,kg_st.accountname); - } else if (ret==-1) - otr_noticest(TXT_KG_POLLERR,kg_st.accountname,strerror(errno)); + otr_noticest (TXT_KG_EXITED, kg_st.accountname); + } + else if (ret == -1) + otr_noticest (TXT_KG_POLLERR, kg_st.accountname, strerror (errno)); - keygen_abort(FALSE); -} + keygen_abort (FALSE); +} /* * Installed as g_io_watch and called when the key generation * process finishs. */ -gboolean keygen_complete(GIOChannel *source, GIOCondition condition, - gpointer data) +gboolean keygen_complete (GIOChannel *source, GIOCondition condition, + gpointer data) { gcry_error_t err; - const char *irssidir = get_irssi_dir(); - char *filename = g_strconcat(irssidir,KEYFILE,NULL); - char *tmpfilename = g_strconcat(irssidir,TMPKEYFILE,NULL); + const char *irssidir = get_irssi_dir (); + char *filename = g_strconcat (irssidir, KEYFILE, NULL); + char *tmpfilename = g_strconcat (irssidir, TMPKEYFILE, NULL); - read(g_io_channel_unix_get_fd(kg_st.ch[0]),&err,sizeof(err)); + read (g_io_channel_unix_get_fd (kg_st.ch[0]), &err, sizeof(err)); - g_io_channel_shutdown(kg_st.ch[0],FALSE,NULL); - g_io_channel_shutdown(kg_st.ch[1],FALSE,NULL); - g_io_channel_unref(kg_st.ch[0]); - g_io_channel_unref(kg_st.ch[1]); + g_io_channel_shutdown (kg_st.ch[0], FALSE, NULL); + g_io_channel_shutdown (kg_st.ch[1], FALSE, NULL); + g_io_channel_unref (kg_st.ch[0]); + g_io_channel_unref (kg_st.ch[1]); if (err) - otr_noticest(TXT_KG_FAILED, - kg_st.accountname, - gcry_strerror(err), - gcry_strsource(err)); - else { + otr_noticest (TXT_KG_FAILED, + kg_st.accountname, + gcry_strerror (err), + gcry_strsource (err)); + else + { /* reload keys */ - otr_noticest(TXT_KG_COMPLETED, - kg_st.accountname, - time(NULL)-kg_st.started); - rename(tmpfilename,filename); + otr_noticest (TXT_KG_COMPLETED, + kg_st.accountname, + time (NULL) - kg_st.started); + rename (tmpfilename, filename); //otrl_privkey_forget_all(otr_state); <-- done by lib - key_load(); + key_load (); } - g_source_remove(kg_st.cwid); - kg_st.cwid = g_child_watch_add(kg_st.pid,keygen_childwatch,(void*)1); + g_source_remove (kg_st.cwid); + kg_st.cwid = g_child_watch_add (kg_st.pid, keygen_childwatch, (void *)1); kg_st.status = KEYGEN_NO; - g_free(kg_st.accountname); + g_free (kg_st.accountname); - g_free(filename); - g_free(tmpfilename); + g_free (filename); + g_free (tmpfilename); return FALSE; } @@ -133,98 +144,107 @@ 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 (const char *accname) { gcry_error_t err; int ret; int fds[2]; - char *filename = g_strconcat(get_irssi_dir(),TMPKEYFILE,NULL); - char *dir = dirname(g_strdup(filename)); - - if (kg_st.status!=KEYGEN_NO) { - if (strcmp(accname,kg_st.accountname)!=0) - otr_noticest(TXT_KG_ABORTED_DUP, - accname,kg_st.accountname); + char *filename = g_strconcat (get_irssi_dir (), TMPKEYFILE, NULL); + char *dir = dirname (g_strdup (filename)); + + if (kg_st.status != KEYGEN_NO) + { + if (strcmp (accname, kg_st.accountname) != 0) + otr_noticest (TXT_KG_ABORTED_DUP, + accname, kg_st.accountname); return; } - if (!g_file_test(dir, G_FILE_TEST_EXISTS)) { - if (g_mkdir(dir,S_IRWXU)) { - otr_noticest(TXT_KG_ABORTED_DIR, - accname,dir,strerror(errno)); - g_free(dir); - g_free(filename); + if (!g_file_test (dir, G_FILE_TEST_EXISTS)) + { + if (g_mkdir (dir, S_IRWXU)) + { + otr_noticest (TXT_KG_ABORTED_DIR, + accname, dir, strerror (errno)); + g_free (dir); + g_free (filename); return; - } else - otr_noticest(TXT_KG_MKDIR,dir); + } + else + otr_noticest (TXT_KG_MKDIR, dir); } - g_free(dir); + g_free (dir); - if (pipe(fds) != 0) { - otr_noticest(TXT_KG_PIPE, - accname,strerror(errno)); - g_free(filename); + if (pipe (fds) != 0) + { + otr_noticest (TXT_KG_PIPE, + accname, strerror (errno)); + g_free (filename); return; } - kg_st.ch[0] = g_io_channel_unix_new(fds[0]); - kg_st.ch[1] = g_io_channel_unix_new(fds[1]); + kg_st.ch[0] = g_io_channel_unix_new (fds[0]); + kg_st.ch[1] = g_io_channel_unix_new (fds[1]); - kg_st.accountname = g_strdup(accname); + kg_st.accountname = g_strdup (accname); kg_st.protocol = PROTOCOLID; - kg_st.started = time(NULL); - - if ((ret = fork())) { - g_free(filename); - if (ret==-1) { - otr_noticest(TXT_KG_FORK, - accname,strerror(errno)); + kg_st.started = time (NULL); + + if ((ret = fork ())) + { + g_free (filename); + if (ret == -1) + { + otr_noticest (TXT_KG_FORK, + accname, strerror (errno)); return; } kg_st.status = KEYGEN_RUNNING; kg_st.pid = ret; - otr_noticest(TXT_KG_INITIATED, - accname); + otr_noticest (TXT_KG_INITIATED, + accname); - kg_st.cpid = g_io_add_watch(kg_st.ch[0], G_IO_IN, - (GIOFunc) keygen_complete, NULL); - kg_st.cwid = g_child_watch_add(kg_st.pid,keygen_childwatch,NULL); + kg_st.cpid = g_io_add_watch (kg_st.ch[0], G_IO_IN, + (GIOFunc)keygen_complete, NULL); + kg_st.cwid = g_child_watch_add (kg_st.pid, keygen_childwatch, NULL); - kg_st.started = time(NULL); + kg_st.started = time (NULL); return; } /* child */ - err = otrl_privkey_generate(otr_state,filename,accname,PROTOCOLID); - write(fds[1],&err,sizeof(err)); + err = otrl_privkey_generate (otr_state, filename, accname, PROTOCOLID); + write (fds[1], &err, sizeof(err)); //g_free(filename); - _exit(0); + _exit (0); } /* * Abort ongoing key generation. */ -void keygen_abort(int ignoreidle) +void keygen_abort (int ignoreidle) { - if (kg_st.status!=KEYGEN_RUNNING) { + if (kg_st.status != KEYGEN_RUNNING) + { if (!ignoreidle) - otr_noticest(TXT_KG_NOABORT); + otr_noticest (TXT_KG_NOABORT); return; } - otr_noticest(TXT_KG_ABORT,kg_st.accountname); + otr_noticest (TXT_KG_ABORT, kg_st.accountname); - g_source_remove(kg_st.cpid); - g_source_remove(kg_st.cwid); - g_free(kg_st.accountname); + g_source_remove (kg_st.cpid); + g_source_remove (kg_st.cwid); + g_free (kg_st.accountname); - if (kg_st.pid!=0) { - kill(kg_st.pid,SIGTERM); - g_child_watch_add(kg_st.pid,keygen_childwatch,(void*)1); + if (kg_st.pid != 0) + { + kill (kg_st.pid, SIGTERM); + g_child_watch_add (kg_st.pid, keygen_childwatch, (void *)1); } kg_st.status = KEYGEN_NO; @@ -233,70 +253,80 @@ void keygen_abort(int ignoreidle) /* * Write fingerprints to file. */ -void otr_writefps() +void otr_writefps () { gcry_error_t err; - char *filename = g_strconcat(get_irssi_dir(),FPSFILE,NULL); + char *filename = g_strconcat (get_irssi_dir (), FPSFILE, NULL); - err = otrl_privkey_write_fingerprints(otr_state,filename); + err = otrl_privkey_write_fingerprints (otr_state, filename); - if (err == GPG_ERR_NO_ERROR) { - otr_noticest(TXT_FP_SAVED); - } else { - otr_noticest(TXT_FP_SAVE_ERROR, - gcry_strerror(err), - gcry_strsource(err)); + if (err == GPG_ERR_NO_ERROR) + { + otr_noticest (TXT_FP_SAVED); + } + else + { + otr_noticest (TXT_FP_SAVE_ERROR, + gcry_strerror (err), + gcry_strsource (err)); } - g_free(filename); + g_free (filename); } /* * Load private keys. */ -void key_load() +void key_load () { gcry_error_t err; - char *filename = g_strconcat(get_irssi_dir(),KEYFILE,NULL); + char *filename = g_strconcat (get_irssi_dir (), KEYFILE, NULL); - if (!g_file_test(filename, G_FILE_TEST_EXISTS)) { - otr_noticest(TXT_KEY_NOT_FOUND); + if (!g_file_test (filename, G_FILE_TEST_EXISTS)) + { + otr_noticest (TXT_KEY_NOT_FOUND); return; } - err = otrl_privkey_read(otr_state, filename); + err = otrl_privkey_read (otr_state, filename); - if (err == GPG_ERR_NO_ERROR) { - otr_noticest(TXT_KEY_LOADED); - } else { - otr_noticest(TXT_KEY_LOAD_ERROR, - gcry_strerror(err), - gcry_strsource(err)); + if (err == GPG_ERR_NO_ERROR) + { + otr_noticest (TXT_KEY_LOADED); } - g_free(filename); + else + { + otr_noticest (TXT_KEY_LOAD_ERROR, + gcry_strerror (err), + gcry_strsource (err)); + } + g_free (filename); } /* * Load fingerprints. */ -void fps_load() +void fps_load () { gcry_error_t err; - char *filename = g_strconcat(get_irssi_dir(),FPSFILE,NULL); + char *filename = g_strconcat (get_irssi_dir (), FPSFILE, NULL); - if (!g_file_test(filename, G_FILE_TEST_EXISTS)) { - otr_noticest(TXT_FP_NOT_FOUND); + if (!g_file_test (filename, G_FILE_TEST_EXISTS)) + { + otr_noticest (TXT_FP_NOT_FOUND); return; } - err = otrl_privkey_read_fingerprints(otr_state,filename,NULL,NULL); + err = otrl_privkey_read_fingerprints (otr_state, filename, NULL, NULL); - if (err == GPG_ERR_NO_ERROR) { - otr_noticest(TXT_FP_LOADED); - } else { - otr_noticest(TXT_FP_LOAD_ERROR, - gcry_strerror(err), - gcry_strsource(err)); + if (err == GPG_ERR_NO_ERROR) + { + otr_noticest (TXT_FP_LOADED); + } + else + { + otr_noticest (TXT_FP_LOAD_ERROR, + gcry_strerror (err), + gcry_strsource (err)); } - g_free(filename); + g_free (filename); } - diff --git a/src/otr_ops.c b/src/otr_ops.c index fd81cb1..9f91aab 100644 --- a/src/otr_ops.c +++ b/src/otr_ops.c @@ -21,55 +21,56 @@ OtrlMessageAppOps otr_ops; extern OtrlUserState otr_state; -extern GSList *plistunknown,*plistknown; +extern GSList *plistunknown, *plistknown; -OtrlPolicy IO_DEFAULT_OTR_POLICY = - OTRL_POLICY_MANUAL|OTRL_POLICY_WHITESPACE_START_AKE; +OtrlPolicy IO_DEFAULT_OTR_POLICY = OTRL_POLICY_MANUAL | OTRL_POLICY_WHITESPACE_START_AKE; /* * Return policy for given context based on the otr_policy /setting */ -OtrlPolicy ops_policy(void *opdata, ConnContext *context) +OtrlPolicy ops_policy (void *opdata, ConnContext *context) { struct co_info *coi = context->app_data; - char *server = strchr(context->accountname,'@')+1; + char *server = strchr (context->accountname, '@') + 1; OtrlPolicy op = IO_DEFAULT_OTR_POLICY; GSList *pl; char fullname[1024]; - sprintf(fullname, "%s@%s", context->username, server); + sprintf (fullname, "%s@%s", context->username, server); /* loop through otr_policy */ - if (plistunknown) { + if (plistunknown) + { pl = plistunknown; - do { + do + { struct plistentry *ple = pl->data; - if (g_pattern_match_string(ple->namepat,fullname)) + if (g_pattern_match_string (ple->namepat, fullname)) op = ple->policy; - } while ((pl = g_slist_next(pl))); + } while ((pl = g_slist_next (pl))); } - if (plistknown&&context->fingerprint_root.next) { + if (plistknown && context->fingerprint_root.next) + { pl = plistknown; /* loop through otr_policy_known */ - do { + do + { struct plistentry *ple = pl->data; - if (g_pattern_match_string(ple->namepat,fullname)) + if (g_pattern_match_string (ple->namepat, fullname)) op = ple->policy; - } while ((pl = g_slist_next(pl))); + } while ((pl = g_slist_next (pl))); } - if (coi && coi->finished && - (op == OTRL_POLICY_OPPORTUNISTIC || - op == OTRL_POLICY_ALWAYS)) - op = OTRL_POLICY_MANUAL|OTRL_POLICY_WHITESPACE_START_AKE; + if (coi && coi->finished && (op == OTRL_POLICY_OPPORTUNISTIC || op == OTRL_POLICY_ALWAYS)) + op = OTRL_POLICY_MANUAL | OTRL_POLICY_WHITESPACE_START_AKE; return op; } @@ -79,10 +80,10 @@ OtrlPolicy ops_policy(void *opdata, ConnContext *context) * Since this can take more than an hour on some systems there isn't even * a point in trying... */ -void ops_create_privkey(void *opdata, const char *accountname, - const char *protocol) +void ops_create_privkey (void *opdata, const char *accountname, + const char *protocol) { - keygen_run(accountname); + keygen_run (accountname); } /* @@ -90,26 +91,28 @@ void ops_create_privkey(void *opdata, const char *accountname, * Deriving the server is currently a hack, * need to derive the server from accountname. */ -void ops_inject_msg(void *opdata, const char *accountname, - const char *protocol, const char *recipient, const char *message) +void ops_inject_msg (void *opdata, const char *accountname, + const char *protocol, const char *recipient, const char *message) { IRC_CTX *a_serv; - char *msgcopy = g_strdup(message); + char *msgcopy = g_strdup (message); /* OTR sometimes gives us multiple lines * (e.g. the default query (a.k.a. "better") message) */ - g_strdelimit (msgcopy,"\n",' '); + g_strdelimit (msgcopy, "\n", ' '); a_serv = opdata; - if (!a_serv) { - otr_notice(a_serv,recipient,TXT_OPS_INJECT, - accountname,recipient,message); - } else { - irc_send_message(a_serv, recipient, msgcopy); + if (!a_serv) + { + otr_notice (a_serv, recipient, TXT_OPS_INJECT, + accountname, recipient, message); } - g_free(msgcopy); + else + { + irc_send_message (a_serv, recipient, msgcopy); + } + g_free (msgcopy); } - #if 0 /* * OTR notification. Haven't seen one yet. @@ -134,89 +137,88 @@ void ops_notify(void *opdata, OtrlNotifyLevel level, const char *accountname, #endif /* This is kind of messy. */ -const char *convert_otr_msg(const char *msg) +const char *convert_otr_msg (const char *msg) { - GRegex *regex_bold = g_regex_new("]*)?>",0,0,NULL); - GRegex *regex_del = g_regex_new("]*)?>",0,0,NULL); - gchar *msgnohtml = - g_regex_replace_literal(regex_del,msg,-1,0,"",0,NULL); + GRegex *regex_bold = g_regex_new ("]*)?>", 0, 0, NULL); + GRegex *regex_del = g_regex_new ("]*)?>", 0, 0, NULL); + gchar *msgnohtml = g_regex_replace_literal (regex_del, msg, -1, 0, "", 0, NULL); - msg = g_regex_replace_literal(regex_bold,msgnohtml,-1,0,"*",0,NULL); + msg = g_regex_replace_literal (regex_bold, msgnohtml, -1, 0, "*", 0, NULL); - g_free(msgnohtml); - g_regex_unref(regex_del); - g_regex_unref(regex_bold); + g_free (msgnohtml); + g_regex_unref (regex_del); + g_regex_unref (regex_bold); return msg; } -void ops_handle_msg(void *opdata, OtrlMessageEvent msg_event, - ConnContext *co, const char *msg, - gcry_error_t err) +void ops_handle_msg (void *opdata, OtrlMessageEvent msg_event, + ConnContext *co, const char *msg, + gcry_error_t err) { IRC_CTX *server = opdata; struct co_info *coi; - if (co) { + if (co) + { coi = co->app_data; server = coi->ircctx; - } else - otr_notice(server, co->username, TXT_OPS_DISPLAY_BUG); + } + else + otr_notice (server, co->username, TXT_OPS_DISPLAY_BUG); - msg = convert_otr_msg(msg); - otr_notice(server, co->username, TXT_OPS_DISPLAY, msg); - g_free((char*)msg); + msg = convert_otr_msg (msg); + otr_notice (server, co->username, TXT_OPS_DISPLAY, msg); + g_free ((char *)msg); } /* * Gone secure. */ -void ops_secure(void *opdata, ConnContext *context) +void ops_secure (void *opdata, ConnContext *context) { struct co_info *coi = context->app_data; - char * trust = context->active_fingerprint->trust ? : ""; - char ownfp[45],peerfp[45]; + char *trust = context->active_fingerprint->trust ?: ""; + char ownfp[45], peerfp[45]; - otr_notice(coi->ircctx, - context->username,TXT_OPS_SEC); - if (*trust!='\0') + otr_notice (coi->ircctx, + context->username, TXT_OPS_SEC); + if (*trust != '\0') return; /* not authenticated. * Let's print out the fingerprints for comparison */ - otrl_privkey_hash_to_human(peerfp, - context->active_fingerprint->fingerprint); + otrl_privkey_hash_to_human (peerfp, + context->active_fingerprint->fingerprint); - otr_notice(coi->ircctx,context->username,TXT_OPS_FPCOMP, - otrl_privkey_fingerprint(otr_state, - ownfp, - context->accountname, - PROTOCOLID), - context->username, - peerfp); + otr_notice (coi->ircctx, context->username, TXT_OPS_FPCOMP, + otrl_privkey_fingerprint (otr_state, + ownfp, + context->accountname, + PROTOCOLID), + context->username, + peerfp); } /* * Gone insecure. */ -void ops_insecure(void *opdata, ConnContext *context) +void ops_insecure (void *opdata, ConnContext *context) { struct co_info *coi = context->app_data; - otr_notice(coi->ircctx, - context->username,TXT_OPS_INSEC); + otr_notice (coi->ircctx, + context->username, TXT_OPS_INSEC); } /* * Still secure? Need to find out what that means... */ -void ops_still_secure(void *opdata, ConnContext *context, int is_reply) +void ops_still_secure (void *opdata, ConnContext *context, int is_reply) { struct co_info *coi = context->app_data; - otr_notice(coi->ircctx, - context->username,is_reply ? - TXT_OPS_STILL_REPLY : - TXT_OPS_STILL_NO_REPLY); + otr_notice (coi->ircctx, + context->username, is_reply ? TXT_OPS_STILL_REPLY : TXT_OPS_STILL_NO_REPLY); } /* @@ -224,7 +226,7 @@ void ops_still_secure(void *opdata, ConnContext *context, int is_reply) * Unfortunately, we can't tell our peer which size to use. * (reminds me of MTU determination...) */ -int ops_max_msg(void *opdata, ConnContext *context) +int ops_max_msg (void *opdata, ConnContext *context) { return OTR_MAX_MSG_SIZE; } @@ -233,21 +235,21 @@ int ops_max_msg(void *opdata, ConnContext *context) * A context changed. * I believe this is not happening for the SMP expects. */ -void ops_up_ctx_list(void *opdata) +void ops_up_ctx_list (void *opdata) { - statusbar_items_redraw("otr"); + statusbar_items_redraw ("otr"); } /* * Save fingerprint changes. */ -void ops_writefps(void *data) +void ops_writefps (void *data) { - otr_writefps(); + otr_writefps (); } -int ops_is_logged_in(void *opdata, const char *accountname, - const char *protocol, const char *recipient) +int ops_is_logged_in (void *opdata, const char *accountname, + const char *protocol, const char *recipient) { /*TODO register a handler for event 401 no such nick and set * a variable offline=TRUE. Reset it to false in otr_receive and @@ -258,8 +260,9 @@ int ops_is_logged_in(void *opdata, const char *accountname, /* * Initialize our OtrlMessageAppOps */ -void otr_initops() { - memset(&otr_ops,0,sizeof(otr_ops)); +void otr_initops () +{ + memset (&otr_ops, 0, sizeof(otr_ops)); otr_ops.policy = ops_policy; otr_ops.create_privkey = ops_create_privkey; diff --git a/src/otr_util.c b/src/otr_util.c index 9f179f7..02caea8 100644 --- a/src/otr_util.c +++ b/src/otr_util.c @@ -31,87 +31,89 @@ GRegex *regex_policies = NULL; /* * init otr lib. */ -int otrlib_init() +int otrlib_init () { - if (!otrinited) { + if (!otrinited) + { OTRL_INIT; otrinited = TRUE; } - otr_state = otrl_userstate_create(); + otr_state = otrl_userstate_create (); /* load keys and fingerprints */ - key_load(); - fps_load(); + key_load (); + fps_load (); - otr_initops(); + otr_initops (); - regex_policies = - g_regex_new("([^,]+) (never|manual|handlews|opportunistic|always)" - "(,|$)",0,0,NULL); + regex_policies = g_regex_new ("([^,]+) (never|manual|handlews|opportunistic|always)" + "(,|$)", + 0, 0, NULL); - return otr_state==NULL; + return otr_state == NULL; } /* * deinit otr lib. */ -void otrlib_deinit() +void otrlib_deinit () { - if (otr_state) { - otr_writefps(); - otrl_userstate_free(otr_state); + if (otr_state) + { + otr_writefps (); + otrl_userstate_free (otr_state); otr_state = NULL; } - keygen_abort(TRUE); + keygen_abort (TRUE); - otr_setpolicies("",FALSE); - otr_setpolicies("",TRUE); + otr_setpolicies ("", FALSE); + otr_setpolicies ("", TRUE); - g_regex_unref(regex_policies); + g_regex_unref (regex_policies); } - /* * Free our app data. */ -void context_free_app_info(void *data) +void context_free_app_info (void *data) { struct co_info *coi = data; - if (coi->msgqueue) { - g_free(coi->msgqueue); + if (coi->msgqueue) + { + g_free (coi->msgqueue); } if (coi->ircctx) - IRCCTX_FREE(coi->ircctx); + IRCCTX_FREE (coi->ircctx); } /* * Add app data to context. * See struct co_info for details. */ -void context_add_app_info(void *data,ConnContext *co) +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)); + IRC_CTX *ircctx = IRCCTX_DUP (data); + struct co_info *coi = g_malloc (sizeof(struct co_info)); - memset(coi,0,sizeof(struct co_info)); + 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); + sprintf (coi->better_msg_two, formats[TXT_OTR_BETTER_TWO].def, co->accountname); } /* * Get a context from a pair. */ -ConnContext *otr_getcontext(const char *accname,const char *nick, - int create,void *data) +ConnContext *otr_getcontext (const char *accname, const char *nick, + int create, void *data) { - ConnContext *co = otrl_context_find( + ConnContext *co = otrl_context_find ( otr_state, nick, accname, @@ -123,8 +125,8 @@ ConnContext *otr_getcontext(const char *accname,const char *nick, data); /* context came from a fingerprint */ - if (co&&data&&!co->app_data) - context_add_app_info(data,co); + if (co && data && !co->app_data) + context_add_app_info (data, co); return co; } @@ -134,28 +136,29 @@ ConnContext *otr_getcontext(const char *accname,const char *nick, * Returns NULL if OTR handled the message and * the original message otherwise. */ -char *otr_send(IRC_CTX *ircctx, const char *msg,const char *to) +char *otr_send (IRC_CTX *ircctx, const char *msg, const char *to) { - const char *nick = IRCCTX_NICK(ircctx); - const char *address = IRCCTX_ADDR(ircctx); + 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); + sprintf (accname, "%s@%s", nick, address); - if (!(co = otr_getcontext(accname,to,FALSE,ircctx))) { - otr_notice(ircctx,to,TXT_SEND_CHANGE); + if (!(co = otr_getcontext (accname, to, FALSE, ircctx))) + { + otr_notice (ircctx, to, TXT_SEND_CHANGE); return NULL; } - err = otrl_message_sending( - otr_state, - &otr_ops, - ircctx, + err = otrl_message_sending ( + otr_state, + &otr_ops, + ircctx, accname, - PROTOCOLID, + PROTOCOLID, to, OTRL_INSTAG_BEST, msg, @@ -163,64 +166,77 @@ char *otr_send(IRC_CTX *ircctx, const char *msg,const char *to) &newmessage, OTRL_FRAGMENT_SEND_ALL, &co, - context_add_app_info, + context_add_app_info, ircctx); - if (err != 0) { - otr_notice(ircctx,to,TXT_SEND_FAILED,msg); + if (err != 0) + { + otr_notice (ircctx, to, TXT_SEND_FAILED, msg); return NULL; } - if (newmessage==NULL) - return (char*)msg; + if (newmessage == NULL) + return (char *)msg; return NULL; } -struct ctxlist_ *otr_contexts() { +struct ctxlist_ *otr_contexts () +{ ConnContext *context; Fingerprint *fprint; struct ctxlist_ *ctxlist = NULL, *ctxhead = NULL; - struct fplist_ *fplist,*fphead; + struct fplist_ *fplist, *fphead; char fp[41]; char *trust; int i; - for(context = otr_state->context_root; context; - context = context->next) { + for (context = otr_state->context_root; context; + context = context->next) + { if (!ctxlist) - ctxhead = ctxlist = g_malloc0(sizeof(struct ctxlist_)); + ctxhead = ctxlist = g_malloc0 (sizeof(struct ctxlist_)); else - ctxlist = ctxlist->next = g_malloc0(sizeof(struct - ctxlist_)); - switch (context->msgstate) { - case OTRL_MSGSTATE_PLAINTEXT: ctxlist->state = STUNENCRYPTED;break; - case OTRL_MSGSTATE_ENCRYPTED: ctxlist->state = STENCRYPTED;break; - case OTRL_MSGSTATE_FINISHED: ctxlist->state = STFINISHED;break; - default: ctxlist->state = STUNKNOWN;break; + ctxlist = ctxlist->next = g_malloc0 (sizeof(struct + ctxlist_)); + switch (context->msgstate) + { + case OTRL_MSGSTATE_PLAINTEXT: + ctxlist->state = STUNENCRYPTED; + break; + case OTRL_MSGSTATE_ENCRYPTED: + ctxlist->state = STENCRYPTED; + break; + case OTRL_MSGSTATE_FINISHED: + ctxlist->state = STFINISHED; + 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) { + fprint = fprint->next) + { if (!fplist) - fphead = fplist = g_malloc0(sizeof(struct - 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]); - fplist->fp = g_strdup(fp); - if (*trust=='\0') + 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]); + fplist->fp = g_strdup (fp); + 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; } @@ -232,33 +248,37 @@ struct ctxlist_ *otr_contexts() { /* * Get the OTR status of this conversation. */ -int otr_getstatus(char *mynick, char *nick, char *server) +int otr_getstatus (char *mynick, char *nick, char *server) { ConnContext *co; char accname[128]; - sprintf(accname, "%s@%s", mynick, server); + sprintf (accname, "%s@%s", mynick, server); - if (!(co = otr_getcontext(accname,nick,FALSE,NULL))) { + if (!(co = otr_getcontext (accname, nick, FALSE, NULL))) + { return 0; } - switch (co->msgstate) { + switch (co->msgstate) + { case OTRL_MSGSTATE_PLAINTEXT: return TXT_ST_PLAINTEXT; - case OTRL_MSGSTATE_ENCRYPTED: { + case OTRL_MSGSTATE_ENCRYPTED: + { char *trust = co->active_fingerprint->trust; int ex = co->smstate->nextExpected; - if (trust&&(*trust!='\0')) - return strcmp(trust,"smp")==0 ? TXT_ST_TRUST_SMP : TXT_ST_TRUST_MANUAL; + if (trust && (*trust != '\0')) + return strcmp (trust, "smp") == 0 ? TXT_ST_TRUST_SMP : TXT_ST_TRUST_MANUAL; - switch (ex) { + switch (ex) + { case OTRL_SMP_EXPECT1: return TXT_ST_UNTRUSTED; case OTRL_SMP_EXPECT2: return TXT_ST_SMP_WAIT_2; - case OTRL_SMP_EXPECT3: + case OTRL_SMP_EXPECT3: case OTRL_SMP_EXPECT4: return TXT_ST_SMP_FINALIZE; default: @@ -275,119 +295,127 @@ int otr_getstatus(char *mynick, char *nick, char *server) /* * 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]; struct co_info *coi; char *pserver = NULL; - if (peername) { - pserver = strchr(peername,'@'); + if (peername) + { + pserver = strchr (peername, '@'); if (!pserver) return; - ircctx = server_find_address(pserver+1); + ircctx = server_find_address (pserver + 1); if (!ircctx) return; *pserver = '\0'; - nick = (char*)peername; + nick = (char *)peername; } - sprintf((char*)accname, "%s@%s", IRCCTX_NICK(ircctx), IRCCTX_ADDR(ircctx)); + sprintf ((char *)accname, "%s@%s", IRCCTX_NICK (ircctx), IRCCTX_ADDR (ircctx)); - if (!(co = otr_getcontext(accname,nick,FALSE,NULL))) { + if (!(co = otr_getcontext (accname, nick, FALSE, NULL))) + { if (inquery) - otr_noticest(TXT_CTX_NOT_FOUND, - accname,nick); + otr_noticest (TXT_CTX_NOT_FOUND, + accname, nick); if (peername) *pserver = '@'; return; } - otrl_message_disconnect(otr_state,&otr_ops,ircctx,accname, - PROTOCOLID,nick,OTRL_INSTAG_BEST); + otrl_message_disconnect (otr_state, &otr_ops, ircctx, accname, + PROTOCOLID, nick, OTRL_INSTAG_BEST); - if (inquery) { - otr_info(ircctx,nick,TXT_CMD_FINISH,nick,IRCCTX_ADDR(ircctx)); - } else { - otr_infost(TXT_CMD_FINISH,nick,IRCCTX_ADDR(ircctx)); + if (inquery) + { + otr_info (ircctx, nick, TXT_CMD_FINISH, nick, IRCCTX_ADDR (ircctx)); + } + else + { + otr_infost (TXT_CMD_FINISH, nick, IRCCTX_ADDR (ircctx)); } coi = co->app_data; /* 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; if (peername) *pserver = '@'; } -void otr_finishall() +void otr_finishall () { ConnContext *context; - int finished=0; + int finished = 0; - for(context = otr_state->context_root; context; - context = context->next) { + for (context = otr_state->context_root; context; + 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(otr_state,&otr_ops,coi->ircctx, - context->accountname, - PROTOCOLID, - context->username, - OTRL_INSTAG_BEST); + otrl_message_disconnect (otr_state, &otr_ops, coi->ircctx, + context->accountname, + PROTOCOLID, + context->username, + OTRL_INSTAG_BEST); - otr_infost(TXT_CMD_FINISH,context->username, - IRCCTX_ADDR(coi->ircctx)); + otr_infost (TXT_CMD_FINISH, context->username, + IRCCTX_ADDR (coi->ircctx)); finished++; } if (!finished) - otr_infost(TXT_CMD_FINISHALL_NONE); + otr_infost (TXT_CMD_FINISHALL_NONE); } /* * Trust our peer. */ -void otr_trust(IRC_CTX *ircctx, char *nick, const char *peername) +void otr_trust (IRC_CTX *ircctx, char *nick, const char *peername) { ConnContext *co; char accname[128]; struct co_info *coi; char *pserver = NULL; - if (peername) { - pserver = strchr(peername,'@'); + if (peername) + { + pserver = strchr (peername, '@'); if (!pserver) return; - ircctx = server_find_address(pserver+1); + ircctx = server_find_address (pserver + 1); if (!ircctx) return; *pserver = '\0'; - nick = (char*)peername; + nick = (char *)peername; } - sprintf((char*)accname, "%s@%s", IRCCTX_NICK(ircctx), IRCCTX_ADDR(ircctx)); + sprintf ((char *)accname, "%s@%s", IRCCTX_NICK (ircctx), IRCCTX_ADDR (ircctx)); - if (!(co = otr_getcontext(accname,nick,FALSE,NULL))) { - otr_noticest(TXT_CTX_NOT_FOUND, - accname,nick); + if (!(co = otr_getcontext (accname, nick, FALSE, NULL))) + { + otr_noticest (TXT_CTX_NOT_FOUND, + accname, nick); if (peername) *pserver = '@'; return; } - otrl_context_set_trust(co->active_fingerprint,"manual"); + otrl_context_set_trust (co->active_fingerprint, "manual"); coi = co->app_data; coi->smp_failed = FALSE; - otr_notice(ircctx,nick,TXT_FP_TRUST,nick); + otr_notice (ircctx, nick, TXT_FP_TRUST, nick); if (peername) *pserver = '@'; @@ -396,7 +424,7 @@ void otr_trust(IRC_CTX *ircctx, char *nick, const char *peername) /* * Abort any ongoing SMP authentication. */ -void otr_abort_auth(ConnContext *co, IRC_CTX *ircctx, const char *nick) +void otr_abort_auth (ConnContext *co, IRC_CTX *ircctx, const char *nick) { struct co_info *coi; @@ -404,45 +432,45 @@ 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); + otr_notice (ircctx, nick, + co->smstate->nextExpected != OTRL_SMP_EXPECT1 ? TXT_AUTH_ABORTED_ONGOING : TXT_AUTH_ABORTED); - otrl_message_abort_smp(otr_state,&otr_ops,ircctx,co); + otrl_message_abort_smp (otr_state, &otr_ops, ircctx, co); } /* * implements /otr authabort */ -void otr_authabort(IRC_CTX *ircctx, char *nick, const char *peername) +void otr_authabort (IRC_CTX *ircctx, char *nick, const char *peername) { ConnContext *co; char accname[128]; char *pserver = NULL; - if (peername) { - pserver = strchr(peername,'@'); + if (peername) + { + pserver = strchr (peername, '@'); if (!pserver) return; - ircctx = server_find_address(pserver+1); + ircctx = server_find_address (pserver + 1); if (!ircctx) return; *pserver = '\0'; - nick = (char*)peername; + nick = (char *)peername; } - sprintf((char*)accname, "%s@%s", IRCCTX_NICK(ircctx), IRCCTX_ADDR(ircctx)); + sprintf ((char *)accname, "%s@%s", IRCCTX_NICK (ircctx), IRCCTX_ADDR (ircctx)); - if (!(co = otr_getcontext(accname,nick,FALSE,NULL))) { - otr_noticest(TXT_CTX_NOT_FOUND, - accname,nick); + if (!(co = otr_getcontext (accname, nick, FALSE, NULL))) + { + otr_noticest (TXT_CTX_NOT_FOUND, + accname, nick); if (peername) *pserver = '@'; return; } - otr_abort_auth(co,ircctx,nick); + otr_abort_auth (co, ircctx, nick); if (peername) *pserver = '@'; @@ -451,79 +479,82 @@ void otr_authabort(IRC_CTX *ircctx, char *nick, const char *peername) /* * Initiate or respond to SMP authentication. */ -void otr_auth(IRC_CTX *ircctx, char *nick, const char *peername, const char *secret) +void otr_auth (IRC_CTX *ircctx, char *nick, const char *peername, const char *secret) { ConnContext *co; char accname[128]; struct co_info *coi; char *pserver = NULL; - if (peername) { - pserver = strchr(peername,'@'); + if (peername) + { + pserver = strchr (peername, '@'); if (!pserver) return; - ircctx = server_find_address(pserver+1); + ircctx = server_find_address (pserver + 1); if (!ircctx) return; *pserver = '\0'; - nick = (char*)peername; + nick = (char *)peername; } - sprintf((char*)accname, "%s@%s", IRCCTX_NICK(ircctx), IRCCTX_ADDR(ircctx)); + sprintf ((char *)accname, "%s@%s", IRCCTX_NICK (ircctx), IRCCTX_ADDR (ircctx)); - if (!(co = otr_getcontext(accname,nick,FALSE,NULL))) { - otr_noticest(TXT_CTX_NOT_FOUND, - accname,nick); + if (!(co = otr_getcontext (accname, nick, FALSE, NULL))) + { + otr_noticest (TXT_CTX_NOT_FOUND, + accname, nick); if (peername) *pserver = '@'; return; } - if (co->msgstate!=OTRL_MSGSTATE_ENCRYPTED) { - otr_notice(ircctx,nick,TXT_AUTH_NEEDENC); + if (co->msgstate != OTRL_MSGSTATE_ENCRYPTED) + { + otr_notice (ircctx, nick, TXT_AUTH_NEEDENC); return; } coi = co->app_data; /* Aborting an ongoing auth */ - if (co->smstate->nextExpected!=OTRL_SMP_EXPECT1) - otr_abort_auth(co,ircctx,nick); + if (co->smstate->nextExpected != OTRL_SMP_EXPECT1) + otr_abort_auth (co, ircctx, nick); coi->smp_failed = FALSE; /* reset trust level */ - if (co->active_fingerprint) { + if (co->active_fingerprint) + { char *trust = co->active_fingerprint->trust; - if (trust&&(*trust!='\0')) { - otrl_context_set_trust(co->active_fingerprint, ""); - otr_writefps(); + if (trust && (*trust != '\0')) + { + otrl_context_set_trust (co->active_fingerprint, ""); + otr_writefps (); } } if (!coi->received_smp_init) - otrl_message_initiate_smp( - otr_state, + otrl_message_initiate_smp ( + otr_state, &otr_ops, ircctx, co, - (unsigned char*)secret, - strlen(secret)); + (unsigned char *)secret, + strlen (secret)); else - otrl_message_respond_smp( + otrl_message_respond_smp ( otr_state, &otr_ops, ircctx, co, - (unsigned char*)secret, - strlen(secret)); + (unsigned char *)secret, + strlen (secret)); - 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); - statusbar_items_redraw("otr"); + statusbar_items_redraw ("otr"); if (peername) *pserver = '@'; @@ -533,55 +564,70 @@ void otr_auth(IRC_CTX *ircctx, char *nick, const char *peername, const char *sec * 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); + 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); abort = TRUE; - } else { - otr_notice(ircctx,from,TXT_AUTH_PEER, - from); + } + else + { + otr_notice (ircctx, from, TXT_AUTH_PEER, + from); coi->received_smp_init = TRUE; } } - 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); + 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); abort = TRUE; - } else { - otr_notice(ircctx,from, - TXT_AUTH_PEER_REPLIED, - from); + } + else + { + otr_notice (ircctx, from, + TXT_AUTH_PEER_REPLIED, + from); co->smstate->nextExpected = OTRL_SMP_EXPECT4; } } - 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); + 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); abort = TRUE; - } else { + } + else + { char *trust = co->active_fingerprint->trust; - if (trust&&(*trust!='\0')) { - otr_notice(ircctx,from, - TXT_AUTH_SUCCESSFUL); - } else { - otr_notice(ircctx,from, - TXT_AUTH_FAILED); + if (trust && (*trust != '\0')) + { + otr_notice (ircctx, from, + TXT_AUTH_SUCCESSFUL); + } + else + { + otr_notice (ircctx, from, + TXT_AUTH_FAILED); coi->smp_failed = TRUE; } co->smstate->nextExpected = OTRL_SMP_EXPECT1; @@ -589,23 +635,30 @@ 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); + 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); abort = TRUE; - } else { + } + else + { char *trust = co->active_fingerprint->trust; - if (trust&&(*trust!='\0')) { - otr_notice(ircctx,from, - TXT_AUTH_SUCCESSFUL); - } else { + if (trust && (*trust != '\0')) + { + otr_notice (ircctx, from, + TXT_AUTH_SUCCESSFUL); + } + 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; } co->smstate->nextExpected = OTRL_SMP_EXPECT1; @@ -613,13 +666,13 @@ void otr_handle_tlvs(OtrlTLV *tlvs, ConnContext *co, } } if (abort) - otr_abort_auth(co,ircctx,from); + otr_abort_auth (co, ircctx, from); - tlv = otrl_tlv_find(tlvs, OTRL_TLV_DISCONNECTED); + tlv = otrl_tlv_find (tlvs, OTRL_TLV_DISCONNECTED); if (tlv) - otr_notice(ircctx,from,TXT_PEER_FINISHED,from); + otr_notice (ircctx, from, TXT_PEER_FINISHED, from); - statusbar_items_redraw("otr"); + statusbar_items_redraw ("otr"); } /* @@ -627,7 +680,7 @@ void otr_handle_tlvs(OtrlTLV *tlvs, ConnContext *co, * Returns NULL if its an OTR protocol message and * the (possibly) decrypted message otherwise. */ -char *otr_receive(IRC_CTX *ircctx, const char *msg,const char *from) +char *otr_receive (IRC_CTX *ircctx, const char *msg, const char *from) { int ignore_message; char *newmessage = NULL; @@ -636,11 +689,12 @@ 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)); + sprintf (accname, "%s@%s", IRCCTX_NICK (ircctx), IRCCTX_ADDR (ircctx)); - if (!(co = otr_getcontext(accname,from,TRUE,ircctx))) { - otr_noticest(TXT_CTX_NOT_CREATE, - accname,from); + if (!(co = otr_getcontext (accname, from, TRUE, ircctx))) + { + otr_noticest (TXT_CTX_NOT_CREATE, + accname, from); return NULL; } @@ -649,9 +703,9 @@ char *otr_receive(IRC_CTX *ircctx, const char *msg,const char *from) /* Really lame but I don't see how you could do this in a generic * 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)) { - otr_debug(ircctx,from,TXT_RECEIVE_IGNORE_QUERY); + if ((strcmp (msg, coi->better_msg_two) == 0) || (strcmp (msg, formats[TXT_OTR_BETTER_THREE].def) == 0)) + { + otr_debug (ircctx, from, TXT_RECEIVE_IGNORE_QUERY); return NULL; } @@ -660,17 +714,16 @@ char *otr_receive(IRC_CTX *ircctx, const char *msg,const char *from) * in the message but it doesn't end with a ".", queue it and wait * for the rest. */ - if (coi->msgqueue) { /* already something in the queue */ - strcpy(coi->msgqueue+strlen(coi->msgqueue),msg); + if (coi->msgqueue) + { /* already something in the queue */ + strcpy (coi->msgqueue + strlen (coi->msgqueue), msg); /* wait for more? */ - if ((strlen(msg)>OTR_MAX_MSG_SIZE)&& - (msg[strlen(msg)-1]!='.')&& - (msg[strlen(msg)-1]!=',')) + if ((strlen (msg) > OTR_MAX_MSG_SIZE) && (msg[strlen (msg) - 1] != '.') && (msg[strlen (msg) - 1] != ',')) return NULL; - 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; @@ -678,72 +731,75 @@ char *otr_receive(IRC_CTX *ircctx, const char *msg,const char *from) /* this is freed thru our caller by otrl_message_free. * 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]!=',')) { - coi->msgqueue = malloc(4096*sizeof(char)); - strcpy(coi->msgqueue,msg); - otr_debug(ircctx,from,TXT_RECEIVE_QUEUED,strlen(msg)); + } + else if (strstr (msg, "?OTR:") && (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; } - ignore_message = otrl_message_receiving( + ignore_message = otrl_message_receiving ( otr_state, &otr_ops, ircctx, - accname, - PROTOCOLID, - from, - msg, + accname, + PROTOCOLID, + from, + msg, &newmessage, &tlvs, &co, NULL, NULL); - if (tlvs) - otr_handle_tlvs(tlvs,co,coi,ircctx,from); - - if (ignore_message) { - otr_debug(ircctx,from, - TXT_RECEIVE_IGNORE, strlen(msg),accname,from,msg); + if (tlvs) + otr_handle_tlvs (tlvs, co, coi, ircctx, from); + + if (ignore_message) + { + otr_debug (ircctx, from, + TXT_RECEIVE_IGNORE, strlen (msg), accname, from, msg); return NULL; } if (newmessage) - otr_debug(ircctx,from,TXT_RECEIVE_CONVERTED); + otr_debug (ircctx, from, TXT_RECEIVE_CONVERTED); - return newmessage ? : (char*)msg; + return newmessage ?: (char *)msg; } -void otr_setpolicies(const char *policies, int known) +void otr_setpolicies (const char *policies, int known) { GMatchInfo *match_info; GSList *plist = known ? plistknown : plistunknown; - if (plist) { + if (plist) + { GSList *p = plist; - do { + do + { struct plistentry *ple = p->data; - g_pattern_spec_free(ple->namepat); - g_free(p->data); - } while ((p = g_slist_next(p))); + g_pattern_spec_free (ple->namepat); + g_free (p->data); + } while ((p = g_slist_next (p))); - g_slist_free(plist); + g_slist_free (plist); plist = NULL; } - g_regex_match(regex_policies,policies,0,&match_info); + g_regex_match (regex_policies, policies, 0, &match_info); + + while (g_match_info_matches (match_info)) + { + struct plistentry *ple = (struct plistentry *)g_malloc0 (sizeof(struct plistentry)); + char *pol = g_match_info_fetch (match_info, 2); - while(g_match_info_matches(match_info)) { - struct plistentry *ple = (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) { + switch (*pol) + { case 'n': ple->policy = OTRL_POLICY_NEVER; break; @@ -751,7 +807,7 @@ void otr_setpolicies(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; @@ -761,14 +817,14 @@ void otr_setpolicies(const char *policies, int known) break; } - plist = g_slist_append(plist,ple); + plist = g_slist_append (plist, ple); - g_free(pol); + g_free (pol); - g_match_info_next(match_info, NULL); + g_match_info_next (match_info, NULL); } - g_match_info_free(match_info); + g_match_info_free (match_info); if (known) plistknown = plist; From b6c02dcbc9e73a16a021211ff47545c0580cf26e Mon Sep 17 00:00:00 2001 From: TingPing Date: Sat, 13 Dec 2014 07:41:19 -0500 Subject: [PATCH 06/49] Add basic help message for /otr --- src/hexchat_otr.c | 10 +++++++++- src/hexchat_otr.h | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/hexchat_otr.c b/src/hexchat_otr.c index 6c8287b..5f64eed 100644 --- a/src/hexchat_otr.c +++ b/src/hexchat_otr.c @@ -43,6 +43,12 @@ int cmd_otr (char *word[], char *word_eol[], void *userdata) char *cmd = word[2]; + if (!cmd) + { + hexchat_command(ph, "help otr"); + return HEXCHAT_EAT_ALL; + } + if (strcmp (cmd, "debug") == 0) { debug = !debug; @@ -133,6 +139,8 @@ int cmd_otr (char *word[], char *word_eol[], void *userdata) set_finishonunload ? "true" : "false"); } } + else + hexchat_command(ph, "help otr"); return HEXCHAT_EAT_ALL; } @@ -262,7 +270,7 @@ int hexchat_plugin_init (hexchat_plugin *plugin_handle, hexchat_hook_server (ph, "PRIVMSG", HEXCHAT_PRI_NORM, hook_privmsg, 0); hexchat_hook_command (ph, "", HEXCHAT_PRI_NORM, hook_outgoing, 0, 0); - hexchat_hook_command (ph, "otr", HEXCHAT_PRI_NORM, cmd_otr, 0, 0); + hexchat_hook_command (ph, "otr", HEXCHAT_PRI_NORM, cmd_otr, OTR_HELP, 0); otr_setpolicies (IO_DEFAULT_POLICY, FALSE); otr_setpolicies (IO_DEFAULT_POLICY_KNOWN, TRUE); diff --git a/src/hexchat_otr.h b/src/hexchat_otr.h index dffaeb6..029f2b9 100644 --- a/src/hexchat_otr.h +++ b/src/hexchat_otr.h @@ -6,6 +6,7 @@ #define PNAME "OTR" #define PDESC "Off-The-Record Messaging for Hexchat" #define PVERSION PACKAGE_VERSION +#define OTR_HELP "OTR " #define MAX_FORMAT_PARAMS 10 From 5215f32efb1fd34c51b5a75876260debbea58f51 Mon Sep 17 00:00:00 2001 From: TingPing Date: Sat, 13 Dec 2014 07:53:40 -0500 Subject: [PATCH 07/49] Fix unsafe string handling --- src/hexchat_otr.c | 12 ++++++------ src/otr_util.c | 8 +++++--- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/hexchat_otr.c b/src/hexchat_otr.c index 5f64eed..1f74255 100644 --- a/src/hexchat_otr.c +++ b/src/hexchat_otr.c @@ -10,14 +10,14 @@ 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) +int extract_nick (char *nick, char *line, size_t nick_size) { char *excl; if (*line++ != ':') return FALSE; - strcpy (nick, line); + g_strlcpy (nick, line, nick_size); if ((excl = strchr (nick, '!'))) *excl = '\0'; @@ -112,19 +112,19 @@ int cmd_otr (char *word[], char *word_eol[], void *userdata) if (strcmp (word[3], "policy") == 0) { otr_setpolicies (word_eol[4], FALSE); - strcpy (set_policy, word_eol[4]); + g_strlcpy (set_policy, word_eol[4], sizeof(set_policy)); } else if (strcmp (word[3], "policy_known") == 0) { otr_setpolicies (word_eol[4], TRUE); - strcpy (set_policy_known, word_eol[4]); + g_strlcpy (set_policy_known, word_eol[4], sizeof(set_policy_known)); } else if (strcmp (word[3], "ignore") == 0) { 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]); + g_strlcpy (set_ignore, word_eol[4], sizeof(set_ignore)); } else if (strcmp (word[3], "finishonunload") == 0) { @@ -195,7 +195,7 @@ int hook_privmsg (char *word[], char *word_eol[], void *userdata) char *chanmsg = word[3]; if ((*chanmsg == '&') || (*chanmsg == '#')) return HEXCHAT_EAT_NONE; - if (!extract_nick (nick, word[1])) + if (!extract_nick (nick, word[1], sizeof(nick))) return HEXCHAT_EAT_NONE; if (g_regex_match (regex_nickignore, nick, 0, NULL)) diff --git a/src/otr_util.c b/src/otr_util.c index 02caea8..de80eba 100644 --- a/src/otr_util.c +++ b/src/otr_util.c @@ -28,6 +28,8 @@ GSList *plistunknown = NULL; GSList *plistknown = NULL; GRegex *regex_policies = NULL; +#define MSGQUEUE_LEN 4096 + /* * init otr lib. */ @@ -716,7 +718,7 @@ char *otr_receive (IRC_CTX *ircctx, const char *msg, const char *from) */ if (coi->msgqueue) { /* already something in the queue */ - strcpy (coi->msgqueue + strlen (coi->msgqueue), msg); + g_strlcat (coi->msgqueue, msg, MSGQUEUE_LEN); /* wait for more? */ if ((strlen (msg) > OTR_MAX_MSG_SIZE) && (msg[strlen (msg) - 1] != '.') && (msg[strlen (msg) - 1] != ',')) @@ -734,8 +736,8 @@ char *otr_receive (IRC_CTX *ircctx, const char *msg, const char *from) } else if (strstr (msg, "?OTR:") && (strlen (msg) > OTR_MAX_MSG_SIZE) && (msg[strlen (msg) - 1] != '.') && (msg[strlen (msg) - 1] != ',')) { - coi->msgqueue = malloc (4096 * sizeof(char)); - strcpy (coi->msgqueue, msg); + coi->msgqueue = g_malloc (MSGQUEUE_LEN); + g_strlcpy (coi->msgqueue, msg, MSGQUEUE_LEN); otr_debug (ircctx, from, TXT_RECEIVE_QUEUED, strlen (msg)); return NULL; } From d975730ebed3ba5be14f6a346e33b25654150fd9 Mon Sep 17 00:00:00 2001 From: TingPing Date: Sat, 13 Dec 2014 08:14:19 -0500 Subject: [PATCH 08/49] Fix header include syntax --- src/hexchat_otr.h | 2 +- src/otr.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hexchat_otr.h b/src/hexchat_otr.h index 029f2b9..f825d13 100644 --- a/src/hexchat_otr.h +++ b/src/hexchat_otr.h @@ -1,5 +1,5 @@ #include "config.h" -#include "hexchat-plugin.h" +#include #define MODULE_NAME "otr" diff --git a/src/otr.h b/src/otr.h index bea1417..edf42af 100644 --- a/src/otr.h +++ b/src/otr.h @@ -36,7 +36,7 @@ /* hexchat */ -#include +#include "hexchat_otr.h" /* log stuff */ From f6f252d91578d5785ced6620ae36deda185d559d Mon Sep 17 00:00:00 2001 From: TingPing Date: Sat, 13 Dec 2014 08:15:09 -0500 Subject: [PATCH 09/49] Don't use libgen.h --- src/otr_key.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/otr_key.c b/src/otr_key.c index 2f22bdf..eae39e1 100644 --- a/src/otr_key.c +++ b/src/otr_key.c @@ -21,7 +21,6 @@ #include "otr.h" -#include #include #include #include @@ -150,7 +149,7 @@ void keygen_run (const char *accname) int ret; int fds[2]; char *filename = g_strconcat (get_irssi_dir (), TMPKEYFILE, NULL); - char *dir = dirname (g_strdup (filename)); + char *dir = g_path_get_dirname (filename); if (kg_st.status != KEYGEN_NO) { From dd01a83499f60ebbacdd3c4be4dbf9b03270407f Mon Sep 17 00:00:00 2001 From: TingPing Date: Sat, 13 Dec 2014 09:01:39 -0500 Subject: [PATCH 10/49] Remove extra fields from formats --- configure.ac | 2 +- src/hexchat-formats.c | 198 +++++++++++++++++++++--------------------- src/hexchat_otr.h | 3 - 3 files changed, 100 insertions(+), 103 deletions(-) diff --git a/configure.ac b/configure.ac index c03cc7f..be191ad 100644 --- a/configure.ac +++ b/configure.ac @@ -40,7 +40,7 @@ AC_SUBST([hexchatlibdir]) CFLAGS="$CFLAGS" # TODO: Improve if test "$CC" = "gcc" || test "$CC" = "clang"; then - CFLAGS="$CFLAGS -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers" + CFLAGS="$CFLAGS -Wall -Wextra -Wno-unused-parameter" fi AC_SUBST([CFLAGS]) diff --git a/src/hexchat-formats.c b/src/hexchat-formats.c index 2c54098..c20845e 100644 --- a/src/hexchat-formats.c +++ b/src/hexchat-formats.c @@ -1,102 +1,102 @@ #include "otr.h" FORMAT_REC formats[] = { - { MODULE_NAME, "otr", 0 }, - { NULL, "Keys", 0 }, - { "kg_failed", "Key generation for %s: failed: %s (%s)", 0 }, - { "kg_completed", "Key generation for %s: completed in %d seconds. Reloading keys", 0 }, - { "kg_aborted_dup", "Key generation for %s: aborted. Key generation for %s still in progress", 0 }, - { "kg_aborted_dir", "Key generation for %s: aborted, failed creating directory %s: %s", 0 }, - { "kg_mkdir", "created directory %s", 0 }, - { "kg_pipe", "Key generation for %s: error creating pipe: %s", 0 }, - { "kg_fork", "Key generation for %s: fork() error: %s", 0 }, - { "kg_initiated", "Key generation for %s: initiated. This might take several minutes or on some systems even an hour. If you wanna check that something is happening, see if there are two processes of your IRC client.", 0 }, - { "kg_exited", "Key generation for %s: child terminated for unknown reason", 0 }, - { "kg_exitsig", "Key generation for %s: child was killed by signal %s", 0 }, - { "kg_pollerr", "Key generation for %s: error poll()ing child: %s", 0 }, - { "kg_abort", "Key generation for %s: aborted", 0 }, - { "kg_needacc", "I need an account name. Try something like /otr genkey mynick@irc.server.net", 0 }, - { "kg_noabort", "No ongoing key generation to abort", 0 }, - { "key_not_found", "no private keys found", 0 }, - { "key_loaded", "private keys loaded", 0 }, - { "key_load_error", "Error loading private keys: %s (%s)", 0 }, - { NULL, "Fingerprints", 0 }, - { "fp_saved", "fingerprints saved", 0 }, - { "fp_save_error", "Error saving fingerprints: %s (%s)", 0 }, - { "fp_not_found", "no fingerprints found", 0 }, - { "fp_loaded", "fingerprints loaded", 0 }, - { "fp_load_error", "Error loading fingerprints: %s (%s)", 0 }, - { "fp_trust", "Trusting fingerprint from %s", 0 }, - { NULL, "Callbacks", 0 }, - { "ops_notify_bug", "BUG() in ops_notify", 0 }, - { "ops_notify", "title: %s prim: %s sec: %s", 0 }, - { "ops_display_bug", "BUG() in ops_display", 0 }, - { "ops_display", "msg: %s", 0 }, - { "ops_sec", "gone secure", 0 }, - { "ops_fpcomp", "Your peer is not authenticated. To make sure you're talking to the right guy you can either agree on a secret and use the authentication described in /otr auth, or use the traditional way and compare fingerprints over a secure line (e.g. telephone) and subsequently enter /otr trust. Your fingerprint is: %s. %s's fingerprint: %s", 0 }, - { "ops_insec", "gone insecure", 0 }, - { "ops_still_reply", "still secure (is reply)", 0 }, - { "ops_still_no_reply", "still secure (is not reply)", 0 }, - { "ops_log", "log msg: %s", 0 }, - { "ops_inject", "Couldn't inject message from %s for %s: %s", 0 }, - { NULL, "SendingReceiving", 0 }, - { "send_failed", "send failed: msg=%s", 0 }, - { "send_change", "couldn't find context also OTR changed the outgoing message(BUG?)", 0 }, - { "send_fragment", "failed to fragment message: msg=%s", 0 }, - { "send_converted", "OTR converted sent message to %s", 0 }, - { "receive_ignore_query", "ignoring rest of OTR default query msg", 0 }, - { "receive_dequeued", "dequeued msg of length %d", 0 }, - { "receive_queued", "queued msg of length %d", 0 }, - { "receive_ignore", "ignoring protocol message of length %d, acc=%s, from=%s: %s", 0 }, - { "receive_converted", "OTR converted received message", 0 }, - { "otr_better_two", "%s has requested an Off-the-Record private conversation. However, you do not have a plugin to support that.", 0 }, - { "otr_better_three", "See http://otr.cypherpunks.ca/ for more information.", 0 }, - { NULL, "Context", 0 }, - { "ctx_not_found", "couldn't find context: acc=%s nick=%s", 0 }, - { "ctx_not_create", "couldn't create/find context: acc=%s from=%s", 0 }, - { NULL, "Authentication", 0 }, - { "auth_aborted_ongoing", "Ongoing authentication aborted", 0 }, - { "auth_aborted", "Authentication aborted", 0 }, - { "auth_responding", "Responding to authentication request...", 0 }, - { "auth_initiated", "Initiated authentication...", 0 }, - { "auth_have_old", "%s wanted to authenticate but an old authentication was still ongoing. Old authentication will be aborted, please try again.", 0 }, - { "auth_peer", "%s wants to authenticate. Type /otr auth to complete.", 0 }, - { "auth_peer_reply_wrong", "%s replied to an auth we didn't start.", 0 }, - { "auth_peer_replied", "%s replied to our auth request...", 0 }, - { "auth_peer_wrong_smp3", "%s sent a wrong authentication message (SMP3).", 0 }, - { "auth_peer_wrong_smp4", "%s sent a wrong authentication message (SMP4).", 0 }, - { "auth_successful", "Authentication successful!", 0 }, - { "auth_failed", "Authentication failed!", 0 }, - { "auth_needenc", "You need to establish an OTR session before you can authenticate.", 0 }, - { NULL, "Commands", 0 }, - { "cmd_otr", "We're alive", 0 }, - { "cmd_qnotfound", "Failed: Can't get nick and server of current query window. (Or maybe you're doing this in the status window?)", 0 }, - { "cmd_auth", "Please agree on a secret with your peer and then initiate the authentication with /otr auth or let him initiate. Should you initiate your peer will after a little while be instructed to enter the secret as well. Once he has done so the authentication will finish up. Should you have both typed in the same secret the authentication should be successful.", 0 }, - { "cmd_debug_on", "Debug mode is on", 0 }, - { "cmd_debug_off", "Debug mode is off", 0 }, - { "cmd_finish", "Finished conversation with %s@%s.", 0 }, - { "cmd_finishall_none", "No conversations to finish.", 0 }, - { "cmd_version", "This is irssi-otr version %s", 0 }, - { "peer_finished", "%s has finished the OTR conversation. If you want to continue talking enter /otr finish for plaintext or ?OTR? to restart OTR.", 0 }, - { NULL, "Contexts", 0 }, - { "ctx_ctx_unencrypted", "%20s %30s plaintext", 0 }, - { "ctx_ctx_encrypted", "%20s %30s encrypted", 0 }, - { "ctx_ctx_finished", "%20s %30s finished", 0 }, - { "ctx_ctx_unknown", "%20s %30s unknown state(BUG?)", 0 }, - { "ctx_fps_no", "%s %rnot authenticated", 0 }, - { "ctx_fps_smp", "%s authenticated via shared secret (SMP)", 0 }, - { "ctx_fps_man", "%s authenticated manually", 0 }, - { "ctx_noctxs", "No active OTR contexts found", 0 }, - { NULL, "Statusbar", 0 }, - { "st_plaintext", "{sb plaintext}", 0 }, - { "st_untrusted", "{sb %rOTR(not auth'ed)}", 0 }, - { "st_trust_smp", "{sb OTR}", 0 }, - { "st_trust_manual", "{sb OTR}", 0 }, - { "st_smp_wait_2", "{sb {hilight awaiting auth reply...}}", 0 }, - { "st_smp_have_2", "{sb {hilight finalizing auth... (won't happen with libotr 3.1(bug), ask the other guy to initiate)}}", 0 }, - { "st_smp_failed", "{sb {hilight auth failed}}", 0 }, - { "st_smp_finalize", "{sb {hilight finalizing auth...}}", 0 }, - { "st_smp_unknown", "{sb {hilight unknown auth state!}}", 0 }, - { "st_finished", "{sb finished}", 0 }, - { "st_unknown", "{sb {hilight state unknown (BUG!)}}", 0 }, - { NULL, NULL, 0 } + { MODULE_NAME, "otr" }, + { NULL, "Keys" }, + { "kg_failed", "Key generation for %s: failed: %s (%s)" }, + { "kg_completed", "Key generation for %s: completed in %d seconds. Reloading keys" }, + { "kg_aborted_dup", "Key generation for %s: aborted. Key generation for %s still in progress" }, + { "kg_aborted_dir", "Key generation for %s: aborted, failed creating directory %s: %s" }, + { "kg_mkdir", "created directory %s" }, + { "kg_pipe", "Key generation for %s: error creating pipe: %s" }, + { "kg_fork", "Key generation for %s: fork() error: %s" }, + { "kg_initiated", "Key generation for %s: initiated. This might take several minutes or on some systems even an hour. If you wanna check that something is happening, see if there are two processes of your IRC client." }, + { "kg_exited", "Key generation for %s: child terminated for unknown reason" }, + { "kg_exitsig", "Key generation for %s: child was killed by signal %s" }, + { "kg_pollerr", "Key generation for %s: error poll()ing child: %s" }, + { "kg_abort", "Key generation for %s: aborted" }, + { "kg_needacc", "I need an account name. Try something like /otr genkey mynick@irc.server.net" }, + { "kg_noabort", "No ongoing key generation to abort" }, + { "key_not_found", "no private keys found" }, + { "key_loaded", "private keys loaded" }, + { "key_load_error", "Error loading private keys: %s (%s)" }, + { NULL, "Fingerprints" }, + { "fp_saved", "fingerprints saved" }, + { "fp_save_error", "Error saving fingerprints: %s (%s)" }, + { "fp_not_found", "no fingerprints found" }, + { "fp_loaded", "fingerprints loaded" }, + { "fp_load_error", "Error loading fingerprints: %s (%s)" }, + { "fp_trust", "Trusting fingerprint from %s" }, + { NULL, "Callbacks" }, + { "ops_notify_bug", "BUG() in ops_notify" }, + { "ops_notify", "title: %s prim: %s sec: %s" }, + { "ops_display_bug", "BUG() in ops_display" }, + { "ops_display", "msg: %s" }, + { "ops_sec", "gone secure" }, + { "ops_fpcomp", "Your peer is not authenticated. To make sure you're talking to the right guy you can either agree on a secret and use the authentication described in /otr auth, or use the traditional way and compare fingerprints over a secure line (e.g. telephone) and subsequently enter /otr trust. Your fingerprint is: %s. %s's fingerprint: %s" }, + { "ops_insec", "gone insecure" }, + { "ops_still_reply", "still secure (is reply)" }, + { "ops_still_no_reply", "still secure (is not reply)" }, + { "ops_log", "log msg: %s" }, + { "ops_inject", "Couldn't inject message from %s for %s: %s" }, + { NULL, "SendingReceiving" }, + { "send_failed", "send failed: msg=%s" }, + { "send_change", "couldn't find context also OTR changed the outgoing message(BUG?)" }, + { "send_fragment", "failed to fragment message: msg=%s" }, + { "send_converted", "OTR converted sent message to %s" }, + { "receive_ignore_query", "ignoring rest of OTR default query msg" }, + { "receive_dequeued", "dequeued msg of length %d" }, + { "receive_queued", "queued msg of length %d" }, + { "receive_ignore", "ignoring protocol message of length %d, acc=%s, from=%s: %s" }, + { "receive_converted", "OTR converted received message" }, + { "otr_better_two", "%s has requested an Off-the-Record private conversation. However, you do not have a plugin to support that." }, + { "otr_better_three", "See http://otr.cypherpunks.ca/ for more information." }, + { NULL, "Context" }, + { "ctx_not_found", "couldn't find context: acc=%s nick=%s" }, + { "ctx_not_create", "couldn't create/find context: acc=%s from=%s" }, + { NULL, "Authentication" }, + { "auth_aborted_ongoing", "Ongoing authentication aborted" }, + { "auth_aborted", "Authentication aborted" }, + { "auth_responding", "Responding to authentication request..." }, + { "auth_initiated", "Initiated authentication..." }, + { "auth_have_old", "%s wanted to authenticate but an old authentication was still ongoing. Old authentication will be aborted, please try again." }, + { "auth_peer", "%s wants to authenticate. Type /otr auth to complete." }, + { "auth_peer_reply_wrong", "%s replied to an auth we didn't start." }, + { "auth_peer_replied", "%s replied to our auth request..." }, + { "auth_peer_wrong_smp3", "%s sent a wrong authentication message (SMP3)." }, + { "auth_peer_wrong_smp4", "%s sent a wrong authentication message (SMP4)." }, + { "auth_successful", "Authentication successful!" }, + { "auth_failed", "Authentication failed!" }, + { "auth_needenc", "You need to establish an OTR session before you can authenticate." }, + { NULL, "Commands" }, + { "cmd_otr", "We're alive" }, + { "cmd_qnotfound", "Failed: Can't get nick and server of current query window. (Or maybe you're doing this in the status window?)" }, + { "cmd_auth", "Please agree on a secret with your peer and then initiate the authentication with /otr auth or let him initiate. Should you initiate your peer will after a little while be instructed to enter the secret as well. Once he has done so the authentication will finish up. Should you have both typed in the same secret the authentication should be successful." }, + { "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" }, + { "peer_finished", "%s has finished the OTR conversation. If you want to continue talking enter /otr finish for plaintext or ?OTR? to restart OTR." }, + { NULL, "Contexts" }, + { "ctx_ctx_unencrypted", "%20s %30s plaintext" }, + { "ctx_ctx_encrypted", "%20s %30s encrypted" }, + { "ctx_ctx_finished", "%20s %30s finished" }, + { "ctx_ctx_unknown", "%20s %30s unknown state(BUG?)" }, + { "ctx_fps_no", "%s %rnot authenticated" }, + { "ctx_fps_smp", "%s authenticated via shared secret (SMP)" }, + { "ctx_fps_man", "%s authenticated manually" }, + { "ctx_noctxs", "No active OTR contexts found" }, + { NULL, "Statusbar" }, + { "st_plaintext", "{sb plaintext}" }, + { "st_untrusted", "{sb %rOTR(not auth'ed)}" }, + { "st_trust_smp", "{sb OTR}" }, + { "st_trust_manual", "{sb OTR}" }, + { "st_smp_wait_2", "{sb {hilight awaiting auth reply...}}" }, + { "st_smp_have_2", "{sb {hilight finalizing auth... (won't happen with libotr 3.1(bug), ask the other guy to initiate)}}" }, + { "st_smp_failed", "{sb {hilight auth failed}}" }, + { "st_smp_finalize", "{sb {hilight finalizing auth...}}" }, + { "st_smp_unknown", "{sb {hilight unknown auth state!}}" }, + { "st_finished", "{sb finished}" }, + { "st_unknown", "{sb {hilight state unknown (BUG!)}}" }, + { NULL, NULL } }; diff --git a/src/hexchat_otr.h b/src/hexchat_otr.h index f825d13..60f826e 100644 --- a/src/hexchat_otr.h +++ b/src/hexchat_otr.h @@ -22,9 +22,6 @@ struct _FORMAT_REC { char *tag; char *def; - - int params; - int paramtypes[MAX_FORMAT_PARAMS]; }; typedef struct _FORMAT_REC FORMAT_REC; From d684c295cb2fbde64a800816d1ce295c4abff77a Mon Sep 17 00:00:00 2001 From: TingPing Date: Sat, 13 Dec 2014 09:21:48 -0500 Subject: [PATCH 11/49] More unsafe string handling --- src/hexchat_otr.c | 4 ++-- src/otr_key.c | 2 +- src/otr_ops.c | 2 +- src/otr_util.c | 17 +++++++++-------- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/hexchat_otr.c b/src/hexchat_otr.c index 1f74255..fa30894 100644 --- a/src/hexchat_otr.c +++ b/src/hexchat_otr.c @@ -328,8 +328,8 @@ void printformat (IRC_CTX *ircctx, const char *nick, int lvl, int fnum, ...) hexchat_set_context (ph, find_query_ctx); - if (vsnprintf (s, LOGMAX, formats[fnum].def, params) < 0) - sprintf (s, "internal error parsing error string (BUG)"); + if (vsnprintf (msg, sizeof(msg), formats[fnum].def, params) < 0) + g_snprintf (msg, sizeof(msg), "internal error parsing error string (BUG)"); va_end (params); hexchat_printf (ph, "OTR: %s", s); } diff --git a/src/otr_key.c b/src/otr_key.c index eae39e1..38e8353 100644 --- a/src/otr_key.c +++ b/src/otr_key.c @@ -72,7 +72,7 @@ void keygen_childwatch (GPid pid, gint status, gpointer data) { char sigstr[16]; - sprintf (sigstr, + g_snprintf (sigstr, sizeof(sigstr), #ifndef HAVE_STRSIGNAL "%d", WTERMSIG (status)); #else diff --git a/src/otr_ops.c b/src/otr_ops.c index 9f91aab..3b0146e 100644 --- a/src/otr_ops.c +++ b/src/otr_ops.c @@ -36,7 +36,7 @@ OtrlPolicy ops_policy (void *opdata, ConnContext *context) GSList *pl; char fullname[1024]; - sprintf (fullname, "%s@%s", context->username, server); + g_snprintf (fullname, sizeof(fullname), "%s@%s", context->username, server); /* loop through otr_policy */ diff --git a/src/otr_util.c b/src/otr_util.c index de80eba..d1f9a7f 100644 --- a/src/otr_util.c +++ b/src/otr_util.c @@ -106,7 +106,8 @@ void context_add_app_info (void *data, ConnContext *co) co->app_data_free = context_free_app_info; coi->ircctx = ircctx; - sprintf (coi->better_msg_two, formats[TXT_OTR_BETTER_TWO].def, co->accountname); + g_snprintf (coi->better_msg_two, sizeof(coi->better_msg_two), + formats[TXT_OTR_BETTER_TWO].def, co->accountname); } /* @@ -147,7 +148,7 @@ char *otr_send (IRC_CTX *ircctx, const char *msg, const char *to) ConnContext *co; char accname[256]; - sprintf (accname, "%s@%s", nick, address); + g_snprintf (accname, sizeof(accname), "%s@%s", nick, address); if (!(co = otr_getcontext (accname, to, FALSE, ircctx))) { @@ -255,7 +256,7 @@ int otr_getstatus (char *mynick, char *nick, char *server) ConnContext *co; char accname[128]; - sprintf (accname, "%s@%s", mynick, server); + g_snprintf (accname, sizeof(accname), "%s@%s", mynick, server); if (!(co = otr_getcontext (accname, nick, FALSE, NULL))) { @@ -316,7 +317,7 @@ void otr_finish (IRC_CTX *ircctx, char *nick, const char *peername, int inquery) nick = (char *)peername; } - sprintf ((char *)accname, "%s@%s", IRCCTX_NICK (ircctx), IRCCTX_ADDR (ircctx)); + g_snprintf (accname, sizeof(accname), "%s@%s", IRCCTX_NICK (ircctx), IRCCTX_ADDR (ircctx)); if (!(co = otr_getcontext (accname, nick, FALSE, NULL))) { @@ -401,7 +402,7 @@ void otr_trust (IRC_CTX *ircctx, char *nick, const char *peername) nick = (char *)peername; } - sprintf ((char *)accname, "%s@%s", IRCCTX_NICK (ircctx), IRCCTX_ADDR (ircctx)); + g_snprintf (accname, sizeof(accname), "%s@%s", IRCCTX_NICK (ircctx), IRCCTX_ADDR (ircctx)); if (!(co = otr_getcontext (accname, nick, FALSE, NULL))) { @@ -461,7 +462,7 @@ void otr_authabort (IRC_CTX *ircctx, char *nick, const char *peername) nick = (char *)peername; } - sprintf ((char *)accname, "%s@%s", IRCCTX_NICK (ircctx), IRCCTX_ADDR (ircctx)); + g_snprintf (accname, sizeof(accname), "%s@%s", IRCCTX_NICK (ircctx), IRCCTX_ADDR (ircctx)); if (!(co = otr_getcontext (accname, nick, FALSE, NULL))) { @@ -500,7 +501,7 @@ void otr_auth (IRC_CTX *ircctx, char *nick, const char *peername, const char *se nick = (char *)peername; } - sprintf ((char *)accname, "%s@%s", IRCCTX_NICK (ircctx), IRCCTX_ADDR (ircctx)); + g_snprintf (accname, sizeof(accname), "%s@%s", IRCCTX_NICK (ircctx), IRCCTX_ADDR (ircctx)); if (!(co = otr_getcontext (accname, nick, FALSE, NULL))) { @@ -691,7 +692,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)); + g_snprintf (accname, sizeof(accname), "%s@%s", IRCCTX_NICK (ircctx), IRCCTX_ADDR (ircctx)); if (!(co = otr_getcontext (accname, from, TRUE, ircctx))) { From 714236209adb09fcb27e30c631e8fec423efd506 Mon Sep 17 00:00:00 2001 From: TingPing Date: Sat, 13 Dec 2014 09:38:54 -0500 Subject: [PATCH 12/49] Fix detecting if tab is a dialog --- src/hexchat_otr.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/hexchat_otr.c b/src/hexchat_otr.c index fa30894..1d082b8 100644 --- a/src/hexchat_otr.c +++ b/src/hexchat_otr.c @@ -10,6 +10,32 @@ static char set_policy_known[512] = IO_DEFAULT_POLICY_KNOWN; static char set_ignore[512] = IO_DEFAULT_IGNORE; static int set_finishonunload = TRUE; +static int +get_current_context_type (void) +{ + int type = 0; + hexchat_list *list; + hexchat_context *cur_ctx; + + list = hexchat_list_get (ph, "channels"); + if (!list) + return 0; + + cur_ctx = hexchat_get_context (ph); + + while (hexchat_list_next (ph, list)) + { + if ((hexchat_context*)hexchat_list_str (ph, list, "context") == cur_ctx) + { + type = hexchat_list_int (ph, list, "type"); + break; + } + } + + hexchat_list_free (ph, list); + return type; +} + int extract_nick (char *nick, char *line, size_t nick_size) { char *excl; @@ -157,7 +183,7 @@ int hook_outgoing (char *word[], char *word_eol[], void *userdata) .address = (char *)server }; - if ((*channel == '&') || (*channel == '#')) + if (get_current_context_type () != 3) /* Not PM */ return HEXCHAT_EAT_NONE; if (g_regex_match (regex_nickignore, channel, 0, NULL)) @@ -192,8 +218,7 @@ int hook_privmsg (char *word[], char *word_eol[], void *userdata) }; hexchat_context *query_ctx; - char *chanmsg = word[3]; - if ((*chanmsg == '&') || (*chanmsg == '#')) + if (get_current_context_type () != 3) /* Not PM */ return HEXCHAT_EAT_NONE; if (!extract_nick (nick, word[1], sizeof(nick))) return HEXCHAT_EAT_NONE; From 2f2114afe52d128355d3455b556eff9ef1b5c41a Mon Sep 17 00:00:00 2001 From: TingPing Date: Sat, 13 Dec 2014 09:54:09 -0500 Subject: [PATCH 13/49] Use g_strsignal --- src/otr_key.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/otr_key.c b/src/otr_key.c index 38e8353..9ab4895 100644 --- a/src/otr_key.c +++ b/src/otr_key.c @@ -69,19 +69,7 @@ void keygen_childwatch (GPid pid, gint status, gpointer data) if (ret == 0) { if (WIFSIGNALED (status)) - { - char sigstr[16]; - - g_snprintf (sigstr, sizeof(sigstr), -#ifndef HAVE_STRSIGNAL - "%d", WTERMSIG (status)); -#else - "%s", strsignal (WTERMSIG (status))); -#endif - otr_noticest (TXT_KG_EXITSIG, - kg_st.accountname, - sigstr); - } + otr_noticest (TXT_KG_EXITSIG, kg_st.accountname, g_strsignal (WTERMSIG (status))); else otr_noticest (TXT_KG_EXITED, kg_st.accountname); } From 2cbadab1c75925607cc987d6cc54c88332a66d06 Mon Sep 17 00:00:00 2001 From: TingPing Date: Sat, 13 Dec 2014 10:00:29 -0500 Subject: [PATCH 14/49] Fix building as c89 --- src/hexchat_otr.c | 8 ++++---- src/otr_key.c | 2 -- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/hexchat_otr.c b/src/hexchat_otr.c index 1d082b8..791587e 100644 --- a/src/hexchat_otr.c +++ b/src/hexchat_otr.c @@ -154,7 +154,7 @@ int cmd_otr (char *word[], char *word_eol[], void *userdata) } else if (strcmp (word[3], "finishonunload") == 0) { - set_finishonunload = (strcasecmp (word[4], "true") == 0); + set_finishonunload = (g_ascii_strcasecmp (word[4], "true") == 0); } else { @@ -198,7 +198,7 @@ int hook_outgoing (char *word[], char *word_eol[], void *userdata) if (!otrmsg) return HEXCHAT_EAT_ALL; - snprintf (newmsg, 511, "PRIVMSG %s :%s", channel, otrmsg); + g_snprintf (newmsg, 511, "PRIVMSG %s :%s", channel, otrmsg); otrl_message_free (otrmsg); hexchat_command (ph, newmsg); @@ -337,7 +337,7 @@ void printformat (IRC_CTX *ircctx, const char *nick, int lvl, int fnum, ...) find_query_ctx = hexchat_find_context (ph, server, nick); if (find_query_ctx == NULL) { - // no query window yet, let's open one + /* no query window yet, let's open one */ hexchat_commandf (ph, "query %s", nick); find_query_ctx = hexchat_find_context (ph, server, nick); } @@ -353,7 +353,7 @@ void printformat (IRC_CTX *ircctx, const char *nick, int lvl, int fnum, ...) hexchat_set_context (ph, find_query_ctx); - if (vsnprintf (msg, sizeof(msg), formats[fnum].def, params) < 0) + if (g_vsnprintf (msg, sizeof(msg), formats[fnum].def, params) < 0) g_snprintf (msg, sizeof(msg), "internal error parsing error string (BUG)"); va_end (params); hexchat_printf (ph, "OTR: %s", s); diff --git a/src/otr_key.c b/src/otr_key.c index 9ab4895..0fd47d4 100644 --- a/src/otr_key.c +++ b/src/otr_key.c @@ -110,7 +110,6 @@ gboolean keygen_complete (GIOChannel *source, GIOCondition condition, kg_st.accountname, time (NULL) - kg_st.started); rename (tmpfilename, filename); - //otrl_privkey_forget_all(otr_state); <-- done by lib key_load (); } @@ -206,7 +205,6 @@ void keygen_run (const char *accname) err = otrl_privkey_generate (otr_state, filename, accname, PROTOCOLID); write (fds[1], &err, sizeof(err)); - //g_free(filename); _exit (0); } From fafcb6aa38a7c3363f7aaa3e1c89df6276516c61 Mon Sep 17 00:00:00 2001 From: TingPing Date: Sat, 13 Dec 2014 12:01:12 -0500 Subject: [PATCH 15/49] Improve makeformats.py - Better formatting - No extra fields - Static assert --- src/Makefile.am | 3 +++ src/makeformats.py | 54 ++++++++++------------------------------------ 2 files changed, 14 insertions(+), 43 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index c52e75a..7750dda 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -7,5 +7,8 @@ otr_la_CFLAGS = $(OTR_CFLAGS) $(GLIB_CFLAGS) $(GCRYPT_CFLAGS) otr_la_LIBADD = $(OTR_LIBS) $(GLIB_LIBS) $(GCRYPT_LIBS) otr_la_LDFLAGS = -avoid-version -module +otr-formats.h hexchat-formats.c: formats.txt + $(AM_V_GEN) python makeformats.py $< + EXTRA_DIST = formats.txt makeformats.py otr.h otr-formats.h hexchat_otr.h diff --git a/src/makeformats.py b/src/makeformats.py index 20170d2..3d910dd 100755 --- a/src/makeformats.py +++ b/src/makeformats.py @@ -10,33 +10,13 @@ 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("hexchat-formats.c","w") -src.write('#include "otr.h"\n'); srcx.write('#include "otr.h"\n'); +srcx.write('FORMAT_REC formats[] = {\n\t') +srcx.write('{ MODULE_NAME, "otr" }') -src.write("""char *otr_help = "%s";\n""" % "\\n".join( - ["%9- OTR help -%9"]+ - [re.sub('^(/otr.*)$','%_\\1%_', - re.sub('^(otr_[a-z_]*)$','%_\\1%_', - re.sub('"([^"]*)"','\\"%_\\1%_\\"', - x.replace('\n','').replace("\t"," ") - ))) - for x in open(sys.argv[2],"r").readlines()] - +["%9- End of OTR help -%9"] - )) - -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"); - -hdr.write("enum {\n") - +hdr.write("enum\n{\n\t") hdr.write("TXT_OTR_MODULE_NAME") fills = 0 @@ -44,18 +24,16 @@ section = None for line in lines: - src.write(",\n") - srcx.write(",\n") + srcx.write(",\n\t") e = line.split("\t") if len(e)==1: # Section name section = e[0] - src.write("""{ NULL, "%s", 0 }\n""" % (e[0])) - srcx.write("""{ NULL, "%s", 0 }\n""" % (e[0])) + srcx.write("""{ NULL, "%s" }""" % (e[0])) - hdr.write(",\nTXT_OTR_FILL_%d" % fills) + hdr.write(",\n\tTXT_OTR_FILL_%d" % fills) fills += 1 @@ -66,7 +44,7 @@ new = "" last=0 i=0 - srcx.write("""{ "%s", "%s", 0""" % (e[0],fo.replace("%%9","").replace("%9","").replace("%g","").replace("%n",""))) + srcx.write("""{ "%s", "%s" """ % (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'] @@ -89,15 +67,9 @@ if e[1][0] != "{" and section!="Nickignore" and section!="Contexts": premsg = "%9OTR%9: " - src.write("""{ "%s", "%s%s", %s""" % (e[0],premsg,e[1],e[2])) - - if len(params)>0: - src.write(", { %s }" % ", ".join(params)) - - src.write("}") srcx.write("}") - hdr.write(",\n") + hdr.write(",\n\t") hdr.write("TXT_%s" % e[0].upper()) @@ -107,16 +79,12 @@ extern FORMAT_REC formats[]; """) -src.write(""", -{ NULL, NULL, 0 } -}; -""") - srcx.write(""", -{ NULL, NULL, 0 } +\t{ NULL, NULL } }; + +G_STATIC_ASSERT (G_N_ELEMENTS(formats) - 1 == TXT_ST_UNKNOWN + 1); """) hdr.close() -src.close() srcx.close() From 859b965d7fdf8dfa929c04314327bdf00a43570e Mon Sep 17 00:00:00 2001 From: TingPing Date: Sat, 13 Dec 2014 12:36:58 -0500 Subject: [PATCH 16/49] Start porting over old upstream changes For some reason the fork I based off used an older version. This is not complete as much of it was never implemented in xchat upstream only irssi. --- src/formats.txt | 17 +++- src/hexchat-formats.c | 17 +++- src/hexchat_otr.c | 14 +-- src/otr-formats.h | 27 +++--- src/otr.h | 81 +++++++++++++++- src/otr_key.c | 52 ++++++++++ src/otr_ops.c | 110 ++++++++++++++-------- src/otr_util.c | 214 +++++++++++++++--------------------------- 8 files changed, 327 insertions(+), 205 deletions(-) diff --git a/src/formats.txt b/src/formats.txt index 9c3a7ee..56cd8b9 100644 --- a/src/formats.txt +++ b/src/formats.txt @@ -23,6 +23,12 @@ fp_not_found no fingerprints found fp_loaded fingerprints loaded fp_load_error Error loading fingerprints: %s (%s) fp_trust Trusting fingerprint from %s +Instance Tags +instag_saved instance tags saved +instag_save_error Error saving instance tags: %s (%s) +instag_not_found no instance tags found +instag_loaded instance tags loaded +instag_load_error Error loading instance tags: %s (%s) Callbacks ops_notify_bug BUG() in ops_notify ops_notify title: %s prim: %s sec: %s @@ -35,6 +41,7 @@ ops_still_reply still %%9secure%9 (is reply) ops_still_no_reply still %%9secure%9 (is not reply) ops_log log msg: %s ops_inject Couldn't inject message from %s for %s: %s +ops_handle_msg Message event %s, msg %s SendingReceiving send_failed send failed: msg=%s send_change couldn't find context also OTR changed the outgoing message(BUG?) @@ -57,6 +64,7 @@ auth_responding Responding to authentication request... auth_initiated Initiated authentication... auth_have_old %s wanted to authenticate but an old authentication was still ongoing. Old authentication will be aborted, please try again. auth_peer %s wants to authenticate. Type /otr auth to complete. +auth_peer_qa %s wants to authenticate and asked you \"%s\". Type /otr auth to complete. auth_peer_reply_wrong %s replied to an auth we didn't start. auth_peer_replied %s replied to our auth request... auth_peer_wrong_smp3 %s sent a wrong authentication message (SMP3). @@ -72,7 +80,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 @@ -88,10 +96,9 @@ st_plaintext {sb plaintext} st_untrusted {sb %rOTR(not auth'ed)%n} st_trust_smp {sb %gOTR%n} st_trust_manual {sb %gOTR%n} -st_smp_wait_2 {sb {hilight awaiting auth reply...}} -st_smp_have_2 {sb {hilight finalizing auth... (won't happen with libotr 3.1(bug), ask the other guy to initiate)}} -st_smp_failed {sb {hilight auth failed}} +st_smp_incoming {sb {hilight incoming auth request...}} +st_smp_outgoing {sb {hilight awaiting auth reply...}} st_smp_finalize {sb {hilight finalizing auth...}} st_smp_unknown {sb {hilight unknown auth state!}} st_finished {sb finished} -st_unknown {sb {hilight state unknown (BUG!)}} +st_unknown {sb {hilight state unknown (BUG!)}} \ No newline at end of file diff --git a/src/hexchat-formats.c b/src/hexchat-formats.c index c20845e..f473d33 100644 --- a/src/hexchat-formats.c +++ b/src/hexchat-formats.c @@ -26,6 +26,12 @@ FORMAT_REC formats[] = { { "fp_loaded", "fingerprints loaded" }, { "fp_load_error", "Error loading fingerprints: %s (%s)" }, { "fp_trust", "Trusting fingerprint from %s" }, + { NULL, "Instance Tags" }, + { "instag_saved", "instance tags saved" }, + { "instag_save_error", "Error saving instance tags: %s (%s)" }, + { "instag_not_found", "no instance tags found" }, + { "instag_loaded", "instance tags loaded" }, + { "instag_load_error", "Error loading instance tags: %s (%s)" }, { NULL, "Callbacks" }, { "ops_notify_bug", "BUG() in ops_notify" }, { "ops_notify", "title: %s prim: %s sec: %s" }, @@ -38,6 +44,7 @@ FORMAT_REC formats[] = { { "ops_still_no_reply", "still secure (is not reply)" }, { "ops_log", "log msg: %s" }, { "ops_inject", "Couldn't inject message from %s for %s: %s" }, + { "ops_handle_msg", "Message event %s, msg %s" }, { NULL, "SendingReceiving" }, { "send_failed", "send failed: msg=%s" }, { "send_change", "couldn't find context also OTR changed the outgoing message(BUG?)" }, @@ -60,6 +67,7 @@ FORMAT_REC formats[] = { { "auth_initiated", "Initiated authentication..." }, { "auth_have_old", "%s wanted to authenticate but an old authentication was still ongoing. Old authentication will be aborted, please try again." }, { "auth_peer", "%s wants to authenticate. Type /otr auth to complete." }, + { "auth_peer_qa", "%s wants to authenticate and asked you \"%s\". Type /otr auth to complete." }, { "auth_peer_reply_wrong", "%s replied to an auth we didn't start." }, { "auth_peer_replied", "%s replied to our auth request..." }, { "auth_peer_wrong_smp3", "%s sent a wrong authentication message (SMP3)." }, @@ -75,7 +83,7 @@ FORMAT_REC formats[] = { { "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 /otr finish for plaintext or ?OTR? to restart OTR." }, { NULL, "Contexts" }, { "ctx_ctx_unencrypted", "%20s %30s plaintext" }, @@ -91,12 +99,13 @@ FORMAT_REC formats[] = { { "st_untrusted", "{sb %rOTR(not auth'ed)}" }, { "st_trust_smp", "{sb OTR}" }, { "st_trust_manual", "{sb OTR}" }, - { "st_smp_wait_2", "{sb {hilight awaiting auth reply...}}" }, - { "st_smp_have_2", "{sb {hilight finalizing auth... (won't happen with libotr 3.1(bug), ask the other guy to initiate)}}" }, - { "st_smp_failed", "{sb {hilight auth failed}}" }, + { "st_smp_incoming", "{sb {hilight incoming auth request...}}" }, + { "st_smp_outgoing", "{sb {hilight awaiting auth reply...}}" }, { "st_smp_finalize", "{sb {hilight finalizing auth...}}" }, { "st_smp_unknown", "{sb {hilight unknown auth state!}}" }, { "st_finished", "{sb finished}" }, { "st_unknown", "{sb {hilight state unknown (BUG!)}}" }, { NULL, NULL } }; + +G_STATIC_ASSERT (G_N_ELEMENTS(formats) - 1 == TXT_ST_UNKNOWN + 1); diff --git a/src/hexchat_otr.c b/src/hexchat_otr.c index 791587e..19c37ce 100644 --- a/src/hexchat_otr.c +++ b/src/hexchat_otr.c @@ -124,14 +124,11 @@ int cmd_otr (char *word[], char *word_eol[], void *userdata) else if (strcmp (cmd, "auth") == 0) { if (!word[3] || !*word[3]) - { - otr_notice (ircctx, target, - TXT_CMD_AUTH); - } + 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]); + otr_auth (NULL, NULL, word_eol[4], NULL, word[3]); else - otr_auth (ircctx, target, NULL, word_eol[3]); + otr_auth (ircctx, target, NULL, NULL, word_eol[3]); } else if (strcmp (cmd, "set") == 0) { @@ -321,6 +318,11 @@ int hexchat_plugin_deinit () return 1; } +void otr_log(IRC_CTX *server, const char *nick, int level, const char *format, ...) +{ + /* TODO: Implement me! */ +} + void printformat (IRC_CTX *ircctx, const char *nick, int lvl, int fnum, ...) { va_list params; diff --git a/src/otr-formats.h b/src/otr-formats.h index 649c2c0..70318db 100644 --- a/src/otr-formats.h +++ b/src/otr-formats.h @@ -1,5 +1,3 @@ -extern char *otr_help; - enum { TXT_OTR_MODULE_NAME, @@ -29,6 +27,12 @@ enum TXT_FP_LOAD_ERROR, TXT_FP_TRUST, TXT_OTR_FILL_2, + TXT_INSTAG_SAVED, + TXT_INSTAG_SAVE_ERROR, + TXT_INSTAG_NOT_FOUND, + TXT_INSTAG_LOADED, + TXT_INSTAG_LOAD_ERROR, + TXT_OTR_FILL_3, TXT_OPS_NOTIFY_BUG, TXT_OPS_NOTIFY, TXT_OPS_DISPLAY_BUG, @@ -40,7 +44,8 @@ enum TXT_OPS_STILL_NO_REPLY, TXT_OPS_LOG, TXT_OPS_INJECT, - TXT_OTR_FILL_3, + TXT_OPS_HANDLE_MSG, + TXT_OTR_FILL_4, TXT_SEND_FAILED, TXT_SEND_CHANGE, TXT_SEND_FRAGMENT, @@ -52,16 +57,17 @@ enum TXT_RECEIVE_CONVERTED, TXT_OTR_BETTER_TWO, TXT_OTR_BETTER_THREE, - TXT_OTR_FILL_4, + TXT_OTR_FILL_5, TXT_CTX_NOT_FOUND, TXT_CTX_NOT_CREATE, - TXT_OTR_FILL_5, + TXT_OTR_FILL_6, TXT_AUTH_ABORTED_ONGOING, TXT_AUTH_ABORTED, TXT_AUTH_RESPONDING, TXT_AUTH_INITIATED, TXT_AUTH_HAVE_OLD, TXT_AUTH_PEER, + TXT_AUTH_PEER_QA, TXT_AUTH_PEER_REPLY_WRONG, TXT_AUTH_PEER_REPLIED, TXT_AUTH_PEER_WRONG_SMP3, @@ -69,7 +75,7 @@ enum TXT_AUTH_SUCCESSFUL, TXT_AUTH_FAILED, TXT_AUTH_NEEDENC, - TXT_OTR_FILL_6, + TXT_OTR_FILL_7, TXT_CMD_OTR, TXT_CMD_QNOTFOUND, TXT_CMD_AUTH, @@ -79,7 +85,7 @@ enum TXT_CMD_FINISHALL_NONE, TXT_CMD_VERSION, TXT_PEER_FINISHED, - TXT_OTR_FILL_7, + TXT_OTR_FILL_8, TXT_CTX_CTX_UNENCRYPTED, TXT_CTX_CTX_ENCRYPTED, TXT_CTX_CTX_FINISHED, @@ -88,14 +94,13 @@ enum TXT_CTX_FPS_SMP, TXT_CTX_FPS_MAN, TXT_CTX_NOCTXS, - TXT_OTR_FILL_8, + TXT_OTR_FILL_9, TXT_ST_PLAINTEXT, TXT_ST_UNTRUSTED, TXT_ST_TRUST_SMP, TXT_ST_TRUST_MANUAL, - TXT_ST_SMP_WAIT_2, - TXT_ST_SMP_HAVE_2, - TXT_ST_SMP_FAILED, + TXT_ST_SMP_INCOMING, + TXT_ST_SMP_OUTGOING, TXT_ST_SMP_FINALIZE, TXT_ST_SMP_UNKNOWN, TXT_ST_FINISHED, diff --git a/src/otr.h b/src/otr.h index edf42af..aa84db7 100644 --- a/src/otr.h +++ b/src/otr.h @@ -69,12 +69,83 @@ void otr_log (IRC_CTX *server, const char *to, #define KEYFILE "/otr/otr.key" #define TMPKEYFILE "/otr/otr.key.tmp" #define FPSFILE "/otr/otr.fp" +#define INSTAGFILE "/otr/otr.instag" /* some defaults */ #define IO_DEFAULT_POLICY "*@localhost opportunistic,*bitlbee* opportunistic,*@im.* opportunistic, *serv@irc* never" #define IO_DEFAULT_POLICY_KNOWN "* always" #define IO_DEFAULT_IGNORE "xmlconsole[0-9]*" +static const char * const otr_msg_event_txt[] = { + "NONE", + "ENCRYPTION_REQUIRED", + "ENCRYPTION_ERROR", + "CONNECTION_ENDED", + "SETUP_ERROR", + "MSG_REFLECTED", + "MSG_RESENT", + "RCVDMSG_NOT_IN_PRIVATE", + "RCVDMSG_UNREADABLE", + "RCVDMSG_MALFORMED", + "LOG_HEARTBEAT_RCVD", + "LOG_HEARTBEAT_SENT", + "RCVDMSG_GENERAL_ERR", + "RCVDMSG_UNENCRYPTED", + "RCVDMSG_UNRECOGNIZED", + "RCVDMSG_FOR_OTHER_INSTANCE" +}; + +static const char * const otr_status_txt[] = { + "FINISHED", + "TRUST_MANUAL", + "TRUST_SMP", + "SMP_ABORT", + "SMP_STARTED", + "SMP_RESPONDED", + "SMP_INCOMING", + "SMP_FINALIZE", + "SMP_ABORTED", + "PEER_FINISHED", + "SMP_FAILED", + "SMP_SUCCESS", + "GONE_SECURE", + "GONE_INSECURE", + "CTX_UPDATE" +}; + +/* returned by otr_getstatus */ +enum { + IO_ST_PLAINTEXT, + IO_ST_FINISHED, + IO_ST_SMP_INCOMING, + IO_ST_SMP_OUTGOING, + IO_ST_SMP_FINALIZE, + IO_ST_UNKNOWN, + IO_ST_UNTRUSTED=32, + IO_ST_TRUST_MANUAL=64, + IO_ST_TRUST_SMP=128, + IO_ST_SMP_ONGOING= IO_ST_SMP_INCOMING|IO_ST_SMP_OUTGOING|IO_ST_SMP_FINALIZE +}; + +/* given to otr_status_change */ +enum { + IO_STC_FINISHED, + IO_STC_TRUST_MANUAL, + IO_STC_TRUST_SMP, + IO_STC_SMP_ABORT, + IO_STC_SMP_STARTED, + IO_STC_SMP_RESPONDED, + IO_STC_SMP_INCOMING, + IO_STC_SMP_FINALIZE, + IO_STC_SMP_ABORTED, + IO_STC_PEER_FINISHED, + IO_STC_SMP_FAILED, + IO_STC_SMP_SUCCESS, + IO_STC_GONE_SECURE, + IO_STC_GONE_INSECURE, + IO_STC_CTX_UPDATE +}; + /* one for each OTR context (=communication pair) */ struct co_info { @@ -131,6 +202,7 @@ extern int debug; void irc_send_message (IRC_CTX *ircctx, const char *recipient, char *msg); IRC_CTX *server_find_address (char *address); +void otr_status_change (IRC_CTX *ircctx, const char *nick, int event); /* init stuff */ @@ -143,15 +215,16 @@ void otr_setpolicies (const char *policies, int known); 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); +int otr_getstatus(IRC_CTX *ircctx, const char *nick); ConnContext *otr_getcontext (const char *accname, const char *nick, int create, void *data); /* user interaction */ 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_auth (IRC_CTX *server, char *nick, const char *peername, const char *question, const char *secret); void otr_authabort (IRC_CTX *server, char *nick, const char *peername); +void otr_abort_auth(ConnContext *co, IRC_CTX *ircctx, const char *nick); struct ctxlist_ *otr_contexts (); void otr_finishall (); @@ -162,3 +235,7 @@ void keygen_abort (); void key_load (); void fps_load (); void otr_writefps (); + +/* instance tags */ +void instag_load (); +void otr_writeinstags (); diff --git a/src/otr_key.c b/src/otr_key.c index 0fd47d4..c63de66 100644 --- a/src/otr_key.c +++ b/src/otr_key.c @@ -315,3 +315,55 @@ void fps_load () } g_free (filename); } + +/* + * Write instance tags to file. + */ +void otr_writeinstags(void) +{ + gcry_error_t err; + char *filename = g_strconcat(get_irssi_dir (), INSTAGFILE, NULL); + + err = otrl_instag_write (otr_state, filename); + + if (err == GPG_ERR_NO_ERROR) + { + otr_noticest(TXT_INSTAG_SAVED); + } + else + { + otr_noticest(TXT_INSTAG_SAVE_ERROR, + gcry_strerror(err), + gcry_strsource(err)); + } + g_free(filename); +} + +/* + * Load instance tags. + */ +void instag_load(void) +{ + gcry_error_t err; + char *filename = g_strconcat(get_irssi_dir (), INSTAGFILE, NULL); + + if (!g_file_test(filename, G_FILE_TEST_EXISTS)) + { + otr_noticest(TXT_INSTAG_NOT_FOUND); + return; + } + + err = otrl_instag_read(otr_state, filename); + + if (err == GPG_ERR_NO_ERROR) + { + otr_noticest(TXT_INSTAG_LOADED); + } + else + { + otr_noticest(TXT_INSTAG_LOAD_ERROR, + gcry_strerror(err), + gcry_strsource(err)); + } + g_free(filename); +} \ No newline at end of file diff --git a/src/otr_ops.c b/src/otr_ops.c index 3b0146e..f191e3e 100644 --- a/src/otr_ops.c +++ b/src/otr_ops.c @@ -113,29 +113,6 @@ void ops_inject_msg (void *opdata, const char *accountname, g_free (msgcopy); } -#if 0 -/* - * OTR notification. Haven't seen one yet. - */ -void ops_notify(void *opdata, OtrlNotifyLevel level, const char *accountname, - const char *protocol, const char *username, - const char *title, const char *primary, - const char *secondary) -{ - ConnContext *co = otr_getcontext(accountname,username,FALSE,NULL); - IRC_CTX *server = opdata; - struct co_info *coi; - if (co) { - coi = co->app_data; - server = coi->ircctx; - } else - otr_notice(server,username,TXT_OPS_NOTIFY_BUG); - - otr_notice(server,username,TXT_OPS_NOTIFY, - title,primary,secondary); -} -#endif - /* This is kind of messy. */ const char *convert_otr_msg (const char *msg) { @@ -152,24 +129,15 @@ const char *convert_otr_msg (const char *msg) return msg; } -void ops_handle_msg (void *opdata, OtrlMessageEvent msg_event, - ConnContext *co, const char *msg, - gcry_error_t err) +void ops_handle_msg_event(void *opdata, OtrlMessageEvent msg_event, + ConnContext *context, const char *message, + gcry_error_t err) { IRC_CTX *server = opdata; - struct co_info *coi; + char *username = context->username; - if (co) - { - coi = co->app_data; - server = coi->ircctx; - } - else - otr_notice (server, co->username, TXT_OPS_DISPLAY_BUG); - - msg = convert_otr_msg (msg); - otr_notice (server, co->username, TXT_OPS_DISPLAY, msg); - g_free ((char *)msg); + otr_debug (server, username, + TXT_OPS_HANDLE_MSG, otr_msg_event_txt[msg_event], message); } /* @@ -231,6 +199,13 @@ int ops_max_msg (void *opdata, ConnContext *context) return OTR_MAX_MSG_SIZE; } +void ops_create_instag (void *opdata, const char *accountname, const char *protocol) +{ + otrl_instag_generate(otr_state, "/dev/null", + accountname, protocol); + otr_writeinstags(otr_state); +} + /* * A context changed. * I believe this is not happening for the SMP expects. @@ -257,6 +232,61 @@ int ops_is_logged_in (void *opdata, const char *accountname, return TRUE; } +void otr_status_change (IRC_CTX *ircctx, const char *nick, int event) +{ + /* TODO: ? */ +} + +void ops_smp_event(void *opdata, OtrlSMPEvent smp_event, + ConnContext *context, unsigned short progress_percent, + char *question) +{ + IRC_CTX *ircctx = (opdata); + char *from = context->username; + struct co_info *coi = context->app_data; + + coi->received_smp_init = + (smp_event == OTRL_SMPEVENT_ASK_FOR_SECRET) || + (smp_event == OTRL_SMPEVENT_ASK_FOR_ANSWER); + + switch (smp_event) { + case OTRL_SMPEVENT_ASK_FOR_SECRET: + otr_notice(ircctx, from, TXT_AUTH_PEER, + from); + otr_status_change(ircctx, from, IO_STC_SMP_INCOMING); + break; + case OTRL_SMPEVENT_ASK_FOR_ANSWER: + otr_notice(ircctx, from, TXT_AUTH_PEER_QA, from, question); + otr_status_change(ircctx, from, IO_STC_SMP_INCOMING); + break; + case OTRL_SMPEVENT_IN_PROGRESS: + otr_notice(ircctx, from, + TXT_AUTH_PEER_REPLIED, + from); + otr_status_change(ircctx, from, IO_STC_SMP_FINALIZE); + break; + case OTRL_SMPEVENT_SUCCESS: + otr_notice(ircctx, from, + TXT_AUTH_SUCCESSFUL); + otr_status_change(ircctx, from, IO_STC_SMP_SUCCESS); + break; + case OTRL_SMPEVENT_ABORT: + otr_abort_auth(context, ircctx, from); + otr_status_change(ircctx, from, IO_STC_SMP_ABORTED); + break; + case OTRL_SMPEVENT_FAILURE: + case OTRL_SMPEVENT_CHEATED: + case OTRL_SMPEVENT_ERROR: + otr_notice(ircctx, from, TXT_AUTH_FAILED); + coi->smp_failed = TRUE; + otr_status_change(ircctx, from, IO_STC_SMP_FAILED); + break; + default: + otr_logst(MSGLEVEL_CRAP, "Received unknown SMP event"); + break; + } +} + /* * Initialize our OtrlMessageAppOps */ @@ -267,7 +297,9 @@ void otr_initops () otr_ops.policy = ops_policy; otr_ops.create_privkey = ops_create_privkey; otr_ops.inject_message = ops_inject_msg; - otr_ops.handle_msg_event = ops_handle_msg; + otr_ops.handle_msg_event = ops_handle_msg_event; + otr_ops.create_instag = ops_create_instag; + otr_ops.handle_smp_event = ops_smp_event; otr_ops.gone_secure = ops_secure; otr_ops.gone_insecure = ops_insecure; otr_ops.still_secure = ops_still_secure; diff --git a/src/otr_util.c b/src/otr_util.c index d1f9a7f..3161f60 100644 --- a/src/otr_util.c +++ b/src/otr_util.c @@ -46,6 +46,7 @@ int otrlib_init () /* load keys and fingerprints */ + instag_load (); key_load (); fps_load (); @@ -251,47 +252,66 @@ 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, const char *nick) { ConnContext *co; char accname[128]; + struct co_info *coi; - g_snprintf (accname, sizeof(accname), "%s@%s", mynick, server); + g_snprintf (accname, sizeof(accname), "%s@%s", ircctx->nick, ircctx->address); - if (!(co = otr_getcontext (accname, nick, FALSE, NULL))) + if (!(co = otr_getcontext(accname, nick, FALSE, ircctx))) { - return 0; + return IO_ST_PLAINTEXT; } + coi = co->app_data; + switch (co->msgstate) { case OTRL_MSGSTATE_PLAINTEXT: - return TXT_ST_PLAINTEXT; + return IO_ST_PLAINTEXT; case OTRL_MSGSTATE_ENCRYPTED: { char *trust = co->active_fingerprint->trust; int ex = co->smstate->nextExpected; - - if (trust && (*trust != '\0')) - return strcmp (trust, "smp") == 0 ? TXT_ST_TRUST_SMP : TXT_ST_TRUST_MANUAL; + int code = 0; switch (ex) { case OTRL_SMP_EXPECT1: - return TXT_ST_UNTRUSTED; + if (coi->received_smp_init) + code = IO_ST_SMP_INCOMING; + break; case OTRL_SMP_EXPECT2: - return TXT_ST_SMP_WAIT_2; + code = IO_ST_SMP_OUTGOING; + break; case OTRL_SMP_EXPECT3: case OTRL_SMP_EXPECT4: - return TXT_ST_SMP_FINALIZE; + code = IO_ST_SMP_FINALIZE; + break; default: - return TXT_ST_SMP_UNKNOWN; + otr_logst( + MSGLEVEL_CRAP, + "Encountered unknown SMP state in libotr, please let maintainers know"); + return IO_ST_UNKNOWN; } + + if (trust && (*trust != '\0')) + code |= strcmp(trust, "smp") == 0 ? IO_ST_TRUST_SMP : + IO_ST_TRUST_MANUAL; + else + code |= IO_ST_UNTRUSTED; + + return code; } case OTRL_MSGSTATE_FINISHED: - return TXT_ST_FINISHED; + return IO_ST_FINISHED; default: - return TXT_ST_UNKNOWN; + otr_logst( + MSGLEVEL_CRAP, + "BUG Found! Please write us a mail and describe how you got here"); + return IO_ST_UNKNOWN; } } @@ -348,6 +368,21 @@ void otr_finish (IRC_CTX *ircctx, char *nick, const char *peername, int inquery) if (coi) coi->finished = inquery; + /* write the finished into the master as well */ + co = otrl_context_find( + otr_state, + nick, + accname, + PROTOCOLID, + OTRL_INSTAG_MASTER, + FALSE, + NULL, + NULL, + NULL); + coi = co->app_data; + if (coi) + coi->finished = inquery; + if (peername) *pserver = '@'; } @@ -482,7 +517,8 @@ void otr_authabort (IRC_CTX *ircctx, char *nick, const char *peername) /* * Initiate or respond to SMP authentication. */ -void otr_auth (IRC_CTX *ircctx, char *nick, const char *peername, const char *secret) +void otr_auth (IRC_CTX *ircctx, char *nick, const char *peername, const char *question, + const char *secret) { ConnContext *co; char accname[128]; @@ -538,13 +574,23 @@ void otr_auth (IRC_CTX *ircctx, char *nick, const char *peername, const char *se } if (!coi->received_smp_init) - otrl_message_initiate_smp ( - otr_state, - &otr_ops, - ircctx, - co, - (unsigned char *)secret, - strlen (secret)); + if (question) + otrl_message_initiate_smp_q( + otr_state, + &otr_ops, + ircctx, + co, + question, + (unsigned char*)secret, + strlen (secret)); + else + otrl_message_initiate_smp ( + otr_state, + &otr_ops, + ircctx, + co, + (unsigned char *)secret, + strlen (secret)); else otrl_message_respond_smp ( otr_state, @@ -563,121 +609,6 @@ void otr_auth (IRC_CTX *ircctx, char *nick, const char *peername, const char *se *pserver = '@'; } -/* - * 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) -{ - 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); - abort = TRUE; - } - else - { - otr_notice (ircctx, from, TXT_AUTH_PEER, - from); - coi->received_smp_init = TRUE; - } - } - - 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); - abort = TRUE; - } - else - { - otr_notice (ircctx, from, - TXT_AUTH_PEER_REPLIED, - from); - co->smstate->nextExpected = OTRL_SMP_EXPECT4; - } - } - - 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); - abort = TRUE; - } - else - { - char *trust = co->active_fingerprint->trust; - if (trust && (*trust != '\0')) - { - otr_notice (ircctx, from, - TXT_AUTH_SUCCESSFUL); - } - else - { - otr_notice (ircctx, from, - TXT_AUTH_FAILED); - coi->smp_failed = TRUE; - } - co->smstate->nextExpected = OTRL_SMP_EXPECT1; - coi->received_smp_init = FALSE; - } - } - - 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); - abort = TRUE; - } - else - { - char *trust = co->active_fingerprint->trust; - if (trust && (*trust != '\0')) - { - otr_notice (ircctx, from, - TXT_AUTH_SUCCESSFUL); - } - else - { - /* unreachable since 4 is never sent out on - * error */ - otr_notice (ircctx, from, - TXT_AUTH_FAILED); - coi->smp_failed = TRUE; - } - co->smstate->nextExpected = OTRL_SMP_EXPECT1; - coi->received_smp_init = FALSE; - } - } - if (abort) - otr_abort_auth (co, ircctx, from); - - tlv = otrl_tlv_find (tlvs, OTRL_TLV_DISCONNECTED); - if (tlv) - otr_notice (ircctx, from, TXT_PEER_FINISHED, from); - - statusbar_items_redraw ("otr"); -} - /* * Hand the given message to OTR. * Returns NULL if its an OTR protocol message and @@ -758,7 +689,14 @@ char *otr_receive (IRC_CTX *ircctx, const char *msg, const char *from) NULL); if (tlvs) - otr_handle_tlvs (tlvs, co, coi, ircctx, from); + { + 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 (ignore_message) { From ed0ac5f05dc0595c638d2f61c24b9a49ff25d379 Mon Sep 17 00:00:00 2001 From: TingPing Date: Sat, 13 Dec 2014 19:41:50 -0500 Subject: [PATCH 17/49] Add /otr start command --- src/hexchat_otr.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/hexchat_otr.c b/src/hexchat_otr.c index 19c37ce..3f933ae 100644 --- a/src/hexchat_otr.c +++ b/src/hexchat_otr.c @@ -56,6 +56,17 @@ void irc_send_message (IRC_CTX *ircctx, const char *recipient, char *msg) hexchat_commandf (ph, "PRIVMSG %s :%s", recipient, msg); } +static void cmd_start (const char *nick) +{ + if (get_current_context_type () != 3) + { + hexchat_print (ph, "OTR: You can only use OTR in a dialog\n"); + return; + } + + hexchat_commandf (ph, "quote PRIVMSG %s :?OTRv23?", nick); +} + int cmd_otr (char *word[], char *word_eol[], void *userdata) { const char *own_nick = hexchat_get_info (ph, "nick"); @@ -80,6 +91,10 @@ int cmd_otr (char *word[], char *word_eol[], void *userdata) debug = !debug; otr_noticest (debug ? TXT_CMD_DEBUG_ON : TXT_CMD_DEBUG_OFF); } + else if (strcmp (cmd, "start") == 0 || strcmp (cmd, "init") == 0) + { + cmd_start (target); + } else if (strcmp (cmd, "version") == 0) { otr_noticest (TXT_CMD_VERSION, PVERSION); From 472df0442314a5576895a2d772eef613dbd4e04f Mon Sep 17 00:00:00 2001 From: TingPing Date: Sat, 13 Dec 2014 19:51:17 -0500 Subject: [PATCH 18/49] Include usage in readme --- Readme.md | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/Readme.md b/Readme.md index d1e9198..de0e80d 100644 --- a/Readme.md +++ b/Readme.md @@ -21,3 +21,45 @@ make -s sudo make install ``` +Usage +----- + +1. Start a session with a user: + + ``` + /query nick + /otr start + ``` + + If this is your first time it may take a while to generate a key. + +2. Authenticate this user: + + At this point you need to verify this is the person you think. + + - If you know their fingerprint and it is correct: + + ``` + /otr trust + ``` + + - If you have previously agreed on a password: + + ``` + /otr auth + ``` + + - If you have neither of these: + + ``` + /otr authq + ``` + +3. Start chatting: + + Everything should be secure at this point. + When you are done: + + ``` + /otr finish + ``` From 2845436d324054597273d79eb233cfb7a2f15823 Mon Sep 17 00:00:00 2001 From: TingPing Date: Sat, 13 Dec 2014 20:06:50 -0500 Subject: [PATCH 19/49] Add /otr authq command --- src/hexchat_otr.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/hexchat_otr.c b/src/hexchat_otr.c index 3f933ae..89aa3c5 100644 --- a/src/hexchat_otr.c +++ b/src/hexchat_otr.c @@ -141,10 +141,19 @@ int cmd_otr (char *word[], char *word_eol[], void *userdata) 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], NULL, word[3]); + otr_auth (NULL, NULL, word[3], NULL, word_eol[4]); else otr_auth (ircctx, target, NULL, NULL, word_eol[3]); } + else if (strcmp (cmd, "authq") == 0) + { + if (!word[3] || !*word[3] || !word[4] || !*word[4]) + otr_notice (ircctx, target, TXT_CMD_AUTH); + else if (word[5] && *word[5] && strchr (word[3], '@')) + otr_auth (NULL, NULL, word[3], word[5], word[4]); + else + otr_auth (ircctx, target, NULL, word[4], word_eol[5]); + } else if (strcmp (cmd, "set") == 0) { if (strcmp (word[3], "policy") == 0) From e8f12f944f611a8eb22d255acf84b1e9e389b011 Mon Sep 17 00:00:00 2001 From: zeriam Date: Mon, 21 Dec 2015 21:35:49 -0600 Subject: [PATCH 20/49] Remove check for PM context in hook_privmsg() Removed the call to get_current_context_type in hook_privmsg, which checks for a current PM context, and the return if one is not found. This appears to have been mistakenly copied from hook_outgoing. The original code resulted in non-decrypted messages being received if the PM/query tab did not have focus. Closes #3 --- src/hexchat_otr.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/hexchat_otr.c b/src/hexchat_otr.c index 89aa3c5..21f1b10 100644 --- a/src/hexchat_otr.c +++ b/src/hexchat_otr.c @@ -239,8 +239,6 @@ int hook_privmsg (char *word[], char *word_eol[], void *userdata) }; hexchat_context *query_ctx; - if (get_current_context_type () != 3) /* Not PM */ - return HEXCHAT_EAT_NONE; if (!extract_nick (nick, word[1], sizeof(nick))) return HEXCHAT_EAT_NONE; From 0c36a02953e07257ad9567a5504ee66be1d1ccaf Mon Sep 17 00:00:00 2001 From: Patrick Griffis Date: Mon, 21 Dec 2015 23:20:33 -0500 Subject: [PATCH 21/49] Remove dependency on gnome-common --- autogen.sh | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/autogen.sh b/autogen.sh index 6ae1ce2..cfdc230 100755 --- a/autogen.sh +++ b/autogen.sh @@ -4,19 +4,23 @@ srcdir=`dirname $0` test -z "$srcdir" && srcdir=. -PKG_NAME="hexchat-otr" - -(test -f $srcdir/src/otr.h) || { - echo -n "**Error**: Directory "\`$srcdir\'" does not look like the" - echo " top-level $PKG_NAME directory" +(test -f $srcdir/configure.ac) || { + echo -n "**Error**: Directory "\`$srcdir\'" does not look like the top-level directory" exit 1 } -which gnome-autogen.sh || { - echo "You need to install gnome-common" - exit 1 -} +aclocal --install -I m4 || exit 1 +libtoolize --quiet --copy || exit 1 +autoreconf --install -Wno-portability || exit 1 + +if [ "$NOCONFIGURE" = "" ]; then + $srcdir/configure "$@" || exit 1 -. gnome-autogen.sh + if [ "$1" = "--help" ]; then exit 0 else + echo "Now type \`make\' to compile" || exit 1 + fi +else + echo "Skipping configure process." +fi -rm -rf autom4te.cache +set +x From 326d1598f993345286b985d4d4d87cc8c20a5068 Mon Sep 17 00:00:00 2001 From: Patrick Griffis Date: Mon, 21 Dec 2015 23:26:39 -0500 Subject: [PATCH 22/49] Simplify context type code --- src/hexchat_otr.c | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/src/hexchat_otr.c b/src/hexchat_otr.c index 21f1b10..2c151f9 100644 --- a/src/hexchat_otr.c +++ b/src/hexchat_otr.c @@ -13,27 +13,7 @@ static int set_finishonunload = TRUE; static int get_current_context_type (void) { - int type = 0; - hexchat_list *list; - hexchat_context *cur_ctx; - - list = hexchat_list_get (ph, "channels"); - if (!list) - return 0; - - cur_ctx = hexchat_get_context (ph); - - while (hexchat_list_next (ph, list)) - { - if ((hexchat_context*)hexchat_list_str (ph, list, "context") == cur_ctx) - { - type = hexchat_list_int (ph, list, "type"); - break; - } - } - - hexchat_list_free (ph, list); - return type; + return hexchat_list_int (ph, NULL, "type"); } int extract_nick (char *nick, char *line, size_t nick_size) From 6a7ce2547ecfd6839909206273f24c665c48cf01 Mon Sep 17 00:00:00 2001 From: Patrick Griffis Date: Wed, 23 Dec 2015 17:05:33 -0500 Subject: [PATCH 23/49] Still ignore incoming channel messages Introduced by e8f12f9 Closes #4 --- src/hexchat_otr.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/hexchat_otr.c b/src/hexchat_otr.c index 2c151f9..d701b4f 100644 --- a/src/hexchat_otr.c +++ b/src/hexchat_otr.c @@ -213,12 +213,16 @@ int hook_privmsg (char *word[], char *word_eol[], void *userdata) char *newmsg; const char *server = hexchat_get_info (ph, "server"); const char *own_nick = hexchat_get_info (ph, "nick"); + const char *chantypes = hexchat_list_str (ph, NULL, "chantypes"); IRC_CTX ircctx = { .nick = (char *)own_nick, .address = (char *)server }; hexchat_context *query_ctx; + if (strchr (chantypes, word[3][0]) != NULL) /* Ignore channels */ + return HEXCHAT_EAT_NONE; + if (!extract_nick (nick, word[1], sizeof(nick))) return HEXCHAT_EAT_NONE; From 13daf879b6ba00810ae3d85ee504ed32b717f71d Mon Sep 17 00:00:00 2001 From: zeriam Date: Sun, 27 Dec 2015 15:17:54 -0600 Subject: [PATCH 24/49] Fix sending messages to non-otr query - Changes the call to otr_getcontext() in otr_send() such that it creates an OTR context if one does not exist. - Makes otr_send() have the same otr_getcontext() behavior as otr_receive(). - Updates corresponding error notice. - Resolves bug where a plugin user could not send regular unencrypted private messages to other users. Fixes #2 Closes #5 --- src/otr_util.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/otr_util.c b/src/otr_util.c index 3161f60..fb2e3ad 100644 --- a/src/otr_util.c +++ b/src/otr_util.c @@ -151,9 +151,10 @@ char *otr_send (IRC_CTX *ircctx, const char *msg, const char *to) g_snprintf (accname, sizeof(accname), "%s@%s", nick, address); - if (!(co = otr_getcontext (accname, to, FALSE, ircctx))) + if (!(co = otr_getcontext (accname, to, TRUE, ircctx))) { - otr_notice (ircctx, to, TXT_SEND_CHANGE); + otr_noticest (TXT_CTX_NOT_CREATE, + accname, to); return NULL; } From d6b164258243f592db8706147a4e9fc4711d75ef Mon Sep 17 00:00:00 2001 From: Patrick Griffis Date: Tue, 29 Dec 2015 21:17:58 -0500 Subject: [PATCH 25/49] Improve help text Fixes #6 --- src/hexchat_otr.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/hexchat_otr.h b/src/hexchat_otr.h index 60f826e..368dda3 100644 --- a/src/hexchat_otr.h +++ b/src/hexchat_otr.h @@ -6,7 +6,16 @@ #define PNAME "OTR" #define PDESC "Off-The-Record Messaging for Hexchat" #define PVERSION PACKAGE_VERSION -#define OTR_HELP "OTR " +#define OTR_HELP "OTR\n\ + version: Prints version of plugin\n\ + start: Starts an OTR chat (init also works)\n\ + finish []: Finish an OTR chat\n\ + trust []: Trusts the other user\n\ + auth [] : Auths a user via password\n\ + authq [] : Auths a user via question\n\ + authabort []: Aborts auth in progress\n\ + genkey [abort|]: Generates a new key\n\ + set []: Changes settings, run without args for current values" #define MAX_FORMAT_PARAMS 10 From d2284e12e32cc9bfac8337d6e3eb20b68a3d4615 Mon Sep 17 00:00:00 2001 From: Patrick Griffis Date: Sat, 13 Feb 2016 06:20:14 -0500 Subject: [PATCH 26/49] Mass warning cleanup --- configure.ac | 27 +++++++++++++++++++++------ src/Makefile.am | 2 +- src/hexchat_otr.c | 16 +++++++--------- src/otr.h | 22 +++++++++++----------- src/otr_key.c | 6 +++--- src/otr_ops.c | 45 +++++++++++++++------------------------------ src/otr_util.c | 4 ++-- 7 files changed, 60 insertions(+), 62 deletions(-) diff --git a/configure.ac b/configure.ac index be191ad..d086635 100644 --- a/configure.ac +++ b/configure.ac @@ -37,12 +37,27 @@ else fi AC_SUBST([hexchatlibdir]) -CFLAGS="$CFLAGS" -# TODO: Improve -if test "$CC" = "gcc" || test "$CC" = "clang"; then - CFLAGS="$CFLAGS -Wall -Wextra -Wno-unused-parameter" -fi -AC_SUBST([CFLAGS]) +AX_APPEND_COMPILE_FLAGS([ \ + -std=gnu99 \ + -funsigned-char \ + -fstack-protector-strong \ + -fPIE \ + -fPIC \ + -Wall \ + -Wextra \ + -Wconversion \ + -Winline \ + -Wno-padded \ + -Wno-unused-parameter \ + -Wstrict-prototypes \ + -Wmissing-prototypes \ + -Werror=implicit-function-declaration \ + -Werror=pointer-arith \ + -Werror=init-self \ + -Werror=format=2 \ + -Werror=missing-include-dirs \ + -Werror=date-time \ +]) AC_CONFIG_FILES([ Makefile diff --git a/src/Makefile.am b/src/Makefile.am index 7750dda..8827e38 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -5,7 +5,7 @@ lib_LTLIBRARIES = otr.la otr_la_SOURCES = otr_key.c otr_ops.c otr_util.c hexchat_otr.c hexchat-formats.c otr_la_CFLAGS = $(OTR_CFLAGS) $(GLIB_CFLAGS) $(GCRYPT_CFLAGS) otr_la_LIBADD = $(OTR_LIBS) $(GLIB_LIBS) $(GCRYPT_LIBS) -otr_la_LDFLAGS = -avoid-version -module +otr_la_LDFLAGS = -avoid-version -module -export-symbols-regex hexchat_.* otr-formats.h hexchat-formats.c: formats.txt $(AM_V_GEN) python makeformats.py $< diff --git a/src/hexchat_otr.c b/src/hexchat_otr.c index d701b4f..d6c82b7 100644 --- a/src/hexchat_otr.c +++ b/src/hexchat_otr.c @@ -1,22 +1,20 @@ #include "otr.h" int debug = 0; - -GRegex *regex_nickignore = NULL; hexchat_plugin *ph; +static GRegex *regex_nickignore = NULL; 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; -static int -get_current_context_type (void) +static int get_current_context_type (void) { return hexchat_list_int (ph, NULL, "type"); } -int extract_nick (char *nick, char *line, size_t nick_size) +static int extract_nick (char *nick, char *line, size_t nick_size) { char *excl; @@ -47,7 +45,7 @@ static void cmd_start (const char *nick) hexchat_commandf (ph, "quote PRIVMSG %s :?OTRv23?", nick); } -int cmd_otr (char *word[], char *word_eol[], void *userdata) +static int cmd_otr (char *word[], char *word_eol[], void *userdata) { const char *own_nick = hexchat_get_info (ph, "nick"); char *target = (char *)hexchat_get_info (ph, "channel"); @@ -172,7 +170,7 @@ int cmd_otr (char *word[], char *word_eol[], void *userdata) return HEXCHAT_EAT_ALL; } -int hook_outgoing (char *word[], char *word_eol[], void *userdata) +static int hook_outgoing (char *word[], char *word_eol[], void *userdata) { const char *own_nick = hexchat_get_info (ph, "nick"); const char *channel = hexchat_get_info (ph, "channel"); @@ -207,7 +205,7 @@ int hook_outgoing (char *word[], char *word_eol[], void *userdata) return HEXCHAT_EAT_ALL; } -int hook_privmsg (char *word[], char *word_eol[], void *userdata) +static int hook_privmsg (char *word[], char *word_eol[], void *userdata) { char nick[256]; char *newmsg; @@ -312,7 +310,7 @@ int hexchat_plugin_init (hexchat_plugin *plugin_handle, return 1; } -int hexchat_plugin_deinit () +int hexchat_plugin_deinit (void) { g_regex_unref (regex_nickignore); diff --git a/src/otr.h b/src/otr.h index aa84db7..8861009 100644 --- a/src/otr.h +++ b/src/otr.h @@ -206,9 +206,9 @@ void otr_status_change (IRC_CTX *ircctx, const char *nick, int event); /* init stuff */ -int otrlib_init (); -void otrlib_deinit (); -void otr_initops (); +int otrlib_init (void); +void otrlib_deinit (void); +void otr_initops (void); void otr_setpolicies (const char *policies, int known); /* basic send/receive/status stuff */ @@ -225,17 +225,17 @@ 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 *question, const char *secret); void otr_authabort (IRC_CTX *server, char *nick, const char *peername); void otr_abort_auth(ConnContext *co, IRC_CTX *ircctx, const char *nick); -struct ctxlist_ *otr_contexts (); -void otr_finishall (); +struct ctxlist_ *otr_contexts (void); +void otr_finishall (void); /* key/fingerprint stuff */ void keygen_run (const char *accname); -void keygen_abort (); -void key_load (); -void fps_load (); -void otr_writefps (); +void keygen_abort (int ignoreidle); +void key_load (void); +void fps_load (void); +void otr_writefps (void); /* instance tags */ -void instag_load (); -void otr_writeinstags (); +void instag_load (void); +void otr_writeinstags (void); diff --git a/src/otr_key.c b/src/otr_key.c index c63de66..d3825c9 100644 --- a/src/otr_key.c +++ b/src/otr_key.c @@ -45,7 +45,7 @@ struct pid_t pid; } kg_st = { .status = KEYGEN_NO }; -void keygen_childwatch (GPid pid, gint status, gpointer data) +static void keygen_childwatch (GPid pid, gint status, gpointer data) { struct pollfd pfd = { .fd = g_io_channel_unix_get_fd (kg_st.ch[0]), @@ -83,7 +83,7 @@ void keygen_childwatch (GPid pid, gint status, gpointer data) * Installed as g_io_watch and called when the key generation * process finishs. */ -gboolean keygen_complete (GIOChannel *source, GIOCondition condition, +static gboolean keygen_complete (GIOChannel *source, GIOCondition condition, gpointer data) { gcry_error_t err; @@ -366,4 +366,4 @@ void instag_load(void) gcry_strsource(err)); } g_free(filename); -} \ No newline at end of file +} diff --git a/src/otr_ops.c b/src/otr_ops.c index f191e3e..6727ee4 100644 --- a/src/otr_ops.c +++ b/src/otr_ops.c @@ -28,7 +28,7 @@ OtrlPolicy IO_DEFAULT_OTR_POLICY = OTRL_POLICY_MANUAL | OTRL_POLICY_WHITESPACE_S /* * Return policy for given context based on the otr_policy /setting */ -OtrlPolicy ops_policy (void *opdata, ConnContext *context) +static OtrlPolicy ops_policy (void *opdata, ConnContext *context) { struct co_info *coi = context->app_data; char *server = strchr (context->accountname, '@') + 1; @@ -80,7 +80,7 @@ OtrlPolicy ops_policy (void *opdata, ConnContext *context) * Since this can take more than an hour on some systems there isn't even * a point in trying... */ -void ops_create_privkey (void *opdata, const char *accountname, +static void ops_create_privkey (void *opdata, const char *accountname, const char *protocol) { keygen_run (accountname); @@ -91,7 +91,7 @@ void ops_create_privkey (void *opdata, const char *accountname, * Deriving the server is currently a hack, * need to derive the server from accountname. */ -void ops_inject_msg (void *opdata, const char *accountname, +static void ops_inject_msg (void *opdata, const char *accountname, const char *protocol, const char *recipient, const char *message) { IRC_CTX *a_serv; @@ -113,23 +113,8 @@ void ops_inject_msg (void *opdata, const char *accountname, g_free (msgcopy); } -/* This is kind of messy. */ -const char *convert_otr_msg (const char *msg) -{ - GRegex *regex_bold = g_regex_new ("]*)?>", 0, 0, NULL); - GRegex *regex_del = g_regex_new ("]*)?>", 0, 0, NULL); - gchar *msgnohtml = g_regex_replace_literal (regex_del, msg, -1, 0, "", 0, NULL); - - msg = g_regex_replace_literal (regex_bold, msgnohtml, -1, 0, "*", 0, NULL); - - g_free (msgnohtml); - g_regex_unref (regex_del); - g_regex_unref (regex_bold); - return msg; -} - -void ops_handle_msg_event(void *opdata, OtrlMessageEvent msg_event, +static void ops_handle_msg_event(void *opdata, OtrlMessageEvent msg_event, ConnContext *context, const char *message, gcry_error_t err) { @@ -140,10 +125,10 @@ void ops_handle_msg_event(void *opdata, OtrlMessageEvent msg_event, TXT_OPS_HANDLE_MSG, otr_msg_event_txt[msg_event], message); } -/* +/* * Gone secure. */ -void ops_secure (void *opdata, ConnContext *context) +static void ops_secure (void *opdata, ConnContext *context) { struct co_info *coi = context->app_data; char *trust = context->active_fingerprint->trust ?: ""; @@ -172,7 +157,7 @@ void ops_secure (void *opdata, ConnContext *context) /* * Gone insecure. */ -void ops_insecure (void *opdata, ConnContext *context) +static void ops_insecure (void *opdata, ConnContext *context) { struct co_info *coi = context->app_data; otr_notice (coi->ircctx, @@ -182,7 +167,7 @@ void ops_insecure (void *opdata, ConnContext *context) /* * Still secure? Need to find out what that means... */ -void ops_still_secure (void *opdata, ConnContext *context, int is_reply) +static void ops_still_secure (void *opdata, ConnContext *context, int is_reply) { struct co_info *coi = context->app_data; otr_notice (coi->ircctx, @@ -194,23 +179,23 @@ void ops_still_secure (void *opdata, ConnContext *context, int is_reply) * Unfortunately, we can't tell our peer which size to use. * (reminds me of MTU determination...) */ -int ops_max_msg (void *opdata, ConnContext *context) +static int ops_max_msg (void *opdata, ConnContext *context) { return OTR_MAX_MSG_SIZE; } -void ops_create_instag (void *opdata, const char *accountname, const char *protocol) +static void ops_create_instag (void *opdata, const char *accountname, const char *protocol) { otrl_instag_generate(otr_state, "/dev/null", accountname, protocol); - otr_writeinstags(otr_state); + otr_writeinstags(); } /* * A context changed. * I believe this is not happening for the SMP expects. */ -void ops_up_ctx_list (void *opdata) +static void ops_up_ctx_list (void *opdata) { statusbar_items_redraw ("otr"); } @@ -218,12 +203,12 @@ void ops_up_ctx_list (void *opdata) /* * Save fingerprint changes. */ -void ops_writefps (void *data) +static void ops_writefps (void *data) { otr_writefps (); } -int ops_is_logged_in (void *opdata, const char *accountname, +static int ops_is_logged_in (void *opdata, const char *accountname, const char *protocol, const char *recipient) { /*TODO register a handler for event 401 no such nick and set @@ -237,7 +222,7 @@ void otr_status_change (IRC_CTX *ircctx, const char *nick, int event) /* TODO: ? */ } -void ops_smp_event(void *opdata, OtrlSMPEvent smp_event, +static void ops_smp_event(void *opdata, OtrlSMPEvent smp_event, ConnContext *context, unsigned short progress_percent, char *question) { diff --git a/src/otr_util.c b/src/otr_util.c index fb2e3ad..d5d807b 100644 --- a/src/otr_util.c +++ b/src/otr_util.c @@ -82,7 +82,7 @@ void otrlib_deinit () /* * Free our app data. */ -void context_free_app_info (void *data) +static void context_free_app_info (void *data) { struct co_info *coi = data; if (coi->msgqueue) @@ -97,7 +97,7 @@ void context_free_app_info (void *data) * 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)); From 1348c4b94b9170f47e2d6d5a8c345bba6823b211 Mon Sep 17 00:00:00 2001 From: Patrick Griffis Date: Sat, 13 Feb 2016 06:37:53 -0500 Subject: [PATCH 27/49] Build system cleanup --- .gitignore | 6 +++++- Makefile.am | 24 ++++++++++++++++++++++-- configure.ac | 17 ++++++++++------- src/Makefile.am | 14 -------------- 4 files changed, 37 insertions(+), 24 deletions(-) delete mode 100644 src/Makefile.am diff --git a/.gitignore b/.gitignore index 819d806..813fcaa 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,7 @@ /autom4te.cache /aclocal.m4 /ar-lib +/build-aux /compile /configure /depcomp @@ -42,6 +43,9 @@ stamp-it Makefile Makefile.in Makefile.in.in +/m4 +/sub +.dirstamp # Gettext /po/POTFILES @@ -54,4 +58,4 @@ Makefile.in.in *~ *.patch *.diff - +tags diff --git a/Makefile.am b/Makefile.am index 06b84a8..e1c260b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,5 +1,25 @@ ACLOCAL_AMFLAGS = -I m4 -SUBDIRS = src +hexchatlib_LTLIBRARIES = otr.la +otr_la_SOURCES = \ + src/otr_key.c \ + src/otr_ops.c \ + src/otr_util.c \ + src/hexchat_otr.c \ + src/hexchat-formats.c -EXTRA_DIST = autogen.sh LICENSE +otr_la_CFLAGS = $(OTR_CFLAGS) $(GLIB_CFLAGS) $(GCRYPT_CFLAGS) +otr_la_LIBADD = $(OTR_LIBS) $(GLIB_LIBS) $(GCRYPT_LIBS) +otr_la_LDFLAGS = -avoid-version -module -export-symbols-regex hexchat_.* + +noinst_HEADERS = \ + src/otr.h \ + src/otr-formats.h \ + src/hexchat_otr.h + +src/otr-formats.h src/hexchat-formats.c: src/formats.txt + $(AM_V_GEN) python makeformats.py $< + +BUILT_SOURCES = src/otr-formats.h src/hexchat-formats.c + +EXTRA_DIST = $(BUILT_SOURCES) autogen.sh LICENSE src/formats.txt diff --git a/configure.ac b/configure.ac index d086635..0396204 100644 --- a/configure.ac +++ b/configure.ac @@ -3,7 +3,9 @@ AC_INIT([hexchat-otr], [0.1.0]) AC_CONFIG_SRCDIR([src/otr.h]) AC_CONFIG_HEADERS([config.h]) AC_CONFIG_MACRO_DIR([m4]) +AC_CONFIG_AUX_DIR([build-aux]) AC_PROG_CC +AC_PROG_CC_C99 AC_PROG_INSTALL AC_PATH_PROG([GCRYPT_CONFIG], [libgcrypt-config], [no]) @@ -11,30 +13,32 @@ AM_INIT_AUTOMAKE([1.11 silent-rules tar-pax dist-xz no-dist-gzip subdir-objects AM_SILENT_RULES([yes]) AM_PROG_AR +LT_PREREQ([2.2.0]) LT_INIT +PKG_PROG_PKG_CONFIG([0.28]) PKG_CHECK_MODULES([GLIB], [glib-2.0]) PKG_CHECK_MODULES([OTR], [libotr >= 4.0.0]) AC_MSG_CHECKING([for GCRYPT]) -if test "$GCRYPT_CONFIG" = "no"; then +AS_IF([test "$GCRYPT_CONFIG" = "no"], [ AC_MSG_ERROR([no]) -else +], [ GCRYPT_CFLAGS="`$GCRYPT_CONFIG --cflags`" GCRYPT_LIBS="`$GCRYPT_CONFIG --libs`" AC_SUBST([GCRYPT_CFLAGS]) AC_SUBST([GCRYPT_LIBS]) AC_MSG_RESULT([yes]) -fi +]) AC_MSG_CHECKING([for hexchat's plugin path]) -if $PKG_CONFIG hexchat-plugin --exists; then +AS_IF([$PKG_CONFIG hexchat-plugin --exists], [ hexchatlibdir="`$PKG_CONFIG --variable=hexchatlibdir hexchat-plugin`" AC_MSG_RESULT([$hexchatlibdir]) -else +], [ hexchatlibdir="$libdir/hexchat/plugins" AC_MSG_RESULT([not found, assuming $hexchatlibdir]) -fi +]) AC_SUBST([hexchatlibdir]) AX_APPEND_COMPILE_FLAGS([ \ @@ -61,7 +65,6 @@ AX_APPEND_COMPILE_FLAGS([ \ AC_CONFIG_FILES([ Makefile - src/Makefile ]) AC_OUTPUT diff --git a/src/Makefile.am b/src/Makefile.am deleted file mode 100644 index 8827e38..0000000 --- a/src/Makefile.am +++ /dev/null @@ -1,14 +0,0 @@ - -libdir = $(hexchatlibdir) - -lib_LTLIBRARIES = otr.la -otr_la_SOURCES = otr_key.c otr_ops.c otr_util.c hexchat_otr.c hexchat-formats.c -otr_la_CFLAGS = $(OTR_CFLAGS) $(GLIB_CFLAGS) $(GCRYPT_CFLAGS) -otr_la_LIBADD = $(OTR_LIBS) $(GLIB_LIBS) $(GCRYPT_LIBS) -otr_la_LDFLAGS = -avoid-version -module -export-symbols-regex hexchat_.* - -otr-formats.h hexchat-formats.c: formats.txt - $(AM_V_GEN) python makeformats.py $< - -EXTRA_DIST = formats.txt makeformats.py otr.h otr-formats.h hexchat_otr.h - From 0c24d4ebd1511136ce1517bf730e2eab864bc146 Mon Sep 17 00:00:00 2001 From: Patrick Griffis Date: Sat, 13 Feb 2016 06:46:59 -0500 Subject: [PATCH 28/49] Remove irssi references --- src/hexchat_otr.h | 3 --- src/otr_key.c | 23 ++++++++++++++--------- src/otr_ops.c | 10 ---------- src/otr_util.c | 2 -- 4 files changed, 14 insertions(+), 24 deletions(-) diff --git a/src/hexchat_otr.h b/src/hexchat_otr.h index 368dda3..a72e399 100644 --- a/src/hexchat_otr.h +++ b/src/hexchat_otr.h @@ -43,9 +43,6 @@ enum extern hexchat_plugin *ph; /* plugin handle */ -#define statusbar_items_redraw(name) ; -#define get_irssi_dir() hexchat_get_info (ph, "configdir") - void printformat (IRC_CTX *ircctx, const char *nick, int lvl, int fnum, ...); #define otr_noticest(formatnum, ...) \ diff --git a/src/otr_key.c b/src/otr_key.c index d3825c9..2b353d9 100644 --- a/src/otr_key.c +++ b/src/otr_key.c @@ -45,6 +45,11 @@ struct pid_t pid; } kg_st = { .status = KEYGEN_NO }; +static inline const char *get_configdir (void) +{ + return hexchat_get_info (ph, "configdir"); +} + static void keygen_childwatch (GPid pid, gint status, gpointer data) { struct pollfd pfd = { @@ -87,9 +92,9 @@ static gboolean keygen_complete (GIOChannel *source, GIOCondition condition, gpointer data) { gcry_error_t err; - const char *irssidir = get_irssi_dir (); - char *filename = g_strconcat (irssidir, KEYFILE, NULL); - char *tmpfilename = g_strconcat (irssidir, TMPKEYFILE, NULL); + const char *confdir = get_configdir (); + char *filename = g_strconcat (confdir, KEYFILE, NULL); + char *tmpfilename = g_strconcat (confdir, TMPKEYFILE, NULL); read (g_io_channel_unix_get_fd (kg_st.ch[0]), &err, sizeof(err)); @@ -135,7 +140,7 @@ void keygen_run (const char *accname) gcry_error_t err; int ret; int fds[2]; - char *filename = g_strconcat (get_irssi_dir (), TMPKEYFILE, NULL); + char *filename = g_strconcat (get_configdir (), TMPKEYFILE, NULL); char *dir = g_path_get_dirname (filename); if (kg_st.status != KEYGEN_NO) @@ -241,7 +246,7 @@ void keygen_abort (int ignoreidle) void otr_writefps () { gcry_error_t err; - char *filename = g_strconcat (get_irssi_dir (), FPSFILE, NULL); + char *filename = g_strconcat (get_configdir (), FPSFILE, NULL); err = otrl_privkey_write_fingerprints (otr_state, filename); @@ -264,7 +269,7 @@ void otr_writefps () void key_load () { gcry_error_t err; - char *filename = g_strconcat (get_irssi_dir (), KEYFILE, NULL); + char *filename = g_strconcat (get_configdir (), KEYFILE, NULL); if (!g_file_test (filename, G_FILE_TEST_EXISTS)) { @@ -293,7 +298,7 @@ void key_load () void fps_load () { gcry_error_t err; - char *filename = g_strconcat (get_irssi_dir (), FPSFILE, NULL); + char *filename = g_strconcat (get_configdir (), FPSFILE, NULL); if (!g_file_test (filename, G_FILE_TEST_EXISTS)) { @@ -322,7 +327,7 @@ void fps_load () void otr_writeinstags(void) { gcry_error_t err; - char *filename = g_strconcat(get_irssi_dir (), INSTAGFILE, NULL); + char *filename = g_strconcat(get_configdir (), INSTAGFILE, NULL); err = otrl_instag_write (otr_state, filename); @@ -345,7 +350,7 @@ void otr_writeinstags(void) void instag_load(void) { gcry_error_t err; - char *filename = g_strconcat(get_irssi_dir (), INSTAGFILE, NULL); + char *filename = g_strconcat(get_configdir (), INSTAGFILE, NULL); if (!g_file_test(filename, G_FILE_TEST_EXISTS)) { diff --git a/src/otr_ops.c b/src/otr_ops.c index 6727ee4..64c582a 100644 --- a/src/otr_ops.c +++ b/src/otr_ops.c @@ -191,15 +191,6 @@ static void ops_create_instag (void *opdata, const char *accountname, const char otr_writeinstags(); } -/* - * A context changed. - * I believe this is not happening for the SMP expects. - */ -static void ops_up_ctx_list (void *opdata) -{ - statusbar_items_redraw ("otr"); -} - /* * Save fingerprint changes. */ @@ -289,7 +280,6 @@ void otr_initops () otr_ops.gone_insecure = ops_insecure; otr_ops.still_secure = ops_still_secure; otr_ops.max_message_size = ops_max_msg; - otr_ops.update_context_list = ops_up_ctx_list; otr_ops.write_fingerprints = ops_writefps; otr_ops.is_logged_in = ops_is_logged_in; } diff --git a/src/otr_util.c b/src/otr_util.c index d5d807b..4d9c3cc 100644 --- a/src/otr_util.c +++ b/src/otr_util.c @@ -604,8 +604,6 @@ void otr_auth (IRC_CTX *ircctx, char *nick, const char *peername, const char *qu otr_notice (ircctx, nick, coi->received_smp_init ? TXT_AUTH_RESPONDING : TXT_AUTH_INITIATED); - statusbar_items_redraw ("otr"); - if (peername) *pserver = '@'; } From 9d4448a27a6c1b3cc64f318608b51fa244478c0f Mon Sep 17 00:00:00 2001 From: Patrick Griffis Date: Sat, 13 Feb 2016 06:56:46 -0500 Subject: [PATCH 29/49] Add editorconfig file --- .editorconfig | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..5cbbd78 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,8 @@ +root = true +[*] +end_of_line = lf +charset = utf-8 +indent_style = tab +indent_size = 4 +insert_final_newline = true +trim_trailing_whitespace = true From eae4c2fd94f45474bb6f8a8c7ffc252ff2e7b258 Mon Sep 17 00:00:00 2001 From: Patrick Griffis Date: Sat, 13 Feb 2016 07:04:54 -0500 Subject: [PATCH 30/49] Bump version --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 0396204..fb1477c 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ AC_PREREQ([2.69]) -AC_INIT([hexchat-otr], [0.1.0]) +AC_INIT([hexchat-otr], [0.2.0]) AC_CONFIG_SRCDIR([src/otr.h]) AC_CONFIG_HEADERS([config.h]) AC_CONFIG_MACRO_DIR([m4]) From 232aa7bf9d7edc5e8cde9eceb81ff37346dee51d Mon Sep 17 00:00:00 2001 From: Patrick Griffis Date: Sat, 13 Feb 2016 07:30:42 -0500 Subject: [PATCH 31/49] Fix generating formats This doesn't affect releases --- Makefile.am | 4 ++-- src/makeformats.py | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Makefile.am b/Makefile.am index e1c260b..993c16d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -18,8 +18,8 @@ noinst_HEADERS = \ src/hexchat_otr.h src/otr-formats.h src/hexchat-formats.c: src/formats.txt - $(AM_V_GEN) python makeformats.py $< + $(AM_V_GEN) python src/makeformats.py $< src BUILT_SOURCES = src/otr-formats.h src/hexchat-formats.c -EXTRA_DIST = $(BUILT_SOURCES) autogen.sh LICENSE src/formats.txt +EXTRA_DIST = $(BUILT_SOURCES) autogen.sh LICENSE src/formats.txt src/makeformats.py diff --git a/src/makeformats.py b/src/makeformats.py index 3d910dd..7163951 100755 --- a/src/makeformats.py +++ b/src/makeformats.py @@ -9,8 +9,9 @@ lines = map(lambda x: x.strip(),open(sys.argv[1],"r").readlines()) -hdr = open("otr-formats.h","w") -srcx = open("hexchat-formats.c","w") +out_dir = sys.argv[2] if len(sys.argv) > 2 or "." +hdr = open(os.path.join(out_dir, "otr-formats.h"), "w") +srcx = open(os.path.join(out_dir, "hexchat-formats.c"), "w") srcx.write('#include "otr.h"\n'); srcx.write('FORMAT_REC formats[] = {\n\t') From 58db3e0a3e19a9c200a1c90b68c6b13046cc69e0 Mon Sep 17 00:00:00 2001 From: Petter Reinholdtsen Date: Thu, 18 Feb 2016 12:24:53 +0100 Subject: [PATCH 32/49] Fix typos discovered by codespell. --- src/formats.txt | 4 ++-- src/hexchat-formats.c | 2 +- src/otr_key.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/formats.txt b/src/formats.txt index 56cd8b9..065fce2 100644 --- a/src/formats.txt +++ b/src/formats.txt @@ -6,7 +6,7 @@ kg_aborted_dir Key generation for %s: aborted, failed creating directory %s: %s kg_mkdir created directory %s kg_pipe Key generation for %s: error creating pipe: %s kg_fork Key generation for %s: fork() error: %s -kg_initiated Key generation for %s: initiated. This might take several minutes or on some systems even an hour. If you wanna check that something is happening, see if there are two processes of your IRC client. +kg_initiated Key generation for %s: initiated. This might take several minutes or on some systems even an hour. If you want to check that something is happening, see if there are two processes of your IRC client. kg_exited Key generation for %s: child terminated for unknown reason kg_exitsig Key generation for %s: child was killed by signal %s kg_pollerr Key generation for %s: error poll()ing child: %s @@ -101,4 +101,4 @@ st_smp_outgoing {sb {hilight awaiting auth reply...}} st_smp_finalize {sb {hilight finalizing auth...}} st_smp_unknown {sb {hilight unknown auth state!}} st_finished {sb finished} -st_unknown {sb {hilight state unknown (BUG!)}} \ No newline at end of file +st_unknown {sb {hilight state unknown (BUG!)}} diff --git a/src/hexchat-formats.c b/src/hexchat-formats.c index f473d33..590a85d 100644 --- a/src/hexchat-formats.c +++ b/src/hexchat-formats.c @@ -9,7 +9,7 @@ FORMAT_REC formats[] = { { "kg_mkdir", "created directory %s" }, { "kg_pipe", "Key generation for %s: error creating pipe: %s" }, { "kg_fork", "Key generation for %s: fork() error: %s" }, - { "kg_initiated", "Key generation for %s: initiated. This might take several minutes or on some systems even an hour. If you wanna check that something is happening, see if there are two processes of your IRC client." }, + { "kg_initiated", "Key generation for %s: initiated. This might take several minutes or on some systems even an hour. If you want to check that something is happening, see if there are two processes of your IRC client." }, { "kg_exited", "Key generation for %s: child terminated for unknown reason" }, { "kg_exitsig", "Key generation for %s: child was killed by signal %s" }, { "kg_pollerr", "Key generation for %s: error poll()ing child: %s" }, diff --git a/src/otr_key.c b/src/otr_key.c index 2b353d9..4a79fe4 100644 --- a/src/otr_key.c +++ b/src/otr_key.c @@ -131,7 +131,7 @@ static gboolean keygen_complete (GIOChannel *source, GIOCondition condition, } /* - * Run key generation in a seperate process (takes ages). + * Run key generation in a separate process (takes ages). * The other process will rewrite the key file, we shouldn't * change anything till it's done and we've reloaded the keys. */ From 14ec99781eb5c76356db6ecebf2251d732446de1 Mon Sep 17 00:00:00 2001 From: Patrick Griffis Date: Thu, 18 Feb 2016 07:35:34 -0500 Subject: [PATCH 33/49] makeformats: Fix Python syntax Closes #14 --- src/makeformats.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/makeformats.py b/src/makeformats.py index 7163951..ca80386 100755 --- a/src/makeformats.py +++ b/src/makeformats.py @@ -9,7 +9,7 @@ lines = map(lambda x: x.strip(),open(sys.argv[1],"r").readlines()) -out_dir = sys.argv[2] if len(sys.argv) > 2 or "." +out_dir = sys.argv[2] if len(sys.argv) > 2 else "." hdr = open(os.path.join(out_dir, "otr-formats.h"), "w") srcx = open(os.path.join(out_dir, "hexchat-formats.c"), "w") From ffa471fde9a1deb207166595b7748fc8eb7bad4f Mon Sep 17 00:00:00 2001 From: Petter Reinholdtsen Date: Thu, 18 Feb 2016 11:50:17 +0100 Subject: [PATCH 34/49] Check exit values from read() and write() when generating OTR keys. This get rid of two compiler warnings. --- src/otr_key.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/otr_key.c b/src/otr_key.c index 4a79fe4..01f24b8 100644 --- a/src/otr_key.c +++ b/src/otr_key.c @@ -96,7 +96,13 @@ static gboolean keygen_complete (GIOChannel *source, GIOCondition condition, char *filename = g_strconcat (confdir, KEYFILE, NULL); char *tmpfilename = g_strconcat (confdir, TMPKEYFILE, NULL); - read (g_io_channel_unix_get_fd (kg_st.ch[0]), &err, sizeof(err)); + if (-1 == read (g_io_channel_unix_get_fd (kg_st.ch[0]), &err, sizeof(err))) + { + otr_noticest (TXT_KG_FAILED, + kg_st.accountname, + strerror(errno), + "read failed"); + } g_io_channel_shutdown (kg_st.ch[0], FALSE, NULL); g_io_channel_shutdown (kg_st.ch[1], FALSE, NULL); @@ -208,7 +214,10 @@ void keygen_run (const char *accname) /* child */ err = otrl_privkey_generate (otr_state, filename, accname, PROTOCOLID); - write (fds[1], &err, sizeof(err)); + if (sizeof(err) != write (fds[1], &err, sizeof(err))) + { + perror("keygen_run - unable to write to stdout pipe"); + } _exit (0); } From 5fe6c93800d208c0a77f9b9b46522e8e25d42e4c Mon Sep 17 00:00:00 2001 From: Patrick Griffis Date: Thu, 18 Feb 2016 08:41:00 -0500 Subject: [PATCH 35/49] Consistently include license headers Fixes #13 --- Makefile.am | 2 +- src/hexchat-formats.c | 17 +++++++++++++++++ src/hexchat_otr.c | 15 +++++++++++++++ src/hexchat_otr.h | 16 ++++++++++++++++ src/makeformats.py | 35 +++++++++++++++++++++++++++++++++++ src/otr-formats.h | 17 +++++++++++++++++ 6 files changed, 101 insertions(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index 993c16d..2c6ed42 100644 --- a/Makefile.am +++ b/Makefile.am @@ -17,7 +17,7 @@ noinst_HEADERS = \ src/otr-formats.h \ src/hexchat_otr.h -src/otr-formats.h src/hexchat-formats.c: src/formats.txt +src/otr-formats.h src/hexchat-formats.c: src/formats.txt src/makeformats.py $(AM_V_GEN) python src/makeformats.py $< src BUILT_SOURCES = src/otr-formats.h src/hexchat-formats.c diff --git a/src/hexchat-formats.c b/src/hexchat-formats.c index 590a85d..7aca5df 100644 --- a/src/hexchat-formats.c +++ b/src/hexchat-formats.c @@ -1,3 +1,20 @@ + +/* + * 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" FORMAT_REC formats[] = { { MODULE_NAME, "otr" }, diff --git a/src/hexchat_otr.c b/src/hexchat_otr.c index d6c82b7..7bef9ed 100644 --- a/src/hexchat_otr.c +++ b/src/hexchat_otr.c @@ -1,3 +1,18 @@ +/* + * 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; diff --git a/src/hexchat_otr.h b/src/hexchat_otr.h index a72e399..9b7d909 100644 --- a/src/hexchat_otr.h +++ b/src/hexchat_otr.h @@ -1,3 +1,19 @@ +/* + * 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 "config.h" #include diff --git a/src/makeformats.py b/src/makeformats.py index ca80386..d5adfa9 100755 --- a/src/makeformats.py +++ b/src/makeformats.py @@ -4,15 +4,50 @@ # # Just a short script to generate our FORMAT_REC # +# 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 import sys,os,re +GPL_LICENSE = """ +/* + * 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 + */ + +""" + lines = map(lambda x: x.strip(),open(sys.argv[1],"r").readlines()) out_dir = sys.argv[2] if len(sys.argv) > 2 else "." hdr = open(os.path.join(out_dir, "otr-formats.h"), "w") srcx = open(os.path.join(out_dir, "hexchat-formats.c"), "w") +srcx.write(GPL_LICENSE) +hdr.write(GPL_LICENSE) + srcx.write('#include "otr.h"\n'); srcx.write('FORMAT_REC formats[] = {\n\t') srcx.write('{ MODULE_NAME, "otr" }') diff --git a/src/otr-formats.h b/src/otr-formats.h index 70318db..f07d4a4 100644 --- a/src/otr-formats.h +++ b/src/otr-formats.h @@ -1,3 +1,20 @@ + +/* + * 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 + */ + enum { TXT_OTR_MODULE_NAME, From 9cf577916fd875c5aa45167b3e78c196b539050c Mon Sep 17 00:00:00 2001 From: Patrick Griffis Date: Tue, 23 Feb 2016 10:46:54 -0500 Subject: [PATCH 36/49] build: Print useful error when autoconf-archive missing Closes #17 --- configure.ac | 3 +++ 1 file changed, 3 insertions(+) diff --git a/configure.ac b/configure.ac index fb1477c..874fb17 100644 --- a/configure.ac +++ b/configure.ac @@ -13,6 +13,9 @@ AM_INIT_AUTOMAKE([1.11 silent-rules tar-pax dist-xz no-dist-gzip subdir-objects AM_SILENT_RULES([yes]) AM_PROG_AR +AC_DEFUN([HOTR_CHECK_MACRO], [m4_ifndef([$1], [m4_fatal([macro ]$1[ is not defined. Is ]$2[ installed?])])]) +HOTR_CHECK_MACRO([AX_APPEND_COMPILE_FLAGS], [autoconf-archive]) + LT_PREREQ([2.2.0]) LT_INIT From 243efd269eb45d54349fa104f472bc6a0f415926 Mon Sep 17 00:00:00 2001 From: Petter Reinholdtsen Date: Fri, 20 May 2016 18:50:13 -0400 Subject: [PATCH 37/49] Use network rather than server for account name Note that this will require regenerating keys as they are not migrated. Closes #7 --- src/hexchat_otr.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/hexchat_otr.c b/src/hexchat_otr.c index 7bef9ed..7e521c6 100644 --- a/src/hexchat_otr.c +++ b/src/hexchat_otr.c @@ -64,10 +64,10 @@ static int cmd_otr (char *word[], char *word_eol[], void *userdata) { const char *own_nick = hexchat_get_info (ph, "nick"); char *target = (char *)hexchat_get_info (ph, "channel"); - const char *server = hexchat_get_info (ph, "server"); + const char *network = hexchat_get_info (ph, "network"); IRC_CTX ircctxs = { .nick = (char *)own_nick, - .address = (char *)server + .address = (char *)network }, *ircctx = &ircctxs; @@ -189,12 +189,12 @@ static int hook_outgoing (char *word[], char *word_eol[], void *userdata) { const char *own_nick = hexchat_get_info (ph, "nick"); const char *channel = hexchat_get_info (ph, "channel"); - const char *server = hexchat_get_info (ph, "server"); + const char *network = hexchat_get_info (ph, "network"); char newmsg[512]; char *otrmsg; IRC_CTX ircctx = { .nick = (char *)own_nick, - .address = (char *)server + .address = (char *)network }; if (get_current_context_type () != 3) /* Not PM */ @@ -224,12 +224,12 @@ static int hook_privmsg (char *word[], char *word_eol[], void *userdata) { char nick[256]; char *newmsg; - const char *server = hexchat_get_info (ph, "server"); + const char *network = hexchat_get_info (ph, "network"); const char *own_nick = hexchat_get_info (ph, "nick"); const char *chantypes = hexchat_list_str (ph, NULL, "chantypes"); IRC_CTX ircctx = { .nick = (char *)own_nick, - .address = (char *)server + .address = (char *)network }; hexchat_context *query_ctx; @@ -254,11 +254,11 @@ static int hook_privmsg (char *word[], char *word_eol[], void *userdata) return HEXCHAT_EAT_NONE; } - query_ctx = hexchat_find_context (ph, server, nick); + query_ctx = hexchat_find_context (ph, network, nick); if (query_ctx == NULL) { hexchat_commandf (ph, "query %s", nick); - query_ctx = hexchat_find_context (ph, server, nick); + query_ctx = hexchat_find_context (ph, network, nick); } GRegex *regex_quot = g_regex_new (""", 0, 0, NULL); @@ -348,19 +348,19 @@ void printformat (IRC_CTX *ircctx, const char *nick, int lvl, int fnum, ...) va_start (params, fnum); char msg[LOGMAX], *s = msg; hexchat_context *find_query_ctx; - char *server = NULL; + char *network = NULL; if (ircctx) - server = ircctx->address; + network = ircctx->address; - if (server && nick) + if (network && nick) { - find_query_ctx = hexchat_find_context (ph, server, nick); + find_query_ctx = hexchat_find_context (ph, network, nick); if (find_query_ctx == NULL) { /* no query window yet, let's open one */ hexchat_commandf (ph, "query %s", nick); - find_query_ctx = hexchat_find_context (ph, server, nick); + find_query_ctx = hexchat_find_context (ph, network, nick); } } else @@ -369,7 +369,7 @@ void printformat (IRC_CTX *ircctx, const char *nick, int lvl, int fnum, ...) NULL, hexchat_get_info (ph, "network") - ?: hexchat_get_info (ph, "server")); + ?: hexchat_get_info (ph, "network")); } hexchat_set_context (ph, find_query_ctx); From 12f84706a9f1991ab5138e2be3e74a2b61428a58 Mon Sep 17 00:00:00 2001 From: Patrick Griffis Date: Fri, 20 May 2016 18:54:08 -0400 Subject: [PATCH 38/49] Ignore format-nonliteral error in newer GCC This is less than ideal but we can assert that the format string is safe as they are literals in hexchat-formats.c --- src/otr_util.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/otr_util.c b/src/otr_util.c index 4d9c3cc..206fa0c 100644 --- a/src/otr_util.c +++ b/src/otr_util.c @@ -107,8 +107,11 @@ static void context_add_app_info (void *data, ConnContext *co) co->app_data_free = context_free_app_info; coi->ircctx = ircctx; + +#pragma GCC diagnostic ignored "-Wformat-nonliteral" g_snprintf (coi->better_msg_two, sizeof(coi->better_msg_two), formats[TXT_OTR_BETTER_TWO].def, co->accountname); +#pragma GCC diagnostic pop } /* From b38b648295d167994ee02abcf2fce7eed32097a6 Mon Sep 17 00:00:00 2001 From: Patrick Griffis Date: Sun, 7 Aug 2016 06:49:59 -0400 Subject: [PATCH 39/49] Bump version to 0.2.1 --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 874fb17..ed8bb7c 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ AC_PREREQ([2.69]) -AC_INIT([hexchat-otr], [0.2.0]) +AC_INIT([hexchat-otr], [0.2.1]) AC_CONFIG_SRCDIR([src/otr.h]) AC_CONFIG_HEADERS([config.h]) AC_CONFIG_MACRO_DIR([m4]) From 41fb5767456ccf9121ee70e7d3667700f4bd2c71 Mon Sep 17 00:00:00 2001 From: Ashish SHUKLA Date: Mon, 6 Feb 2017 01:42:33 +0530 Subject: [PATCH 40/49] Ignore format-nonliteral error in clang This is less than ideal but we can assert that the format string is safe as they are literals in hexchat-formats.c --- src/hexchat_otr.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/hexchat_otr.c b/src/hexchat_otr.c index 7e521c6..7a0031e 100644 --- a/src/hexchat_otr.c +++ b/src/hexchat_otr.c @@ -374,7 +374,9 @@ void printformat (IRC_CTX *ircctx, const char *nick, int lvl, int fnum, ...) hexchat_set_context (ph, find_query_ctx); +#pragma GCC diagnostic ignored "-Wformat-nonliteral" if (g_vsnprintf (msg, sizeof(msg), formats[fnum].def, params) < 0) +#pragma GCC diagnostic pop g_snprintf (msg, sizeof(msg), "internal error parsing error string (BUG)"); va_end (params); hexchat_printf (ph, "OTR: %s", s); From 2ef419e4e579925427620dddcd545a089e2bc3ce Mon Sep 17 00:00:00 2001 From: Patrick Griffis Date: Wed, 12 Apr 2017 21:02:47 -0400 Subject: [PATCH 41/49] Fix format error on some compilers Some seem to count the pragma as the code line Closes #24 --- src/hexchat_otr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hexchat_otr.c b/src/hexchat_otr.c index 7a0031e..1266155 100644 --- a/src/hexchat_otr.c +++ b/src/hexchat_otr.c @@ -376,8 +376,8 @@ void printformat (IRC_CTX *ircctx, const char *nick, int lvl, int fnum, ...) #pragma GCC diagnostic ignored "-Wformat-nonliteral" if (g_vsnprintf (msg, sizeof(msg), formats[fnum].def, params) < 0) -#pragma GCC diagnostic pop g_snprintf (msg, sizeof(msg), "internal error parsing error string (BUG)"); +#pragma GCC diagnostic pop va_end (params); hexchat_printf (ph, "OTR: %s", s); } From c27d6de85104216032a81e1564a85dc0d1bf0c99 Mon Sep 17 00:00:00 2001 From: Patrick Griffis Date: Wed, 12 Apr 2017 21:28:38 -0400 Subject: [PATCH 42/49] Bump version --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index ed8bb7c..651af60 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ AC_PREREQ([2.69]) -AC_INIT([hexchat-otr], [0.2.1]) +AC_INIT([hexchat-otr], [0.2.2]) AC_CONFIG_SRCDIR([src/otr.h]) AC_CONFIG_HEADERS([config.h]) AC_CONFIG_MACRO_DIR([m4]) From a7a60165fad14df23c26132aa4f8125e1c66bdd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillaume=20Cor=C3=A9?= Date: Tue, 25 Apr 2017 09:58:42 +0200 Subject: [PATCH 43/49] add prototypes to fix -Werror=missing-prototypes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit src/hexchat_otr.c:328:5: error: no previous prototype for ‘hexchat_plugin_deinit’ [-Werror=missing-prototypes] --- src/hexchat_otr.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/hexchat_otr.h b/src/hexchat_otr.h index 9b7d909..0bd21fc 100644 --- a/src/hexchat_otr.h +++ b/src/hexchat_otr.h @@ -59,6 +59,13 @@ enum extern hexchat_plugin *ph; /* plugin handle */ +int hexchat_plugin_deinit (void); +int hexchat_plugin_init (hexchat_plugin *plugin_handle, + char **plugin_name, + char **plugin_desc, + char **plugin_version, + char *arg); +void hexchat_plugin_get_info (char **name, char **desc, char **version, void **reserved); void printformat (IRC_CTX *ircctx, const char *nick, int lvl, int fnum, ...); #define otr_noticest(formatnum, ...) \ From d9ccf688b83e333e0d231938cb75874e500db2f1 Mon Sep 17 00:00:00 2001 From: Patrick Griffis Date: Sun, 23 Sep 2018 16:43:46 -0400 Subject: [PATCH 44/49] Port buildsystem to Meson local_install option relevant to #18 --- .gitignore | 62 +------------------- Makefile.am | 25 --------- Readme.md | 16 +++++- autogen.sh | 26 --------- configure.ac | 78 ------------------------- meson.build | 77 +++++++++++++++++++++++++ meson_options.txt | 3 + src/hexchat-formats.c | 128 ------------------------------------------ src/hexchat_otr.h | 15 ++--- src/makeformats.py | 4 +- src/meson.build | 27 +++++++++ src/otr-formats.h | 127 ----------------------------------------- 12 files changed, 131 insertions(+), 457 deletions(-) delete mode 100644 Makefile.am delete mode 100755 autogen.sh delete mode 100644 configure.ac create mode 100644 meson.build create mode 100644 meson_options.txt delete mode 100644 src/hexchat-formats.c create mode 100644 src/meson.build delete mode 100644 src/otr-formats.h diff --git a/.gitignore b/.gitignore index 813fcaa..f3d6549 100644 --- a/.gitignore +++ b/.gitignore @@ -1,61 +1 @@ -# C -*.o -*.ko -*.obj -*.elf -*.gch -*.pch -*.lib -*.a -*.la -*.lo -*.dll -*.so -*.so.* -*.dylib -*.exe -*.out -*.app -*.i*86 -*.x86_64 -*.hex -*.tar.xz - -# Autotools -/autom4te.cache -/aclocal.m4 -/ar-lib -/build-aux -/compile -/configure -/depcomp -/install-sh -/ltmain.sh -/missing -/libtool -/test-driver -/config.* -/test/test-suite.log -.deps/ -.libs/ -stamp-h1 -stamp-it -Makefile -Makefile.in -Makefile.in.in -/m4 -/sub -.dirstamp - -# Gettext -/po/POTFILES -/po/.intltool-merge-cache -*.mo -*.gmo -*.pot - -# Misc -*~ -*.patch -*.diff -tags +/build/ \ No newline at end of file diff --git a/Makefile.am b/Makefile.am deleted file mode 100644 index 2c6ed42..0000000 --- a/Makefile.am +++ /dev/null @@ -1,25 +0,0 @@ -ACLOCAL_AMFLAGS = -I m4 - -hexchatlib_LTLIBRARIES = otr.la -otr_la_SOURCES = \ - src/otr_key.c \ - src/otr_ops.c \ - src/otr_util.c \ - src/hexchat_otr.c \ - src/hexchat-formats.c - -otr_la_CFLAGS = $(OTR_CFLAGS) $(GLIB_CFLAGS) $(GCRYPT_CFLAGS) -otr_la_LIBADD = $(OTR_LIBS) $(GLIB_LIBS) $(GCRYPT_LIBS) -otr_la_LDFLAGS = -avoid-version -module -export-symbols-regex hexchat_.* - -noinst_HEADERS = \ - src/otr.h \ - src/otr-formats.h \ - src/hexchat_otr.h - -src/otr-formats.h src/hexchat-formats.c: src/formats.txt src/makeformats.py - $(AM_V_GEN) python src/makeformats.py $< src - -BUILT_SOURCES = src/otr-formats.h src/hexchat-formats.c - -EXTRA_DIST = $(BUILT_SOURCES) autogen.sh LICENSE src/formats.txt src/makeformats.py diff --git a/Readme.md b/Readme.md index de0e80d..c6ccbd6 100644 --- a/Readme.md +++ b/Readme.md @@ -14,11 +14,21 @@ Installation - gcrypt - libotr4 - hexchat +- meson + +#### User install + +```sh +meson builddir -Dlocal_install=true +ninja -C builddir install +``` + +#### System install ```sh -./autogen.sh -make -s -sudo make install +meson builddir +ninja -C builddir +sudo ninja -C builddir install ``` Usage diff --git a/autogen.sh b/autogen.sh deleted file mode 100755 index cfdc230..0000000 --- a/autogen.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/sh -# Run this to generate all the initial makefiles, etc. - -srcdir=`dirname $0` -test -z "$srcdir" && srcdir=. - -(test -f $srcdir/configure.ac) || { - echo -n "**Error**: Directory "\`$srcdir\'" does not look like the top-level directory" - exit 1 -} - -aclocal --install -I m4 || exit 1 -libtoolize --quiet --copy || exit 1 -autoreconf --install -Wno-portability || exit 1 - -if [ "$NOCONFIGURE" = "" ]; then - $srcdir/configure "$@" || exit 1 - - if [ "$1" = "--help" ]; then exit 0 else - echo "Now type \`make\' to compile" || exit 1 - fi -else - echo "Skipping configure process." -fi - -set +x diff --git a/configure.ac b/configure.ac deleted file mode 100644 index 651af60..0000000 --- a/configure.ac +++ /dev/null @@ -1,78 +0,0 @@ -AC_PREREQ([2.69]) -AC_INIT([hexchat-otr], [0.2.2]) -AC_CONFIG_SRCDIR([src/otr.h]) -AC_CONFIG_HEADERS([config.h]) -AC_CONFIG_MACRO_DIR([m4]) -AC_CONFIG_AUX_DIR([build-aux]) -AC_PROG_CC -AC_PROG_CC_C99 -AC_PROG_INSTALL -AC_PATH_PROG([GCRYPT_CONFIG], [libgcrypt-config], [no]) - -AM_INIT_AUTOMAKE([1.11 silent-rules tar-pax dist-xz no-dist-gzip subdir-objects no-define foreign -Wall]) -AM_SILENT_RULES([yes]) -AM_PROG_AR - -AC_DEFUN([HOTR_CHECK_MACRO], [m4_ifndef([$1], [m4_fatal([macro ]$1[ is not defined. Is ]$2[ installed?])])]) -HOTR_CHECK_MACRO([AX_APPEND_COMPILE_FLAGS], [autoconf-archive]) - -LT_PREREQ([2.2.0]) -LT_INIT - -PKG_PROG_PKG_CONFIG([0.28]) -PKG_CHECK_MODULES([GLIB], [glib-2.0]) -PKG_CHECK_MODULES([OTR], [libotr >= 4.0.0]) - -AC_MSG_CHECKING([for GCRYPT]) -AS_IF([test "$GCRYPT_CONFIG" = "no"], [ - AC_MSG_ERROR([no]) -], [ - GCRYPT_CFLAGS="`$GCRYPT_CONFIG --cflags`" - GCRYPT_LIBS="`$GCRYPT_CONFIG --libs`" - AC_SUBST([GCRYPT_CFLAGS]) - AC_SUBST([GCRYPT_LIBS]) - AC_MSG_RESULT([yes]) -]) - -AC_MSG_CHECKING([for hexchat's plugin path]) -AS_IF([$PKG_CONFIG hexchat-plugin --exists], [ - hexchatlibdir="`$PKG_CONFIG --variable=hexchatlibdir hexchat-plugin`" - AC_MSG_RESULT([$hexchatlibdir]) -], [ - hexchatlibdir="$libdir/hexchat/plugins" - AC_MSG_RESULT([not found, assuming $hexchatlibdir]) -]) -AC_SUBST([hexchatlibdir]) - -AX_APPEND_COMPILE_FLAGS([ \ - -std=gnu99 \ - -funsigned-char \ - -fstack-protector-strong \ - -fPIE \ - -fPIC \ - -Wall \ - -Wextra \ - -Wconversion \ - -Winline \ - -Wno-padded \ - -Wno-unused-parameter \ - -Wstrict-prototypes \ - -Wmissing-prototypes \ - -Werror=implicit-function-declaration \ - -Werror=pointer-arith \ - -Werror=init-self \ - -Werror=format=2 \ - -Werror=missing-include-dirs \ - -Werror=date-time \ -]) - -AC_CONFIG_FILES([ - Makefile -]) - -AC_OUTPUT -echo " - $PACKAGE $VERSION - - install location: ${hexchatlibdir} -" diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..453e13a --- /dev/null +++ b/meson.build @@ -0,0 +1,77 @@ +project('hexchat-otr', 'c', + version: '0.2.2', + meson_version: '>= 0.46', + default_options: [ + 'c_std=gnu99', + 'buildtype=debugoptimized', + 'warning_level=2', + ] +) + +cc = meson.get_compiler('c') + +add_project_arguments(cc.get_supported_arguments([ + '-fvisibility=hidden', + '-funsigned-char', + '-fstack-protector-strong', + '-fPIE', + '-fPIC', + '-Wconversion', + '-Winline', + '-Wno-padded', + '-Wno-unused-parameter', + '-Wstrict-prototypes', + '-Wmissing-prototypes', + '-Werror=implicit-function-declaration', + '-Werror=pointer-arith', + '-Werror=init-self', + '-Werror=format=2', + '-Werror=missing-include-dirs', + '-Werror=date-time', +]), language: 'c') + +add_project_link_arguments(cc.get_supported_link_arguments([ + '-Wl,-z,relro', + '-Wl,-z,now', +]), language: 'c') + +config = configuration_data() +config.set_quoted('PACKAGE_VERSION', meson.project_version()) +configure_file( + configuration: config, + output: 'config.h', +) +config_dep = declare_dependency(include_directories: include_directories('.')) + +glib_dep = dependency('glib-2.0') +otr_dep = dependency('libotr', version: '>= 4.0.0') +hexchat_dep = dependency('hexchat-plugin') +# Added in 0.49 +# https://github.com/mesonbuild/meson/pull/4246 +# gcrypt_dep = dependency('libgcrypt') + +gcrypt_config = find_program('libgcrypt-config') +ret = run_command([gcrypt_config, '--cflags']) +if ret.returncode() != 0 + error('Failed to get gcrypt flags') +endif +gcrypt_cflags = ret.stdout().strip().split() +ret = run_command([gcrypt_config, '--libs']) +if ret.returncode() != 0 + error('Failed to get gcrypt libs') +endif +gcrypt_libs = ret.stdout().strip().split() + +if get_option('local_install') + # Replace this with check: true in 0.47+ + ret = run_command([find_program('hexchat'), '--configdir']) + if ret.returncode() != 0 + error('Failed to get hexchat configdir') + endif + hexchatplugindir = join_paths(ret.stdout().strip(), 'addons') +else + hexchatplugindir = hexchat_dep.get_pkgconfig_variable('hexchatlibdir') +endif +message('Install location: ' + hexchatplugindir) + +subdir('src') diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 0000000..d2dc490 --- /dev/null +++ b/meson_options.txt @@ -0,0 +1,3 @@ +option('local_install', type: 'boolean', + description: 'Install the plugin into your home directory' +) \ No newline at end of file diff --git a/src/hexchat-formats.c b/src/hexchat-formats.c deleted file mode 100644 index 7aca5df..0000000 --- a/src/hexchat-formats.c +++ /dev/null @@ -1,128 +0,0 @@ - -/* - * 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" -FORMAT_REC formats[] = { - { MODULE_NAME, "otr" }, - { NULL, "Keys" }, - { "kg_failed", "Key generation for %s: failed: %s (%s)" }, - { "kg_completed", "Key generation for %s: completed in %d seconds. Reloading keys" }, - { "kg_aborted_dup", "Key generation for %s: aborted. Key generation for %s still in progress" }, - { "kg_aborted_dir", "Key generation for %s: aborted, failed creating directory %s: %s" }, - { "kg_mkdir", "created directory %s" }, - { "kg_pipe", "Key generation for %s: error creating pipe: %s" }, - { "kg_fork", "Key generation for %s: fork() error: %s" }, - { "kg_initiated", "Key generation for %s: initiated. This might take several minutes or on some systems even an hour. If you want to check that something is happening, see if there are two processes of your IRC client." }, - { "kg_exited", "Key generation for %s: child terminated for unknown reason" }, - { "kg_exitsig", "Key generation for %s: child was killed by signal %s" }, - { "kg_pollerr", "Key generation for %s: error poll()ing child: %s" }, - { "kg_abort", "Key generation for %s: aborted" }, - { "kg_needacc", "I need an account name. Try something like /otr genkey mynick@irc.server.net" }, - { "kg_noabort", "No ongoing key generation to abort" }, - { "key_not_found", "no private keys found" }, - { "key_loaded", "private keys loaded" }, - { "key_load_error", "Error loading private keys: %s (%s)" }, - { NULL, "Fingerprints" }, - { "fp_saved", "fingerprints saved" }, - { "fp_save_error", "Error saving fingerprints: %s (%s)" }, - { "fp_not_found", "no fingerprints found" }, - { "fp_loaded", "fingerprints loaded" }, - { "fp_load_error", "Error loading fingerprints: %s (%s)" }, - { "fp_trust", "Trusting fingerprint from %s" }, - { NULL, "Instance Tags" }, - { "instag_saved", "instance tags saved" }, - { "instag_save_error", "Error saving instance tags: %s (%s)" }, - { "instag_not_found", "no instance tags found" }, - { "instag_loaded", "instance tags loaded" }, - { "instag_load_error", "Error loading instance tags: %s (%s)" }, - { NULL, "Callbacks" }, - { "ops_notify_bug", "BUG() in ops_notify" }, - { "ops_notify", "title: %s prim: %s sec: %s" }, - { "ops_display_bug", "BUG() in ops_display" }, - { "ops_display", "msg: %s" }, - { "ops_sec", "gone secure" }, - { "ops_fpcomp", "Your peer is not authenticated. To make sure you're talking to the right guy you can either agree on a secret and use the authentication described in /otr auth, or use the traditional way and compare fingerprints over a secure line (e.g. telephone) and subsequently enter /otr trust. Your fingerprint is: %s. %s's fingerprint: %s" }, - { "ops_insec", "gone insecure" }, - { "ops_still_reply", "still secure (is reply)" }, - { "ops_still_no_reply", "still secure (is not reply)" }, - { "ops_log", "log msg: %s" }, - { "ops_inject", "Couldn't inject message from %s for %s: %s" }, - { "ops_handle_msg", "Message event %s, msg %s" }, - { NULL, "SendingReceiving" }, - { "send_failed", "send failed: msg=%s" }, - { "send_change", "couldn't find context also OTR changed the outgoing message(BUG?)" }, - { "send_fragment", "failed to fragment message: msg=%s" }, - { "send_converted", "OTR converted sent message to %s" }, - { "receive_ignore_query", "ignoring rest of OTR default query msg" }, - { "receive_dequeued", "dequeued msg of length %d" }, - { "receive_queued", "queued msg of length %d" }, - { "receive_ignore", "ignoring protocol message of length %d, acc=%s, from=%s: %s" }, - { "receive_converted", "OTR converted received message" }, - { "otr_better_two", "%s has requested an Off-the-Record private conversation. However, you do not have a plugin to support that." }, - { "otr_better_three", "See http://otr.cypherpunks.ca/ for more information." }, - { NULL, "Context" }, - { "ctx_not_found", "couldn't find context: acc=%s nick=%s" }, - { "ctx_not_create", "couldn't create/find context: acc=%s from=%s" }, - { NULL, "Authentication" }, - { "auth_aborted_ongoing", "Ongoing authentication aborted" }, - { "auth_aborted", "Authentication aborted" }, - { "auth_responding", "Responding to authentication request..." }, - { "auth_initiated", "Initiated authentication..." }, - { "auth_have_old", "%s wanted to authenticate but an old authentication was still ongoing. Old authentication will be aborted, please try again." }, - { "auth_peer", "%s wants to authenticate. Type /otr auth to complete." }, - { "auth_peer_qa", "%s wants to authenticate and asked you \"%s\". Type /otr auth to complete." }, - { "auth_peer_reply_wrong", "%s replied to an auth we didn't start." }, - { "auth_peer_replied", "%s replied to our auth request..." }, - { "auth_peer_wrong_smp3", "%s sent a wrong authentication message (SMP3)." }, - { "auth_peer_wrong_smp4", "%s sent a wrong authentication message (SMP4)." }, - { "auth_successful", "Authentication successful!" }, - { "auth_failed", "Authentication failed!" }, - { "auth_needenc", "You need to establish an OTR session before you can authenticate." }, - { NULL, "Commands" }, - { "cmd_otr", "We're alive" }, - { "cmd_qnotfound", "Failed: Can't get nick and server of current query window. (Or maybe you're doing this in the status window?)" }, - { "cmd_auth", "Please agree on a secret with your peer and then initiate the authentication with /otr auth or let him initiate. Should you initiate your peer will after a little while be instructed to enter the secret as well. Once he has done so the authentication will finish up. Should you have both typed in the same secret the authentication should be successful." }, - { "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 irc-otr version %s" }, - { "peer_finished", "%s has finished the OTR conversation. If you want to continue talking enter /otr finish for plaintext or ?OTR? to restart OTR." }, - { NULL, "Contexts" }, - { "ctx_ctx_unencrypted", "%20s %30s plaintext" }, - { "ctx_ctx_encrypted", "%20s %30s encrypted" }, - { "ctx_ctx_finished", "%20s %30s finished" }, - { "ctx_ctx_unknown", "%20s %30s unknown state(BUG?)" }, - { "ctx_fps_no", "%s %rnot authenticated" }, - { "ctx_fps_smp", "%s authenticated via shared secret (SMP)" }, - { "ctx_fps_man", "%s authenticated manually" }, - { "ctx_noctxs", "No active OTR contexts found" }, - { NULL, "Statusbar" }, - { "st_plaintext", "{sb plaintext}" }, - { "st_untrusted", "{sb %rOTR(not auth'ed)}" }, - { "st_trust_smp", "{sb OTR}" }, - { "st_trust_manual", "{sb OTR}" }, - { "st_smp_incoming", "{sb {hilight incoming auth request...}}" }, - { "st_smp_outgoing", "{sb {hilight awaiting auth reply...}}" }, - { "st_smp_finalize", "{sb {hilight finalizing auth...}}" }, - { "st_smp_unknown", "{sb {hilight unknown auth state!}}" }, - { "st_finished", "{sb finished}" }, - { "st_unknown", "{sb {hilight state unknown (BUG!)}}" }, - { NULL, NULL } -}; - -G_STATIC_ASSERT (G_N_ELEMENTS(formats) - 1 == TXT_ST_UNKNOWN + 1); diff --git a/src/hexchat_otr.h b/src/hexchat_otr.h index 0bd21fc..10cc3de 100644 --- a/src/hexchat_otr.h +++ b/src/hexchat_otr.h @@ -16,6 +16,7 @@ #include "config.h" #include +#include #define MODULE_NAME "otr" @@ -59,13 +60,13 @@ enum extern hexchat_plugin *ph; /* plugin handle */ -int hexchat_plugin_deinit (void); -int hexchat_plugin_init (hexchat_plugin *plugin_handle, - char **plugin_name, - char **plugin_desc, - char **plugin_version, - char *arg); -void hexchat_plugin_get_info (char **name, char **desc, char **version, void **reserved); +G_MODULE_EXPORT int hexchat_plugin_deinit (void); +G_MODULE_EXPORT int hexchat_plugin_init (hexchat_plugin *plugin_handle, + char **plugin_name, + char **plugin_desc, + char **plugin_version, + char *arg); +G_MODULE_EXPORT void hexchat_plugin_get_info (char **name, char **desc, char **version, void **reserved); void printformat (IRC_CTX *ircctx, const char *nick, int lvl, int fnum, ...); #define otr_noticest(formatnum, ...) \ diff --git a/src/makeformats.py b/src/makeformats.py index d5adfa9..16b1d7c 100755 --- a/src/makeformats.py +++ b/src/makeformats.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python3 # # Uli Meis # @@ -48,7 +48,7 @@ srcx.write(GPL_LICENSE) hdr.write(GPL_LICENSE) -srcx.write('#include "otr.h"\n'); +srcx.write('#include "otr.h"\n') srcx.write('FORMAT_REC formats[] = {\n\t') srcx.write('{ MODULE_NAME, "otr" }') diff --git a/src/meson.build b/src/meson.build new file mode 100644 index 0000000..bce30a6 --- /dev/null +++ b/src/meson.build @@ -0,0 +1,27 @@ +sources = [ + 'otr_key.c', + 'otr_ops.c', + 'otr_util.c', + 'hexchat_otr.c', +] + +sources += custom_target('formats', + input: 'formats.txt', + output: ['hexchat-formats.c', 'otr-formats.h'], + command: [find_program('makeformats.py'), '@INPUT@', '@OUTDIR@'] +) + +shared_module('otr', sources, + dependencies: [ + glib_dep, + otr_dep, + # gcrypt_dep, + hexchat_dep, + config_dep, + ], + link_args: gcrypt_libs, + c_args: gcrypt_cflags, + name_prefix: '', + install: true, + install_dir: hexchatplugindir, +) diff --git a/src/otr-formats.h b/src/otr-formats.h deleted file mode 100644 index f07d4a4..0000000 --- a/src/otr-formats.h +++ /dev/null @@ -1,127 +0,0 @@ - -/* - * 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 - */ - -enum -{ - TXT_OTR_MODULE_NAME, - TXT_OTR_FILL_0, - TXT_KG_FAILED, - TXT_KG_COMPLETED, - TXT_KG_ABORTED_DUP, - TXT_KG_ABORTED_DIR, - TXT_KG_MKDIR, - TXT_KG_PIPE, - TXT_KG_FORK, - TXT_KG_INITIATED, - TXT_KG_EXITED, - TXT_KG_EXITSIG, - TXT_KG_POLLERR, - TXT_KG_ABORT, - TXT_KG_NEEDACC, - TXT_KG_NOABORT, - TXT_KEY_NOT_FOUND, - TXT_KEY_LOADED, - TXT_KEY_LOAD_ERROR, - TXT_OTR_FILL_1, - TXT_FP_SAVED, - TXT_FP_SAVE_ERROR, - TXT_FP_NOT_FOUND, - TXT_FP_LOADED, - TXT_FP_LOAD_ERROR, - TXT_FP_TRUST, - TXT_OTR_FILL_2, - TXT_INSTAG_SAVED, - TXT_INSTAG_SAVE_ERROR, - TXT_INSTAG_NOT_FOUND, - TXT_INSTAG_LOADED, - TXT_INSTAG_LOAD_ERROR, - TXT_OTR_FILL_3, - TXT_OPS_NOTIFY_BUG, - TXT_OPS_NOTIFY, - TXT_OPS_DISPLAY_BUG, - TXT_OPS_DISPLAY, - TXT_OPS_SEC, - TXT_OPS_FPCOMP, - TXT_OPS_INSEC, - TXT_OPS_STILL_REPLY, - TXT_OPS_STILL_NO_REPLY, - TXT_OPS_LOG, - TXT_OPS_INJECT, - TXT_OPS_HANDLE_MSG, - TXT_OTR_FILL_4, - TXT_SEND_FAILED, - TXT_SEND_CHANGE, - TXT_SEND_FRAGMENT, - TXT_SEND_CONVERTED, - TXT_RECEIVE_IGNORE_QUERY, - TXT_RECEIVE_DEQUEUED, - TXT_RECEIVE_QUEUED, - TXT_RECEIVE_IGNORE, - TXT_RECEIVE_CONVERTED, - TXT_OTR_BETTER_TWO, - TXT_OTR_BETTER_THREE, - TXT_OTR_FILL_5, - TXT_CTX_NOT_FOUND, - TXT_CTX_NOT_CREATE, - TXT_OTR_FILL_6, - TXT_AUTH_ABORTED_ONGOING, - TXT_AUTH_ABORTED, - TXT_AUTH_RESPONDING, - TXT_AUTH_INITIATED, - TXT_AUTH_HAVE_OLD, - TXT_AUTH_PEER, - TXT_AUTH_PEER_QA, - TXT_AUTH_PEER_REPLY_WRONG, - TXT_AUTH_PEER_REPLIED, - TXT_AUTH_PEER_WRONG_SMP3, - TXT_AUTH_PEER_WRONG_SMP4, - TXT_AUTH_SUCCESSFUL, - TXT_AUTH_FAILED, - TXT_AUTH_NEEDENC, - TXT_OTR_FILL_7, - TXT_CMD_OTR, - TXT_CMD_QNOTFOUND, - TXT_CMD_AUTH, - TXT_CMD_DEBUG_ON, - TXT_CMD_DEBUG_OFF, - TXT_CMD_FINISH, - TXT_CMD_FINISHALL_NONE, - TXT_CMD_VERSION, - TXT_PEER_FINISHED, - TXT_OTR_FILL_8, - TXT_CTX_CTX_UNENCRYPTED, - TXT_CTX_CTX_ENCRYPTED, - TXT_CTX_CTX_FINISHED, - TXT_CTX_CTX_UNKNOWN, - TXT_CTX_FPS_NO, - TXT_CTX_FPS_SMP, - TXT_CTX_FPS_MAN, - TXT_CTX_NOCTXS, - TXT_OTR_FILL_9, - TXT_ST_PLAINTEXT, - TXT_ST_UNTRUSTED, - TXT_ST_TRUST_SMP, - TXT_ST_TRUST_MANUAL, - TXT_ST_SMP_INCOMING, - TXT_ST_SMP_OUTGOING, - TXT_ST_SMP_FINALIZE, - TXT_ST_SMP_UNKNOWN, - TXT_ST_FINISHED, - TXT_ST_UNKNOWN -}; - -extern FORMAT_REC formats[]; From 22d54953c5d769b03f9408b76730c0b70a2e8740 Mon Sep 17 00:00:00 2001 From: Patrick Griffis Date: Sun, 23 Sep 2018 16:54:36 -0400 Subject: [PATCH 45/49] Add metainfo file --- data/io.github.Hexchat.Plugin.OTR.metainfo.xml | 11 +++++++++++ data/meson.build | 14 ++++++++++++++ meson.build | 1 + meson_options.txt | 2 +- 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 data/io.github.Hexchat.Plugin.OTR.metainfo.xml create mode 100644 data/meson.build diff --git a/data/io.github.Hexchat.Plugin.OTR.metainfo.xml b/data/io.github.Hexchat.Plugin.OTR.metainfo.xml new file mode 100644 index 0000000..6a39c0a --- /dev/null +++ b/data/io.github.Hexchat.Plugin.OTR.metainfo.xml @@ -0,0 +1,11 @@ + + + io.github.Hexchat.Plugin.OTR + io.github.Hexchat.desktop + OTR Plugin + Adds support for Off-the-Record Messaging + https://github.com/TingPing/hexchat-otr + GPL-2.0+ + CC0-1.0 + tingping_AT_fedoraproject.org + diff --git a/data/meson.build b/data/meson.build new file mode 100644 index 0000000..2cb7249 --- /dev/null +++ b/data/meson.build @@ -0,0 +1,14 @@ +if not get_option('local_install') + hexchatprefix = hexchat_dep.get_pkgconfig_variable('prefix') + + install_data('io.github.Hexchat.Plugin.OTR.metainfo.xml', + install_dir: join_paths(hexchatprefix, get_option('datadir'), 'metainfo') + ) +endif + +appstream_util = find_program('appstream-util', required: false) +if appstream_util.found() + test('Validate appstream file', appstream_util, + args: ['validate', files('io.github.Hexchat.Plugin.OTR.metainfo.xml')] + ) +endif diff --git a/meson.build b/meson.build index 453e13a..6eedb05 100644 --- a/meson.build +++ b/meson.build @@ -74,4 +74,5 @@ else endif message('Install location: ' + hexchatplugindir) +subdir('data') subdir('src') diff --git a/meson_options.txt b/meson_options.txt index d2dc490..d6bcb9e 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,3 +1,3 @@ option('local_install', type: 'boolean', description: 'Install the plugin into your home directory' -) \ No newline at end of file +) From 34590882ca0dc1123a8c3cd57f748b477a0585da Mon Sep 17 00:00:00 2001 From: Andrew Cagney Date: Tue, 12 May 2020 14:10:23 -0400 Subject: [PATCH 46/49] fix and use enum lvls --- src/hexchat_otr.c | 4 ++-- src/hexchat_otr.h | 6 +++--- src/otr.h | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/hexchat_otr.c b/src/hexchat_otr.c index 1266155..9855657 100644 --- a/src/hexchat_otr.c +++ b/src/hexchat_otr.c @@ -337,12 +337,12 @@ int hexchat_plugin_deinit (void) return 1; } -void otr_log(IRC_CTX *server, const char *nick, int level, const char *format, ...) +void otr_log(IRC_CTX *server, const char *nick, enum lvls level, const char *format, ...) { /* TODO: Implement me! */ } -void printformat (IRC_CTX *ircctx, const char *nick, int lvl, int fnum, ...) +void printformat (IRC_CTX *ircctx, const char *nick, enum lvls lvl, int fnum, ...) { va_list params; va_start (params, fnum); diff --git a/src/hexchat_otr.h b/src/hexchat_otr.h index 10cc3de..7d5903f 100644 --- a/src/hexchat_otr.h +++ b/src/hexchat_otr.h @@ -52,11 +52,11 @@ struct _FORMAT_REC typedef struct _FORMAT_REC FORMAT_REC; -enum +enum lvls { MSGLEVEL_CRAP, MSGLEVEL_MSGS -} lvls; +}; extern hexchat_plugin *ph; /* plugin handle */ @@ -67,7 +67,7 @@ G_MODULE_EXPORT int hexchat_plugin_init (hexchat_plugin *plugin_handle, char **plugin_version, char *arg); G_MODULE_EXPORT void hexchat_plugin_get_info (char **name, char **desc, char **version, void **reserved); -void printformat (IRC_CTX *ircctx, const char *nick, int lvl, int fnum, ...); +void printformat (IRC_CTX *ircctx, const char *nick, enum lvls lvl, int fnum, ...); #define otr_noticest(formatnum, ...) \ printformat (NULL, NULL, MSGLEVEL_MSGS, formatnum, ##__VA_ARGS__) diff --git a/src/otr.h b/src/otr.h index 8861009..9131960 100644 --- a/src/otr.h +++ b/src/otr.h @@ -49,7 +49,7 @@ otr_log (NULL, NULL, level, format, ##__VA_ARGS__) void otr_log (IRC_CTX *server, const char *to, - int level, const char *format, ...); + enum lvls level, const char *format, ...); /* own */ From d87484724ae1dfa49cc963351e07ec96d4e705b9 Mon Sep 17 00:00:00 2001 From: Andrew Cagney Date: Tue, 26 May 2020 11:57:03 -0400 Subject: [PATCH 47/49] change <> to <> --- src/hexchat_otr.c | 4 ++-- src/hexchat_otr.h | 6 +++--- src/otr.h | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/hexchat_otr.c b/src/hexchat_otr.c index 9855657..ea871f8 100644 --- a/src/hexchat_otr.c +++ b/src/hexchat_otr.c @@ -337,12 +337,12 @@ int hexchat_plugin_deinit (void) return 1; } -void otr_log(IRC_CTX *server, const char *nick, enum lvls level, const char *format, ...) +void otr_log(IRC_CTX *server, const char *nick, MessageLevel level, const char *format, ...) { /* TODO: Implement me! */ } -void printformat (IRC_CTX *ircctx, const char *nick, enum lvls lvl, int fnum, ...) +void printformat (IRC_CTX *ircctx, const char *nick, MessageLevel lvl, int fnum, ...) { va_list params; va_start (params, fnum); diff --git a/src/hexchat_otr.h b/src/hexchat_otr.h index 7d5903f..004d39d 100644 --- a/src/hexchat_otr.h +++ b/src/hexchat_otr.h @@ -52,11 +52,11 @@ struct _FORMAT_REC typedef struct _FORMAT_REC FORMAT_REC; -enum lvls +typedef enum { MSGLEVEL_CRAP, MSGLEVEL_MSGS -}; +} MessageLevel; extern hexchat_plugin *ph; /* plugin handle */ @@ -67,7 +67,7 @@ G_MODULE_EXPORT int hexchat_plugin_init (hexchat_plugin *plugin_handle, char **plugin_version, char *arg); G_MODULE_EXPORT void hexchat_plugin_get_info (char **name, char **desc, char **version, void **reserved); -void printformat (IRC_CTX *ircctx, const char *nick, enum lvls lvl, int fnum, ...); +void printformat (IRC_CTX *ircctx, const char *nick, MessageLevel lvl, int fnum, ...); #define otr_noticest(formatnum, ...) \ printformat (NULL, NULL, MSGLEVEL_MSGS, formatnum, ##__VA_ARGS__) diff --git a/src/otr.h b/src/otr.h index 9131960..04b7e83 100644 --- a/src/otr.h +++ b/src/otr.h @@ -49,7 +49,7 @@ otr_log (NULL, NULL, level, format, ##__VA_ARGS__) void otr_log (IRC_CTX *server, const char *to, - enum lvls level, const char *format, ...); + MessageLevel level, const char *format, ...); /* own */ From 1b1e0bbf0244704d15e90dc3f24730faf2c45cae Mon Sep 17 00:00:00 2001 From: notmike Date: Tue, 21 Dec 2021 14:20:48 -0700 Subject: [PATCH 48/49] minor edits to Readme.md and application prompts (#34) --- Readme.md | 8 ++++---- src/formats.txt | 28 ++++++++++++++-------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Readme.md b/Readme.md index c6ccbd6..6765c83 100644 --- a/Readme.md +++ b/Readme.md @@ -1,7 +1,7 @@ HexChat OTR =========== -Adds off the record support to HexChat. +Adds off-the-record (OTR) support to HexChat. Originally forked from irssi-otr and still a work in progress. @@ -45,7 +45,7 @@ Usage 2. Authenticate this user: - At this point you need to verify this is the person you think. + At this point you need to verify this is the person you think it is. - If you know their fingerprint and it is correct: @@ -53,10 +53,10 @@ Usage /otr trust ``` - - If you have previously agreed on a password: + - If you have previously agreed on a shared secret: ``` - /otr auth + /otr auth ``` - If you have neither of these: diff --git a/src/formats.txt b/src/formats.txt index 065fce2..5bdcbb0 100644 --- a/src/formats.txt +++ b/src/formats.txt @@ -1,20 +1,20 @@ Keys kg_failed Key generation for %s: failed: %s (%s) -kg_completed Key generation for %s: completed in %d seconds. Reloading keys -kg_aborted_dup Key generation for %s: aborted. Key generation for %s still in progress -kg_aborted_dir Key generation for %s: aborted, failed creating directory %s: %s -kg_mkdir created directory %s +kg_completed Key generation for %s: completed in %d seconds. Reloading keys... +kg_aborted_dup Key generation for %s: aborted. Key generation for %s still in progress. +kg_aborted_dir Key generation for %s: aborted, failed to create directory %s: %s +kg_mkdir Created directory %s kg_pipe Key generation for %s: error creating pipe: %s kg_fork Key generation for %s: fork() error: %s -kg_initiated Key generation for %s: initiated. This might take several minutes or on some systems even an hour. If you want to check that something is happening, see if there are two processes of your IRC client. +kg_initiated Key generation for %s: initiated. This might take several minutes or, on some systems, even an hour. If you want to check that something is happening, see if there are two processes of your IRC client. kg_exited Key generation for %s: child terminated for unknown reason kg_exitsig Key generation for %s: child was killed by signal %s kg_pollerr Key generation for %s: error poll()ing child: %s kg_abort Key generation for %s: aborted kg_needacc I need an account name. Try something like /otr genkey mynick@irc.server.net kg_noabort No ongoing key generation to abort -key_not_found no private keys found -key_loaded private keys loaded +key_not_found No private keys found +key_loaded Private keys loaded key_load_error Error loading private keys: %s (%s) Fingerprints fp_saved fingerprints saved @@ -35,7 +35,7 @@ ops_notify title: %s prim: %s sec: %s ops_display_bug BUG() in ops_display ops_display msg: %s ops_sec gone %%9secure%%9 -ops_fpcomp Your peer is not authenticated. To make sure you're talking to the right guy you can either agree on a secret and use the authentication described in %9/otr auth%9, or use the traditional way and compare fingerprints over a secure line (e.g. telephone) and subsequently enter %9/otr trust%9. Your fingerprint is: %s. %s's fingerprint: %s +ops_fpcomp Your peer is not authenticated. To be sure you're talking to the correct person you may have agreed on a pre-shared secret, and you may use the authentication described in %9/otr auth%9. Otherwise you should compare fingerprints in-person or over a secure line (e.g. encrypted messenger) and, subsequently, enter %9/otr trust%9 when you have confirmed their identity. Your fingerprint is: %s. %s's fingerprint: %s ops_insec gone %9insecure%9 ops_still_reply still %%9secure%9 (is reply) ops_still_no_reply still %%9secure%9 (is not reply) @@ -44,7 +44,7 @@ ops_inject Couldn't inject message from %s for %s: %s ops_handle_msg Message event %s, msg %s SendingReceiving send_failed send failed: msg=%s -send_change couldn't find context also OTR changed the outgoing message(BUG?) +send_change couldn't find context, also OTR changed the outgoing message(BUG?) send_fragment failed to fragment message: msg=%s send_converted OTR converted sent message to %s receive_ignore_query ignoring rest of OTR default query msg @@ -52,17 +52,17 @@ receive_dequeued dequeued msg of length %d receive_queued queued msg of length %d receive_ignore ignoring protocol message of length %d, acc=%s, from=%s: %s receive_converted OTR converted received message -otr_better_two %s has requested an Off-the-Record private conversation. However, you do not have a plugin to support that. +otr_better_two %s has requested an Off-the-Record private conversation. However, you do not have a plugin to support that. otr_better_three See http://otr.cypherpunks.ca/ for more information. Context ctx_not_found couldn't find context: acc=%s nick=%s ctx_not_create couldn't create/find context: acc=%s from=%s Authentication -auth_aborted_ongoing Ongoing authentication aborted -auth_aborted Authentication aborted +auth_aborted_ongoing Ongoing authentication aborted. +auth_aborted Authentication aborted. auth_responding Responding to authentication request... auth_initiated Initiated authentication... -auth_have_old %s wanted to authenticate but an old authentication was still ongoing. Old authentication will be aborted, please try again. +auth_have_old %s wanted to authenticate, but an old authentication was still ongoing. Old authentication will be aborted, please try again. auth_peer %s wants to authenticate. Type /otr auth to complete. auth_peer_qa %s wants to authenticate and asked you \"%s\". Type /otr auth to complete. auth_peer_reply_wrong %s replied to an auth we didn't start. @@ -75,7 +75,7 @@ auth_needenc You need to establish an OTR session before you can authenticate. Commands cmd_otr We're alive cmd_qnotfound Failed: Can't get nick and server of current query window. (Or maybe you're doing this in the status window?) -cmd_auth Please agree on a secret with your peer and then initiate the authentication with /otr auth or let him initiate. Should you initiate your peer will after a little while be instructed to enter the secret as well. Once he has done so the authentication will finish up. Should you have both typed in the same secret the authentication should be successful. +cmd_auth First, agree privately on a pre-shared secret with your peer, and then initiate authentication with /otr auth (or let them initiate). Should you initiate, your peer will be instructed to enter the shared secret as well. Once they have done so the authentication will finish up. If you have both typed in the same secret the authentication should be successful. cmd_debug_on Debug mode is on cmd_debug_off Debug mode is off cmd_finish Finished conversation with %s@%s. From 4ed3a35ed891bf58132c2585a65930bb0af58d63 Mon Sep 17 00:00:00 2001 From: notmike-5 Date: Thu, 23 Dec 2021 01:39:07 -0700 Subject: [PATCH 49/49] max message size and header guards --- src/formats.txt | 20 ++++++++++---------- src/hexchat_otr.h | 4 ++++ src/otr.h | 30 ++++++++++++++---------------- src/otr_key.c | 3 ++- src/otr_ops.c | 16 +++++++--------- src/otr_util.c | 3 ++- 6 files changed, 39 insertions(+), 37 deletions(-) diff --git a/src/formats.txt b/src/formats.txt index 5bdcbb0..fa88528 100644 --- a/src/formats.txt +++ b/src/formats.txt @@ -3,9 +3,9 @@ kg_failed Key generation for %s: failed: %s (%s) kg_completed Key generation for %s: completed in %d seconds. Reloading keys... kg_aborted_dup Key generation for %s: aborted. Key generation for %s still in progress. kg_aborted_dir Key generation for %s: aborted, failed to create directory %s: %s -kg_mkdir Created directory %s -kg_pipe Key generation for %s: error creating pipe: %s -kg_fork Key generation for %s: fork() error: %s +kg_mkdir created directory %s +kg_pipe Key generation for %s: error creating pipe: %s +kg_fork Key generation for %s: fork() error: %s kg_initiated Key generation for %s: initiated. This might take several minutes or, on some systems, even an hour. If you want to check that something is happening, see if there are two processes of your IRC client. kg_exited Key generation for %s: child terminated for unknown reason kg_exitsig Key generation for %s: child was killed by signal %s @@ -34,11 +34,11 @@ ops_notify_bug BUG() in ops_notify ops_notify title: %s prim: %s sec: %s ops_display_bug BUG() in ops_display ops_display msg: %s -ops_sec gone %%9secure%%9 -ops_fpcomp Your peer is not authenticated. To be sure you're talking to the correct person you may have agreed on a pre-shared secret, and you may use the authentication described in %9/otr auth%9. Otherwise you should compare fingerprints in-person or over a secure line (e.g. encrypted messenger) and, subsequently, enter %9/otr trust%9 when you have confirmed their identity. Your fingerprint is: %s. %s's fingerprint: %s -ops_insec gone %9insecure%9 -ops_still_reply still %%9secure%9 (is reply) -ops_still_no_reply still %%9secure%9 (is not reply) +ops_sec Channel has gone %%9secure%%9. +ops_fpcomp Your peer is not authenticated. To be sure you're talking to the correct person you may have privately agreed on a shared secret. If so, you may use the authentication described in %9/otr auth%9. Otherwise you should compare fingerprints in-person or over a secure line (e.g. encrypted messenger) and, subsequently, enter %9/otr trust%9 when you have confirmed your peer's identity. Your fingerprint is: %s. %s's fingerprint: %s +ops_insec Channel has gone %9insecure%9 +ops_still_reply still %%9secure%9 (Peer replied) +ops_still_no_reply still %%9secure%9 (Peer did not reply) ops_log log msg: %s ops_inject Couldn't inject message from %s for %s: %s ops_handle_msg Message event %s, msg %s @@ -73,9 +73,9 @@ auth_successful Authentication successful! auth_failed Authentication failed! auth_needenc You need to establish an OTR session before you can authenticate. Commands -cmd_otr We're alive +cmd_otr We're alive cmd_qnotfound Failed: Can't get nick and server of current query window. (Or maybe you're doing this in the status window?) -cmd_auth First, agree privately on a pre-shared secret with your peer, and then initiate authentication with /otr auth (or let them initiate). Should you initiate, your peer will be instructed to enter the shared secret as well. Once they have done so the authentication will finish up. If you have both typed in the same secret the authentication should be successful. +cmd_auth First, agree privately on a shared secret with your peer, and then initiate authentication with /otr auth (or let them initiate). Should you initiate, your peer will be instructed to enter the shared secret as well. Once they have done so the authentication will finish up. If you have both typed in the same secret the authentication should be successful. cmd_debug_on Debug mode is on cmd_debug_off Debug mode is off cmd_finish Finished conversation with %s@%s. diff --git a/src/hexchat_otr.h b/src/hexchat_otr.h index 004d39d..84c98ca 100644 --- a/src/hexchat_otr.h +++ b/src/hexchat_otr.h @@ -1,3 +1,5 @@ +#ifndef HEX_OTR_H +#define HEX_OTR_H /* * 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 @@ -90,3 +92,5 @@ void printformat (IRC_CTX *ircctx, const char *nick, MessageLevel lvl, int fnum, #define IRCCTX_ADDR(ircctx) ircctx->address #define IRCCTX_NICK(ircctx) ircctx->nick #define IRCCTX_FREE(ircctx) g_free (ircctx) + +#endif //EOF diff --git a/src/otr.h b/src/otr.h index 04b7e83..797027c 100644 --- a/src/otr.h +++ b/src/otr.h @@ -1,5 +1,8 @@ -/* - * Off-the-Record Messaging (OTR) module for the irssi IRC client +#ifndef OTR_H +#define OTR_H +/* + * Off-the-Record Messaging (OTR) module for IRC clients + * *************************************************** * Copyright (C) 2008 Uli Meis * * This program is free software; you can redistribute it and/or modify @@ -54,14 +57,12 @@ void otr_log (IRC_CTX *server, const char *to, /* own */ #include "config.h" - #include "otr-formats.h" -/* - * maybe this should be configurable? - * I believe bitlbee has something >500. - */ -#define OTR_MAX_MSG_SIZE 400 +/* Most IRC servers limit messages to 512 bytes in length, + * including trailing whitespace and the CR-LF terminating characters + * i.e len( bytes(msg) | <0x20> x ... | <0x0D0A> ) <= 512 bytes */ +#define OTR_MAX_MSG_SIZE 510 //RFC 2812 /* otr protocol id */ #define PROTOCOLID "IRC" @@ -151,12 +152,12 @@ struct co_info { char *msgqueue; /* holds partially reconstructed base64 messages */ - IRC_CTX *ircctx; /* irssi server object for this peer */ + IRC_CTX *ircctx; /* IRC server object for this peer */ int received_smp_init; /* received SMP init msg */ int smp_failed; /* last SMP failed */ char better_msg_two[256]; /* what the second line of the "better" - default query msg should like. Eat it - up when it comes in */ + default query msg should like. Eat + it up when it comes in */ int finished; /* true after you've /otr finished */ }; @@ -190,7 +191,6 @@ struct ctxlist_ }; /* policy list generated from /set otr_policy */ - struct plistentry { GPatternSpec *namepat; @@ -205,21 +205,18 @@ IRC_CTX *server_find_address (char *address); void otr_status_change (IRC_CTX *ircctx, const char *nick, int event); /* init stuff */ - int otrlib_init (void); void otrlib_deinit (void); void otr_initops (void); void otr_setpolicies (const char *policies, int known); /* 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(IRC_CTX *ircctx, const char *nick); ConnContext *otr_getcontext (const char *accname, const char *nick, int create, void *data); /* user interaction */ - 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 *question, const char *secret); @@ -229,7 +226,6 @@ struct ctxlist_ *otr_contexts (void); void otr_finishall (void); /* key/fingerprint stuff */ - void keygen_run (const char *accname); void keygen_abort (int ignoreidle); void key_load (void); @@ -239,3 +235,5 @@ void otr_writefps (void); /* instance tags */ void instag_load (void); void otr_writeinstags (void); + +#endif //EOF diff --git a/src/otr_key.c b/src/otr_key.c index 01f24b8..e89d621 100644 --- a/src/otr_key.c +++ b/src/otr_key.c @@ -1,5 +1,6 @@ /* - * Off-the-Record Messaging (OTR) module for the irssi IRC client + * Off-the-Record Messaging (OTR) module for IRC clients + * *************************************************** * Copyright (C) 2008 Uli Meis * * This program is free software; you can redistribute it and/or modify diff --git a/src/otr_ops.c b/src/otr_ops.c index 64c582a..0bd36ab 100644 --- a/src/otr_ops.c +++ b/src/otr_ops.c @@ -1,5 +1,6 @@ /* - * Off-the-Record Messaging (OTR) module for the irssi IRC client + * Off-the-Record Messaging (OTR) module for IRC clients + * *************************************************** * Copyright (C) 2008 Uli Meis * * This program is free software; you can redistribute it and/or modify @@ -143,15 +144,12 @@ static void ops_secure (void *opdata, ConnContext *context) * Let's print out the fingerprints for comparison */ otrl_privkey_hash_to_human (peerfp, - context->active_fingerprint->fingerprint); + context->active_fingerprint->fingerprint); otr_notice (coi->ircctx, context->username, TXT_OPS_FPCOMP, - otrl_privkey_fingerprint (otr_state, - ownfp, - context->accountname, - PROTOCOLID), - context->username, - peerfp); + otrl_privkey_fingerprint (otr_state, ownfp, + context->accountname, PROTOCOLID), + context->username, peerfp); } /* @@ -174,7 +172,7 @@ static void ops_still_secure (void *opdata, ConnContext *context, int is_reply) context->username, is_reply ? TXT_OPS_STILL_REPLY : TXT_OPS_STILL_NO_REPLY); } -/* +/* * Really critical with IRC. * Unfortunately, we can't tell our peer which size to use. * (reminds me of MTU determination...) diff --git a/src/otr_util.c b/src/otr_util.c index 206fa0c..b4b1389 100644 --- a/src/otr_util.c +++ b/src/otr_util.c @@ -1,5 +1,6 @@ /* - * Off-the-Record Messaging (OTR) module for the irssi IRC client + * Off-the-Record Messaging (OTR) module for IRC clients + * *************************************************** * Copyright (C) 2008 Uli Meis * * This program is free software; you can redistribute it and/or modify