Changeset 8427
- Timestamp:
- 02/25/13 14:03:36 (11 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/module-webif-tpl.c
r8421 r8427 8 8 9 9 extern uint8_t cs_http_use_utf8; 10 extern const char *templates[][3]; 10 extern const struct template templates[]; 11 11 12 static int8_t *tplchksum; 12 13 … … 319 320 320 321 for(i = 0; i < tplcnt; ++i) { 321 if (tplchksum && chksum == tplchksum[i] && name[0] == templates[i][0][0]) { // basic check to save strcmp calls as we are doing this hundreds of times per page in some cases 322 if (strcmp(name, templates[i][0]) == 0) break; 322 const struct template *tpl = &templates[i]; 323 if (tplchksum && chksum == tplchksum[i] && name[0] == tpl->tpl_name[0]) { // basic check to save strcmp calls as we are doing this hundreds of times per page in some cases 324 if (strcmp(name, tpl->tpl_name) == 0) break; 323 325 } 324 326 } 325 327 326 328 if (i >= 0 && i < tplcnt) { 327 const char * tpl_res = templates[i][1];328 int32_t len = strlen(tpl_ res) + 1;329 const char *tpl_data = templates[i].tpl_data; 330 int32_t len = strlen(tpl_data) + 1; 329 331 if (!cs_malloc(&result, len)) return NULL; 330 memcpy(result, tpl_ res, len);332 memcpy(result, tpl_data, len); 331 333 } else { 332 334 if (!cs_malloc(&result, 1)) return NULL; … … 398 400 FILE *fp; 399 401 for (i = 0; i < tplcnt; ++i) { 400 if (strlen(tpl_getTplPath(templates[i][0], path, tmp, 256)) > 0 && (fp = fopen(tmp,"w")) != NULL) { 401 int32_t len = strlen(templates[i][1]); 402 if (strncmp(templates[i][0], "IC", 2) != 0) { 403 fprintf(fp, "<!--OSCam;%lu;%s;%s;%s-->\n", crc32(0L, (unsigned char*)templates[i][1], len), CS_VERSION, CS_SVN_VERSION, templates[i][2]); 402 const struct template *tpl = &templates[i]; 403 if (strlen(tpl_getTplPath(tpl->tpl_name, path, tmp, 256)) > 0 && (fp = fopen(tmp,"w")) != NULL) { 404 int32_t len = strlen(tpl->tpl_data); 405 if (strncmp(tpl->tpl_name, "IC", 2) != 0) { 406 fprintf(fp, "<!--OSCam;%lu;%s;%s;%s-->\n", crc32(0L, (unsigned char *)tpl->tpl_data, len), CS_VERSION, CS_SVN_VERSION, tpl->tpl_deps); 404 407 } 405 fwrite(t emplates[i][1], sizeof(char), len, fp);408 fwrite(tpl->tpl_data, sizeof(char), len, fp); 406 409 fclose (fp); 407 410 ++cnt; … … 418 421 char path[255]; 419 422 for(i = 0; i < tplcnt; ++i) { 420 if (strncmp(templates[i][0], "IC", 2) != 0 && strlen(tpl_getTplPath(templates[i][0], dirpath, path, 255)) > 0 && file_exists(path)) { 423 const struct template *tpl = &templates[i]; 424 if (strncmp(tpl->tpl_name, "IC", 2) != 0 && strlen(tpl_getTplPath(tpl->tpl_name, dirpath, path, 255)) > 0 && file_exists(path)) { 421 425 int8_t error = 1; 422 char *tplorg = tpl_getUnparsedTpl(t emplates[i][0], 0, subdir);423 unsigned long checksum = 0, curchecksum = crc32(0L, (unsigned char*)t emplates[i][1], strlen(templates[i][1]));426 char *tplorg = tpl_getUnparsedTpl(tpl->tpl_name, 0, subdir); 427 unsigned long checksum = 0, curchecksum = crc32(0L, (unsigned char*)tpl->tpl_data, strlen(tpl->tpl_data)); 424 428 char *ifdefs = "", *pch1 = strstr(tplorg,"<!--OSCam"); 425 429 if (pch1 != NULL) { … … 489 493 for(i = 0; i < tplcnt; ++i) { 490 494 tplchksum[i] = 0; 491 for(j = strlen(templates[i][0]); j > 0; --j) { 492 tplchksum[i] += templates[i][0][j]; 495 const char *tpl_name = templates[i].tpl_name; 496 for(j = strlen(tpl_name); j > 0; --j) { 497 tplchksum[i] += tpl_name[j]; 493 498 } 494 499 } -
trunk/webif/pages_gen.c
r8418 r8427 240 240 } 241 241 242 fprintf(output_file, "\t{ \"%s\", %s%s,\"%s\" },\n",242 fprintf(output_file, "\t{ .tpl_name=\"%s\", .tpl_data=%s%s, .tpl_deps=\"%s\" },\n", 243 243 ident, 244 244 templates.data[tpl_idx].type == TXT ? "TPL" : "", ident, … … 307 307 fprintf(output_file, "#define WEBIF_PAGES_H_\n"); 308 308 fprintf(output_file, "\n"); 309 fprintf(output_file, "struct template {\n"); 310 fprintf(output_file, " char *tpl_name;\n"); 311 fprintf(output_file, " char *tpl_data;\n"); 312 fprintf(output_file, " char *tpl_deps;\n"); 313 fprintf(output_file, "};\n"); 314 fprintf(output_file, "\n"); 309 315 fprintf(output_file, "int32_t tpl_count(void);\n"); 310 316 fprintf(output_file, "\n"); … … 331 337 } 332 338 333 fprintf(output_file, "const char *templates[][3] = {\n");339 fprintf(output_file, "const struct template templates[] = {\n"); 334 340 for (i = 0; i < templates.num; i++) { 335 341 parse_deps(i); … … 337 343 fprintf(output_file, "};\n"); 338 344 fprintf(output_file, "\n"); 339 fprintf(output_file, "int32_t tpl_count(void) { return sizeof(templates) / (3*sizeof(char *)); }\n");345 fprintf(output_file, "int32_t tpl_count(void) { return sizeof(templates) / sizeof(struct template); }\n"); 340 346 fprintf(output_file, "\n"); 341 347 fprintf(output_file, "#endif\n");
Note:
See TracChangeset
for help on using the changeset viewer.