Skip to content

Commit

Permalink
Merge branch 'release/1.1.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Ellzey committed Oct 24, 2012
2 parents 921248d + 0019735 commit 91071e2
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 59 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Expand Up @@ -3,7 +3,7 @@ project(reason)


set(PROJECT_MAJOR_VERSION 1) set(PROJECT_MAJOR_VERSION 1)
set(PROJECT_MINOR_VERSION 1) set(PROJECT_MINOR_VERSION 1)
set(PROJECT_PATCH_VERSION 5) set(PROJECT_PATCH_VERSION 6)


set (PROJECT_VERSION ${PROJECT_MAJOR_VERSION}.${PROJECT_MINOR_VERSION}.${PROJECT_PATCH_VERSION}) set (PROJECT_VERSION ${PROJECT_MAJOR_VERSION}.${PROJECT_MINOR_VERSION}.${PROJECT_PATCH_VERSION})
set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeModules) set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeModules)
Expand Down
8 changes: 8 additions & 0 deletions ChangeLog
@@ -1,3 +1,11 @@
v1.1.6
o Added __cplusplus into evthr (31e3973 Mark Ellzey)
o Use evhtp_hook_generic_cb function pointer prototype when setting a hook (59f01f3 Gian-Paolo Musumeci)
o ISO C fixes. (d1627f7 Mark Ellzey)
o ISO C fixes. (5be2662 Mark Ellzey)
o Renaming evhtp_hook_generic_cb to evhtp_hook, more ISO compliance. (60b3502 Mark Ellzey)
o Removing strict flags from BaseConfig. (bdc6265 Mark Ellzey)

v1.1.5 v1.1.5
o Don't treat non hex chars as errors. (d8c584d Mark Ellzey) o Don't treat non hex chars as errors. (d8c584d Mark Ellzey)
o If non hex, replace idx-1 with % (2783983 Mark Ellzey) o If non hex, replace idx-1 with % (2783983 Mark Ellzey)
Expand Down
80 changes: 47 additions & 33 deletions evhtp.c
Expand Up @@ -87,9 +87,9 @@ static void _evhtp_path_free(evhtp_path_t * path);
#endif #endif


#ifndef TAILQ_FOREACH_SAFE #ifndef TAILQ_FOREACH_SAFE
#define TAILQ_FOREACH_SAFE(var, head, field, tvar) \ #define TAILQ_FOREACH_SAFE(var, head, field, tvar) \
for ((var) = TAILQ_FIRST((head)); \ for ((var) = TAILQ_FIRST((head)); \
(var) && ((tvar) = TAILQ_NEXT((var), field), 1); \ (var) && ((tvar) = TAILQ_NEXT((var), field), 1); \
(var) = (tvar)) (var) = (tvar))
#endif #endif


Expand All @@ -115,7 +115,7 @@ status_code_cmp(void * _a, void * _b) {
} }


RB_HEAD(status_code_tree, status_code) status_code_head = RB_INITIALIZER(&status_code_head); RB_HEAD(status_code_tree, status_code) status_code_head = RB_INITIALIZER(&status_code_head);
RB_GENERATE(status_code_tree, status_code, entry, status_code_cmp); RB_GENERATE(status_code_tree, status_code, entry, status_code_cmp)


#define scode_add(scode, cstr) do { \ #define scode_add(scode, cstr) do { \
struct status_code * c = malloc(sizeof(struct status_code)); \ struct status_code * c = malloc(sizeof(struct status_code)); \
Expand Down Expand Up @@ -1329,7 +1329,7 @@ _evhtp_connection_resumecb(int fd, short events, void * arg) {
c->request->status = EVHTP_RES_OK; c->request->status = EVHTP_RES_OK;
} }


return _evhtp_connection_readcb(c->bev, c); _evhtp_connection_readcb(c->bev, c);
} }


static void static void
Expand Down Expand Up @@ -1360,7 +1360,8 @@ _evhtp_connection_readcb(evbev_t * bev, void * arg) {
* drain the input buffer that had been read up to this point. * drain the input buffer that had been read up to this point.
*/ */
evbuffer_drain(bufferevent_get_input(bev), nread); evbuffer_drain(bufferevent_get_input(bev), nread);
return evhtp_connection_free(c); evhtp_connection_free(c);
return;
} }


if (c->request) { if (c->request) {
Expand All @@ -1369,7 +1370,8 @@ _evhtp_connection_readcb(evbev_t * bev, void * arg) {
if (c->request->hooks && c->request->hooks->on_error) { if (c->request->hooks && c->request->hooks->on_error) {
(*c->request->hooks->on_error)(c->request, -1, c->request->hooks->on_error_arg); (*c->request->hooks->on_error)(c->request, -1, c->request->hooks->on_error_arg);
} }
return evhtp_connection_free(c); evhtp_connection_free(c);
return;
default: default:
break; break;
} }
Expand All @@ -1379,7 +1381,8 @@ _evhtp_connection_readcb(evbev_t * bev, void * arg) {
if (c->request && c->request->status == EVHTP_RES_PAUSE) { if (c->request && c->request->status == EVHTP_RES_PAUSE) {
evhtp_request_pause(c->request); evhtp_request_pause(c->request);
} else { } else {
return evhtp_connection_free(c); evhtp_connection_free(c);
return;
} }
} }


Expand Down Expand Up @@ -1429,9 +1432,11 @@ _evhtp_connection_writecb(evbev_t * bev, void * arg) {
htparser_init(c->parser, htp_type_request); htparser_init(c->parser, htp_type_request);




return htparser_set_userdata(c->parser, c); htparser_set_userdata(c->parser, c);
return;
} else { } else {
return evhtp_connection_free(c); evhtp_connection_free(c);
return;
} }


return; return;
Expand Down Expand Up @@ -1463,7 +1468,7 @@ _evhtp_connection_eventcb(evbev_t * bev, short events, void * arg) {
c->request->hooks->on_error_arg); c->request->hooks->on_error_arg);
} }


return evhtp_connection_free((evhtp_connection_t *)arg); evhtp_connection_free((evhtp_connection_t *)arg);
} }


static int static int
Expand Down Expand Up @@ -1550,7 +1555,7 @@ _evhtp_connection_accept(evbase_t * evbase, evhtp_connection_t * connection) {


static void static void
_evhtp_default_request_cb(evhtp_request_t * request, void * arg) { _evhtp_default_request_cb(evhtp_request_t * request, void * arg) {
return evhtp_send_reply(request, EVHTP_RES_NOTFOUND); evhtp_send_reply(request, EVHTP_RES_NOTFOUND);
} }


static evhtp_connection_t * static evhtp_connection_t *
Expand Down Expand Up @@ -1613,11 +1618,13 @@ _evhtp_run_in_thread(evthr_t * thr, void * arg, void * shared) {
evthr_inc_backlog(connection->thread); evthr_inc_backlog(connection->thread);


if (_evhtp_connection_accept(connection->evbase, connection) < 0) { if (_evhtp_connection_accept(connection->evbase, connection) < 0) {
return evhtp_connection_free(connection); evhtp_connection_free(connection);
return;
} }


if (_evhtp_run_post_accept(htp, connection) < 0) { if (_evhtp_run_post_accept(htp, connection) < 0) {
return evhtp_connection_free(connection); evhtp_connection_free(connection);
return;
} }
} }


Expand All @@ -1639,19 +1646,22 @@ _evhtp_accept_cb(evserv_t * serv, int fd, struct sockaddr * s, int sl, void * ar
if (htp->thr_pool != NULL) { if (htp->thr_pool != NULL) {
if (evthr_pool_defer(htp->thr_pool, _evhtp_run_in_thread, connection) != EVTHR_RES_OK) { if (evthr_pool_defer(htp->thr_pool, _evhtp_run_in_thread, connection) != EVTHR_RES_OK) {
evutil_closesocket(connection->sock); evutil_closesocket(connection->sock);
return evhtp_connection_free(connection); evhtp_connection_free(connection);
return;
} }
return; return;
} }
#endif #endif
connection->evbase = htp->evbase; connection->evbase = htp->evbase;


if (_evhtp_connection_accept(htp->evbase, connection) < 0) { if (_evhtp_connection_accept(htp->evbase, connection) < 0) {
return evhtp_connection_free(connection); evhtp_connection_free(connection);
return;
} }


if (_evhtp_run_post_accept(htp, connection) < 0) { if (_evhtp_run_post_accept(htp, connection) < 0) {
return evhtp_connection_free(connection); evhtp_connection_free(connection);
return;
} }
} }


Expand Down Expand Up @@ -1817,7 +1827,7 @@ evhtp_connection_resume(evhtp_connection_t * c) {
void void
evhtp_request_pause(evhtp_request_t * request) { evhtp_request_pause(evhtp_request_t * request) {
request->status = EVHTP_RES_PAUSE; request->status = EVHTP_RES_PAUSE;
return evhtp_connection_pause(request->conn); evhtp_connection_pause(request->conn);
} }


/** /**
Expand All @@ -1829,7 +1839,7 @@ evhtp_request_pause(evhtp_request_t * request) {
*/ */
void void
evhtp_request_resume(evhtp_request_t * request) { evhtp_request_resume(evhtp_request_t * request) {
return evhtp_connection_resume(request->conn); evhtp_connection_resume(request->conn);
} }


evhtp_header_t * evhtp_header_t *
Expand Down Expand Up @@ -2159,11 +2169,11 @@ evhtp_parse_query(const char * query, size_t len) {


query_args = evhtp_query_new(); query_args = evhtp_query_new();


if (!(key_buf = malloc(len+1))) { if (!(key_buf = malloc(len + 1))) {
return NULL; return NULL;
} }


if (!(val_buf = malloc(len+1))) { if (!(val_buf = malloc(len + 1))) {
free(key_buf); free(key_buf);
return NULL; return NULL;
} }
Expand Down Expand Up @@ -2355,7 +2365,8 @@ evhtp_send_reply_start(evhtp_request_t * request, evhtp_res code) {
c = evhtp_request_get_connection(request); c = evhtp_request_get_connection(request);


if (!(reply_buf = _evhtp_create_reply(request, code))) { if (!(reply_buf = _evhtp_create_reply(request, code))) {
return evhtp_connection_free(c); evhtp_connection_free(c);
return;
} }


bufferevent_write_buffer(c->bev, reply_buf); bufferevent_write_buffer(c->bev, reply_buf);
Expand All @@ -2375,8 +2386,8 @@ void
evhtp_send_reply_end(evhtp_request_t * request) { evhtp_send_reply_end(evhtp_request_t * request) {
request->finished = 1; request->finished = 1;


return _evhtp_connection_writecb(evhtp_request_get_bev(request), _evhtp_connection_writecb(evhtp_request_get_bev(request),
evhtp_request_get_connection(request)); evhtp_request_get_connection(request));
} }


void void
Expand All @@ -2388,7 +2399,8 @@ evhtp_send_reply(evhtp_request_t * request, evhtp_res code) {
request->finished = 1; request->finished = 1;


if (!(reply_buf = _evhtp_create_reply(request, code))) { if (!(reply_buf = _evhtp_create_reply(request, code))) {
return evhtp_connection_free(request->conn); evhtp_connection_free(request->conn);
return;
} }


bufferevent_write_buffer(evhtp_connection_get_bev(c), reply_buf); bufferevent_write_buffer(evhtp_connection_get_bev(c), reply_buf);
Expand Down Expand Up @@ -2687,7 +2699,7 @@ evhtp_callbacks_add_callback(evhtp_callbacks_t * cbs, evhtp_callback_t * cb) {
} }


int int
evhtp_set_hook(evhtp_hooks_t ** hooks, evhtp_hook_type type, void * cb, void * arg) { evhtp_set_hook(evhtp_hooks_t ** hooks, evhtp_hook_type type, evhtp_hook cb, void * arg) {
if (*hooks == NULL) { if (*hooks == NULL) {
if (!(*hooks = calloc(sizeof(evhtp_hooks_t), 1))) { if (!(*hooks = calloc(sizeof(evhtp_hooks_t), 1))) {
return -1; return -1;
Expand Down Expand Up @@ -3090,7 +3102,8 @@ evhtp_ssl_init(evhtp_t * htp, evhtp_ssl_cfg_t * cfg) {
} /* switch */ } /* switch */


SSL_CTX_use_certificate_file(htp->ssl_ctx, cfg->pemfile, SSL_FILETYPE_PEM); SSL_CTX_use_certificate_file(htp->ssl_ctx, cfg->pemfile, SSL_FILETYPE_PEM);
SSL_CTX_use_PrivateKey_file(htp->ssl_ctx, cfg->privfile ? : cfg->pemfile, SSL_FILETYPE_PEM); SSL_CTX_use_PrivateKey_file(htp->ssl_ctx,
cfg->privfile ? cfg->privfile : cfg->pemfile, SSL_FILETYPE_PEM);


SSL_CTX_set_session_id_context(htp->ssl_ctx, SSL_CTX_set_session_id_context(htp->ssl_ctx,
(void *)&session_id_context, (void *)&session_id_context,
Expand Down Expand Up @@ -3164,7 +3177,7 @@ evhtp_connection_set_bev(evhtp_connection_t * conn, evbev_t * bev) {


void void
evhtp_request_set_bev(evhtp_request_t * request, evbev_t * bev) { evhtp_request_set_bev(evhtp_request_t * request, evbev_t * bev) {
return evhtp_connection_set_bev(request->conn, bev); evhtp_connection_set_bev(request->conn, bev);
} }


evhtp_connection_t * evhtp_connection_t *
Expand All @@ -3173,9 +3186,9 @@ evhtp_request_get_connection(evhtp_request_t * request) {
} }


void void
evhtp_connection_set_timeouts(evhtp_connection_t * c, evhtp_connection_set_timeouts(evhtp_connection_t * c,
const struct timeval * rtimeo, const struct timeval * rtimeo,
const struct timeval * wtimeo) { const struct timeval * wtimeo) {
if (!c) { if (!c) {
return; return;
} }
Expand All @@ -3194,7 +3207,7 @@ evhtp_connection_set_max_body_size(evhtp_connection_t * c, uint64_t len) {


void void
evhtp_request_set_max_body_size(evhtp_request_t * req, uint64_t len) { evhtp_request_set_max_body_size(evhtp_request_t * req, uint64_t len) {
return evhtp_connection_set_max_body_size(req->conn, len); evhtp_connection_set_max_body_size(req->conn, len);
} }


void void
Expand Down Expand Up @@ -3239,7 +3252,7 @@ evhtp_connection_free(evhtp_connection_t * connection) {


void void
evhtp_request_free(evhtp_request_t * request) { evhtp_request_free(evhtp_request_t * request) {
return _evhtp_request_free(request); _evhtp_request_free(request);
} }


void void
Expand Down Expand Up @@ -3401,3 +3414,4 @@ evhtp_free(evhtp_t * evhtp) {


free(evhtp); free(evhtp);
} }

8 changes: 6 additions & 2 deletions evhtp.h
Expand Up @@ -130,6 +130,10 @@ typedef enum evhtp_ssl_scache_type evhtp_ssl_scache_type;
typedef void (*evhtp_thread_init_cb)(evhtp_t * htp, evthr_t * thr, void * arg); typedef void (*evhtp_thread_init_cb)(evhtp_t * htp, evthr_t * thr, void * arg);
typedef void (*evhtp_callback_cb)(evhtp_request_t * req, void * arg); typedef void (*evhtp_callback_cb)(evhtp_request_t * req, void * arg);
typedef void (*evhtp_hook_err_cb)(evhtp_request_t * req, evhtp_error_flags errtype, void * arg); typedef void (*evhtp_hook_err_cb)(evhtp_request_t * req, evhtp_error_flags errtype, void * arg);

/* Generic hook for passing ISO tests */
typedef evhtp_res (*evhtp_hook)();

typedef evhtp_res (*evhtp_pre_accept_cb)(evhtp_connection_t * conn, void * arg); typedef evhtp_res (*evhtp_pre_accept_cb)(evhtp_connection_t * conn, void * arg);
typedef evhtp_res (*evhtp_post_accept_cb)(evhtp_connection_t * conn, void * arg); typedef evhtp_res (*evhtp_post_accept_cb)(evhtp_connection_t * conn, void * arg);
typedef evhtp_res (*evhtp_hook_header_cb)(evhtp_request_t * req, evhtp_header_t * hdr, void * arg); typedef evhtp_res (*evhtp_hook_header_cb)(evhtp_request_t * req, evhtp_header_t * hdr, void * arg);
Expand All @@ -155,7 +159,7 @@ typedef void (*evhtp_ssl_scache_del)(evhtp_t * htp, unsigned char * sid, int sid
typedef evhtp_ssl_sess_t * (*evhtp_ssl_scache_get)(evhtp_connection_t * connection, unsigned char * sid, int sid_len); typedef evhtp_ssl_sess_t * (*evhtp_ssl_scache_get)(evhtp_connection_t * connection, unsigned char * sid, int sid_len);
typedef void * (*evhtp_ssl_scache_init)(evhtp_t *); typedef void * (*evhtp_ssl_scache_init)(evhtp_t *);


#define EVHTP_VERSION "1.1.5" #define EVHTP_VERSION "1.1.6"
#define EVHTP_VERSION_MAJOR 1 #define EVHTP_VERSION_MAJOR 1
#define EVHTP_VERSION_MINOR 1 #define EVHTP_VERSION_MINOR 1
#define EVHTP_VERSION_PATCH 5 #define EVHTP_VERSION_PATCH 5
Expand Down Expand Up @@ -605,7 +609,7 @@ evhtp_callback_t * evhtp_set_glob_cb(evhtp_t * htp, const char * pattern, evhtp_
* *
* @return 0 on success, -1 on error (if hooks is NULL, it is allocated) * @return 0 on success, -1 on error (if hooks is NULL, it is allocated)
*/ */
int evhtp_set_hook(evhtp_hooks_t ** hooks, evhtp_hook_type type, void * cb, void * arg); int evhtp_set_hook(evhtp_hooks_t ** hooks, evhtp_hook_type type, evhtp_hook cb, void * arg);




/** /**
Expand Down
8 changes: 8 additions & 0 deletions evthr/evthr.h
Expand Up @@ -10,6 +10,10 @@
#include <event2/event.h> #include <event2/event.h>
#include <event2/thread.h> #include <event2/thread.h>


#ifdef __cplusplus
extern "C" {
#endif

enum evthr_res { enum evthr_res {
EVTHR_RES_OK = 0, EVTHR_RES_OK = 0,
EVTHR_RES_BACKLOG, EVTHR_RES_BACKLOG,
Expand Down Expand Up @@ -51,5 +55,9 @@ evthr_res evthr_pool_defer(evthr_pool_t * pool, evthr_cb cb, void * arg);
void evthr_pool_free(evthr_pool_t * pool); void evthr_pool_free(evthr_pool_t * pool);
void evthr_pool_set_max_backlog(evthr_pool_t * evthr, int max); void evthr_pool_set_max_backlog(evthr_pool_t * evthr, int max);


#ifdef __cplusplus
}
#endif

#endif /* __EVTHR_H__ */ #endif /* __EVTHR_H__ */


0 comments on commit 91071e2

Please sign in to comment.