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.18'
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFrench committed Feb 6, 2019
2 parents 0077e7a + 01ad044 commit e200bfa
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 90 deletions.
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
@@ -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 <sys/types.h> 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)
Expand Down
135 changes: 62 additions & 73 deletions evhtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion examples/test_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions include/evhtp/evhtp.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#ifndef EVHTP_DISABLE_SSL
#include <event2/bufferevent_ssl.h>
#include <openssl/dh.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#include <openssl/rand.h>
Expand Down Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
#include <ctype.h>
#include <string.h>

#ifdef EVHTP_HAS_SYS_TYPES
#include <sys/types.h>
#endif

#include "internal.h"
#include "evhtp/parser.h"
#include "evhtp/config.h"
Expand Down
29 changes: 17 additions & 12 deletions sslutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down

0 comments on commit e200bfa

Please sign in to comment.