X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fprocd.git;a=blobdiff_plain;f=service%2Ftrigger.c;h=4cfea316f2af4b7e5e5c4c241bff230db94a0c2d;hp=6cd94d40809dd7c0985ffedf618c4e31b83c7456;hb=0cf8b0576a66ca28aeec98e19dc9c1cbf4324894;hpb=bc0900b190015b3018adc652d91c4dfd6851aadd diff --git a/service/trigger.c b/service/trigger.c index 6cd94d4..4cfea31 100644 --- a/service/trigger.c +++ b/service/trigger.c @@ -16,9 +16,6 @@ #include #include -#include -#include - #include #include #include @@ -77,6 +74,9 @@ rule_load_script(struct json_script_ctx *ctx, const char *name) { struct trigger *t = container_of(ctx, struct trigger, jctx); + if (strcmp(name, t->type) != 0) + return NULL; + return json_script_file_from_blobmsg(t->type, t->rule, blob_pad_len(t->rule)); } @@ -90,6 +90,7 @@ static void q_job_run(struct runqueue *q, struct runqueue_task *t) static void trigger_free(struct trigger *t) { + json_script_free(&t->jctx); uloop_timeout_cancel(&t->delay); free(t->data); list_del(&t->list); @@ -224,7 +225,7 @@ static void trigger_delay_cb(struct uloop_timeout *tout) { struct trigger *t = container_of(tout, struct trigger, delay); - json_script_run(&t->jctx, "foo", t->data); + json_script_run(&t->jctx, t->type, t->data); free(t->data); t->data = NULL; } @@ -322,21 +323,29 @@ void trigger_init(void) q.max_running_tasks = 1; } -void trigger_event(char *type, struct blob_attr *data) +static bool trigger_match(const char *event, const char *match) +{ + char *wildcard = strstr(match, ".*"); + if (wildcard) + return !strncmp(event, match, wildcard - match); + return !strcmp(event, match); +} + +void trigger_event(const char *type, struct blob_attr *data) { struct trigger *t; list_for_each_entry(t, &triggers, list) { - if (t->pending || t->remove) + if (t->remove) continue; - if (!strcmp(t->type, type)) { - if (t->timeout) { - free(t->data); - t->data = blob_memdup(data); - uloop_timeout_set(&t->delay, t->timeout); - } else { - json_script_run(&t->jctx, "foo", data); - } + if (!trigger_match(type, t->type)) + continue; + if (t->timeout) { + free(t->data); + t->data = blob_memdup(data); + uloop_timeout_set(&t->delay, t->timeout); + } else { + json_script_run(&t->jctx, t->type, data); } } }