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.12-pre2'
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFrench committed Jul 8, 2017
2 parents 084fa14 + b6b96ce commit 4c9b3dd
Show file tree
Hide file tree
Showing 8 changed files with 185 additions and 792 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ endif()
if (NOT HAVE_SYS_TREE)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/compat/sys/tree.h.in
${CMAKE_CURRENT_BINARY_DIR}/compat/sys/tree.h)

include_directories(${PROJECT_BINARY_DIR}/compat)

endif(NOT HAVE_SYS_TREE)

if (NOT HAVE_SYS_QUEUE)
Expand Down Expand Up @@ -303,7 +306,6 @@ if (EVHTP_BUILD_SHARED)
set_target_properties(evhtp PROPERTIES SOVERSION "${PROJECT_VERSION}")
endif()

add_subdirectory(tools)
add_subdirectory(examples)

if (NOT LIB_INSTALL_DIR)
Expand Down
45 changes: 45 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,48 @@
v1.2.12-pre2
o Internalize some structs / deprecate evhtp_set_hook() (50ab327 Nathan French)
o remove cruft (1b1a037 Nathan French)
o add include directory for compat/sys headers (948c547 Nathan French)
o export flag functions (3467cbb Nathan French)
o formatting (4ec8dd3 Nathan French)

v1.2.12-pre1
o (evhtp_send_reply): Grab reference to bufferevent during write. (a976a2f Marcus Sundberg)
o add thread exit callback for cleaning (0c7d9c4 jgli)
o fix memory leak (a6b00cc jgli)
o fix thread exit callback type (c8978b6 jgli)
o Updates for threading functionality. (b634002 Mark Ellzey)
o Added evhtp_accept_socket (a497a14 Mark Ellzey)
o Forgot to export evhtp_accept_socke. (c94cb5b Mark Ellzey)
o Formatting. (4a78297 Mark Ellzey)
o Maybe I should spell rite. (2114210 Mark Ellzey)
o Fix cmake compilation issue in centos7 (dfc8c2b kaustubh-d)
o Remove double-free when SSL is used. (ee32b2a Jacob Marble)
o Add CPack commands to build a debian package. (0c4a8ec Tom Pusateri)
o [docs] added some doxygen groups (8a247f1 Mark Ellzey)
o check res for bufferevent_socket_connect (#136) (70b68d4 mthomas)
o Regression from commit 67ed0bc (c96c51e Ultima1252)
o Added build/* to gitignore (c64f1dc Mark Ellzey)
o Updating license to include Marcus Sundberg (801c52f Mark Ellzey)
o [htparse] fix up some stuff to make coverity happy (abc7eb4 Mark Ellzey)
o More coverity fixes (7d3cc52 Mark Ellzey)
o check for sockopt returns (534bb48 Mark Ellzey)
o master travis updates (2c6bb88 Mark Ellzey)
o added testbigendian module for old cmake (fb6a866 Mark Ellzey)
o Added initial evhtp_json API (6e48770 Mark Ellzey)
o LICENSE update for ripping liblz json api (fb473ef Mark Ellzey)
o Removing the SIGNED.md file (outdated anyway) (d4bcfa8 Mark Ellzey)
o Update README (6ef073e Mark Ellzey)
o updates / formatting / renames (926e355 Nathan French)
o static funcs from now on will just return int (5112b6d Nathan French)
o fix htp__use_threads_ call error (2ed2f7f weijiazhen)
o FIX : Socket leakage on error #6 (d13b72b Nathan French)
o Issue#6: make evhtp_accept_socket conform to api (d0347dc Nathan French)
o Establish conformity through flags. (58da6dd Nathan French)
o request flags (71341d9 Nathan French)
o EVHTP_CONN flags (087e9a7 Nathan French)
o Flag ops (and related functions) / cleanup (0abc96f Nathan French)
o Add flags accessor (e0f04aa Nathan French)

v1.2.11
o Grab reference to bufferevent during write. (a976a2f Marcus Sundberg)
o add thread exit callback for cleaning (0c7d9c4 jgli)
Expand Down
152 changes: 101 additions & 51 deletions evhtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,40 @@
#include "evhtp_numtoa.h"
#include "evhtp.h"

/**
* @brief structure containing a single callback and configuration
*
* The definition structure which is used within the evhtp_callbacks_t
* structure. This holds information about what should execute for either
* a single or regex path.
*
* For example, if you registered a callback to be executed on a request
* for "/herp/derp", your defined callback will be executed.
*
* Optionally you can set callback-specific hooks just like per-connection
* hooks using the same rules.
*
*/
struct evhtp_callback_s {
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 */
evhtp_hooks_t * hooks; /**< per-callback hooks */
size_t len;

union {
char * path;
char * glob;
#ifndef EVHTP_DISABLE_REGEX
regex_t * regex;
#endif
} val;

TAILQ_ENTRY(evhtp_callback_s) next;
};

TAILQ_HEAD(evhtp_callbacks_s, evhtp_callback_s);


#ifdef EVHTP_DEBUG
static void
Expand Down Expand Up @@ -262,26 +296,6 @@ strndup(const char * s, size_t n)
* PRIVATE FUNCTIONS
*/

/**
* @brief a weak hash function
*
* @param str a null terminated string
*
* @return an unsigned integer hash of str
*/
static inline unsigned int
htp__quick_hash_(const char * str)
{
unsigned int h = 0;

for (; *str; str++)
{
h = 31 * h + *str;
}

return h;
}

/**
*
* @brief helper macro to determine if http version is HTTP/1.0
Expand Down Expand Up @@ -554,8 +568,8 @@ htp__hook_connection_write_(evhtp_connection_t * connection)
* @return
*/
static int
htp__glob_match2_(const char * pattern, size_t plen,
const char * string, size_t str_len)
htp__glob_match_(const char * pattern, size_t plen,
const char * string, size_t str_len)
{
while (plen)
{
Expand All @@ -574,8 +588,8 @@ htp__glob_match2_(const char * pattern, size_t plen,

while (str_len)
{
if (htp__glob_match2_(pattern + 1, plen - 1,
string, str_len))
if (htp__glob_match_(pattern + 1, plen - 1,
string, str_len))
{
return 1; /* match */
}
Expand Down Expand Up @@ -617,27 +631,6 @@ htp__glob_match2_(const char * pattern, size_t plen,
}

return 0;
} /* htp__glob_match2_ */

static inline int
htp__glob_match_(const char * pattern, size_t pat_len, const char * string, size_t str_len)
{
if (evhtp_unlikely(!pattern || !string))
{
return 0;
}

if (pat_len == 0)
{
pat_len = strlen(pattern);
}

if (str_len == 0)
{
str_len = strlen(string);
}

return htp__glob_match2_(pattern, pat_len, string, str_len);
} /* htp__glob_match_ */

static evhtp_callback_t *
Expand All @@ -660,6 +653,11 @@ htp__callback_find_(evhtp_callbacks_t * cbs,
{
switch (callback->type) {
case evhtp_callback_type_hash:
if (callback->val.path[1] != path[1])
{
continue;
}

if (strcmp(callback->val.path, path) == 0)
{
*start_offset = 0;
Expand Down Expand Up @@ -1224,7 +1222,7 @@ htp__request_find_vhost_(evhtp_t * evhtp, const char * name)
continue;
}

if (htp__glob_match_(evhtp_vhost->server_name, 0, name, 0) == 1)
if (htp__glob_match_(evhtp_vhost->server_name, strlen(evhtp_vhost->server_name), name, strlen(name)) == 1)
{
return evhtp_vhost;
}
Expand All @@ -1236,7 +1234,7 @@ htp__request_find_vhost_(evhtp_t * evhtp, const char * name)
continue;
}

if (htp__glob_match_(evhtp_alias->alias, 0, name, 0) == 1)
if (htp__glob_match_(evhtp_alias->alias, strlen(evhtp_alias->alias), name, strlen(name)) == 1)
{
return evhtp_vhost;
}
Expand Down Expand Up @@ -3779,7 +3777,6 @@ evhtp_callback_new(const char * path, evhtp_callback_type type, evhtp_callback_c

switch (type) {
case evhtp_callback_type_hash:
hcb->hash = htp__quick_hash_(path);
hcb->val.path = strdup(path);
break;
#ifndef EVHTP_DISABLE_REGEX
Expand Down Expand Up @@ -3848,8 +3845,8 @@ evhtp_callbacks_add_callback(evhtp_callbacks_t * cbs, evhtp_callback_t * cb)
return 0;
}

int
evhtp_set_hook(evhtp_hooks_t ** hooks, evhtp_hook_type type, evhtp_hook cb, void * arg)
static int
htp__set_hook_(evhtp_hooks_t ** hooks, evhtp_hook_type type, evhtp_hook cb, void * arg)
{
if (*hooks == NULL)
{
Expand Down Expand Up @@ -3925,7 +3922,31 @@ evhtp_set_hook(evhtp_hooks_t ** hooks, evhtp_hook_type type, evhtp_hook cb, void
} /* switch */

return 0;
} /* evhtp_set_hook */
} /* htp__set_hook_ */

int
evhtp_set_hook(evhtp_hooks_t ** hooks, evhtp_hook_type type, evhtp_hook cb, void * arg)
{
return htp__set_hook_(hooks, type, cb, arg);
}

int
evhtp_callback_set_hook(evhtp_callback_t * callback, evhtp_hook_type type, evhtp_hook cb, void * arg)
{
return htp__set_hook_(&callback->hooks, type, cb, arg);
}

int
evhtp_request_set_hook(evhtp_request_t * req, evhtp_hook_type type, evhtp_hook cb, void * arg)
{
return htp__set_hook_(&req->hooks, type, cb, arg);
}

int
evhtp_connection_set_hook(evhtp_connection_t * conn, evhtp_hook_type type, evhtp_hook cb, void * arg)
{
return htp__set_hook_(&conn->hooks, type, cb, arg);
}

int
evhtp_unset_hook(evhtp_hooks_t ** hooks, evhtp_hook_type type)
Expand Down Expand Up @@ -4016,6 +4037,34 @@ evhtp_unset_all_hooks(evhtp_hooks_t ** hooks)
return res;
} /* evhtp_unset_all_hooks */

evhtp_hooks_t *
evhtp_connection_get_hooks(evhtp_connection_t * c)
{
if (evhtp_unlikely(c == NULL))
{
return NULL;
}

return c->hooks;
}

evhtp_hooks_t *
evhtp_request_get_hooks(evhtp_request_t * r)
{
if (evhtp_unlikely(r == NULL))
{
return NULL;
}

return r->hooks;
}

evhtp_hooks_t *
evhtp_callback_get_hooks(evhtp_callback_t * cb)
{
return cb->hooks;
}

evhtp_callback_t *
evhtp_set_cb(evhtp_t * htp, const char * path, evhtp_callback_cb cb, void * arg)
{
Expand Down Expand Up @@ -4690,6 +4739,7 @@ evhtp_set_parser_flags(evhtp_t * htp, int flags)
{ \
return v->flags; \
} \
return -1; \
}

HTP_FLAG_FNGEN(, evhtp_t *);
Expand Down
51 changes: 16 additions & 35 deletions evhtp.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ extern "C" {
} while (0)
#endif

struct evhtp_callback_s;
struct evhtp_callbacks_s;

#ifndef EVHTP_DISABLE_SSL
typedef SSL_SESSION evhtp_ssl_sess_t;
Expand Down Expand Up @@ -337,39 +339,6 @@ struct evhtp_s {
TAILQ_ENTRY(evhtp_s) next_vhost;
};

/**
* @brief structure containing a single callback and configuration
*
* The definition structure which is used within the evhtp_callbacks_t
* structure. This holds information about what should execute for either
* a single or regex path.
*
* For example, if you registered a callback to be executed on a request
* for "/herp/derp", your defined callback will be executed.
*
* Optionally you can set callback-specific hooks just like per-connection
* hooks using the same rules.
*
*/
struct evhtp_callback_s {
evhtp_callback_type type; /**< the type of callback (regex|path) */
evhtp_callback_cb cb; /**< the actual callback function */
unsigned int hash; /**< the full hash generated integer */
void * cbarg; /**< user-defind arguments passed to the cb */
evhtp_hooks_t * hooks; /**< per-callback hooks */

union {
char * path;
char * glob;
#ifndef EVHTP_DISABLE_REGEX
regex_t * regex;
#endif
} val;

TAILQ_ENTRY(evhtp_callback_s) next;
};

TAILQ_HEAD(evhtp_callbacks_s, evhtp_callback_s);

/**
* @brief a generic key/value structure
Expand Down Expand Up @@ -577,6 +546,15 @@ struct evhtp_ssl_cfg_s {
*/
EVHTP_EXPORT evhtp_t * evhtp_new(evbase_t * evbase, void * arg);

EVHTP_EXPORT void evhtp_enable_flag(evhtp_t *, int);
EVHTP_EXPORT void evhtp_connection_enable_flag(evhtp_connection_t *, int);
EVHTP_EXPORT void evhtp_request_enable_flag(evhtp_request_t *, int);
EVHTP_EXPORT int evhtp_get_flags(evhtp_t *);
EVHTP_EXPORT int evhtp_connection_get_flags(evhtp_connection_t *);
EVHTP_EXPORT int evhtp_request_get_flags(evhtp_request_t *);
EVHTP_EXPORT void evhtp_disable_flag(evhtp_t *, int);
EVHTP_EXPORT void evhtp_connection_disable_flag(evhtp_connection_t *, int);
EVHTP_EXPORT void evhtp_request_disable_flag(evhtp_request_t *, int);

/**
* @brief free a evhtp_t context
Expand Down Expand Up @@ -796,9 +774,12 @@ EVHTP_EXPORT evhtp_callback_t * evhtp_get_cb(evhtp_t * htp, const char * needle)
*
* @return 0 on success, -1 on error (if hooks is NULL, it is allocated)
*/
EVHTP_EXPORT int evhtp_set_hook(evhtp_hooks_t ** hooks, evhtp_hook_type type,
evhtp_hook cb, void * arg);
EVHTP_EXPORT int evhtp_set_hook(evhtp_hooks_t ** hooks, evhtp_hook_type type, evhtp_hook cb, void * arg);
DEPRECATED("use evhtp_[connection|request|callback]_set_hook() instead of set_hook directly");

EVHTP_EXPORT int evhtp_connection_set_hook(evhtp_connection_t * c, evhtp_hook_type type, evhtp_hook cb, void * arg);
EVHTP_EXPORT int evhtp_request_set_hook(evhtp_request_t * r, evhtp_hook_type type, evhtp_hook cb, void * arg);
EVHTP_EXPORT int evhtp_callback_set_hook(evhtp_callback_t * cb, evhtp_hook_type type, evhtp_hook hookcb, void * arg);

/**
* @brief remove a specific hook from being called.
Expand Down
1 change: 0 additions & 1 deletion evhtp_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <ctype.h>
#include <unistd.h>

#include "internal.h"

#include "evhtp_heap.h"
#include "evhtp_json.h"
Expand Down
Loading

0 comments on commit 4c9b3dd

Please sign in to comment.