Esempio n. 1
0
evhtp_connection::evhtp_connection(evhtp * htp, int sock) {
    this->evbase    = NULL;
    this->bev       = NULL;
    //connection->thread    = NULL;
    this->ssl       = NULL;
    this->hooks     = NULL;
    this->request   = NULL;
    this->resume_ev = NULL;
    this->error     = 0;
    this->sock      = sock;
    this->htp       = htp;
    this->parser    = htparser_new();

	if(this->parser==NULL)
		throw std::runtime_error("create parser fail");

	this->parser->init(htp_type_request);
	this->parser->set_userdata(this);
}
Esempio n. 2
0
int
main(int argc, char ** argv) {
    htparser    * p     = htparser_new();
    htparse_hooks hooks = {
        .on_msg_begin       = _on_msg_start,
        .method             = _method,
        .scheme             = NULL,
        .host               = NULL,
        .port               = NULL,
        .path               = _path,
        .args               = _args,
        .uri                = _uri,
        .on_hdrs_begin      = _hdrs_start,
        .hdr_key            = _hdr_key,
        .hdr_val            = _hdr_val,
        .on_hdrs_complete   = _hdrs_end,
        .on_new_chunk       = _on_new_chunk,
        .on_chunk_complete  = NULL,
        .on_chunks_complete = NULL,
        .body               = _read_body,
        .on_msg_complete    = _on_msg_end
    };

    const char  * test_1                = "GET / HTTP/1.0\r\n\r\n";
    const char  * test_2                = "GET /hi?a=b&c=d HTTP/1.1\r\n\r\n";
    const char  * test_3                = "GET /hi/die/?a=b&c=d HTTP/1.1\r\n\r\n";
    const char  * test_4                = "POST /fjdls HTTP/1.0\r\n"
                                          "Content-Length: 4\r\n"
                                          "\r\n"
                                          "abcd";
    const char * test_7                 = "POST /derp HTTP/1.1\r\n"
                                          "Transfer-Encoding: chunked\r\n\r\n"
                                          "1e\r\nall your base are belong to us\r\n"
                                          "0\r\n"
                                          "\r\n\0";
    const char * test_8                 = "GET /DIE HTTP/1.1\r\n"
                                          "HERP: DE\r\n"
                                          "\tRP\r\nthings:stuff\r\n\r\n";
    const char * test_9                 = "GET /big_content_len HTTP/1.1\r\n"
                                          "Content-Length: 18446744073709551615\r\n\r\n";

    const char * test_fail              = "GET /JF HfD]\r\n\r\n";
    const char * test_resp_1            = "HTTP/1.0 200 OK\r\n"
                                          "Stuff: junk\r\n\r\n";
    const char * test_empty_header      = "GET /blah HTTP/1.1\r\n"
                                          "Empty: \r\n"
                                          "Stuff: junk\r\n\r\n";
    const char * test_resp_empty_header = "HTTP/1.1 200 OK\r\n"
                                          "Empty: \r\n"
                                          "Things: junk\r\n\r\n";

    const char * test_no_cr             = "GET / HTTP/1.1\n"
                                          "Host: stuff\n"
                                          "Things: blah\n\n";
    const char * test_no_hdr_cr         = "GET / HTTP/1.1\r\n"
                                          "Host: things\n"
                                          "Stuff: blah\n\n";
    const char * test_no_hdr_cr_end     = "GET / HTTP/1.1\r\n"
                                          "Host: blah\r\n"
                                          "things: stuff\n\n\r\n";



    _test(p, &hooks, test_resp_1, htp_type_response);
    _test(p, &hooks, test_1, htp_type_request);
    _test(p, &hooks, test_2, htp_type_request);
    _test(p, &hooks, test_3, htp_type_request);
    _test(p, &hooks, test_4, htp_type_request);
    _test(p, &hooks, test_7, htp_type_request);
    _test(p, &hooks, test_8, htp_type_request);
    _test(p, &hooks, test_9, htp_type_request);
    _test(p, &hooks, test_fail, htp_type_request);
    _test(p, &hooks, test_empty_header, htp_type_request);
    _test(p, &hooks, test_resp_empty_header, htp_type_response);
    _test(p, &hooks, test_no_cr, htp_type_request);
    _test(p, &hooks, test_no_hdr_cr, htp_type_request);
    _test(p, &hooks, test_no_hdr_cr_end, htp_type_request);

    _test_fragments(p, &hooks, test_fragment_1, htp_type_request);
    _test_fragments(p, &hooks, test_fragment_2, htp_type_request);
    _test_fragments(p, &hooks, test_chunk_fragment_1, htp_type_request);
    _test_fragments(p, &hooks, test_chunk_fragment_2, htp_type_request);

    return 0;
} /* main */