From 386dfd4cdb444633861a812c645d56bd5c329c78 Mon Sep 17 00:00:00 2001 From: John Crispin Date: Wed, 4 Jun 2014 19:36:03 +0100 Subject: add wildcard support to trigger matching code Signed-off-by: John Crispin --- service/trigger.c | 10 +++++++++- service/watch.c | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'service') diff --git a/service/trigger.c b/service/trigger.c index 9fb77cd..ced758b 100644 --- a/service/trigger.c +++ b/service/trigger.c @@ -323,6 +323,14 @@ void trigger_init(void) q.max_running_tasks = 1; } +static int 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; @@ -330,7 +338,7 @@ void trigger_event(const char *type, struct blob_attr *data) list_for_each_entry(t, &triggers, list) { if (t->pending || t->remove) continue; - if (!strcmp(t->type, type)) { + if (!trigger_match(type, t->type)) { if (t->timeout) { free(t->data); t->data = blob_memdup(data); diff --git a/service/watch.c b/service/watch.c index 1d7cf78..fd44a16 100644 --- a/service/watch.c +++ b/service/watch.c @@ -104,7 +104,7 @@ watch_notify_cb(struct ubus_context *ctx, struct ubus_object *obj, char *str; str = blobmsg_format_json(msg, true); - LOG("Received ubus notify '%s': %s\n", method, str); + DEBUG(3, "Received ubus notify '%s': %s\n", method, str); free(str); } -- cgit v1.2.3