Changeset 5675

Show
Ignore:
Timestamp:
02/24/10 13:51:20 (3 years ago)
Author:
blogic
Message:

adds handling of a virtual root and better allocation of cbi_ctx

Location:
luci2/cbi2
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • luci2/cbi2/cbi.c

    r5674 r5675  
    540540} 
    541541 
    542 struct cbi_ctx* cbi_load_files(const char *dir) 
     542static const char* cbi_virt_path(struct cbi_ctx *ctx, const char *path, const char *file) 
     543{ 
     544    static char buf[256]; 
     545    buf[255] = '\0'; 
     546    snprintf(buf, 255, "%s%s%s", (ctx->vroot)?(ctx->vroot):(""), path, (file)?(file):("")); 
     547    return buf; 
     548} 
     549 
     550struct cbi_ctx* cbi_load_files(struct cbi_ctx *ctx) 
    543551{ 
    544552    glob_t gl; 
    545553    int gl_flags = GLOB_NOESCAPE | GLOB_NOSORT | GLOB_MARK; 
    546     struct cbi_ctx *ctx = cbi_alloc_ctx(); 
    547     if(glob(dir, gl_flags, NULL, &gl) >= 0) 
     554    if(glob(cbi_virt_path(ctx, ctx->path, "*.lucio"), gl_flags, NULL, &gl) >= 0) 
    548555    { 
    549556        int i; 
     
    568575} 
    569576 
    570 void cbi_check_new_files(struct cbi_ctx *ctx, const char *dir) 
     577void cbi_check_new_files(struct cbi_ctx *ctx) 
    571578{ 
    572579    glob_t gl; 
    573580    int gl_flags = GLOB_NOESCAPE | GLOB_NOSORT | GLOB_MARK; 
    574     if(glob(dir, gl_flags, NULL, &gl) >= 0) 
     581    if(glob(cbi_virt_path(ctx, ctx->path, "*.luco"), gl_flags, NULL, &gl) >= 0) 
    575582    { 
    576583        int i; 
     
    581588} 
    582589 
    583 void cbi_check_new_files_src(struct cbi_ctx *ctx, const char *dir) 
     590void cbi_check_new_files_src(struct cbi_ctx *ctx) 
    584591{ 
    585592    glob_t gl; 
    586593    int gl_flags = GLOB_NOESCAPE | GLOB_NOSORT | GLOB_MARK; 
    587     if(glob(dir, gl_flags, NULL, &gl) >= 0) 
     594    if(glob(cbi_virt_path(ctx, ctx->path, "*.luci"), gl_flags, NULL, &gl) >= 0) 
    588595    { 
    589596        int i; 
     
    608615{ 
    609616    cbi_check_old_files(ctx); 
    610     cbi_check_new_files_src(ctx, "/lib/luci2/*.luci"); 
    611     cbi_check_new_files(ctx, "/lib/luci2/*.luco"); 
    612 } 
    613  
    614 struct cbi_ctx* cbi_load(void) 
    615 { 
    616     struct cbi_ctx *ctx = cbi_load_files("/lib/luci2/*.luco"); 
     617    cbi_check_new_files_src(ctx); 
     618    cbi_check_new_files(ctx); 
     619} 
     620 
     621struct cbi_ctx* cbi_init(const char *vroot, const char *path) 
     622{ 
     623    struct cbi_ctx *ctx = cbi_alloc_ctx(); 
     624    if(!path) 
     625        ctx->path = strdup("/lib/luci2/"); 
     626    else 
     627        ctx->path = strdup(path); 
     628    if(vroot) 
     629        ctx->vroot = strdup(vroot); 
     630    else 
     631        ctx->vroot = 0; 
     632    cbi_load_files(ctx); 
    617633    cbi_index(ctx); 
    618634    cbi_reindex(ctx); 
    619635    return ctx; 
    620636} 
    621  
  • luci2/cbi2/cbi.h

    r5673 r5675  
    2424    struct list_head menus; 
    2525    struct uvl_context *uvl; 
     26    const char *vroot; 
     27    const char *path; 
    2628}; 
    2729 
     
    9294}; 
    9395 
    94 struct cbi_ctx* cbi_load(void); 
     96struct cbi_ctx* cbi_init(const char *vroot, const char *path); 
    9597void cbi_dump(struct cbi_ctx *ctx); 
    9698void cbi_free_context(struct cbi_ctx *ctx); 
  • luci2/cbi2/luci.c

    r5674 r5675  
    6262    int daemonize = 0; 
    6363    int sock = 0; 
    64     int blob; 
    65     char *b_file; 
     64    int blob = 0; 
     65    char *b_file = 0; 
    6666    int uvl = 0; 
    6767    char *u_file = 0; 
     
    129129        daemon(0,0); 
    130130 
    131     ctx = cbi_load(); 
     131    ctx = cbi_init(vpath, "/lib/luci2/"); 
    132132 
    133133    cbi_dump(ctx);