Ignore:
Timestamp:
05/10/11 01:20:32 (9 years ago)
Author:
Admin
Message:

WebIf: Small code cleanups

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/oscam-http-helpers.c

    r5213 r5214  
    469469}
    470470
    471 
    472471void send_headers(FILE *f, int32_t status, char *title, char *extra, char *mime, int32_t cache, int32_t length, char *content, int8_t forcePlain){
    473472  time_t now;
     
    512511    char buf[(2* strlen(title)) + strlen(text) + 128];
    513512    char *pos = buf;
    514     send_headers(f, status, title, extra, "text/html", 0, strlen(buf), NULL, forcePlain);
    515513    pos += snprintf(pos, sizeof(buf)-(pos-buf), "<HTML><HEAD><TITLE>%d %s</TITLE></HEAD>\r\n", status, title);
    516514    pos += snprintf(pos, sizeof(buf)-(pos-buf), "<BODY><H4>%d %s</H4>\r\n", status, title);
    517515    pos += snprintf(pos, sizeof(buf)-(pos-buf), "%s\r\n", text);
    518516    pos += snprintf(pos, sizeof(buf)-(pos-buf), "</BODY></HTML>\r\n");
     517    send_headers(f, status, title, extra, "text/html", 0, strlen(buf), NULL, forcePlain);
    519518    if(forcePlain == 1) fwrite(buf, 1, strlen(buf), f);
    520519    else webif_write(buf, f);
     
    523522void send_error500(FILE *f){
    524523    send_error(f, 500, "Internal Server Error", NULL, "The server encountered an internal error that prevented it from fulfilling this request.", 0);
     524}
     525
     526void send_header304(FILE *f){
     527    send_headers(f, 304, "Not Modified", NULL, NULL, 1, 0, NULL, 0);
    525528}
    526529
     
    551554        stat(filename, &st);
    552555        moddate = st.st_mtime;
     556        if(moddate < modifiedheader){
     557            send_header304(f);
     558            return;
     559        }
    553560        if((fp = fopen(filename, "r"))==NULL) return;
    554561        if(!cs_malloc(&result, st.st_size + 1, -1)){
     
    575582    }
    576583    if(moddate < modifiedheader || (uint32_t)crc32(0L, (uchar *)result, strlen(result)) == etagheader){
    577         send_headers(f, 304, "Not Modified", NULL, NULL, 1, strlen(result), result, 0);
     584        send_header304(f);
    578585    } else {
    579586        send_headers(f, 200, "OK", NULL, mimetype, 1, strlen(result), result, 0);
Note: See TracChangeset for help on using the changeset viewer.