Skip to content

Commit

Permalink
General housecleaning and small bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFrench committed Mar 23, 2018
1 parent 9cbd30d commit 8439850
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 93 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ include (TestBigEndian)

add_definitions ("-DPROJECT_VERSION=${PROJECT_VERSION} -Wall")

set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -ggdb3")
SET(CMAKE_BUILD_TYPE Release CACHE STRING "default to Release")

Expand Down
24 changes: 12 additions & 12 deletions evhtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <signal.h>
#include <strings.h>
#include <inttypes.h>
#include <stdbool.h>
#ifndef WIN32
#include <sys/socket.h>
#include <netinet/in.h>
Expand Down Expand Up @@ -48,7 +49,7 @@
* hooks using the same rules.
*
*/
struct evhtp_callback_s {
struct evhtp_callback {
evhtp_callback_type type; /**< the type of callback (regex|path) */
evhtp_callback_cb cb; /**< the actual callback function */
void * cbarg; /**< user-defind arguments passed to the cb */
Expand All @@ -63,10 +64,10 @@ struct evhtp_callback_s {
#endif
} val;

TAILQ_ENTRY(evhtp_callback_s) next;
TAILQ_ENTRY(evhtp_callback) next;
};

TAILQ_HEAD(evhtp_callbacks_s, evhtp_callback_s);
TAILQ_HEAD(evhtp_callbacks, evhtp_callback);

#define SET_BIT(VAR, FLAG) VAR |= FLAG
#define UNSET_BIT(VAR, FLAG) VAR &= ~FLAG
Expand Down Expand Up @@ -2738,7 +2739,7 @@ htp__connection_new_(evhtp_t * htp, evutil_socket_t sock, evhtp_type type)
return NULL;
}

connection = htp__calloc_(sizeof(evhtp_connection_t), 1);
connection = htp__calloc_(sizeof(*connection), 1);
evhtp_alloc_assert(connection);

connection->scratch_buf = evbuffer_new();
Expand Down Expand Up @@ -2918,7 +2919,7 @@ htp__ssl_add_scache_ent_(evhtp_ssl_t * ssl, evhtp_ssl_sess_t * sess)
evhtp_connection_t * connection;
evhtp_ssl_cfg_t * cfg;
evhtp_ssl_data_t * sid;
int slen;
unsigned int slen;

connection = (evhtp_connection_t *)SSL_get_app_data(ssl);
if (connection->htp == NULL)
Expand Down Expand Up @@ -3099,7 +3100,7 @@ evhtp_header_val_add(evhtp_headers_t * headers, const char * val, char val_alloc
return NULL;
}

if (!(header = TAILQ_LAST(headers, evhtp_headers_s)))
if (!(header = TAILQ_LAST(headers, evhtp_kvs)))
{
return NULL;
}
Expand Down Expand Up @@ -3132,7 +3133,7 @@ evhtp_kvs_new(void)
{
evhtp_kvs_t * kvs;

kvs = htp__malloc_(sizeof(evhtp_kvs_t));
kvs = htp__malloc_(sizeof(*kvs));
evhtp_alloc_assert(kvs);

TAILQ_INIT(kvs);
Expand All @@ -3146,7 +3147,7 @@ evhtp_kv_new(const char * key, const char * val,
{
evhtp_kv_t * kv;

kv = htp__malloc_(sizeof(evhtp_kv_t));
kv = htp__malloc_(sizeof(*kv));
evhtp_alloc_assert(kv);

kv->k_heaped = key_alloc;
Expand Down Expand Up @@ -4195,7 +4196,7 @@ evhtp_callback_new(const char * path, evhtp_callback_type type, evhtp_callback_c
{
evhtp_callback_t * hcb;

hcb = htp__calloc_(sizeof(evhtp_callback_t), 1);
hcb = htp__calloc_(sizeof(*hcb), 1);
evhtp_alloc_assert(hcb);

hcb->type = type;
Expand Down Expand Up @@ -4418,14 +4419,14 @@ evhtp_unset_all_hooks(evhtp_hooks_t ** hooks)
{ evhtp_hook_on_write },
{ evhtp_hook_on_event },
{ evhtp_hook_on_conn_error },
{ -1 }
{ evhtp_hook__max }
};

if (hooks == NULL) {
return -1;
}

for (i = 0; hooklist_[i].type != -1; i++) {
for (i = 0; hooklist_[i].type != evhtp_hook__max; i++) {
if (htp__unset_hook_(hooks, hooklist_[i].type) == -1) {
return -1;
}
Expand Down Expand Up @@ -5212,7 +5213,6 @@ 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;

if (evhtp_add_alias(htp, name) == -1) {
return -1;
Expand Down
139 changes: 64 additions & 75 deletions include/evhtp/evhtp.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,68 +35,63 @@
extern "C" {
#endif

struct evhtp_callback_s;
struct evhtp_callbacks_s;
struct evhtp_callback;
struct evhtp_callbacks;
struct evhtp_kvs;

#ifndef EVHTP_DISABLE_SSL
typedef SSL_SESSION evhtp_ssl_sess_t;
typedef SSL evhtp_ssl_t;
typedef SSL_CTX evhtp_ssl_ctx_t;
typedef X509 evhtp_x509_t;
typedef X509_STORE_CTX evhtp_x509_store_ctx_t;
typedef SSL_SESSION evhtp_ssl_sess_t;
typedef SSL evhtp_ssl_t;
typedef SSL_CTX evhtp_ssl_ctx_t;
typedef X509 evhtp_x509_t;
typedef X509_STORE_CTX evhtp_x509_store_ctx_t;
#if OPENSSL_VERSION_NUMBER < 0x10100000L
typedef unsigned char evhtp_ssl_data_t;
typedef unsigned char evhtp_ssl_data_t;
#else
typedef const unsigned char evhtp_ssl_data_t;
typedef const unsigned char evhtp_ssl_data_t;
#endif
#else
typedef void evhtp_ssl_sess_t;
typedef void evhtp_ssl_t;
typedef void evhtp_ssl_ctx_t;
typedef void evhtp_x509_t;
typedef void evhtp_x509_store_ctx_t;
typedef void evhtp_ssl_sess_t;
typedef void evhtp_ssl_t;
typedef void evhtp_ssl_ctx_t;
typedef void evhtp_x509_t;
typedef void evhtp_x509_store_ctx_t;
#endif

typedef struct evbuffer evbuf_t;
typedef struct event event_t;
typedef struct evconnlistener evserv_t;
typedef struct bufferevent evbev_t;
typedef struct evbuffer evbuf_t;
typedef struct event event_t;
typedef struct evconnlistener evserv_t;
typedef struct bufferevent evbev_t;

#ifdef EVHTP_DISABLE_EVTHR
typedef struct event_base evbase_t;
typedef void evthr_t;
typedef void evthr_pool_t;
typedef void evhtp_mutex_t;
typedef struct event_base evbase_t;
typedef void evthr_t;
typedef void evthr_pool_t;
typedef void evhtp_mutex_t;
#else
typedef pthread_mutex_t evhtp_mutex_t;
typedef pthread_mutex_t evhtp_mutex_t;
#endif

typedef struct evhtp_s evhtp_t;
typedef struct evhtp_defaults_s evhtp_defaults_t;
typedef struct evhtp_callbacks_s evhtp_callbacks_t;
typedef struct evhtp_callback_s evhtp_callback_t;
typedef struct evhtp_defaults_s evhtp_defaults_5;
typedef struct evhtp_kv_s evhtp_kv_t;
typedef struct evhtp_kvs_s evhtp_kvs_t;
typedef struct evhtp_uri_s evhtp_uri_t;
typedef struct evhtp_path_s evhtp_path_t;
typedef struct evhtp_authority_s evhtp_authority_t;
typedef struct evhtp_request_s evhtp_request_t;
typedef struct evhtp_hooks_s evhtp_hooks_t;
typedef struct evhtp_connection_s evhtp_connection_t;
typedef struct evhtp_ssl_cfg_s evhtp_ssl_cfg_t;
typedef struct evhtp_alias_s evhtp_alias_t;
typedef uint16_t evhtp_res;
typedef uint8_t evhtp_error_flags;


#define evhtp_header_s evhtp_kv_s
#define evhtp_headers_s evhtp_kvs_s
#define evhtp_query_s evhtp_kvs_s

#define evhtp_header_t evhtp_kv_t
#define evhtp_headers_t evhtp_kvs_t
#define evhtp_query_t evhtp_kvs_t
typedef struct evhtp evhtp_t;
typedef struct evhtp_defaults evhtp_defaults_t;
typedef struct evhtp_callbacks evhtp_callbacks_t;
typedef struct evhtp_callback evhtp_callback_t;
typedef struct evhtp_kv evhtp_kv_t;
typedef struct evhtp_kvs evhtp_kvs_t;
typedef struct evhtp_uri evhtp_uri_t;
typedef struct evhtp_path evhtp_path_t;
typedef struct evhtp_authority evhtp_authority_t;
typedef struct evhtp_request evhtp_request_t;
typedef struct evhtp_hooks evhtp_hooks_t;
typedef struct evhtp_connection evhtp_connection_t;
typedef struct evhtp_ssl_cfg evhtp_ssl_cfg_t;
typedef struct evhtp_alias evhtp_alias_t;
typedef uint16_t evhtp_res;
typedef uint8_t evhtp_error_flags;

typedef struct evhtp_kv evhtp_header_t;
typedef struct evhtp_kvs evhtp_headers_t;
typedef struct evhtp_kvs evhtp_query_t;

enum evhtp_ssl_scache_type {
evhtp_ssl_scache_type_disabled = 0,
Expand Down Expand Up @@ -125,6 +120,7 @@ enum evhtp_hook_type {
evhtp_hook_on_write,
evhtp_hook_on_event,
evhtp_hook_on_conn_error, /**< type which defines to hook whenever a connection error occurs */
evhtp_hook__max
};

enum evhtp_callback_type {
Expand Down Expand Up @@ -264,7 +260,7 @@ typedef void * (* evhtp_ssl_scache_init)(evhtp_t *);
#define EVHTP_RES_BWEXEED 509
#endif

struct evhtp_defaults_s {
struct evhtp_defaults {
evhtp_callback_cb cb;
evhtp_pre_accept_cb pre_accept;
evhtp_post_accept_cb post_accept;
Expand All @@ -273,17 +269,17 @@ struct evhtp_defaults_s {
void * post_accept_cbarg;
};

struct evhtp_alias_s {
struct evhtp_alias {
char * alias;

TAILQ_ENTRY(evhtp_alias_s) next;
TAILQ_ENTRY(evhtp_alias) next;
};

/**
* @ingroup evhtp_core
* @brief main structure containing all configuration information
*/
struct evhtp_s {
struct evhtp {
evhtp_t * parent; /**< only when this is a vhost */
struct event_base * evbase; /**< the initialized event_base */
struct evconnlistener * server; /**< the libevent listener struct */
Expand Down Expand Up @@ -330,16 +326,16 @@ struct evhtp_s {
struct timeval recv_timeo;
struct timeval send_timeo;

TAILQ_HEAD(, evhtp_alias_s) aliases;
TAILQ_HEAD(, evhtp_s) vhosts;
TAILQ_ENTRY(evhtp_s) next_vhost;
TAILQ_HEAD(, evhtp_alias) aliases;
TAILQ_HEAD(, evhtp) vhosts;
TAILQ_ENTRY(evhtp) next_vhost;
};


/**
* @brief a generic key/value structure
*/
struct evhtp_kv_s {
struct evhtp_kv {
char * key;
char * val;

Expand All @@ -349,17 +345,17 @@ struct evhtp_kv_s {
char k_heaped; /**< set to 1 if the key can be free()'d */
char v_heaped; /**< set to 1 if the val can be free()'d */

TAILQ_ENTRY(evhtp_kv_s) next;
TAILQ_ENTRY(evhtp_kv) next;
};

TAILQ_HEAD(evhtp_kvs_s, evhtp_kv_s);
TAILQ_HEAD(evhtp_kvs, evhtp_kv);



/**
* @brief a generic container representing an entire URI strucutre
*/
struct evhtp_uri_s {
struct evhtp_uri {
evhtp_authority_t * authority;
evhtp_path_t * path;
unsigned char * fragment; /**< data after '#' in uri */
Expand All @@ -372,7 +368,7 @@ struct evhtp_uri_s {
/**
* @brief structure which represents authority information in a URI
*/
struct evhtp_authority_s {
struct evhtp_authority {
char * username; /**< the username in URI (scheme://USER:.. */
char * password; /**< the password in URI (scheme://...:PASS.. */
char * hostname; /**< hostname if present in URI */
Expand All @@ -383,7 +379,7 @@ struct evhtp_authority_s {
/**
* @brief structure which represents a URI path and or file
*/
struct evhtp_path_s {
struct evhtp_path {
char * full; /**< the full path+file (/a/b/c.html) */
char * path; /**< the path (/a/b/) */
char * file; /**< the filename if present (c.html) */
Expand All @@ -401,7 +397,7 @@ struct evhtp_path_s {
/**
* @brief a structure containing all information for a http request.
*/
struct evhtp_request_s {
struct evhtp_request {
evhtp_t * htp; /**< the parent evhtp_t structure */
evhtp_connection_t * conn; /**< the associated connection */
evhtp_hooks_t * hooks; /**< request specific hooks */
Expand All @@ -422,12 +418,12 @@ struct evhtp_request_s {
evhtp_callback_cb cb; /**< the function to call when fully processed */
void * cbarg; /**< argument which is passed to the cb function */

TAILQ_ENTRY(evhtp_request_s) next;
TAILQ_ENTRY(evhtp_request) next;
};

#define evhtp_request_content_len(r) htparser_get_content_length(r->conn->parser)

struct evhtp_connection_s {
struct evhtp_connection {
evhtp_t * htp;
struct event_base * evbase;
struct bufferevent * bev;
Expand Down Expand Up @@ -462,11 +458,11 @@ struct evhtp_connection_s {
struct evbuffer * scratch_buf; /**< always zero'd out after used */

#ifdef EVHTP_FUTURE_USE
TAILQ_HEAD(, evhtp_request_s) pending; /**< client pending data */
TAILQ_HEAD(, evhtp_request) pending; /**< client pending data */
#endif
};

struct evhtp_hooks_s {
struct evhtp_hooks {
evhtp_hook_headers_start_cb on_headers_start;
evhtp_hook_header_cb on_header;
evhtp_hook_headers_cb on_headers;
Expand Down Expand Up @@ -501,7 +497,7 @@ struct evhtp_hooks_s {
};

#ifndef EVHTP_DISABLE_SSL
struct evhtp_ssl_cfg_s {
struct evhtp_ssl_cfg {
char * pemfile;
char * privfile;
char * cafile;
Expand Down Expand Up @@ -533,11 +529,6 @@ EVHTP_EXPORT void evhtp_set_mem_functions(void *(*malloc_)(size_t),
void *(*realloc_)(void *, size_t),
void (* free_)(void *));

/**
* @defgroup evhtp_core Core evhtp functions
* @{
*/

/**
* @brief creates a new evhtp_t instance
*
Expand Down Expand Up @@ -567,8 +558,6 @@ EVHTP_EXPORT void evhtp_request_disable_flag(evhtp_request_t *, int);
*/
EVHTP_EXPORT void evhtp_free(evhtp_t * evhtp);

/** @} */

/**
* @brief set a read/write timeout on all things evhtp_t. When the timeout
* expires your error hook will be called with the libevent supplied event
Expand Down
Loading

0 comments on commit 8439850

Please sign in to comment.