Changeset 5786
- Timestamp:
- 03/10/10 15:00:40 (3 years ago)
- Location:
- luci2/cbi2
- Files:
-
- 14 modified
-
cbi.h (modified) (1 diff)
-
cbi_element.c (modified) (2 diffs)
-
json.c (modified) (3 diffs)
-
json.h (modified) (1 diff)
-
log.c (modified) (1 diff)
-
luci-cli.c (modified) (2 diffs)
-
luci.c (modified) (1 diff)
-
Makefile (modified) (1 diff)
-
session.c (modified) (4 diffs)
-
uci.c (modified) (1 diff)
-
u_sock.c (modified) (3 diffs)
-
u_sock.h (modified) (1 diff)
-
widget.c (modified) (5 diffs)
-
widget.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
luci2/cbi2/cbi.h
r5785 r5786 170 170 171 171 int cbi_dump_blob(char *file); 172 void cbi_request(struct cbi_ctx *ctx, char *request);173 172 const char* cbi_virt_path(struct cbi_ctx *ctx, const char *path, const char *file); 174 173 void cbi_create_instance(struct cbi_ctx *ctx, struct cbi_element *e1, struct cbi_element *e2); -
luci2/cbi2/cbi_element.c
r5785 r5786 173 173 return 1; 174 174 list_add_tail(&e->widget_ref, &e->w->refs); 175 if(widget_ find_prop(e->w, "id") || (CAPS(e) & CAP_CONTAINER))175 if(widget_prop_find(e->w, "id") || (CAPS(e) & CAP_CONTAINER)) 176 176 cbi_element_default_id(e, count); 177 177 if(e->w->init) … … 348 348 } 349 349 350 void cbi_request(struct cbi_ctx *ctx, char *request) 351 { 352 json_object *out, *in = json_tokener_parse(request); 353 if(is_error(in)) 354 { 355 printf("bad json\n"); 356 return; 357 } 358 out = json_request(ctx, in); 359 if(out) 360 { 361 printf("res -> %s\n", json_object_to_json_string(out)); 362 json_object_put(out); 363 } 364 json_object_put(in); 365 } 350 -
luci2/cbi2/json.c
r5781 r5786 73 73 json_object *_pass; 74 74 const char *pass; 75 if(!in) 76 return 0; 75 77 76 78 _pass = json_object_object_get(in, "pass"); … … 115 117 if(!strcmp(r, "auth")) 116 118 out = json_req_auth(ctx, vals); 117 else if(!strcmp(r, "logout") )119 else if(!strcmp(r, "logout") && (sauth)) 118 120 out = session_logout(ctx, json_object_get_string(sauth)); 119 121 else if(!json_auth(ctx, sauth)) … … 133 135 } 134 136 137 char* u_sock_json_request(struct cbi_ctx *ctx, char *request) 138 { 139 json_object *out = 0, *in = json_tokener_parse(request); 140 char *answer = 0; 141 printf("in -> %s\n", request); 142 if(!is_error(in)) 143 out = json_request(ctx, in); 144 if(!out) 145 { 146 out = json_object_new_object(); 147 json_object_object_add(out, "error", json_object_new_string("1")); 148 } 149 answer = strdup(json_object_to_json_string(out)); 150 json_object_put(out); 151 json_object_put(in); 152 printf("out -> %s\n", answer); 153 return answer; 154 } -
luci2/cbi2/json.h
r5696 r5786 7 7 json_object* json_request(struct cbi_ctx *ctx, json_object *in); 8 8 json_object* json_req_node(struct cbi_ctx *ctx, const char *node); 9 char* u_sock_json_request(struct cbi_ctx *ctx, char *request); 9 10 10 11 #endif -
luci2/cbi2/log.c
r5784 r5786 8 8 { 9 9 daemonize = daemon; 10 openlog("luci2", 0, 0); 10 if(daemon) 11 openlog("luci2", 0, 0); 11 12 } 12 13 -
luci2/cbi2/luci-cli.c
r5682 r5786 17 17 int s, len; 18 18 struct sockaddr_un remote; 19 char reply[4096]; 19 20 if(argc != 2) 20 21 return 1; … … 41 42 exit(1); 42 43 } 44 len = recv(s, reply, 4095, 0); 45 if(len) 46 { 47 reply[4095] = 0; 48 printf("received -> \"%s\"\n", reply); 49 } 43 50 close(s); 44 51 return 0; -
luci2/cbi2/luci.c
r5784 r5786 169 169 if(spath) 170 170 free(spath); 171 u_sock_register_handler(ctx, "json", cbi_request);171 u_sock_register_handler(ctx, "json", u_sock_json_request); 172 172 } 173 173 { -
luci2/cbi2/Makefile
r5784 r5786 35 35 36 36 run: $(BINARY) 37 mkdir -p ./root/lib/luci2/ ./root/etc/config/ 37 mkdir -p ./root/lib/luci2/ ./root/etc/config/ ./root/var/state/ ./root/tmp/.uci/ 38 38 cp apps/*.luci ./root/lib/luci2/ 39 39 cp -r ./config/* ./root/etc/config/ 40 40 ./lmo_po2lmo ./apps/en.po ./root/lib/luci2/en.lmo 41 41 ./uvlc ./apps/network.uvl ./root/lib/luci2/test.uvo 42 ./luci -s -V ./root42 ./luci -s -V ${PWD}/root 43 43 44 44 %.o: %.c -
luci2/cbi2/session.c
r5685 r5786 44 44 ucix_add_option_int(ctx, "luci", "session", session, time(0)); 45 45 ucix_save(ctx, "luci"); 46 ucix_cleanup(ctx);46 ucix_cleanup(ctx); 47 47 return session; 48 48 } … … 63 63 struct uci_context *ctx; 64 64 ctx = ucix_init(cbictx, "luci", 1); 65 uci_set_savedir(ctx, "/var/state/");66 65 ucix_for_each_section_option(ctx, "luci", "session", session_expire_cb, ctx); 67 66 ucix_save(ctx, "luci"); … … 77 76 goto out; 78 77 ctx = ucix_init(cbictx, "luci", 1); 79 uci_set_savedir(ctx, "/var/state/");80 78 t = ucix_get_option_int(ctx, "luci", "session", auth, 0); 81 79 if(t) … … 101 99 goto out; 102 100 ctx = ucix_init(cbictx, "luci", 1); 103 uci_set_savedir(ctx, "/var/state/");104 101 t = ucix_get_option_int(ctx, "luci", "session", sauth, 0); 105 102 if(t) -
luci2/cbi2/uci.c
r5694 r5786 23 23 uci_set_confdir(ctx, cbi_virt_path(cbictx, "/etc/config", NULL)); 24 24 if(state) 25 uci_add_history_path(ctx, "/var/state"); 25 uci_set_savedir(ctx, cbi_virt_path(cbictx, "/var/state/", NULL)); 26 else 27 uci_set_savedir(ctx, cbi_virt_path(cbictx, "/tmp/.uci/", NULL)); 26 28 if(uci_load(ctx, config_file, NULL) != UCI_OK) 27 29 { -
luci2/cbi2/u_sock.c
r5682 r5786 63 63 } 64 64 65 voidu_sock_incoming(struct cbi_ctx *ctx, char *data)65 char* u_sock_incoming(struct cbi_ctx *ctx, char *data) 66 66 { 67 67 char *t = strtok(data, "|"); … … 73 73 struct sock_handler *sh = container_of(p, struct sock_handler, list); 74 74 if(!strcmp(t, sh->name)) 75 sh->cb(ctx, &data[strlen(sh->name) + 1]); 75 { 76 char *answer = sh->cb(ctx, &data[strlen(sh->name) + 1]); 77 if(answer) 78 return answer; 79 break; 80 } 76 81 } 77 82 } 83 return 0; 78 84 } 79 85 … … 95 101 if(n > 0) 96 102 { 103 char *answer; 97 104 str[n] = '\0'; 98 printf("incoming data -> %s\n", str); 99 u_sock_incoming(ctx, str); 105 answer = u_sock_incoming(ctx, str); 106 if(answer) 107 { 108 send(s, answer, strlen(answer), 0); 109 free(answer); 110 } 100 111 } 101 112 close(s); -
luci2/cbi2/u_sock.h
r5682 r5786 3 3 #include "cbi.h" 4 4 5 typedef void(*sock_handler_func)(struct cbi_ctx *ctx, char *data);5 typedef char* (*sock_handler_func)(struct cbi_ctx *ctx, char *data); 6 6 7 7 void u_sock_init(struct cbi_ctx *ctx, const char *path); -
luci2/cbi2/widget.c
r5781 r5786 29 29 } 30 30 31 int widget_ find_prop(struct cbi_widget *w, const char *name)31 int widget_prop_find(struct cbi_widget *w, const char *name) 32 32 { 33 33 int i; … … 59 59 { 60 60 struct cbi_property *p = container_of(q, struct cbi_property, list); 61 if(!widget_ find_prop(e->w, p->key))61 if(!widget_prop_find(e->w, p->key)) 62 62 { 63 63 CBILOG(e, "unknown property %s\n", p->key); … … 78 78 } 79 79 80 static int widget_verify_parent _caps(struct cbi_element *e)80 static int widget_verify_parent(struct cbi_element *e) 81 81 { 82 82 struct cbi_element *parent; … … 96 96 } 97 97 98 static int widget_ abstract(struct cbi_ctx *ctx, struct cbi_element *e)98 static int widget_verify_abstract(struct cbi_ctx *ctx, struct cbi_element *e) 99 99 { 100 100 const char *ref = cbi_prop_find(e, "ref"); … … 115 115 int widget_verify(struct cbi_ctx *ctx, struct cbi_element *e) 116 116 { 117 if(widget_ abstract(ctx, e))117 if(widget_verify_abstract(ctx, e)) 118 118 return 1; 119 if(widget_verify_parent _caps(e))119 if(widget_verify_parent(e)) 120 120 return 1; 121 121 if(widget_verify_props(e)) 122 122 return 1; 123 if( e->w->caps& CAP_DATA)123 if(CAPS(e) & CAP_DATA) 124 124 if(source_init_element(ctx, e)) 125 125 return 1; -
luci2/cbi2/widget.h
r5779 r5786 5 5 struct cbi_widget* widget_find(const char *namespace, const char *name); 6 6 int widget_verify(struct cbi_ctx *ctx, struct cbi_element *e); 7 int widget_ find_prop(struct cbi_widget *w, const char *name);7 int widget_prop_find(struct cbi_widget *w, const char *name); 8 8 9 9 #endif
