Permalink
Browse files

Merge branch 'release/0.4.10'

  • Loading branch information...
Mark Ellzey
Mark Ellzey committed Mar 12, 2012
2 parents 81ec5e2 + 60d0f25 commit 59f65303a82581cf107026bffebeb883506be743
Showing with 208 additions and 968 deletions.
  1. +4 −0 CMakeLists.txt
  2. +3 −1 CMakeModules/BaseConfig.cmake
  3. +125 −941 ChangeLog
  4. +14 −0 contrib/make_release.sh
  5. +10 −5 evhtp.c
  6. +2 −2 evhtp.h
  7. +8 −2 evthr/evthr.c
  8. +9 −2 htparse/htparse.c
  9. +1 −0 htparse/htparse.h
  10. +32 −15 test.c
View
@@ -150,6 +150,10 @@ if (NOT EVHTP_DISABLE_EVTHR)
set (LIBEVHTP_SOURCES ${LIBEVHTP_SOURCES} evthr/evthr.c)
endif(NOT EVHTP_DISABLE_EVTHR)
+if (NOT ${CMAKE_BUILD_TYPE} STREQUAL "Debug")
+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNDEBUG")
+endif (NOT ${CMAKE_BUILD_TYPE} STREQUAL "Debug")
+
add_library(libevhtp STATIC ${LIBEVHTP_SOURCES} ${ONIG_SOURCES})
set_target_properties(libevhtp PROPERTIES OUTPUT_NAME "evhtp")
@@ -6,7 +6,9 @@ if (CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${RSN_BASE_C_FLAGS}")
if(APPLE)
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshorten-64-to-32 -D_BSD_SOURCE")
+ # Newer versions of OSX will spew a bunch of warnings about deprecated ssl functions,
+ # this should be addressed at some point in time, but for now, just ignore them.
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_BSD_SOURCE -Wno-deprecated-declarations")
elseif(UNIX)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_BSD_SOURCE -D_POSIX_C_SOURCE=199309L")
endif(APPLE)
View
1,066 ChangeLog

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+mv ChangeLog bak.ChangeLog
+
+rev_list=`git rev-list --tags --max-count=1..HEAD`
+tag_desc=`git describe --tags $rev_list`
+cur_desc=`git flow release | awk '{print $2}'`
+
+echo v$cur_desc > ChangeLog
+git log --no-merges --reverse --pretty='format: o %s (%h %an)' $tag_desc..HEAD >> ChangeLog
+echo "" >> ChangeLog
+echo "" >> ChangeLog
+
+cat bak.ChangeLog >> ChangeLog
View
15 evhtp.c
@@ -1094,7 +1094,13 @@ _evhtp_create_headers(evhtp_header_t * header, void * arg) {
static evbuf_t *
_evhtp_create_reply(evhtp_request_t * request, evhtp_res code) {
- evbuf_t * buf = evbuffer_new();
+ evbuf_t * buf = evbuffer_new();
+ const char * content_type = evhtp_header_find(request->headers_out, "Content-Type");
+
+ if (content_type && strstr(content_type, "multipart")) {
+ /* multipart messages should not get any extra headers */
+ goto check_proto;
+ }
if (evbuffer_get_length(request->buffer_out) && request->chunked == 0) {
/* add extra headers (like content-length/type) if not already present */
@@ -1117,7 +1123,7 @@ _evhtp_create_reply(evhtp_request_t * request, evhtp_res code) {
evhtp_header_new("Content-Length", lstr, 0, 1));
}
- if (!evhtp_header_find(request->headers_out, "Content-Type")) {
+ if (!content_type) {
evhtp_headers_add_header(request->headers_out,
evhtp_header_new("Content-Type", "text/plain", 0, 0));
}
@@ -1294,7 +1300,7 @@ _evhtp_connection_accept(evbase_t * evbase, evhtp_connection_t * connection) {
connection->bev = bufferevent_openssl_socket_new(evbase,
connection->sock, connection->ssl,
BUFFEREVENT_SSL_ACCEPTING,
- BEV_OPT_THREADSAFE | BEV_OPT_CLOSE_ON_FREE | BEV_OPT_DEFER_CALLBACKS);
+ BEV_OPT_CLOSE_ON_FREE | BEV_OPT_DEFER_CALLBACKS);
SSL_set_app_data(connection->ssl, connection);
goto end;
}
@@ -2786,8 +2792,7 @@ evhtp_connection_free(evhtp_connection_t * connection) {
#else
#ifndef DISABLE_SSL
if (connection->ssl != NULL) {
- SSL_set_shutdown(connection->ssl,
- SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN);
+ SSL_set_shutdown(connection->ssl, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN);
SSL_shutdown(connection->ssl);
}
#endif
View
@@ -145,10 +145,10 @@ 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 void * (*evhtp_ssl_scache_init)(evhtp_t *);
-#define EVHTP_VERSION "0.4.9"
+#define EVHTP_VERSION "0.4.10"
#define EVHTP_VERSION_MAJOR 0
#define EVHTP_VERSION_MINOR 4
-#define EVHTP_VERSION_PATCH 9
+#define EVHTP_VERSION_PATCH 10
#define evhtp_headers_iterator evhtp_kvs_iterator
View
@@ -297,6 +297,8 @@ evthr_new(evthr_init_cb init_cb, void * args) {
int
evthr_start(evthr_t * thread) {
+ int res;
+
if (thread == NULL || thread->thr == NULL) {
return -1;
}
@@ -305,7 +307,9 @@ evthr_start(evthr_t * thread) {
return -1;
}
- return pthread_detach(*thread->thr);
+ res = pthread_detach(*thread->thr);
+
+ return res;
}
void
@@ -329,10 +333,12 @@ evthr_free(evthr_t * thread) {
if (thread->stat_lock) {
pthread_mutex_destroy(thread->stat_lock);
+ free(thread->stat_lock);
}
if (thread->rlock) {
pthread_mutex_destroy(thread->rlock);
+ free(thread->rlock);
}
if (thread->thr) {
@@ -348,7 +354,7 @@ evthr_free(evthr_t * thread) {
}
free(thread);
-}
+} /* evthr_free */
void
evthr_pool_free(evthr_pool_t * pool) {
View
@@ -113,6 +113,7 @@ struct htparser {
unsigned char minor;
uint64_t content_len;
uint64_t bytes_read;
+ uint64_t total_bytes_read;
unsigned int status; /* only for responses */
unsigned int status_count; /* only for responses */
@@ -410,6 +411,11 @@ htparser_get_bytes_read(htparser * p) {
return p->bytes_read;
}
+uint64_t
+htparser_get_total_bytes_read(htparser * p) {
+ return p->total_bytes_read;
+}
+
void
htparser_init(htparser * p, htp_type type) {
memset(p, 0, sizeof(htparser));
@@ -447,7 +453,8 @@ htparser_run(htparser * p, htparse_hooks * hooks, const char * data, size_t len)
return i + 1;
}
- p->bytes_read += 1;
+ p->total_bytes_read += 1;
+ p->bytes_read += 1;
switch (p->state) {
case s_start:
@@ -1319,7 +1326,7 @@ htparser_run(htparser * p, htparse_hooks * hooks, const char * data, size_t len)
case eval_hdr_val_none:
break;
case eval_hdr_val_content_length:
- p->content_len = str_to_uint64(p->buf, p->buf_idx, &err);
+ p->content_len = str_to_uint64(p->buf, p->buf_idx, &err);
if (err == 1) {
p->error = htparse_error_too_big;
View
@@ -95,6 +95,7 @@ unsigned char htparser_get_major(htparser *);
unsigned char htparser_get_minor(htparser *);
unsigned int htparser_get_status(htparser *);
uint64_t htparser_get_content_length(htparser *);
+uint64_t htparser_get_total_bytes_read(htparser *);
htpparse_error htparser_get_error(htparser *);
const char * htparser_get_strerror(htparser *);
void * htparser_get_userdata(htparser *);
View
47 test.c
@@ -5,6 +5,7 @@
#include <stdint.h>
#include <errno.h>
#include <signal.h>
+#include <inttypes.h>
#include <evhtp.h>
#ifndef DISABLE_EVTHR
@@ -16,6 +17,7 @@ uint16_t bind_port = 8081;
char * ssl_pem = NULL;
char * ssl_ca = NULL;
char * ssl_capath = NULL;
+size_t bw_limit = 0;
struct pauser {
event_t * timer_ev;
@@ -241,23 +243,20 @@ print_path(evhtp_request_t * req, evhtp_path_t * path, void * arg) {
}
static evhtp_res
-print_data(evhtp_request_t * req, evbuf_t * buf, void * arg ) {
-#if 0
+print_data(evhtp_request_t * req, evbuf_t * buf, void * arg) {
+#ifndef NDEBUG
evbuffer_add_printf(req->buffer_out,
"got %zu bytes of data\n",
evbuffer_get_length(buf));
- printf("%.*s", evbuffer_get_length(buf), (char *)evbuffer_pullup(buf,
- evbuffer_get_length(buf)));
+ printf("%.*s", evbuffer_get_length(buf), (char *)evbuffer_pullup(buf, evbuffer_get_length(buf)));
#endif
evbuffer_drain(buf, -1);
-
return EVHTP_RES_OK;
}
static evhtp_res
print_new_chunk_len(evhtp_request_t * req, uint64_t len, void * arg) {
- evbuffer_add_printf(req->buffer_out,
- "started new chunk, %zu bytes\n", len);
+ evbuffer_add_printf(req->buffer_out, "started new chunk, %" PRId64 "u bytes\n", len);
return EVHTP_RES_OK;
}
@@ -285,7 +284,7 @@ static evhtp_res
test_pre_accept(evhtp_connection_t * c, void * arg) {
uint16_t port = *(uint16_t *)arg;
- if (port > 8089) {
+ if (port > 10000) {
return EVHTP_RES_ERROR;
}
@@ -294,24 +293,38 @@ test_pre_accept(evhtp_connection_t * c, void * arg) {
static evhtp_res
test_fini(evhtp_request_t * r, void * arg) {
-#if 0
- fprintf(stderr, ".");
- fflush(stderr);
-#endif
+ struct ev_token_bucket_cfg * tcfg = arg;
+
+ if (tcfg) {
+ ev_token_bucket_cfg_free(tcfg);
+ }
return EVHTP_RES_OK;
}
static evhtp_res
-set_my_connection_handlers(evhtp_connection_t * conn, void * arg ) {
+set_my_connection_handlers(evhtp_connection_t * conn, void * arg) {
+ struct timeval tick;
+ struct ev_token_bucket_cfg * tcfg = NULL;
+
evhtp_set_hook(&conn->hooks, evhtp_hook_on_header, print_kv, "foo");
evhtp_set_hook(&conn->hooks, evhtp_hook_on_headers, print_kvs, "bar");
evhtp_set_hook(&conn->hooks, evhtp_hook_on_path, print_path, "baz");
evhtp_set_hook(&conn->hooks, evhtp_hook_on_read, print_data, "derp");
evhtp_set_hook(&conn->hooks, evhtp_hook_on_new_chunk, print_new_chunk_len, NULL);
evhtp_set_hook(&conn->hooks, evhtp_hook_on_chunk_complete, print_chunk_complete, NULL);
evhtp_set_hook(&conn->hooks, evhtp_hook_on_chunks_complete, print_chunks_complete, NULL);
- evhtp_set_hook(&conn->hooks, evhtp_hook_on_request_fini, test_fini, NULL);
+
+ if (bw_limit > 0) {
+ tick.tv_sec = 0;
+ tick.tv_usec = 500 * 100;
+
+ tcfg = ev_token_bucket_cfg_new(bw_limit, bw_limit, bw_limit, bw_limit, &tick);
+
+ bufferevent_set_rate_limit(conn->bev, tcfg);
+ }
+
+ evhtp_set_hook(&conn->hooks, evhtp_hook_on_request_fini, test_fini, tcfg);
return EVHTP_RES_OK;
}
@@ -329,7 +342,7 @@ dummy_check_issued_cb(X509_STORE_CTX * ctx, X509 * x, X509 * issuer) {
#endif
-const char * optstr = "htn:a:p:r:s:c:C:";
+const char * optstr = "htn:a:p:r:s:c:C:l:";
const char * help =
"Options: \n"
@@ -343,6 +356,7 @@ const char * help =
" -c <ca> : CA cert file (default: NULL)\n"
" -C <path>: CA Path (default: NULL)\n"
#endif
+ " -l <int> : Max bandwidth (in bytes) (default: NULL)\n"
" -r <str> : Document root (default: .)\n"
" -a <str> : Bind Address (default: 0.0.0.0)\n"
" -p <int> : Bind Port (default: 8081)\n";
@@ -386,6 +400,9 @@ parse_args(int argc, char ** argv) {
ssl_capath = strdup(optarg);
break;
#endif
+ case 'l':
+ bw_limit = atoll(optarg);
+ break;
default:
printf("Unknown opt %s\n", optarg);
return -1;

0 comments on commit 59f6530

Please sign in to comment.