irssi-plugin-robustirc-0.6/000077500000000000000000000000001300765507200160235ustar00rootroot00000000000000irssi-plugin-robustirc-0.6/.clang-format000066400000000000000000000004661300765507200204040ustar00rootroot00000000000000BasedOnStyle: google AllowShortIfStatementsOnASingleLine: false AllowShortLoopsOnASingleLine: false AllowShortFunctionsOnASingleLine: None AllowShortBlocksOnASingleLine: false AlwaysBreakBeforeMultilineStrings: false IndentWidth: 4 PointerBindsToType: false ColumnLimit: 0 SpaceBeforeParens: ControlStatements irssi-plugin-robustirc-0.6/.gitignore000066400000000000000000000024121300765507200200120ustar00rootroot00000000000000## https://raw.githubusercontent.com/github/gitignore/master/Global/Vim.gitignore [._]*.s[a-w][a-z] [._]s[a-w][a-z] *.un~ Session.vim .netrwhist *~ ## https://raw.githubusercontent.com/github/gitignore/master/Global/Emacs.gitignore # -*- mode: gitignore; -*- *~ \#*\# /.emacs.desktop /.emacs.desktop.lock *.elc auto-save-list tramp .\#* # Org-mode .org-id-locations *_archive # flymake-mode *_flymake.* # eshell files /eshell/history /eshell/lastdir # elpa packages /elpa/ # reftex files *.rel # AUCTeX auto folder /auto/ # cask packages .cask/ ## https://raw.githubusercontent.com/github/gitignore/master/Global/Tags.gitignore # Ignore tags created by etags, ctags, gtags (GNU global) and cscope TAGS !TAGS/ tags !tags/ gtags.files GTAGS GRTAGS GPATH cscope.files cscope.out cscope.in.out cscope.po.out ## https://raw.githubusercontent.com/github/gitignore/master/C.gitignore # Object files *.o *.ko *.obj *.elf # Precompiled Headers *.gch *.pch # Libraries *.lib *.a *.la *.lo # Shared objects (inc. Windows DLLs) *.dll *.so *.so.* *.dylib # Executables *.exe *.out *.app *.i*86 *.x86_64 *.hex # Debug files *.dSYM/ ## https://raw.githubusercontent.com/github/gitignore/master/CMake.gitignore CMakeCache.txt CMakeFiles Makefile cmake_install.cmake install_manifest.txt irssi-plugin-robustirc-0.6/CMakeLists.txt000066400000000000000000000034341300765507200205670ustar00rootroot00000000000000# vim:ts=4:sw=4:et cmake_minimum_required(VERSION 2.6) # TODO: get rid of this once we bump the cmake version to ≥ 2.8.2 string(REGEX MATCH "clang" CMAKE_COMPILER_IS_CLANG "${CMAKE_C_COMPILER}") if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra") set(CMAKE_C_FLAGS_ASAN "-fsanitize=address -fno-omit-frame-pointer -g3 -O1") set(CMAKE_C_FLAGS_RELEASE "-O2") set(CMAKE_C_FLAGS_DEBUG "-g3 -O0") endif() set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "Choose the type of build: None Debug Release ASan" FORCE) # Required by irssi/src/common.h. add_definitions("-DUOFF_T_LONG") find_package(PkgConfig REQUIRED) pkg_check_modules(DEPS REQUIRED glib-2.0 yajl gio-2.0 libcurl) include_directories(${DEPS_INCLUDE_DIRS}) link_directories(${DEPS_LIBRARY_DIRS}) add_definitions(${DEPS_CFLAGS_OTHER}) set(IRSSI_PATH "/usr/include/irssi" CACHE PATH "path to irssi include files") find_path(irssi_INCLUDE_DIR NAMES irssi-config.h src/common.h PATHS ${IRSSI_PATH} /usr/local/include/irssi ) if(NOT irssi_INCLUDE_DIR) message(SEND_ERROR "Could not auto find the irssi include files, please run:\n# cmake -DIRSSI_PATH:PATH=/path/to/irssi/includes .") return() endif() include_directories(src/core) include_directories(src/core/robustsession) include_directories(src/fe-common) include_directories( ${irssi_INCLUDE_DIR} ${irssi_INCLUDE_DIR}/src ${irssi_INCLUDE_DIR}/src/fe-common/core ${irssi_INCLUDE_DIR}/src/core ${irssi_INCLUDE_DIR}/src/irc/core ) add_definitions("-std=gnu99") # TODO: switch to this method for specifying -std once cmake 3.1+ is sufficiently wide-spread # set(CMAKE_C_STANDARD 99) # set(CMAKE_C_STANDARD_REQUIRED ON) add_subdirectory(src/core) add_subdirectory(src/fe-common) irssi-plugin-robustirc-0.6/COPYING000066400000000000000000000450251300765507200170640ustar00rootroot00000000000000Specific permission is granted for the GPLed code in this distribution to be linked to OpenSSL without invoking GPL clause 2(b). Copyright (C) 2015 Michael Stapelberg 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. ------------------------------------------------------------------------------ GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 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. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. irssi-plugin-robustirc-0.6/README.md000066400000000000000000000042551300765507200173100ustar00rootroot00000000000000This is an irssi plugin which allows you to connect to a [RobustIRC](http://robustirc.net/) network without using [a bridge](https://github.com/robustirc/bridge). The plugin is very new, hence there will likely be bugs. Please report them so that we get a chance to fix them. ## Installing On Debian testing, use: ``` sudo apt-get install irssi-plugin-robustirc ``` ## Building from source To build: ```bash git clone https://github.com/robustirc/irssi-robustirc.git mkdir irssi-robustirc/build cd irssi-robustirc/build cmake .. && make sudo make install ``` If you need to specify a custom path to the irssi sources, specify `IRSSI_PATH`: ```bash cmake -DIRSSI_PATH:PATH=$HOME/irssi .. ``` To build with https://code.google.com/p/address-sanitizer/wiki/AddressSanitizer enabled: ```bash cmake -DCMAKE_BUILD_TYPE:String="asan" .. ``` to use asan, run `irssi 2>/tmp/asan.log`. When memory errors are found, irssi will terminate and you can examine /tmp/asan.log ## Using If you just want to load the module and connect as quickly as possible, here is how you do it: ``` /load robustirc /connect -robustirc robustirc.net ``` ### Persistent setup To load the RobustIRC plugin automatically when starting irssi, use: ```bash echo 'LOAD robustirc' >> ~/.irssi/startup ``` #### Converting an existing network In case you were previously connecting to legacy-irc.robustirc.net, or to a bridge, open up `~/.irssi/config` in an editor, find the corresponding network entry in the `chatnets` section and add: ``` type = "robustirc"; ``` Then, find the corresponding server entry in the `servers` section and replace the `address` line with the address of the RobustIRC network, e.g.: ``` address = "robustirc.net"; ``` #### Configuring a new network Edit `~/.irssi/config` and add a new network to the `chatnets` section: ``` = { type = "robustirc"; }; ``` Then, add a server to the `servers` section: ``` { address = "robustirc.net"; chatnet = ""; autoconnect = "yes"; } ``` Here’s a full example: ``` chatnets = { robustirc = { type = "robustirc"; }; }; servers = ( { address = "robustirc.net"; chatnet = "robustirc"; autoconnect = "yes"; } ); ``` irssi-plugin-robustirc-0.6/src/000077500000000000000000000000001300765507200166125ustar00rootroot00000000000000irssi-plugin-robustirc-0.6/src/core/000077500000000000000000000000001300765507200175425ustar00rootroot00000000000000irssi-plugin-robustirc-0.6/src/core/CMakeLists.txt000066400000000000000000000006701300765507200223050ustar00rootroot00000000000000set(SOURCE ${SOURCE} ${CMAKE_CURRENT_SOURCE_DIR}/robustirc.c ${CMAKE_CURRENT_SOURCE_DIR}/robustio.c) set(HEADERS ${HEADERS} ${CMAKE_CURRENT_SOURCE_DIR}/robustirc.h ${CMAKE_CURRENT_SOURCE_DIR}/robustio.h) add_subdirectory("robustsession") add_library(robustirc_core MODULE ${SOURCE} ${HEADERS}) target_link_libraries(robustirc_core ${DEPS_LIBRARIES} m) install(TARGETS robustirc_core LIBRARY DESTINATION lib/irssi/modules) irssi-plugin-robustirc-0.6/src/core/robustio.c000066400000000000000000000113331300765507200215550ustar00rootroot00000000000000// vim:ts=4:sw=4:et // © 2015 Michael Stapelberg (see COPYING) #include #include "common.h" #include "printtext.h" #include "levels.h" #include "robustio.h" #include "robustsession.h" static GIOStatus robust_io_read(GIOChannel *channel, gchar *buf, gsize count, gsize *bytes_read, GError **err); static GIOStatus robust_io_write(GIOChannel *channel, const gchar *buf, gsize count, gsize *bytes_written, GError **err); static GIOStatus robust_io_close(GIOChannel *channel, GError **err); static void robust_io_free(GIOChannel *channel); static GSource *robust_io_create_watch(GIOChannel *channel, GIOCondition condition); static GIOStatus robust_io_set_flags(GIOChannel *channel, GIOFlags flags, GError **err); static GIOFlags robust_io_get_flags(GIOChannel *channel); static GIOFuncs robust_channel_funcs = { .io_read = robust_io_read, .io_write = robust_io_write, .io_seek = NULL, .io_close = robust_io_close, .io_create_watch = robust_io_create_watch, .io_free = robust_io_free, .io_set_flags = robust_io_set_flags, .io_get_flags = robust_io_get_flags, }; gboolean robust_io_is_robustio_channel(GIOChannel *channel) { return (channel->funcs == &robust_channel_funcs); } GIOChannel *robust_io_channel_new(SERVER_REC *server) { RobustIOChannel *channel; GIOChannel *iochannel; printtext(NULL, NULL, MSGLEVEL_CRAP, "robust_io_channel_new"); channel = g_new0(RobustIOChannel, 1); iochannel = (GIOChannel *)channel; channel->server = server; iochannel->is_readable = FALSE; iochannel->is_seekable = FALSE; iochannel->is_writeable = TRUE; g_io_channel_init(iochannel); iochannel->use_buffer = FALSE; iochannel->close_on_unref = TRUE; iochannel->funcs = &robust_channel_funcs; return iochannel; } static GIOStatus robust_io_read(GIOChannel *channel, gchar *buf, gsize count, gsize *bytes_read, GError **err) { (void)channel; (void)buf; (void)count; (void)err; // This function should never be called because we never signal readiness // for reading, so return EOF if it does get called nevertheless. *bytes_read = 0; return G_IO_STATUS_EOF; } static GIOStatus robust_io_write(GIOChannel *channel, const gchar *buf, gsize count, gsize *bytes_written, GError **err) { (void)err; RobustIOChannel *robust_channel = (RobustIOChannel *)channel; robustsession_send(robust_channel->robustsession, robust_channel->server, buf, count); *bytes_written = count; return G_IO_STATUS_NORMAL; } static GIOStatus robust_io_close(GIOChannel *channel, GError **err) { (void)err; RobustIOChannel *robust_channel = (RobustIOChannel *)channel; robustsession_destroy(robust_channel->robustsession); return G_IO_STATUS_NORMAL; } static void robust_io_free(GIOChannel *channel) { g_free(channel); } static gboolean never_prepare(GSource *source, gint *timeout_); static gboolean never_check(GSource *source); static gboolean never_dispatch(GSource *source, GSourceFunc callback, gpointer user_data); static GSourceFuncs never_source_funcs = { .prepare = never_prepare, .check = never_check, .dispatch = never_dispatch, }; static gboolean never_prepare(GSource *source, gint *timeout_) { (void)source; *timeout_ = -1; return FALSE; } static gboolean never_check(GSource *source) { (void)source; return FALSE; } static gboolean never_dispatch(GSource *source, GSourceFunc callback, gpointer user_data) { (void)source; (void)callback; (void)user_data; return TRUE; } static GSource *robust_io_create_watch(GIOChannel *channel, GIOCondition condition) { (void)channel; (void)condition; return g_source_new(&never_source_funcs, sizeof(GSource)); } static GIOStatus robust_io_set_flags(GIOChannel *channel, GIOFlags flags, GError **err) { (void)channel; (void)flags; (void)err; return G_IO_STATUS_NORMAL; } static GIOFlags robust_io_get_flags(GIOChannel *channel) { (void)channel; return 0; } irssi-plugin-robustirc-0.6/src/core/robustio.h000066400000000000000000000004611300765507200215620ustar00rootroot00000000000000#pragma once typedef struct _RobustIOChannel RobustIOChannel; struct _RobustIOChannel { GIOChannel channel; SERVER_REC *server; struct t_robustsession_ctx *robustsession; }; GIOChannel *robust_io_channel_new(SERVER_REC *server); gboolean robust_io_is_robustio_channel(GIOChannel *channel); irssi-plugin-robustirc-0.6/src/core/robustirc.c000066400000000000000000000135521300765507200217300ustar00rootroot00000000000000// vim:ts=4:sw=4:et // © 2015 Michael Stapelberg (see COPYING) #include #include "common.h" #include "modules.h" #include "signals.h" #include "channels.h" #include "channels-setup.h" #include "chat-protocols.h" #include "chatnets.h" #include "servers-setup.h" #include "settings.h" #include "queries.h" #include "commands.h" #include "rawlog.h" #include "irc.h" #include "irc-servers.h" #include "irc-queries.h" #include "net-sendbuffer.h" #include "printtext.h" #include "levels.h" #include "robustirc.h" #include "robustio.h" #include "robustsession.h" static GHashTable *connrecs = NULL; static CHATNET_REC *create_chatnet(void) { return g_malloc0(sizeof(CHATNET_REC)); } static SERVER_SETUP_REC *create_server_setup(void) { return g_malloc0(sizeof(SERVER_SETUP_REC)); } static CHANNEL_SETUP_REC *create_channel_setup(void) { return g_malloc0(sizeof(CHANNEL_SETUP_REC)); } static SERVER_CONNECT_REC *create_server_connect(void) { return g_malloc0(sizeof(IRC_SERVER_CONNECT_REC)); } static void destroy_server_connect(IRC_SERVER_CONNECT_REC *conn) { (void)conn; } SERVER_REC *robustirc_server_init_connect(SERVER_CONNECT_REC *connrec) { SERVER_REC *server; printtext(NULL, NULL, MSGLEVEL_CRAP, "robustirc_server_init_connect"); connrec->chat_type = IRC_PROTOCOL; server = irc_server_init_connect(connrec); GIOChannel *handle = robust_io_channel_new(server); RobustIOChannel *io = (RobustIOChannel *)handle; io->robustsession = robustsession_connect(server); server->handle = net_sendbuffer_create(handle, 0); // TODO: how many of these are necessary? server->connrec->no_connect = TRUE; server->connect_pid = -1; server->connect_tag = 1; g_hash_table_insert(connrecs, connrec, server); return server; } static void robustirc_server_connect_copy(SERVER_CONNECT_REC **dest, IRC_SERVER_CONNECT_REC *src) { g_return_if_fail(dest != NULL); if (!IS_IRC_SERVER_CONNECT(src)) return; // *dest == NULL likely means the sig_server_connect_copy() in // irssi/src/irc/core/irc-servers-reconnect.c did not run. // Perhaps the irssi code structure has changed? assert(*dest != NULL); SERVER_REC *server = g_hash_table_lookup(connrecs, src); g_return_if_fail(server != NULL); // We need to trigger the server reconnect save status signal here because // chat_type needs to be IRC_PROTOCOL at the time when that signal is // processed so that channels are saved for rejoining after reconnecting. (*dest)->type = module_get_uniq_id("SERVER CONNECT", 0); // Passing |src| is intentional: properties get copied over from |src| to // |*dest| in server_connect_copy_skeleton() once this signal handler // returns. signal_emit("server reconnect save status", 2, src, server); // So that robustirc_server_init_connect is called on reconnects. (*dest)->chat_type = ROBUSTIRC_PROTOCOL; g_hash_table_remove(connrecs, src); } static void robustirc_server_disconnected(SERVER_REC *server) { g_return_if_fail(server != NULL); g_return_if_fail(server->handle != NULL); g_return_if_fail(server->handle->handle != NULL); if (!robust_io_is_robustio_channel(server->handle->handle)) { printtext(NULL, NULL, MSGLEVEL_CRAP, "disconnect from server, but not a robustio channel"); return; } printtext(NULL, NULL, MSGLEVEL_CRAP, "disconnect from server, marking robustsession write-only"); RobustIOChannel *io = (RobustIOChannel *)server->handle->handle; robustsession_write_only(io->robustsession); } void robustirc_server_connect(IRC_SERVER_REC *server) { if (!IS_IRC_SERVER(server)) { return; } gchar *m = g_strdup_printf("server = %p, server->connrec = %p", server, server->connrec); printtext(NULL, NULL, MSGLEVEL_CRAP, "connect. server = %s", m); g_free(m); //err: // server->connection_lost = TRUE; // if (error != NULL) { // server_connect_failed(SERVER(server), error->message); // g_error_free(error); // } else // server_connect_failed(SERVER(server), err_msg); } QUERY_REC *query_create(const char *server_tag, const char *nick, int automatic) { QUERY_REC *rec; g_return_val_if_fail(nick != NULL, NULL); rec = g_new0(QUERY_REC, 1); rec->chat_type = IRC_PROTOCOL; rec->name = g_strdup(nick); rec->server_tag = g_strdup(server_tag); query_init(rec, automatic); return rec; } #ifdef IRSSI_ABI_VERSION void robustirc_core_abicheck(int *version) { *version = IRSSI_ABI_VERSION; } #endif void robustirc_core_init(void) { CHAT_PROTOCOL_REC *rec; rec = g_new0(CHAT_PROTOCOL_REC, 1); rec->name = ROBUSTIRC_PROTOCOL_NAME; rec->fullname = "RobustIRC"; rec->chatnet = "robustirc"; rec->create_chatnet = create_chatnet; rec->create_server_setup = create_server_setup; rec->create_server_connect = create_server_connect; rec->create_channel_setup = create_channel_setup; rec->destroy_server_connect = (void (*)(SERVER_CONNECT_REC *))destroy_server_connect; rec->server_init_connect = robustirc_server_init_connect; rec->server_connect = (void (*)(SERVER_REC *))robustirc_server_connect; rec->channel_create = (CHANNEL_REC * (*)(SERVER_REC *, const char *, const char *, int)) irc_channel_create; rec->query_create = irc_query_create; chat_protocol_register(rec); g_free(rec); command_set_options("connect", "robustirc"); signal_add_last("server connect copy", (SIGNAL_FUNC)robustirc_server_connect_copy); signal_add_last("server disconnected", (SIGNAL_FUNC)robustirc_server_disconnected); connrecs = g_hash_table_new(NULL, NULL); robustsession_init(); module_register(MODULE_NAME, "core"); } void robustirc_core_deinit(void) { robustsession_deinit(); g_hash_table_destroy(connrecs); } irssi-plugin-robustirc-0.6/src/core/robustirc.h000066400000000000000000000004051300765507200217260ustar00rootroot00000000000000#pragma once #define MODULE_NAME "robustirc" #define ROBUSTIRC_PROTOCOL_NAME "robustirc" #define ROBUSTIRC_PROTOCOL (chat_protocol_lookup(ROBUSTIRC_PROTOCOL_NAME)) // TODO: define this from git. #define ROBUSTSESSION_USER_AGENT "irssi-plugin-robustirc v0.6" irssi-plugin-robustirc-0.6/src/core/robustsession/000077500000000000000000000000001300765507200224645ustar00rootroot00000000000000irssi-plugin-robustirc-0.6/src/core/robustsession/CMakeLists.txt000066400000000000000000000004421300765507200252240ustar00rootroot00000000000000set(SOURCE ${SOURCE} ${CMAKE_CURRENT_SOURCE_DIR}/robustsession.c ${CMAKE_CURRENT_SOURCE_DIR}/robustsession-network.c PARENT_SCOPE ) set(HEADERS ${HEADERS} ${CMAKE_CURRENT_SOURCE_DIR}/robustsession.h ${CMAKE_CURRENT_SOURCE_DIR}/robustsession-network.h PARENT_SCOPE ) irssi-plugin-robustirc-0.6/src/core/robustsession/robustsession-network.c000066400000000000000000000246721300765507200272540ustar00rootroot00000000000000// vim:ts=4:sw=4:et // © 2015 Michael Stapelberg (see COPYING) // stdlib includes #include #include #include // external library includes #include #include #include // irssi includes #include "common.h" #include "irc.h" #include "irc-servers.h" #include "levels.h" #include "printtext.h" // module includes #include "robustsession-network.h" // Hash table, keyed by lowercase network address (e.g. “robustirc.net”), // holding the resolved host:port targets and their current backoff state. static GHashTable *networks = NULL; struct backoff_state { int exponent; time_t next; }; struct network_ctx { GList *servers; GHashTable *backoff; }; struct query { SERVER_REC *server; robustsession_network_resolved_cb callback; gpointer userdata; GCancellable *cancellable; gulong cancellable_handler; }; static void resolve_cancelled(GCancellable *cancellable, gpointer user_data) { printtext(NULL, NULL, MSGLEVEL_CRAP, "resolve_cancelled()"); g_free(user_data); } static void srv_resolved(GObject *obj, GAsyncResult *res, gpointer user_data) { struct query *query = user_data; GError *err = NULL; GResolver *resolver = (GResolver *)obj; GList *targets = g_resolver_lookup_service_finish(resolver, res, &err); if (g_cancellable_is_cancelled(query->cancellable)) { return; } if (err != NULL) { // TODO: is this how irssi’s retry works? robustsession_connect(query->server); return; } // Note that we do not shuffle the list of targets here, but call // robustsession_network_server() with random == TRUE for CreateSession // requests, achieving the same effect. GList *servers = NULL; for (GList *r = targets; r != NULL; r = r->next) { GSrvTarget *target = r->data; gchar *server = g_strdup_printf( "%s:%d", g_srv_target_get_hostname(target), g_srv_target_get_port(target)); if (server) { servers = g_list_append(servers, server); } } struct network_ctx *ctx = g_new0(struct network_ctx, 1); ctx->servers = servers; ctx->backoff = g_hash_table_new(g_str_hash, g_str_equal); gchar *key = g_ascii_strdown(query->server->connrec->address, -1); g_hash_table_insert(networks, key, ctx); g_resolver_free_targets(targets); // TODO: here and below, signal resolving errors (g_list_length(servers) == 0) query->callback(query->server, query->userdata); g_cancellable_disconnect(query->cancellable, query->cancellable_handler); g_free(query); } bool robustsession_network_init(void) { srand(time(NULL)); networks = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); return (networks != NULL); } void robustsession_network_resolve( SERVER_REC *server, GCancellable *cancellable, robustsession_network_resolved_cb callback, gpointer userdata) { // Skip resolving if we already resolved this network address. if (g_hash_table_lookup(networks, server->connrec->address)) { callback(server, userdata); return; } // For testing, a comma-separated list of targets skips resolving. gchar **targets = g_strsplit(server->connrec->address, ",", -1); guint len = g_strv_length(targets); if (len > 1) { struct network_ctx *ctx = g_new0(struct network_ctx, 1); ctx->backoff = g_hash_table_new(g_str_hash, g_str_equal); for (guint i = 0; i < len; i++) { gchar *server = g_strdup(targets[i]); if (server) { g_strstrip(server); if (strcmp(server, "") != 0) { ctx->servers = g_list_append(ctx->servers, server); } else { g_free(server); } } } gchar *key = g_ascii_strdown(server->connrec->address, -1); g_hash_table_insert(networks, key, ctx); g_strfreev(targets); callback(server, userdata); return; } g_strfreev(targets); struct query *query = g_new0(struct query, 1); query->server = server; query->callback = callback; query->userdata = userdata; gulong cancellable_handler = g_cancellable_connect(cancellable, G_CALLBACK(resolve_cancelled), query, NULL); if (cancellable_handler == 0) { // g_cancellable_connect called g_free(query). return; } query->cancellable = cancellable; query->cancellable_handler = cancellable_handler; GResolver *resolver = g_resolver_get_default(); g_resolver_lookup_service_async( resolver, "robustirc", "tcp", server->connrec->address, cancellable, srv_resolved, query); g_object_unref(resolver); } struct server_retry_ctx { char *address; gboolean random; robustsession_network_server_cb callback; gpointer userdata; guint timeout_id; GCancellable *cancellable; gulong cancellable_handler; }; static void retry_cancelled(GCancellable *cancellable, gpointer user_data) { struct server_retry_ctx *ctx = user_data; g_source_remove(ctx->timeout_id); g_free(ctx->address); g_free(ctx); } static gboolean robustsession_network_server_retry_cb(gpointer user_data) { struct server_retry_ctx *ctx = user_data; robustsession_network_server( ctx->address, ctx->random, ctx->cancellable, ctx->callback, ctx->userdata); g_cancellable_disconnect(ctx->cancellable, ctx->cancellable_handler); free(ctx->address); free(ctx); return FALSE; } // Returns TRUE and calls |callback| as soon as a connection to a server for // network |address| is possible. Connections might be blocked due to // exponential backoff. // // Returns FALSE when |address| was not yet resolved using // robustsession_network_resolve(). gboolean robustsession_network_server( const char *address, gboolean random, GCancellable *cancellable, robustsession_network_server_cb callback, gpointer userdata) { gchar *key = g_ascii_strdown(address, -1); struct network_ctx *ctx = g_hash_table_lookup(networks, key); g_free(key); if (!ctx) { return FALSE; } #if 0 GHashTableIter iter; gpointer k, v; g_hash_table_iter_init(&iter, ctx->backoff); printtext(NULL, NULL, MSGLEVEL_CRAP, "dumping ht"); while (g_hash_table_iter_next(&iter, &k, &v)) { printtext(NULL, NULL, MSGLEVEL_CRAP, "entry for key=%s", k); } printtext(NULL, NULL, MSGLEVEL_CRAP, "end dumping ht"); #endif // Try to use a random server, but fall back to using the next // available server in case the randomly picked server is unhealthy. if (random) { gchar *server = g_list_nth_data( ctx->servers, rand() % g_list_length(ctx->servers)); struct backoff_state *backoff = g_hash_table_lookup(ctx->backoff, server); #if 0 printtext(NULL, NULL, MSGLEVEL_CRAP, "backoff = %s for *%s*", (backoff ? "yes" : "no"), server); if (backoff) printtext(NULL, NULL, MSGLEVEL_CRAP, "current backoff = %d, next = %d for *%s*, time = %d", backoff->exponent, backoff->next, server, time(NULL)); #endif if (!backoff || backoff->next <= time(NULL)) { callback(server, userdata); return TRUE; } } time_t soonest = LONG_MAX; for (GList *s = ctx->servers; s != NULL; s = s->next) { struct backoff_state *backoff = g_hash_table_lookup(ctx->backoff, s->data); #if 0 printtext(NULL, NULL, MSGLEVEL_CRAP, "backoff = %s for s->data=*%s*", (backoff ? "yes" : "no"), s->data); if (backoff) printtext(NULL, NULL, MSGLEVEL_CRAP, "current backoff = %d, next = %d for *%s*, time = %d", backoff->exponent, backoff->next, s->data, time(NULL)); #endif if (!backoff || backoff->next <= time(NULL)) { callback(s->data, userdata); return TRUE; } const time_t wait = backoff->next - time(NULL); if (wait < soonest) { soonest = wait; } } struct server_retry_ctx *retry_ctx = g_new0(struct server_retry_ctx, 1); retry_ctx->address = g_strdup(address); retry_ctx->random = random; retry_ctx->callback = callback; retry_ctx->userdata = userdata; retry_ctx->timeout_id = g_timeout_add_seconds( soonest, robustsession_network_server_retry_cb, retry_ctx); gulong cancellable_handler = g_cancellable_connect(cancellable, G_CALLBACK(retry_cancelled), retry_ctx, NULL); if (cancellable_handler == 0) { // g_cancellable_connect called g_free(retry_ctx). return; } retry_ctx->cancellable = cancellable; retry_ctx->cancellable_handler = cancellable_handler; return TRUE; } // Correspondingly adjusts exponential backoff state after |target| failed. void robustsession_network_failed(const char *address, const char *target) { gchar *key = g_ascii_strdown(address, -1); struct network_ctx *ctx = g_hash_table_lookup(networks, key); g_free(key); if (!ctx) { return; } struct backoff_state *backoff = g_hash_table_lookup(ctx->backoff, target); if (!backoff) { backoff = g_new0(struct backoff_state, 1); } // Cap the exponential backoff at 2^6 = 64 seconds. In that region, we run // into danger of the client disconnecting due to ping timeout. if (backoff->exponent < 6) { backoff->exponent++; } backoff->next = time(NULL) + pow(2, backoff->exponent) + (rand() % (backoff->exponent + 1)); #if 0 printtext(NULL, NULL, MSGLEVEL_CRAP, "set backoff = %d, next = %d for *%s*", backoff->exponent, backoff->next, target); #endif g_hash_table_replace(ctx->backoff, (gpointer)g_strdup(target), backoff); } void robustsession_network_succeeded(const char *address, const char *target) { gchar *key = g_ascii_strdown(address, -1); struct network_ctx *ctx = g_hash_table_lookup(networks, key); g_free(key); if (!ctx) { return; } g_hash_table_remove(ctx->backoff, target); } void robustsession_network_update_servers(const char *address, GList *servers) { gchar *key = g_ascii_strdown(address, -1); struct network_ctx *ctx = g_hash_table_lookup(networks, key); g_free(key); if (!ctx) { return; } g_list_free_full(ctx->servers, g_free); ctx->servers = servers; // TODO: delete entries in ctx->backoff which now no longer have a corresponding server } irssi-plugin-robustirc-0.6/src/core/robustsession/robustsession-network.h000066400000000000000000000017751300765507200272600ustar00rootroot00000000000000#pragma once // stdlib includes #include // irssi includes #include "irc.h" #include "irc-servers.h" typedef void (*robustsession_network_resolved_cb)(SERVER_REC *server, gpointer userdata); typedef void (*robustsession_network_server_cb)(const char *target, gpointer userdata); bool robustsession_network_init(void); void robustsession_network_resolve( SERVER_REC *server, GCancellable *cancellable, robustsession_network_resolved_cb callback, gpointer userdata); gboolean robustsession_network_server( const char *address, gboolean random, GCancellable *cancellable, robustsession_network_server_cb callback, gpointer userdata); void robustsession_network_failed(const char *address, const char *target); void robustsession_network_succeeded(const char *address, const char *target); void robustsession_network_update_servers(const char *address, GList *servers); irssi-plugin-robustirc-0.6/src/core/robustsession/robustsession.c000066400000000000000000000763001300765507200255600ustar00rootroot00000000000000// vim:ts=4:sw=4:et // © 2015 Michael Stapelberg (see COPYING) // stdlib includes #define _GNU_SOURCE #include #include #include // external library includes #include #include #include #include #include #include // irssi includes #include "common.h" #include "misc.h" #include "network.h" #include "levels.h" #include "printtext.h" #include "irc.h" #include "irc-servers.h" #include "rawlog.h" // module includes #include "robustirc.h" #include "module-formats.h" #include "robustsession-network.h" // from http://robustirc.net/docs/robustsession.html#getmessages static const long robustirc_to_client = 3; static const long robustping = 4; static CURLM *curl_handle; // TODO: when is this freed? struct t_robustsession_ctx { char *sessionid; char *sessionauth; char *lastseen; struct curl_slist *headers; GList *curl_handles; GCancellable *cancellable; SERVER_REC *server; }; struct t_body_buffer { char *body; size_t size; }; // TODO: create a constructor/destructor, figure out what’s idiomatic with glib struct t_robustirc_request { enum { RT_CREATESESSION = 0, RT_DELETESESSION = 1, RT_POSTMESSAGE = 2, RT_GETMESSAGES = 3, } type; char curl_error_buf[CURL_ERROR_SIZE]; // |target| is the host:port to which this request is currently being sent. char *target; // Do not free. Used to prolong the GetMessages timeout when receiving a // RobustPing message. CURL *curl; // |url_suffix| contains the part of the URL after the host:port, so that // the correct URL can easily be re-assembled with a new |target|. char *url_suffix; SERVER_REC *server; struct t_body_buffer *body; // Used when type == RT_GETMESSAGES. guint timeout_tag; struct t_robustsession_ctx *ctx; yajl_handle parser; char *last_key; char *data; bool parsing_id; bool parsing_servers; long last_id_id; long last_id_reply; long last_type; int depth; GList *servers; }; static void get_messages(const char *target, gpointer userdata); static gboolean get_messages_timeout(gpointer userdata); static void curl_set_common_options(CURL *curl, struct t_robustsession_ctx *ctx, SERVER_REC *server, struct t_robustirc_request *request); // Feeds messages such as the following into the JSON parser: // // {"Id": {"Id":1428773900924989332,"Reply":1}, // "Session":{"Id":1428773900606543398,"Reply":0}, // "Type": 3, // "Data": ":robustirc.net 311 sECuRE blorgh michael robust/0x13d4059e24c28428 * :Michael Stapelberg"} // // or (a ping message): // // {"Id": {"Id":0,"Reply":0}, // "Session":{"Id":0,"Reply":0}, // "Type": 4, // "Data": "", // "Servers":["localhost:13003","localhost:13001","localhost:13002"]} static size_t gm_write_func(void *ptr, size_t size, size_t nmemb, void *userdata) { struct t_robustirc_request *request = userdata; // We can safely multiply size * nmemb without overflow checking because // curl_easy_setopt(3), section CURLOPT_WRITEFUNCTION specifies that (size // * nmemb) < CURL_MAX_WRITE_SIZE == 16 KiB. if (yajl_parse(request->parser, ptr, size * nmemb) != yajl_status_ok) { unsigned char *yajl_error = yajl_get_error(request->parser, 0, ptr, size * nmemb); gchar *chunk = g_strdup(ptr); gchar *error = g_strdup((const char *)yajl_error); g_strstrip(chunk); g_strstrip(error); printformat_module(MODULE_NAME, request->server, NULL, MSGLEVEL_CRAP, ROBUSTIRCTXT_ERROR_PARSE_JSON, chunk, error); g_free(chunk); g_free(error); yajl_free_error(request->parser, yajl_error); } return size * nmemb; } static int gm_json_map_key(void *ctx, const unsigned char *val, size_t len) { struct t_robustirc_request *request = ctx; free(request->last_key); request->last_key = g_new0(char, len + 1); memcpy(request->last_key, val, len); return 1; } static int gm_json_integer(void *ctx, long long val) { struct t_robustirc_request *request = ctx; if (!request->last_key) { return 1; } if (request->parsing_id) { if (strcasecmp(request->last_key, "id") == 0) { request->last_id_id = val; } else if (strcasecmp(request->last_key, "reply") == 0) { request->last_id_reply = val; } } if (strcasecmp(request->last_key, "type") == 0) { request->last_type = val; } return 1; } static int gm_json_string(void *ctx, const unsigned char *val, size_t len) { struct t_robustirc_request *request = ctx; if (request->parsing_servers) { char *str = g_new0(char, len + 1); memcpy(str, val, len); request->servers = g_list_append(request->servers, str); return 1; } if (!request->last_key) { return 1; } if (strcasecmp(request->last_key, "data") == 0) { free(request->data); request->data = g_new0(char, len + 1); memcpy(request->data, val, len); } return 1; } static int gm_json_start_array(void *ctx) { struct t_robustirc_request *request = ctx; if (request->last_key && strcasecmp(request->last_key, "servers") == 0) { request->parsing_servers = true; g_list_free_full(request->servers, g_free); } return 1; } static int gm_json_end_array(void *ctx) { struct t_robustirc_request *request = ctx; request->parsing_servers = false; return 1; } static int gm_json_start_map(void *ctx) { struct t_robustirc_request *request = ctx; request->parsing_id = (request->last_key && strcasecmp(request->last_key, "id") == 0); request->depth++; return 1; } static int gm_json_end_map(void *ctx) { struct t_robustirc_request *request = ctx; request->parsing_id = false; request->depth--; if (request->depth > 0) { return 1; } // TODO: need to confirm the server is connected and has a rawlog, otherwise segfault if (request->data != NULL && request->last_type == robustirc_to_client) { rawlog_input(request->server->rawlog, request->data); signal_emit("server incoming", 2, request->server, request->data); free(request->data); request->data = NULL; free(request->ctx->lastseen); request->ctx->lastseen = g_strdup_printf( "%ld.%ld", request->last_id_id, request->last_id_reply); } if (request->last_type == robustping) { g_source_remove(request->timeout_tag); request->timeout_tag = g_timeout_add_seconds( 60, get_messages_timeout, request->curl); robustsession_network_update_servers( request->server->connrec->address, request->servers); request->servers = NULL; } robustsession_network_succeeded( request->server->connrec->address, request->target); return 1; } static yajl_callbacks gm_callbacks = { NULL, NULL, gm_json_integer, NULL, NULL, gm_json_string, gm_json_start_map, gm_json_map_key, gm_json_end_map, gm_json_start_array, gm_json_end_array}; static gboolean get_messages_timeout(gpointer userdata) { CURL *curl = userdata; struct t_robustirc_request *request = NULL; curl_easy_getinfo(curl, CURLINFO_PRIVATE, &request); SERVER_REC *server = request->server; gchar *address = NULL; if (request->server->connrec && request->server->connrec->address) { address = g_strdup(request->server->connrec->address); robustsession_network_failed(address, request->target); } printtext(NULL, NULL, MSGLEVEL_CRAP, "get_messages_timeout"); curl_multi_remove_handle(curl_handle, curl); request->ctx->curl_handles = g_list_remove(request->ctx->curl_handles, curl); curl_easy_cleanup(curl); free(request->body->body); free(request->body); free(request->target); free(request); if (address) { robustsession_network_server(address, TRUE, request->ctx->cancellable, get_messages, request->ctx); g_free(address); } return G_SOURCE_REMOVE; } static void get_messages(const char *target, gpointer userdata) { struct t_robustirc_request *request = NULL; struct t_robustsession_ctx *ctx = userdata; SERVER_REC *server = ctx->server; CURL *curl = curl_easy_init(); if (!curl) { printformat_module(MODULE_NAME, server, NULL, MSGLEVEL_CRAP, ROBUSTIRCTXT_ERROR_TEMPORARY, "curl_easy_init() failed. Out of memory?"); return; } request = g_new0(struct t_robustirc_request, 1); request->ctx = ctx; request->type = RT_GETMESSAGES; request->body = g_new0(struct t_body_buffer, 1); request->server = server; request->url_suffix = g_strdup_printf("/robustirc/v1/%s/messages", ctx->sessionid); request->target = g_strdup(target); request->curl = curl; request->timeout_tag = g_timeout_add_seconds( 60, get_messages_timeout, curl); yajl_handle hand = yajl_alloc(&gm_callbacks, NULL, request); yajl_config(hand, yajl_allow_multiple_values, 1); request->parser = hand; gchar *url = g_strdup_printf( "https://%s%s?lastseen=%s", request->target, request->url_suffix, ctx->lastseen); curl_easy_setopt(curl, CURLOPT_URL, url); g_free(url); curl_set_common_options(curl, ctx, server, request); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, gm_write_func); curl_easy_setopt(curl, CURLOPT_TIMEOUT, 0); /* Make libcurl immediately start handling the request. */ curl_multi_add_handle(curl_handle, curl); ctx->curl_handles = g_list_append(ctx->curl_handles, curl); int running; curl_multi_socket_action(curl_handle, CURL_SOCKET_TIMEOUT, 0, &running); } static bool create_session_done(struct t_robustirc_request *request, CURL *curl) { yajl_val root, sessionid, sessionauth; char errmsg[1024]; const char *ip_address; root = yajl_tree_parse((const char *)request->body->body, errmsg, sizeof(errmsg)); if (root == NULL) { gchar *chunk = g_strdup(request->body->body); gchar *error = g_strdup(errmsg); g_strstrip(chunk); g_strstrip(error); printformat_module(MODULE_NAME, request->server, NULL, MSGLEVEL_CRAP, ROBUSTIRCTXT_ERROR_PARSE_JSON, chunk, error); g_free(chunk); g_free(error); return false; } if (!(sessionid = yajl_tree_get(root, (const char *[]){"Sessionid", NULL}, yajl_t_string))) { printtext(NULL, NULL, MSGLEVEL_CRAP, "sessionid not found"); yajl_tree_free(root); return false; } if (!(sessionauth = yajl_tree_get(root, (const char *[]){"Sessionauth", NULL}, yajl_t_string))) { printtext(NULL, NULL, MSGLEVEL_CRAP, "sessionauth not found"); yajl_tree_free(root); return false; } curl_easy_getinfo(curl, CURLINFO_PRIMARY_IP, &ip_address); struct t_robustsession_ctx *ctx = request->ctx; ctx->sessionid = g_strdup(YAJL_GET_STRING(sessionid)); ctx->sessionauth = g_strdup(YAJL_GET_STRING(sessionauth)); ctx->headers = curl_slist_append(ctx->headers, "Accept: application/json"); ctx->headers = curl_slist_append(ctx->headers, "Content-Type: application/json"); gchar *auth = g_strdup_printf("X-Session-Auth: %s", ctx->sessionauth); ctx->headers = curl_slist_append(ctx->headers, auth); g_free(auth); // TODO: store ip somewhere // TODO: is this necessary? request->server->rawlog = rawlog_create(); request->server->connect_tag = -1; server_connect_finished(SERVER(request->server)); yajl_tree_free(root); return true; } static void retry_request(const char *target, gpointer userdata) { CURL *curl = userdata; struct t_robustirc_request *request = NULL; curl_easy_getinfo(curl, CURLINFO_PRIVATE, &request); printformat_module(MODULE_NAME, request->server, NULL, MSGLEVEL_CRAP, ROBUSTIRCTXT_ERROR_RETRY, request->url_suffix, request->target, target); // Reset the HTTP body and parser state, if any. free(request->body->body); request->body->body = NULL; request->body->size = 0; if (request->type == RT_GETMESSAGES) { yajl_free(request->parser); yajl_handle hand = yajl_alloc(&gm_callbacks, NULL, request); yajl_config(hand, yajl_allow_multiple_values, 1); request->parser = hand; } g_free(request->target); request->target = g_strdup(target); gchar *url = NULL; if (request->type == RT_GETMESSAGES) { url = g_strdup_printf( "https://%s%s?lastseen=%s", request->target, request->url_suffix, request->ctx->lastseen); request->timeout_tag = g_timeout_add_seconds( 60, get_messages_timeout, curl); } else { url = g_strdup_printf( "https://%s%s", request->target, request->url_suffix); } curl_easy_setopt(curl, CURLOPT_URL, url); g_free(url); curl_multi_add_handle(curl_handle, curl); request->ctx->curl_handles = g_list_append(request->ctx->curl_handles, curl); int running; curl_multi_socket_action(curl_handle, CURL_SOCKET_TIMEOUT, 0, &running); } // check_multi_info iterates through all curl handles, handling those that // completed by either retrying the request (on temporary errors) or freeing // the corresponding memory. static void check_multi_info(void) { CURLMsg *message = NULL; struct t_robustirc_request *request = NULL; int pending; long http_code; while ((message = curl_multi_info_read(curl_handle, &pending))) { if (message->msg != CURLMSG_DONE) continue; curl_easy_getinfo(message->easy_handle, CURLINFO_PRIVATE, &request); curl_easy_getinfo(message->easy_handle, CURLINFO_RESPONSE_CODE, &http_code); const bool error = (message->data.result != CURLE_OK || http_code != 200); // Errors on the curl higher level (e.g. connection refused) are not // permanent, and neither are the 5xx HTTP error codes. const bool temporary_error = (message->data.result != CURLE_OK || (http_code >= 500 && http_code < 600)); // TODO: log a line for every terminated HTTP request into the rawlog (or is there a better one?) if (!request->server || !request->server->connrec || !request->server->connrec->address) { goto cleanup; } if (message->data.result != CURLE_OK) { printformat_module(MODULE_NAME, request->server, NULL, MSGLEVEL_CRAP, ROBUSTIRCTXT_ERROR_TEMPORARY, request->curl_error_buf); } // RT_GETMESSAGES requests are never-ending. If such a request // succeeds, the server has closed the connection, likely because the // server is in a network partition. Hence, treat a finished // RT_GETMESSAGES like an error. if (error || request->type == RT_GETMESSAGES) { robustsession_network_failed( request->server->connrec->address, request->target); } else { robustsession_network_succeeded( request->server->connrec->address, request->target); } if ((error && temporary_error) || (!error && request->type == RT_GETMESSAGES)) { curl_multi_remove_handle(curl_handle, message->easy_handle); request->ctx->curl_handles = g_list_remove(request->ctx->curl_handles, message->easy_handle); if (request->type == RT_GETMESSAGES) { g_source_remove(request->timeout_tag); } robustsession_network_server( request->server->connrec->address, (request->type == RT_GETMESSAGES), request->ctx->cancellable, retry_request, message->easy_handle); continue; } if (error && !temporary_error) { gchar *reason = g_strdup_printf("HTTP error code %ld", http_code); printformat_module(MODULE_NAME, request->server, NULL, MSGLEVEL_CRAP, ROBUSTIRCTXT_ERROR_PERMANENT, reason); g_free(reason); request->server->connection_lost = TRUE; server_disconnect(request->server); continue; } // TODO: check for Content-Location header and _network_prefer that // server. Requires setting CURLOPT_HEADERFUNCTION, see // http://curl.haxx.se/libcurl/c/CURLOPT_HEADERFUNCTION.html switch (request->type) { case RT_CREATESESSION: if (create_session_done(request, message->easy_handle)) { robustsession_network_server( request->server->connrec->address, TRUE, request->ctx->cancellable, get_messages, request->ctx); } break; case RT_POSTMESSAGE: break; default: assert(false); } cleanup: curl_multi_remove_handle(curl_handle, message->easy_handle); request->ctx->curl_handles = g_list_remove(request->ctx->curl_handles, message->easy_handle); curl_easy_cleanup(message->easy_handle); free(request->body->body); free(request->body); free(request); } } /* irssi callback which notifies libcurl about events on file descriptor |fd|. */ static void socket_recv_cb(void *data, GIOChannel *source, int condition) { int running; CURLMcode result = curl_multi_socket_action( curl_handle, g_io_channel_unix_get_fd(source), 0, &running); if (result != CURLM_OK) { printformat_module(MODULE_NAME, NULL, NULL, MSGLEVEL_CRAP, ROBUSTIRCTXT_ERROR_TEMPORARY, curl_multi_strerror(result)); } check_multi_info(); } /* irssi callback which notifies libcurl about a timeout. */ static gboolean timeout_cb(gpointer user_data) { if (user_data) { g_free(user_data); curl_multi_setopt(curl_handle, CURLMOPT_TIMERDATA, NULL); } int running; CURLMcode result = curl_multi_socket_action( curl_handle, CURL_SOCKET_TIMEOUT, 0, &running); if (result != CURLM_OK) { printformat_module(MODULE_NAME, NULL, NULL, MSGLEVEL_CRAP, ROBUSTIRCTXT_ERROR_TEMPORARY, curl_multi_strerror(result)); } check_multi_info(); return G_SOURCE_REMOVE; } /* libcurl callback which sets up a WeeChat hook to watch for events on socket |s|. */ static int socket_callback(CURL *easy, curl_socket_t s, int what, void *userp, void *socketp) { if (what == CURL_POLL_NONE) return 0; guint *id = socketp; if (what == CURL_POLL_REMOVE) { if (id) { g_source_remove(*id); g_free(id); curl_multi_assign(curl_handle, s, NULL); } return 0; } if (!id) { id = g_new(guint, 1); } else { g_source_remove(*id); } GIOChannel *handle = g_io_channel_new(s); int condition = 0; switch (what) { case CURL_POLL_IN: condition = G_INPUT_READ; break; case CURL_POLL_OUT: condition = G_INPUT_WRITE; break; case CURL_POLL_INOUT: condition = G_INPUT_READ | G_INPUT_WRITE; break; } *id = g_input_add(handle, condition, socket_recv_cb, NULL); g_io_channel_unref(handle); curl_multi_assign(curl_handle, s, id); return 0; } /* libcurl callback to adjust the timeout of our WeeChat timer. */ static int start_timeout(CURLM *multi, long timeout_ms, void *userp) { guint *id = userp; if (id) g_source_remove(*id); // -1 means we should just delete our timer. if (timeout_ms == -1) { g_free(id); id = NULL; } else { if (!id) id = g_new(guint, 1); *id = g_timeout_add(timeout_ms, timeout_cb, id); } curl_multi_setopt(multi, CURLMOPT_TIMERDATA, id); return 0; } static size_t write_func(void *contents, size_t size, size_t nmemb, void *userp) { // We can safely multiply size * nmemb without overflow checking because // curl_easy_setopt(3), section CURLOPT_WRITEFUNCTION specifies that (size // * nmemb) < CURL_MAX_WRITE_SIZE == 16 KiB. size_t realsize = size * nmemb; struct t_robustirc_request *request = userp; struct t_body_buffer *body_buffer = request->body; if ((SIZE_MAX - realsize - 1) < body_buffer->size) { return 0; } body_buffer->body = realloc(body_buffer->body, body_buffer->size + realsize + 1); if (body_buffer->body == NULL) { return 0; } memcpy(&(body_buffer->body[body_buffer->size]), contents, realsize); body_buffer->size += realsize; body_buffer->body[body_buffer->size] = 0; return realsize; } bool robustsession_init(void) { if (curl_global_init(CURL_GLOBAL_DEFAULT) != 0) return false; if (!(curl_handle = curl_multi_init())) return false; curl_multi_setopt(curl_handle, CURLMOPT_SOCKETFUNCTION, socket_callback); curl_multi_setopt(curl_handle, CURLMOPT_TIMERFUNCTION, start_timeout); return robustsession_network_init(); } void robustsession_deinit(void) { curl_multi_cleanup(curl_handle); } static void curl_set_common_options(CURL *curl, struct t_robustsession_ctx *ctx, SERVER_REC *server, struct t_robustirc_request *request) { curl_easy_setopt(curl, CURLOPT_USERAGENT, ROBUSTSESSION_USER_AGENT); if (ctx) { curl_easy_setopt(curl, CURLOPT_HTTPHEADER, ctx->headers); } curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_func); curl_easy_setopt(curl, CURLOPT_WRITEDATA, request); curl_easy_setopt(curl, CURLOPT_PRIVATE, request); curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, request->curl_error_buf); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, (int)server->connrec->ssl_verify); curl_easy_setopt(curl, CURLOPT_TIMEOUT, 30); curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 5); if (server->connrec->family) { long resolve = CURL_IPRESOLVE_V6; if (server->connrec->family == AF_INET) { resolve = CURL_IPRESOLVE_V4; } curl_easy_setopt(curl, CURLOPT_IPRESOLVE, resolve); } // TODO: set proxy options, see CURLOPT_PROXY and CURLOPT_PROXYUSERPWD in // libcurl, see server->connrec->proxy{,_password,_port} in irssi. } // Called once robustsession_network_server gave us an available server. // Sends a CreateSession request. static void robustsession_connect_target(const char *target, gpointer userdata) { CURL *curl = NULL; struct t_robustsession_ctx *ctx = userdata; SERVER_REC *server = ctx->server; if (!(curl = curl_easy_init())) { printformat_module(MODULE_NAME, server, NULL, MSGLEVEL_CRAP, ROBUSTIRCTXT_ERROR_TEMPORARY, "curl_easy_init() failed. Out of memory?"); return; } struct t_robustirc_request *request = g_new0(struct t_robustirc_request, 1); request->type = RT_CREATESESSION; request->body = g_new0(struct t_body_buffer, 1); request->server = SERVER(server); request->ctx = ctx; request->url_suffix = g_strdup("/robustirc/v1/session"); request->target = g_strdup(target); gchar *url = g_strdup_printf( "https://%s%s", request->target, request->url_suffix); curl_easy_setopt(curl, CURLOPT_URL, url); g_free(url); curl_easy_setopt(curl, CURLOPT_POST, 1); curl_set_common_options(curl, ctx, SERVER(server), request); /* Make libcurl immediately start handling the request. */ curl_multi_add_handle(curl_handle, curl); ctx->curl_handles = g_list_append(ctx->curl_handles, curl); int running; curl_multi_socket_action(curl_handle, CURL_SOCKET_TIMEOUT, 0, &running); } static void robustsession_connect_resolved( SERVER_REC *server, gpointer userdata) { struct t_robustsession_ctx *ctx = userdata; robustsession_network_server( server->connrec->address, TRUE, ctx->cancellable, robustsession_connect_target, ctx); } struct t_robustsession_ctx *robustsession_connect(SERVER_REC *server) { gchar *m = g_strdup_printf("server = %p, server->connrec = %p", server, server->connrec); printtext(NULL, NULL, MSGLEVEL_CRAP, "looking. server = %s", m); g_free(m); struct t_robustsession_ctx *ctx = g_new0(struct t_robustsession_ctx, 1); ctx->lastseen = g_strdup("0.0"); ctx->server = server; ctx->cancellable = g_cancellable_new(); robustsession_network_resolve(server, ctx->cancellable, robustsession_connect_resolved, ctx); signal_emit("server looking", 1, server); return ctx; } struct send_ctx { SERVER_REC *server; char *buffer; struct t_robustsession_ctx *ctx; }; static void robustsession_send_target(const char *target, gpointer callback) { struct send_ctx *send_ctx = callback; gchar *url = NULL; yajl_gen gen = NULL; CURL *curl = NULL; struct t_robustirc_request *request = NULL; struct t_robustsession_ctx *ctx = send_ctx->ctx; if (!(curl = curl_easy_init())) { printformat_module(MODULE_NAME, send_ctx->server, NULL, MSGLEVEL_CRAP, ROBUSTIRCTXT_ERROR_TEMPORARY, "curl_easy_init() failed. Out of memory?"); goto error; } if (!(gen = yajl_gen_alloc(NULL))) { printformat_module(MODULE_NAME, send_ctx->server, NULL, MSGLEVEL_CRAP, ROBUSTIRCTXT_ERROR_TEMPORARY, "yajl_gen_alloc() failed. Out of memory?"); goto error; } // TODO: yajl error handling yajl_gen_map_open(gen); yajl_gen_string(gen, (const unsigned char *)"Data", strlen("Data")); yajl_gen_string(gen, (const unsigned char *)send_ctx->buffer, strlen(send_ctx->buffer)); yajl_gen_string(gen, (const unsigned char *)"ClientMessageId", strlen("ClientMessageId")); yajl_gen_integer(gen, g_str_hash(send_ctx->buffer) + rand()); yajl_gen_map_close(gen); const unsigned char *body = NULL; size_t len = 0; yajl_gen_get_buf(gen, &body, &len); request = g_new0(struct t_robustirc_request, 1); request->type = RT_POSTMESSAGE; request->body = g_new0(struct t_body_buffer, 1); request->server = send_ctx->server; request->target = g_strdup(target); request->ctx = ctx; request->url_suffix = g_strdup_printf("/robustirc/v1/%s/message", ctx->sessionid); if (!(url = g_strdup_printf("https://%s%s", request->target, request->url_suffix))) { printformat_module(MODULE_NAME, send_ctx->server, NULL, MSGLEVEL_CRAP, ROBUSTIRCTXT_ERROR_TEMPORARY, "g_strdup_printf() failed. Out of memory?"); goto error; } curl_easy_setopt(curl, CURLOPT_URL, url); g_free(url); curl_easy_setopt(curl, CURLOPT_POST, 1); curl_easy_setopt(curl, CURLOPT_COPYPOSTFIELDS, body); curl_set_common_options(curl, ctx, send_ctx->server, request); yajl_gen_free(gen); /* Make libcurl immediately start handling the request. */ curl_multi_add_handle(curl_handle, curl); ctx->curl_handles = g_list_append(ctx->curl_handles, curl); int running; curl_multi_socket_action(curl_handle, CURL_SOCKET_TIMEOUT, 0, &running); free(send_ctx->buffer); free(send_ctx); return; error: if (curl != NULL) curl_easy_cleanup(curl); if (gen != NULL) yajl_gen_free(gen); g_free(url); if (request != NULL) { free(request->body); } free(request); free(send_ctx->buffer); free(send_ctx); } void robustsession_send(struct t_robustsession_ctx *ctx, SERVER_REC *server, const char *buffer, int size_buf) { assert(ctx); struct send_ctx *sendctx = g_new0(struct send_ctx, 1); sendctx->server = server; sendctx->buffer = g_strdup(buffer); sendctx->ctx = ctx; robustsession_network_server( server->connrec->address, FALSE, ctx->cancellable, robustsession_send_target, sendctx); } // Delivers outstanding /message requests, but never reads anything or interacts with irssi. void robustsession_write_only(struct t_robustsession_ctx *ctx) { assert(ctx); printtext(NULL, NULL, MSGLEVEL_CRAP, "robustsession_write_only"); // Abort all currently running GetMessages, set the server pointer to NULL // for the rest. This prevents any callbacks from triggering and trying to // reference the server data which is about to be freed. for (GList *h = ctx->curl_handles; h;) { CURL *curl = h->data; // TODO: refactor cleanup into a separate function struct t_robustirc_request *request = NULL; curl_easy_getinfo(curl, CURLINFO_PRIVATE, &request); if (request->type != RT_GETMESSAGES) { request->server = NULL; h = h->next; continue; } curl_multi_remove_handle(curl_handle, curl); curl_easy_cleanup(curl); g_source_remove(request->timeout_tag); free(request->body->body); free(request->body); free(request->target); free(request); GList *next = h->next; ctx->curl_handles = g_list_remove_link(ctx->curl_handles, h); g_list_free_1(h); h = next; } } void robustsession_destroy(struct t_robustsession_ctx *ctx) { assert(ctx); printtext(NULL, NULL, MSGLEVEL_CRAP, "robustsession_destroy"); // Abort all pending robustsession_network_* operations. g_cancellable_cancel(ctx->cancellable); // Abort all currently running requests. This prevents any callbacks from // triggering and trying to reference the server data which is about to be // freed. for (GList *h = ctx->curl_handles; h; h = h->next) { CURL *curl = h->data; // TODO: refactor cleanup into a separate function struct t_robustirc_request *request = NULL; curl_easy_getinfo(curl, CURLINFO_PRIVATE, &request); curl_multi_remove_handle(curl_handle, curl); curl_easy_cleanup(curl); if (request->type == RT_GETMESSAGES) { g_source_remove(request->timeout_tag); } free(request->body->body); free(request->body); free(request->target); free(request); } g_list_free(ctx->curl_handles); g_free(ctx); // TODO: send destroysession request, possibly only on a best-effort basis to avoid big refactoring. // TODO: free the _network entry if there are no other open connections to // that same network so that we’ll re-resolve the next time we connect. // maybe use refcounting for that? does that play nice with a hashtable? } irssi-plugin-robustirc-0.6/src/core/robustsession/robustsession.h000066400000000000000000000006651300765507200255660ustar00rootroot00000000000000#pragma once #include struct t_robustsession_ctx; bool robustsession_init(void); void robustsession_deinit(void); struct t_robustsession_ctx *robustsession_connect(SERVER_REC *server); void robustsession_send(struct t_robustsession_ctx *ctx, SERVER_REC *server, const char *buffer, int size_buf); void robustsession_write_only(struct t_robustsession_ctx *ctx); void robustsession_destroy(struct t_robustsession_ctx *ctx); irssi-plugin-robustirc-0.6/src/fe-common/000077500000000000000000000000001300765507200204725ustar00rootroot00000000000000irssi-plugin-robustirc-0.6/src/fe-common/CMakeLists.txt000066400000000000000000000002751300765507200232360ustar00rootroot00000000000000add_library(fe_robustirc MODULE module-formats.c fe-robustirc.c) target_link_libraries(fe_robustirc ${DEPS_LIBRARIES} m) install(TARGETS fe_robustirc LIBRARY DESTINATION lib/irssi/modules) irssi-plugin-robustirc-0.6/src/fe-common/fe-robustirc.c000066400000000000000000000015561300765507200232510ustar00rootroot00000000000000// vim:ts=4:sw=4:et // © 2015 Michael Stapelberg (see COPYING) #include "common.h" //#include "module.h" #include "servers-setup.h" #include "signals.h" #include "module-formats.h" #include "robustirc.h" static void sig_server_add_fill(SERVER_SETUP_REC *rec, GHashTable *optlist) { char *value; if ((value = g_hash_table_lookup(optlist, "robustirc")) != NULL) { g_free_and_null(rec->chatnet); if (*value != '\0') rec->chatnet = g_strdup("robustirc"); } } void fe_robustirc_init(void) { signal_add("server add fill", sig_server_add_fill); theme_register(fe_robustirc_formats); module_register(MODULE_NAME, "fe"); } void fe_robustirc_deinit(void) { signal_remove("server add fill", sig_server_add_fill); } #ifdef IRSSI_ABI_VERSION void fe_robustirc_abicheck(int *version) { *version = IRSSI_ABI_VERSION; } #endif irssi-plugin-robustirc-0.6/src/fe-common/module-formats.c000066400000000000000000000012331300765507200235730ustar00rootroot00000000000000// vim:ts=4:sw=4:et // © 2015 Michael Stapelberg (see COPYING) #include "robustirc.h" #include "common.h" #include "formats.h" FORMAT_REC fe_robustirc_formats[] = { {MODULE_NAME, "RobustIRC", 0, {0}}, {NULL, "Errors", 0, {0}}, {"error_temporary", "{hilight RobustIRC:} Temporary error {reason $0}", 1, {0}}, {"error_retry", "{hilight RobustIRC:} Retrying request $0 (failed on {server $1}) on {server $2}", 3, {0}}, {"error_parse_json", "{hilight RobustIRC:} Error parsing chunk \"$0\" as JSON {reason $1}", 2, {0}}, {"error_permanent", "{hilight RobustIRC:} Permanent error (killed?) {reason $0}", 1, {0}}, {NULL, NULL, 0, {0}}, }; irssi-plugin-robustirc-0.6/src/fe-common/module-formats.h000066400000000000000000000004251300765507200236020ustar00rootroot00000000000000#pragma once #include "formats.h" enum { ROBUSTIRCTXT_MODULE_NAME, ROBUSTIRCTXT_FILL_1, ROBUSTIRCTXT_ERROR_TEMPORARY, ROBUSTIRCTXT_ERROR_RETRY, ROBUSTIRCTXT_ERROR_PARSE_JSON, ROBUSTIRCTXT_ERROR_PERMANENT, }; extern FORMAT_REC fe_robustirc_formats[];