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

Commit

Permalink
deprecated unset_hook and set_hook / cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFrench committed Nov 21, 2017
1 parent a595c23 commit f1d2bd1
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 59 deletions.
36 changes: 17 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,19 @@ if (EVHTP_THR_SHARED_PIPE)
add_definitions(-DEVTHR_SHARED_PIPE)
endif()

CHECK_include_FILES(strings.h HAVE_STRINGS_H)
CHECK_include_FILES(string.h HAVE_STRING_H)
CHECK_include_FILES(stdlib.h HAVE_STDLIB_H)
CHECK_include_FILES(sys/time.h HAVE_SYS_TIME_H)
CHECK_include_FILES(sys/times.h HAVE_SYS_TIMES_H)
CHECK_include_FILES(unistd.h HAVE_UNISTD_H)
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 (stdlib.h HAVE_STDLIB_H)
check_include_files (string.h HAVE_STRING_H)
check_include_files (stdint.h HAVE_STDINT_H)
check_include_files (errno.h HAVE_ERRNO_H)
check_include_files (strings.h HAVE_STRINGS_H)
check_include_files (inttypes.h HAVE_INTTYPES_H)
check_include_files (limits.h HAVE_LIMITS_H)

check_include_files (unistd.h HAVE_UNISTD_H)
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_TYPE_SIZE("int" SIZEOF_INT)
CHECK_TYPE_SIZE("long" SIZEOF_LONG)
Expand Down Expand Up @@ -189,11 +192,11 @@ if (NOT EVHTP_DISABLE_EVTHR)
list (APPEND LIBEVHTP_EXTERNAL_LIBS pthread)
endif()

add_library(evhtp ${EVHTP_LIBTYPE} ${LIBEVHTP_SOURCE_FILES})
target_link_libraries(evhtp ${LIBEVHTP_EXTERNAL_LIBS})
add_library (evhtp ${EVHTP_LIBTYPE} ${LIBEVHTP_SOURCE_FILES})
target_link_libraries (evhtp ${LIBEVHTP_EXTERNAL_LIBS})

if (EVHTP_BUILD_SHARED)
set_target_properties(evhtp PROPERTIES SOVERSION "${PROJECT_VERSION}")
set_target_properties(evhtp PROPERTIES VERSION "${PROJECT_VERSION}" 0 OUTPUT_NAME "evhtp")
endif()

add_subdirectory(examples)
Expand All @@ -212,6 +215,7 @@ install (
FILES
${PROJECT_SOURCE_DIR}/include/evhtp/evhtp.h
${PROJECT_SOURCE_DIR}/include/evhtp/parser.h
${PROJECT_BINARY_DIR}/include/evhtp/config.h
DESTINATION
${INCLUDE_INSTALL_DIR}/evhtp)

Expand All @@ -221,12 +225,6 @@ install (
DESTINATION
${INCLUDE_INSTALL_DIR})

install (
FILES
${CMAKE_CURRENT_BINARY_DIR}/include/evhtp/config.h
DESTINATION
${INCLUDE_INSTALL_DIR}/evhtp)

if (NOT EVHTP_DISABLE_EVTHR)
install (
FILES
Expand Down
29 changes: 20 additions & 9 deletions evhtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -4352,10 +4352,27 @@ htp__set_hook_(evhtp_hooks_t ** hooks, evhtp_hook_type type, evhtp_hook cb, void
return 0;
} /* htp__set_hook_ */

static int
htp__unset_hook_(evhtp_hooks_t ** hooks, evhtp_hook_type type) {
return htp__set_hook_(hooks, type, NULL, NULL);
}

int
evhtp_callback_unset_hook(evhtp_callback_t * callback, evhtp_hook_type type)
{
return htp__unset_hook_(&callback->hooks, type);
}

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

int
evhtp_connection_unset_hook(evhtp_connection_t * conn, evhtp_hook_type type)
{
return htp__unset_hook_(&conn->hooks, type);
}

int
Expand All @@ -4376,12 +4393,6 @@ evhtp_connection_set_hook(evhtp_connection_t * conn, evhtp_hook_type type, evhtp
return htp__set_hook_(&conn->hooks, type, cb, arg);
}

int
evhtp_unset_hook(evhtp_hooks_t ** hooks, evhtp_hook_type type)
{
return evhtp_set_hook(hooks, type, NULL, NULL);
}

int
evhtp_unset_all_hooks(evhtp_hooks_t ** hooks)
{
Expand Down Expand Up @@ -4413,7 +4424,7 @@ evhtp_unset_all_hooks(evhtp_hooks_t ** hooks)
}

for (i = 0; hooklist_[i].type != -1; i++) {
if (evhtp_unset_hook(hooks, hooklist_[i].type) == -1) {
if (htp__unset_hook_(hooks, hooklist_[i].type) == -1) {
return -1;
}
}
Expand Down
24 changes: 5 additions & 19 deletions include/evhtp/evhtp.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ 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_headers_cb)(evhtp_request_t * req, evhtp_headers_t * hdr, void * arg);
typedef evhtp_res (* evhtp_hook_path_cb)(evhtp_request_t * req, evhtp_path_t * path, void * arg);
typedef evhtp_res (* evhtp_hook_read_cb)(evhtp_request_t * req, evbuf_t * buf, void * arg);
typedef evhtp_res (* evhtp_hook_read_cb)(evhtp_request_t * req, struct evbuffer * buf, void * arg);
typedef evhtp_res (* evhtp_hook_request_fini_cb)(evhtp_request_t * req, void * arg);
typedef evhtp_res (* evhtp_hook_connection_fini_cb)(evhtp_connection_t * connection, void * arg);
typedef evhtp_res (* evhtp_hook_chunk_new_cb)(evhtp_request_t * r, uint64_t len, void * arg);
Expand Down Expand Up @@ -395,8 +395,8 @@ struct evhtp_request_s {
evhtp_connection_t * conn; /**< the associated connection */
evhtp_hooks_t * hooks; /**< request specific hooks */
evhtp_uri_t * uri; /**< request URI information */
evbuf_t * buffer_in; /**< buffer containing data from client */
evbuf_t * buffer_out; /**< buffer containing data to client */
struct evbuffer * buffer_in; /**< buffer containing data from client */
struct evbuffer * buffer_out; /**< buffer containing data to client */
evhtp_headers_t * headers_in; /**< headers from client */
evhtp_headers_t * headers_out; /**< headers to client */
evhtp_proto proto; /**< HTTP protocol used */
Expand Down Expand Up @@ -765,24 +765,10 @@ 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)
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.
*
* @param hooks
* @param type
*
* @return
*/
EVHTP_EXPORT int evhtp_unset_hook(evhtp_hooks_t ** hooks, evhtp_hook_type type);


/**
* @brief removes all hooks.
*
Expand Down Expand Up @@ -887,7 +873,7 @@ EVHTP_EXPORT void evhtp_send_reply(evhtp_request_t * request, evhtp_res code);
* but for the weak of heart.
*/
EVHTP_EXPORT void evhtp_send_reply_start(evhtp_request_t * request, evhtp_res code);
EVHTP_EXPORT void evhtp_send_reply_body(evhtp_request_t * request, evbuf_t * buf);
EVHTP_EXPORT void evhtp_send_reply_body(evhtp_request_t * request, struct evbuffer * buf);
EVHTP_EXPORT void evhtp_send_reply_end(evhtp_request_t * request);

/**
Expand All @@ -914,7 +900,7 @@ EVHTP_EXPORT void evhtp_send_reply_chunk_start(evhtp_request_t * request, evhtp_
* @param request
* @param buf
*/
EVHTP_EXPORT void evhtp_send_reply_chunk(evhtp_request_t * request, evbuf_t * buf);
EVHTP_EXPORT void evhtp_send_reply_chunk(evhtp_request_t * request, struct evbuffer * buf);

/**
* @brief call when all chunks have been sent and you wish to send the last
Expand Down
6 changes: 0 additions & 6 deletions parser.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <stdint.h>
#include <errno.h>
#include <ctype.h>
#include <unistd.h>

#include "internal.h"
#include "evhtp/parser.h"
Expand Down
6 changes: 0 additions & 6 deletions thread.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <inttypes.h>
#include <limits.h>
#include <errno.h>
#include <fcntl.h>
#ifndef WIN32
#include <sys/syscall.h>
#include <sys/ioctl.h>
#include <sys/queue.h>
#endif

Expand Down

0 comments on commit f1d2bd1

Please sign in to comment.