Beispiel #1
0
int parse_request(struct buf *bufp) {
    
    char *p;
    
    p = bufp->parse_p;
    //dbprintf("parse_request:\n\trbuf left to parse:\n%s\n", p);

    // count request number based on CRLF2
    while ((p = strstr(p, CRLF2)) != NULL && p < bufp->rbuf_tail) {
	++(bufp->rbuf_req_count);
	p += strlen(CRLF2);
	bufp->parse_p = p;
    }

    // parse every request
    while (bufp->rbuf_req_count != 0) {

	dbprintf("parse_request: request count %d\n", bufp->rbuf_req_count);

	// calloc http_req
	if (bufp->req_fully_received == 1) {
	    //dbprintf("parse_request: start parsing new request\n");
	    bufp->http_req_p = (struct http_req *)calloc(1, sizeof(struct http_req));

	    bufp->req_fully_received = 0;
	    bufp->req_line_header_received = 0;

	}

	// parse req
	parse_request_line(bufp);
	parse_request_headers(bufp);

	bufp->req_line_header_received = 1;// update 

	parse_message_body(bufp); // set req_fully_received inside

	// if fully received, enqueue	
	if (bufp->req_fully_received == 1) {
	    dbprintf("parse_request: req fully received\n");

	    // update req_queue
	    req_enqueue(bufp->req_queue_p, bufp->http_req_p);

	    // update rbuf
	    --(bufp->rbuf_req_count);
	    bufp->rbuf_head = strstr(bufp->rbuf_head, CRLF2) + strlen(CRLF2);

	} else {
	    // only POST can reach here
	    dbprintf("parse_request: POST req not fully received yet, continue receiving\n");
	    break; // break out while loop
	}
	
    }
    
    return 0;
}
Beispiel #2
0
// generic-message = start-line
//                   *(message-header CRLF)
//                   CRLF
//                   [ message-body ]
const char* parse_generic_message(unsigned char** p)
{
	if (parse_start_line(p))
		return ERR;

	while (0 != (char)**p) {
		if (parse_message_header(p))
			break;
		if (parse_crlf(p))
			return ERR;
	}

	if (parse_crlf(p))
		return ERR;

	return parse_message_body(p);
}