diff options
38 files changed, 342 insertions, 1 deletions
diff --git a/src/core/hook/wee-hook-command-run.c b/src/core/hook/wee-hook-command-run.c index 80015629e..cb08b5352 100644 --- a/src/core/hook/wee-hook-command-run.c +++ b/src/core/hook/wee-hook-command-run.c @@ -36,6 +36,18 @@ /* + * Returns description of hook. + * + * Note: result must be freed after use. + */ + +char * +hook_command_run_get_description (struct t_hook *hook) +{ + return strdup (HOOK_COMMAND_RUN(hook, command)); +} + +/* * Hooks a command when it's run by WeeChat. * * Returns pointer to new hook, NULL if error. diff --git a/src/core/hook/wee-hook-command-run.h b/src/core/hook/wee-hook-command-run.h index 53561fb44..2f0f7ff34 100644 --- a/src/core/hook/wee-hook-command-run.h +++ b/src/core/hook/wee-hook-command-run.h @@ -36,6 +36,7 @@ struct t_hook_command_run char *command; /* name of command (without '/') */ }; +extern char *hook_command_run_get_description (struct t_hook *hook); extern struct t_hook *hook_command_run (struct t_weechat_plugin *plugin, const char *command, t_hook_callback_command_run *callback, diff --git a/src/core/hook/wee-hook-command.c b/src/core/hook/wee-hook-command.c index a1ec2e1f9..c5206f4d1 100644 --- a/src/core/hook/wee-hook-command.c +++ b/src/core/hook/wee-hook-command.c @@ -39,6 +39,18 @@ /* + * Returns description of hook. + * + * Note: result must be freed after use. + */ + +char * +hook_command_get_description (struct t_hook *hook) +{ + return strdup (HOOK_COMMAND(hook, command)); +} + +/* * Searches for a command hook in list. * * Returns pointer to hook found, NULL if not found. diff --git a/src/core/hook/wee-hook-command.h b/src/core/hook/wee-hook-command.h index 9a5e30bf8..70b4225af 100644 --- a/src/core/hook/wee-hook-command.h +++ b/src/core/hook/wee-hook-command.h @@ -65,6 +65,7 @@ struct t_hook_command char **cplt_template_args_concat; /* concatenated arguments */ }; +extern char *hook_command_get_description (struct t_hook *hook); extern struct t_hook *hook_command (struct t_weechat_plugin *plugin, const char *command, const char *description, diff --git a/src/core/hook/wee-hook-completion.c b/src/core/hook/wee-hook-completion.c index e2722e136..b277d1042 100644 --- a/src/core/hook/wee-hook-completion.c +++ b/src/core/hook/wee-hook-completion.c @@ -35,6 +35,18 @@ /* + * Returns description of hook. + * + * Note: result must be freed after use. + */ + +char * +hook_completion_get_description (struct t_hook *hook) +{ + return strdup (HOOK_COMPLETION(hook, completion_item)); +} + +/* * Hooks a completion. * * Returns pointer to new hook, NULL if error. diff --git a/src/core/hook/wee-hook-completion.h b/src/core/hook/wee-hook-completion.h index ab5a13358..d51222617 100644 --- a/src/core/hook/wee-hook-completion.h +++ b/src/core/hook/wee-hook-completion.h @@ -39,6 +39,7 @@ struct t_hook_completion char *description; /* description */ }; +extern char *hook_completion_get_description (struct t_hook *hook); extern struct t_hook *hook_completion (struct t_weechat_plugin *plugin, const char *completion_item, const char *description, diff --git a/src/core/hook/wee-hook-config.c b/src/core/hook/wee-hook-config.c index 4e997570e..a95cb4d67 100644 --- a/src/core/hook/wee-hook-config.c +++ b/src/core/hook/wee-hook-config.c @@ -34,6 +34,18 @@ /* + * Returns description of hook. + * + * Note: result must be freed after use. + */ + +char * +hook_config_get_description (struct t_hook *hook) +{ + return strdup (HOOK_CONFIG(hook, option)); +} + +/* * Hooks a configuration option. * * Returns pointer to new hook, NULL if error. diff --git a/src/core/hook/wee-hook-config.h b/src/core/hook/wee-hook-config.h index 2e676bc51..09c6e07ef 100644 --- a/src/core/hook/wee-hook-config.h +++ b/src/core/hook/wee-hook-config.h @@ -35,6 +35,7 @@ struct t_hook_config /* (NULL = hook for all options) */ }; +extern char *hook_config_get_description (struct t_hook *hook); extern struct t_hook *hook_config (struct t_weechat_plugin *plugin, const char *option, t_hook_callback_config *callback, diff --git a/src/core/hook/wee-hook-connect.c b/src/core/hook/wee-hook-connect.c index efb84c930..8b562a31f 100644 --- a/src/core/hook/wee-hook-connect.c +++ b/src/core/hook/wee-hook-connect.c @@ -39,6 +39,27 @@ /* + * Returns description of hook. + * + * Note: result must be freed after use. + */ + +char * +hook_connect_get_description (struct t_hook *hook) +{ + char str_desc[1024]; + + snprintf (str_desc, sizeof (str_desc), + "socket: %d, address: %s, port: %d, child pid: %d", + HOOK_CONNECT(hook, sock), + HOOK_CONNECT(hook, address), + HOOK_CONNECT(hook, port), + HOOK_CONNECT(hook, child_pid)); + + return strdup (str_desc); +} + +/* * Hooks a connection to a peer (using fork). * * Returns pointer to new hook, NULL if error. diff --git a/src/core/hook/wee-hook-connect.h b/src/core/hook/wee-hook-connect.h index 5b9e2ea6c..b2f7a081c 100644 --- a/src/core/hook/wee-hook-connect.h +++ b/src/core/hook/wee-hook-connect.h @@ -78,6 +78,7 @@ struct t_hook_connect int sock_v6[HOOK_CONNECT_MAX_SOCKETS]; /* IPv6 sockets for connecting */ }; +extern char *hook_connect_get_description (struct t_hook *hook); extern struct t_hook *hook_connect (struct t_weechat_plugin *plugin, const char *proxy, const char *address, int port, int ipv6, int retry, diff --git a/src/core/hook/wee-hook-fd.c b/src/core/hook/wee-hook-fd.c index 25ef4a8ab..21fcad622 100644 --- a/src/core/hook/wee-hook-fd.c +++ b/src/core/hook/wee-hook-fd.c @@ -24,6 +24,7 @@ #endif #include <stdlib.h> +#include <string.h> #include <poll.h> #include <fcntl.h> #include <errno.h> @@ -40,6 +41,28 @@ int hook_fd_pollfd_count = 0; /* number of file descriptors */ /* + * Returns description of hook. + * + * Note: result must be freed after use. + */ + +char * +hook_fd_get_description (struct t_hook *hook) +{ + char str_desc[512]; + + snprintf (str_desc, sizeof (str_desc), + "%d (flags: 0x%x:%s%s%s)", + HOOK_FD(hook, fd), + HOOK_FD(hook, flags), + (HOOK_FD(hook, flags) & HOOK_FD_FLAG_READ) ? " read" : "", + (HOOK_FD(hook, flags) & HOOK_FD_FLAG_WRITE) ? " write" : "", + (HOOK_FD(hook, flags) & HOOK_FD_FLAG_EXCEPTION) ? " exception" : ""); + + return strdup (str_desc); +} + +/* * Searches for a fd hook in list. * * Returns pointer to hook found, NULL if not found. diff --git a/src/core/hook/wee-hook-fd.h b/src/core/hook/wee-hook-fd.h index 93947e397..accbcc896 100644 --- a/src/core/hook/wee-hook-fd.h +++ b/src/core/hook/wee-hook-fd.h @@ -41,6 +41,7 @@ struct t_hook_fd /* with fd */ }; +extern char *hook_fd_get_description (struct t_hook *hook); extern void hook_fd_add_cb (struct t_hook *hook); extern void hook_fd_remove_cb (struct t_hook *hook); extern struct t_hook *hook_fd (struct t_weechat_plugin *plugin, int fd, diff --git a/src/core/hook/wee-hook-focus.c b/src/core/hook/wee-hook-focus.c index 7d2a1371e..6f56517b8 100644 --- a/src/core/hook/wee-hook-focus.c +++ b/src/core/hook/wee-hook-focus.c @@ -36,6 +36,18 @@ /* + * Returns description of hook. + * + * Note: result must be freed after use. + */ + +char * +hook_focus_get_description (struct t_hook *hook) +{ + return strdup (HOOK_FOCUS(hook, area)); +} + +/* * Hooks a focus. * * Returns pointer to new hook, NULL if error. diff --git a/src/core/hook/wee-hook-focus.h b/src/core/hook/wee-hook-focus.h index 5a2339513..1494c14a3 100644 --- a/src/core/hook/wee-hook-focus.h +++ b/src/core/hook/wee-hook-focus.h @@ -36,6 +36,7 @@ struct t_hook_focus char *area; /* "chat" or bar item name */ }; +extern char *hook_focus_get_description (struct t_hook *hook); extern struct t_hook *hook_focus (struct t_weechat_plugin *plugin, const char *area, t_hook_callback_focus *callback, diff --git a/src/core/hook/wee-hook-hdata.c b/src/core/hook/wee-hook-hdata.c index c69317e16..852d84693 100644 --- a/src/core/hook/wee-hook-hdata.c +++ b/src/core/hook/wee-hook-hdata.c @@ -35,6 +35,18 @@ /* + * Returns description of hook. + * + * Note: result must be freed after use. + */ + +char * +hook_hdata_get_description (struct t_hook *hook) +{ + return strdup (HOOK_HDATA(hook, hdata_name)); +} + +/* * Hooks a hdata. * * Returns pointer to new hook, NULL if error. diff --git a/src/core/hook/wee-hook-hdata.h b/src/core/hook/wee-hook-hdata.h index 2935c9f9b..4664a4a98 100644 --- a/src/core/hook/wee-hook-hdata.h +++ b/src/core/hook/wee-hook-hdata.h @@ -36,6 +36,7 @@ struct t_hook_hdata char *description; /* description */ }; +extern char *hook_hdata_get_description (struct t_hook *hook); extern struct t_hook *hook_hdata (struct t_weechat_plugin *plugin, const char *hdata_name, const char *description, diff --git a/src/core/hook/wee-hook-hsignal.c b/src/core/hook/wee-hook-hsignal.c index 451d108e5..82198c3c0 100644 --- a/src/core/hook/wee-hook-hsignal.c +++ b/src/core/hook/wee-hook-hsignal.c @@ -35,6 +35,18 @@ /* + * Returns description of hook. + * + * Note: result must be freed after use. + */ + +char * +hook_hsignal_get_description (struct t_hook *hook) +{ + return strdup (HOOK_HSIGNAL(hook, signal)); +} + +/* * Hooks a hsignal (signal with hashtable). * * Returns pointer to new hook, NULL if error. diff --git a/src/core/hook/wee-hook-hsignal.h b/src/core/hook/wee-hook-hsignal.h index 9c181f6e8..b90304529 100644 --- a/src/core/hook/wee-hook-hsignal.h +++ b/src/core/hook/wee-hook-hsignal.h @@ -36,6 +36,7 @@ struct t_hook_hsignal /* with "*", "*" == any signal) */ }; +extern char *hook_hsignal_get_description (struct t_hook *hook); extern struct t_hook *hook_hsignal (struct t_weechat_plugin *plugin, const char *signal, t_hook_callback_hsignal *callback, diff --git a/src/core/hook/wee-hook-info-hashtable.c b/src/core/hook/wee-hook-info-hashtable.c index 76c3690f7..1610b2649 100644 --- a/src/core/hook/wee-hook-info-hashtable.c +++ b/src/core/hook/wee-hook-info-hashtable.c @@ -34,6 +34,18 @@ /* + * Returns description of hook. + * + * Note: result must be freed after use. + */ + +char * +hook_info_hashtable_get_description (struct t_hook *hook) +{ + return strdup (HOOK_INFO_HASHTABLE(hook, info_name)); +} + +/* * Hooks an info using hashtable. * * Returns pointer to new hook, NULL if error. diff --git a/src/core/hook/wee-hook-info-hashtable.h b/src/core/hook/wee-hook-info-hashtable.h index a3c24df58..3dff70e69 100644 --- a/src/core/hook/wee-hook-info-hashtable.h +++ b/src/core/hook/wee-hook-info-hashtable.h @@ -39,6 +39,7 @@ struct t_hook_info_hashtable char *output_description; /* description of output (hashtable) */ }; +extern char *hook_info_hashtable_get_description (struct t_hook *hook); extern struct t_hook *hook_info_hashtable (struct t_weechat_plugin *plugin, const char *info_name, const char *description, diff --git a/src/core/hook/wee-hook-info.c b/src/core/hook/wee-hook-info.c index 09cc7a8eb..d51e31f60 100644 --- a/src/core/hook/wee-hook-info.c +++ b/src/core/hook/wee-hook-info.c @@ -34,6 +34,18 @@ /* + * Returns description of hook. + * + * Note: result must be freed after use. + */ + +char * +hook_info_get_description (struct t_hook *hook) +{ + return strdup (HOOK_INFO(hook, info_name)); +} + +/* * Hooks an info. * * Returns pointer to new hook, NULL if error. diff --git a/src/core/hook/wee-hook-info.h b/src/core/hook/wee-hook-info.h index 6025fc520..7f59441d2 100644 --- a/src/core/hook/wee-hook-info.h +++ b/src/core/hook/wee-hook-info.h @@ -37,6 +37,7 @@ struct t_hook_info char *args_description; /* description of arguments */ }; +extern char *hook_info_get_description (struct t_hook *hook); extern struct t_hook *hook_info (struct t_weechat_plugin *plugin, const char *info_name, const char *description, diff --git a/src/core/hook/wee-hook-infolist.c b/src/core/hook/wee-hook-infolist.c index 5b550746a..37c4d8d5a 100644 --- a/src/core/hook/wee-hook-infolist.c +++ b/src/core/hook/wee-hook-infolist.c @@ -34,6 +34,18 @@ /* + * Returns description of hook. + * + * Note: result must be freed after use. + */ + +char * +hook_infolist_get_description (struct t_hook *hook) +{ + return strdup (HOOK_INFOLIST(hook, infolist_name)); +} + +/* * Hooks an infolist. * * Returns pointer to new hook, NULL if error. diff --git a/src/core/hook/wee-hook-infolist.h b/src/core/hook/wee-hook-infolist.h index 4322db4e9..212f565ff 100644 --- a/src/core/hook/wee-hook-infolist.h +++ b/src/core/hook/wee-hook-infolist.h @@ -40,6 +40,7 @@ struct t_hook_infolist char *args_description; /* description of arguments */ }; +extern char *hook_infolist_get_description (struct t_hook *hook); extern struct t_hook *hook_infolist (struct t_weechat_plugin *plugin, const char *infolist_name, const char *description, diff --git a/src/core/hook/wee-hook-line.c b/src/core/hook/wee-hook-line.c index 6c1d3f03c..d1ef37d63 100644 --- a/src/core/hook/wee-hook-line.c +++ b/src/core/hook/wee-hook-line.c @@ -38,6 +38,26 @@ /* + * Returns description of hook. + * + * Note: result must be freed after use. + */ + +char * +hook_line_get_description (struct t_hook *hook) +{ + char str_desc[1024]; + + snprintf (str_desc, sizeof (str_desc), + "buffer type: %d, %d buffers, %d tags", + HOOK_LINE(hook, buffer_type), + HOOK_LINE(hook, num_buffers), + HOOK_LINE(hook, tags_count)); + + return strdup (str_desc); +} + +/* * Hooks a line added in a buffer. * * Returns pointer to new hook, NULL if error. diff --git a/src/core/hook/wee-hook-line.h b/src/core/hook/wee-hook-line.h index 8d595250b..6cc52267c 100644 --- a/src/core/hook/wee-hook-line.h +++ b/src/core/hook/wee-hook-line.h @@ -43,6 +43,7 @@ struct t_hook_line char ***tags_array; /* tags selected (NULL = any) */ }; +extern char *hook_line_get_description (struct t_hook *hook); extern struct t_hook *hook_line (struct t_weechat_plugin *plugin, const char *buffer_type, const char *buffer_name, diff --git a/src/core/hook/wee-hook-modifier.c b/src/core/hook/wee-hook-modifier.c index 33fb40627..5923fb325 100644 --- a/src/core/hook/wee-hook-modifier.c +++ b/src/core/hook/wee-hook-modifier.c @@ -34,6 +34,18 @@ /* + * Returns description of hook. + * + * Note: result must be freed after use. + */ + +char * +hook_modifier_get_description (struct t_hook *hook) +{ + return strdup (HOOK_MODIFIER(hook, modifier)); +} + +/* * Hooks a modifier. * * Returns pointer to new hook, NULL if error. diff --git a/src/core/hook/wee-hook-modifier.h b/src/core/hook/wee-hook-modifier.h index cf211c5d2..40d887697 100644 --- a/src/core/hook/wee-hook-modifier.h +++ b/src/core/hook/wee-hook-modifier.h @@ -36,6 +36,7 @@ struct t_hook_modifier char *modifier; /* name of modifier */ }; +extern char *hook_modifier_get_description (struct t_hook *hook); extern struct t_hook *hook_modifier (struct t_weechat_plugin *plugin, const char *modifier, t_hook_callback_modifier *callback, diff --git a/src/core/hook/wee-hook-print.c b/src/core/hook/wee-hook-print.c index 833538c5a..b21ba088c 100644 --- a/src/core/hook/wee-hook-print.c +++ b/src/core/hook/wee-hook-print.c @@ -31,11 +31,44 @@ #include "../wee-infolist.h" #include "../wee-log.h" #include "../wee-string.h" +#include "../../gui/gui-buffer.h" #include "../../gui/gui-color.h" #include "../../gui/gui-line.h" /* + * Returns description of hook. + * + * Note: result must be freed after use. + */ + +char * +hook_print_get_description (struct t_hook *hook) +{ + char str_desc[1024]; + + if (HOOK_PRINT(hook, buffer)) + { + snprintf (str_desc, sizeof (str_desc), + "buffer: %s, message: %s%s%s", + HOOK_PRINT(hook, buffer)->name, + (HOOK_PRINT(hook, message)) ? "\"" : "", + (HOOK_PRINT(hook, message)) ? HOOK_PRINT(hook, message) : "(none)", + (HOOK_PRINT(hook, message)) ? "\"" : ""); + } + else + { + snprintf (str_desc, sizeof (str_desc), + "message: %s%s%s", + (HOOK_PRINT(hook, message)) ? "\"" : "", + (HOOK_PRINT(hook, message)) ? HOOK_PRINT(hook, message) : "(none)", + (HOOK_PRINT(hook, message)) ? "\"" : ""); + } + + return strdup (str_desc); +} + +/* * Hooks a message printed by WeeChat. * * Returns pointer to new hook, NULL if error. diff --git a/src/core/hook/wee-hook-print.h b/src/core/hook/wee-hook-print.h index a56790fee..157caabb0 100644 --- a/src/core/hook/wee-hook-print.h +++ b/src/core/hook/wee-hook-print.h @@ -46,6 +46,7 @@ struct t_hook_print int strip_colors; /* strip colors in msg for callback? */ }; +extern char *hook_print_get_description (struct t_hook *hook); extern struct t_hook *hook_print (struct t_weechat_plugin *plugin, struct t_gui_buffer *buffer, const char *tags, const char *message, diff --git a/src/core/hook/wee-hook-process.c b/src/core/hook/wee-hook-process.c index 9a48e4c1e..15366eb3b 100644 --- a/src/core/hook/wee-hook-process.c +++ b/src/core/hook/wee-hook-process.c @@ -50,6 +50,25 @@ void hook_process_run (struct t_hook *hook_process); /* + * Returns description of hook. + * + * Note: result must be freed after use. + */ + +char * +hook_process_get_description (struct t_hook *hook) +{ + char str_desc[1024]; + + snprintf (str_desc, sizeof (str_desc), + "command: \"%s\", child pid: %d", + HOOK_PROCESS(hook, command), + HOOK_PROCESS(hook, child_pid)); + + return strdup (str_desc); +} + +/* * Hooks a process (using fork) with options in hashtable. * * Returns pointer to new hook, NULL if error. diff --git a/src/core/hook/wee-hook-process.h b/src/core/hook/wee-hook-process.h index 3263c3a51..f95a6e544 100644 --- a/src/core/hook/wee-hook-process.h +++ b/src/core/hook/wee-hook-process.h @@ -56,6 +56,7 @@ struct t_hook_process extern int hook_process_pending; +extern char *hook_process_get_description (struct t_hook *hook); extern struct t_hook *hook_process (struct t_weechat_plugin *plugin, const char *command, int timeout, diff --git a/src/core/hook/wee-hook-signal.c b/src/core/hook/wee-hook-signal.c index 463c93798..5be0fb81b 100644 --- a/src/core/hook/wee-hook-signal.c +++ b/src/core/hook/wee-hook-signal.c @@ -35,6 +35,18 @@ /* + * Returns description of hook. + * + * Note: result must be freed after use. + */ + +char * +hook_signal_get_description (struct t_hook *hook) +{ + return strdup (HOOK_SIGNAL(hook, signal)); +} + +/* * Hooks a signal. * * Returns pointer to new hook, NULL if error. diff --git a/src/core/hook/wee-hook-signal.h b/src/core/hook/wee-hook-signal.h index f8e157fc8..0d00e11c1 100644 --- a/src/core/hook/wee-hook-signal.h +++ b/src/core/hook/wee-hook-signal.h @@ -36,6 +36,7 @@ struct t_hook_signal /* with "*", "*" == any signal) */ }; +extern char *hook_signal_get_description (struct t_hook *hook); extern struct t_hook *hook_signal (struct t_weechat_plugin *plugin, const char *signal, t_hook_callback_signal *callback, diff --git a/src/core/hook/wee-hook-timer.c b/src/core/hook/wee-hook-timer.c index d0278a850..4dbe4d955 100644 --- a/src/core/hook/wee-hook-timer.c +++ b/src/core/hook/wee-hook-timer.c @@ -24,6 +24,7 @@ #endif #include <stdlib.h> +#include <string.h> #include <time.h> #include "../weechat.h" @@ -38,6 +39,43 @@ time_t hook_last_system_time = 0; /* used to detect system clock skew */ /* + * Returns description of hook. + * + * Note: result must be freed after use. + */ + +char * +hook_timer_get_description (struct t_hook *hook) +{ + char str_desc[512]; + int unit_seconds; + long interval; + + unit_seconds = (HOOK_TIMER(hook, interval) % 1000 == 0); + interval = (unit_seconds) ? + HOOK_TIMER(hook, interval) / 1000 : + HOOK_TIMER(hook, interval); + + if (HOOK_TIMER(hook, remaining_calls) > 0) + { + snprintf (str_desc, sizeof (str_desc), + "%ld%s (%d calls remaining)", + interval, + (unit_seconds) ? "s" : "ms", + HOOK_TIMER(hook, remaining_calls)); + } + else + { + snprintf (str_desc, sizeof (str_desc), + "%ld%s (no call limit)", + interval, + (unit_seconds) ? "s" : "ms"); + } + + return strdup (str_desc); +} + +/* * Initializes a timer hook. */ diff --git a/src/core/hook/wee-hook-timer.h b/src/core/hook/wee-hook-timer.h index 43328ce67..45b00612b 100644 --- a/src/core/hook/wee-hook-timer.h +++ b/src/core/hook/wee-hook-timer.h @@ -44,6 +44,7 @@ struct t_hook_timer extern time_t hook_last_system_time; +extern char *hook_timer_get_description (struct t_hook *hook); extern struct t_hook *hook_timer (struct t_weechat_plugin *plugin, long interval, int align_second, int max_calls, diff --git a/src/core/wee-hook.c b/src/core/wee-hook.c index 0d0fd6b22..04b1acc2e 100644 --- a/src/core/wee-hook.c +++ b/src/core/wee-hook.c @@ -71,6 +71,16 @@ t_callback_hook *hook_callback_free_data[HOOK_NUM_TYPES] = &hook_modifier_free_data, &hook_info_free_data, &hook_info_hashtable_free_data, &hook_infolist_free_data, &hook_hdata_free_data, &hook_focus_free_data }; +t_callback_hook_get_desc *hook_callback_get_desc[HOOK_NUM_TYPES] = +{ &hook_command_get_description, &hook_command_run_get_description, + &hook_timer_get_description, &hook_fd_get_description, + &hook_process_get_description, &hook_connect_get_description, + &hook_line_get_description, &hook_print_get_description, + &hook_signal_get_description, &hook_hsignal_get_description, + &hook_config_get_description, &hook_completion_get_description, + &hook_modifier_get_description, &hook_info_get_description, + &hook_info_hashtable_get_description, &hook_infolist_get_description, + &hook_hdata_get_description, &hook_focus_get_description }; t_callback_hook_infolist *hook_callback_add_to_infolist[HOOK_NUM_TYPES] = { &hook_command_add_to_infolist, &hook_command_run_add_to_infolist, &hook_timer_add_to_infolist, &hook_fd_add_to_infolist, @@ -459,6 +469,18 @@ hook_exec_end () } /* + * Returns description of hook. + * + * Note: result must be freed after use. + */ + +char * +hook_get_description (struct t_hook *hook) +{ + return (hook_callback_get_desc[hook->type]) (hook); +} + +/* * Sets a hook property (string). */ diff --git a/src/core/wee-hook.h b/src/core/wee-hook.h index cf64aa69c..7efbd82ac 100644 --- a/src/core/wee-hook.h +++ b/src/core/wee-hook.h @@ -20,6 +20,8 @@ #ifndef WEECHAT_HOOK_H #define WEECHAT_HOOK_H +struct t_hook; + #include "hook/wee-hook-command-run.h" #include "hook/wee-hook-command.h" #include "hook/wee-hook-completion.h" @@ -39,7 +41,6 @@ #include "hook/wee-hook-signal.h" #include "hook/wee-hook-timer.h" -struct t_hook; struct t_gui_bar; struct t_gui_buffer; struct t_gui_line; @@ -83,6 +84,7 @@ enum t_hook_type #define HOOK_PRIORITY_DEFAULT 1000 typedef void (t_callback_hook)(struct t_hook *hook); +typedef char *(t_callback_hook_get_desc)(struct t_hook *hook); typedef int (t_callback_hook_infolist)(struct t_infolist_item *item, struct t_hook *hook); @@ -130,6 +132,7 @@ extern void hook_init_data (struct t_hook *hook, extern int hook_valid (struct t_hook *hook); extern void hook_exec_start (); extern void hook_exec_end (); +extern char *hook_get_description (struct t_hook *hook); extern void hook_set (struct t_hook *hook, const char *property, const char *value); extern void unhook (struct t_hook *hook); |