Changeset 5692
- Timestamp:
- 02/28/10 01:52:44 (3 years ago)
- Location:
- luci2/cbi2
- Files:
-
- 9 modified
-
cbi.c (modified) (7 diffs)
-
cbi.h (modified) (3 diffs)
-
example.uvl (modified) (2 diffs)
-
network.luci (modified) (2 diffs)
-
sources/uci.c (modified) (1 diff)
-
widget.c (modified) (2 diffs)
-
widgets/foreach.c (modified) (1 diff)
-
widgets/option.c (modified) (1 diff)
-
widgets/section.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
luci2/cbi2/cbi.c
r5689 r5692 98 98 return p->value; 99 99 } 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 }107 100 return 0; 108 101 } … … 191 184 } 192 185 } 193 if(e->ref)194 return cbi_find_element(e->ref, id);195 186 return 0; 196 187 } … … 248 239 return 0; 249 240 } 241 element = element2; 242 rem = rem2; 250 243 for(; 251 244 (blob_pad_len(element2) <= rem2) && (blob_pad_len(element2) >= sizeof(struct blob_attr)); … … 269 262 } 270 263 } 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 } 271 271 return e; 272 } 273 274 void 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 } 272 300 } 273 301 … … 288 316 { 289 317 struct list_head *p; 318 if(e->w->caps & CAP_TEMPLATE) 319 return; 290 320 widget_verify(ctx, e); 291 321 if(e->broken) … … 481 511 if(e->w->caps & CAP_TEMPLATE) 482 512 return; 483 if(e->ref)484 if(!nl && !list_empty(&e->ref->elements))485 nl = '\n';486 513 print_spaces(depth); 487 514 printf("<%s:%s", e->namespace, e->widget); … … 505 532 cbi_dump_element(e, depth + 1); 506 533 } 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 }513 534 if(nl) 514 535 print_spaces(depth); -
luci2/cbi2/cbi.h
r5689 r5692 88 88 }; 89 89 90 struct cbi_blob 91 { 92 int rem; 93 void *blob; 94 }; 95 90 96 struct cbi_element 91 97 { … … 98 104 99 105 struct cbi_element *parent; 100 struct cbi_ element *ref;106 struct cbi_blob *blob; 101 107 struct cbi_source *source; 102 108 void *source_priv; … … 130 136 void cbi_request(struct cbi_ctx *ctx, char *request); 131 137 const char* cbi_virt_path(struct cbi_ctx *ctx, const char *path, const char *file); 138 void cbi_create_instance(struct cbi_ctx *ctx, struct cbi_element *e1, struct cbi_element *e2); 132 139 133 140 void cbi_widget_register(char *name, struct cbi_widget *w); -
luci2/cbi2/example.uvl
r5682 r5692 31 31 }, 32 32 option { 33 name = "mtu", 34 type = "ipaddr", 35 }, 36 option { 37 name = "gateway", 38 type = "netmask", 39 }, 40 option { 33 41 name = "ipaddr", 34 42 type = "ipaddr", … … 36 44 option { 37 45 name = "netmask", 46 type = "netmask", 47 }, 48 option { 49 name = "dns1", 50 type = "ipaddr", 51 }, 52 option { 53 name = "dns2", 38 54 type = "netmask", 39 55 }, -
luci2/cbi2/network.luci
r5689 r5692 28 28 <luci:tsection name="dhcp_lease"> 29 29 <luci:title>DHCP lease</luci:title> 30 <luci:option src=".ipaddr ">IP</luci:option>30 <luci:option src=".ipaddr1">IP</luci:option> 31 31 <luci:option src=".netmask" >Netmask</luci:option> 32 32 </luci:tsection> … … 34 34 <luci:page src="network"> 35 35 <luci:section ref="network.simple" src="wan"> 36 <luci:section package="dhcp" src="dhcp ">36 <luci:section package="dhcp" src="dhcp.dhcp"> 37 37 <luci:option src=".enable">Enable</luci:option> 38 38 <luci:option src=".start">start_ip</luci:option> 39 39 <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"> 41 41 <luci:filter net="wan"/> 42 42 </luci:foreach> -
luci2/cbi2/sources/uci.c
r5689 r5692 111 111 } else if(!dot1 && !dot2) 112 112 { 113 if( use_parent || (e->w->caps & CAP_OPTION))113 if(e->w->caps & CAP_OPTION) 114 114 p->option = strdup(tmp); 115 115 else if(e->w->caps & CAP_SECTION) -
luci2/cbi2/widget.c
r5687 r5692 107 107 { 108 108 const char *ref = cbi_find_prop(e, "ref"); 109 struct cbi_element *r; 109 110 if(!ref) 110 111 return 0; 111 e->ref= cbi_resolv(ctx, e, ref);112 if(! e->ref)112 r = cbi_resolv(ctx, e, ref); 113 if(!r) 113 114 { 114 115 CBI_BROKEN(e); … … 116 117 return 1; 117 118 } 119 cbi_create_instance(ctx, e, r); 118 120 return 0; 119 121 } -
luci2/cbi2/widgets/foreach.c
r5680 r5692 9 9 { "src", PROP_REQUIRED }, 10 10 { "id", PROP_REQUIRED }, 11 { "package", PROP_OPTIONAL },12 11 }; 13 12 14 13 struct cbi_widget foreach = { 15 .caps = CAP_DATA | CAP_PA GE | CAP_PACKAGE,14 .caps = CAP_DATA | CAP_PACKAGE | CAP_SECTION, 16 15 .parent_caps = CAP_SECTION, 17 16 .init = foreach_init, -
luci2/cbi2/widgets/option.c
r5680 r5692 4 4 { "src", PROP_REQUIRED }, 5 5 { "id", PROP_REQUIRED }, 6 { "section", PROP_OPTIONAL },7 { "package", PROP_OPTIONAL },8 6 }; 9 7 -
luci2/cbi2/widgets/section.c
r5686 r5692 9 9 { "id", PROP_REQUIRED }, 10 10 { "src", PROP_OPTIONAL }, 11 { "package", PROP_OPTIONAL },12 11 { "ref", PROP_OPTIONAL }, 13 12 };
