summaryrefslogtreecommitdiff
path: root/src/plugins/trigger/trigger-callback.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/trigger/trigger-callback.c')
-rw-r--r--src/plugins/trigger/trigger-callback.c39
1 files changed, 27 insertions, 12 deletions
diff --git a/src/plugins/trigger/trigger-callback.c b/src/plugins/trigger/trigger-callback.c
index afe350624..c2625265d 100644
--- a/src/plugins/trigger/trigger-callback.c
+++ b/src/plugins/trigger/trigger-callback.c
@@ -123,6 +123,21 @@ trigger_callback_get_irc_server_channel (const char *irc_server_name,
}
/*
+ * Sets variables common to all triggers in a hashtable:
+ * - tg_trigger_name
+ */
+
+void
+trigger_callback_set_common_vars (struct t_trigger *trigger,
+ struct t_hashtable *hashtable)
+{
+ if (!trigger || !hashtable)
+ return;
+
+ weechat_hashtable_set (hashtable, "tg_trigger_name", trigger->name);
+}
+
+/*
* Sets variables in "extra_vars" hashtable using tags from message.
*
* Returns:
@@ -514,7 +529,7 @@ trigger_callback_signal_cb (const void *pointer, void *data,
}
/* add data in hashtable used for conditions/replace/command */
- weechat_hashtable_set (extra_vars, "tg_trigger_name", trigger->name);
+ trigger_callback_set_common_vars (trigger, extra_vars);
weechat_hashtable_set (extra_vars, "tg_signal", signal);
ptr_signal_data = NULL;
if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_STRING) == 0)
@@ -590,7 +605,7 @@ trigger_callback_hsignal_cb (const void *pointer, void *data,
}
/* add data in hashtable used for conditions/replace/command */
- weechat_hashtable_set (extra_vars, "tg_trigger_name", trigger->name);
+ trigger_callback_set_common_vars (trigger, extra_vars);
weechat_hashtable_set (extra_vars, "tg_signal", signal);
/* execute the trigger (conditions, regex, command) */
@@ -654,7 +669,7 @@ trigger_callback_modifier_cb (const void *pointer, void *data,
}
/* add data in hashtable used for conditions/replace/command */
- weechat_hashtable_set (extra_vars, "tg_trigger_name", trigger->name);
+ trigger_callback_set_common_vars (trigger, extra_vars);
weechat_hashtable_set (extra_vars, "tg_modifier", modifier);
weechat_hashtable_set (extra_vars, "tg_modifier_data", modifier_data);
weechat_hashtable_set (extra_vars, "tg_string", string);
@@ -827,7 +842,7 @@ trigger_callback_line_cb (const void *pointer, void *data,
weechat_hashtable_remove (extra_vars, "tags");
/* add data in hashtables used for conditions/replace/command */
- weechat_hashtable_set (extra_vars, "tg_trigger_name", trigger->name);
+ trigger_callback_set_common_vars (trigger, extra_vars);
ptr_value = weechat_hashtable_get (line, "buffer");
if (!ptr_value || (ptr_value[0] != '0') || (ptr_value[1] != 'x'))
goto end;
@@ -964,7 +979,7 @@ trigger_callback_print_cb (const void *pointer, void *data,
TRIGGER_CALLBACK_CB_NEW_EXTRA_VARS;
/* add data in hashtables used for conditions/replace/command */
- weechat_hashtable_set (extra_vars, "tg_trigger_name", trigger->name);
+ trigger_callback_set_common_vars (trigger, extra_vars);
weechat_hashtable_set (pointers, "buffer", buffer);
date_tmp = localtime (&date);
if (date_tmp)
@@ -1036,7 +1051,7 @@ trigger_callback_command_cb (const void *pointer, void *data,
TRIGGER_CALLBACK_CB_NEW_EXTRA_VARS;
/* add data in hashtables used for conditions/replace/command */
- weechat_hashtable_set (extra_vars, "tg_trigger_name", trigger->name);
+ trigger_callback_set_common_vars (trigger, extra_vars);
weechat_hashtable_set (pointers, "buffer", buffer);
for (i = 0; i < argc; i++)
{
@@ -1069,7 +1084,7 @@ trigger_callback_command_run_cb (const void *pointer, void *data,
TRIGGER_CALLBACK_CB_NEW_EXTRA_VARS;
/* add data in hashtables used for conditions/replace/command */
- weechat_hashtable_set (extra_vars, "tg_trigger_name", trigger->name);
+ trigger_callback_set_common_vars (trigger, extra_vars);
weechat_hashtable_set (pointers, "buffer", buffer);
weechat_hashtable_set (extra_vars, "tg_command", command);
@@ -1112,7 +1127,7 @@ trigger_callback_timer_cb (const void *pointer, void *data,
TRIGGER_CALLBACK_CB_NEW_EXTRA_VARS;
/* add data in hashtable used for conditions/replace/command */
- weechat_hashtable_set (extra_vars, "tg_trigger_name", trigger->name);
+ trigger_callback_set_common_vars (trigger, extra_vars);
snprintf (str_temp, sizeof (str_temp), "%d", remaining_calls);
weechat_hashtable_set (extra_vars, "tg_remaining_calls", str_temp);
date = time (NULL);
@@ -1146,7 +1161,7 @@ trigger_callback_config_cb (const void *pointer, void *data,
TRIGGER_CALLBACK_CB_NEW_EXTRA_VARS;
/* add data in hashtable used for conditions/replace/command */
- weechat_hashtable_set (extra_vars, "tg_trigger_name", trigger->name);
+ trigger_callback_set_common_vars (trigger, extra_vars);
weechat_hashtable_set (extra_vars, "tg_option", option);
weechat_hashtable_set (extra_vars, "tg_value", value);
@@ -1175,7 +1190,7 @@ trigger_callback_focus_cb (const void *pointer, void *data,
TRIGGER_CALLBACK_CB_NEW_POINTERS;
/* add data in hashtables used for conditions/replace/command */
- weechat_hashtable_set (info, "tg_trigger_name", trigger->name);
+ trigger_callback_set_common_vars (trigger, info);
ptr_value = weechat_hashtable_get (info, "_window");
if (ptr_value && ptr_value[0] && (strncmp (ptr_value, "0x", 2) == 0))
{
@@ -1214,7 +1229,7 @@ trigger_callback_info_cb (const void *pointer, void *data,
TRIGGER_CALLBACK_CB_NEW_EXTRA_VARS;
/* add data in hashtable used for conditions/replace/command */
- weechat_hashtable_set (extra_vars, "tg_trigger_name", trigger->name);
+ trigger_callback_set_common_vars (trigger, extra_vars);
weechat_hashtable_set (extra_vars, "tg_info_name", info_name);
weechat_hashtable_set (extra_vars, "tg_arguments", arguments);
weechat_hashtable_set (extra_vars, "tg_info", "");
@@ -1253,7 +1268,7 @@ trigger_callback_info_hashtable_cb (const void *pointer, void *data,
extra_vars = weechat_hashtable_dup (hashtable);
/* add data in hashtable used for conditions/replace/command */
- weechat_hashtable_set (extra_vars, "tg_trigger_name", trigger->name);
+ trigger_callback_set_common_vars (trigger, extra_vars);
weechat_hashtable_set (extra_vars, "tg_info_name", info_name);
/* execute the trigger (conditions, regex, command) */