summaryrefslogtreecommitdiff
path: root/src/plugins/trigger/trigger-callback.c
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2014-01-28 08:23:50 +0100
committerSebastien Helleu <flashcode@flashtux.org>2014-02-09 12:55:40 +0100
commite0de501a0a674424b0f71013d761dc523eadea02 (patch)
treebe73984a54be2d30bc71b6f1d84da94691356a59 /src/plugins/trigger/trigger-callback.c
parent2e28f7c6bee20e836c1a3b4f91e5139564b2b666 (diff)
downloadweechat-e0de501a0a674424b0f71013d761dc523eadea02.zip
trigger: add hsignal
Diffstat (limited to 'src/plugins/trigger/trigger-callback.c')
-rw-r--r--src/plugins/trigger/trigger-callback.c95
1 files changed, 91 insertions, 4 deletions
diff --git a/src/plugins/trigger/trigger-callback.c b/src/plugins/trigger/trigger-callback.c
index 38dd3dc15..a1c1f1d73 100644
--- a/src/plugins/trigger/trigger-callback.c
+++ b/src/plugins/trigger/trigger-callback.c
@@ -281,11 +281,98 @@ int
trigger_callback_hsignal_cb (void *data, const char *signal,
struct t_hashtable *hashtable)
{
- (void) data;
- (void) signal;
- (void) hashtable;
+ struct t_trigger *trigger;
+ struct t_hashtable *pointers, *extra_vars;
+ const char *type_values, *command;
+ int rc;
+
+ /* get trigger pointer, return immediately if not found or trigger running */
+ trigger = (struct t_trigger *)data;
+ if (!trigger || trigger->hook_running)
+ return WEECHAT_RC_OK;
+
+ trigger->hook_count_cb++;
+ trigger->hook_running = 1;
+
+ pointers = NULL;
+ extra_vars = NULL;
+
+ rc = trigger_return_code[weechat_config_integer (trigger->options[TRIGGER_OPTION_RETURN_CODE])];
+
+ /*
+ * in a hsignal, the only possible action is to execute a command;
+ * so if the command is empty, just exit without checking conditions
+ */
+ command = weechat_config_string (trigger->options[TRIGGER_OPTION_COMMAND]);
+ if (!command || !command[0])
+ goto end;
+
+ /* duplicate hashtable */
+ if (hashtable
+ && (strcmp (weechat_hashtable_get_string (hashtable, "type_keys"), "string") == 0))
+ {
+ type_values = weechat_hashtable_get_string (hashtable, "type_values");
+ if (strcmp (type_values, "pointer") == 0)
+ {
+ pointers = weechat_hashtable_dup (hashtable);
+ if (!pointers)
+ goto end;
+ }
+ else if (strcmp (type_values, "pointer") == 0)
+ {
+ extra_vars = weechat_hashtable_dup (hashtable);
+ if (!extra_vars)
+ goto end;
+ }
+ }
+
+ /* create hashtable (if not already created) */
+ if (!extra_vars)
+ {
+ extra_vars = weechat_hashtable_new (32,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING,
+ NULL,
+ NULL);
+ if (!extra_vars)
+ goto end;
+ }
+
+ /* add data in hashtable used for conditions/replace/command */
+ weechat_hashtable_set (extra_vars, "tg_signal", signal);
+
+ /* display debug info on trigger buffer */
+ if (!trigger_buffer && (weechat_trigger_plugin->debug >= 1))
+ trigger_buffer_open (0);
+ if (trigger_buffer)
+ {
+ weechat_printf_tags (trigger_buffer, "no_trigger",
+ "hsignal\t%s%s",
+ weechat_color ("chat_channel"),
+ trigger->name);
+ trigger_buffer_display_hashtable ("pointers", pointers);
+ trigger_buffer_display_hashtable ("extra_vars", extra_vars);
+ }
+
+ /* check conditions */
+ if (!trigger_callback_check_conditions (trigger, pointers, extra_vars))
+ goto end;
- return WEECHAT_RC_OK;
+ /* replace text with regex */
+ trigger_callback_replace_regex (trigger, extra_vars);
+
+ /* execute command */
+ trigger_callback_run_command (trigger, NULL, pointers, extra_vars);
+
+end:
+ if (pointers)
+ weechat_hashtable_free (pointers);
+ if (extra_vars)
+ weechat_hashtable_free (extra_vars);
+
+ trigger->hook_running = 0;
+
+ return rc;
}
/*