Ignore:
Timestamp:
04/30/11 15:53:07 (9 years ago)
Author:
Admin
Message:

WebIf: Make webinterface multithreaded. Page processing is actually synchronized by a mutex as it is not threadsafe in most parts but all client communication and static pages are really multithreaded. This also prevents DoS attacks on WebIf by just opening a connection and waiting till it timeouts as well as problems with IE9 when running on non-standard ports.

File:
1 edited

Legend:

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

    r4994 r5130  
    409409}
    410410
    411 void send_headers(FILE *f, int32_t status, char *title, char *extra, char *mime, int32_t cache){
     411void send_headers(FILE *f, int32_t status, char *title, char *extra, char *mime, int32_t cache, int8_t forcePlain){
    412412  time_t now;
    413413  char timebuf[32];
    414414  char buf[sizeof(PROTOCOL) + sizeof(SERVER) + strlen(title) + (extra == NULL?0:strlen(extra)+2) + (mime == NULL?0:strlen(mime)+2) + 256];
    415     char *pos = buf;
     415  char *pos = buf;
    416416   
    417417  pos += snprintf(pos, sizeof(buf)-(pos-buf), "%s %d %s\r\n", PROTOCOL, status, title);
     
    437437    pos += snprintf(pos, sizeof(buf)-(pos-buf), "Connection: close\r\n");
    438438    pos += snprintf(pos, sizeof(buf)-(pos-buf),"\r\n");
    439     webif_write(buf, f);
     439    if(forcePlain == 1) fwrite(buf, 1, strlen(buf), f);
     440    else webif_write(buf, f);
    440441}
    441442
     
    474475}
    475476
    476 void send_error(FILE *f, int32_t status, char *title, char *extra, char *text){
     477void send_error(FILE *f, int32_t status, char *title, char *extra, char *text, int8_t forcePlain){
    477478    char buf[(2* strlen(title)) + strlen(text) + 128];
    478479    char *pos = buf;
    479     send_headers(f, status, title, extra, "text/html", 0);
     480    send_headers(f, status, title, extra, "text/html", 0, forcePlain);
    480481    pos += snprintf(pos, sizeof(buf)-(pos-buf), "<HTML><HEAD><TITLE>%d %s</TITLE></HEAD>\r\n", status, title);
    481482    pos += snprintf(pos, sizeof(buf)-(pos-buf), "<BODY><H4>%d %s</H4>\r\n", status, title);
    482483    pos += snprintf(pos, sizeof(buf)-(pos-buf), "%s\r\n", text);
    483484    pos += snprintf(pos, sizeof(buf)-(pos-buf), "</BODY></HTML>\r\n");
    484     webif_write(buf, f);
     485    if(forcePlain == 1) fwrite(buf, 1, strlen(buf), f);
     486    else webif_write(buf, f);
    485487}
    486488
    487489void send_error500(FILE *f){
    488     send_error(f, 500, "Internal Server Error", NULL, "The server encountered an internal error that prevented it from fulfilling this request.");
     490    send_error(f, 500, "Internal Server Error", NULL, "The server encountered an internal error that prevented it from fulfilling this request.", 0);
    489491}
    490492
Note: See TracChangeset for help on using the changeset viewer.