From 73d7ee599d2c34bfc578db53f8667d95669b3b21 Mon Sep 17 00:00:00 2001 From: Mark Ellzey Date: Sun, 12 Apr 2015 01:44:08 -0400 Subject: [PATCH] Various fixes / added SOVERSION'ing --- CMakeLists.txt | 24 ++++++++++++------- examples/test.c | 61 +++++++++++++++++++++++++++++++++---------------- htparse.c | 23 ++++++++++++++----- 3 files changed, 74 insertions(+), 34 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c39816..fa2f711 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -300,6 +300,10 @@ configure_file( add_library(evhtp ${EVHTP_LIBTYPE} ${LIBEVHTP_SOURCES} ${ONIG_SOURCES}) target_link_libraries(evhtp ${LIBEVHTP_EXTERNAL_LIBS}) +if (EVHTP_BUILD_SHARED) + set_target_properties(evhtp PROPERTIES SOVERSION "${PROJECT_VERSION}") +endif() + add_subdirectory(tools) add_subdirectory(examples) @@ -326,6 +330,11 @@ if (NOT EVHTP_DISABLE_REGEX) endif() endif() +if (NOT HAVE_SYS_QUEUE) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/compat/sys/queue.h + DESTINATION ${INCLUDE_INSTALL_DIR}/evhtp/sys) +endif() + IF (WIN32) install (FILES compat/sys/queue.h DESTINATION ${INCLUDE_INSTALL_DIR}/sys) install (FILES oniguruma/onigposix.h DESTINATION ${INCLUDE_INSTALL_DIR}) @@ -335,7 +344,6 @@ configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/evhtp.pc.in ${CMAKE_CURRENT_BINARY_DIR}/evhtp.pc @ONLY) - # add_definitions() calls do not show up in the C_FLAGS var # it is instead a property of COMPILE_DEFINITIONS. # @@ -351,13 +359,13 @@ endforeach() string(REPLACE ";" " -D" CFLAG_DEFS "${CFLAG_LIST}") message("") -message(STATUS "${BoldBlue}EVHTP_VERSION${ColourReset} : ${BoldGreen} ${PROJECT_VERSION} ${ColourReset}") -message(STATUS "${BoldBlue}EVHTP_DISABLE_SSL${ColourReset} : ${BoldGreen} ${EVHTP_DISABLE_SSL} ${ColourReset}") -message(STATUS "${BoldBlue}EVHTP_DISABLE_EVTHR${ColourReset} : ${BoldGreen} ${EVHTP_DISABLE_EVTHR} ${ColourReset}") -message(STATUS "${BoldBlue}EVHTP_DISABLE_REGEX${ColourReset} : ${BoldGreen} ${EVHTP_DISABLE_REGEX} ${ColourReset}") -message(STATUS "${BoldBlue}EVHTP_BUILD_SHARED${ColourReset} : ${BoldGreen} ${EVHTP_BUILD_SHARED} ${ColourReset}") -message(STATUS "${BoldBlue}EVHTP_USE_JEMALLOC${ColourReset} : ${BoldGreen} ${EVHTP_USE_JEMALLOC} ${ColourReset}") -message(STATUS "${BoldBlue}EVHTP_USE_TCMALLOC${ColourReset} : ${BoldGreen} ${EVHTP_USE_TCMALLOC} ${ColourReset}") +message(STATUS "${BoldBlue}EVHTP_VERSION${ColourReset} : ${BoldGreen} ${PROJECT_VERSION}${ColourReset}") +message(STATUS "${BoldBlue}EVHTP_DISABLE_SSL${ColourReset} : ${BoldGreen} ${EVHTP_DISABLE_SSL}${ColourReset}") +message(STATUS "${BoldBlue}EVHTP_DISABLE_EVTHR${ColourReset} : ${BoldGreen} ${EVHTP_DISABLE_EVTHR}${ColourReset}") +message(STATUS "${BoldBlue}EVHTP_DISABLE_REGEX${ColourReset} : ${BoldGreen} ${EVHTP_DISABLE_REGEX}${ColourReset}") +message(STATUS "${BoldBlue}EVHTP_BUILD_SHARED${ColourReset} : ${BoldGreen} ${EVHTP_BUILD_SHARED}${ColourReset}") +message(STATUS "${BoldBlue}EVHTP_USE_JEMALLOC${ColourReset} : ${BoldGreen} ${EVHTP_USE_JEMALLOC}${ColourReset}") +message(STATUS "${BoldBlue}EVHTP_USE_TCMALLOC${ColourReset} : ${BoldGreen} ${EVHTP_USE_TCMALLOC}${ColourReset}") message("") message(STATUS "${Blue}CMAKE_BUILD_TYPE${ColourReset} : " ${BoldRed}${CMAKE_BUILD_TYPE}${ColourReset}) message(STATUS "${Blue}CMAKE_INSTALL_PREFIX${ColourReset} : " ${BoldMagenta}${CMAKE_INSTALL_PREFIX}${ColourReset}) diff --git a/examples/test.c b/examples/test.c index 4c686ec..dd385e4 100644 --- a/examples/test.c +++ b/examples/test.c @@ -6,9 +6,12 @@ #include #include #include -#include #include +#include "../evhtp-internal.h" +#include "../evhtp.h" + + #ifndef EVHTP_DISABLE_EVTHR int use_threads = 0; int num_threads = 0; @@ -21,7 +24,7 @@ char * ssl_ca = NULL; char * ssl_capath = NULL; size_t bw_limit = 0; uint64_t max_keepalives = 0; -int backlog = 1024; +int backlog = 1024; struct pauser { event_t * timer_ev; @@ -479,9 +482,9 @@ parse_args(int argc, char ** argv) { case 'm': max_keepalives = atoll(optarg); break; - case 'b': - backlog = atoll(optarg); - break; + case 'b': + backlog = atoll(optarg); + break; default: printf("Unknown opt %s\n", optarg); return -1; @@ -537,32 +540,50 @@ main(int argc, char ** argv) { evhtp_set_parser_flags(htp, EVHTP_PARSE_QUERY_FLAG_LENIENT); evhtp_set_max_keepalive_requests(htp, max_keepalives); - //htp->enable_nodelay = 1; - //htp->enable_defer_accept = 1; + /* htp->enable_nodelay = 1; */ + /* htp->enable_defer_accept = 1; */ htp->enable_reuseport = 1; - cb_1 = evhtp_set_cb(htp, "/ref", test_default_cb, "fjdkls"); - cb_2 = evhtp_set_cb(htp, "/foo", test_foo_cb, "bar"); - cb_3 = evhtp_set_cb(htp, "/foo/", test_foo_cb, "bar"); - cb_4 = evhtp_set_cb(htp, "/bar", test_bar_cb, "baz"); - cb_5 = evhtp_set_cb(htp, "/500", test_500_cb, "500"); + cb_1 = evhtp_set_cb(htp, "/ref", test_default_cb, "fjdkls"); + evhtp_assert(cb_1 != NULL); + + cb_2 = evhtp_set_cb(htp, "/foo", test_foo_cb, "bar"); + evhtp_assert(cb_2 != NULL); + + cb_3 = evhtp_set_cb(htp, "/foo/", test_foo_cb, "bar"); + evhtp_assert(cb_3 != NULL); + + cb_4 = evhtp_set_cb(htp, "/bar", test_bar_cb, "baz"); + evhtp_assert(cb_4 != NULL); + + cb_5 = evhtp_set_cb(htp, "/500", test_500_cb, "500"); + evhtp_assert(cb_5 != NULL); + #ifndef EVHTP_DISABLE_REGEX - cb_6 = evhtp_set_regex_cb(htp, "^(/anything/).*", test_regex, NULL); + cb_6 = evhtp_set_regex_cb(htp, "^(/anything/).*", test_regex, NULL); + evhtp_assert(cb_6 != NULL); #endif - cb_7 = evhtp_set_cb(htp, "/pause", test_pause_cb, NULL); + cb_7 = evhtp_set_cb(htp, "/pause", test_pause_cb, NULL); + evhtp_assert(cb_7 != NULL); #ifndef EVHTP_DISABLE_REGEX - cb_8 = evhtp_set_regex_cb(htp, "^/create/(.*)", create_callback, NULL); + cb_8 = evhtp_set_regex_cb(htp, "^/create/(.*)", create_callback, NULL); + evhtp_assert(cb_8 != NULL); #endif - cb_9 = evhtp_set_glob_cb(htp, "*/glob/*", test_glob_cb, NULL); - cb_10 = evhtp_set_cb(htp, "/max_body_size", test_max_body, NULL); + cb_9 = evhtp_set_glob_cb(htp, "*/glob/*", test_glob_cb, NULL); + evhtp_assert(cb_9 != NULL); + + cb_10 = evhtp_set_cb(htp, "/max_body_size", test_max_body, NULL); + evhtp_assert(cb_10 != NULL); /* set a callback to test out chunking API */ - cb_11 = evhtp_set_cb(htp, "/chunkme", test_chunking, NULL); + cb_11 = evhtp_set_cb(htp, "/chunkme", test_chunking, NULL); + evhtp_assert(cb_11 != NULL); /* set a callback which takes ownership of the underlying bufferevent and * just starts echoing things */ - cb_12 = evhtp_set_cb(htp, "/ownme", test_ownership, NULL); + cb_12 = evhtp_set_cb(htp, "/ownme", test_ownership, NULL); + evhtp_assert(cb_12 != NULL); /* set a callback to pause on each header for cb_7 */ evhtp_set_hook(&cb_7->hooks, evhtp_hook_on_path, pause_init_cb, NULL); @@ -578,7 +599,7 @@ main(int argc, char ** argv) { evhtp_set_gencb(htp, test_default_cb, "foobarbaz"); /* set a callback invoked before a connection is accepted */ - //evhtp_set_pre_accept_cb(htp, test_pre_accept, &bind_port); + evhtp_set_pre_accept_cb(htp, test_pre_accept, &bind_port); /* set a callback to set per-connection hooks (via a post_accept cb) */ evhtp_set_post_accept_cb(htp, set_my_connection_handlers, NULL); diff --git a/htparse.c b/htparse.c index 5b7c20f..ffc9a22 100644 --- a/htparse.c +++ b/htparse.c @@ -1635,8 +1635,9 @@ htparser_run(htparser * p, htparse_hooks * hooks, const char * data, size_t len) break; case eval_hdr_val_connection: switch (p->buf[0]) { - char A_case; - char C_case; + char A_case; + char C_case; + const char * S_buf; case 'K': case 'k': @@ -1645,8 +1646,9 @@ htparser_run(htparser * p, htparse_hooks * hooks, const char * data, size_t len) } A_case = (p->buf[5] == 'A') ? 'A' : 'a'; + S_buf = (const char *)(p->buf + 1); - if (_str9cmp((p->buf + 1), + if (_str9cmp(S_buf, 'e', 'e', 'p', '-', A_case, 'l', 'i', 'v', 'e')) { p->flags |= parser_flag_connection_keep_alive; } @@ -1658,8 +1660,9 @@ htparser_run(htparser * p, htparse_hooks * hooks, const char * data, size_t len) } C_case = (p->buf[0] == 'C') ? 'C' : 'c'; + S_buf = (const char *)p->buf; - if (_str5cmp(p->buf, C_case, 'l', 'o', 's', 'e')) { + if (_str5cmp(S_buf, C_case, 'l', 'o', 's', 'e')) { p->flags |= parser_flag_connection_close; } break; @@ -1671,13 +1674,17 @@ htparser_run(htparser * p, htparse_hooks * hooks, const char * data, size_t len) } switch (p->buf[0]) { + const char * S_buf; + case 'c': case 'C': if (p->buf_idx != 7) { break; } - if (_str6cmp((p->buf + 1), 'h', 'u', 'n', 'k', 'e', 'd')) { + S_buf = (const char *)(p->buf + 1); + + if (_str6cmp(S_buf, 'h', 'u', 'n', 'k', 'e', 'd')) { p->flags |= parser_flag_chunked; } @@ -1691,9 +1698,13 @@ htparser_run(htparser * p, htparse_hooks * hooks, const char * data, size_t len) } switch (p->buf[0]) { + const char * S_buf; + case 'm': case 'M': - if (_str8cmp((p->buf + 1), 'u', 'l', 't', 'i', 'p', 'a', 'r', 't')) { + S_buf = (const char *)(p->buf + 1); + + if (_str8cmp(S_buf, 'u', 'l', 't', 'i', 'p', 'a', 'r', 't')) { p->multipart = 1; }