Beispiel #1
0
int GetHeaderValueFromCollection(vector<SSDP_HTTP_HEADER*> headers, u8* fieldname, int fieldnamelen, u8** value, int *len){
	int ret=0;
	int found=0;
	
	vector<SSDP_HTTP_HEADER*>::const_iterator it;
	SSDP_HTTP_HEADER *hdr;
	
	if(headers.size() <= 0){
		ret = -1;
		goto EXIT;
	}
	
	for(it=headers.begin(); it<headers.end(); it++){
		hdr = *it;
		if(caseinstringcmp(fieldname, fieldnamelen, hdr->fieldname, hdr->fieldnamelen) == 0){
			//found
			found=1;
			break;
		}
	}
	
	if(found){
		*value=hdr->fieldvalue;
		*len=hdr->fieldvaluelen;
	}else{
		ret =-1;
	}
	
EXIT:
	return ret;
}
Beispiel #2
0
int cachecontroltoi(u8* s, u32 l){
	u32 ret = -1;
	u32 p;
	
	char buf[1024];
	int buflen=1024;
	
	if(l >= buflen){
		return ret;
	}
	
	memcpy(&buf, s, l);
	buf[l]=0;
	
	//max-age=nn
	trimspaces(&s, &l);
	if(l >= 7 && caseinstringcmp(s, 7, (u8*)"max-age", 7) == 0){
		//search the =
		p = getchar((u8*)buf, strlen(buf), '=');
		if(p > 0){
			ret = atoi(buf+p+1);
		}
	}
	
	return ret;
}
Beispiel #3
0
//modifies the buffer (!)
int HTTPSession::ParseHeader(unsigned char* buf, int len){
    u8* pos = buf;
    int poslen = len;
    int space = 0;
    int eol = 0;
    int colon = 0;

    //Parse http header
    //New request
    /*
     * Parse Request line
     * method<space>path<space>version<cr><lf>
     */
    //Method
    space = getchar(pos, poslen, ' ');
    pos[space]=0;
    mMethod = (char*)pos;
    pos = pos + space + 1;
    poslen = (buf + len) - pos;

    //Path
    space = getchar(pos, poslen, ' ');
    pos[space]=0;
    mPath = (char*)pos;
    pos = pos + space + 1;
    poslen = (buf + len) - pos;

    //Version
    eol = getchar(pos, poslen, '\r');
    pos[eol]=0;
    mVersion = (char*)pos;
    pos = pos + eol + 2;
    poslen = (buf + len) - pos;

    /*
     * Parse headers
     */
    string headerName;
    string headerValue;
    mContentlength = -1;

    mHeaders.clear();

    while (true) {
        colon = getchar(pos, poslen, ':');
        eol = getchar(pos, poslen, '\r');

        if(eol < 0){
            break;
        }

        if(colon <= 0 || colon > eol){
            while(*pos == '\r' || *pos == '\n' || *pos == ' '){
                pos++;
                poslen--;
            }
            break;//end of header
        }

        pos[colon] = 0;
        pos[eol] = 0;

        char* pheadervalue = (char*)pos + colon + 1;
        int tmpeol = eol;

        //LR Trim the header values
        while(*pheadervalue == ' '){
            pheadervalue++;
        }
        while(pheadervalue[tmpeol-1] == ' '){
            pheadervalue[tmpeol-1] = 0;
            tmpeol--;
        }

        headerValue = pheadervalue;//(char*)pos + colon + 1;

        char* pheadername = (char*)pos;
        int tmpcolon = colon;

        while(*pheadername == ' '){
            pheadername++;
        }
        while(pheadername[tmpcolon-1] == ' '){
            pheadername[tmpcolon-1] = 0;
            tmpcolon--;
        }

        headerName = pheadername;//(char*)pos;

        //Content length ?
        if( caseinstringcmp((u8*)pos, strlen((char*)pos), (u8*)"CONTENT-LENGTH", 14) == 0 ){
            mContentlength = atoi((char*)pos + colon + 1);
        }

        pos = pos + eol + 2;
        poslen = (buf + len) - pos;

        //add it to the map
        mHeaders[headerName] = headerValue;
    }

    mHeaderlength = len - poslen;

    return mHeaderlength;
}