summaryrefslogtreecommitdiff
path: root/src/core/wee-hook.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/wee-hook.c')
-rw-r--r--src/core/wee-hook.c361
1 files changed, 269 insertions, 92 deletions
diff --git a/src/core/wee-hook.c b/src/core/wee-hook.c
index c0c195eef..40396facc 100644
--- a/src/core/wee-hook.c
+++ b/src/core/wee-hook.c
@@ -1,7 +1,7 @@
/*
* wee-hook.c - WeeChat hooks management
*
- * Copyright (C) 2003-2015 Sébastien Helleu <flashcode@flashtux.org>
+ * Copyright (C) 2003-2016 Sébastien Helleu <flashcode@flashtux.org>
* Copyright (C) 2012 Simon Arlott
*
* This file is part of WeeChat, the extensible chat client.
@@ -76,6 +76,8 @@ int real_delete_pending = 0; /* 1 if some hooks must be deleted */
struct pollfd *hook_fd_pollfd = NULL; /* file descriptors for poll() */
int hook_fd_pollfd_count = 0; /* number of file descriptors */
+int hook_process_pending = 0; /* 1 if there are some process to */
+ /* run (via fork) */
void hook_process_run (struct t_hook *hook_process);
@@ -364,7 +366,8 @@ hook_get_priority_and_name (const char *string,
void
hook_init_data (struct t_hook *hook, struct t_weechat_plugin *plugin,
- int type, int priority, void *callback_data)
+ int type, int priority,
+ const void *callback_pointer, void *callback_data)
{
hook->plugin = plugin;
hook->subplugin = NULL;
@@ -372,16 +375,18 @@ hook_init_data (struct t_hook *hook, struct t_weechat_plugin *plugin,
hook->deleted = 0;
hook->running = 0;
hook->priority = priority;
+ hook->callback_pointer = callback_pointer;
hook->callback_data = callback_data;
hook->hook_data = NULL;
if (weechat_debug_core >= 2)
{
gui_chat_printf (NULL,
- "debug: adding hook: type=%d (%s), plugin=%lx (%s), "
+ "debug: adding hook: type=%d (%s), plugin=\"%s\", "
"priority=%d",
- hook->type, hook_type_string[hook->type],
- hook->plugin, plugin_get_name (hook->plugin),
+ hook->type,
+ hook_type_string[hook->type],
+ plugin_get_name (hook->plugin),
hook->priority);
}
}
@@ -647,7 +652,9 @@ hook_command (struct t_weechat_plugin *plugin, const char *command,
const char *description,
const char *args, const char *args_description,
const char *completion,
- t_hook_callback_command *callback, void *callback_data)
+ t_hook_callback_command *callback,
+ const void *callback_pointer,
+ void *callback_data)
{
struct t_hook *new_hook;
struct t_hook_command *new_hook_command;
@@ -680,7 +687,7 @@ hook_command (struct t_weechat_plugin *plugin, const char *command,
hook_get_priority_and_name (command, &priority, &ptr_command);
hook_init_data (new_hook, plugin, HOOK_TYPE_COMMAND, priority,
- callback_data);
+ callback_pointer, callback_data);
new_hook->hook_data = new_hook_command;
new_hook_command->callback = callback;
@@ -858,7 +865,12 @@ hook_command_exec (struct t_gui_buffer *buffer, int any_plugin,
/* execute the command! */
ptr_hook->running++;
rc = (int) (HOOK_COMMAND(ptr_hook, callback))
- (ptr_hook->callback_data, buffer, argc, argv, argv_eol);
+ (ptr_hook->callback_pointer,
+ ptr_hook->callback_data,
+ buffer,
+ argc,
+ argv,
+ argv_eol);
ptr_hook->running--;
if (rc == WEECHAT_RC_ERROR)
rc = HOOK_COMMAND_EXEC_ERROR;
@@ -882,8 +894,11 @@ hook_command_exec (struct t_gui_buffer *buffer, int any_plugin,
*/
struct t_hook *
-hook_command_run (struct t_weechat_plugin *plugin, const char *command,
- t_hook_callback_command_run *callback, void *callback_data)
+hook_command_run (struct t_weechat_plugin *plugin,
+ const char *command,
+ t_hook_callback_command_run *callback,
+ const void *callback_pointer,
+ void *callback_data)
{
struct t_hook *new_hook;
struct t_hook_command_run *new_hook_command_run;
@@ -905,7 +920,7 @@ hook_command_run (struct t_weechat_plugin *plugin, const char *command,
hook_get_priority_and_name (command, &priority, &ptr_command);
hook_init_data (new_hook, plugin, HOOK_TYPE_COMMAND_RUN, priority,
- callback_data);
+ callback_pointer, callback_data);
new_hook->hook_data = new_hook_command_run;
new_hook_command_run->callback = callback;
@@ -967,9 +982,11 @@ hook_command_run_exec (struct t_gui_buffer *buffer, const char *command)
if (hook_matching)
{
ptr_hook->running = 1;
- rc = (HOOK_COMMAND_RUN(ptr_hook, callback)) (ptr_hook->callback_data,
- buffer,
- ptr_command);
+ rc = (HOOK_COMMAND_RUN(ptr_hook, callback)) (
+ ptr_hook->callback_pointer,
+ ptr_hook->callback_data,
+ buffer,
+ ptr_command);
ptr_hook->running = 0;
if (rc == WEECHAT_RC_OK_EAT)
{
@@ -1054,6 +1071,7 @@ hook_timer_init (struct t_hook *hook)
struct t_hook *
hook_timer (struct t_weechat_plugin *plugin, long interval, int align_second,
int max_calls, t_hook_callback_timer *callback,
+ const void *callback_pointer,
void *callback_data)
{
struct t_hook *new_hook;
@@ -1073,7 +1091,7 @@ hook_timer (struct t_weechat_plugin *plugin, long interval, int align_second,
}
hook_init_data (new_hook, plugin, HOOK_TYPE_TIMER, HOOK_PRIORITY_DEFAULT,
- callback_data);
+ callback_pointer, callback_data);
new_hook->hook_data = new_hook_timer;
new_hook_timer->callback = callback;
@@ -1236,7 +1254,8 @@ hook_timer_exec ()
{
ptr_hook->running = 1;
(void) (HOOK_TIMER(ptr_hook, callback))
- (ptr_hook->callback_data,
+ (ptr_hook->callback_pointer,
+ ptr_hook->callback_data,
(HOOK_TIMER(ptr_hook, remaining_calls) > 0) ?
HOOK_TIMER(ptr_hook, remaining_calls) - 1 : -1);
ptr_hook->running = 0;
@@ -1295,7 +1314,9 @@ hook_search_fd (int fd)
struct t_hook *
hook_fd (struct t_weechat_plugin *plugin, int fd, int flag_read,
int flag_write, int flag_exception,
- t_hook_callback_fd *callback, void *callback_data)
+ t_hook_callback_fd *callback,
+ const void *callback_pointer,
+ void *callback_data)
{
struct t_hook *new_hook;
struct t_hook_fd *new_hook_fd;
@@ -1314,7 +1335,7 @@ hook_fd (struct t_weechat_plugin *plugin, int fd, int flag_read,
}
hook_init_data (new_hook, plugin, HOOK_TYPE_FD, HOOK_PRIORITY_DEFAULT,
- callback_data);
+ callback_pointer, callback_data);
new_hook->hook_data = new_hook_fd;
new_hook_fd->callback = callback;
@@ -1386,6 +1407,8 @@ hook_fd_exec ()
/* perform the poll() */
timeout = hook_timer_get_time_to_next ();
+ if (hook_process_pending)
+ timeout = 0;
ready = poll (hook_fd_pollfd, num_fd, timeout);
if (ready <= 0)
return;
@@ -1414,8 +1437,10 @@ hook_fd_exec ()
if (found)
{
ptr_hook->running = 1;
- (void) (HOOK_FD(ptr_hook, callback)) (ptr_hook->callback_data,
- HOOK_FD(ptr_hook, fd));
+ (void) (HOOK_FD(ptr_hook, callback)) (
+ ptr_hook->callback_pointer,
+ ptr_hook->callback_data,
+ HOOK_FD(ptr_hook, fd));
ptr_hook->running = 0;
}
}
@@ -1434,9 +1459,12 @@ hook_fd_exec ()
struct t_hook *
hook_process_hashtable (struct t_weechat_plugin *plugin,
- const char *command, struct t_hashtable *options,
+ const char *command,
+ struct t_hashtable *options,
int timeout,
- t_hook_callback_process *callback, void *callback_data)
+ t_hook_callback_process *callback,
+ const void *callback_pointer,
+ void *callback_data)
{
struct t_hook *new_hook;
struct t_hook_process *new_hook_process;
@@ -1469,7 +1497,7 @@ hook_process_hashtable (struct t_weechat_plugin *plugin,
goto error;
hook_init_data (new_hook, plugin, HOOK_TYPE_PROCESS, HOOK_PRIORITY_DEFAULT,
- callback_data);
+ callback_pointer, callback_data);
new_hook->hook_data = new_hook_process;
new_hook_process->callback = callback;
@@ -1523,7 +1551,10 @@ hook_process_hashtable (struct t_weechat_plugin *plugin,
new_hook_process->timeout);
}
- hook_process_run (new_hook);
+ if (strncmp (new_hook_process->command, "func:", 5) == 0)
+ hook_process_pending = 1;
+ else
+ hook_process_run (new_hook);
return new_hook;
@@ -1547,11 +1578,14 @@ error:
struct t_hook *
hook_process (struct t_weechat_plugin *plugin,
- const char *command, int timeout,
- t_hook_callback_process *callback, void *callback_data)
+ const char *command,
+ int timeout,
+ t_hook_callback_process *callback,
+ const void *callback_pointer,
+ void *callback_data)
{
return hook_process_hashtable (plugin, command, NULL, timeout,
- callback, callback_data);
+ callback, callback_pointer, callback_data);
}
/*
@@ -1629,6 +1663,16 @@ hook_process_child (struct t_hook *hook_process)
}
rc = weeurl_download (ptr_url, HOOK_PROCESS(hook_process, options));
}
+ else if (strncmp (HOOK_PROCESS(hook_process, command), "func:", 5) == 0)
+ {
+ /* run a function (via the hook callback) */
+ rc = (int) (HOOK_PROCESS(hook_process, callback))
+ (hook_process->callback_pointer,
+ hook_process->callback_data,
+ HOOK_PROCESS(hook_process, command),
+ WEECHAT_HOOK_PROCESS_CHILD,
+ NULL, NULL);
+ }
else
{
/* launch command */
@@ -1732,7 +1776,8 @@ hook_process_send_buffers (struct t_hook *hook_process, int callback_rc)
/* send buffers to callback */
(void) (HOOK_PROCESS(hook_process, callback))
- (hook_process->callback_data,
+ (hook_process->callback_pointer,
+ hook_process->callback_data,
HOOK_PROCESS(hook_process, command),
callback_rc,
(HOOK_PROCESS(hook_process, buffer_size[HOOK_PROCESS_STDOUT]) > 0) ?
@@ -1800,11 +1845,15 @@ hook_process_child_read (struct t_hook *hook_process, int fd,
*/
int
-hook_process_child_read_stdout_cb (void *arg_hook_process, int fd)
+hook_process_child_read_stdout_cb (const void *pointer, void *data, int fd)
{
struct t_hook *hook_process;
- hook_process = (struct t_hook *)arg_hook_process;
+ /* make C compiler happy */
+ (void) data;
+
+ hook_process = (struct t_hook *)pointer;
+
hook_process_child_read (hook_process, fd, HOOK_PROCESS_STDOUT,
&(HOOK_PROCESS(hook_process, hook_fd[HOOK_PROCESS_STDOUT])));
return WEECHAT_RC_OK;
@@ -1815,11 +1864,15 @@ hook_process_child_read_stdout_cb (void *arg_hook_process, int fd)
*/
int
-hook_process_child_read_stderr_cb (void *arg_hook_process, int fd)
+hook_process_child_read_stderr_cb (const void *pointer, void *data, int fd)
{
struct t_hook *hook_process;
- hook_process = (struct t_hook *)arg_hook_process;
+ /* make C compiler happy */
+ (void) data;
+
+ hook_process = (struct t_hook *)pointer;
+
hook_process_child_read (hook_process, fd, HOOK_PROCESS_STDERR,
&(HOOK_PROCESS(hook_process, hook_fd[HOOK_PROCESS_STDERR])));
return WEECHAT_RC_OK;
@@ -1882,6 +1935,7 @@ hook_process_child_read_until_eof (struct t_hook *hook_process)
{
(void) hook_process_child_read_stdout_cb (
hook_process,
+ NULL,
HOOK_PROCESS(hook_process,
child_read[HOOK_PROCESS_STDOUT]));
}
@@ -1889,6 +1943,7 @@ hook_process_child_read_until_eof (struct t_hook *hook_process)
{
(void) hook_process_child_read_stderr_cb (
hook_process,
+ NULL,
HOOK_PROCESS(hook_process,
child_read[HOOK_PROCESS_STDERR]));
}
@@ -1904,15 +1959,16 @@ hook_process_child_read_until_eof (struct t_hook *hook_process)
*/
int
-hook_process_timer_cb (void *arg_hook_process, int remaining_calls)
+hook_process_timer_cb (const void *pointer, void *data, int remaining_calls)
{
struct t_hook *hook_process;
int status, rc;
/* make C compiler happy */
+ (void) data;
(void) remaining_calls;
- hook_process = (struct t_hook *)arg_hook_process;
+ hook_process = (struct t_hook *)pointer;
if (hook_process->deleted)
return WEECHAT_RC_OK;
@@ -2006,7 +2062,8 @@ hook_process_run (struct t_hook *hook_process)
/* fork failed */
case -1:
(void) (HOOK_PROCESS(hook_process, callback))
- (hook_process->callback_data,
+ (hook_process->callback_pointer,
+ hook_process->callback_data,
HOOK_PROCESS(hook_process, command),
WEECHAT_HOOK_PROCESS_ERROR,
NULL, NULL);
@@ -2047,7 +2104,7 @@ hook_process_run (struct t_hook *hook_process)
HOOK_PROCESS(hook_process, child_read[HOOK_PROCESS_STDOUT]),
1, 0, 0,
&hook_process_child_read_stdout_cb,
- hook_process);
+ hook_process, NULL);
}
if (HOOK_PROCESS(hook_process, child_read[HOOK_PROCESS_STDERR]) >= 0)
@@ -2057,7 +2114,7 @@ hook_process_run (struct t_hook *hook_process)
HOOK_PROCESS(hook_process, child_read[HOOK_PROCESS_STDERR]),
1, 0, 0,
&hook_process_child_read_stderr_cb,
- hook_process);
+ hook_process, NULL);
}
timeout = HOOK_PROCESS(hook_process, timeout);
@@ -2081,7 +2138,8 @@ hook_process_run (struct t_hook *hook_process)
HOOK_PROCESS(hook_process, hook_timer) = hook_timer (hook_process->plugin,
interval, 0, max_calls,
&hook_process_timer_cb,
- hook_process);
+ hook_process,
+ NULL);
return;
error:
@@ -2093,7 +2151,8 @@ error:
close (pipes[i][1]);
}
(void) (HOOK_PROCESS(hook_process, callback))
- (hook_process->callback_data,
+ (hook_process->callback_pointer,
+ hook_process->callback_data,
HOOK_PROCESS(hook_process, command),
WEECHAT_HOOK_PROCESS_ERROR,
NULL, NULL);
@@ -2101,6 +2160,39 @@ error:
}
/*
+ * Executes all process commands pending.
+ */
+
+void
+hook_process_exec ()
+{
+ struct t_hook *ptr_hook, *next_hook;
+
+ hook_exec_start ();
+
+ ptr_hook = weechat_hooks[HOOK_TYPE_PROCESS];
+ while (ptr_hook)
+ {
+ next_hook = ptr_hook->next_hook;
+
+ if (!ptr_hook->deleted
+ && !ptr_hook->running
+ && (HOOK_PROCESS(ptr_hook, child_pid) == 0))
+ {
+ ptr_hook->running = 1;
+ hook_process_run (ptr_hook);
+ ptr_hook->running = 0;
+ }
+
+ ptr_hook = next_hook;
+ }
+
+ hook_exec_end ();
+
+ hook_process_pending = 0;
+}
+
+/*
* Hooks a connection to a peer (using fork).
*
* Returns pointer to new hook, NULL if error.
@@ -2111,7 +2203,9 @@ hook_connect (struct t_weechat_plugin *plugin, const char *proxy,
const char *address, int port, int ipv6, int retry,
void *gnutls_sess, void *gnutls_cb, int gnutls_dhkey_size,
const char *gnutls_priorities, const char *local_hostname,
- t_hook_callback_connect *callback, void *callback_data)
+ t_hook_callback_connect *callback,
+ const void *callback_pointer,
+ void *callback_data)
{
struct t_hook *new_hook;
struct t_hook_connect *new_hook_connect;
@@ -2141,7 +2235,7 @@ hook_connect (struct t_weechat_plugin *plugin, const char *proxy,
}
hook_init_data (new_hook, plugin, HOOK_TYPE_CONNECT, HOOK_PRIORITY_DEFAULT,
- callback_data);
+ callback_pointer, callback_data);
new_hook->hook_data = new_hook_connect;
new_hook_connect->callback = callback;
@@ -2207,7 +2301,9 @@ hook_connect_gnutls_verify_certificates (gnutls_session_t tls_session)
&& (*(HOOK_CONNECT(ptr_hook, gnutls_sess)) == tls_session))
{
rc = (int) (HOOK_CONNECT(ptr_hook, gnutls_cb))
- (ptr_hook->callback_data, tls_session, NULL, 0,
+ (ptr_hook->callback_pointer,
+ ptr_hook->callback_data,
+ tls_session, NULL, 0,
NULL, 0, NULL,
WEECHAT_HOOK_CONNECT_GNUTLS_CB_VERIFY_CERT);
break;
@@ -2248,7 +2344,9 @@ hook_connect_gnutls_set_certificates (gnutls_session_t tls_session,
&& (*(HOOK_CONNECT(ptr_hook, gnutls_sess)) == tls_session))
{
rc = (int) (HOOK_CONNECT(ptr_hook, gnutls_cb))
- (ptr_hook->callback_data, tls_session, req_ca, nreq,
+ (ptr_hook->callback_pointer,
+ ptr_hook->callback_data,
+ tls_session, req_ca, nreq,
pk_algos, pk_algos_len, answer,
WEECHAT_HOOK_CONNECT_GNUTLS_CB_SET_CERT);
break;
@@ -2269,7 +2367,9 @@ hook_connect_gnutls_set_certificates (gnutls_session_t tls_session,
struct t_hook *
hook_print (struct t_weechat_plugin *plugin, struct t_gui_buffer *buffer,
const char *tags, const char *message, int strip_colors,
- t_hook_callback_print *callback, void *callback_data)
+ t_hook_callback_print *callback,
+ const void *callback_pointer,
+ void *callback_data)
{
struct t_hook *new_hook;
struct t_hook_print *new_hook_print;
@@ -2290,7 +2390,7 @@ hook_print (struct t_weechat_plugin *plugin, struct t_gui_buffer *buffer,
}
hook_init_data (new_hook, plugin, HOOK_TYPE_PRINT, HOOK_PRIORITY_DEFAULT,
- callback_data);
+ callback_pointer, callback_data);
new_hook->hook_data = new_hook_print;
new_hook_print->callback = callback;
@@ -2374,7 +2474,8 @@ hook_print_exec (struct t_gui_buffer *buffer, struct t_gui_line *line)
/* run callback */
ptr_hook->running = 1;
(void) (HOOK_PRINT(ptr_hook, callback))
- (ptr_hook->callback_data, buffer, line->data->date,
+ (ptr_hook->callback_pointer,
+ ptr_hook->callback_data, buffer, line->data->date,
line->data->tags_count,
(const char **)line->data->tags_array,
(int)line->data->displayed, (int)line->data->highlight,
@@ -2403,7 +2504,9 @@ hook_print_exec (struct t_gui_buffer *buffer, struct t_gui_line *line)
struct t_hook *
hook_signal (struct t_weechat_plugin *plugin, const char *signal,
- t_hook_callback_signal *callback, void *callback_data)
+ t_hook_callback_signal *callback,
+ const void *callback_pointer,
+ void *callback_data)
{
struct t_hook *new_hook;
struct t_hook_signal *new_hook_signal;
@@ -2425,7 +2528,7 @@ hook_signal (struct t_weechat_plugin *plugin, const char *signal,
hook_get_priority_and_name (signal, &priority, &ptr_signal);
hook_init_data (new_hook, plugin, HOOK_TYPE_SIGNAL, priority,
- callback_data);
+ callback_pointer, callback_data);
new_hook->hook_data = new_hook_signal;
new_hook_signal->callback = callback;
@@ -2461,7 +2564,11 @@ hook_signal_send (const char *signal, const char *type_data, void *signal_data)
{
ptr_hook->running = 1;
rc = (HOOK_SIGNAL(ptr_hook, callback))
- (ptr_hook->callback_data, signal, type_data, signal_data);
+ (ptr_hook->callback_pointer,
+ ptr_hook->callback_data,
+ signal,
+ type_data,
+ signal_data);
ptr_hook->running = 0;
if (rc == WEECHAT_RC_OK_EAT)
@@ -2484,7 +2591,9 @@ hook_signal_send (const char *signal, const char *type_data, void *signal_data)
struct t_hook *
hook_hsignal (struct t_weechat_plugin *plugin, const char *signal,
- t_hook_callback_hsignal *callback, void *callback_data)
+ t_hook_callback_hsignal *callback,
+ const void *callback_pointer,
+ void *callback_data)
{
struct t_hook *new_hook;
struct t_hook_hsignal *new_hook_hsignal;
@@ -2506,7 +2615,7 @@ hook_hsignal (struct t_weechat_plugin *plugin, const char *signal,
hook_get_priority_and_name (signal, &priority, &ptr_signal);
hook_init_data (new_hook, plugin, HOOK_TYPE_HSIGNAL, priority,
- callback_data);
+ callback_pointer, callback_data);
new_hook->hook_data = new_hook_hsignal;
new_hook_hsignal->callback = callback;
@@ -2542,7 +2651,10 @@ hook_hsignal_send (const char *signal, struct t_hashtable *hashtable)
{
ptr_hook->running = 1;
rc = (HOOK_HSIGNAL(ptr_hook, callback))
- (ptr_hook->callback_data, signal, hashtable);
+ (ptr_hook->callback_pointer,
+ ptr_hook->callback_data,
+ signal,
+ hashtable);
ptr_hook->running = 0;
if (rc == WEECHAT_RC_OK_EAT)
@@ -2565,7 +2677,9 @@ hook_hsignal_send (const char *signal, struct t_hashtable *hashtable)
struct t_hook *
hook_config (struct t_weechat_plugin *plugin, const char *option,
- t_hook_callback_config *callback, void *callback_data)
+ t_hook_callback_config *callback,
+ const void *callback_pointer,
+ void *callback_data)
{
struct t_hook *new_hook;
struct t_hook_config *new_hook_config;
@@ -2587,7 +2701,7 @@ hook_config (struct t_weechat_plugin *plugin, const char *option,
hook_get_priority_and_name (option, &priority, &ptr_option);
hook_init_data (new_hook, plugin, HOOK_TYPE_CONFIG, priority,
- callback_data);
+ callback_pointer, callback_data);
new_hook->hook_data = new_hook_config;
new_hook_config->callback = callback;
@@ -2622,7 +2736,10 @@ hook_config_exec (const char *option, const char *value)
{
ptr_hook->running = 1;
(void) (HOOK_CONFIG(ptr_hook, callback))
- (ptr_hook->callback_data, option, value);
+ (ptr_hook->callback_pointer,
+ ptr_hook->callback_data,
+ option,
+ value);
ptr_hook->running = 0;
}
@@ -2641,7 +2758,9 @@ hook_config_exec (const char *option, const char *value)
struct t_hook *
hook_completion (struct t_weechat_plugin *plugin, const char *completion_item,
const char *description,
- t_hook_callback_completion *callback, void *callback_data)
+ t_hook_callback_completion *callback,
+ const void *callback_pointer,
+ void *callback_data)
{
struct t_hook *new_hook;
struct t_hook_completion *new_hook_completion;
@@ -2664,7 +2783,7 @@ hook_completion (struct t_weechat_plugin *plugin, const char *completion_item,
hook_get_priority_and_name (completion_item, &priority, &ptr_completion_item);
hook_init_data (new_hook, plugin, HOOK_TYPE_COMPLETION, priority,
- callback_data);
+ callback_pointer, callback_data);
new_hook->hook_data = new_hook_completion;
new_hook_completion->callback = callback;
@@ -2730,7 +2849,11 @@ hook_completion_exec (struct t_weechat_plugin *plugin,
{
ptr_hook->running = 1;
(void) (HOOK_COMPLETION(ptr_hook, callback))
- (ptr_hook->callback_data, completion_item, buffer, completion);
+ (ptr_hook->callback_pointer,
+ ptr_hook->callback_data,
+ completion_item,
+ buffer,
+ completion);
ptr_hook->running = 0;
}
@@ -2748,7 +2871,9 @@ hook_completion_exec (struct t_weechat_plugin *plugin,
struct t_hook *
hook_modifier (struct t_weechat_plugin *plugin, const char *modifier,
- t_hook_callback_modifier *callback, void *callback_data)
+ t_hook_callback_modifier *callback,
+ const void *callback_pointer,
+ void *callback_data)
{
struct t_hook *new_hook;
struct t_hook_modifier *new_hook_modifier;
@@ -2770,7 +2895,7 @@ hook_modifier (struct t_weechat_plugin *plugin, const char *modifier,
hook_get_priority_and_name (modifier, &priority, &ptr_modifier);
hook_init_data (new_hook, plugin, HOOK_TYPE_MODIFIER, priority,
- callback_data);
+ callback_pointer, callback_data);
new_hook->hook_data = new_hook_modifier;
new_hook_modifier->callback = callback;
@@ -2819,7 +2944,10 @@ hook_modifier_exec (struct t_weechat_plugin *plugin, const char *modifier,
{
ptr_hook->running = 1;
new_msg = (HOOK_MODIFIER(ptr_hook, callback))
- (ptr_hook->callback_data, modifier, modifier_data,
+ (ptr_hook->callback_pointer,
+ ptr_hook->callback_data,
+ modifier,
+ modifier_data,
message_modified);
ptr_hook->running = 0;
@@ -2856,7 +2984,9 @@ hook_modifier_exec (struct t_weechat_plugin *plugin, const char *modifier,
struct t_hook *
hook_info (struct t_weechat_plugin *plugin, const char *info_name,
const char *description, const char *args_description,
- t_hook_callback_info *callback, void *callback_data)
+ t_hook_callback_info *callback,
+ const void *callback_pointer,
+ void *callback_data)
{
struct t_hook *new_hook;
struct t_hook_info *new_hook_info;
@@ -2877,7 +3007,8 @@ hook_info (struct t_weechat_plugin *plugin, const char *info_name,
}
hook_get_priority_and_name (info_name, &priority, &ptr_info_name);
- hook_init_data (new_hook, plugin, HOOK_TYPE_INFO, priority, callback_data);
+ hook_init_data (new_hook, plugin, HOOK_TYPE_INFO, priority,
+ callback_pointer, callback_data);
new_hook->hook_data = new_hook_info;
new_hook_info->callback = callback;
@@ -2923,7 +3054,10 @@ hook_info_get (struct t_weechat_plugin *plugin, const char *info_name,
{
ptr_hook->running = 1;
value = (HOOK_INFO(ptr_hook, callback))
- (ptr_hook->callback_data, info_name, arguments);
+ (ptr_hook->callback_pointer,
+ ptr_hook->callback_data,
+ info_name,
+ arguments);
ptr_hook->running = 0;
hook_exec_end ();
@@ -2950,6 +3084,7 @@ hook_info_hashtable (struct t_weechat_plugin *plugin, const char *info_name,
const char *description, const char *args_description,
const char *output_description,
t_hook_callback_info_hashtable *callback,
+ const void *callback_pointer,
void *callback_data)
{
struct t_hook *new_hook;
@@ -2972,7 +3107,7 @@ hook_info_hashtable (struct t_weechat_plugin *plugin, const char *info_name,
hook_get_priority_and_name (info_name, &priority, &ptr_info_name);
hook_init_data (new_hook, plugin, HOOK_TYPE_INFO_HASHTABLE, priority,
- callback_data);
+ callback_pointer, callback_data);
new_hook->hook_data = new_hook_info_hashtable;
new_hook_info_hashtable->callback = callback;
@@ -3020,7 +3155,10 @@ hook_info_get_hashtable (struct t_weechat_plugin *plugin, const char *info_name,
{
ptr_hook->running = 1;
value = (HOOK_INFO_HASHTABLE(ptr_hook, callback))
- (ptr_hook->callback_data, info_name, hashtable);
+ (ptr_hook->callback_pointer,
+ ptr_hook->callback_data,
+ info_name,
+ hashtable);
ptr_hook->running = 0;
hook_exec_end ();
@@ -3046,7 +3184,9 @@ struct t_hook *
hook_infolist (struct t_weechat_plugin *plugin, const char *infolist_name,
const char *description, const char *pointer_description,
const char *args_description,
- t_hook_callback_infolist *callback, void *callback_data)
+ t_hook_callback_infolist *callback,
+ const void *callback_pointer,
+ void *callback_data)
{
struct t_hook *new_hook;
struct t_hook_infolist *new_hook_infolist;
@@ -3068,7 +3208,7 @@ hook_infolist (struct t_weechat_plugin *plugin, const char *infolist_name,
hook_get_priority_and_name (infolist_name, &priority, &ptr_infolist_name);
hook_init_data (new_hook, plugin, HOOK_TYPE_INFOLIST, priority,
- callback_data);
+ callback_pointer, callback_data);
new_hook->hook_data = new_hook_infolist;
new_hook_infolist->callback = callback;
@@ -3116,7 +3256,11 @@ hook_infolist_get (struct t_weechat_plugin *plugin, const char *infolist_name,
{
ptr_hook->running = 1;
value = (HOOK_INFOLIST(ptr_hook, callback))
- (ptr_hook->callback_data, infolist_name, pointer, arguments);
+ (ptr_hook->callback_pointer,
+ ptr_hook->callback_data,
+ infolist_name,
+ pointer,
+ arguments);
ptr_hook->running = 0;
hook_exec_end ();
@@ -3141,7 +3285,9 @@ hook_infolist_get (struct t_weechat_plugin *plugin, const char *infolist_name,
struct t_hook *
hook_hdata (struct t_weechat_plugin *plugin, const char *hdata_name,
const char *description,
- t_hook_callback_hdata *callback, void *callback_data)
+ t_hook_callback_hdata *callback,
+ const void *callback_pointer,
+ void *callback_data)
{
struct t_hook *new_hook;
struct t_hook_hdata *new_hook_hdata;
@@ -3163,7 +3309,7 @@ hook_hdata (struct t_weechat_plugin *plugin, const char *hdata_name,
hook_get_priority_and_name (hdata_name, &priority, &ptr_hdata_name);
hook_init_data (new_hook, plugin, HOOK_TYPE_HDATA, priority,
- callback_data);
+ callback_pointer, callback_data);
new_hook->hook_data = new_hook_hdata;
new_hook_hdata->callback = callback;
@@ -3212,7 +3358,8 @@ hook_hdata_get (struct t_weechat_plugin *plugin, const char *hdata_name)
{
ptr_hook->running = 1;
value = (HOOK_HDATA(ptr_hook, callback))
- (ptr_hook->callback_data,
+ (ptr_hook->callback_pointer,
+ ptr_hook->callback_data,
HOOK_HDATA(ptr_hook, hdata_name));
ptr_hook->running = 0;
@@ -3236,8 +3383,11 @@ hook_hdata_get (struct t_weechat_plugin *plugin, const char *hdata_name)
*/
struct t_hook *
-hook_focus (struct t_weechat_plugin *plugin, const char *area,
- t_hook_callback_focus *callback, void *callback_data)
+hook_focus (struct t_weechat_plugin *plugin,
+ const char *area,
+ t_hook_callback_focus *callback,
+ const void *callback_pointer,
+ void *callback_data)
{
struct t_hook *new_hook;
struct t_hook_focus *new_hook_focus;
@@ -3259,7 +3409,7 @@ hook_focus (struct t_weechat_plugin *plugin, const char *area,
hook_get_priority_and_name (area, &priority, &ptr_area);
hook_init_data (new_hook, plugin, HOOK_TYPE_FOCUS, priority,
- callback_data);
+ callback_pointer, callback_data);
new_hook->hook_data = new_hook_focus;
new_hook_focus->callback = callback;
@@ -3275,7 +3425,8 @@ hook_focus (struct t_weechat_plugin *plugin, const char *area,
*/
void
-hook_focus_hashtable_map_cb (void *data, struct t_hashtable *hashtable,
+hook_focus_hashtable_map_cb (void *data,
+ struct t_hashtable *hashtable,
const void *key, const void *value)
{
struct t_hashtable *hashtable1;
@@ -3294,7 +3445,8 @@ hook_focus_hashtable_map_cb (void *data, struct t_hashtable *hashtable,
*/
void
-hook_focus_hashtable_map2_cb (void *data, struct t_hashtable *hashtable,
+hook_focus_hashtable_map2_cb (void *data,
+ struct t_hashtable *hashtable,
const void *key, const void *value)
{
struct t_hashtable *hashtable1;
@@ -3363,7 +3515,9 @@ hook_focus_get_data (struct t_hashtable *hashtable_focus1,
/* run callback for focus #1 */
ptr_hook->running = 1;
hashtable_ret = (HOOK_FOCUS(ptr_hook, callback))
- (ptr_hook->callback_data, hashtable1);
+ (ptr_hook->callback_pointer,
+ ptr_hook->callback_data,
+ hashtable1);
ptr_hook->running = 0;
if (hashtable_ret)
{
@@ -3385,7 +3539,9 @@ hook_focus_get_data (struct t_hashtable *hashtable_focus1,
{
ptr_hook->running = 1;
hashtable_ret = (HOOK_FOCUS(ptr_hook, callback))
- (ptr_hook->callback_data, hashtable2);
+ (ptr_hook->callback_pointer,
+ ptr_hook->callback_data,
+ hashtable2);
ptr_hook->running = 0;
if (hashtable_ret)
{
@@ -3409,7 +3565,8 @@ hook_focus_get_data (struct t_hashtable *hashtable_focus1,
if (hashtable2)
{
- hashtable_map (hashtable2, &hook_focus_hashtable_map2_cb, hashtable1);
+ hashtable_map (hashtable2,
+ &hook_focus_hashtable_map2_cb, hashtable1);
hashtable_free (hashtable2);
}
else
@@ -3538,17 +3695,13 @@ unhook (struct t_hook *hook)
if (weechat_debug_core >= 2)
{
gui_chat_printf (NULL,
- "debug: removing hook: type=%d (%s), plugin=%lx (%s)",
- hook->type, hook_type_string[hook->type],
- hook->plugin, plugin_get_name (hook->plugin));
+ "debug: removing hook: type=%d (%s), plugin=\"%s\"",
+ hook->type,
+ hook_type_string[hook->type],
+ plugin_get_name (hook->plugin));
}
- /* free data */
- if (hook->subplugin)
- {
- free (hook->subplugin);
- hook->subplugin = NULL;
- }
+ /* free data specific to the hook */
if (hook->hook_data)
{
switch (hook->type)
@@ -3949,6 +4102,18 @@ unhook (struct t_hook *hook)
hook->hook_data = NULL;
}
+ /* free data common to all hooks */
+ if (hook->subplugin)
+ {
+ free (hook->subplugin);
+ hook->subplugin = NULL;
+ }
+ if (hook->callback_data)
+ {
+ free (hook->callback_data);
+ hook->callback_data = NULL;
+ }
+
/* remove hook from list (if there's no hook exec pending) */
if (hook_exec_recursion == 0)
{
@@ -3963,11 +4128,11 @@ unhook (struct t_hook *hook)
}
/*
- * Unhooks everything for a plugin.
+ * Unhooks everything for a plugin/subplugin.
*/
void
-unhook_all_plugin (struct t_weechat_plugin *plugin)
+unhook_all_plugin (struct t_weechat_plugin *plugin, const char *subplugin)
{
int type;
struct t_hook *ptr_hook, *next_hook;
@@ -3979,7 +4144,14 @@ unhook_all_plugin (struct t_weechat_plugin *plugin)
{
next_hook = ptr_hook->next_hook;
if (ptr_hook->plugin == plugin)
- unhook (ptr_hook);
+ {
+ if (!subplugin
+ || (ptr_hook->subplugin &&
+ strcmp (ptr_hook->subplugin, subplugin) == 0))
+ {
+ unhook (ptr_hook);
+ }
+ }
ptr_hook = next_hook;
}
}
@@ -4043,6 +4215,10 @@ hook_add_to_infolist_pointer (struct t_infolist *infolist, struct t_hook *hook)
return 0;
if (!infolist_new_var_integer (ptr_item, "priority", hook->priority))
return 0;
+ if (!infolist_new_var_pointer (ptr_item, "callback_pointer", (void *)hook->callback_pointer))
+ return 0;
+ if (!infolist_new_var_pointer (ptr_item, "callback_data", (void *)hook->callback_data))
+ return 0;
switch (hook->type)
{
case HOOK_TYPE_COMMAND:
@@ -4519,6 +4695,7 @@ hook_print_log ()
log_printf (" deleted . . . . . . . . : %d", ptr_hook->deleted);
log_printf (" running . . . . . . . . : %d", ptr_hook->running);
log_printf (" priority. . . . . . . . : %d", ptr_hook->priority);
+ log_printf (" callback_pointer. . . . : 0x%lx", ptr_hook->callback_pointer);
log_printf (" callback_data . . . . . : 0x%lx", ptr_hook->callback_data);
if (ptr_hook->deleted)
continue;