Changeset 5798

Show
Ignore:
Timestamp:
03/12/10 19:33:56 (3 years ago)
Author:
blogic
Message:

split tree functions into its own files

Location:
luci2/ubus
Files:
2 added
3 modified

Legend:

Unmodified
Added
Removed
  • luci2/ubus/Makefile

    r5796 r5798  
    77all: $(BINARY) 
    88 
    9 ubus: ubus.c ubus_core.c ubus_msg.c blob.c log.c ubus_dispatch.c hash.c  
     9ubus: ubus.c ubus_core.c ubus_msg.c blob.c log.c ubus_dispatch.c ubus_tree.c hash.c  
    1010    $(CC) -g $(CFLAGS) -o $@ $^ -luci 
    1111 
  • luci2/ubus/ubus.h

    r5796 r5798  
    55#include "list.h" 
    66#include "blob.h" 
     7#include "ubus_tree.h" 
    78 
    89#define UBUS_SOCK_PATH "/tmp/ubus-socket" 
  • luci2/ubus/ubus_dispatch.c

    r5796 r5798  
    1010    int wildcard; 
    1111    uint32_t hash; 
    12 }; 
    13  
    14 struct ubus_tree 
    15 { 
    16     struct list_head list; 
    17     struct list_head childs; 
    18     struct list_head events; 
    19     struct list_head wildcards; 
    20     const char *name; 
    2112}; 
    2213 
     
    9081} 
    9182 
    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             else 
    134                 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  
    14683void ubus_dispatch_add(struct ubus_client *u, struct blob_attr *node, int wildcard) 
    14784{ 
    14885    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); 
    15087    LOG("adding event handler %s wildcard=%d\n", ubus_to_string(node), wildcard); 
    15188    if(!n)