Changeset 5686
- Timestamp:
- 02/26/10 02:22:37 (3 years ago)
- Location:
- luci2/cbi2
- Files:
-
- 7 added
- 9 modified
-
cbi.c (modified) (8 diffs)
-
cbi.h (modified) (6 diffs)
-
lang.c (modified) (1 diff)
-
log.c (added)
-
log.h (added)
-
luci.c (modified) (4 diffs)
-
Makefile (modified) (3 diffs)
-
network.luci (modified) (2 diffs)
-
session.h (added)
-
source.c (added)
-
source.h (added)
-
sources (added)
-
sources/uci.c (added)
-
widget.c (modified) (8 diffs)
-
widgets/section.c (modified) (1 diff)
-
widgets/tsection.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
luci2/cbi2/cbi.c
r5683 r5686 162 162 *buffer = 0; 163 163 cbi_get_element_id(e->parent, buffer, 1); 164 printf("generating id for %s\n", tmp);164 LOG("generating id for %s\n", tmp); 165 165 (*count)++; 166 166 } … … 238 238 break; 239 239 default: 240 printf("unknown blob_id %d unknown\n", blob_id(element));240 LOG("unknown blob_id %d unknown\n", blob_id(element)); 241 241 abort(); 242 242 break; … … 259 259 break; 260 260 default: 261 printf("unknown blob_id %d unknown\n", blob_id(element2));261 LOG("unknown blob_id %d unknown\n", blob_id(element2)); 262 262 abort(); 263 263 break; … … 298 298 { 299 299 struct list_head *p; 300 printf("indexing %s\n", f->name);300 LOG("indexing %s\n", f->name); 301 301 list_for_each(p, &f->e.elements) 302 302 { … … 325 325 { 326 326 struct list_head *p; 327 printf("unindexing %s\n", f->name);327 LOG("unindexing %s\n", f->name); 328 328 list_for_each(p, &f->e.elements) 329 329 { … … 366 366 struct list_head *p, *q; 367 367 cbi_index_remove(file); 368 printf("dropping %s\n", file->name);368 LOG("dropping %s\n", file->name); 369 369 list_for_each_safe(p, q, &file->e.elements) 370 370 { … … 417 417 } 418 418 } 419 printf("loading %s\n", filename);419 LOG("loading %s\n", filename); 420 420 fd = open(filename, O_RDONLY); 421 421 if(fd < 0) … … 603 603 char *out = strdup(gl.gl_pathv[i]); 604 604 out[strlen(out) - 1] = 'o'; 605 printf("compiling %s -> %s\n", gl.gl_pathv[i], out);605 LOG("compiling %s -> %s\n", gl.gl_pathv[i], out); 606 606 if(!lucic_main(gl.gl_pathv[i], out)) 607 607 { 608 printf("deleting %s\n", gl.gl_pathv[i]);608 LOG("deleting %s\n", gl.gl_pathv[i]); 609 609 unlink(gl.gl_pathv[i]); 610 610 } else { 611 printf("failed\n");611 LOG("failed\n"); 612 612 } 613 613 } -
luci2/cbi2/cbi.h
r5684 r5686 9 9 10 10 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) 11 12 #define CBI_BROKEN(e) {e->broken = 1;} 11 13 12 14 #define CBI_LUCI 0x4C554349 … … 42 44 }; 43 45 46 #define SRC_PACKAGE 0x01 47 #define SRC_SECTION 0x02 48 #define SRC_OPTION 0x03 49 #define SRC_MASK 0x03 50 #define SCAP_READ 0x04 51 #define SCAP_WRITE 0x08 52 53 struct cbi_element; 54 struct cbi_source 55 { 56 struct list_head list; 57 const char *name; 58 uint64_t caps; 59 void *priv; 60 int (*init)(struct cbi_ctx *ctx, struct cbi_element *e); 61 }; 62 44 63 #define CAP_SECTION 0x0001 45 64 #define CAP_PACKAGE 0x0002 … … 49 68 #define CAP_FILE 0x0020 50 69 #define CAP_TEMPLATE 0x0040 51 struct cbi_element;52 70 struct cbi_element 53 71 { … … 57 75 struct list_head index; 58 76 59 u nsigned longcaps;77 uint64_t caps; 60 78 int broken; 61 79 62 80 struct cbi_element *parent; 63 81 struct cbi_element *ref; 82 struct cbi_source *source; 64 83 65 84 char *namespace; … … 92 111 struct list_head list; 93 112 char *name; 94 int caps;95 int parent_caps;113 uint64_t caps; 114 uint64_t parent_caps; 96 115 struct cbi_widget_property *props; 97 116 int prop_count; … … 122 141 123 142 #include "widget.h" 143 #include "log.h" 144 #include "source.h" 124 145 125 146 #endif -
luci2/cbi2/lang.c
r5683 r5686 8 8 if(ctx->lmo) 9 9 lmo_close(ctx->lmo); 10 printf("loading %s\n", cbi_virt_path(ctx, ctx->path, file));10 LOG("loading %s\n", cbi_virt_path(ctx, ctx->path, file)); 11 11 ctx->lmo = (lmo_archive_t *)lmo_open(cbi_virt_path(ctx, ctx->path, file)); 12 12 if(!ctx->lmo) 13 13 { 14 printf("failed to load language file %s\n", file);14 LOG("failed to load language file %s\n", file); 15 15 if(strcmp(lang, "en")) 16 16 lmo_load_lang(ctx, "en"); -
luci2/cbi2/luci.c
r5684 r5686 11 11 #include <sys/stat.h> 12 12 #include <sys/mman.h> 13 #include <syslog.h> 13 14 14 15 #define _GNU_SOURCE … … 25 26 void handler_INT(int signo) 26 27 { 27 printf("away we go\n");28 LOG("away we go\n"); 28 29 loop = 0; 29 30 } … … 144 145 daemon(0,0); 145 146 147 log_start(daemonize); 148 146 149 uctx = ucix_init_path(vpath, "luci", 0); 147 150 if(uctx) … … 176 179 } 177 180 cbi_free_context(ctx); 181 closelog(); 178 182 return 0; 179 183 } -
luci2/cbi2/Makefile
r5683 r5686 8 8 all: $(BINARY) 9 9 10 luci: luci.c lucic.c lucip.c uci.c json.c cbi.c s ession.c u_sock.c validate.c uvl.c lang.c lmo_core.c lmo_hash.c blob.c widget.c validator/boolean.c widgets/page.c widgets/form.c widgets/section.c widgets/option.c widgets/field.c widgets/foreach.c widgets/file.c widgets/tsection.c11 $(CC) $(CFLAGS) -o $@ $^ -luci -ljson -lcrypt 10 luci: luci.c lucic.c lucip.c uci.c json.c cbi.c source.c session.c u_sock.c validate.c uvl.c lang.c blob.c widget.c log.c validator/boolean.c widgets/page.c widgets/form.c widgets/section.c widgets/option.c widgets/field.c widgets/foreach.c widgets/file.c widgets/tsection.c sources/uci.c liblmo.a 11 $(CC) $(CFLAGS) -o $@ $^ -luci -ljson -lcrypt 12 12 13 13 luci-cli: luci-cli.c … … 20 20 $(CC) $(CFLAGS) $(LIBS) -o $@ $^ 21 21 22 liblmo.a: lmo_core. c lmo_hash.c22 liblmo.a: lmo_core.o lmo_hash.o 23 23 $(AR) rc $@ $^ 24 24 … … 28 28 clean: 29 29 rm -f $(BINARY) *.luco *.o widgets/*.o validators/*.o *.lmo 30 rm -rf ./root 30 31 31 32 run: $(BINARY) -
luci2/cbi2/network.luci
r5680 r5686 2 2 <luci:title>Page title</luci:title> 3 3 Page text 4 <luci:section name="wan">4 <luci:section src="wan"> 5 5 <luci:title>Form title</luci:title> 6 6 Form text … … 33 33 34 34 <luci:page src="network"> 35 <luci:section ref="network.simple" name="wan">36 <luci:section package="dhcp" name="dhcp">35 <luci:section ref="network.simple" src="wan"> 36 <luci:section package="dhcp" src="dhcp"> 37 37 <luci:option src=".enable">Enable</luci:option> 38 38 <luci:option src=".start">start_ip</luci:option> -
luci2/cbi2/widget.c
r5682 r5686 19 19 struct list_head *q; 20 20 int i; 21 char buf[256];22 *buf = 0;23 21 for(i = 0; i < w->prop_count; i++) 24 22 { … … 26 24 if(!cbi_find_prop(e, w->props[i].name)) 27 25 { 28 cbi_get_element_id(e, buf, 1); 29 printf("%s - missing required property %s\n", buf, w->props[i].name); 30 e->broken = 1; 26 CBILOG(e, "missing required property %s\n", w->props[i].name); 27 CBI_BROKEN(e); 31 28 return 1; 32 29 } … … 37 34 if(!widget_find_prop(w, p->key)) 38 35 { 39 cbi_get_element_id(e, buf, 1); 40 printf("%s - unknown property %s\n", buf, p->key); 41 e->broken = 1; 36 CBILOG(e, "unknown property %s\n", p->key); 37 CBI_BROKEN(e); 42 38 return 1; 43 39 } … … 47 43 static int widget_verify_parent_caps(struct cbi_element *e, struct cbi_widget *w) 48 44 { 49 char buf[256];50 *buf = 0;51 45 if(!w->parent_caps) 52 46 return 0; … … 56 50 return 0; 57 51 error: 58 e->broken = 1; 59 cbi_get_element_id(e, buf, 1); 60 printf("%s - parent capabilities were not meet\n", buf); 61 return 1; 62 } 63 64 static int widget_resolv_data(struct cbi_element *e, struct cbi_widget *w) 65 { 66 if(!(w->caps | CAP_DATA)) 67 return 0; 68 if(w->caps & CAP_SECTION) 69 { 70 } else if(w->caps & CAP_PACKAGE) 71 { 72 } else if(w->caps & CAP_OPTION) 73 { 74 } 52 CBI_BROKEN(e); 53 CBILOG(e, "parent capabilities were not meet\n"); 75 54 return 1; 76 55 } … … 128 107 { 129 108 const char *ref = cbi_find_prop(e, "ref"); 130 char buf[256];131 *buf = 0;132 109 if(!ref) 133 110 return 0; … … 135 112 if(!e->ref) 136 113 { 137 e->broken = 1; 138 cbi_get_element_id(e, buf, 1); 139 printf("%s - unable to resolv reference for \"%s\"\n", buf, ref); 114 CBI_BROKEN(e); 115 CBILOG(e, "unable to resolv reference for \"%s\"\n", ref); 140 116 return 1; 141 117 } … … 152 128 if(widget_verify_props(e, w)) 153 129 return 1; 154 if(widget_resolv_data(e, w)) 130 if(w->caps & CAP_DATA) 131 if(source_init_element(ctx, e)) 155 132 return 1; 156 133 return 0; -
luci2/cbi2/widgets/section.c
r5680 r5686 7 7 8 8 struct cbi_widget_property section_props[] = { 9 { "name", PROP_REQUIRED },10 9 { "id", PROP_REQUIRED }, 11 10 { "src", PROP_OPTIONAL }, -
luci2/cbi2/widgets/tsection.c
r5680 r5686 12 12 13 13 struct cbi_widget tsection = { 14 .caps = CAP_ DATA | CAP_SECTION | CAP_TEMPLATE,14 .caps = CAP_SECTION | CAP_TEMPLATE, 15 15 .parent_caps = CAP_PACKAGE, 16 16 .init = tsection_init,
