#include <sys/socket.h>
#include <sys/types.h>
-#include <linux/types.h>
-#include <linux/netlink.h>
-
#include <libubox/blobmsg_json.h>
#include <libubox/json_script.h>
#include <libubox/runqueue.h>
};
static LIST_HEAD(triggers);
-static struct runqueue q;
+static RUNQUEUE(q, 1);
static const char* rule_handle_var(struct json_script_ctx *ctx, const char *name, struct blob_attr *vars)
{
{
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));
}
free(s);
}
-static void q_empty(struct runqueue *q)
-{
-}
-
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;
}
}
}
-void trigger_init(void)
-{
- runqueue_init(&q);
- q.empty_cb = q_empty;
- q.max_running_tasks = 1;
-}
-
-static int trigger_match(const char *event, const char *match)
+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);
+ 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 (!trigger_match(type, t->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);
}
}
}