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/alias | |
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/alias')
-rw-r--r-- | src/plugins/alias/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/plugins/alias/Makefile.am | 5 | ||||
-rw-r--r-- | src/plugins/alias/alias-info.c | 93 | ||||
-rw-r--r-- | src/plugins/alias/alias-info.h | 25 | ||||
-rw-r--r-- | src/plugins/alias/alias.c | 58 | ||||
-rw-r--r-- | src/plugins/alias/alias.h | 10 |
6 files changed, 192 insertions, 3 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 */ |