Ignore:
Timestamp:
02/27/13 14:34:41 (9 years ago)
Author:
gf
Message:

webif: Simplify template loading and checking.

The subdir logic seems to complicate the code for no good reason and
as far as I can work out it does nothing. It looks like a leftover
that can be removed.

File:
1 edited

Legend:

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

    r8435 r8436  
    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 char *tpl_getUnparsedTpl(const char* name, int8_t removeHeader, const char* subdir) {
     232static char *__tpl_getUnparsedTpl(const char* name, bool removeHeader) {
    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, 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)))
     247        if (strlen(tpl_getFilePathInSubdir(cfg.http_tpl, "", name, ".tpl", path, 255)) > 0 && file_exists(path))
    253248        {
    254249            FILE *fp;
     
    297292}
    298293
     294char *tpl_getUnparsedTpl(const char* name) {
     295    return __tpl_getUnparsedTpl(name, true);
     296}
     297
    299298/* Returns the specified template with all variables/other templates replaced or an
    300299   empty string if the template doesn't exist. Do not free the result yourself, it
    301300   will get automatically cleaned up! */
    302301char *tpl_getTpl(struct templatevars *vars, const char* name) {
    303     char *tplorg = tpl_getUnparsedTpl(name, 1, tpl_getVar(vars, "SUBDIR"));
     302    char *tplorg = tpl_getUnparsedTpl(name);
    304303    if (!tplorg) return "";
    305304    char *tplend = tplorg + strlen(tplorg);
     
    372371
    373372/* Checks all disk templates in a directory if they are still current or may need upgrade! */
    374 void tpl_checkOneDirDiskRevisions(const char* subdir) {
    375     char dirpath[255] = "\0";
    376     snprintf(dirpath, 255, "%s%s", cfg.http_tpl ? cfg.http_tpl : "", subdir);
     373void tpl_checkDiskRevisions(void) {
     374    if (!cfg.http_tpl)
     375        return;
    377376    int32_t i;
    378377    char path[255];
    379378    for(i = 0; i < tpls_count; ++i) {
    380379        const struct tpl *tpl = &tpls[i];
    381         if (strncmp(tpl->tpl_name, "IC", 2) != 0 && strlen(tpl_getTplPath(tpl->tpl_name, dirpath, path, 255)) > 0 && file_exists(path)) {
     380        if (strncmp(tpl->tpl_name, "IC", 2) != 0 && strlen(tpl_getTplPath(tpl->tpl_name, cfg.http_tpl, path, 255)) > 0 && file_exists(path)) {
    382381            int8_t error = 1;
    383             char *tplorg = tpl_getUnparsedTpl(tpl->tpl_name, 0, subdir);
     382            char *tplorg = __tpl_getUnparsedTpl(tpl->tpl_name, false); // Do not strip the header
    384383            unsigned long checksum = 0, curchecksum = crc32(0L, (unsigned char*)tpl->tpl_data, tpl->tpl_data_len);
    385384            char *pch1 = strstr(tplorg,"<!--OSCam");
     
    403402            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);
    404403            free(tplorg);
    405         }
    406     }
    407 }
    408 
    409 /* Checks whether disk templates need upgrade - including sub-directories */
    410 void 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);
    439404        }
    440405    }
Note: See TracChangeset for help on using the changeset viewer.