mirror of
https://github.com/weechat/weechat.git
synced 2026-07-02 15:53:12 +02:00
Add new hooks in plugins: info (fifo_filename) and infolists (alias, logger_buffer, xfer)
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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 */
|
||||
@@ -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;
|
||||
@@ -46,6 +46,31 @@ struct t_alias *alias_list = NULL;
|
||||
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
|
||||
*/
|
||||
@@ -833,6 +858,35 @@ alias_completion_cb (void *data, const char *completion_item,
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user