1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-28 13:56:37 +02:00

core: add functions to get short description of hooks

This commit is contained in:
Sébastien Helleu
2022-04-24 10:00:09 +02:00
parent 95cf2aa956
commit d16640130e
38 changed files with 342 additions and 1 deletions
+12
View File
@@ -35,6 +35,18 @@
#include "../../plugins/plugin.h"
/*
* 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.
*
+1
View File
@@ -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,
+12
View File
@@ -38,6 +38,18 @@
#include "../../plugins/plugin.h"
/*
* 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.
*
+1
View File
@@ -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,
+12
View File
@@ -34,6 +34,18 @@
#include "../../gui/gui-completion.h"
/*
* 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.
*
+1
View File
@@ -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,
+12
View File
@@ -33,6 +33,18 @@
#include "../wee-string.h"
/*
* 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.
*
+1
View File
@@ -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,
+21
View File
@@ -38,6 +38,27 @@
#include "../../plugins/plugin.h"
/*
* 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).
*
+1
View File
@@ -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,
+23
View File
@@ -24,6 +24,7 @@
#endif
#include <stdlib.h>
#include <string.h>
#include <poll.h>
#include <fcntl.h>
#include <errno.h>
@@ -39,6 +40,28 @@ struct pollfd *hook_fd_pollfd = NULL; /* file descriptors for poll() */
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.
*
+1
View File
@@ -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,
+12
View File
@@ -35,6 +35,18 @@
#include "../../plugins/plugin.h"
/*
* 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.
*
+1
View File
@@ -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,
+12
View File
@@ -34,6 +34,18 @@
#include "../wee-log.h"
/*
* 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.
*
+1
View File
@@ -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,
+12
View File
@@ -34,6 +34,18 @@
#include "../../plugins/plugin.h"
/*
* 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).
*
+1
View File
@@ -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,
+12
View File
@@ -33,6 +33,18 @@
#include "../wee-string.h"
/*
* 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.
*
+1
View File
@@ -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,
+12
View File
@@ -33,6 +33,18 @@
#include "../wee-string.h"
/*
* 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.
*
+1
View File
@@ -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,
+12
View File
@@ -33,6 +33,18 @@
#include "../wee-string.h"
/*
* 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.
*
+1
View File
@@ -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,
+20
View File
@@ -37,6 +37,26 @@
#include "../../plugins/plugin.h"
/*
* 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.
*
+1
View File
@@ -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,
+12
View File
@@ -33,6 +33,18 @@
#include "../wee-string.h"
/*
* 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.
*
+1
View File
@@ -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,
+33
View File
@@ -31,10 +31,43 @@
#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.
*
+1
View File
@@ -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,
+19
View File
@@ -49,6 +49,25 @@ int hook_process_pending = 0; /* 1 if there are some process to */
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.
*
+1
View File
@@ -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,
+12
View File
@@ -34,6 +34,18 @@
#include "../../plugins/plugin.h"
/*
* 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.
*
+1
View File
@@ -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,
+38
View File
@@ -24,6 +24,7 @@
#endif
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "../weechat.h"
@@ -37,6 +38,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.
*/
+1
View File
@@ -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,
+22
View File
@@ -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,
@@ -458,6 +468,18 @@ hook_exec_end ()
hook_remove_deleted ();
}
/*
* 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).
*/
+4 -1
View File
@@ -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);