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

Commit

Permalink
replace cruft in evhtp_unset_all_hooks with for loop
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFrench committed Nov 13, 2017
1 parent 2307737 commit 4e62d69
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 104 deletions.
117 changes: 34 additions & 83 deletions evhtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1911,8 +1911,7 @@ htp__create_headers_(evhtp_header_t * header, void * arg)
}

static struct evbuffer *
htp__create_reply_(evhtp_request_t * request, evhtp_res code)
{
htp__create_reply_(evhtp_request_t * request, evhtp_res code) {
struct evbuffer * buf;
const char * content_type;
char res_buf[2048];
Expand Down Expand Up @@ -4220,85 +4219,41 @@ evhtp_unset_hook(evhtp_hooks_t ** hooks, evhtp_hook_type type)
int
evhtp_unset_all_hooks(evhtp_hooks_t ** hooks)
{
int res = 0;

if (evhtp_unset_hook(hooks, evhtp_hook_on_headers_start))
{
res -= 1;
}

if (evhtp_unset_hook(hooks, evhtp_hook_on_header))
{
res -= 1;
}

if (evhtp_unset_hook(hooks, evhtp_hook_on_headers))
{
res -= 1;
}

if (evhtp_unset_hook(hooks, evhtp_hook_on_path))
{
res -= 1;
}

if (evhtp_unset_hook(hooks, evhtp_hook_on_read))
{
res -= 1;
}

if (evhtp_unset_hook(hooks, evhtp_hook_on_request_fini))
{
res -= 1;
}

if (evhtp_unset_hook(hooks, evhtp_hook_on_connection_fini))
{
res -= 1;
}

if (evhtp_unset_hook(hooks, evhtp_hook_on_conn_error))
{
res -= 1;
}

if (evhtp_unset_hook(hooks, evhtp_hook_on_error))
{
res -= 1;
}

if (evhtp_unset_hook(hooks, evhtp_hook_on_new_chunk))
{
res -= 1;
}

if (evhtp_unset_hook(hooks, evhtp_hook_on_chunk_complete))
{
res -= 1;
}

if (evhtp_unset_hook(hooks, evhtp_hook_on_chunks_complete))
{
res -= 1;
}

if (evhtp_unset_hook(hooks, evhtp_hook_on_hostname))
{
res -= 1;
}
int i;

if (evhtp_unset_hook(hooks, evhtp_hook_on_write))
{
struct {
enum evhtp_hook_type type;
} hooklist_[] = {
{ evhtp_hook_on_header },
{ evhtp_hook_on_headers },
{ evhtp_hook_on_path },
{ evhtp_hook_on_read },
{ evhtp_hook_on_request_fini },
{ evhtp_hook_on_connection_fini },
{ evhtp_hook_on_new_chunk },
{ evhtp_hook_on_chunk_complete },
{ evhtp_hook_on_chunks_complete },
{ evhtp_hook_on_headers_start },
{ evhtp_hook_on_error },
{ evhtp_hook_on_hostname },
{ evhtp_hook_on_write },
{ evhtp_hook_on_event },
{ evhtp_hook_on_conn_error },
{ -1 }
};

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

if (evhtp_unset_hook(hooks, evhtp_hook_on_event))
{
return -1;
for (i = 0; hooklist_[i].type != -1; i++) {
if (evhtp_unset_hook(hooks, hooklist_[i].type) == -1) {
return -1;
}
}

return res;
} /* evhtp_unset_all_hooks */
return 0;
}

evhtp_hooks_t *
evhtp_connection_get_hooks(evhtp_connection_t * c)
Expand Down Expand Up @@ -4801,14 +4756,12 @@ evhtp_ssl_init(evhtp_t * htp, evhtp_ssl_cfg_t * cfg)
#endif

struct bufferevent *
evhtp_connection_get_bev(evhtp_connection_t * connection)
{
evhtp_connection_get_bev(evhtp_connection_t * connection) {
return connection->bev;
}

struct bufferevent *
evhtp_connection_take_ownership(evhtp_connection_t * connection)
{
evhtp_connection_take_ownership(evhtp_connection_t * connection) {
struct bufferevent * bev = evhtp_connection_get_bev(connection);

if (connection->hooks)
Expand All @@ -4835,14 +4788,12 @@ evhtp_connection_take_ownership(evhtp_connection_t * connection)
}

struct bufferevent *
evhtp_request_get_bev(evhtp_request_t * request)
{
evhtp_request_get_bev(evhtp_request_t * request) {
return evhtp_connection_get_bev(request->conn);
}

struct bufferevent *
evhtp_request_take_ownership(evhtp_request_t * request)
{
evhtp_request_take_ownership(evhtp_request_t * request) {
return evhtp_connection_take_ownership(request->conn);
}

Expand Down
45 changes: 24 additions & 21 deletions include/evhtp/evhtp.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,14 +278,14 @@ struct evhtp_alias_s {
* @brief main structure containing all configuration information
*/
struct evhtp_s {
evhtp_t * parent; /**< only when this is a vhost */
evbase_t * evbase; /**< the initialized event_base */
evserv_t * server; /**< the libevent listener struct */
char * server_name; /**< the name included in Host: responses */
void * arg; /**< user-defined evhtp_t specific arguments */
int bev_flags; /**< bufferevent flags to use on bufferevent_*_socket_new() */
uint64_t max_body_size;
uint64_t max_keepalive_requests;
evhtp_t * parent; /**< only when this is a vhost */
struct event_base * evbase; /**< the initialized event_base */
struct evconnlistener * server; /**< the libevent listener struct */
char * server_name; /**< the name included in Host: responses */
void * arg; /**< user-defined evhtp_t specific arguments */
int bev_flags; /**< bufferevent flags to use on bufferevent_*_socket_new() */
uint64_t max_body_size;
uint64_t max_keepalive_requests;

#define EVHTP_FLAG_ENABLE_100_CONT (1 << 1)
#define EVHTP_FLAG_ENABLE_REUSEPORT (1 << 2)
Expand Down Expand Up @@ -417,9 +417,9 @@ struct evhtp_request_s {
#define evhtp_request_content_len(r) htparser_get_content_length(r->conn->parser)

struct evhtp_connection_s {
evhtp_t * htp;
evbase_t * evbase;
evbev_t * bev;
evhtp_t * htp;
struct event_base * evbase;
struct bufferevent * bev;
#ifndef EVHTP_DISABLE_EVTHR
evthr_t * thread;
#endif
Expand All @@ -428,7 +428,7 @@ struct evhtp_connection_s {
#endif
evhtp_hooks_t * hooks;
htparser * parser;
event_t * resume_ev;
struct event * resume_ev;
struct sockaddr * saddr;
struct timeval recv_timeo; /**< conn read timeouts (overrides global) */
struct timeval send_timeo; /**< conn write timeouts (overrides global) */
Expand Down Expand Up @@ -535,7 +535,7 @@ EVHTP_EXPORT void evhtp_set_mem_functions(void *(*malloc_)(size_t),
*
* @return a new evhtp_t structure or NULL on error
*/
EVHTP_EXPORT evhtp_t * evhtp_new(evbase_t * evbase, void * arg);
EVHTP_EXPORT evhtp_t * evhtp_new(struct event_base * evbase, void * arg);

EVHTP_EXPORT void evhtp_enable_flag(evhtp_t *, int);
EVHTP_EXPORT void evhtp_connection_enable_flag(evhtp_connection_t *, int);
Expand Down Expand Up @@ -1241,15 +1241,15 @@ EVHTP_EXPORT evhtp_connection_t * evhtp_request_get_connection(evhtp_request_t *
* @param conn
* @param bev
*/
EVHTP_EXPORT void evhtp_connection_set_bev(evhtp_connection_t * conn, evbev_t * bev);
EVHTP_EXPORT void evhtp_connection_set_bev(evhtp_connection_t * conn, struct bufferevent * bev);

/**
* @brief sets the underlying bufferevent for a evhtp_request
*
* @param request
* @param bev
*/
EVHTP_EXPORT void evhtp_request_set_bev(evhtp_request_t * request, evbev_t * bev);
EVHTP_EXPORT void evhtp_request_set_bev(evhtp_request_t * request, struct bufferevent * bev);


/**
Expand All @@ -1259,7 +1259,7 @@ EVHTP_EXPORT void evhtp_request_set_bev(evhtp_request_t * request, evbev_t * bev
*
* @return bufferevent on success, otherwise NULL
*/
EVHTP_EXPORT evbev_t * evhtp_connection_get_bev(evhtp_connection_t * conn);
EVHTP_EXPORT struct bufferevent * evhtp_connection_get_bev(evhtp_connection_t * conn);

/**
* @brief sets a connection-specific read/write timeout which overrides the
Expand All @@ -1281,7 +1281,7 @@ evhtp_connection_set_timeouts(evhtp_connection_t * conn,
*
* @return bufferevent on success, otherwise NULL
*/
EVHTP_EXPORT evbev_t * evhtp_request_get_bev(evhtp_request_t * request);
EVHTP_EXPORT struct bufferevent * evhtp_request_get_bev(evhtp_request_t * request);


/**
Expand All @@ -1296,7 +1296,7 @@ EVHTP_EXPORT evbev_t * evhtp_request_get_bev(evhtp_request_t * request);
*
* @return underlying connections bufferevent.
*/
EVHTP_EXPORT evbev_t * evhtp_connection_take_ownership(evhtp_connection_t * connection);
EVHTP_EXPORT struct bufferevent * evhtp_connection_take_ownership(evhtp_connection_t * connection);


/**
Expand Down Expand Up @@ -1351,18 +1351,21 @@ EVHTP_EXPORT void evhtp_set_max_keepalive_requests(evhtp_t * htp, uint64_t num);
/**
* @brief allocate a new connection
*/
EVHTP_EXPORT evhtp_connection_t * evhtp_connection_new_dns(evbase_t * evbase,
EVHTP_EXPORT evhtp_connection_t * evhtp_connection_new_dns(
struct event_base * evbase,
struct evdns_base * dns_base,
const char * addr, uint16_t port);

/**
* @brief allocate a new connection
*/
EVHTP_EXPORT evhtp_connection_t *
evhtp_connection_new(evbase_t * evbase, const char * addr, uint16_t port);
evhtp_connection_new(struct event_base * evbase, const char * addr, uint16_t port);

#ifndef EVHTP_DISABLE_SSL
EVHTP_EXPORT evhtp_connection_t * evhtp_connection_ssl_new(evbase_t * evbase, const char * addr, uint16_t port, evhtp_ssl_ctx_t * ctx);
EVHTP_EXPORT evhtp_connection_t * evhtp_connection_ssl_new(
struct event_base * evbase,
const char * addr, uint16_t port, evhtp_ssl_ctx_t * ctx);
#endif


Expand Down

0 comments on commit 4e62d69

Please sign in to comment.