Changeset 5686

Show
Ignore:
Timestamp:
02/26/10 02:22:37 (3 years ago)
Author:
blogic
Message:

adss handling of datasource and macros for loging

Location:
luci2/cbi2
Files:
7 added
9 modified

Legend:

Unmodified
Added
Removed
  • luci2/cbi2/cbi.c

    r5683 r5686  
    162162    *buffer = 0; 
    163163    cbi_get_element_id(e->parent, buffer, 1); 
    164     printf("generating id for %s\n", tmp); 
     164    LOG("generating id for %s\n", tmp); 
    165165    (*count)++; 
    166166} 
     
    238238            break; 
    239239        default: 
    240             printf("unknown blob_id %d unknown\n", blob_id(element)); 
     240            LOG("unknown blob_id %d unknown\n", blob_id(element)); 
    241241            abort(); 
    242242            break; 
     
    259259            break; 
    260260        default: 
    261             printf("unknown blob_id %d unknown\n", blob_id(element2)); 
     261            LOG("unknown blob_id %d unknown\n", blob_id(element2)); 
    262262            abort(); 
    263263            break; 
     
    298298{ 
    299299    struct list_head *p; 
    300     printf("indexing %s\n", f->name); 
     300    LOG("indexing %s\n", f->name); 
    301301    list_for_each(p, &f->e.elements) 
    302302    { 
     
    325325{ 
    326326    struct list_head *p; 
    327     printf("unindexing %s\n", f->name); 
     327    LOG("unindexing %s\n", f->name); 
    328328    list_for_each(p, &f->e.elements) 
    329329    { 
     
    366366    struct list_head *p, *q; 
    367367    cbi_index_remove(file); 
    368     printf("dropping %s\n", file->name); 
     368    LOG("dropping %s\n", file->name); 
    369369    list_for_each_safe(p, q, &file->e.elements) 
    370370    { 
     
    417417        } 
    418418    } 
    419     printf("loading %s\n", filename); 
     419    LOG("loading %s\n", filename); 
    420420    fd = open(filename, O_RDONLY); 
    421421    if(fd < 0) 
     
    603603            char *out = strdup(gl.gl_pathv[i]); 
    604604            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); 
    606606            if(!lucic_main(gl.gl_pathv[i], out)) 
    607607            { 
    608                 printf("deleting %s\n", gl.gl_pathv[i]); 
     608                LOG("deleting %s\n", gl.gl_pathv[i]); 
    609609                unlink(gl.gl_pathv[i]); 
    610610            } else { 
    611                 printf("failed\n"); 
     611                LOG("failed\n"); 
    612612            } 
    613613        } 
  • luci2/cbi2/cbi.h

    r5684 r5686  
    99 
    1010#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) 
     11 
     12#define CBI_BROKEN(e) {e->broken = 1;} 
    1113 
    1214#define CBI_LUCI        0x4C554349 
     
    4244}; 
    4345 
     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 
     53struct cbi_element; 
     54struct 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 
    4463#define CAP_SECTION         0x0001 
    4564#define CAP_PACKAGE         0x0002 
     
    4968#define CAP_FILE            0x0020 
    5069#define CAP_TEMPLATE        0x0040 
    51 struct cbi_element; 
    5270struct cbi_element 
    5371{ 
     
    5775    struct list_head index; 
    5876 
    59     unsigned long caps; 
     77    uint64_t caps; 
    6078    int broken; 
    6179 
    6280    struct cbi_element *parent; 
    6381    struct cbi_element *ref; 
     82    struct cbi_source *source; 
    6483 
    6584    char *namespace; 
     
    92111    struct list_head list; 
    93112    char *name; 
    94     int caps; 
    95     int parent_caps; 
     113    uint64_t caps; 
     114    uint64_t parent_caps; 
    96115    struct cbi_widget_property *props; 
    97116    int prop_count; 
     
    122141 
    123142#include "widget.h" 
     143#include "log.h" 
     144#include "source.h" 
    124145 
    125146#endif 
  • luci2/cbi2/lang.c

    r5683 r5686  
    88    if(ctx->lmo) 
    99        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)); 
    1111    ctx->lmo = (lmo_archive_t *)lmo_open(cbi_virt_path(ctx, ctx->path, file)); 
    1212    if(!ctx->lmo) 
    1313    { 
    14         printf("failed to load language file %s\n", file); 
     14        LOG("failed to load language file %s\n", file); 
    1515        if(strcmp(lang, "en")) 
    1616            lmo_load_lang(ctx, "en"); 
  • luci2/cbi2/luci.c

    r5684 r5686  
    1111#include <sys/stat.h> 
    1212#include <sys/mman.h> 
     13#include <syslog.h> 
    1314 
    1415#define _GNU_SOURCE 
     
    2526void handler_INT(int signo) 
    2627{ 
    27     printf("away we go\n"); 
     28    LOG("away we go\n"); 
    2829    loop = 0; 
    2930} 
     
    144145        daemon(0,0); 
    145146 
     147    log_start(daemonize); 
     148 
    146149    uctx = ucix_init_path(vpath, "luci", 0); 
    147150    if(uctx) 
     
    176179    } 
    177180    cbi_free_context(ctx); 
     181    closelog(); 
    178182    return 0; 
    179183} 
  • luci2/cbi2/Makefile

    r5683 r5686  
    88all: $(BINARY) 
    99 
    10 luci: luci.c lucic.c lucip.c uci.c json.c cbi.c session.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.c  
    11     $(CC) $(CFLAGS) -o $@ $^ -luci -ljson -lcrypt 
     10luci: 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  
    1212 
    1313luci-cli: luci-cli.c 
     
    2020    $(CC) $(CFLAGS) $(LIBS) -o $@ $^ 
    2121 
    22 liblmo.a: lmo_core.c lmo_hash.c 
     22liblmo.a: lmo_core.o lmo_hash.o 
    2323    $(AR) rc $@ $^ 
    2424 
     
    2828clean: 
    2929    rm -f $(BINARY) *.luco *.o widgets/*.o validators/*.o *.lmo 
     30    rm -rf ./root 
    3031 
    3132run: $(BINARY) 
  • luci2/cbi2/network.luci

    r5680 r5686  
    22    <luci:title>Page title</luci:title> 
    33    Page text 
    4     <luci:section name="wan"> 
     4    <luci:section src="wan"> 
    55        <luci:title>Form title</luci:title> 
    66        Form text 
     
    3333 
    3434<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"> 
    3737            <luci:option src=".enable">Enable</luci:option> 
    3838            <luci:option src=".start">start_ip</luci:option> 
  • luci2/cbi2/widget.c

    r5682 r5686  
    1919    struct list_head *q; 
    2020    int i; 
    21     char buf[256]; 
    22     *buf = 0; 
    2321    for(i = 0; i < w->prop_count; i++) 
    2422    { 
     
    2624            if(!cbi_find_prop(e, w->props[i].name)) 
    2725            { 
    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); 
    3128                return 1; 
    3229            } 
     
    3734        if(!widget_find_prop(w, p->key)) 
    3835        { 
    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); 
    4238            return 1; 
    4339        } 
     
    4743static int widget_verify_parent_caps(struct cbi_element *e, struct cbi_widget *w) 
    4844{ 
    49     char buf[256]; 
    50     *buf = 0; 
    5145    if(!w->parent_caps) 
    5246        return 0; 
     
    5650        return 0; 
    5751error: 
    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"); 
    7554    return 1; 
    7655} 
     
    128107{ 
    129108    const char *ref = cbi_find_prop(e, "ref"); 
    130     char buf[256]; 
    131     *buf = 0; 
    132109    if(!ref) 
    133110        return 0; 
     
    135112    if(!e->ref) 
    136113    { 
    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); 
    140116        return 1; 
    141117    } 
     
    152128    if(widget_verify_props(e, w)) 
    153129        return 1; 
    154     if(widget_resolv_data(e, w)) 
     130    if(w->caps & CAP_DATA) 
     131        if(source_init_element(ctx, e)) 
    155132        return 1; 
    156133    return 0; 
  • luci2/cbi2/widgets/section.c

    r5680 r5686  
    77 
    88struct cbi_widget_property section_props[] = { 
    9     { "name", PROP_REQUIRED }, 
    109    { "id", PROP_REQUIRED }, 
    1110    { "src", PROP_OPTIONAL }, 
  • luci2/cbi2/widgets/tsection.c

    r5680 r5686  
    1212 
    1313struct cbi_widget tsection = { 
    14     .caps = CAP_DATA | CAP_SECTION | CAP_TEMPLATE, 
     14    .caps = CAP_SECTION | CAP_TEMPLATE, 
    1515    .parent_caps = CAP_PACKAGE, 
    1616    .init = tsection_init,