Browse files

Merge branch 'release/1.1.3'

  • Loading branch information...
2 parents 265b9d4 + 129cb3e commit 96be9dd97a876672f9ed7d77f2ede220659374e7 Mark Ellzey committed Sep 24, 2012
Showing with 68 additions and 16 deletions.
  1. +1 −1 CMakeLists.txt
  2. +5 −0 ChangeLog
  3. +6 −0 evhtp.c
  4. +9 −2 evhtp.h
  5. +28 −11 htparse/htparse.c
  6. +14 −0 htparse/test.c
  7. +5 −2 test_basic.c
View
2 CMakeLists.txt
@@ -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)
View
5 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)
View
6 evhtp.c
@@ -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);
View
11 evhtp.h
@@ -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
@@ -647,6 +647,13 @@ int evhtp_bind_socket(evhtp_t * htp, const char * addr, uint16_t port, int backl
/**
+ * @brief stops the listening socket.
+ *
+ * @param htp
+ */
+void evhtp_unbind_socket(evhtp_t * htp);
+
+/**
* @brief bind to an already allocated sockaddr.
*
* @param htp
View
39 htparse/htparse.c
@@ -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 */
@@ -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;
@@ -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;
@@ -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';
View
14 htparse/test.c
@@ -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);
@@ -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);
View
7 test_basic.c
@@ -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);
}
@@ -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

0 comments on commit 96be9dd

Please sign in to comment.