Changeset 5692

Show
Ignore:
Timestamp:
02/28/10 01:52:44 (3 years ago)
Author:
blogic
Message:

adds cbi_create_instance to allow creating instances of template references

Location:
luci2/cbi2
Files:
9 modified

Legend:

Unmodified
Added
Removed
  • luci2/cbi2/cbi.c

    r5689 r5692  
    9898            return p->value; 
    9999    } 
    100     if(e->ref) 
    101         list_for_each(q, &e->ref->properties) 
    102         { 
    103             struct cbi_property *p = container_of(q, struct cbi_property, list); 
    104             if(!strcmp(p->key, key)) 
    105                 return p->value; 
    106         } 
    107100    return 0; 
    108101} 
     
    191184        } 
    192185    } 
    193     if(e->ref) 
    194         return cbi_find_element(e->ref, id); 
    195186    return 0; 
    196187} 
     
    248239        return 0; 
    249240    } 
     241    element = element2; 
     242    rem = rem2; 
    250243    for(; 
    251244        (blob_pad_len(element2) <= rem2) && (blob_pad_len(element2) >= sizeof(struct blob_attr)); 
     
    269262        } 
    270263    } 
     264    if(e->w->caps & CAP_TEMPLATE) 
     265    { 
     266        e->blob = (struct cbi_blob*)malloc(sizeof(struct cbi_blob)); 
     267        e->blob->rem = rem; 
     268        e->blob->blob = malloc(rem); 
     269        memcpy(e->blob->blob, element, rem); 
     270    } 
    271271    return e; 
     272} 
     273 
     274void cbi_create_instance(struct cbi_ctx *ctx, struct cbi_element *e1, struct cbi_element *e2) 
     275{ 
     276    struct blob_attr *element = (struct blob_attr*)e2->blob->blob; 
     277    int rem = e2->blob->rem; 
     278    int sub_count = 0; 
     279    for(; 
     280        (blob_pad_len(element) <= rem) && (blob_pad_len(element) >= sizeof(struct blob_attr)); 
     281        rem -= blob_pad_len(element), element = blob_next(element)) 
     282    { 
     283        struct cbi_element *sub_e; 
     284        switch(blob_id(element)) 
     285        { 
     286        case CBI_PROPERTY: 
     287        case CBI_VALUE: 
     288            break; 
     289        case CBI_ELEMENT: 
     290            sub_e = cbi_parse_element(ctx, element, &sub_count, e1); 
     291            if(sub_e) 
     292                list_add_tail(&sub_e->list, &e1->elements); 
     293            break; 
     294        default: 
     295            LOG("unknown blob_id %d unknown\n", blob_id(element)); 
     296            abort(); 
     297            break; 
     298        } 
     299    } 
    272300} 
    273301 
     
    288316{ 
    289317    struct list_head *p; 
     318    if(e->w->caps & CAP_TEMPLATE) 
     319        return; 
    290320    widget_verify(ctx, e); 
    291321    if(e->broken) 
     
    481511    if(e->w->caps & CAP_TEMPLATE) 
    482512        return; 
    483     if(e->ref) 
    484         if(!nl && !list_empty(&e->ref->elements)) 
    485             nl = '\n'; 
    486513    print_spaces(depth); 
    487514    printf("<%s:%s", e->namespace, e->widget); 
     
    505532        cbi_dump_element(e, depth + 1); 
    506533    } 
    507     if(e->ref) 
    508         list_for_each(p, &e->ref->elements) 
    509         { 
    510             struct cbi_element *e = container_of(p, struct cbi_element, list); 
    511             cbi_dump_element(e, depth + 1); 
    512         } 
    513534    if(nl) 
    514535        print_spaces(depth); 
  • luci2/cbi2/cbi.h

    r5689 r5692  
    8888}; 
    8989 
     90struct cbi_blob 
     91{ 
     92    int rem; 
     93    void *blob; 
     94}; 
     95 
    9096struct cbi_element 
    9197{ 
     
    98104 
    99105    struct cbi_element *parent; 
    100     struct cbi_element *ref; 
     106    struct cbi_blob *blob; 
    101107    struct cbi_source *source; 
    102108    void *source_priv; 
     
    130136void cbi_request(struct cbi_ctx *ctx, char *request); 
    131137const char* cbi_virt_path(struct cbi_ctx *ctx, const char *path, const char *file); 
     138void cbi_create_instance(struct cbi_ctx *ctx, struct cbi_element *e1, struct cbi_element *e2); 
    132139 
    133140void cbi_widget_register(char *name, struct cbi_widget *w); 
  • luci2/cbi2/example.uvl

    r5682 r5692  
    3131        }, 
    3232        option { 
     33            name = "mtu", 
     34            type = "ipaddr", 
     35        }, 
     36        option { 
     37            name = "gateway", 
     38            type = "netmask", 
     39        }, 
     40        option { 
    3341            name = "ipaddr", 
    3442            type = "ipaddr", 
     
    3644        option { 
    3745            name = "netmask", 
     46            type = "netmask", 
     47        }, 
     48        option { 
     49            name = "dns1", 
     50            type = "ipaddr", 
     51        }, 
     52        option { 
     53            name = "dns2", 
    3854            type = "netmask", 
    3955        }, 
  • luci2/cbi2/network.luci

    r5689 r5692  
    2828<luci:tsection name="dhcp_lease"> 
    2929    <luci:title>DHCP lease</luci:title> 
    30     <luci:option src=".ipaddr">IP</luci:option> 
     30    <luci:option src=".ipaddr1">IP</luci:option> 
    3131    <luci:option src=".netmask" >Netmask</luci:option> 
    3232</luci:tsection> 
     
    3434<luci:page src="network"> 
    3535    <luci:section ref="network.simple" src="wan"> 
    36         <luci:section package="dhcp" src="dhcp"> 
     36        <luci:section package="dhcp" src="dhcp.dhcp"> 
    3737            <luci:option src=".enable">Enable</luci:option> 
    3838            <luci:option src=".start">start_ip</luci:option> 
    3939            <luci:option src=".stop">stop_ip</luci:option> 
    40             <luci:foreach ref="network.dhcp_lease" package="dhcp" src=".leases"> 
     40            <luci:foreach ref="network.dhcp_lease" src=".leases"> 
    4141                <luci:filter net="wan"/> 
    4242            </luci:foreach> 
  • luci2/cbi2/sources/uci.c

    r5689 r5692  
    111111    } else if(!dot1 && !dot2) 
    112112    { 
    113         if(use_parent || (e->w->caps & CAP_OPTION)) 
     113        if(e->w->caps & CAP_OPTION) 
    114114            p->option = strdup(tmp); 
    115115        else if(e->w->caps & CAP_SECTION) 
  • luci2/cbi2/widget.c

    r5687 r5692  
    107107{ 
    108108    const char *ref = cbi_find_prop(e, "ref"); 
     109    struct cbi_element *r; 
    109110    if(!ref) 
    110111        return 0; 
    111     e->ref = cbi_resolv(ctx, e, ref); 
    112     if(!e->ref) 
     112    r = cbi_resolv(ctx, e, ref); 
     113    if(!r) 
    113114    { 
    114115        CBI_BROKEN(e); 
     
    116117        return 1; 
    117118    } 
     119    cbi_create_instance(ctx, e, r); 
    118120    return 0; 
    119121} 
  • luci2/cbi2/widgets/foreach.c

    r5680 r5692  
    99    { "src", PROP_REQUIRED }, 
    1010    { "id", PROP_REQUIRED }, 
    11     { "package", PROP_OPTIONAL }, 
    1211}; 
    1312 
    1413struct cbi_widget foreach = { 
    15     .caps = CAP_DATA | CAP_PAGE | CAP_PACKAGE, 
     14    .caps = CAP_DATA | CAP_PACKAGE | CAP_SECTION, 
    1615    .parent_caps = CAP_SECTION, 
    1716    .init = foreach_init, 
  • luci2/cbi2/widgets/option.c

    r5680 r5692  
    44    { "src", PROP_REQUIRED }, 
    55    { "id", PROP_REQUIRED }, 
    6     { "section", PROP_OPTIONAL }, 
    7     { "package", PROP_OPTIONAL }, 
    86}; 
    97 
  • luci2/cbi2/widgets/section.c

    r5686 r5692  
    99    { "id", PROP_REQUIRED }, 
    1010    { "src", PROP_OPTIONAL }, 
    11     { "package", PROP_OPTIONAL }, 
    1211    { "ref", PROP_OPTIONAL }, 
    1312};