Changeset 4137


Ignore:
Timestamp:
12/17/10 17:58:19 (13 years ago)
Author:
_network
Message:

WebIf: add POST support

Location:
trunk
Files:
4 edited

Legend:

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

    r4031 r4137  
    390390    } else
    391391#endif
    392     {
    393         buf[0]='\0';
    394         int len=0;
    395         while (fgets(buf+len, num-len-1, f)) {
    396             if (buf[0+len] == '\r' && buf[1+len] == '\n') break;
    397             len=strlen(buf);
    398         }
    399         return len;
    400     }
     392        return read(fileno(f), buf, num);
    401393}
    402394
  • trunk/oscam-http.c

    r4129 r4137  
    25592559}
    25602560
     2561void webif_parse_request(struct uriparams *params, char *pch) {
     2562    /* Parse url parameters; parsemode = 1 means parsing next param, parsemode = -1 parsing next
     2563     value; pch2 points to the beginning of the currently parsed string, pch is the current position */
     2564
     2565    char *pch2;
     2566    int parsemode = 1;
     2567
     2568    pch2=pch;
     2569    while(pch[0] != '\0') {
     2570        if((parsemode == 1 && pch[0] == '=') || (parsemode == -1 && pch[0] == '&')) {
     2571            pch[0] = '\0';
     2572            urldecode(pch2);
     2573            if(parsemode == 1) {
     2574                if(params->paramcount >= MAXGETPARAMS) break;
     2575                ++params->paramcount;
     2576                params->params[params->paramcount-1] = pch2;
     2577            } else {
     2578                params->values[params->paramcount-1] = pch2;
     2579            }
     2580            parsemode = -parsemode;
     2581            pch2 = pch + 1;
     2582        }
     2583        ++pch;
     2584    }
     2585    /* last value wasn't processed in the loop yet... */
     2586    if(parsemode == -1 && params->paramcount <= MAXGETPARAMS) {
     2587        urldecode(pch2);
     2588        params->values[params->paramcount-1] = pch2;
     2589    }
     2590}
     2591
    25612592int process_request(FILE *f, struct in_addr in) {
    25622593
     
    26212652    }
    26222653
    2623     char buf[4096];
     2654    char buf[10240];
    26242655    char *tmp;
    26252656
     
    26312662    char *protocol;
    26322663    char *pch;
    2633     char *pch2;
    26342664    /* List of possible pages */
    26352665    char *pages[]= {
     
    26582688    int pgidx = -1;
    26592689    int i;
    2660     int parsemode = 1;
    26612690    struct uriparams params;
    26622691    params.paramcount = 0;
     
    26652694    char *saveptr1=NULL;
    26662695    int n;
    2667     if ((n=webif_read(buf, sizeof(buf), f)) <= 0) {
     2696    if ((n=webif_read(buf, sizeof(buf)-1, f)) <= 0) {
    26682697        cs_debug("webif read error %d", n);
    26692698        return -1;
    26702699    }
     2700    buf[n]='\0';
    26712701
    26722702    method = strtok_r(buf, " ", &saveptr1);
     
    26892719    }
    26902720
    2691     /* Parse url parameters; parsemode = 1 means parsing next param, parsemode = -1 parsing next
    2692      value; pch2 points to the beginning of the currently parsed string, pch is the current position */
    2693     pch2=pch;
    2694     while(pch[0] != '\0') {
    2695         if((parsemode == 1 && pch[0] == '=') || (parsemode == -1 && pch[0] == '&')) {
    2696             pch[0] = '\0';
    2697             urldecode(pch2);
    2698             if(parsemode == 1) {
    2699                 if(params.paramcount >= MAXGETPARAMS) break;
    2700                 ++params.paramcount;
    2701                 params.params[params.paramcount-1] = pch2;
    2702             } else {
    2703                 params.values[params.paramcount-1] = pch2;
    2704             }
    2705             parsemode = -parsemode;
    2706             pch2 = pch + 1;
    2707         }
    2708         ++pch;
    2709     }
    2710     /* last value wasn't processed in the loop yet... */
    2711     if(parsemode == -1 && params.paramcount <= MAXGETPARAMS) {
    2712         urldecode(pch2);
    2713         params.values[params.paramcount-1] = pch2;
    2714     }
     2721    webif_parse_request(&params, pch);
    27152722
    27162723    if(strlen(cfg->http_user) == 0 || strlen(cfg->http_pwd) == 0) authok = 1;
     
    27182725
    27192726    char *str1, *saveptr=NULL;
     2727
    27202728    for (str1=strtok_r(tmp, "\n", &saveptr); str1; str1=strtok_r(NULL, "\n", &saveptr)) {
    2721         if (str1[0] == '\r' && str1[1] == '\n') break;
    2722         else if(authok == 0 && strlen(str1) > 50 && strncmp(str1, "Authorization:", 14) == 0 && strstr(str1, "Digest") != NULL) {
     2729        if (strlen(str1)==1) {
     2730            if (strcmp(method, "POST")==0) {
     2731                webif_parse_request(&params, str1+2);
     2732            }
     2733            break;
     2734        }
     2735        if(authok == 0 && strlen(str1) > 50 && strncmp(str1, "Authorization:", 14) == 0 && strstr(str1, "Digest") != NULL) {
    27232736            authok = check_auth(str1, method, path, expectednonce);
    27242737        }
  • trunk/oscam-http.h

    r4130 r4137  
    318318  ##TPLFILEMENU##\n\
    319319  <BR><BR>##SDEBUG####SLOG####SCLEAR##<BR>##FILTER##\n\
    320   <FORM ACTION=\"files.html\" method=\"get\">\n\
     320  <FORM ACTION=\"files.html\" method=\"post\">\n\
    321321  <INPUT TYPE=\"hidden\" NAME=\"part\" VALUE=\"##PART##\">\n\
    322322  <TEXTAREA NAME=\"filecontent\" CLASS=\"editor\">##FILECONTENT##</TEXTAREA><BR>##WRITEPROTECTION##<BR>\n\
  • trunk/oscam.c

    r4136 r4137  
    31233123                break;
    31243124          case 'x':
     3125#ifdef COOL
    31253126                cooldebug = 1;
     3127#endif
    31263128                break;
    31273129          case 'h':
Note: See TracChangeset for help on using the changeset viewer.