diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2008-09-02 15:42:20 +0200 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2008-09-02 15:42:20 +0200 |
commit | e756f4770ae99b07c7aaf7d43d5f07d0c88f256f (patch) | |
tree | 03715590305b4a4fb4cd7018470fb1153f873bd0 /src/plugins | |
parent | b03393fd428a2cf78d2ce1cae81588f598b3d46c (diff) | |
download | weechat-e756f4770ae99b07c7aaf7d43d5f07d0c88f256f.zip |
Add new hooks in plugins: info (fifo_filename) and infolists (alias, logger_buffer, xfer)
Diffstat (limited to 'src/plugins')
27 files changed, 765 insertions, 11 deletions
diff --git a/src/plugins/alias/CMakeLists.txt b/src/plugins/alias/CMakeLists.txt index 6924f52e9..b108d6ed2 100644 --- a/src/plugins/alias/CMakeLists.txt +++ b/src/plugins/alias/CMakeLists.txt @@ -14,7 +14,9 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # -ADD_LIBRARY(alias MODULE alias.c alias.h) +ADD_LIBRARY(alias MODULE +alias.c alias.h +alias-info.c alias-info.h) SET_TARGET_PROPERTIES(alias PROPERTIES PREFIX "") TARGET_LINK_LIBRARIES(alias) diff --git a/src/plugins/alias/Makefile.am b/src/plugins/alias/Makefile.am index 9792be749..9524933d0 100644 --- a/src/plugins/alias/Makefile.am +++ b/src/plugins/alias/Makefile.am @@ -20,6 +20,9 @@ libdir = ${weechat_libdir}/plugins lib_LTLIBRARIES = alias.la -alias_la_SOURCES = alias.c alias.h +alias_la_SOURCES = alias.c \ + alias.h \ + alias-info.c \ + alias-info.h alias_la_LDFLAGS = -module alias_la_LIBADD = $(ALIAS_LFLAGS) diff --git a/src/plugins/alias/alias-info.c b/src/plugins/alias/alias-info.c new file mode 100644 index 000000000..829d228e1 --- /dev/null +++ b/src/plugins/alias/alias-info.c @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2003-2008 by FlashCode <flashcode@flashtux.org> + * See README for License detail, AUTHORS for developers list. + * + * 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 3 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, see <http://www.gnu.org/licenses/>. + */ + +/* alias-info.c: info and infolist hooks for alias plugin */ + + +#include <stdlib.h> + +#include "../weechat-plugin.h" +#include "alias.h" + + +/* + * alias_info_get_infolist_cb: callback called when alias infolist is asked + */ + +struct t_infolist * +alias_info_get_infolist_cb (void *data, const char *infolist_name, + void *pointer, const char *arguments) +{ + struct t_infolist *ptr_infolist; + struct t_alias *ptr_alias; + + /* make C compiler happy */ + (void) data; + (void) arguments; + + if (!infolist_name || !infolist_name[0]) + return NULL; + + if (weechat_strcasecmp (infolist_name, "alias") == 0) + { + if (pointer && !alias_valid (pointer)) + return NULL; + + ptr_infolist = weechat_infolist_new (); + if (ptr_infolist) + { + if (pointer) + { + /* build list with only one alias */ + if (!alias_add_to_infolist (ptr_infolist, pointer)) + { + weechat_infolist_free (ptr_infolist); + return NULL; + } + return ptr_infolist; + } + else + { + /* build list with all aliases */ + for (ptr_alias = alias_list; ptr_alias; + ptr_alias = ptr_alias->next_alias) + { + if (!alias_add_to_infolist (ptr_infolist, ptr_alias)) + { + weechat_infolist_free (ptr_infolist); + return NULL; + } + } + return ptr_infolist; + } + } + } + + return NULL; +} + +/* + * alias_info_init: initialize info and infolist hooks for alias plugin + */ + +void +alias_info_init () +{ + /* alias infolist hooks */ + weechat_hook_infolist ("alias", &alias_info_get_infolist_cb, NULL); +} diff --git a/src/plugins/alias/alias-info.h b/src/plugins/alias/alias-info.h new file mode 100644 index 000000000..4da206168 --- /dev/null +++ b/src/plugins/alias/alias-info.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2003-2008 by FlashCode <flashcode@flashtux.org> + * See README for License detail, AUTHORS for developers list. + * + * 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 3 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, see <http://www.gnu.org/licenses/>. + */ + + +#ifndef __WEECHAT_ALIAS_INFO_H +#define __WEECHAT_ALIAS_INFO_H 1 + +extern void alias_info_init (); + +#endif /* alias-info.h */ diff --git a/src/plugins/alias/alias.c b/src/plugins/alias/alias.c index cd2f13f1b..75768f688 100644 --- a/src/plugins/alias/alias.c +++ b/src/plugins/alias/alias.c @@ -25,6 +25,7 @@ #include "../weechat-plugin.h" #include "alias.h" +#include "alias-info.h" WEECHAT_PLUGIN_NAME("alias"); @@ -37,7 +38,6 @@ WEECHAT_PLUGIN_LICENSE("GPL3"); #define ALIAS_CONFIG_NAME "alias" struct t_weechat_plugin *weechat_alias_plugin = NULL; -#define weechat_plugin weechat_alias_plugin struct t_config_file *alias_config_file = NULL; struct t_config_section *alias_config_section_cmd = NULL; @@ -47,6 +47,31 @@ struct t_alias *last_alias = NULL; /* + * alias_valid: check if an alias pointer exists + * return 1 if alias exists + * 0 if alias is not found + */ + +int +alias_valid (struct t_alias *alias) +{ + struct t_alias *ptr_alias; + + if (!alias) + return 0; + + for (ptr_alias = alias_list; ptr_alias; + ptr_alias = ptr_alias->next_alias) + { + if (ptr_alias == alias) + return 1; + } + + /* alias not found */ + return 0; +} + +/* * alias_search: search an alias */ @@ -834,6 +859,35 @@ alias_completion_cb (void *data, const char *completion_item, } /* + * alias_add_to_infolist: add an alias in an infolist + * return 1 if ok, 0 if error + */ + +int +alias_add_to_infolist (struct t_infolist *infolist, struct t_alias *alias) +{ + struct t_infolist_item *ptr_item; + + if (!infolist || !alias) + return 0; + + ptr_item = weechat_infolist_new_item (infolist); + if (!ptr_item) + return 0; + + if (!weechat_infolist_new_var_pointer (ptr_item, "hook", alias->hook)) + return 0; + if (!weechat_infolist_new_var_string (ptr_item, "name", alias->name)) + return 0; + if (!weechat_infolist_new_var_string (ptr_item, "command", alias->command)) + return 0; + if (!weechat_infolist_new_var_integer (ptr_item, "running", alias->running)) + return 0; + + return 1; +} + +/* * weechat_plugin_init: initialize alias plugin */ @@ -878,6 +932,8 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) weechat_hook_completion ("alias", &alias_completion_cb, NULL); + alias_info_init (); + return WEECHAT_RC_OK; } diff --git a/src/plugins/alias/alias.h b/src/plugins/alias/alias.h index 9aed403ad..97a348e45 100644 --- a/src/plugins/alias/alias.h +++ b/src/plugins/alias/alias.h @@ -20,6 +20,8 @@ #ifndef __WEECHAT_ALIAS_H #define __WEECHAT_ALIAS_H 1 +#define weechat_plugin weechat_alias_plugin + struct t_alias { struct t_hook *hook; /* command hook */ @@ -30,4 +32,12 @@ struct t_alias struct t_alias *next_alias; /* link to next alias */ }; +extern struct t_alias *alias_list; + +extern struct t_weechat_plugin *weechat_alias_plugin; + +extern int alias_valid (struct t_alias *alias); +extern int alias_add_to_infolist (struct t_infolist *infolist, + struct t_alias *alias); + #endif /* alias.h */ diff --git a/src/plugins/fifo/CMakeLists.txt b/src/plugins/fifo/CMakeLists.txt index 46881d208..ac5d17d30 100644 --- a/src/plugins/fifo/CMakeLists.txt +++ b/src/plugins/fifo/CMakeLists.txt @@ -14,7 +14,9 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # -ADD_LIBRARY(fifo MODULE fifo.c) +ADD_LIBRARY(fifo MODULE +fifo.c fifo.h +fifo-info.c fifo-info.h) SET_TARGET_PROPERTIES(fifo PROPERTIES PREFIX "") TARGET_LINK_LIBRARIES(fifo) diff --git a/src/plugins/fifo/Makefile.am b/src/plugins/fifo/Makefile.am index 06cd3be29..09959d8f2 100644 --- a/src/plugins/fifo/Makefile.am +++ b/src/plugins/fifo/Makefile.am @@ -20,6 +20,9 @@ libdir = ${weechat_libdir}/plugins lib_LTLIBRARIES = fifo.la -fifo_la_SOURCES = fifo.c +fifo_la_SOURCES = fifo.c \ + fifo.h \ + fifo-info.c \ + fifo-info.h fifo_la_LDFLAGS = -module fifo_la_LIBADD = $(FIFO_LFLAGS) diff --git a/src/plugins/fifo/fifo-info.c b/src/plugins/fifo/fifo-info.c new file mode 100644 index 000000000..e9f46f5a6 --- /dev/null +++ b/src/plugins/fifo/fifo-info.c @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2003-2008 by FlashCode <flashcode@flashtux.org> + * See README for License detail, AUTHORS for developers list. + * + * 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 3 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, see <http://www.gnu.org/licenses/>. + */ + +/* fifo-info.c: info and infolist hooks for fifo plugin */ + + +#include <stdlib.h> + +#include "../weechat-plugin.h" +#include "fifo.h" + + +/* + * fifo_info_get_info_cb: callback called when fifo info is asked + */ + +char * +fifo_info_get_info_cb (void *data, const char *info_name, + const char *arguments) +{ + /* make C compiler happy */ + (void) data; + (void) arguments; + + if (weechat_strcasecmp (info_name, "fifo_filename") == 0) + { + return fifo_filename; + } + + return NULL; +} + +/* + * fifo_info_init: initialize info and infolist hooks for fifo plugin + */ + +void +fifo_info_init () +{ + /* fifo info hooks */ + weechat_hook_info ("fifo_filename", &fifo_info_get_info_cb, NULL); +} diff --git a/src/plugins/fifo/fifo-info.h b/src/plugins/fifo/fifo-info.h new file mode 100644 index 000000000..494e95ace --- /dev/null +++ b/src/plugins/fifo/fifo-info.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2003-2008 by FlashCode <flashcode@flashtux.org> + * See README for License detail, AUTHORS for developers list. + * + * 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 3 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, see <http://www.gnu.org/licenses/>. + */ + + +#ifndef __WEECHAT_FIFO_INFO_H +#define __WEECHAT_FIFO_INFO_H 1 + +extern void fifo_info_init (); + +#endif /* fifo-info.h */ diff --git a/src/plugins/fifo/fifo.c b/src/plugins/fifo/fifo.c index 7d2c8f5e1..fc4219aeb 100644 --- a/src/plugins/fifo/fifo.c +++ b/src/plugins/fifo/fifo.c @@ -28,6 +28,8 @@ #include <fcntl.h> #include "../weechat-plugin.h" +#include "fifo.h" +#include "fifo-info.h" WEECHAT_PLUGIN_NAME("fifo"); @@ -367,6 +369,8 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) weechat_hook_config ("plugins.var.fifo.fifo", &fifo_config_cb, NULL); + fifo_info_init (); + return WEECHAT_RC_OK; } diff --git a/src/plugins/fifo/fifo.h b/src/plugins/fifo/fifo.h new file mode 100644 index 000000000..be25fd892 --- /dev/null +++ b/src/plugins/fifo/fifo.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2003-2008 by FlashCode <flashcode@flashtux.org> + * See README for License detail, AUTHORS for developers list. + * + * 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 3 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, see <http://www.gnu.org/licenses/>. + */ + + +#ifndef __WEECHAT_FIFO_H +#define __WEECHAT_FIFO_H 1 + +#define weechat_plugin weechat_fifo_plugin + +extern struct t_weechat_plugin *weechat_fifo_plugin; +extern char *fifo_filename; + +#endif /* fifo.h */ diff --git a/src/plugins/irc/irc-info.c b/src/plugins/irc/irc-info.c index 85014c9b1..f70f031c5 100644 --- a/src/plugins/irc/irc-info.c +++ b/src/plugins/irc/irc-info.c @@ -25,7 +25,6 @@ #include "../weechat-plugin.h" #include "irc.h" -#include "irc-info.h" #include "irc-channel.h" #include "irc-nick.h" #include "irc-protocol.h" @@ -177,8 +176,7 @@ irc_info_get_infolist_cb (void *data, const char *infolist_name, /* make C compiler happy */ (void) data; - (void) arguments; - + if (!infolist_name || !infolist_name[0]) return NULL; diff --git a/src/plugins/logger/CMakeLists.txt b/src/plugins/logger/CMakeLists.txt index 26d7b84b9..816d2cc6a 100644 --- a/src/plugins/logger/CMakeLists.txt +++ b/src/plugins/logger/CMakeLists.txt @@ -14,7 +14,10 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # -ADD_LIBRARY(logger MODULE logger.c logger.h logger-buffer.c logger-buffer.h +ADD_LIBRARY(logger MODULE +logger.c logger.h +logger-buffer.c logger-buffer.h +logger-info.c logger-info.h logger-tail.c logger-tail.h) SET_TARGET_PROPERTIES(logger PROPERTIES PREFIX "") diff --git a/src/plugins/logger/Makefile.am b/src/plugins/logger/Makefile.am index 37bd6b9e4..89f7966e5 100644 --- a/src/plugins/logger/Makefile.am +++ b/src/plugins/logger/Makefile.am @@ -24,6 +24,8 @@ logger_la_SOURCES = logger.c \ logger.h \ logger-buffer.c \ logger-buffer.h \ + logger-info.c \ + logger-info.h \ logger-tail.c \ logger-tail.h logger_la_LDFLAGS = -module diff --git a/src/plugins/logger/logger-buffer.c b/src/plugins/logger/logger-buffer.c index 338566f88..446d48133 100644 --- a/src/plugins/logger/logger-buffer.c +++ b/src/plugins/logger/logger-buffer.c @@ -27,6 +27,8 @@ #include <string.h> #include <stdio.h> +#include "../weechat-plugin.h" +#include "logger.h" #include "logger-buffer.h" @@ -35,6 +37,31 @@ struct t_logger_buffer *last_logger_buffer = NULL; /* + * logger_buffer_valid: check if a logger buffer pointer exists + * return 1 if logger buffer exists + * 0 if logger buffer is not found + */ + +int +logger_buffer_valid (struct t_logger_buffer *logger_buffer) +{ + struct t_logger_buffer *ptr_logger_buffer; + + if (!logger_buffer) + return 0; + + for (ptr_logger_buffer = logger_buffers; ptr_logger_buffer; + ptr_logger_buffer = ptr_logger_buffer->next_buffer) + { + if (ptr_logger_buffer == logger_buffer) + return 1; + } + + /* logger_buffer not found */ + return 0; +} + +/* * logger_buffer_add: add a new buffer for logging */ @@ -128,3 +155,33 @@ logger_buffer_free_all () logger_buffer_free (logger_buffers); } } + +/* + * logger_buffer_add_to_infolist: add a logger buffer in an infolist + * return 1 if ok, 0 if error + */ + +int +logger_buffer_add_to_infolist (struct t_infolist *infolist, + struct t_logger_buffer *logger_buffer) +{ + struct t_infolist_item *ptr_item; + + if (!infolist || !logger_buffer) + return 0; + + ptr_item = weechat_infolist_new_item (infolist); + if (!ptr_item) + return 0; + + if (!weechat_infolist_new_var_pointer (ptr_item, "buffer", logger_buffer->buffer)) + return 0; + if (!weechat_infolist_new_var_string (ptr_item, "log_filename", logger_buffer->log_filename)) + return 0; + if (!weechat_infolist_new_var_pointer (ptr_item, "log_file", logger_buffer->log_file)) + return 0; + if (!weechat_infolist_new_var_integer (ptr_item, "log_enabled", logger_buffer->log_enabled)) + return 0; + + return 1; +} diff --git a/src/plugins/logger/logger-buffer.h b/src/plugins/logger/logger-buffer.h index da17c3f10..d2d464461 100644 --- a/src/plugins/logger/logger-buffer.h +++ b/src/plugins/logger/logger-buffer.h @@ -20,6 +20,8 @@ #ifndef __WEECHAT_LOGGER_BUFFER_H #define __WEECHAT_LOGGER_BUFFER_H 1 +struct t_infolist; + struct t_logger_buffer { struct t_gui_buffer *buffer; /* pointer to buffer */ @@ -33,10 +35,13 @@ struct t_logger_buffer extern struct t_logger_buffer *logger_buffers; extern struct t_logger_buffer *last_logger_buffer; +extern int logger_buffer_valid (struct t_logger_buffer *logger_buffer); extern struct t_logger_buffer *logger_buffer_add (struct t_gui_buffer *, const char *log_filename); extern struct t_logger_buffer *logger_buffer_search (struct t_gui_buffer *buffer); extern void logger_buffer_free (struct t_logger_buffer *logger_buffer); extern void logger_buffer_free_all (); +extern int logger_buffer_add_to_infolist (struct t_infolist *infolist, + struct t_logger_buffer *logger_buffer); #endif /* logger-buffer.h */ diff --git a/src/plugins/logger/logger-info.c b/src/plugins/logger/logger-info.c new file mode 100644 index 000000000..0e75f7eb6 --- /dev/null +++ b/src/plugins/logger/logger-info.c @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2003-2008 by FlashCode <flashcode@flashtux.org> + * See README for License detail, AUTHORS for developers list. + * + * 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 3 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, see <http://www.gnu.org/licenses/>. + */ + +/* logger-info.c: info and infolist hooks for logger plugin */ + + +#include <stdlib.h> +#include <stdio.h> + +#include "../weechat-plugin.h" +#include "logger.h" +#include "logger-buffer.h" + + +/* + * logger_info_get_infolist_cb: callback called when logger infolist is asked + */ + +struct t_infolist * +logger_info_get_infolist_cb (void *data, const char *infolist_name, + void *pointer, const char *arguments) +{ + struct t_infolist *ptr_infolist; + struct t_logger_buffer *ptr_logger_buffer; + + /* make C compiler happy */ + (void) data; + (void) arguments; + + if (!infolist_name || !infolist_name[0]) + return NULL; + + if (weechat_strcasecmp (infolist_name, "logger_buffer") == 0) + { + if (pointer && !logger_buffer_valid (pointer)) + return NULL; + + ptr_infolist = weechat_infolist_new (); + if (ptr_infolist) + { + if (pointer) + { + /* build list with only one logger buffer */ + if (!logger_buffer_add_to_infolist (ptr_infolist, pointer)) + { + weechat_infolist_free (ptr_infolist); + return NULL; + } + return ptr_infolist; + } + else + { + /* build list with all logger buffers */ + for (ptr_logger_buffer = logger_buffers; ptr_logger_buffer; + ptr_logger_buffer = ptr_logger_buffer->next_buffer) + { + if (!logger_buffer_add_to_infolist (ptr_infolist, + ptr_logger_buffer)) + { + weechat_infolist_free (ptr_infolist); + return NULL; + } + } + return ptr_infolist; + } + } + } + + return NULL; +} + +/* + * logger_info_init: initialize info and infolist hooks for logger plugin + */ + +void +logger_info_init () +{ + /* irc infolist hooks */ + weechat_hook_infolist ("logger_buffer", &logger_info_get_infolist_cb, NULL); +} diff --git a/src/plugins/logger/logger-info.h b/src/plugins/logger/logger-info.h new file mode 100644 index 000000000..02c75fa67 --- /dev/null +++ b/src/plugins/logger/logger-info.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2003-2008 by FlashCode <flashcode@flashtux.org> + * See README for License detail, AUTHORS for developers list. + * + * 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 3 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, see <http://www.gnu.org/licenses/>. + */ + + +#ifndef __WEECHAT_LOGGER_INFO_H +#define __WEECHAT_LOGGER_INFO_H 1 + +extern void logger_info_init (); + +#endif /* logger-info.h */ diff --git a/src/plugins/logger/logger.c b/src/plugins/logger/logger.c index dac2f267c..37d0d0035 100644 --- a/src/plugins/logger/logger.c +++ b/src/plugins/logger/logger.c @@ -34,8 +34,10 @@ #include <fcntl.h> #include <time.h> +#include "../weechat-plugin.h" #include "logger.h" #include "logger-buffer.h" +#include "logger-info.h" #include "logger-tail.h" @@ -747,6 +749,8 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) weechat_hook_config ("plugins.var.logger.*", &logger_config_cb, NULL); + logger_info_init (); + return WEECHAT_RC_OK; } diff --git a/src/plugins/logger/logger.h b/src/plugins/logger/logger.h index 6b1bb36d0..7f46a7b66 100644 --- a/src/plugins/logger/logger.h +++ b/src/plugins/logger/logger.h @@ -20,8 +20,6 @@ #ifndef __WEECHAT_LOGGER_H #define __WEECHAT_LOGGER_H 1 -#include "../weechat-plugin.h" - #define weechat_plugin weechat_logger_plugin #define LOGGER_BUF_WRITE_SIZE (16*1024) diff --git a/src/plugins/xfer/CMakeLists.txt b/src/plugins/xfer/CMakeLists.txt index fa5126751..855b95121 100644 --- a/src/plugins/xfer/CMakeLists.txt +++ b/src/plugins/xfer/CMakeLists.txt @@ -22,6 +22,7 @@ xfer-command.c xfer-command.h xfer-config.c xfer-config.h xfer-dcc.c xfer-dcc.h xfer-file.c xfer-file.h +xfer-info.c xfer-info.h xfer-network.c xfer-network.h xfer-upgrade.c xfer-upgrade.h) SET_TARGET_PROPERTIES(xfer PROPERTIES PREFIX "") diff --git a/src/plugins/xfer/Makefile.am b/src/plugins/xfer/Makefile.am index b6a7cb0da..47c1be299 100644 --- a/src/plugins/xfer/Makefile.am +++ b/src/plugins/xfer/Makefile.am @@ -34,6 +34,8 @@ xfer_la_SOURCES = xfer.c \ xfer-dcc.h \ xfer-file.c \ xfer-file.h \ + xfer-info.c \ + xfer-info.h \ xfer-network.c \ xfer-network.h \ xfer-upgrade.c \ diff --git a/src/plugins/xfer/xfer-info.c b/src/plugins/xfer/xfer-info.c new file mode 100644 index 000000000..762c5cba3 --- /dev/null +++ b/src/plugins/xfer/xfer-info.c @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2003-2008 by FlashCode <flashcode@flashtux.org> + * See README for License detail, AUTHORS for developers list. + * + * 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 3 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, see <http://www.gnu.org/licenses/>. + */ + +/* xfer-info.c: info and infolist hooks for xfer plugin */ + + +#include <stdlib.h> +#include <stdio.h> + +#include "../weechat-plugin.h" +#include "xfer.h" + + +/* + * xfer_info_get_infolist_cb: callback called when xfer infolist is asked + */ + +struct t_infolist * +xfer_info_get_infolist_cb (void *data, const char *infolist_name, + void *pointer, const char *arguments) +{ + struct t_infolist *ptr_infolist; + struct t_xfer *ptr_xfer; + + /* make C compiler happy */ + (void) data; + (void) arguments; + + if (!infolist_name || !infolist_name[0]) + return NULL; + + if (weechat_strcasecmp (infolist_name, "xfer") == 0) + { + if (pointer && !xfer_valid (pointer)) + return NULL; + + ptr_infolist = weechat_infolist_new (); + if (ptr_infolist) + { + if (pointer) + { + /* build list with only one xfer */ + if (!xfer_add_to_infolist (ptr_infolist, pointer)) + { + weechat_infolist_free (ptr_infolist); + return NULL; + } + return ptr_infolist; + } + else + { + /* build list with all xfers */ + for (ptr_xfer = xfer_list; ptr_xfer; + ptr_xfer = ptr_xfer->next_xfer) + { + if (!xfer_add_to_infolist (ptr_infolist, ptr_xfer)) + { + weechat_infolist_free (ptr_infolist); + return NULL; + } + } + return ptr_infolist; + } + } + } + + return NULL; +} + +/* + * xfer_info_init: initialize info and infolist hooks for xfer plugin + */ + +void +xfer_info_init () +{ + /* xfer infolist hooks */ + weechat_hook_infolist ("xfer", &xfer_info_get_infolist_cb, NULL); +} diff --git a/src/plugins/xfer/xfer-info.h b/src/plugins/xfer/xfer-info.h new file mode 100644 index 000000000..1c3b5be57 --- /dev/null +++ b/src/plugins/xfer/xfer-info.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2003-2008 by FlashCode <flashcode@flashtux.org> + * See README for License detail, AUTHORS for developers list. + * + * 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 3 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, see <http://www.gnu.org/licenses/>. + */ + + +#ifndef __WEECHAT_XFER_INFO_H +#define __WEECHAT_XFER_INFO_H 1 + +extern void xfer_info_init (); + +#endif /* xfer-info.h */ diff --git a/src/plugins/xfer/xfer.c b/src/plugins/xfer/xfer.c index e93af86bb..641fd1a4e 100644 --- a/src/plugins/xfer/xfer.c +++ b/src/plugins/xfer/xfer.c @@ -36,6 +36,7 @@ #include "xfer-command.h" #include "xfer-config.h" #include "xfer-file.h" +#include "xfer-info.h" #include "xfer-network.h" #include "xfer-upgrade.h" @@ -75,6 +76,31 @@ int xfer_signal_upgrade_received = 0; /* signal "upgrade" received ? */ /* + * xfer_valid: check if a xfer pointer exists + * return 1 if xfer exists + * 0 if xfer is not found + */ + +int +xfer_valid (struct t_xfer *xfer) +{ + struct t_xfer *ptr_xfer; + + if (!xfer) + return 0; + + for (ptr_xfer = xfer_list; ptr_xfer; + ptr_xfer = ptr_xfer->next_xfer) + { + if (ptr_xfer == xfer) + return 1; + } + + /* xfer not found */ + return 0; +} + +/* * xfer_signal_upgrade_cb: callback for "upgrade" signal */ @@ -1135,6 +1161,111 @@ xfer_accept_resume_cb (void *data, const char *signal, const char *type_data, } /* + * xfer_add_to_infolist: add a xfer in an infolist + * return 1 if ok, 0 if error + */ + +int +xfer_add_to_infolist (struct t_infolist *infolist, struct t_xfer *xfer) +{ + struct t_infolist_item *ptr_item; + char value[128]; + + if (!infolist || !xfer) + return 0; + + ptr_item = weechat_infolist_new_item (infolist); + if (!ptr_item) + return 0; + + if (!weechat_infolist_new_var_string (ptr_item, "plugin_name", xfer->plugin_name)) + return 0; + if (!weechat_infolist_new_var_string (ptr_item, "plugin_id", xfer->plugin_id)) + return 0; + if (!weechat_infolist_new_var_integer (ptr_item, "type", xfer->type)) + return 0; + if (!weechat_infolist_new_var_string (ptr_item, "type_string", xfer_type_string[xfer->type])) + return 0; + if (!weechat_infolist_new_var_integer (ptr_item, "protocol", xfer->protocol)) + return 0; + if (!weechat_infolist_new_var_string (ptr_item, "protocol_string", xfer_protocol_string[xfer->protocol])) + return 0; + if (!weechat_infolist_new_var_string (ptr_item, "remote_nick", xfer->remote_nick)) + return 0; + if (!weechat_infolist_new_var_string (ptr_item, "local_nick", xfer->local_nick)) + return 0; + if (!weechat_infolist_new_var_string (ptr_item, "filename", xfer->filename)) + return 0; + snprintf (value, sizeof (value), "%lu", xfer->size); + if (!weechat_infolist_new_var_string (ptr_item, "size", value)) + return 0; + snprintf (value, sizeof (value), "%lu", xfer->address); + if (!weechat_infolist_new_var_string (ptr_item, "address", value)) + return 0; + if (!weechat_infolist_new_var_integer (ptr_item, "port", xfer->port)) + return 0; + + if (!weechat_infolist_new_var_integer (ptr_item, "status", xfer->status)) + return 0; + if (!weechat_infolist_new_var_string (ptr_item, "status_string", xfer_status_string[xfer->status])) + return 0; + if (!weechat_infolist_new_var_pointer (ptr_item, "buffer", xfer->buffer)) + return 0; + if (!weechat_infolist_new_var_integer (ptr_item, "fast_send", xfer->fast_send)) + return 0; + if (!weechat_infolist_new_var_integer (ptr_item, "blocksize", xfer->blocksize)) + return 0; + if (!weechat_infolist_new_var_time (ptr_item, "start_time", xfer->start_time)) + return 0; + if (!weechat_infolist_new_var_time (ptr_item, "start_transfer", xfer->start_transfer)) + return 0; + if (!weechat_infolist_new_var_integer (ptr_item, "sock", xfer->sock)) + return 0; + if (!weechat_infolist_new_var_integer (ptr_item, "child_pid", xfer->child_pid)) + return 0; + if (!weechat_infolist_new_var_integer (ptr_item, "child_read", xfer->child_read)) + return 0; + if (!weechat_infolist_new_var_integer (ptr_item, "child_write", xfer->child_write)) + return 0; + if (!weechat_infolist_new_var_pointer (ptr_item, "hook_fd", xfer->hook_fd)) + return 0; + if (!weechat_infolist_new_var_pointer (ptr_item, "hook_timer", xfer->hook_timer)) + return 0; + if (!weechat_infolist_new_var_string (ptr_item, "unterminated_message", xfer->unterminated_message)) + return 0; + if (!weechat_infolist_new_var_integer (ptr_item, "file", xfer->file)) + return 0; + if (!weechat_infolist_new_var_string (ptr_item, "local_filename", xfer->local_filename)) + return 0; + if (!weechat_infolist_new_var_integer (ptr_item, "filename_suffix", xfer->filename_suffix)) + return 0; + snprintf (value, sizeof (value), "%lu", xfer->pos); + if (!weechat_infolist_new_var_string (ptr_item, "pos", value)) + return 0; + snprintf (value, sizeof (value), "%lu", xfer->ack); + if (!weechat_infolist_new_var_string (ptr_item, "ack", value)) + return 0; + snprintf (value, sizeof (value), "%lu", xfer->start_resume); + if (!weechat_infolist_new_var_string (ptr_item, "start_resume", value)) + return 0; + if (!weechat_infolist_new_var_time (ptr_item, "last_check_time", xfer->last_check_time)) + return 0; + snprintf (value, sizeof (value), "%lu", xfer->last_check_pos); + if (!weechat_infolist_new_var_string (ptr_item, "last_check_pos", value)) + return 0; + if (!weechat_infolist_new_var_time (ptr_item, "last_activity", xfer->last_activity)) + return 0; + snprintf (value, sizeof (value), "%lu", xfer->bytes_per_sec); + if (!weechat_infolist_new_var_string (ptr_item, "bytes_per_sec", value)) + return 0; + snprintf (value, sizeof (value), "%lu", xfer->eta); + if (!weechat_infolist_new_var_string (ptr_item, "eta", value)) + return 0; + + return 1; +} + +/* * xfer_print_log: print DCC infos in log (usually for crash dump) */ @@ -1245,6 +1376,8 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) weechat_hook_signal ("xfer_accept_resume", &xfer_accept_resume_cb, NULL); weechat_hook_signal ("debug_dump", &xfer_debug_dump_cb, NULL); + xfer_info_init (); + return WEECHAT_RC_OK; } diff --git a/src/plugins/xfer/xfer.h b/src/plugins/xfer/xfer.h index 228f7f3fa..d3539d965 100644 --- a/src/plugins/xfer/xfer.h +++ b/src/plugins/xfer/xfer.h @@ -154,9 +154,12 @@ extern struct t_xfer *xfer_list, *last_xfer; extern int xfer_count; extern int xfer_debug; +extern int xfer_valid (struct t_xfer *xfer); extern struct t_xfer *xfer_search_by_number (int number); extern void xfer_close (struct t_xfer *xfer, enum t_xfer_status status); extern void xfer_send_signal (struct t_xfer *xfer, const char *signal); extern void xfer_free (struct t_xfer *xfer); +extern int xfer_add_to_infolist (struct t_infolist *infolist, + struct t_xfer *xfer); #endif /* xfer.h */ |