1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-03 16:23:14 +02:00

api: add function hook_line

This commit is contained in:
Sébastien Helleu
2018-08-12 21:45:00 +02:00
parent 12a6f74ec0
commit 42be1a74a0
47 changed files with 3836 additions and 1226 deletions
+53
View File
@@ -2454,6 +2454,58 @@ weechat_guile_api_hook_connect (SCM proxy, SCM address, SCM port, SCM ipv6,
API_RETURN_STRING(result);
}
struct t_hashtable *
weechat_guile_api_hook_line_cb (const void *pointer, void *data,
struct t_hashtable *line)
{
struct t_plugin_script *script;
void *func_argv[2];
char empty_arg[1] = { '\0' };
const char *ptr_function, *ptr_data;
script = (struct t_plugin_script *)pointer;
plugin_script_get_function_and_data (data, &ptr_function, &ptr_data);
if (ptr_function && ptr_function[0])
{
func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = line;
return (struct t_hashtable *)weechat_guile_exec (
script,
WEECHAT_SCRIPT_EXEC_HASHTABLE,
ptr_function,
"sh", func_argv);
}
return NULL;
}
SCM
weechat_guile_api_hook_line (SCM buffer_type, SCM buffer_name, SCM tags,
SCM function, SCM data)
{
const char *result;
SCM return_value;
API_INIT_FUNC(1, "hook_line", API_RETURN_EMPTY);
if (!scm_is_string (buffer_type) || !scm_is_string (buffer_name)
|| !scm_is_string (tags) || !scm_is_string (function)
|| !scm_is_string (data))
API_WRONG_ARGS(API_RETURN_EMPTY);
result = API_PTR2STR(plugin_script_api_hook_line (weechat_guile_plugin,
guile_current_script,
API_SCM_TO_STRING(buffer_type),
API_SCM_TO_STRING(buffer_name),
API_SCM_TO_STRING(tags),
&weechat_guile_api_hook_line_cb,
API_SCM_TO_STRING(function),
API_SCM_TO_STRING(data)));
API_RETURN_STRING(result);
}
int
weechat_guile_api_hook_print_cb (const void *pointer, void *data,
struct t_gui_buffer *buffer,
@@ -4884,6 +4936,7 @@ weechat_guile_api_module_init (void *data)
API_DEF_FUNC(hook_process, 4);
API_DEF_FUNC(hook_process_hashtable, 5);
API_DEF_FUNC(hook_connect, 8);
API_DEF_FUNC(hook_line, 5);
API_DEF_FUNC(hook_print, 6);
API_DEF_FUNC(hook_signal, 3);
API_DEF_FUNC(hook_signal_send, 3);
+57
View File
@@ -2361,6 +2361,62 @@ API_FUNC(hook_connect)
API_RETURN_STRING(result);
}
struct t_hashtable *
weechat_js_api_hook_line_cb (const void *pointer, void *data,
struct t_hashtable *line)
{
struct t_plugin_script *script;
void *func_argv[2];
char empty_arg[1] = { '\0' };
const char *ptr_function, *ptr_data;
struct t_hashtable *ret_hashtable;
script = (struct t_plugin_script *)pointer;
plugin_script_get_function_and_data (data, &ptr_function, &ptr_data);
if (ptr_function && ptr_function[0])
{
func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = line;
ret_hashtable = (struct t_hashtable *)weechat_js_exec (
script,
WEECHAT_SCRIPT_EXEC_HASHTABLE,
ptr_function,
"sh", func_argv);
return ret_hashtable;
}
return NULL;
}
API_FUNC(hook_line)
{
const char *result;
API_INIT_FUNC(1, "hook_line", "sssss", API_RETURN_EMPTY);
v8::String::Utf8Value buffer_type(args[0]);
v8::String::Utf8Value buffer_name(args[1]);
v8::String::Utf8Value tags(args[2]);
v8::String::Utf8Value function(args[3]);
v8::String::Utf8Value data(args[4]);
result = API_PTR2STR(
plugin_script_api_hook_line (
weechat_js_plugin,
js_current_script,
*buffer_type,
*buffer_name,
*tags,
&weechat_js_api_hook_line_cb,
*function,
*data));
API_RETURN_STRING(result);
}
int
weechat_js_api_hook_print_cb (const void *pointer, void *data,
struct t_gui_buffer *buffer,
@@ -4831,6 +4887,7 @@ WeechatJsV8::loadLibs()
API_DEF_FUNC(hook_process);
API_DEF_FUNC(hook_process_hashtable);
API_DEF_FUNC(hook_connect);
API_DEF_FUNC(hook_line);
API_DEF_FUNC(hook_print);
API_DEF_FUNC(hook_signal);
API_DEF_FUNC(hook_signal_send);
+55
View File
@@ -2583,6 +2583,60 @@ API_FUNC(hook_connect)
API_RETURN_STRING(result);
}
struct t_hashtable *
weechat_lua_api_hook_line_cb (const void *pointer, void *data,
struct t_hashtable *line)
{
struct t_plugin_script *script;
void *func_argv[2];
char empty_arg[1] = { '\0' };
const char *ptr_function, *ptr_data;
script = (struct t_plugin_script *)pointer;
plugin_script_get_function_and_data (data, &ptr_function, &ptr_data);
if (ptr_function && ptr_function[0])
{
func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = line;
return (struct t_hashtable *)weechat_lua_exec (
script,
WEECHAT_SCRIPT_EXEC_HASHTABLE,
ptr_function,
"sh", func_argv);
}
return NULL;
}
API_FUNC(hook_line)
{
const char *buffer_type, *buffer_name, *tags, *function, *data;
const char *result;
API_INIT_FUNC(1, "hook_line", API_RETURN_EMPTY);
if (lua_gettop (L) < 5)
API_WRONG_ARGS(API_RETURN_EMPTY);
buffer_type = lua_tostring (L, -5);
buffer_name = lua_tostring (L, -4);
tags = lua_tostring (L, -3);
function = lua_tostring (L, -2);
data = lua_tostring (L, -1);
result = API_PTR2STR(plugin_script_api_hook_line (weechat_lua_plugin,
lua_current_script,
buffer_type,
buffer_name,
tags,
&weechat_lua_api_hook_line_cb,
function,
data));
API_RETURN_STRING(result);
}
int
weechat_lua_api_hook_print_cb (const void *pointer, void *data,
struct t_gui_buffer *buffer,
@@ -5181,6 +5235,7 @@ const struct luaL_Reg weechat_lua_api_funcs[] = {
API_DEF_FUNC(hook_process),
API_DEF_FUNC(hook_process_hashtable),
API_DEF_FUNC(hook_connect),
API_DEF_FUNC(hook_line),
API_DEF_FUNC(hook_print),
API_DEF_FUNC(hook_signal),
API_DEF_FUNC(hook_signal_send),
+56
View File
@@ -2484,6 +2484,61 @@ API_FUNC(hook_connect)
API_RETURN_STRING(result);
}
struct t_hashtable *
weechat_perl_api_hook_line_cb (const void *pointer, void *data,
struct t_hashtable *line)
{
struct t_plugin_script *script;
void *func_argv[2];
char empty_arg[1] = { '\0' };
const char *ptr_function, *ptr_data;
script = (struct t_plugin_script *)pointer;
plugin_script_get_function_and_data (data, &ptr_function, &ptr_data);
if (ptr_function && ptr_function[0])
{
func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = line;
return (struct t_hashtable *)weechat_perl_exec (
script,
WEECHAT_SCRIPT_EXEC_HASHTABLE,
ptr_function,
"sh", func_argv);
}
return NULL;
}
API_FUNC(hook_line)
{
char *buffer_type, *buffer_name, *tags, *function, *data;
const char *result;
dXSARGS;
API_INIT_FUNC(1, "hook_line", API_RETURN_EMPTY);
if (items < 5)
API_WRONG_ARGS(API_RETURN_EMPTY);
buffer_type = SvPV_nolen (ST (0));
buffer_name = SvPV_nolen (ST (1));
tags = SvPV_nolen (ST (2));
function = SvPV_nolen (ST (3));
data = SvPV_nolen (ST (4));
result = API_PTR2STR(plugin_script_api_hook_line (weechat_perl_plugin,
perl_current_script,
buffer_type,
buffer_name,
tags,
&weechat_perl_api_hook_line_cb,
function,
data));
API_RETURN_STRING(result);
}
int
weechat_perl_api_hook_print_cb (const void *pointer, void *data,
struct t_gui_buffer *buffer,
@@ -5142,6 +5197,7 @@ weechat_perl_api_init (pTHX)
API_DEF_FUNC(hook_process);
API_DEF_FUNC(hook_process_hashtable);
API_DEF_FUNC(hook_connect);
API_DEF_FUNC(hook_line);
API_DEF_FUNC(hook_print);
API_DEF_FUNC(hook_signal);
API_DEF_FUNC(hook_signal_send);
File diff suppressed because it is too large Load Diff
+1
View File
@@ -135,6 +135,7 @@ PHP_FUNCTION(weechat_hook_fd);
PHP_FUNCTION(weechat_hook_process);
PHP_FUNCTION(weechat_hook_process_hashtable);
PHP_FUNCTION(weechat_hook_connect);
PHP_FUNCTION(weechat_hook_line);
PHP_FUNCTION(weechat_hook_print);
PHP_FUNCTION(weechat_hook_signal);
PHP_FUNCTION(weechat_hook_signal_send);
+1
View File
@@ -189,6 +189,7 @@ const zend_function_entry weechat_functions[] = {
PHP_FE(weechat_hook_process, NULL)
PHP_FE(weechat_hook_process_hashtable, NULL)
PHP_FE(weechat_hook_connect, NULL)
PHP_FE(weechat_hook_line, NULL)
PHP_FE(weechat_hook_print, NULL)
PHP_FE(weechat_hook_signal, NULL)
PHP_FE(weechat_hook_signal_send, NULL)
+42
View File
@@ -657,6 +657,48 @@ plugin_script_api_hook_connect (struct t_weechat_plugin *weechat_plugin,
return new_hook;
}
/*
* Hooks a line.
*
* Returns pointer to new hook, NULL if error.
*/
struct t_hook *
plugin_script_api_hook_line (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
const char *buffer_type,
const char *buffer_name,
const char *tags,
struct t_hashtable *(*callback)(const void *pointer,
void *data,
struct t_hashtable *line),
const char *function,
const char *data)
{
char *function_and_data;
struct t_hook *new_hook;
if (!script)
return NULL;
function_and_data = plugin_script_build_function_and_data (function, data);
new_hook = weechat_hook_line (buffer_type, buffer_name, tags, callback,
script, function_and_data);
if (new_hook)
{
weechat_hook_set (new_hook, "subplugin", script->name);
}
else
{
if (function_and_data)
free (function_and_data);
}
return new_hook;
}
/*
* Hooks a message printed by WeeChat.
*
+10
View File
@@ -203,6 +203,16 @@ extern struct t_hook *plugin_script_api_hook_connect (struct t_weechat_plugin *w
const char *ip_address),
const char *function,
const char *data);
extern struct t_hook *plugin_script_api_hook_line (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
const char *buffer_type,
const char *buffer_name,
const char *tags,
struct t_hashtable *(*callback)(const void *pointer,
void *data,
struct t_hashtable *line),
const char *function,
const char *data);
extern struct t_hook *plugin_script_api_hook_print (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_gui_buffer *buffer,
+1
View File
@@ -777,6 +777,7 @@ plugin_load (const char *filename, int init_plugin, int argc, char **argv)
new_plugin->hook_process = &hook_process;
new_plugin->hook_process_hashtable = &hook_process_hashtable;
new_plugin->hook_connect = &hook_connect;
new_plugin->hook_line = &hook_line;
new_plugin->hook_print = &hook_print;
new_plugin->hook_signal = &hook_signal;
new_plugin->hook_signal_send = &hook_signal_send;
+62
View File
@@ -2510,6 +2510,67 @@ API_FUNC(hook_connect)
API_RETURN_STRING(result);
}
struct t_hashtable *
weechat_python_api_hook_line_cb (const void *pointer, void *data,
struct t_hashtable *line)
{
struct t_plugin_script *script;
void *func_argv[2];
char empty_arg[1] = { '\0' };
const char *ptr_function, *ptr_data;
struct t_hashtable *ret_hashtable;
script = (struct t_plugin_script *)pointer;
plugin_script_get_function_and_data (data, &ptr_function, &ptr_data);
if (ptr_function && ptr_function[0])
{
func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = weechat_python_hashtable_to_dict (line);
ret_hashtable = weechat_python_exec (script,
WEECHAT_SCRIPT_EXEC_HASHTABLE,
ptr_function,
"sO", func_argv);
if (func_argv[1])
{
Py_XDECREF((PyObject *)func_argv[1]);
}
return ret_hashtable;
}
return NULL;
}
API_FUNC(hook_line)
{
char *buffer_type, *buffer_name, *tags, *function, *data;
const char *result;
API_INIT_FUNC(1, "hook_line", API_RETURN_EMPTY);
buffer_type = NULL;
buffer_name = NULL;
tags = NULL;
function = NULL;
data = NULL;
if (!PyArg_ParseTuple (args, "sssss", &buffer_type, &buffer_name, &tags,
&function, &data))
API_WRONG_ARGS(API_RETURN_EMPTY);
result = API_PTR2STR(plugin_script_api_hook_line (weechat_python_plugin,
python_current_script,
buffer_type,
buffer_name,
tags,
&weechat_python_api_hook_line_cb,
function,
data));
API_RETURN_STRING(result);
}
int
weechat_python_api_hook_print_cb (const void *pointer, void *data,
struct t_gui_buffer *buffer,
@@ -5084,6 +5145,7 @@ PyMethodDef weechat_python_funcs[] =
API_DEF_FUNC(hook_process),
API_DEF_FUNC(hook_process_hashtable),
API_DEF_FUNC(hook_connect),
API_DEF_FUNC(hook_line),
API_DEF_FUNC(hook_print),
API_DEF_FUNC(hook_signal),
API_DEF_FUNC(hook_signal_send),
+64
View File
@@ -3033,6 +3033,69 @@ weechat_ruby_api_hook_connect (VALUE class, VALUE proxy, VALUE address,
API_RETURN_STRING(result);
}
struct t_hashtable *
weechat_ruby_api_hook_line_cb (const void *pointer, void *data,
struct t_hashtable *line)
{
struct t_plugin_script *script;
void *func_argv[2];
char empty_arg[1] = { '\0' };
const char *ptr_function, *ptr_data;
script = (struct t_plugin_script *)pointer;
plugin_script_get_function_and_data (data, &ptr_function, &ptr_data);
if (ptr_function && ptr_function[0])
{
func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = line;
return (struct t_hashtable *)weechat_ruby_exec (
script,
WEECHAT_SCRIPT_EXEC_HASHTABLE,
ptr_function,
"sh", func_argv);
}
return NULL;
}
static VALUE
weechat_ruby_api_hook_line (VALUE class, VALUE buffer_type, VALUE buffer_name,
VALUE tags, VALUE function, VALUE data)
{
char *c_buffer_type, *c_buffer_name, *c_tags, *c_function, *c_data;
const char *result;
API_INIT_FUNC(1, "hook_line", API_RETURN_EMPTY);
if (NIL_P (buffer_type) || NIL_P (buffer_name) || NIL_P (tags)
|| NIL_P (function) || NIL_P (data))
API_WRONG_ARGS(API_RETURN_EMPTY);
Check_Type (buffer_type, T_STRING);
Check_Type (buffer_name, T_STRING);
Check_Type (tags, T_STRING);
Check_Type (function, T_STRING);
Check_Type (data, T_STRING);
c_buffer_type = StringValuePtr (buffer_type);
c_buffer_name = StringValuePtr (buffer_name);
c_tags = StringValuePtr (tags);
c_function = StringValuePtr (function);
c_data = StringValuePtr (data);
result = API_PTR2STR(plugin_script_api_hook_line (weechat_ruby_plugin,
ruby_current_script,
c_buffer_type,
c_buffer_name,
c_tags,
&weechat_ruby_api_hook_line_cb,
c_function,
c_data));
API_RETURN_STRING(result);
}
int
weechat_ruby_api_hook_print_cb (const void *pointer, void *data,
struct t_gui_buffer *buffer,
@@ -6236,6 +6299,7 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
API_DEF_FUNC(hook_process, 4);
API_DEF_FUNC(hook_process_hashtable, 5);
API_DEF_FUNC(hook_connect, 8);
API_DEF_FUNC(hook_line, 5);
API_DEF_FUNC(hook_print, 6);
API_DEF_FUNC(hook_signal, 3);
API_DEF_FUNC(hook_signal_send, 3);
+57
View File
@@ -2763,6 +2763,62 @@ API_FUNC(hook_connect)
API_RETURN_STRING(result);
}
struct t_hashtable *
weechat_tcl_api_hook_line_cb (const void *pointer, void *data,
struct t_hashtable *line)
{
struct t_plugin_script *script;
void *func_argv[2];
char empty_arg[1] = { '\0' };
const char *ptr_function, *ptr_data;
script = (struct t_plugin_script *)pointer;
plugin_script_get_function_and_data (data, &ptr_function, &ptr_data);
if (ptr_function && ptr_function[0])
{
func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = line;
return (struct t_hashtable *)weechat_tcl_exec (
script,
WEECHAT_SCRIPT_EXEC_HASHTABLE,
ptr_function,
"sh", func_argv);
}
return NULL;
}
API_FUNC(hook_line)
{
Tcl_Obj *objp;
char *buffer_type, *buffer_name, *tags, *function, *data;
const char *result;
int i;
API_INIT_FUNC(1, "hook_line", API_RETURN_EMPTY);
if (objc < 6)
API_WRONG_ARGS(API_RETURN_EMPTY);
buffer_type = Tcl_GetStringFromObj (objv[1], &i);
buffer_name = Tcl_GetStringFromObj (objv[2], &i);
tags = Tcl_GetStringFromObj (objv[3], &i);
function = Tcl_GetStringFromObj (objv[4], &i);
data = Tcl_GetStringFromObj (objv[5], &i);
result = API_PTR2STR(plugin_script_api_hook_line (weechat_tcl_plugin,
tcl_current_script,
buffer_type,
buffer_name,
tags,
&weechat_tcl_api_hook_line_cb,
function,
data));
API_RETURN_STRING(result);
}
int
weechat_tcl_api_hook_print_cb (const void *pointer, void *data,
struct t_gui_buffer *buffer,
@@ -5611,6 +5667,7 @@ void weechat_tcl_api_init (Tcl_Interp *interp)
API_DEF_FUNC(hook_process);
API_DEF_FUNC(hook_process_hashtable);
API_DEF_FUNC(hook_connect);
API_DEF_FUNC(hook_line);
API_DEF_FUNC(hook_print);
API_DEF_FUNC(hook_signal);
API_DEF_FUNC(hook_signal_send);
+138 -11
View File
@@ -227,6 +227,7 @@ void
trigger_callback_replace_regex (struct t_trigger *trigger,
struct t_hashtable *pointers,
struct t_hashtable *extra_vars,
struct t_weelist *vars_updated,
int display_monitor)
{
char *value;
@@ -312,6 +313,11 @@ trigger_callback_replace_regex (struct t_trigger *trigger,
weechat_color ("chat_delimiters"));
}
weechat_hashtable_set (extra_vars, ptr_key, value);
if (vars_updated)
{
weechat_list_add (vars_updated, ptr_key, WEECHAT_LIST_POS_END,
NULL);
}
free (value);
}
}
@@ -392,7 +398,8 @@ void
trigger_callback_execute (struct t_trigger *trigger,
struct t_gui_buffer *buffer,
struct t_hashtable *pointers,
struct t_hashtable *extra_vars)
struct t_hashtable *extra_vars,
struct t_weelist *vars_updated)
{
int display_monitor;
@@ -409,7 +416,7 @@ trigger_callback_execute (struct t_trigger *trigger,
{
/* replace text with regex */
trigger_callback_replace_regex (trigger, pointers, extra_vars,
display_monitor);
vars_updated, display_monitor);
/* execute command(s) */
trigger_callback_run_command (trigger, buffer, pointers, extra_vars,
@@ -521,7 +528,7 @@ trigger_callback_signal_cb (const void *pointer, void *data,
weechat_hashtable_set (extra_vars, "tg_signal_data", ptr_signal_data);
/* execute the trigger (conditions, regex, command) */
trigger_callback_execute (trigger, NULL, pointers, extra_vars);
trigger_callback_execute (trigger, NULL, pointers, extra_vars, NULL);
end:
TRIGGER_CALLBACK_CB_END(trigger_rc);
@@ -569,7 +576,7 @@ trigger_callback_hsignal_cb (const void *pointer, void *data,
weechat_hashtable_set (extra_vars, "tg_signal", signal);
/* execute the trigger (conditions, regex, command) */
trigger_callback_execute (trigger, NULL, pointers, extra_vars);
trigger_callback_execute (trigger, NULL, pointers, extra_vars, NULL);
end:
TRIGGER_CALLBACK_CB_END(trigger_rc);
@@ -753,7 +760,7 @@ trigger_callback_modifier_cb (const void *pointer, void *data,
}
/* execute the trigger (conditions, regex, command) */
trigger_callback_execute (trigger, buffer, pointers, extra_vars);
trigger_callback_execute (trigger, buffer, pointers, extra_vars, NULL);
end:
ptr_string = weechat_hashtable_get (extra_vars, "tg_string");
@@ -768,6 +775,126 @@ end:
TRIGGER_CALLBACK_CB_END(string_modified);
}
/*
* Callback for a line hooked.
*/
struct t_hashtable *
trigger_callback_line_cb (const void *pointer, void *data,
struct t_hashtable *line)
{
struct t_hashtable *hashtable;
struct t_gui_buffer *buffer;
struct t_weelist_item *ptr_item;
long unsigned int value;
const char *ptr_key, *ptr_value;
char **tags, *str_tags;
int rc, num_tags, length;
TRIGGER_CALLBACK_CB_INIT(NULL);
hashtable = NULL;
TRIGGER_CALLBACK_CB_NEW_POINTERS;
TRIGGER_CALLBACK_CB_NEW_VARS_UPDATED;
extra_vars = weechat_hashtable_dup (line);
weechat_hashtable_remove (extra_vars, "buffer");
weechat_hashtable_remove (extra_vars, "tags_count");
weechat_hashtable_remove (extra_vars, "tags");
/* add data in hashtables used for conditions/replace/command */
ptr_value = weechat_hashtable_get (line, "buffer");
if (!ptr_value || (ptr_value[0] != '0') || (ptr_value[1] != 'x'))
goto end;
rc = sscanf (ptr_value + 2, "%lx", &value);
if ((rc == EOF) || (rc < 1))
goto end;
buffer = (void *)value;
weechat_hashtable_set (pointers, "buffer", buffer);
ptr_value = weechat_hashtable_get (line, "tags");
tags = weechat_string_split ((ptr_value) ? ptr_value : "", ",", 0, 0,
&num_tags);
/* build string with tags and commas around: ",tag1,tag2,tag3," */
length = 1 + strlen ((ptr_value) ? ptr_value : "") + 1 + 1;
str_tags = malloc (length);
if (str_tags)
{
snprintf (str_tags, length, ",%s,",
(ptr_value) ? ptr_value : "");
weechat_hashtable_set (extra_vars, "tg_tags", str_tags);
free (str_tags);
}
if (!trigger_callback_set_tags (buffer, (const char **)tags, num_tags,
extra_vars))
{
goto end;
}
/* execute the trigger (conditions, regex, command) */
trigger_callback_execute (trigger, buffer, pointers, extra_vars,
vars_updated);
hashtable = weechat_hashtable_new (32,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_STRING,
NULL, NULL);
if (hashtable)
{
/* copy updated variables into the result "hashtable" */
for (ptr_item = weechat_list_get (vars_updated, 0); ptr_item;
ptr_item = weechat_list_next (ptr_item))
{
ptr_key = weechat_list_string (ptr_item);
if (weechat_hashtable_has_key (extra_vars, ptr_key))
{
if (strcmp (ptr_key, "tg_tags") == 0)
{
/*
* remove commas at the beginning/end of tg_tags and
* rename the key to "tags"
*/
ptr_value = weechat_hashtable_get (extra_vars, ptr_key);
if (ptr_value && ptr_value[0])
{
str_tags = strdup (
(ptr_value[0] == ',') ? ptr_value + 1 : ptr_value);
if (str_tags)
{
if (str_tags[0]
&& (str_tags[strlen (str_tags) - 1] == ','))
{
str_tags[strlen (str_tags) - 1] = '\0';
}
weechat_hashtable_set (hashtable,
"tags", str_tags);
free (str_tags);
}
}
else
{
weechat_hashtable_set (hashtable, "tags", ptr_value);
}
}
else
{
weechat_hashtable_set (
hashtable,
ptr_key,
weechat_hashtable_get (extra_vars, ptr_key));
}
}
}
}
end:
TRIGGER_CALLBACK_CB_END(hashtable);
}
/*
* Callback for a print hooked.
*/
@@ -840,7 +967,7 @@ trigger_callback_print_cb (const void *pointer, void *data,
goto end;
/* execute the trigger (conditions, regex, command) */
trigger_callback_execute (trigger, buffer, pointers, extra_vars);
trigger_callback_execute (trigger, buffer, pointers, extra_vars, NULL);
end:
TRIGGER_CALLBACK_CB_END(trigger_rc);
@@ -874,7 +1001,7 @@ trigger_callback_command_cb (const void *pointer, void *data,
}
/* execute the trigger (conditions, regex, command) */
trigger_callback_execute (trigger, buffer, pointers, extra_vars);
trigger_callback_execute (trigger, buffer, pointers, extra_vars, NULL);
end:
TRIGGER_CALLBACK_CB_END(trigger_rc);
@@ -899,7 +1026,7 @@ trigger_callback_command_run_cb (const void *pointer, void *data,
weechat_hashtable_set (extra_vars, "tg_command", command);
/* execute the trigger (conditions, regex, command) */
trigger_callback_execute (trigger, buffer, pointers, extra_vars);
trigger_callback_execute (trigger, buffer, pointers, extra_vars, NULL);
end:
TRIGGER_CALLBACK_CB_END(trigger_rc);
@@ -949,7 +1076,7 @@ trigger_callback_timer_cb (const void *pointer, void *data,
}
/* execute the trigger (conditions, regex, command) */
trigger_callback_execute (trigger, NULL, pointers, extra_vars);
trigger_callback_execute (trigger, NULL, pointers, extra_vars, NULL);
end:
TRIGGER_CALLBACK_CB_END(trigger_rc);
@@ -972,7 +1099,7 @@ trigger_callback_config_cb (const void *pointer, void *data,
weechat_hashtable_set (extra_vars, "tg_value", value);
/* execute the trigger (conditions, regex, command) */
trigger_callback_execute (trigger, NULL, pointers, extra_vars);
trigger_callback_execute (trigger, NULL, pointers, extra_vars, NULL);
end:
TRIGGER_CALLBACK_CB_END(trigger_rc);
@@ -1011,7 +1138,7 @@ trigger_callback_focus_cb (const void *pointer, void *data,
}
/* execute the trigger (conditions, regex, command) */
trigger_callback_execute (trigger, NULL, pointers, info);
trigger_callback_execute (trigger, NULL, pointers, info, NULL);
end:
TRIGGER_CALLBACK_CB_END(info);
+12
View File
@@ -25,10 +25,13 @@
#define TRIGGER_CALLBACK_CB_INIT(__rc) \
struct t_trigger *trigger; \
struct t_hashtable *pointers, *extra_vars; \
struct t_weelist *vars_updated; \
int trigger_rc; \
pointers = NULL; \
extra_vars = NULL; \
vars_updated = NULL; \
(void) data; \
(void) vars_updated; \
(void) trigger_rc; \
if (!trigger_enabled) \
return __rc; \
@@ -59,11 +62,18 @@
if (!extra_vars) \
goto end;
#define TRIGGER_CALLBACK_CB_NEW_VARS_UPDATED \
vars_updated = weechat_list_new (); \
if (!vars_updated) \
goto end;
#define TRIGGER_CALLBACK_CB_END(__rc) \
if (pointers) \
weechat_hashtable_free (pointers); \
if (extra_vars) \
weechat_hashtable_free (extra_vars); \
if (vars_updated) \
weechat_list_free (vars_updated); \
trigger->hook_running = 0; \
switch (weechat_config_integer ( \
trigger->options[TRIGGER_OPTION_POST_ACTION])) \
@@ -93,6 +103,8 @@ extern char *trigger_callback_modifier_cb (const void *pointer, void *data,
const char *modifier,
const char *modifier_data,
const char *string);
extern struct t_hashtable *trigger_callback_line_cb (const void *pointer, void *data,
struct t_hashtable *line);
extern int trigger_callback_print_cb (const void *pointer, void *data,
struct t_gui_buffer *buffer,
time_t date, int tags_count,
+4 -3
View File
@@ -1153,13 +1153,14 @@ trigger_command_init ()
" addoff: add a trigger (disabled)\n"
" addreplace: add or replace an existing trigger\n"
" name: name of trigger\n"
" hook: signal, hsignal, modifier, print, command, command_run, "
"timer, config, focus\n"
" hook: signal, hsignal, modifier, line, print, command, "
"command_run, timer, config, focus\n"
" arguments: arguments for the hook, depending on hook (separated "
"by semicolons):\n"
" signal: name(s) of signal (required)\n"
" hsignal: name(s) of hsignal (required)\n"
" modifier: name(s) of modifier (required)\n"
" line: list of buffer masks, tags\n"
" print: buffer, tags, message, strip colors\n"
" command: command (required), description, arguments, "
"description of arguments, completion\n"
@@ -1212,7 +1213,7 @@ trigger_command_init ()
" 2. replace text using POSIX extended regular expression(s) (if "
"defined in trigger)\n"
" 3. execute command(s) (if defined in trigger)\n"
" 4. exit with a return code (except for modifiers and focus)\n"
" 4. exit with a return code (except for modifier, line and focus)\n"
" 5. perform post action\n"
"\n"
"Examples (you can also look at default triggers with /trigger "
+30 -4
View File
@@ -49,10 +49,11 @@ char *trigger_option_default[TRIGGER_NUM_OPTIONS] =
{ "on", "signal", "", "", "", "", "ok", "none" };
char *trigger_hook_type_string[TRIGGER_NUM_HOOK_TYPES] =
{ "signal", "hsignal", "modifier", "print", "command", "command_run", "timer",
"config", "focus" };
{ "signal", "hsignal", "modifier", "line", "print", "command", "command_run",
"timer", "config", "focus" };
char *trigger_hook_option_values =
"signal|hsignal|modifier|print|command|command_run|timer|config|focus";
"signal|hsignal|modifier|line|print|command|command_run|timer|config|"
"focus";
char *trigger_hook_default_arguments[TRIGGER_NUM_HOOK_TYPES] =
{ "xxx", "xxx", "xxx", "", "cmd;desc;args;args_desc;%(buffers_names)", "/cmd",
"60000;0;0", "xxx", "chat" };
@@ -262,7 +263,8 @@ trigger_unhook (struct t_trigger *trigger)
void
trigger_hook (struct t_trigger *trigger)
{
char **argv, **argv_eol, *tags, *message, *error1, *error2, *error3;
char **argv, **argv_eol, *buffer_type, *buffer_name, *tags, *message;
char *error1, *error2, *error3;
int i, argc, strip_colors;
long interval, align_second, max_calls;
@@ -329,6 +331,30 @@ trigger_hook (struct t_trigger *trigger)
}
}
break;
case TRIGGER_HOOK_LINE:
buffer_type = NULL;
buffer_name = NULL;
tags = NULL;
if (argv && (argc >= 1))
{
buffer_type = argv[0];
if ((argc >= 2) && (strcmp (argv[1], "*") != 0))
buffer_name = argv[1];
if ((argc >= 3) && (strcmp (argv[2], "*") != 0))
tags = argv[2];
}
trigger->hooks = malloc (sizeof (trigger->hooks[0]));
if (trigger->hooks)
{
trigger->hooks_count = 1;
trigger->hooks[0] = weechat_hook_line (
buffer_type,
buffer_name,
tags,
&trigger_callback_line_cb,
trigger, NULL);
}
break;
case TRIGGER_HOOK_PRINT:
tags = NULL;
message = NULL;
+1
View File
@@ -48,6 +48,7 @@ enum t_trigger_hook_type
TRIGGER_HOOK_SIGNAL = 0,
TRIGGER_HOOK_HSIGNAL,
TRIGGER_HOOK_MODIFIER,
TRIGGER_HOOK_LINE,
TRIGGER_HOOK_PRINT,
TRIGGER_HOOK_COMMAND,
TRIGGER_HOOK_COMMAND_RUN,
+15 -1
View File
@@ -67,7 +67,7 @@ struct timeval;
* please change the date with current one; for a second change at same
* date, increment the 01, otherwise please keep 01.
*/
#define WEECHAT_PLUGIN_API_VERSION "20180520-01"
#define WEECHAT_PLUGIN_API_VERSION "20180812-01"
/* macros for defining plugin infos */
#define WEECHAT_PLUGIN_NAME(__name) \
@@ -709,6 +709,15 @@ struct t_weechat_plugin
const char *ip_address),
const void *callback_pointer,
void *callback_data);
struct t_hook *(*hook_line) (struct t_weechat_plugin *plugin,
const char *buffer_type,
const char *buffer_name,
const char *tags,
struct t_hashtable *(*callback)(const void *pointer,
void *data,
struct t_hashtable *line),
const void *callback_pointer,
void *callback_data);
struct t_hook *(*hook_print) (struct t_weechat_plugin *plugin,
struct t_gui_buffer *buffer,
const char *tags,
@@ -1645,6 +1654,11 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin);
__gnutls_priorities, \
__local_hostname, \
__callback, __pointer, __data)
#define weechat_hook_line(_buffer_type, __buffer_name, __tags, \
__callback, __pointer, __data) \
(weechat_plugin->hook_line)(weechat_plugin, _buffer_type, \
__buffer_name, __tags, __callback, \
__pointer, __data)
#define weechat_hook_print(__buffer, __tags, __msg, __strip__colors, \
__callback, __pointer, __data) \
(weechat_plugin->hook_print)(weechat_plugin, __buffer, __tags, \