Changeset 5798
- Timestamp:
- 03/12/10 19:33:56 (3 years ago)
- Location:
- luci2/ubus
- Files:
-
- 2 added
- 3 modified
-
Makefile (modified) (1 diff)
-
ubus.h (modified) (1 diff)
-
ubus_dispatch.c (modified) (2 diffs)
-
ubus_tree.c (added)
-
ubus_tree.h (added)
Legend:
- Unmodified
- Added
- Removed
-
luci2/ubus/Makefile
r5796 r5798 7 7 all: $(BINARY) 8 8 9 ubus: ubus.c ubus_core.c ubus_msg.c blob.c log.c ubus_dispatch.c hash.c9 ubus: ubus.c ubus_core.c ubus_msg.c blob.c log.c ubus_dispatch.c ubus_tree.c hash.c 10 10 $(CC) -g $(CFLAGS) -o $@ $^ -luci 11 11 -
luci2/ubus/ubus.h
r5796 r5798 5 5 #include "list.h" 6 6 #include "blob.h" 7 #include "ubus_tree.h" 7 8 8 9 #define UBUS_SOCK_PATH "/tmp/ubus-socket" -
luci2/ubus/ubus_dispatch.c
r5796 r5798 10 10 int wildcard; 11 11 uint32_t hash; 12 };13 14 struct ubus_tree15 {16 struct list_head list;17 struct list_head childs;18 struct list_head events;19 struct list_head wildcards;20 const char *name;21 12 }; 22 13 … … 90 81 } 91 82 92 static struct ubus_tree* ubus_tree_alloc(const char *name)93 {94 struct ubus_tree *n = (struct ubus_tree*)malloc(sizeof(struct ubus_tree));95 memset(n, 0, sizeof(struct ubus_tree));96 INIT_LIST_HEAD(&n->childs);97 INIT_LIST_HEAD(&n->events);98 INIT_LIST_HEAD(&n->wildcards);99 n->name = strdup(name);100 return n;101 }102 103 static struct ubus_tree* ubus_tree_find_child(struct list_head *l, const char *name)104 {105 struct list_head *p;106 list_for_each(p, l)107 {108 struct ubus_tree *t = container_of(p, struct ubus_tree, list);109 if(!strcmp(t->name, name))110 return t;111 }112 return 0;113 }114 115 static struct ubus_tree* ubus_tree_find(struct blob_attr *node, int create)116 {117 struct blob_attr *pos;118 int rem;119 struct list_head *t = &tree;120 int c = 0;121 struct ubus_tree *n = 0;122 blob_for_each_attr(pos, node, rem)123 {124 if(!c)125 {126 if(blob_id(pos) != UBUS_ITEM)127 return 0;128 n = ubus_tree_find_child(t, blob_get_string(pos));129 if(n)130 t = &n->childs;131 else if(create)132 c = 1;133 else134 return 0;135 }136 if(c)137 {138 n = ubus_tree_alloc(blob_get_string(pos));139 list_add_tail(&n->list, t);140 t = &n->childs;141 }142 }143 return n;144 }145 146 83 void ubus_dispatch_add(struct ubus_client *u, struct blob_attr *node, int wildcard) 147 84 { 148 85 struct ubus_disp *d; 149 struct ubus_tree *n = (struct ubus_tree*)ubus_tree_find( node, 1);86 struct ubus_tree *n = (struct ubus_tree*)ubus_tree_find(&tree, node, 1); 150 87 LOG("adding event handler %s wildcard=%d\n", ubus_to_string(node), wildcard); 151 88 if(!n)
