add Lua bindings for ubus events
[project/ubus.git] / ubusd_event.c
index 87213b3..85031a6 100644 (file)
@@ -1,3 +1,16 @@
+/*
+ * Copyright (C) 2011 Felix Fietkau <nbd@openwrt.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1
+ * as published by the Free Software Foundation
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
 #include <arpa/inet.h>
 #include "ubusd.h"
 
@@ -46,7 +59,7 @@ static int ubusd_alloc_event_pattern(struct ubus_client *cl, struct blob_attr *m
        struct event_source *ev;
        struct ubus_object *obj;
        struct blob_attr *attr[EVREG_LAST];
-       char *pattern;
+       char *pattern, *name;
        uint32_t id;
        bool partial = false;
        int len;
@@ -82,8 +95,9 @@ static int ubusd_alloc_event_pattern(struct ubus_client *cl, struct blob_attr *m
        list_add(&ev->list, &obj->events);
        ev->obj = obj;
        ev->partial = partial;
-       ev->avl.key = (void *) (ev + 1);
-       strcpy(ev->avl.key, pattern);
+       name = (char *) (ev + 1);
+       strcpy(name, pattern);
+       ev->avl.key = name;
        avl_insert(&patterns, &ev->avl);
 
        return 0;
@@ -120,7 +134,7 @@ static void ubusd_send_event_msg(struct ubus_msg_buf **ub, struct ubus_client *c
        ubus_msg_send(obj->client, *ub, false);
 }
 
-bool strmatch_len(const char *s1, const char *s2, int *len)
+static bool strmatch_len(const char *s1, const char *s2, int *len)
 {
        for (*len = 0; s1[*len] == s2[*len]; (*len)++)
                if (!s1[*len])