Skip to content

Commit

Permalink
Merge branch 'release/1.1.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Ellzey committed Sep 24, 2012
2 parents 265b9d4 + 129cb3e commit 96be9dd
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 16 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Expand Up @@ -3,7 +3,7 @@ project(reason)

set(PROJECT_MAJOR_VERSION 1)
set(PROJECT_MINOR_VERSION 1)
set(PROJECT_PATCH_VERSION 2)
set(PROJECT_PATCH_VERSION 3)

set (PROJECT_VERSION ${PROJECT_MAJOR_VERSION}.${PROJECT_MINOR_VERSION}.${PROJECT_PATCH_VERSION})
set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeModules)
Expand Down
5 changes: 5 additions & 0 deletions ChangeLog
@@ -1,3 +1,8 @@
v1.1.3
o Added evhtp_unbind_socket() (9c9b508 Mark Ellzey)
o Fixed issue with query argument decoding. (8ff9cf3 Mark Ellzey)
o Fix issue 53, error on LF without CR's (d51b526 Mark Ellzey)

v1.1.2
o Manual verification modes for SNI vhosts. (5f9b3a5 Mark Ellzey)

Expand Down
6 changes: 6 additions & 0 deletions evhtp.c
Expand Up @@ -2480,6 +2480,12 @@ evhtp_send_reply_chunk_end(evhtp_request_t * request) {
evhtp_send_reply_end(request);
}

void
evhtp_unbind_socket(evhtp_t * htp) {
evconnlistener_free(htp->server);
htp->server = NULL;
}

int
evhtp_bind_sockaddr(evhtp_t * htp, struct sockaddr * sa, size_t sin_len, int backlog) {
signal(SIGPIPE, SIG_IGN);
Expand Down
11 changes: 9 additions & 2 deletions evhtp.h
Expand Up @@ -155,10 +155,10 @@ typedef void (*evhtp_ssl_scache_del)(evhtp_t * htp, unsigned char * sid, int sid
typedef evhtp_ssl_sess_t * (*evhtp_ssl_scache_get)(evhtp_connection_t * connection, unsigned char * sid, int sid_len);
typedef void * (*evhtp_ssl_scache_init)(evhtp_t *);

#define EVHTP_VERSION "1.1.2"
#define EVHTP_VERSION "1.1.3"
#define EVHTP_VERSION_MAJOR 1
#define EVHTP_VERSION_MINOR 1
#define EVHTP_VERSION_PATCH 2
#define EVHTP_VERSION_PATCH 3

#define evhtp_headers_iterator evhtp_kvs_iterator

Expand Down Expand Up @@ -646,6 +646,13 @@ int evhtp_unset_all_hooks(evhtp_hooks_t ** hooks);
int evhtp_bind_socket(evhtp_t * htp, const char * addr, uint16_t port, int backlog);


/**
* @brief stops the listening socket.
*
* @param htp
*/
void evhtp_unbind_socket(evhtp_t * htp);

/**
* @brief bind to an already allocated sockaddr.
*
Expand Down
39 changes: 28 additions & 11 deletions htparse/htparse.c
Expand Up @@ -931,19 +931,22 @@ htparser_run(htparser * p, htparse_hooks * hooks, const char * data, size_t len)
p->minor = 9;
p->buf_idx = 0;

p->state = s_hdrline_start;
p->state = s_hdrline_start;
break;
default:
if (ch == '?') {
res = hook_path_run(p, hooks, p->path_offset, (&p->buf[p->buf_idx] - p->path_offset));
p->args_offset = &p->buf[p->buf_idx];
}
case '?':
res = hook_path_run(p, hooks, p->path_offset, (&p->buf[p->buf_idx] - p->path_offset));

p->buf[p->buf_idx++] = ch;
p->buf[p->buf_idx] = '\0';

p->state = s_uri;
p->args_offset = &p->buf[p->buf_idx];
p->state = s_uri;
break;
default:
p->buf[p->buf_idx++] = ch;
p->buf[p->buf_idx] = '\0';

p->state = s_uri;
break;
} /* switch */

Expand Down Expand Up @@ -987,6 +990,18 @@ htparser_run(htparser * p, htparse_hooks * hooks, const char * data, size_t len)
}
}
break;
case '?':

res = hook_path_run(p, hooks, p->path_offset,
(&p->buf[p->buf_idx] - p->path_offset));

p->buf[p->buf_idx++] = ch;
p->buf[p->buf_idx] = '\0';
p->args_offset = &p->buf[p->buf_idx];
break;



case CR:
p->minor = 9;
p->buf_idx = 0;
Expand Down Expand Up @@ -1123,8 +1138,9 @@ htparser_run(htparser * p, htparse_hooks * hooks, const char * data, size_t len)
p->state = s_almost_done;
break;
case LF:
p->state = s_hdrline_start;
break;
/* LF without a CR? error.... */
p->error = htparse_error_inval_reqline;
return i + 1;
default:
if (ch < '0' || ch > '9') {
p->error = htparse_error_inval_ver;
Expand Down Expand Up @@ -1414,8 +1430,9 @@ htparser_run(htparser * p, htparse_hooks * hooks, const char * data, size_t len)

break;
case LF:
p->state = s_hdrline_hdr_done;
break;
/* LF before CR? invalid */
p->error = htparse_error_inval_hdr;
return i + 1;
default:
p->buf[p->buf_idx++] = ch;
p->buf[p->buf_idx] = '\0';
Expand Down
14 changes: 14 additions & 0 deletions htparse/test.c
Expand Up @@ -236,6 +236,17 @@ main(int argc, char ** argv) {
"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);
Expand All @@ -248,6 +259,9 @@ main(int argc, char ** argv) {
_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);
Expand Down
7 changes: 5 additions & 2 deletions test_basic.c
Expand Up @@ -7,7 +7,9 @@

void
testcb(evhtp_request_t * req, void * a) {
evbuffer_add_reference(req->buffer_out, "foobar", 6, NULL, NULL);
const char * str = a;

evbuffer_add_printf(req->buffer_out, "%s", str);
evhtp_send_reply(req, EVHTP_RES_OK);
}

Expand All @@ -16,7 +18,8 @@ main(int argc, char ** argv) {
evbase_t * evbase = event_base_new();
evhtp_t * htp = evhtp_new(evbase, NULL);

// evhtp_set_cb(htp, "/test", testcb, NULL);
evhtp_set_cb(htp, "/1/ping", testcb, "one");
evhtp_set_cb(htp, "/1/ping.json", testcb, "two");
#ifndef EVHTP_DISABLE_EVTHR
evhtp_use_threads(htp, NULL, 4, NULL);
#endif
Expand Down

0 comments on commit 96be9dd

Please sign in to comment.