diff --git a/CMakeLists.txt b/CMakeLists.txt index e08acb3..481ddd0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.1) list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) -project(libevhtp VERSION "1.2.17") +project(libevhtp VERSION "1.2.18") # For us YCM users. set(CMAKE_EXPORT_COMPILE_COMMANDS ON) @@ -34,6 +34,7 @@ check_include_files(stdarg.h HAVE_STDARG_PROTOTYPES) check_include_files(sys/tree.h HAVE_SYS_TREE) check_include_files(sys/queue.h HAVE_SYS_QUEUE) check_include_files(sys/un.h HAVE_SYS_UN) +check_include_files(sys/types.h HAVE_SYS_TYPES_H) check_type_size("int" SIZEOF_INT) check_type_size("long" SIZEOF_LONG) @@ -126,6 +127,10 @@ if(has_c99) target_compile_definitions(evhtp PUBLIC EVHTP_HAS_C99) endif() +if (HAVE_SYS_TYPES_H) + target_compile_definitions(evhtp PUBLIC EVHTP_HAS_SYS_TYPES) +endif() + if(NOT HAVE_SYS_TREE) configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/compat/sys/tree.h.in diff --git a/ChangeLog b/ChangeLog index 2a4491e..7b4d906 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,14 @@ -v1.2.17 +v1.2.18 + o Add htp__evbuffer_add_iovec_ helper for libevent < 2.1 (8991567 Nathan French) + o [#122] Fix compilation without deprecated OpenSSL 1.1 APIs (78e8e41 Rosen Penev) + o [#122] Reorganize OpenSSL < 1.0.0 compatibility for greater readability. (8e543fe Rosen Penev) + o [#123] add missing include for ssize_t (6a74ec7 maxice8) + o [#123] include sys/types only if EVHTP_HAS_SYS_TYPES is set (0839f8e Nathan French) + o [#122] cleanup for ssl locking changes (7d0fd5d Nathan French) + o better get0_notBefore ssl defs (8ae5cdd Nathan French) + o cleanup / optimization for iovec operations (874a225 Nathan French) + +v1.2.17 (alpha/beta) o [#111] assert frontends not compiled with -DNDEBUG (07d6f5f Nathan French) o [#111] Remove asserts for alloc functions. (#112) (114bf53 Nathan French) o [#108] do not include content-length with chunked (#113) (73255df Nathan French) diff --git a/evhtp.c b/evhtp.c index 5a4915a..8d34676 100644 --- a/evhtp.c +++ b/evhtp.c @@ -2013,25 +2013,46 @@ htp__request_parse_fini_(htparser * p) return 0; } /* htp__request_parse_fini_ */ -static int -htp__create_headers_(evhtp_header_t * header, void * arg) +static size_t +htp__evbuffer_add_iovec_(struct evbuffer * buf, struct evbuffer_iovec * vec, int n_vec) { - struct evbuffer * buf = arg; - struct evbuffer_iovec iov[4]; +#if LIBEVENT_VERSION_NUMBER < 0x02010000 + int n; + size_t res; + size_t to_alloc; - iov[0].iov_base = header->key; - iov[0].iov_len = header->klen; + res = to_alloc = 0; - iov[1].iov_base = ": "; - iov[1].iov_len = 2; + for (n = 0; n < n_vec; n++) { + to_alloc += vec[n].iov_len; + } + + evbuffer_expand(buf, to_alloc); - iov[2].iov_base = header->val; - iov[2].iov_len = header->vlen; + for (n = 0; n < n_vec; n++) { + evbuffer_add(buf, vec[n].iov_base, vec[n].iov_len); - iov[3].iov_base = "\r\n"; - iov[3].iov_len = 2; + res += vec[n].iov_len; + } - evbuffer_add_iovec(buf, iov, 4); + return res; +#else + return evbuffer_add_iovec(buf, vec, n_vec); +#endif +} + +static int +htp__create_headers_(evhtp_header_t * header, void * arg) +{ + struct evbuffer * buf = arg; + struct evbuffer_iovec iov[4] = { + { header->key, header->klen }, + { ": ", 2 }, + { header->val, header->vlen }, + { "\r\n", 2 } + }; + + htp__evbuffer_add_iovec_(buf, iov, 4); return 0; } @@ -2140,47 +2161,20 @@ htp__create_reply_(evhtp_request_t * request, evhtp_res code) * of the header. */ { - struct evbuffer_iovec iov[9]; const char * status_str = status_code_to_str(code); + struct evbuffer_iovec iov[9] = { + { "HTTP/1", 5 }, /* data == "HTTP/" */ + { (void *)&major, 1 }, /* data == "HTTP/X */ + { ".", 1 }, /* data == "HTTP/X." */ + { (void *)&minor, 1 }, /* data == "HTTP/X.X" */ + { " ", 1 }, /* data == "HTTP/X.X " */ + { out_buf, strlen(out_buf) }, /* data = "HTTP/X.X YYY" */ + { " ", 1 }, /* data = "HTTP/X.X YYY " */ + { (void *)status_str, strlen(status_str) }, /* data = "HTTP/X.X YYY ZZZ" */ + { "\r\n", 2 }, /* data = "HTTP/X.X YYY ZZZ\r\n" */ + }; - /* data == "HTTP/" */ - iov[0].iov_base = "HTTP/"; - iov[0].iov_len = 5; - - /* data == "HTTP/X" */ - iov[1].iov_base = (void *)&major; - iov[1].iov_len = 1; - - /* data == "HTTP/X." */ - iov[2].iov_base = "."; - iov[2].iov_len = 1; - - /* data == "HTTP/X.X" */ - iov[3].iov_base = (void *)&minor; - iov[3].iov_len = 1; - - - /* data == "HTTP/X.X " */ - iov[4].iov_base = " "; - iov[4].iov_len = 1; - - /* data == "HTTP/X.X YYY" */ - iov[5].iov_base = out_buf; - iov[5].iov_len = strlen(out_buf); - - /* data == "HTTP/X.X YYY " */ - iov[6].iov_base = " "; - iov[6].iov_len = 1; - - /* data == "HTTP/X.X YYY ZZZ" */ - iov[7].iov_base = (void *)status_str; - iov[7].iov_len = strlen(status_str); - - /* data == "HTTP/X.X YYY ZZZ\r\n" */ - iov[8].iov_base = "\r\n"; - iov[8].iov_len = 2; - - evbuffer_add_iovec(buf, iov, 9); + htp__evbuffer_add_iovec_(buf, iov, 9); } evhtp_headers_for_each(request->headers_out, htp__create_headers_, buf); @@ -2870,35 +2864,30 @@ htp__accept_cb_(struct evconnlistener * serv, int fd, struct sockaddr * s, int s #ifndef EVHTP_DISABLE_SSL #ifndef EVHTP_DISABLE_EVTHR -static -#if OPENSSL_VERSION_NUMBER >= 0x10000000L -void -#else -unsigned long -#endif -htp__ssl_get_thread_id_( -#if OPENSSL_VERSION_NUMBER >= 0x10000000L - CRYPTO_THREADID * id -#else - void -#endif - ) -{ - unsigned long tid; #ifndef WIN32 - tid = (unsigned long)pthread_self(); +#define _HTP_tid (unsigned long)pthread_self() #else - tid = pthread_self().p; +#define _HTP_tid pthread_self().p #endif -#if OPENSSL_VERSION_NUMBER >= 0x10000000L - CRYPTO_THREADID_set_numeric(id, tid); +#if OPENSSL_VERSION_NUMBER < 0x10000000L +static unsigned long +htp__ssl_get_thread_id_(void) +{ + return _HTP_tid; +} + #else - return tid; -#endif + +static void +htp__ssl_get_thread_id_(CRYPTO_THREADID * id) +{ + CRYPTO_THREADID_set_numeric(id, _HTP_tid); } +#endif + static void htp__ssl_thread_lock_(int mode, int type, const char * file, int line) { diff --git a/examples/test_client.c b/examples/test_client.c index 8a5983c..aa5ac4c 100644 --- a/examples/test_client.c +++ b/examples/test_client.c @@ -52,7 +52,7 @@ main(int argc, char ** argv) evhtp_request_t * request; evbase = event_base_new(); - conn = evhtp_connection_new(evbase, "75.126.169.52", 80); + conn = evhtp_connection_new(evbase, "104.27.150.225", 80); request = evhtp_request_new(request_cb, evbase); evhtp_request_set_hook(request, evhtp_hook_on_read, print_data, evbase); diff --git a/include/evhtp/evhtp.h b/include/evhtp/evhtp.h index 483c6cf..9bcee44 100644 --- a/include/evhtp/evhtp.h +++ b/include/evhtp/evhtp.h @@ -26,6 +26,7 @@ #ifndef EVHTP_DISABLE_SSL #include +#include #include #include #include @@ -188,10 +189,10 @@ typedef evhtp_ssl_sess_t * (* evhtp_ssl_scache_get)(evhtp_connection_t * connect typedef void * (* evhtp_ssl_scache_init)(evhtp_t *); #endif -#define EVHTP_VERSION "1.2.17" +#define EVHTP_VERSION "1.2.18" #define EVHTP_VERSION_MAJOR 1 #define EVHTP_VERSION_MINOR 2 -#define EVHTP_VERSION_PATCH 17 +#define EVHTP_VERSION_PATCH 18 #define evhtp_headers_iterator evhtp_kvs_iterator diff --git a/parser.c b/parser.c index a4e3d78..2bb84a1 100644 --- a/parser.c +++ b/parser.c @@ -3,6 +3,10 @@ #include #include +#ifdef EVHTP_HAS_SYS_TYPES +#include +#endif + #include "internal.h" #include "evhtp/parser.h" #include "evhtp/config.h" diff --git a/sslutils.c b/sslutils.c index 9c0e480..87568c6 100644 --- a/sslutils.c +++ b/sslutils.c @@ -10,6 +10,11 @@ #include "evhtp/sslutils.h" #include "internal.h" +#if OPENSSL_VERSION_NUMBER < 0x10100000L +#define X509_get0_notBefore(x) X509_get_notBefore(x) +#define X509_get0_notAfter(x) X509_get_notAfter(x) +#endif + unsigned char * htp_sslutil_subject_tostr(evhtp_ssl_t * ssl) { unsigned char * subj_str; @@ -78,11 +83,11 @@ htp_sslutil_issuer_tostr(evhtp_ssl_t * ssl) { unsigned char * htp_sslutil_notbefore_tostr(evhtp_ssl_t * ssl) { - BIO * bio; - X509 * cert; - ASN1_TIME * time; - size_t len; - unsigned char * time_str; + BIO * bio; + X509 * cert; + const ASN1_TIME * time; + size_t len; + unsigned char * time_str; if (!ssl) { return NULL; @@ -92,7 +97,7 @@ htp_sslutil_notbefore_tostr(evhtp_ssl_t * ssl) { return NULL; } - if (!(time = X509_get_notBefore(cert))) { + if (!(time = X509_get0_notBefore(cert))) { X509_free(cert); return NULL; } @@ -128,11 +133,11 @@ htp_sslutil_notbefore_tostr(evhtp_ssl_t * ssl) { unsigned char * htp_sslutil_notafter_tostr(evhtp_ssl_t * ssl) { - BIO * bio; - X509 * cert; - ASN1_TIME * time; - size_t len; - unsigned char * time_str; + BIO * bio; + X509 * cert; + const ASN1_TIME * time; + size_t len; + unsigned char * time_str; if (!ssl) { return NULL; @@ -142,7 +147,7 @@ htp_sslutil_notafter_tostr(evhtp_ssl_t * ssl) { return NULL; } - if (!(time = X509_get_notAfter(cert))) { + if (!(time = X509_get0_notAfter(cert))) { X509_free(cert); return NULL; }