mirror of
https://github.com/weechat/weechat.git
synced 2026-07-02 07:46:38 +02:00
Event hook added
This commit is contained in:
+75
-54
@@ -41,7 +41,9 @@
|
||||
#include "wee-list.h"
|
||||
#include "../gui/gui-chat.h"
|
||||
#include "../gui/gui-history.h"
|
||||
#include "../gui/gui-input.h"
|
||||
#include "../gui/gui-keyboard.h"
|
||||
#include "../gui/gui-status.h"
|
||||
#include "../gui/gui-window.h"
|
||||
#include "../plugins/plugin.h"
|
||||
#include "../plugins/plugin-config.h"
|
||||
@@ -520,6 +522,20 @@ command_buffer (struct t_gui_buffer *buffer,
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if (string_strcasecmp (argv[0], "close") == 0)
|
||||
{
|
||||
if (!buffer->plugin)
|
||||
{
|
||||
gui_chat_printf (NULL,
|
||||
_("%sError: WeeChat main buffer can't be "
|
||||
"closed"),
|
||||
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]);
|
||||
return -1;
|
||||
}
|
||||
gui_buffer_free (buffer, 1);
|
||||
gui_status_draw (gui_current_window->buffer, 1);
|
||||
gui_input_draw (gui_current_window->buffer, 1);
|
||||
}
|
||||
else if (string_strcasecmp (argv[0], "notify") == 0)
|
||||
{
|
||||
if (argc < 2)
|
||||
@@ -1276,54 +1292,6 @@ command_plugin_list (char *name, int full)
|
||||
}
|
||||
}
|
||||
|
||||
/* prints hooked */
|
||||
hook_found = 0;
|
||||
for (ptr_hook = weechat_hooks; ptr_hook;
|
||||
ptr_hook = ptr_hook->next_hook)
|
||||
{
|
||||
if ((ptr_hook->plugin == ptr_plugin)
|
||||
&& (ptr_hook->type == HOOK_TYPE_PRINT))
|
||||
{
|
||||
if (!hook_found)
|
||||
gui_chat_printf (NULL, _(" prints hooked:"));
|
||||
hook_found = 1;
|
||||
if (HOOK_PRINT(ptr_hook, buffer))
|
||||
gui_chat_printf (NULL,
|
||||
_(" buffer: %s / %s, message: \"%s\""),
|
||||
HOOK_PRINT(ptr_hook, buffer)->category,
|
||||
HOOK_PRINT(ptr_hook, buffer)->name,
|
||||
HOOK_PRINT(ptr_hook, message) ?
|
||||
HOOK_PRINT(ptr_hook, message) : _("(none)"));
|
||||
else
|
||||
gui_chat_printf (NULL,
|
||||
_(" message: \"%s\""),
|
||||
HOOK_PRINT(ptr_hook, message) ?
|
||||
HOOK_PRINT(ptr_hook, message) : _("(none)"));
|
||||
}
|
||||
}
|
||||
|
||||
/* config options hooked */
|
||||
hook_found = 0;
|
||||
for (ptr_hook = weechat_hooks; ptr_hook;
|
||||
ptr_hook = ptr_hook->next_hook)
|
||||
{
|
||||
if ((ptr_hook->plugin == ptr_plugin)
|
||||
&& (ptr_hook->type == HOOK_TYPE_CONFIG))
|
||||
{
|
||||
if (!hook_found)
|
||||
gui_chat_printf (NULL,
|
||||
_(" configuration otions "
|
||||
"hooked:"));
|
||||
hook_found = 1;
|
||||
gui_chat_printf (NULL,
|
||||
" (%s) %s",
|
||||
HOOK_CONFIG(ptr_hook, type) ?
|
||||
HOOK_CONFIG(ptr_hook, type) : "*",
|
||||
HOOK_CONFIG(ptr_hook, option) ?
|
||||
HOOK_CONFIG(ptr_hook, option) : "*");
|
||||
}
|
||||
}
|
||||
|
||||
/* timers hooked */
|
||||
hook_found = 0;
|
||||
for (ptr_hook = weechat_hooks; ptr_hook;
|
||||
@@ -1385,18 +1353,71 @@ command_plugin_list (char *name, int full)
|
||||
}
|
||||
}
|
||||
|
||||
/* keyboards hooked */
|
||||
/* prints hooked */
|
||||
hook_found = 0;
|
||||
for (ptr_hook = weechat_hooks; ptr_hook;
|
||||
ptr_hook = ptr_hook->next_hook)
|
||||
{
|
||||
if ((ptr_hook->plugin == ptr_plugin)
|
||||
&& (ptr_hook->type == HOOK_TYPE_KEYBOARD))
|
||||
hook_found++;
|
||||
&& (ptr_hook->type == HOOK_TYPE_PRINT))
|
||||
{
|
||||
if (!hook_found)
|
||||
gui_chat_printf (NULL, _(" prints hooked:"));
|
||||
hook_found = 1;
|
||||
if (HOOK_PRINT(ptr_hook, buffer))
|
||||
gui_chat_printf (NULL,
|
||||
_(" buffer: %s / %s, message: \"%s\""),
|
||||
HOOK_PRINT(ptr_hook, buffer)->category,
|
||||
HOOK_PRINT(ptr_hook, buffer)->name,
|
||||
HOOK_PRINT(ptr_hook, message) ?
|
||||
HOOK_PRINT(ptr_hook, message) : _("(none)"));
|
||||
else
|
||||
gui_chat_printf (NULL,
|
||||
_(" message: \"%s\""),
|
||||
HOOK_PRINT(ptr_hook, message) ?
|
||||
HOOK_PRINT(ptr_hook, message) : _("(none)"));
|
||||
}
|
||||
}
|
||||
|
||||
/* events hooked */
|
||||
hook_found = 0;
|
||||
for (ptr_hook = weechat_hooks; ptr_hook;
|
||||
ptr_hook = ptr_hook->next_hook)
|
||||
{
|
||||
if ((ptr_hook->plugin == ptr_plugin)
|
||||
&& (ptr_hook->type == HOOK_TYPE_EVENT))
|
||||
{
|
||||
if (!hook_found)
|
||||
gui_chat_printf (NULL, _(" events hooked:"));
|
||||
hook_found = 1;
|
||||
gui_chat_printf (NULL,
|
||||
_(" event: %s"),
|
||||
HOOK_EVENT(ptr_hook, event) ?
|
||||
HOOK_EVENT(ptr_hook, event) : _("(all)"));
|
||||
}
|
||||
}
|
||||
|
||||
/* config options hooked */
|
||||
hook_found = 0;
|
||||
for (ptr_hook = weechat_hooks; ptr_hook;
|
||||
ptr_hook = ptr_hook->next_hook)
|
||||
{
|
||||
if ((ptr_hook->plugin == ptr_plugin)
|
||||
&& (ptr_hook->type == HOOK_TYPE_CONFIG))
|
||||
{
|
||||
if (!hook_found)
|
||||
gui_chat_printf (NULL,
|
||||
_(" configuration otions "
|
||||
"hooked:"));
|
||||
hook_found = 1;
|
||||
gui_chat_printf (NULL,
|
||||
" (%s) %s",
|
||||
HOOK_CONFIG(ptr_hook, type) ?
|
||||
HOOK_CONFIG(ptr_hook, type) : "*",
|
||||
HOOK_CONFIG(ptr_hook, option) ?
|
||||
HOOK_CONFIG(ptr_hook, option) : "*");
|
||||
}
|
||||
}
|
||||
if (hook_found)
|
||||
gui_chat_printf (NULL, _(" %d keyboards hooked"),
|
||||
hook_found);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+241
-154
@@ -34,6 +34,7 @@
|
||||
#include "wee-log.h"
|
||||
#include "wee-string.h"
|
||||
#include "wee-util.h"
|
||||
#include "../gui/gui-color.h"
|
||||
#include "../plugins/plugin.h"
|
||||
|
||||
|
||||
@@ -221,140 +222,6 @@ hook_command_exec (void *plugin, char *string)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* hook_print: hook a message printed by WeeChat
|
||||
*/
|
||||
|
||||
struct t_hook *
|
||||
hook_print (void *plugin, void *buffer, char *message,
|
||||
t_hook_callback_print *callback, void *callback_data)
|
||||
{
|
||||
struct t_hook *new_hook;
|
||||
struct t_hook_print *new_hook_print;
|
||||
|
||||
new_hook = (struct t_hook *)malloc (sizeof (struct t_hook));
|
||||
if (!new_hook)
|
||||
return NULL;
|
||||
new_hook_print = (struct t_hook_print *)malloc (sizeof (struct t_hook_print));
|
||||
if (!new_hook_print)
|
||||
{
|
||||
free (new_hook);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
hook_init (new_hook, plugin, HOOK_TYPE_PRINT, callback_data);
|
||||
|
||||
new_hook->hook_data = new_hook_print;
|
||||
new_hook_print->callback = callback;
|
||||
new_hook_print->buffer = (struct t_gui_buffer *)buffer;
|
||||
new_hook_print->message = (message) ? strdup (message) : NULL;
|
||||
|
||||
hook_add_to_list (new_hook);
|
||||
|
||||
return new_hook;
|
||||
}
|
||||
|
||||
/*
|
||||
* hook_print_exec: execute print hook
|
||||
*/
|
||||
|
||||
void
|
||||
hook_print_exec (void *buffer, time_t date, char *prefix, char *message)
|
||||
{
|
||||
struct t_hook *ptr_hook, *next_hook;
|
||||
|
||||
if (!message || !message[0])
|
||||
return;
|
||||
|
||||
ptr_hook = weechat_hooks;
|
||||
while (ptr_hook)
|
||||
{
|
||||
next_hook = ptr_hook->next_hook;
|
||||
|
||||
if ((ptr_hook->type == HOOK_TYPE_PRINT)
|
||||
&& (!ptr_hook->running)
|
||||
&& (!HOOK_PRINT(ptr_hook, buffer)
|
||||
|| ((struct t_gui_buffer *)buffer == HOOK_PRINT(ptr_hook, buffer)))
|
||||
&& (string_strcasestr (message, HOOK_PRINT(ptr_hook, message))))
|
||||
{
|
||||
ptr_hook->running = 1;
|
||||
(void) (HOOK_PRINT(ptr_hook, callback))
|
||||
(ptr_hook->callback_data, buffer, date, prefix, message);
|
||||
if (hook_valid (ptr_hook))
|
||||
ptr_hook->running = 0;
|
||||
}
|
||||
|
||||
ptr_hook = next_hook;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* hook_config: hook a config option
|
||||
*/
|
||||
|
||||
struct t_hook *
|
||||
hook_config (void *plugin, char *type, char *option,
|
||||
t_hook_callback_config *callback, void *callback_data)
|
||||
{
|
||||
struct t_hook *new_hook;
|
||||
struct t_hook_config *new_hook_config;
|
||||
|
||||
new_hook = (struct t_hook *)malloc (sizeof (struct t_hook));
|
||||
if (!new_hook)
|
||||
return NULL;
|
||||
new_hook_config = (struct t_hook_config *)malloc (sizeof (struct t_hook_config));
|
||||
if (!new_hook_config)
|
||||
{
|
||||
free (new_hook);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
hook_init (new_hook, plugin, HOOK_TYPE_CONFIG, callback_data);
|
||||
|
||||
new_hook->hook_data = new_hook_config;
|
||||
new_hook_config->callback = callback;
|
||||
new_hook_config->type = (type) ? strdup (type) : strdup ("");
|
||||
new_hook_config->option = (option) ? strdup (option) : strdup ("");
|
||||
|
||||
hook_add_to_list (new_hook);
|
||||
|
||||
return new_hook;
|
||||
}
|
||||
|
||||
/*
|
||||
* hook_config_exec: execute config hooks
|
||||
*/
|
||||
|
||||
void
|
||||
hook_config_exec (char *type, char *option, char *value)
|
||||
{
|
||||
struct t_hook *ptr_hook, *next_hook;
|
||||
|
||||
ptr_hook = weechat_hooks;
|
||||
while (ptr_hook)
|
||||
{
|
||||
next_hook = ptr_hook->next_hook;
|
||||
|
||||
if ((ptr_hook->type == HOOK_TYPE_CONFIG)
|
||||
&& (!ptr_hook->running)
|
||||
&& (!HOOK_CONFIG(ptr_hook, type)
|
||||
|| (string_strcasecmp (HOOK_CONFIG(ptr_hook, type),
|
||||
type) == 0))
|
||||
&& (!HOOK_CONFIG(ptr_hook, option)
|
||||
|| (string_strcasecmp (HOOK_CONFIG(ptr_hook, option),
|
||||
option) == 0)))
|
||||
{
|
||||
ptr_hook->running = 1;
|
||||
(void) (HOOK_CONFIG(ptr_hook, callback))
|
||||
(ptr_hook->callback_data, type, option, value);
|
||||
if (hook_valid (ptr_hook))
|
||||
ptr_hook->running = 0;
|
||||
}
|
||||
|
||||
ptr_hook = next_hook;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* hook_timer: hook a timer
|
||||
*/
|
||||
@@ -549,6 +416,222 @@ hook_fd_exec (fd_set *read_fds, fd_set *write_fds, fd_set *except_fds)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* hook_print: hook a message printed by WeeChat
|
||||
*/
|
||||
|
||||
struct t_hook *
|
||||
hook_print (void *plugin, void *buffer, char *message, int strip_colors,
|
||||
t_hook_callback_print *callback, void *callback_data)
|
||||
{
|
||||
struct t_hook *new_hook;
|
||||
struct t_hook_print *new_hook_print;
|
||||
|
||||
new_hook = (struct t_hook *)malloc (sizeof (struct t_hook));
|
||||
if (!new_hook)
|
||||
return NULL;
|
||||
new_hook_print = (struct t_hook_print *)malloc (sizeof (struct t_hook_print));
|
||||
if (!new_hook_print)
|
||||
{
|
||||
free (new_hook);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
hook_init (new_hook, plugin, HOOK_TYPE_PRINT, callback_data);
|
||||
|
||||
new_hook->hook_data = new_hook_print;
|
||||
new_hook_print->callback = callback;
|
||||
new_hook_print->buffer = (struct t_gui_buffer *)buffer;
|
||||
new_hook_print->message = (message) ? strdup (message) : NULL;
|
||||
new_hook_print->strip_colors = strip_colors;
|
||||
|
||||
hook_add_to_list (new_hook);
|
||||
|
||||
return new_hook;
|
||||
}
|
||||
|
||||
/*
|
||||
* hook_print_exec: execute print hook
|
||||
*/
|
||||
|
||||
void
|
||||
hook_print_exec (void *buffer, time_t date, char *prefix, char *message)
|
||||
{
|
||||
struct t_hook *ptr_hook, *next_hook;
|
||||
char *prefix_no_color, *message_no_color;
|
||||
|
||||
if (!message || !message[0])
|
||||
return;
|
||||
|
||||
prefix_no_color = (char *)gui_color_decode ((unsigned char *)prefix);
|
||||
if (!prefix_no_color)
|
||||
return;
|
||||
|
||||
message_no_color = (char *)gui_color_decode ((unsigned char *)message);
|
||||
if (!message_no_color)
|
||||
{
|
||||
free (prefix_no_color);
|
||||
return;
|
||||
}
|
||||
|
||||
ptr_hook = weechat_hooks;
|
||||
while (ptr_hook)
|
||||
{
|
||||
next_hook = ptr_hook->next_hook;
|
||||
|
||||
if ((ptr_hook->type == HOOK_TYPE_PRINT)
|
||||
&& (!ptr_hook->running)
|
||||
&& (!HOOK_PRINT(ptr_hook, buffer)
|
||||
|| ((struct t_gui_buffer *)buffer == HOOK_PRINT(ptr_hook, buffer)))
|
||||
&& (!HOOK_PRINT(ptr_hook, message)
|
||||
|| string_strcasestr (prefix_no_color, HOOK_PRINT(ptr_hook, message))
|
||||
|| string_strcasestr (message_no_color, HOOK_PRINT(ptr_hook, message))))
|
||||
{
|
||||
ptr_hook->running = 1;
|
||||
(void) (HOOK_PRINT(ptr_hook, callback))
|
||||
(ptr_hook->callback_data, buffer, date,
|
||||
(HOOK_PRINT(ptr_hook, strip_colors)) ? prefix_no_color : prefix,
|
||||
(HOOK_PRINT(ptr_hook, strip_colors)) ? message_no_color : message);
|
||||
if (hook_valid (ptr_hook))
|
||||
ptr_hook->running = 0;
|
||||
}
|
||||
|
||||
ptr_hook = next_hook;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* hook_event: hook an event
|
||||
*/
|
||||
|
||||
struct t_hook *
|
||||
hook_event (void *plugin, char *event,
|
||||
t_hook_callback_event *callback, void *callback_data)
|
||||
{
|
||||
struct t_hook *new_hook;
|
||||
struct t_hook_event *new_hook_event;
|
||||
|
||||
if (!event || !event[0])
|
||||
return NULL;
|
||||
|
||||
new_hook = (struct t_hook *)malloc (sizeof (struct t_hook));
|
||||
if (!new_hook)
|
||||
return NULL;
|
||||
new_hook_event = (struct t_hook_event *)malloc (sizeof (struct t_hook_event));
|
||||
if (!new_hook_event)
|
||||
{
|
||||
free (new_hook);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
hook_init (new_hook, plugin, HOOK_TYPE_EVENT, callback_data);
|
||||
|
||||
new_hook->hook_data = new_hook_event;
|
||||
new_hook_event->callback = callback;
|
||||
new_hook_event->event = strdup (event);
|
||||
|
||||
hook_add_to_list (new_hook);
|
||||
|
||||
return new_hook;
|
||||
}
|
||||
|
||||
/*
|
||||
* hook_event_exec: execute event hook
|
||||
*/
|
||||
|
||||
void
|
||||
hook_event_exec (char *event, void *pointer)
|
||||
{
|
||||
struct t_hook *ptr_hook, *next_hook;
|
||||
|
||||
ptr_hook = weechat_hooks;
|
||||
while (ptr_hook)
|
||||
{
|
||||
next_hook = ptr_hook->next_hook;
|
||||
|
||||
if ((ptr_hook->type == HOOK_TYPE_EVENT)
|
||||
&& (!ptr_hook->running)
|
||||
&& ((string_strcasecmp (HOOK_EVENT(ptr_hook, event), "*") == 0)
|
||||
|| (string_strcasecmp (HOOK_EVENT(ptr_hook, event), event) == 0)))
|
||||
{
|
||||
ptr_hook->running = 1;
|
||||
(void) (HOOK_EVENT(ptr_hook, callback))
|
||||
(ptr_hook->callback_data, event, pointer);
|
||||
if (hook_valid (ptr_hook))
|
||||
ptr_hook->running = 0;
|
||||
}
|
||||
|
||||
ptr_hook = next_hook;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* hook_config: hook a config option
|
||||
*/
|
||||
|
||||
struct t_hook *
|
||||
hook_config (void *plugin, char *type, char *option,
|
||||
t_hook_callback_config *callback, void *callback_data)
|
||||
{
|
||||
struct t_hook *new_hook;
|
||||
struct t_hook_config *new_hook_config;
|
||||
|
||||
new_hook = (struct t_hook *)malloc (sizeof (struct t_hook));
|
||||
if (!new_hook)
|
||||
return NULL;
|
||||
new_hook_config = (struct t_hook_config *)malloc (sizeof (struct t_hook_config));
|
||||
if (!new_hook_config)
|
||||
{
|
||||
free (new_hook);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
hook_init (new_hook, plugin, HOOK_TYPE_CONFIG, callback_data);
|
||||
|
||||
new_hook->hook_data = new_hook_config;
|
||||
new_hook_config->callback = callback;
|
||||
new_hook_config->type = (type) ? strdup (type) : strdup ("");
|
||||
new_hook_config->option = (option) ? strdup (option) : strdup ("");
|
||||
|
||||
hook_add_to_list (new_hook);
|
||||
|
||||
return new_hook;
|
||||
}
|
||||
|
||||
/*
|
||||
* hook_config_exec: execute config hooks
|
||||
*/
|
||||
|
||||
void
|
||||
hook_config_exec (char *type, char *option, char *value)
|
||||
{
|
||||
struct t_hook *ptr_hook, *next_hook;
|
||||
|
||||
ptr_hook = weechat_hooks;
|
||||
while (ptr_hook)
|
||||
{
|
||||
next_hook = ptr_hook->next_hook;
|
||||
|
||||
if ((ptr_hook->type == HOOK_TYPE_CONFIG)
|
||||
&& (!ptr_hook->running)
|
||||
&& (!HOOK_CONFIG(ptr_hook, type)
|
||||
|| (string_strcasecmp (HOOK_CONFIG(ptr_hook, type),
|
||||
type) == 0))
|
||||
&& (!HOOK_CONFIG(ptr_hook, option)
|
||||
|| (string_strcasecmp (HOOK_CONFIG(ptr_hook, option),
|
||||
option) == 0)))
|
||||
{
|
||||
ptr_hook->running = 1;
|
||||
(void) (HOOK_CONFIG(ptr_hook, callback))
|
||||
(ptr_hook->callback_data, type, option, value);
|
||||
if (hook_valid (ptr_hook))
|
||||
ptr_hook->running = 0;
|
||||
}
|
||||
|
||||
ptr_hook = next_hook;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* unhook: unhook something
|
||||
*/
|
||||
@@ -579,11 +662,22 @@ unhook (struct t_hook *hook)
|
||||
free (HOOK_COMMAND(hook, completion));
|
||||
free ((struct t_hook_command *)hook->hook_data);
|
||||
break;
|
||||
case HOOK_TYPE_TIMER:
|
||||
free ((struct t_hook_timer *)hook->hook_data);
|
||||
break;
|
||||
case HOOK_TYPE_FD:
|
||||
free ((struct t_hook_fd *)hook->hook_data);
|
||||
break;
|
||||
case HOOK_TYPE_PRINT:
|
||||
if (HOOK_PRINT(hook, message))
|
||||
free (HOOK_PRINT(hook, message));
|
||||
free ((struct t_hook_print *)hook->hook_data);
|
||||
break;
|
||||
case HOOK_TYPE_EVENT:
|
||||
if (HOOK_EVENT(hook, event))
|
||||
free (HOOK_EVENT(hook, event));
|
||||
free ((struct t_hook_event *)hook->hook_data);
|
||||
break;
|
||||
case HOOK_TYPE_CONFIG:
|
||||
if (HOOK_CONFIG(hook, type))
|
||||
free (HOOK_CONFIG(hook, type));
|
||||
@@ -591,14 +685,6 @@ unhook (struct t_hook *hook)
|
||||
free (HOOK_CONFIG(hook, option));
|
||||
free ((struct t_hook_config *)hook->hook_data);
|
||||
break;
|
||||
case HOOK_TYPE_TIMER:
|
||||
free ((struct t_hook_timer *)hook->hook_data);
|
||||
break;
|
||||
case HOOK_TYPE_FD:
|
||||
free ((struct t_hook_fd *)hook->hook_data);
|
||||
break;
|
||||
case HOOK_TYPE_KEYBOARD:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -681,16 +767,6 @@ hook_print_log ()
|
||||
weechat_log_printf (" command_args_desc. . : '%s'\n", HOOK_COMMAND(ptr_hook, args_description));
|
||||
weechat_log_printf (" command_completion . : '%s'\n", HOOK_COMMAND(ptr_hook, completion));
|
||||
break;
|
||||
case HOOK_TYPE_PRINT:
|
||||
weechat_log_printf (" print data:\n");
|
||||
weechat_log_printf (" buffer . . . . . . . : 0x%X\n", HOOK_PRINT(ptr_hook, buffer));
|
||||
weechat_log_printf (" message. . . . . . . : '%s'\n", HOOK_PRINT(ptr_hook, message));
|
||||
break;
|
||||
case HOOK_TYPE_CONFIG:
|
||||
weechat_log_printf (" config data:\n");
|
||||
weechat_log_printf (" type . . . . . . . . : '%s'\n", HOOK_CONFIG(ptr_hook, type));
|
||||
weechat_log_printf (" option . . . . . . . : '%s'\n", HOOK_CONFIG(ptr_hook, option));
|
||||
break;
|
||||
case HOOK_TYPE_TIMER:
|
||||
weechat_log_printf (" timer data:\n");
|
||||
weechat_log_printf (" interval . . . . . . : %ld\n", HOOK_TIMER(ptr_hook, interval));
|
||||
@@ -702,8 +778,19 @@ hook_print_log ()
|
||||
weechat_log_printf (" fd . . . . . . . . . : %ld\n", HOOK_FD(ptr_hook, fd));
|
||||
weechat_log_printf (" flags. . . . . . . . : %ld\n", HOOK_FD(ptr_hook, flags));
|
||||
break;
|
||||
case HOOK_TYPE_KEYBOARD:
|
||||
weechat_log_printf (" keyboard data:\n");
|
||||
case HOOK_TYPE_PRINT:
|
||||
weechat_log_printf (" print data:\n");
|
||||
weechat_log_printf (" buffer . . . . . . . : 0x%X\n", HOOK_PRINT(ptr_hook, buffer));
|
||||
weechat_log_printf (" message. . . . . . . : '%s'\n", HOOK_PRINT(ptr_hook, message));
|
||||
break;
|
||||
case HOOK_TYPE_EVENT:
|
||||
weechat_log_printf (" event data:\n");
|
||||
weechat_log_printf (" event. . . . . . . . : '%s'\n", HOOK_EVENT(ptr_hook, event));
|
||||
break;
|
||||
case HOOK_TYPE_CONFIG:
|
||||
weechat_log_printf (" config data:\n");
|
||||
weechat_log_printf (" type . . . . . . . . : '%s'\n", HOOK_CONFIG(ptr_hook, type));
|
||||
weechat_log_printf (" option . . . . . . . : '%s'\n", HOOK_CONFIG(ptr_hook, option));
|
||||
break;
|
||||
}
|
||||
weechat_log_printf (" running. . . . . . . . : %d\n", ptr_hook->running);
|
||||
|
||||
+45
-30
@@ -25,11 +25,11 @@
|
||||
enum t_hook_type
|
||||
{
|
||||
HOOK_TYPE_COMMAND = 0, /* new command */
|
||||
HOOK_TYPE_PRINT, /* printed messages */
|
||||
HOOK_TYPE_CONFIG, /* config option */
|
||||
HOOK_TYPE_TIMER, /* timer */
|
||||
HOOK_TYPE_FD, /* socket of file descriptor */
|
||||
HOOK_TYPE_KEYBOARD, /* keyboard handler */
|
||||
HOOK_TYPE_PRINT, /* printed message */
|
||||
HOOK_TYPE_EVENT, /* event */
|
||||
HOOK_TYPE_CONFIG, /* config option */
|
||||
};
|
||||
|
||||
#define HOOK_FD_FLAG_READ 1
|
||||
@@ -37,10 +37,11 @@ enum t_hook_type
|
||||
#define HOOK_FD_FLAG_EXCEPTION 4
|
||||
|
||||
#define HOOK_COMMAND(hook, var) (((struct t_hook_command *)hook->hook_data)->var)
|
||||
#define HOOK_PRINT(hook, var) (((struct t_hook_print *)hook->hook_data)->var)
|
||||
#define HOOK_CONFIG(hook, var) (((struct t_hook_config *)hook->hook_data)->var)
|
||||
#define HOOK_TIMER(hook, var) (((struct t_hook_timer *)hook->hook_data)->var)
|
||||
#define HOOK_FD(hook, var) (((struct t_hook_fd *)hook->hook_data)->var)
|
||||
#define HOOK_PRINT(hook, var) (((struct t_hook_print *)hook->hook_data)->var)
|
||||
#define HOOK_EVENT(hook, var) (((struct t_hook_event *)hook->hook_data)->var)
|
||||
#define HOOK_CONFIG(hook, var) (((struct t_hook_config *)hook->hook_data)->var)
|
||||
|
||||
struct t_hook
|
||||
{
|
||||
@@ -70,25 +71,6 @@ struct t_hook_command
|
||||
char *completion; /* template for completion */
|
||||
};
|
||||
|
||||
typedef int (t_hook_callback_print)(void *, void *, time_t, char *, char *);
|
||||
|
||||
struct t_hook_print
|
||||
{
|
||||
t_hook_callback_print *callback; /* print callback */
|
||||
struct t_gui_buffer *buffer; /* buffer selected (NULL = all) */
|
||||
char *message; /* part of message (NULL/empty = all)*/
|
||||
};
|
||||
|
||||
typedef int (t_hook_callback_config)(void *, char *, char *, char *);
|
||||
|
||||
struct t_hook_config
|
||||
{
|
||||
t_hook_callback_config *callback; /* config callback */
|
||||
char *type; /* "weechat" or "plugin" */
|
||||
char *option; /* config option for hook */
|
||||
/* (NULL = hook for all options) */
|
||||
};
|
||||
|
||||
typedef int (t_hook_callback_timer)(void *);
|
||||
|
||||
struct t_hook_timer
|
||||
@@ -108,6 +90,34 @@ struct t_hook_fd
|
||||
int flags; /* fd flags (read,write,..) */
|
||||
};
|
||||
|
||||
typedef int (t_hook_callback_print)(void *, void *, time_t, char *, char *);
|
||||
|
||||
struct t_hook_print
|
||||
{
|
||||
t_hook_callback_print *callback; /* print callback */
|
||||
struct t_gui_buffer *buffer; /* buffer selected (NULL = all) */
|
||||
char *message; /* part of message (NULL/empty = all)*/
|
||||
int strip_colors; /* strip colors in msg for callback? */
|
||||
};
|
||||
|
||||
typedef int (t_hook_callback_event)(void *, char *, void *);
|
||||
|
||||
struct t_hook_event
|
||||
{
|
||||
t_hook_callback_event *callback; /* event callback */
|
||||
char *event; /* event selected ("*" = any event) */
|
||||
};
|
||||
|
||||
typedef int (t_hook_callback_config)(void *, char *, char *, char *);
|
||||
|
||||
struct t_hook_config
|
||||
{
|
||||
t_hook_callback_config *callback; /* config callback */
|
||||
char *type; /* "weechat" or "plugin" */
|
||||
char *option; /* config option for hook */
|
||||
/* (NULL = hook for all options) */
|
||||
};
|
||||
|
||||
/* hook variables */
|
||||
|
||||
extern struct t_hook *weechat_hooks;
|
||||
@@ -117,21 +127,26 @@ extern struct t_hook *last_weechat_hook;
|
||||
|
||||
extern int hook_valid (struct t_hook *);
|
||||
extern int hook_valid_for_plugin (void *, struct t_hook *);
|
||||
|
||||
extern struct t_hook *hook_command (void *, char *, char *, char *, char *,
|
||||
char *, t_hook_callback_command *, void *);
|
||||
extern int hook_command_exec (void *, char *);
|
||||
extern struct t_hook *hook_print (void *, void *, char *,
|
||||
t_hook_callback_print *, void *);
|
||||
extern void hook_print_exec (void *, time_t, char *, char *);
|
||||
extern struct t_hook *hook_config (void *, char *, char *,
|
||||
t_hook_callback_config *, void *);
|
||||
extern void hook_config_exec (char *, char *, char *);
|
||||
extern struct t_hook *hook_timer (void *, long, int, t_hook_callback_timer *,
|
||||
void *);
|
||||
extern void hook_timer_exec (struct timeval *);
|
||||
extern struct t_hook *hook_fd (void *, int, int, t_hook_callback_fd *,void *);
|
||||
extern void hook_fd_set (fd_set *, fd_set *, fd_set *);
|
||||
extern void hook_fd_exec (fd_set *, fd_set *, fd_set *);
|
||||
extern struct t_hook *hook_print (void *, void *, char *, int,
|
||||
t_hook_callback_print *, void *);
|
||||
extern void hook_print_exec (void *, time_t, char *, char *);
|
||||
extern struct t_hook *hook_event (void *, char *,
|
||||
t_hook_callback_event *, void *);
|
||||
extern void hook_event_exec (char *, void *);
|
||||
extern struct t_hook *hook_config (void *, char *, char *,
|
||||
t_hook_callback_config *, void *);
|
||||
extern void hook_config_exec (char *, char *, char *);
|
||||
|
||||
extern void unhook (struct t_hook *);
|
||||
extern void unhook_all_plugin (void *);
|
||||
extern void unhook_all ();
|
||||
|
||||
Reference in New Issue
Block a user