Ignore:
Timestamp:
11/19/10 10:08:02 (10 years ago)
Author:
_network
Message:

Webif: add code for ssl support (not working yet)

File:
1 edited

Legend:

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

    r3830 r3929  
    369369}
    370370
     371#ifdef WITH_SSL
     372#include <openssl/crypto.h>
     373#include <openssl/ssl.h>
     374#include <openssl/err.h>
     375#endif
     376
     377int webif_write(char *buf, FILE* f) {
     378#ifdef WITH_SSL
     379    return SSL_write((SSL*)f, buf, strlen(buf));
     380#else
     381    return fwrite(buf, 1, strlen(buf), f);
     382#endif
     383}
     384
     385int webif_read(char *buf, int num, FILE *f) {
     386#ifdef WITH_SSL
     387    return SSL_read((SSL*)f, buf, num);
     388#else
     389    buf[0]='\0';
     390    int len=0;
     391    while (fgets(buf+len, num-len-1, f)) {
     392        if (buf[0+len] == '\r' && buf[1+len] == '\n') break;
     393        len=strlen(buf);
     394    }
     395    return len;
     396#endif
     397}
     398
    371399void send_headers(FILE *f, int status, char *title, char *extra, char *mime){
    372400
    373401  time_t now;
    374402  char timebuf[128];
    375 
    376   fprintf(f, "%s %d %s\r\n", PROTOCOL, status, title);
    377   fprintf(f, "Server: %s\r\n", SERVER);
     403  char buf[1024];
     404
     405  sprintf(buf, "%s %d %s\r\n", PROTOCOL, status, title);
     406  sprintf(buf, "Server: %s\r\n", SERVER);
    378407
    379408  now = time(NULL);
    380409  strftime(timebuf, sizeof(timebuf), RFC1123FMT, gmtime(&now));
    381   fprintf(f, "Date: %s\r\n", timebuf);
    382 
    383   if (extra)
    384         fprintf(f, "%s\r\n", extra);
    385 
    386   if (mime)
    387         fprintf(f, "Content-Type: %s\r\n", mime);
     410  sprintf(buf, "Date: %s\r\n", timebuf);
     411
     412    if (extra)
     413        sprintf(buf, "%s\r\n", extra);
     414
     415    if (mime)
     416        sprintf(buf, "Content-Type: %s\r\n", mime);
    388417
    389418    strftime(timebuf, sizeof(timebuf), RFC1123FMT, gmtime(&now));
    390     fprintf(f, "Cache-Control: no-store, no-cache, must-revalidate\r\n");
    391     fprintf(f, "Expires: Sat, 26 Jul 1997 05:00:00 GMT\r\n");
    392     fprintf(f, "Last-Modified: %s\r\n", timebuf);
    393     fprintf(f, "Connection: close\r\n");
    394     fprintf(f, "\r\n");
     419    sprintf(buf, "Cache-Control: no-store, no-cache, must-revalidate\r\n");
     420    sprintf(buf, "Expires: Sat, 26 Jul 1997 05:00:00 GMT\r\n");
     421    sprintf(buf, "Last-Modified: %s\r\n", timebuf);
     422    sprintf(buf, "Connection: close\r\n");
     423    sprintf(buf, "\r\n");
     424    webif_write(buf, f);
    395425}
    396426
     
    402432
    403433        if((fp = fopen(cfg->http_css,"r"))==NULL) return;
    404         while((read = fread(&buffer,sizeof(char),1024,fp)) > 0) fwrite(&buffer, sizeof(char), read, f);
     434        while((read = fread(buffer,sizeof(char),1024,fp)) > 0) webif_write(buffer, f);
    405435        fclose (fp);
    406436    } else {
    407         fputs(CSS, f);
     437        webif_write(CSS, f);
    408438    }
    409439}
     
    416446
    417447        if((fp = fopen(cfg->http_jscript,"r"))==NULL) return;
    418         while((read = fread(&buffer,sizeof(char),1024,fp)) > 0) fwrite(&buffer, sizeof(char), read, f);
     448        while((read = fread(buffer,sizeof(char),1024,fp)) > 0) webif_write(buffer, f);
    419449        fclose (fp);
    420450    } else {
    421         fputs(JSCRIPT, f);
     451        webif_write(JSCRIPT, f);
    422452    }
    423453}
    424454
    425455void send_error(FILE *f, int status, char *title, char *extra, char *text){
    426   send_headers(f, status, title, extra, "text/html");
    427   fprintf(f, "<HTML><HEAD><TITLE>%d %s</TITLE></HEAD>\r\n", status, title);
    428   fprintf(f, "<BODY><H4>%d %s</H4>\r\n", status, title);
    429   fprintf(f, "%s\r\n", text);
    430   fprintf(f, "</BODY></HTML>\r\n");
     456    char buf[1024];
     457    send_headers(f, status, title, extra, "text/html");
     458    sprintf(buf, "<HTML><HEAD><TITLE>%d %s</TITLE></HEAD>\r\n", status, title);
     459    sprintf(buf, "<BODY><H4>%d %s</H4>\r\n", status, title);
     460    sprintf(buf, "%s\r\n", text);
     461    sprintf(buf, "</BODY></HTML>\r\n");
     462    webif_write(buf, f);
    431463}
    432464
Note: See TracChangeset for help on using the changeset viewer.