Changeset 5213 for trunk/oscam-http.c
- Timestamp:
- 05/10/11 00:30:39 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/oscam-http.c
r5212 r5213 2639 2639 tpl_printf(vars, TPLADD, "SECONDS", "%d", SHUTDOWNREFRESH); 2640 2640 char *result = tpl_getTpl(vars, "SHUTDOWN"); 2641 send_headers(f, 200, "OK", NULL, "text/html", 0, strlen(result), 0);2641 send_headers(f, 200, "OK", NULL, "text/html", 0, strlen(result), NULL, 0); 2642 2642 webif_write(result, f); 2643 2643 cs_log("Shutdown requested by WebIF from %s", cs_inet_ntoa(GET_IP())); … … 2664 2664 tpl_addVar(vars, TPLADD, "SECONDS", "5"); 2665 2665 char *result = tpl_getTpl(vars, "SHUTDOWN"); 2666 send_headers(f, 200, "OK", NULL, "text/html", 0,strlen(result), 0);2666 send_headers(f, 200, "OK", NULL, "text/html", 0,strlen(result), NULL, 0); 2667 2667 webif_write(result, f); 2668 2668 cs_log("Restart requested by WebIF from %s", cs_inet_ntoa(GET_IP())); … … 3054 3054 } 3055 3055 3056 char *send_oscam_image(struct templatevars *vars, FILE *f, struct uriparams *params, char *image, time_t modifiedheader ) {3056 char *send_oscam_image(struct templatevars *vars, FILE *f, struct uriparams *params, char *image, time_t modifiedheader, uint32_t etagheader) { 3057 3057 char *wanted; 3058 3058 int8_t disktpl = 0; … … 3067 3067 stat(path, &st); 3068 3068 if(st.st_mtime < modifiedheader){ 3069 send_headers(f, 304, "Not Modified", NULL, NULL, 1, 0, 0);3069 send_headers(f, 304, "Not Modified", NULL, NULL, 1, 0, NULL, 0); 3070 3070 return "1"; 3071 3071 } … … 3073 3073 } 3074 3074 if(disktpl == 0 && first_client->login < modifiedheader){ 3075 send_headers(f, 304, "Not Modified", NULL, NULL, 1, 0, 0);3075 send_headers(f, 304, "Not Modified", NULL, NULL, 1, 0, NULL, 0); 3076 3076 return "1"; 3077 3077 } … … 3086 3086 int32_t len = b64decode((uchar *)ptr + 7); 3087 3087 if(len > 0){ 3088 send_headers(f, 200, "OK", NULL, header + 5, 1, len, 0); 3089 webif_write_raw(ptr + 7, f, len); 3088 if((uint32_t)crc32(0L, (uchar *)ptr + 7, strlen(ptr + 7)) == etagheader){ 3089 send_headers(f, 304, "Not Modified", NULL, NULL, 1, strlen(ptr + 7), ptr + 7, 0); 3090 } else { 3091 send_headers(f, 200, "OK", NULL, header + 5, 1, len, ptr + 7, 0); 3092 webif_write_raw(ptr + 7, f, len); 3093 } 3090 3094 return "1"; 3091 3095 } … … 3265 3269 char expectednonce[(MD5_DIGEST_LENGTH * 2) + 1]; 3266 3270 3267 char *method, *path, *protocol, * etag, *str1, *saveptr1=NULL, *authheader = NULL, *filebuf = NULL;3271 char *method, *path, *protocol, *str1, *saveptr1=NULL, *authheader = NULL, *filebuf = NULL; 3268 3272 char *pch, *tmp, *buf; 3269 3273 /* List of possible pages */ … … 3293 3297 int32_t pagescnt = sizeof(pages)/sizeof(char *); // Calculate the amount of items in array 3294 3298 int32_t i, bufsize, len, pgidx = -1, keepalive = -1; 3299 uint32_t etagheader = 0; 3295 3300 struct uriparams params; 3296 3301 params.paramcount = 0; … … 3353 3358 } else if (len > 40 && strncmp(str1, "If-Modified-Since:", 18) == 0){ 3354 3359 modifiedheader = parse_modifiedsince(str1); 3355 } else if (len > 10 && strncmp(str1, "ETag:", 5) == 0){ 3356 for(pch = str1 + 5; pch[0] != '"' && pch[0] != '\0'; ++pch) 3357 etag = pch; 3358 for(; pch[0] != '"' && pch[0] != '\0'; ++pch) 3359 pch[0] = '\0'; 3360 } else if (len > 20 && strncmp(str1, "If-None-Match:", 14) == 0){ 3361 for(pch = str1 + 14; pch[0] != '"' && pch[0] != '\0'; ++pch); 3362 if(strlen(pch) > 5) etagheader = (uint32_t)strtoul(++pch, NULL, 10); 3360 3363 } else if (len > 12 && strncmp(str1, "Keep-Alive:", 11) == 0){ 3361 3364 keepalive = atoi(str1 + 11); … … 3374 3377 snprintf(temp, sizeof(temp), "WWW-Authenticate: Digest algorithm=\"MD5\", realm=\"%s\", qop=\"auth\", opaque=\"\", nonce=\"%s\"", AUTHREALM, expectednonce); 3375 3378 if(authok == 2) strncat(temp, ", stale=true", sizeof(temp)); 3376 send_headers(f, 401, "Unauthorized", temp, "text/html", 0, 0, 0);3379 send_headers(f, 401, "Unauthorized", temp, "text/html", 0, 0, NULL, 0); 3377 3380 NULLFREE(authheader); 3378 3381 free(filebuf); … … 3382 3385 /*build page*/ 3383 3386 if(pgidx == 8) { 3384 send_file(f, "CSS", modifiedheader );3387 send_file(f, "CSS", modifiedheader, etagheader); 3385 3388 } else if (pgidx == 17) { 3386 send_file(f, "JS", modifiedheader );3389 send_file(f, "JS", modifiedheader, etagheader); 3387 3390 } else { 3388 3391 time_t t; … … 3458 3461 //case 17: js file 3459 3462 case 18: result = send_oscam_api(vars, f, ¶ms); break; 3460 case 19: result = send_oscam_image(vars, f, ¶ms, NULL, modifiedheader ); break;3461 case 20: result = send_oscam_image(vars, f, ¶ms, "ICMAI", modifiedheader ); break;3463 case 19: result = send_oscam_image(vars, f, ¶ms, NULL, modifiedheader, etagheader); break; 3464 case 20: result = send_oscam_image(vars, f, ¶ms, "ICMAI", modifiedheader, etagheader); break; 3462 3465 default: result = send_oscam_status(vars, ¶ms, 0); break; 3463 3466 } … … 3466 3469 if(result == NULL || !strcmp(result, "0") || strlen(result) == 0) send_error500(f); 3467 3470 else if (strcmp(result, "1")) { 3471 //it doesn't make sense to check for modified etagheader here as standard template has timestamp in output and so site changes on every request 3468 3472 if (pgidx == 18) 3469 send_headers(f, 200, "OK", NULL, "text/xml", 0, strlen(result), 0);3473 send_headers(f, 200, "OK", NULL, "text/xml", 0, strlen(result), NULL, 0); 3470 3474 else 3471 send_headers(f, 200, "OK", NULL, "text/html", 0, strlen(result), 0);3475 send_headers(f, 200, "OK", NULL, "text/html", 0, strlen(result), NULL, 0); 3472 3476 webif_write(result, f); 3473 3477 }
Note:
See TracChangeset
for help on using the changeset viewer.