diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2019-04-13 13:53:16 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2019-04-13 13:53:16 +0200 |
commit | 30768d4d24a6a9047dabd473cdbce434439d48c2 (patch) | |
tree | 1864c8f39bd8111d3053da6013f3c366036af029 /src/plugins | |
parent | 8bc06ea101ad05466e420e63b46bdc7039991a2e (diff) | |
download | weechat-30768d4d24a6a9047dabd473cdbce434439d48c2.zip |
trigger: add hook "info_hashtable"
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/trigger/trigger-callback.c | 54 | ||||
-rw-r--r-- | src/plugins/trigger/trigger-callback.h | 4 | ||||
-rw-r--r-- | src/plugins/trigger/trigger-command.c | 7 | ||||
-rw-r--r-- | src/plugins/trigger/trigger.c | 30 | ||||
-rw-r--r-- | src/plugins/trigger/trigger.h | 1 |
5 files changed, 88 insertions, 8 deletions
diff --git a/src/plugins/trigger/trigger-callback.c b/src/plugins/trigger/trigger-callback.c index d1765afdd..711dd3647 100644 --- a/src/plugins/trigger/trigger-callback.c +++ b/src/plugins/trigger/trigger-callback.c @@ -1201,6 +1201,60 @@ end: } /* + * Callback for an info_hashtable hooked. + */ + +struct t_hashtable * +trigger_callback_info_hashtable_cb (const void *pointer, void *data, + const char *info_name, + struct t_hashtable *hashtable) +{ + struct t_hashtable *ret_hashtable; + struct t_weelist_item *ptr_item; + const char *ptr_key; + + TRIGGER_CALLBACK_CB_INIT(NULL); + + ret_hashtable = NULL; + + TRIGGER_CALLBACK_CB_NEW_POINTERS; + TRIGGER_CALLBACK_CB_NEW_VARS_UPDATED; + + extra_vars = weechat_hashtable_dup (hashtable); + + /* add data in hashtable used for conditions/replace/command */ + weechat_hashtable_set (extra_vars, "tg_info_name", info_name); + + /* execute the trigger (conditions, regex, command) */ + trigger_callback_execute (trigger, NULL, pointers, extra_vars, + vars_updated); + + ret_hashtable = weechat_hashtable_new (32, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_STRING, + NULL, NULL); + if (ret_hashtable) + { + /* copy updated variables into the result "ret_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)) + { + weechat_hashtable_set ( + ret_hashtable, + ptr_key, + weechat_hashtable_get (extra_vars, ptr_key)); + } + } + } + +end: + TRIGGER_CALLBACK_CB_END(ret_hashtable); +} + +/* * Initializes trigger callback. */ diff --git a/src/plugins/trigger/trigger-callback.h b/src/plugins/trigger/trigger-callback.h index 2abfe5d67..11c8861ae 100644 --- a/src/plugins/trigger/trigger-callback.h +++ b/src/plugins/trigger/trigger-callback.h @@ -131,6 +131,10 @@ extern char *trigger_callback_info_cb (const void *pointer, void *data, const char *info_name, const char *arguments); +extern struct t_hashtable *trigger_callback_info_hashtable_cb (const void *pointer, + void *data, + const char *info_name, + struct t_hashtable *hashtable); extern void trigger_callback_init (); extern void trigger_callback_end (); diff --git a/src/plugins/trigger/trigger-command.c b/src/plugins/trigger/trigger-command.c index 70dd25159..c6db62a26 100644 --- a/src/plugins/trigger/trigger-command.c +++ b/src/plugins/trigger/trigger-command.c @@ -1157,7 +1157,7 @@ trigger_command_init () " addreplace: add or replace an existing trigger\n" " name: name of trigger\n" " hook: signal, hsignal, modifier, line, print, command, " - "command_run, timer, config, focus, info\n" + "command_run, timer, config, focus, info, info_hashtable\n" " arguments: arguments for the hook, depending on hook (separated " "by semicolons):\n" " signal: name(s) of signal (required)\n" @@ -1173,6 +1173,7 @@ trigger_command_init () " config: name(s) of option (required)\n" " focus: name(s) of area (required)\n" " info: name(s) of info (required)\n" + " info_hashtable: name(s) of info (required)\n" " conditions: evaluated conditions for the trigger\n" " regex: one or more regular expressions to replace strings " "in variables\n" @@ -1218,8 +1219,8 @@ 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 modifier, line, focus " - "and info)\n" + " 4. exit with a return code (except for modifier, line, focus, " + "info and info_hashtable)\n" " 5. perform post action\n" "\n" "Examples (you can also look at default triggers with /trigger " diff --git a/src/plugins/trigger/trigger.c b/src/plugins/trigger/trigger.c index a25bb7c10..e5136a780 100644 --- a/src/plugins/trigger/trigger.c +++ b/src/plugins/trigger/trigger.c @@ -50,20 +50,20 @@ char *trigger_option_default[TRIGGER_NUM_OPTIONS] = char *trigger_hook_type_string[TRIGGER_NUM_HOOK_TYPES] = { "signal", "hsignal", "modifier", "line", "print", "command", "command_run", - "timer", "config", "focus", "info" }; + "timer", "config", "focus", "info", "info_hashtable" }; char *trigger_hook_option_values = "signal|hsignal|modifier|line|print|command|command_run|timer|config|" - "focus|info"; + "focus|info|info_hashtable"; 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", "xxx" }; + "/cmd", "60000;0;0", "xxx", "chat", "xxx", "xxx" }; char *trigger_hook_default_rc[TRIGGER_NUM_HOOK_TYPES] = { "ok,ok_eat,error", "ok,ok_eat,error", "", "", "ok,error", "ok,error", - "ok,ok_eat,error", "ok", "ok", "", "" }; + "ok,ok_eat,error", "ok", "ok", "", "", "" }; char *trigger_hook_regex_default_var[TRIGGER_NUM_HOOK_TYPES] = { "tg_signal_data", "", "tg_string", "message", "tg_message", "tg_argv_eol1", - "tg_command", "tg_remaining_calls", "tg_value", "", "tg_info" }; + "tg_command", "tg_remaining_calls", "tg_value", "", "tg_info", "" }; char *trigger_return_code_string[TRIGGER_NUM_RETURN_CODES] = { "ok", "ok_eat", "error" }; @@ -509,6 +509,26 @@ trigger_hook (struct t_trigger *trigger) } } break; + case TRIGGER_HOOK_INFO_HASHTABLE: + if (argv && (argc >= 1)) + { + trigger->hooks = malloc (argc * sizeof (trigger->hooks[0])); + if (trigger->hooks) + { + trigger->hooks_count = argc; + for (i = 0; i < argc; i++) + { + trigger->hooks[i] = weechat_hook_info_hashtable ( + argv[i], + NULL, + NULL, + NULL, + &trigger_callback_info_hashtable_cb, + trigger, NULL); + } + } + } + break; } if (!trigger->hooks) diff --git a/src/plugins/trigger/trigger.h b/src/plugins/trigger/trigger.h index ce7ec21e3..319343389 100644 --- a/src/plugins/trigger/trigger.h +++ b/src/plugins/trigger/trigger.h @@ -56,6 +56,7 @@ enum t_trigger_hook_type TRIGGER_HOOK_CONFIG, TRIGGER_HOOK_FOCUS, TRIGGER_HOOK_INFO, + TRIGGER_HOOK_INFO_HASHTABLE, /* number of hook types */ TRIGGER_NUM_HOOK_TYPES, }; |