static onion_connection_status parse_headers_KEY(onion_request *req, onion_buffer *data){ onion_token *token=req->parser_data; int res=token_read_KEY(token, data); if (res<=1000) return res; ONION_DEBUG0("Got %d at KEY",res); if ( res == NEW_LINE ){ if ((req->flags&OR_METHODS)==OR_POST){ const char *content_type=onion_request_get_header(req, "Content-Type"); if (content_type && (strstr(content_type,"application/x-www-form-urlencoded") || strstr(content_type, "boundary"))) return prepare_POST(req); } if ((req->flags&OR_METHODS)==OR_PUT) return prepare_PUT(req); if (onion_request_get_header(req, "Content-Length")){ // Some length, not POST, get data. int n=atoi(onion_request_get_header(req, "Content-Length")); if (n>0) return prepare_CONTENT_LENGTH(req); } return OCS_REQUEST_READY; } assert(token->extra==NULL); token->extra=onion_low_strdup(token->str); req->parser=parse_headers_VALUE; return parse_headers_VALUE(req, data); }
static onion_connection_status parse_headers_KEY(onion_request *req, onion_buffer *data){ onion_token *token=req->parser_data; int res=token_read_KEY(token, data); if (res<=1000) return res; ONION_DEBUG0("Got %d at KEY",res); if ( res == NEW_LINE ){ #if 0 if ((req->flags&OR_METHODS)==OR_POST) return prepare_POST(req); #endif if ((req->flags&OR_METHODS)==OR_PUT) return prepare_PUT(req); if (onion_request_get_header(req, "Content-Length")){ // Soem length, not POST, get data. int n=atoi(onion_request_get_header(req, "Content-Length")); if (n>0) return prepare_CONTENT_LENGTH(req); } return onion_request_process(req); } token->extra=strdup(token->str); req->parser=parse_headers_VALUE; return parse_headers_VALUE(req, data); }
static onion_connection_status parse_POST_multipart_headers_key(onion_request *req, onion_buffer *data){ onion_token *token=req->parser_data; int res=token_read_KEY(token, data); if (res<=1000) return res; if (res==NEW_LINE){ if (!req->POST) req->POST=onion_dict_new(); ONION_DEBUG("New line"); onion_multipart_buffer *multipart=(onion_multipart_buffer*)token->extra; multipart->pos=0; if (multipart->filename){ char filename[]="/tmp/onion-XXXXXX"; multipart->fd=mkstemp(filename); if (multipart->fd<0) ONION_ERROR("Could not create temporal file at %s.", filename); if (!req->FILES) req->FILES=onion_dict_new(); onion_dict_add(req->POST,multipart->name,multipart->filename, 0); onion_dict_add(req->FILES,multipart->name, filename, OD_DUP_VALUE); ONION_DEBUG0("Created temporal file %s",filename); req->parser=parse_POST_multipart_file; return parse_POST_multipart_file(req, data); } else{ req->parser=parse_POST_multipart_data; return parse_POST_multipart_data(req, data); } } // Only interested in one header if (strcmp(token->str,"Content-Disposition")==0){ req->parser=parse_POST_multipart_content_type; return parse_POST_multipart_content_type(req,data); } ONION_DEBUG("Not interested in header '%s'",token->str); req->parser=parse_POST_multipart_ignore_header; return parse_POST_multipart_ignore_header(req,data); }