diff options
Diffstat (limited to 'src/plugins/fifo')
-rw-r--r-- | src/plugins/fifo/CMakeLists.txt | 3 | ||||
-rw-r--r-- | src/plugins/fifo/Makefile.am | 4 | ||||
-rw-r--r-- | src/plugins/fifo/fifo-command.c | 117 | ||||
-rw-r--r-- | src/plugins/fifo/fifo-command.h | 25 | ||||
-rw-r--r-- | src/plugins/fifo/fifo-info.c | 2 | ||||
-rw-r--r-- | src/plugins/fifo/fifo-info.h | 2 | ||||
-rw-r--r-- | src/plugins/fifo/fifo.c | 35 | ||||
-rw-r--r-- | src/plugins/fifo/fifo.h | 4 |
8 files changed, 173 insertions, 19 deletions
diff --git a/src/plugins/fifo/CMakeLists.txt b/src/plugins/fifo/CMakeLists.txt index 9a547d86e..b1c27b62f 100644 --- a/src/plugins/fifo/CMakeLists.txt +++ b/src/plugins/fifo/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (C) 2003-2015 Sébastien Helleu <flashcode@flashtux.org> +# Copyright (C) 2003-2016 Sébastien Helleu <flashcode@flashtux.org> # # This file is part of WeeChat, the extensible chat client. # @@ -19,6 +19,7 @@ add_library(fifo MODULE fifo.c fifo.h +fifo-command.c fifo-command.h fifo-info.c fifo-info.h) set_target_properties(fifo PROPERTIES PREFIX "") diff --git a/src/plugins/fifo/Makefile.am b/src/plugins/fifo/Makefile.am index b7fb2ec7e..8a51e9fb2 100644 --- a/src/plugins/fifo/Makefile.am +++ b/src/plugins/fifo/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright (C) 2003-2015 Sébastien Helleu <flashcode@flashtux.org> +# Copyright (C) 2003-2016 Sébastien Helleu <flashcode@flashtux.org> # # This file is part of WeeChat, the extensible chat client. # @@ -25,6 +25,8 @@ lib_LTLIBRARIES = fifo.la fifo_la_SOURCES = fifo.c \ fifo.h \ + fifo-command.c \ + fifo-command.h \ fifo-info.c \ fifo-info.h fifo_la_LDFLAGS = -module -no-undefined diff --git a/src/plugins/fifo/fifo-command.c b/src/plugins/fifo/fifo-command.c new file mode 100644 index 000000000..ece6ea646 --- /dev/null +++ b/src/plugins/fifo/fifo-command.c @@ -0,0 +1,117 @@ +/* + * fifo-command.c - fifo command + * + * Copyright (C) 2003-2016 Sébastien Helleu <flashcode@flashtux.org> + * + * This file is part of WeeChat, the extensible chat client. + * + * WeeChat 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 3 of the License, or + * (at your option) any later version. + * + * WeeChat 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 WeeChat. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <stdlib.h> + +#include "../weechat-plugin.h" +#include "fifo.h" + + +/* + * Callback for command "/fifo": manages FIFO pipe. + */ + +int +fifo_command_fifo (void *data, struct t_gui_buffer *buffer, int argc, + char **argv, char **argv_eol) +{ + /* make C compiler happy */ + (void) data; + (void) buffer; + (void) argv_eol; + + if (argc == 1) + { + if (fifo_fd != -1) + { + weechat_printf (NULL, + _("%s: pipe is enabled (file: %s)"), + FIFO_PLUGIN_NAME, + fifo_filename); + } + else + { + weechat_printf (NULL, + _("%s: pipe is disabled"), FIFO_PLUGIN_NAME); + } + return WEECHAT_RC_OK; + } + + /* enable pipe */ + if (weechat_strcasecmp (argv[1], "enable") == 0) + { + weechat_config_set_plugin (FIFO_OPTION_NAME, "on"); + return WEECHAT_RC_OK; + } + + /* disable pipe */ + if (weechat_strcasecmp (argv[1], "disable") == 0) + { + weechat_config_set_plugin (FIFO_OPTION_NAME, "off"); + return WEECHAT_RC_OK; + } + + /* toggle pipe */ + if (weechat_strcasecmp (argv[1], "toggle") == 0) + { + weechat_config_set_plugin (FIFO_OPTION_NAME, + (fifo_fd == -1) ? "on" : "off"); + return WEECHAT_RC_OK; + } + + WEECHAT_COMMAND_ERROR; +} + +/* + * Hooks fifo command. + */ + +void +fifo_command_init () +{ + weechat_hook_command ( + "fifo", + N_("fifo plugin configuration"), + N_("enable|disable|toggle"), + N_(" enable: enable FIFO pipe\n" + "disable: disable FIFO pipe\n" + " toggle: toggle FIFO pipe\n" + "\n" + "FIFO pipe is used as remote control of WeeChat: you can send " + "commands or text to the FIFO pipe from your shell.\n" + "By default the FIFO pipe is in ~/.weechat/weechat_fifo_xxx " + "(\"xxx\" is the WeeChat PID).\n" + "\n" + "The expected format is one of:\n" + " plugin.buffer *text or command here\n" + " *text or command here\n" + "\n" + "For example to change your freenode nick:\n" + " echo 'irc.server.freenode */nick newnick' " + ">~/.weechat/weechat_fifo_12345\n" + "\n" + "Please read the user's guide for more info and examples.\n" + "\n" + "Examples:\n" + " /fifo toggle"), + "enable|disable|toggle", + &fifo_command_fifo, NULL); +} diff --git a/src/plugins/fifo/fifo-command.h b/src/plugins/fifo/fifo-command.h new file mode 100644 index 000000000..0b7f29b81 --- /dev/null +++ b/src/plugins/fifo/fifo-command.h @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2003-2016 Sébastien Helleu <flashcode@flashtux.org> + * + * This file is part of WeeChat, the extensible chat client. + * + * WeeChat 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 3 of the License, or + * (at your option) any later version. + * + * WeeChat 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 WeeChat. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef WEECHAT_FIFO_COMMAND_H +#define WEECHAT_FIFO_COMMAND_H 1 + +extern void fifo_command_init (); + +#endif /* WEECHAT_FIFO_COMMAND_H */ diff --git a/src/plugins/fifo/fifo-info.c b/src/plugins/fifo/fifo-info.c index 6c5fe2d35..dd709fb9f 100644 --- a/src/plugins/fifo/fifo-info.c +++ b/src/plugins/fifo/fifo-info.c @@ -1,7 +1,7 @@ /* * fifo-info.c - info and infolist hooks for fifo plugin * - * Copyright (C) 2003-2015 Sébastien Helleu <flashcode@flashtux.org> + * Copyright (C) 2003-2016 Sébastien Helleu <flashcode@flashtux.org> * * This file is part of WeeChat, the extensible chat client. * diff --git a/src/plugins/fifo/fifo-info.h b/src/plugins/fifo/fifo-info.h index 234c0b6ab..0a41e7817 100644 --- a/src/plugins/fifo/fifo-info.h +++ b/src/plugins/fifo/fifo-info.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2015 Sébastien Helleu <flashcode@flashtux.org> + * Copyright (C) 2003-2016 Sébastien Helleu <flashcode@flashtux.org> * * This file is part of WeeChat, the extensible chat client. * diff --git a/src/plugins/fifo/fifo.c b/src/plugins/fifo/fifo.c index 8694b57c8..4331eeafa 100644 --- a/src/plugins/fifo/fifo.c +++ b/src/plugins/fifo/fifo.c @@ -1,7 +1,7 @@ /* * fifo.c - fifo plugin for WeeChat: remote control with FIFO pipe * - * Copyright (C) 2003-2015 Sébastien Helleu <flashcode@flashtux.org> + * Copyright (C) 2003-2016 Sébastien Helleu <flashcode@flashtux.org> * * This file is part of WeeChat, the extensible chat client. * @@ -32,6 +32,7 @@ #include "../weechat-plugin.h" #include "fifo.h" +#include "fifo-command.h" #include "fifo-info.h" @@ -158,8 +159,9 @@ fifo_create () if ((weechat_fifo_plugin->debug >= 1) || !fifo_quiet) { weechat_printf (NULL, - _("%s: pipe opened"), - FIFO_PLUGIN_NAME); + _("%s: pipe opened (file: %s)"), + FIFO_PLUGIN_NAME, + fifo_filename); } fifo_fd_hook = weechat_hook_fd (fifo_fd, 1, 0, 0, &fifo_read, NULL); @@ -259,7 +261,7 @@ fifo_exec (const char *text) if (!pos_msg) { weechat_printf (NULL, - _("%s%s: error, invalid text received on pipe"), + _("%s%s: invalid text received in pipe"), weechat_prefix ("error"), FIFO_PLUGIN_NAME); free (text2); return; @@ -267,15 +269,15 @@ fifo_exec (const char *text) pos_msg[0] = '\0'; pos_msg += 2; ptr_buffer = weechat_buffer_search ("==", text2); - } - - if (!ptr_buffer) - { - weechat_printf (NULL, - _("%s%s: error, buffer not found for pipe data"), - weechat_prefix ("error"), FIFO_PLUGIN_NAME); - free (text2); - return; + if (!ptr_buffer) + { + weechat_printf (NULL, + _("%s%s: buffer \"%s\" not found"), + weechat_prefix ("error"), FIFO_PLUGIN_NAME, + text2); + free (text2); + return; + } } weechat_command (ptr_buffer, pos_msg); @@ -424,6 +426,8 @@ fifo_config_cb (void *data, const char *option, const char *value) int weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) { + char str_option[256]; + /* make C compiler happy */ (void) argc; (void) argv; @@ -434,8 +438,11 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) fifo_create (); - weechat_hook_config ("plugins.var.fifo.fifo", &fifo_config_cb, NULL); + snprintf (str_option, sizeof (str_option), + "plugins.var.fifo.%s", FIFO_OPTION_NAME); + weechat_hook_config (str_option, &fifo_config_cb, NULL); + fifo_command_init (); fifo_info_init (); fifo_quiet = 0; diff --git a/src/plugins/fifo/fifo.h b/src/plugins/fifo/fifo.h index 008251ef5..35eb72b0d 100644 --- a/src/plugins/fifo/fifo.h +++ b/src/plugins/fifo/fifo.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2015 Sébastien Helleu <flashcode@flashtux.org> + * Copyright (C) 2003-2016 Sébastien Helleu <flashcode@flashtux.org> * * This file is part of WeeChat, the extensible chat client. * @@ -22,8 +22,10 @@ #define weechat_plugin weechat_fifo_plugin #define FIFO_PLUGIN_NAME "fifo" +#define FIFO_OPTION_NAME "fifo" extern struct t_weechat_plugin *weechat_fifo_plugin; +extern int fifo_fd; extern char *fifo_filename; #endif /* WEECHAT_FIFO_H */ |