Skip to content
This repository has been archived by the owner on Jun 30, 2021. It is now read-only.

Commit

Permalink
Merge branch 'release/1.2.16'
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFrench committed Jan 15, 2018
2 parents 0f246e3 + 109a927 commit 7fe78cd
Show file tree
Hide file tree
Showing 20 changed files with 1,457 additions and 327 deletions.
14 changes: 13 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ set (LIBEVHTP_SOURCE_FILES
numtoa.c
parser.c)

if (NOT EVHTP_DISABLE_SSL)
list (APPEND LIBEVHTP_SOURCE_FILES sslutils.c)
endif()

if (NOT EVHTP_DISABLE_EVTHR)
list (APPEND LIBEVHTP_SOURCE_FILES thread.c)
list (APPEND LIBEVHTP_EXTERNAL_LIBS pthread)
Expand All @@ -196,7 +200,7 @@ add_library (evhtp ${EVHTP_LIBTYPE} ${LIBEVHTP_SOURCE_FILES})
target_link_libraries (evhtp ${LIBEVHTP_EXTERNAL_LIBS})

if (EVHTP_BUILD_SHARED)
set_target_properties(evhtp PROPERTIES VERSION "${PROJECT_VERSION}" 0 OUTPUT_NAME "evhtp")
set_target_properties(evhtp PROPERTIES VERSION "${PROJECT_VERSION}" SOVERSION 0 OUTPUT_NAME "evhtp")
endif()

add_subdirectory(examples)
Expand Down Expand Up @@ -225,6 +229,14 @@ install (
DESTINATION
${INCLUDE_INSTALL_DIR})

if (NOT EVHTP_DISABLE_SSL)
install (
FILES
${PROJECT_SOURCE_DIR}/include/evhtp/sslutils.h
DESTINATION
${INCLUDE_INSTALL_DIR}/evhtp)
endif()

if (NOT EVHTP_DISABLE_EVTHR)
install (
FILES
Expand Down
16 changes: 16 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
v1.2.16
o Added various SSL utility functions (ab190e1 Nathan French)
o Fix compilation with shared libraries (6075565 Vincent Bernat)
o Extensive example of streaming data without hogging memory (8f50b83 Nathan French)
o Added EVHTP_FLAG_ENABLE_ALL to enable all socket flags (756a7e2 Nathan French)
o only warn if setsockopt fails on EOPNOTSUPP (e5a3bdf Nathan French)
o sslutil API updates [documentation / parsers / x-hdr helpers] (22207ad Nathan French)
o OpenSSL 1.1.0 updates (load_*/_init/_add*) (3819073 Nathan French)
o example_https_server now uses htp_sslutil_verify2opts (086afd1 Nathan French)
o added example_https_client.c (933febf Nathan French)
o [#69] Fix potential out of bound write to p->buf (8b68657 Nathan French)
o [#72] Fix for oob read from htparser_get_strerror (75574ba Nathan French)
o [#70] Do not disable EV_WRITE when pausing requests; The assumption
that libevent would automatically start transferring pending data was
wrong. (4cb782db77 Ultima1252)

v1.2.15
o deprecated unset_hook and set_hook / cleanup (f1d2bd1 Nathan French)
o updated travis configuration (45003e1 Nathan French)
Expand Down
3 changes: 3 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
This document describes details on using the evhtp API. This document is
probably not very awesome, it's best to look at test.c to see advanced usage.

# Prebuilt Packages
[![Package Versions](https://repology.org/badge/vertical-allrepos/libevhtp.svg)](https://repology.org/metapackage/libevhtp)

## Required Dependencies
* [gcc](http://gcc.gnu.org/)
* [Libevent2](http://libevent.org)
Expand Down
8 changes: 5 additions & 3 deletions cmake/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ option (EVHTP_DISABLE_REGEX "Disable regex support" OFF)
option (EVHTP_BUILD_SHARED "Build shared library too" OFF)

# -DEVHTP_DEBUG:STRING=ON
option (EVHTP_DEBUG "Enable verbose debug logging" OFF)
option (EVHTP_DEBUG "Enable verbose debug logging" OFF)

# can be overwritten by new set_alloc functions
option (EVHTP_USE_JEMALLOC "Enable jemalloc allocator" OFF)
option (EVHTP_USE_TCMALLOC "Enable tcmalloc allocator" OFF)
option (EVHTP_USE_JEMALLOC "Enable jemalloc allocator" OFF)
option (EVHTP_USE_TCMALLOC "Enable tcmalloc allocator" OFF)

# disable ability to wrap memory functions
option (EVHTP_DISABLE_MEMFUNCTIONS "Disable custom allocators" OFF)
2 changes: 1 addition & 1 deletion cmake/version.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
set (PROJECT_MAJOR_VERSION 1)
set (PROJECT_MINOR_VERSION 2)
set (PROJECT_PATCH_VERSION 15)
set (PROJECT_PATCH_VERSION 16)
set (PROJECT_VERSION
"${PROJECT_MAJOR_VERSION}.${PROJECT_MINOR_VERSION}.${PROJECT_PATCH_VERSION}")
65 changes: 49 additions & 16 deletions evhtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ htp__strndup_(const char * str, size_t len)
void
evhtp_set_mem_functions(void *(*mallocfn_)(size_t len),
void *(*reallocfn_)(void * p, size_t sz),
void (* freefn_)(void * p))
void (*freefn_)(void * p))
{
#ifndef EVHTP_DISABLE_MEMFUNCTIONS
malloc_ = mallocfn_;
Expand Down Expand Up @@ -2373,15 +2373,15 @@ htp__connection_writecb_(struct bufferevent * bev, void * arg)
return;
}

/* run user-hook for on_write callback before further analysis */
htp__hook_connection_write_(conn);

/* connection is in a paused state, no further processing yet */
if ((conn->flags & EVHTP_CONN_FLAG_PAUSED))
{
return;
}

/* run user-hook for on_write callback before further analysis */
htp__hook_connection_write_(conn);

if (conn->flags & EVHTP_CONN_FLAG_WAITING)
{
HTP_FLAG_OFF(conn, EVHTP_CONN_FLAG_WAITING);
Expand Down Expand Up @@ -2929,8 +2929,8 @@ htp__ssl_add_scache_ent_(evhtp_ssl_t * ssl, evhtp_ssl_sess_t * sess)
return 0; /* We cannot get the ssl_cfg */
}

cfg = connection->htp->ssl_cfg;
sid = (evhtp_ssl_data_t *)SSL_SESSION_get_id(sess, &slen);
cfg = connection->htp->ssl_cfg;
sid = (evhtp_ssl_data_t *)SSL_SESSION_get_id(sess, &slen);

SSL_set_timeout(sess, cfg->scache_timeout);

Expand All @@ -2955,8 +2955,8 @@ htp__ssl_get_scache_ent_(evhtp_ssl_t * ssl, evhtp_ssl_data_t * sid, int sid_len,
{
return NULL; /* We have no way of getting ssl_cfg */
}
cfg = connection->htp->ssl_cfg;
sess = NULL;
cfg = connection->htp->ssl_cfg;
sess = NULL;

if (cfg->scache_get)
{
Expand Down Expand Up @@ -3043,7 +3043,7 @@ evhtp_connection_pause(evhtp_connection_t * c)

HTP_FLAG_ON(c, EVHTP_CONN_FLAG_PAUSED);

bufferevent_disable(c->bev, EV_READ | EV_WRITE);
bufferevent_disable(c->bev, EV_READ);

return;
}
Expand Down Expand Up @@ -3964,7 +3964,11 @@ evhtp_accept_socket(evhtp_t * htp, evutil_socket_t sock, int backlog)
{
if (setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, (void *)&on, sizeof(on)) == -1)
{
break;
if (errno != EOPNOTSUPP) {
break;
}

log_warn("SO_REUSEPORT not supported for this socket.. Skipping");
}
}
#endif
Expand All @@ -3974,7 +3978,11 @@ evhtp_accept_socket(evhtp_t * htp, evutil_socket_t sock, int backlog)
{
if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (void *)&on, sizeof(on)) == -1)
{
break;
if (errno != EOPNOTSUPP) {
break;
}

log_warn("TCP_NODELAY not supported for this socket.. Skipping");
}
}
#endif
Expand All @@ -3984,7 +3992,11 @@ evhtp_accept_socket(evhtp_t * htp, evutil_socket_t sock, int backlog)
{
if (setsockopt(sock, IPPROTO_TCP, TCP_DEFER_ACCEPT, (void *)&on, sizeof(on)) == -1)
{
break;
if (errno != EOPNOTSUPP) {
break;
}

log_warn("TCP_DEFER_ACCEPT not supported for this socket.. Skipping");
}
}
#endif
Expand Down Expand Up @@ -4767,11 +4779,28 @@ evhtp_ssl_init(evhtp_t * htp, evhtp_ssl_cfg_t * cfg)
return -1;
}

#if OPENSSL_VERSION_NUMBER < 0x10100000L
SSL_library_init();
ERR_load_crypto_strings();
SSL_load_error_strings();
OpenSSL_add_all_algorithms();

#else
/* unnecessary in OpenSSL 1.1.0 */
/*
* if (OPENSSL_init_ssl(OPENSSL_INIT_SSL_DEFAULT, NULL) == 0) {
* log_error("OPENSSL_init_ssl");
* return -1;
* }
*
* if (OPENSSL_init_crypto(
* OPENSSL_INIT_ADD_ALL_CIPHERS |
* OPENSSL_INIT_ADD_ALL_DIGESTS |
* OPENSSL_INIT_LOAD_CONFIG, NULL) == 0) {
* log_error("OPENSSL_init_crypto");
* return -1;
* }
*/
#endif
if (RAND_poll() != 1) {
log_error("RAND_poll");
return -1;
Expand All @@ -4788,7 +4817,11 @@ evhtp_ssl_init(evhtp_t * htp, evhtp_ssl_cfg_t * cfg)
#endif

htp->ssl_cfg = cfg;
#if OPENSSL_VERSION_NUMBER < 0x10100000L
htp->ssl_ctx = SSL_CTX_new(SSLv23_server_method());
#else
htp->ssl_ctx = SSL_CTX_new(TLS_server_method());
#endif

evhtp_alloc_assert(htp->ssl_ctx);

Expand All @@ -4804,7 +4837,7 @@ evhtp_ssl_init(evhtp_t * htp, evhtp_ssl_cfg_t * cfg)
EC_KEY * ecdh = NULL;
int nid = 0;

nid = OBJ_sn2nid(cfg->named_curve);
nid = OBJ_sn2nid(cfg->named_curve);

if (nid == 0) {
log_error("ECDH initialization failed: unknown curve %s", cfg->named_curve);
Expand Down Expand Up @@ -5176,8 +5209,8 @@ evhtp_add_alias(evhtp_t * evhtp, const char * name)

int
evhtp_add_aliases(evhtp_t * htp, const char * name, ...) {
va_list argp;
size_t len;
va_list argp;
size_t len;

if (evhtp_add_alias(htp, name) == -1) {
return -1;
Expand Down
33 changes: 22 additions & 11 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ add_executable(test_query EXCLUDE_FROM_ALL test_query.c)
add_executable(test_perf EXCLUDE_FROM_ALL test_perf.c)
add_executable(example_vhost EXCLUDE_FROM_ALL example_vhost.c)
add_executable(example_pause EXCLUDE_FROM_ALL example_pause.c)
add_executable(example_https EXCLUDE_FROM_ALL https/example_https.c)
add_executable(example_chunked EXCLUDE_FROM_ALL example_chunked.c)


if (NOT EVHTP_DISABLE_EVTHR)
add_executable(test_proxy EXCLUDE_FROM_ALL test_proxy.c)
Expand All @@ -24,16 +25,26 @@ target_link_libraries(test_query evhtp ${LIBEVHTP_EXTERNAL_LIBS} ${SYS_LIBS})
target_link_libraries(test_perf evhtp ${LIBEVHTP_EXTERNAL_LIBS} ${SYS_LIBS})
target_link_libraries(example_vhost evhtp ${LIBEVHTP_EXTERNAL_LIBS} ${SYS_LIBS})
target_link_libraries(example_pause evhtp ${LIBEVHTP_EXTERNAL_LIBS} ${SYS_LIBS})
target_link_libraries(example_https evhtp ${LIBEVHTP_EXTERNAL_LIBS} ${SYS_LIBS})
target_link_libraries(example_chunked evhtp ${LIBEVHTP_EXTERNAL_LIBS} ${SYS_LIBS})


if (NOT EVHTP_DISABLE_SSL)
file (COPY
https/etc/ca.cnf
https/etc/client1.cnf
https/etc/client2.cnf
https/etc/server.cnf
DESTINATION https/etc/)

add_dependencies(examples example_https example_pause example_vhost test_extensive test_basic test_vhost test_client test_query test_perf)
configure_file(https/bin/generate.sh.in https/bin/generate.sh @ONLY)

file (COPY
https/etc/ca.cnf
https/etc/client1.cnf
https/etc/client2.cnf
https/etc/server.cnf
DESTINATION
https/etc/)
add_executable(example_https_server EXCLUDE_FROM_ALL https/example_https_server.c)
target_link_libraries(example_https_server evhtp ${LIBEVHTP_EXTERNAL_LIBS} ${SYS_LIBS})

add_executable(example_https_client EXCLUDE_FROM_ALL https/example_https_client.c)
target_link_libraries(example_https_client evhtp ${LIBEVHTP_EXTERNAL_LIBS} ${SYS_LIBS})

add_dependencies(examples example_https_server example_https_client)
endif()

configure_file(https/bin/generate.sh.in https/bin/generate.sh @ONLY)
add_dependencies(examples example_chunked example_pause example_vhost test_extensive test_basic test_vhost test_client test_query test_perf)
25 changes: 25 additions & 0 deletions examples/eutils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once

static void * mm__dup_(const void * src, size_t size) {
void * mem = malloc(size);

return mem ? memcpy(mem, src, size) : NULL;
}

#define mm__alloc_(type, ...) \
(type *)mm__dup_((type[]) {__VA_ARGS__ }, sizeof(type))

#define bind__sock_port0_(HTP) ({ \
struct sockaddr_in sin; \
socklen_t len = len = sizeof(struct sockaddr); \
uint16_t port; \
\
evhtp_bind_socket(HTP, "127.0.0.1", 0, 128); \
\
getsockname( \
evconnlistener_get_fd(HTP->server), \
(struct sockaddr *)&sin, &len); \
\
port = ntohs(sin.sin_port); \
port; \
})
Loading

0 comments on commit 7fe78cd

Please sign in to comment.