Changeset 8437


Ignore:
Timestamp:
02/27/13 15:12:32 (8 years ago)
Author:
gf
Message:

Revert "webif: Simplify template loading and checking."

This reverts commit r8346. The subdir logic is used to have different
template directories for different paths comming from http request.

For more info see:

http://www.streamboard.tv/wbb2/thread.php?threadid=37378

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/module-webif-lib.c

    r8436 r8437  
    387387            char* separator = "/* External CSS */";
    388388            char* oldallocated = allocated;
    389             CSS = tpl_getUnparsedTpl("CSS");
     389            CSS = tpl_getUnparsedTpl("CSS", 1, "");
    390390            int32_t newsize = strlen(CSS) + strlen(separator) + 2;
    391391            if (oldallocated) newsize += strlen(oldallocated) + 1;
     
    404404
    405405    } else {
    406         CSS = tpl_getUnparsedTpl("CSS");
    407         JSCRIPT = tpl_getUnparsedTpl("JSCRIPT");
     406        CSS = tpl_getUnparsedTpl("CSS", 1, "");
     407        JSCRIPT = tpl_getUnparsedTpl("JSCRIPT", 1, "");
    408408#ifdef TOUCH
    409         TOUCH_CSS = tpl_getUnparsedTpl("TOUCH_CSS");
    410         TOUCH_JSCRIPT = tpl_getUnparsedTpl("TOUCH_JSCRIPT");
     409        TOUCH_CSS = tpl_getUnparsedTpl("TOUCH_CSS", 1, "");
     410        TOUCH_JSCRIPT = tpl_getUnparsedTpl("TOUCH_JSCRIPT", 1, "");
    411411        char* res_tpl = !subdir || strcmp(subdir, TOUCH_SUBDIR)
    412412            ? (filen == 1 ? CSS : JSCRIPT)
  • trunk/module-webif-tpl.c

    r8436 r8437  
    230230/* Returns an unparsed template either from disk or from internal templates.
    231231   Note: You must free() the result after using it and you may get NULL if an error occured!*/
    232 static char *__tpl_getUnparsedTpl(const char* name, bool removeHeader) {
     232char *tpl_getUnparsedTpl(const char* name, int8_t removeHeader, const char* subdir) {
    233233    int32_t i;
    234234    const struct tpl *tpl = NULL;
     
    245245    if (tpl && cfg.http_tpl) {
    246246        char path[255];
    247         if (strlen(tpl_getFilePathInSubdir(cfg.http_tpl, "", name, ".tpl", path, 255)) > 0 && file_exists(path))
     247        if ((strlen(tpl_getFilePathInSubdir(cfg.http_tpl, subdir, name, ".tpl", path, 255)) > 0 && file_exists(path))
     248             || (strlen(subdir) > 0
     249#ifdef TOUCH
     250             && strcmp(subdir, TOUCH_SUBDIR)
     251#endif
     252             && strlen(tpl_getFilePathInSubdir(cfg.http_tpl, ""    , name, ".tpl", path, 255)) > 0 && file_exists(path)))
    248253        {
    249254            FILE *fp;
     
    292297}
    293298
    294 char *tpl_getUnparsedTpl(const char* name) {
    295     return __tpl_getUnparsedTpl(name, true);
    296 }
    297 
    298299/* Returns the specified template with all variables/other templates replaced or an
    299300   empty string if the template doesn't exist. Do not free the result yourself, it
    300301   will get automatically cleaned up! */
    301302char *tpl_getTpl(struct templatevars *vars, const char* name) {
    302     char *tplorg = tpl_getUnparsedTpl(name);
     303    char *tplorg = tpl_getUnparsedTpl(name, 1, tpl_getVar(vars, "SUBDIR"));
    303304    if (!tplorg) return "";
    304305    char *tplend = tplorg + strlen(tplorg);
     
    371372
    372373/* Checks all disk templates in a directory if they are still current or may need upgrade! */
    373 void tpl_checkDiskRevisions(void) {
    374     if (!cfg.http_tpl)
    375         return;
     374void tpl_checkOneDirDiskRevisions(const char* subdir) {
     375    char dirpath[255] = "\0";
     376    snprintf(dirpath, 255, "%s%s", cfg.http_tpl ? cfg.http_tpl : "", subdir);
    376377    int32_t i;
    377378    char path[255];
    378379    for(i = 0; i < tpls_count; ++i) {
    379380        const struct tpl *tpl = &tpls[i];
    380         if (strncmp(tpl->tpl_name, "IC", 2) != 0 && strlen(tpl_getTplPath(tpl->tpl_name, cfg.http_tpl, path, 255)) > 0 && file_exists(path)) {
     381        if (strncmp(tpl->tpl_name, "IC", 2) != 0 && strlen(tpl_getTplPath(tpl->tpl_name, dirpath, path, 255)) > 0 && file_exists(path)) {
    381382            int8_t error = 1;
    382             char *tplorg = __tpl_getUnparsedTpl(tpl->tpl_name, false); // Do not strip the header
     383            char *tplorg = tpl_getUnparsedTpl(tpl->tpl_name, 0, subdir);
    383384            unsigned long checksum = 0, curchecksum = crc32(0L, (unsigned char*)tpl->tpl_data, tpl->tpl_data_len);
    384385            char *pch1 = strstr(tplorg,"<!--OSCam");
     
    402403            if (error) cs_log("If you are sure that it is current, add the following line at the beginning of the template to suppress this warning: <!--OSCam;%lu;%s;%s-->", curchecksum, CS_VERSION, CS_SVN_VERSION);
    403404            free(tplorg);
     405        }
     406    }
     407}
     408
     409/* Checks whether disk templates need upgrade - including sub-directories */
     410void tpl_checkDiskRevisions(void) {
     411    char subdir[255];
     412    char dirpath[255];
     413    if (cfg.http_tpl) {
     414        tpl_checkOneDirDiskRevisions("");
     415        DIR *hdir;
     416        struct dirent entry;
     417        struct dirent *result;
     418        struct stat s;
     419        if ((hdir = opendir(cfg.http_tpl)) != NULL) {
     420            while(cs_readdir_r(hdir, &entry, &result) == 0 && result != NULL) {
     421                if (strcmp(".", entry.d_name) == 0 || strcmp("..", entry.d_name) == 0) {
     422                    continue;
     423                }
     424                snprintf(dirpath, 255, "%s%s", cfg.http_tpl, entry.d_name);
     425                if (stat(dirpath, &s) == 0) {
     426                    if (s.st_mode & S_IFDIR) {
     427                        snprintf(subdir, 255,
     428                        #ifdef WIN32
     429                                    "%s\\"
     430                        #else
     431                                    "%s/"
     432                        #endif
     433                                , entry.d_name);
     434                        tpl_checkOneDirDiskRevisions(subdir);
     435                    }
     436                }
     437            }
     438            closedir(hdir);
    404439        }
    405440    }
  • trunk/module-webif-tpl.h

    r8436 r8437  
    4343char    *tpl_getTplPath(const char *name, const char *path, char *result, uint32_t resultsize);
    4444char    *tpl_getTpl(struct templatevars *vars, const char* name);
    45 char    *tpl_getUnparsedTpl(const char* name);
     45char    *tpl_getUnparsedTpl(const char* name, int8_t removeHeader, const char* subdir);
    4646
    4747int32_t tpl_saveIncludedTpls(const char *path);
    4848
     49void    tpl_checkOneDirDiskRevisions(const char* subdir);
    4950void    tpl_checkDiskRevisions(void);
    5051
  • trunk/module-webif.c

    r8436 r8437  
    36423642        *keepalive = 0;
    36433643        if(!apicall){
    3644             char *CSS = tpl_getUnparsedTpl("CSS");
     3644            char *CSS = tpl_getUnparsedTpl("CSS", 1, "");
    36453645            tpl_addVar(vars, TPLADD, "STYLESHEET", CSS);
    36463646            free(CSS);
     
    36703670        *keepalive = 0;
    36713671        if(!apicall){
    3672             char *CSS = tpl_getUnparsedTpl("CSS");
     3672            char *CSS = tpl_getUnparsedTpl("CSS", 1, "");
    36733673            tpl_addVar(vars, TPLADD, "STYLESHEET", CSS);
    36743674            free(CSS);
Note: See TracChangeset for help on using the changeset viewer.