From 65a50280aeda166d4f780208e5eb47abb54fc5bf Mon Sep 17 00:00:00 2001 From: andrew-canaday Date: Tue, 30 Nov 2021 22:51:10 -0500 Subject: [PATCH] HTTP: Move request flags out of exchange + remove ymo_std_http. MISC: remove pre-release changelog. --- CHANGELOG.md | 12 ---- benchmarks/Makefile.am | 1 + benchmarks/benchmark_trie.c | 4 ++ include/yimmo.h.in | 7 +-- include/ymo_attrs.h | 85 ++++++++++++++++++----------- lib/Makefile.am | 6 +- lib/test/test_trie.c | 12 ++-- lib/ymo_assert.h | 2 +- lib/ymo_bucket.h | 1 - lib/ymo_conn.h | 2 + lib/ymo_server.c | 1 + lib/ymo_server.h | 3 - lib/ymo_util.c | 2 - mod/http/Makefile.am | 1 - mod/http/{ => extra}/ymo_std_http.c | 0 mod/http/{ => extra}/ymo_std_http.h | 0 mod/http/include/ymo_http.h | 1 + mod/http/test/Makefile.am | 14 +++-- mod/http/ymo_http_exchange.c | 4 +- mod/http/ymo_http_exchange.h | 5 -- mod/http/ymo_http_parse.c | 30 +++++----- mod/http/ymo_http_response.h | 2 +- mod/http/ymo_http_session.c | 1 - mod/http/ymo_proto_http.c | 12 ++-- 24 files changed, 107 insertions(+), 101 deletions(-) delete mode 100644 CHANGELOG.md rename mod/http/{ => extra}/ymo_std_http.c (100%) rename mod/http/{ => extra}/ymo_std_http.h (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 99be190..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,12 +0,0 @@ -pre-release-0.0.0 ------------------ - -*NOTICE*: -This release is being cut _purely to make sure that the *master* branch -contains appropriate licensing information_ (GPLv3). This semi-functional -release and is _not recommended for use by anyone for any purpose._ This -software package has not been publicly released. The licensing terms are -tentative. If you have received a copy of this software, it has likely been -in error. Please reach out to the package maintainer for more information. - - diff --git a/benchmarks/Makefile.am b/benchmarks/Makefile.am index 696ea05..699e1fc 100644 --- a/benchmarks/Makefile.am +++ b/benchmarks/Makefile.am @@ -28,6 +28,7 @@ AM_CFLAGS=\ -I@top_builddir@/include \ -I@top_srcdir@/include \ -I@top_srcdir@/mod/http \ + -I@top_srcdir@/mod/http/extra \ -I@top_srcdir@/mod/http/include \ -I@srcdir@ diff --git a/benchmarks/benchmark_trie.c b/benchmarks/benchmark_trie.c index 215d362..e9c21a8 100644 --- a/benchmarks/benchmark_trie.c +++ b/benchmarks/benchmark_trie.c @@ -28,6 +28,10 @@ #include "ymo_http_hdr_table.h" #include "ymo_http.h" #include "ymo_std_http.h" + +/* HACK HACK: so sorry about this. It's temporary. */ +#include "ymo_std_http.c" + #include "ymo_benchmark.h" #define NO_ITERATIONS 10000000 diff --git a/include/yimmo.h.in b/include/yimmo.h.in index 692815a..940e954 100644 --- a/include/yimmo.h.in +++ b/include/yimmo.h.in @@ -179,12 +179,11 @@ typedef void (*ymo_user_conn_cleanup_cb_t)( ymo_conn_t* conn, void* user); -/** Enumeration type used to pass server configuration flags. - */ -YMO_ENUM16_TYPEDEF(ymo_server_config_flags) { +/** Enumeration type used to pass server configuration flags. */ +typedef enum ymo_server_config_flags { YMO_SERVER_REUSE_ADDR = 0x01, /* allow service to bind while socket in the WAIT state */ YMO_SERVER_REUSE_PORT = 0x02, /* allow multiple processes to bind to the listen port */ -} YMO_ENUM16_AS(ymo_server_config_flags_t); +} ymo_server_config_flags_t; /** Struct used to pass configuration information to * :c:func:`ymo_server_create`. diff --git a/include/ymo_attrs.h b/include/ymo_attrs.h index f4ae257..1b01ae7 100644 --- a/include/ymo_attrs.h +++ b/include/ymo_attrs.h @@ -48,35 +48,56 @@ *---------------------------------------------------------------*/ #if defined(HAVE_VAR_ATTRIBUTE_MODE) && (HAVE_VAR_ATTRIBUTE_MODE == 1) -#define YMO_ATTR_MODE(x) __attribute__((mode(x))) -#define YMO_ENUM8_TYPEDEF(x) typedef enum x -#define YMO_ENUM8_AS(x) x YMO_ATTR_MODE(__byte__) -#define YMO_ENUM16_TYPEDEF(x) enum x -#define YMO_ENUM16_AS(x) ; typedef uint16_t x -// #define YMO_ENUM16_TYPEDEF(x) typedef enum x -// #define YMO_ENUM16_AS(x) x YMO_ATTR_MODE(HImode) +# define YMO_ATTR_MODE(x) __attribute__((mode(x))) #else -#define YMO_ATTR_MODE(x) -#define YMO_ENUM8_TYPEDEF(x) enum x -#define YMO_ENUM8_AS(x) ; typedef uint8_t x -#define YMO_ENUM16_TYPEDEF(x) enum x -#define YMO_ENUM16_AS(x) ; typedef uint16_t x +# define YMO_ATTR_MODE(x) #endif /* HAVE_VAR_ATTRIBUTE_MODE */ #if defined(HAVE_VAR_ATTRIBUTE_ALIGNED) && (HAVE_VAR_ATTRIBUTE_ALIGNED == 1) -#define YMO_ATTR_ALIGNED(x) __attribute__((aligned(x))) +# define YMO_ATTR_ALIGNED(x) __attribute__((aligned(x))) #else -#define YMO_ATTR_ALIGNED(x) +# define YMO_ATTR_ALIGNED(x) #endif /* HAVE_VAR_ATTRIBUTE_ALIGNED */ + +/*---------------------------------------------------------------* + * Packed Enum Definitions: + * (To disable #define YMO_ENUM_NO_PACK 1) + *---------------------------------------------------------------*/ + +#if defined(YMO_ENUM_NO_PACK) && (YMO_ENUM_NO_PACK == 1) +# define YMO_ENUM8_TYPEDEF(x) typedef enum x +# define YMO_ENUM8_AS(x) x +# define YMO_ENUM16_TYPEDEF(x) typedef enum x +# define YMO_ENUM16_AS(x) x +#else +# if defined(HAVE_VAR_ATTRIBUTE_MODE) && (HAVE_VAR_ATTRIBUTE_MODE == 1) +# define YMO_ENUM8_TYPEDEF(x) typedef enum x +# define YMO_ENUM8_AS(x) x YMO_ATTR_MODE(__byte__) +# define YMO_ENUM16_TYPEDEF(x) enum x +# define YMO_ENUM16_AS(x) ; typedef uint16_t x +/* TODO: why did I do this? Also, why did I undo it? */ +# if 0 +# define YMO_ENUM16_TYPEDEF(x) typedef enum x +# define YMO_ENUM16_AS(x) x YMO_ATTR_MODE(HImode) +# endif +# else +# define YMO_ENUM8_TYPEDEF(x) enum x +# define YMO_ENUM8_AS(x) ; typedef uint8_t x +# define YMO_ENUM16_TYPEDEF(x) enum x +# define YMO_ENUM16_AS(x) ; typedef uint16_t x +# endif /* HAVE_VAR_ATTRIBUTE_MODE */ +#endif /* YMO_ENUM_NO_PACK */ + + /*---------------------------------------------------------------* * Compiler Function Attribute Wrappers: *---------------------------------------------------------------*/ #if defined(HAVE_FUNC_ATTRIBUTE_MALLOC) && (HAVE_FUNC_ATTRIBUTE_MALLOC == 1) -# define YMO_FUNC_MALLOC __attribute__((malloc)) -# define YMO_FUNC_MALLOC_A malloc -# define YMO_FUNC_MALLOC_P malloc, +# define YMO_FUNC_MALLOC __attribute__((malloc)) +# define YMO_FUNC_MALLOC_A malloc +# define YMO_FUNC_MALLOC_P malloc, #else # define YMO_FUNC_MALLOC # define YMO_FUNC_MALLOC_A @@ -84,9 +105,9 @@ #endif /* HAVE_FUNC_ATTRIBUTE_MALLOC */ #if defined(HAVE_FUNC_ATTRIBUTE_UNUSED) && (HAVE_FUNC_ATTRIBUTE_UNUSED == 1) -# define YMO_FUNC_UNUSED __attribute__((unused)) -# define YMO_FUNC_UNUSED_A unused -# define YMO_FUNC_UNUSED_P unused, +# define YMO_FUNC_UNUSED __attribute__((unused)) +# define YMO_FUNC_UNUSED_A unused +# define YMO_FUNC_UNUSED_P unused, #else # define YMO_FUNC_UNUSED # define YMO_FUNC_UNUSED_A @@ -94,9 +115,9 @@ #endif /* HAVE_FUNC_ATTRIBUTE_UNUSED */ #if defined(HAVE_FUNC_ATTRIBUTE_FLATTEN) && (HAVE_FUNC_ATTRIBUTE_FLATTEN == 1) -# define YMO_FUNC_FLATTEN __attribute__((flatten)) -# define YMO_FUNC_FLATTEN_A flatten -# define YMO_FUNC_FLATTEN_P flatten, +# define YMO_FUNC_FLATTEN __attribute__((flatten)) +# define YMO_FUNC_FLATTEN_A flatten +# define YMO_FUNC_FLATTEN_P flatten, #else # define YMO_FUNC_FLATTEN # define YMO_FUNC_FLATTEN_A @@ -110,9 +131,9 @@ #endif /* HAVE_FUNC_ATTRIBUTE_FALLTHROUGH */ #if defined(HAVE_FUNC_ATTRIBUTE_WEAK) && (HAVE_FUNC_ATTRIBUTE_WEAK == 1) -# define YMO_FUNC_WEAK __attribute__((weak)) -# define YMO_FUNC_WEAK_A weak -# define YMO_FUNC_WEAK_P weak, +# define YMO_FUNC_WEAK __attribute__((weak)) +# define YMO_FUNC_WEAK_A weak +# define YMO_FUNC_WEAK_P weak, #else # define YMO_FUNC_WEAK # define YMO_FUNC_WEAK_A @@ -120,9 +141,9 @@ #endif /* HAVE_FUNC_ATTRIBUTE_WEAK */ #if defined(HAVE_FUNC_ATTRIBUTE_WEAKREF) && (HAVE_FUNC_ATTRIBUTE_WEAKREF == 1) -# define YMO_FUNC_WEAKREF(x) __attribute__((weakref(#x))) -# define YMO_FUNC_WEAKREF_A(x) weakref(#x) -# define YMO_FUNC_WEAKREF_P(x) weakref(#x), +# define YMO_FUNC_WEAKREF(x) __attribute__((weakref(#x))) +# define YMO_FUNC_WEAKREF_A(x) weakref(#x) +# define YMO_FUNC_WEAKREF_P(x) weakref(#x), #else # define YMO_FUNC_WEAKREF # define YMO_FUNC_WEAKREF_A @@ -130,9 +151,9 @@ #endif /* HAVE_FUNC_ATTRIBUTE_WEAKREF */ #if defined(HAVE_FUNC_ATTRIBUTE_ALIAS) && (HAVE_FUNC_ATTRIBUTE_ALIAS == 1) -# define YMO_FUNC_ALIAS(x) __attribute__((alias(#x))) -# define YMO_FUNC_ALIAS_A(x) alias(#x) -# define YMO_FUNC_ALIAS_P(x) alias(#x), +# define YMO_FUNC_ALIAS(x) __attribute__((alias(#x))) +# define YMO_FUNC_ALIAS_A(x) alias(#x) +# define YMO_FUNC_ALIAS_P(x) alias(#x), #else # define YMO_FUNC_ALIAS # define YMO_FUNC_ALIAS_A diff --git a/lib/Makefile.am b/lib/Makefile.am index 389221a..2fc7513 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -29,9 +29,9 @@ lib_LTLIBRARIES=\ libyimmo.la libyimmo_la_CFLAGS=\ - -I@top_builddir@/include \ - -I@top_srcdir@/include \ - -I@top_srcdir@/lib \ + -I@top_builddir@/include \ + -I@top_srcdir@/include \ + -I@top_srcdir@/lib \ @BSAT_CFLAGS@ libyimmo_la_LDFLAGS=\ diff --git a/lib/test/test_trie.c b/lib/test/test_trie.c index 0c2e3a2..c3cd0a2 100644 --- a/lib/test/test_trie.c +++ b/lib/test/test_trie.c @@ -90,14 +90,14 @@ static int add_headers(void) r_val = ymo_trie_add_string(trie, hdr); ymo_assert(r_val == YMO_OKAY); } - YMO_TAP_PASS("TODO: update message"); + YMO_TAP_PASS(__func__); } static int create_oitrie(void) { oitrie = ymo_oitrie_create(trie); ymo_assert(oitrie != NULL); - YMO_TAP_PASS("TODO: update message"); + YMO_TAP_PASS(__func__); } static int check_headers(void) @@ -108,7 +108,7 @@ static int check_headers(void) r_val = ymo_oitrie_get_id(&hdr_id, oitrie, hdr); ymo_assert(r_val == YMO_OKAY); } - YMO_TAP_PASS("TODO: update message"); + YMO_TAP_PASS(__func__); } static int check_missing(void) @@ -117,7 +117,7 @@ static int check_missing(void) hdr = "Not-A-Real-Header"; r_val = ymo_oitrie_get_id(&hdr_id, oitrie, hdr); ymo_assert(r_val == EINVAL); - YMO_TAP_PASS("TODO: update message"); + YMO_TAP_PASS(__func__); } static int check_partial1(void) @@ -126,7 +126,7 @@ static int check_partial1(void) hdr = "Accept-Charse"; r_val = ymo_oitrie_get_id(&hdr_id, oitrie, hdr); ymo_assert(r_val == EINVAL); - YMO_TAP_PASS("TODO: update message"); + YMO_TAP_PASS(__func__); } static int check_partial2(void) @@ -135,7 +135,7 @@ static int check_partial2(void) hdr = "Accept-Charset-"; r_val = ymo_oitrie_get_id(&hdr_id, oitrie, hdr); ymo_assert(r_val == EINVAL); - YMO_TAP_PASS("TODO: update message"); + YMO_TAP_PASS(__func__); } /*-------------------------------------------------------------* diff --git a/lib/ymo_assert.h b/lib/ymo_assert.h index 097520a..22656f4 100644 --- a/lib/ymo_assert.h +++ b/lib/ymo_assert.h @@ -99,7 +99,7 @@ */ #define ymo_assert_test_pass_fmt(fmt, ...) \ if( YMO_ASSERT_VERBOSE ) { \ - fprintf(YMO_ASSERT_STREAM_OUT, \ + fprintf(YMO_ASSERT_STREAM_OUT, \ " - \033[00;32mPASS: "fmt " (%s:%s:%i)\033[00;m\n", \ __VA_ARGS__, YMO_SOURCE, __func__, __LINE__); \ } diff --git a/lib/ymo_bucket.h b/lib/ymo_bucket.h index eb4d7d6..683c428 100644 --- a/lib/ymo_bucket.h +++ b/lib/ymo_bucket.h @@ -59,7 +59,6 @@ YMO_ENUM8_TYPEDEF(ymo_bucket_code) { *---------------------------------------------------------------*/ /* TODO: this should probably take the bucket data, as well... - * TODO: this isn't used... */ typedef ymo_status_t (*ymo_bucket_cb_t)(void* data); diff --git a/lib/ymo_conn.h b/lib/ymo_conn.h index bcf89b7..d0ef2bb 100644 --- a/lib/ymo_conn.h +++ b/lib/ymo_conn.h @@ -64,8 +64,10 @@ struct ymo_conn { int ev_flags; /* Used to store EV_READ/EV_WRITE flags */ struct ev_io w_read; /* Per-connection read watcher */ struct ev_io w_write; /* Per-connection write watcher */ +#if defined(YMO_CONN_LOCK) && (YMO_CONN_LOCK == 1) pthread_mutexattr_t lattr; /* Per-connection mutex attributes */ pthread_mutex_t lock; /* Per-connection mutex */ +#endif /* YMO_CONN_LOCK */ }; /*---------------------------------------------------------------* diff --git a/lib/ymo_server.c b/lib/ymo_server.c index bc2d258..588f29c 100644 --- a/lib/ymo_server.c +++ b/lib/ymo_server.c @@ -30,6 +30,7 @@ #include #include #include +#include #include "yimmo.h" #include "ymo_alloc.h" diff --git a/lib/ymo_server.h b/lib/ymo_server.h index 4c72b95..a1d7262 100644 --- a/lib/ymo_server.h +++ b/lib/ymo_server.h @@ -58,9 +58,6 @@ #include #include "yimmo.h" -#include "ymo_proto.h" -#include "ymo_trie.h" - #include "ymo_proto.h" /**--------------------------------------------------------------- diff --git a/lib/ymo_util.c b/lib/ymo_util.c index 05972e1..ffd57ed 100644 --- a/lib/ymo_util.c +++ b/lib/ymo_util.c @@ -117,7 +117,6 @@ char ymo_toupper(char c) #endif /* YMO_TOLOWER_NO_INLINE */ -/* TODO: SIMD optimizations here? */ void ymo_ntolower(char* dst, const char* src, size_t len) { /* Number of iterations we can perform at maximum stride: */ @@ -204,7 +203,6 @@ void ymo_ntolower(char* dst, const char* src, size_t len) } -/* TODO: SIMD optimizations here? */ void ymo_ntoupper(char* dst, const char* src, size_t len) { /* Number of iterations we can perform at maximum stride: */ diff --git a/mod/http/Makefile.am b/mod/http/Makefile.am index b136a9a..582c68b 100644 --- a/mod/http/Makefile.am +++ b/mod/http/Makefile.am @@ -47,7 +47,6 @@ libyimmo_http_la_LDFLAGS=\ @BSAT_LIBS@ libyimmo_http_la_SOURCES=\ - ymo_std_http.c \ ymo_proto_http.c \ ymo_http_session.c \ ymo_http_parse.c \ diff --git a/mod/http/ymo_std_http.c b/mod/http/extra/ymo_std_http.c similarity index 100% rename from mod/http/ymo_std_http.c rename to mod/http/extra/ymo_std_http.c diff --git a/mod/http/ymo_std_http.h b/mod/http/extra/ymo_std_http.h similarity index 100% rename from mod/http/ymo_std_http.h rename to mod/http/extra/ymo_std_http.h diff --git a/mod/http/include/ymo_http.h b/mod/http/include/ymo_http.h index 050a7c7..9038081 100644 --- a/mod/http/include/ymo_http.h +++ b/mod/http/include/ymo_http.h @@ -375,6 +375,7 @@ struct ymo_http_request { char* body; /* Optionally buffered body data */ size_t body_received; /* Body data received */ size_t content_length; /* Content-length, per client */ + ymo_http_flags_t flags; /* Request flags */ }; /** Responses diff --git a/mod/http/test/Makefile.am b/mod/http/test/Makefile.am index 3599bbd..973d9a2 100644 --- a/mod/http/test/Makefile.am +++ b/mod/http/test/Makefile.am @@ -29,14 +29,18 @@ TEST_LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) \ @top_srcdir@/build-aux/tap-driver.sh AM_CFLAGS=\ - -I@top_builddir@/include \ - -I@top_srcdir@/include \ - -I@top_srcdir@/lib \ - -I@top_srcdir@/mod \ + -I@top_builddir@/include \ + -I@top_srcdir@/include \ + -I@top_srcdir@/lib \ + -I@top_srcdir@/mod \ -I@top_srcdir@/mod/http \ - -I@top_srcdir@/mod/http/include \ + -I@top_srcdir@/mod/http/include \ @BSAT_CFLAGS@ +AM_LDFLAGS=\ + @BSAT_LIBS@ \ + @LIBS@ + LDADD=\ $(top_builddir)/mod/http/libyimmo_http.la \ $(top_builddir)/lib/libyimmo.la diff --git a/mod/http/ymo_http_exchange.c b/mod/http/ymo_http_exchange.c index f05160d..04914a8 100644 --- a/mod/http/ymo_http_exchange.c +++ b/mod/http/ymo_http_exchange.c @@ -81,7 +81,7 @@ void ymo_http_exchange_reset(ymo_http_exchange_t* exchange) exchange->request.content_length = 0; exchange->request.body_received = 0; exchange->recv_current = exchange->recv_buf; - exchange->flags = 0; + exchange->request.flags = 0; exchange->state = HTTP_STATE_CONNECTED; exchange->next_state = 0; exchange->remain = YMO_HTTP_RECV_BUF_SIZE; @@ -90,7 +90,7 @@ void ymo_http_exchange_reset(ymo_http_exchange_t* exchange) ymo_http_flags_t ymo_http_request_flags(const ymo_http_exchange_t* exchange) { - return exchange->flags; + return exchange->request.flags; } void ymo_http_exchange_free(ymo_http_exchange_t* exchange) diff --git a/mod/http/ymo_http_exchange.h b/mod/http/ymo_http_exchange.h index 1c17820..6a50501 100644 --- a/mod/http/ymo_http_exchange.h +++ b/mod/http/ymo_http_exchange.h @@ -65,10 +65,6 @@ YMO_ENUM8_TYPEDEF(crlf_state) { HTTP_EXPECT_LF, } YMO_ENUM8_AS(crlf_state_t); -/** Indicates the offset for a given HTTP header value within recv_buf. - */ -typedef uint16_t ymo_http_hdr_offset_t; - /** Struct used to store HTTP exchange data. * * .. TODO:: @@ -94,7 +90,6 @@ struct ymo_http_exchange { }; }; - ymo_http_flags_t flags; http_state_t state; http_state_t next_state; char* recv_current; diff --git a/mod/http/ymo_http_parse.c b/mod/http/ymo_http_parse.c index 0e35059..38c87a7 100644 --- a/mod/http/ymo_http_parse.c +++ b/mod/http/ymo_http_parse.c @@ -121,7 +121,7 @@ static ymo_status_t check_request( switch( http_ver ) { case HACK_HTTP_11: - exchange->flags \ + exchange->request.flags \ |= (YMO_HTTP_FLAG_VERSION_1_1 | YMO_HTTP_FLAG_SUPPORTS_CHUNKED | YMO_HTTP_FLAG_REQUEST_KEEPALIVE); @@ -163,13 +163,13 @@ static ymo_status_t ymo_http_session_init_response( } exchange->response = response; - response->flags = exchange->flags; - if( exchange->flags & YMO_HTTP_FLAG_REQUEST_KEEPALIVE ) { - if( !(exchange->flags & YMO_HTTP_FLAG_VERSION_1_1) ) { + response->flags = exchange->request.flags; + if( exchange->request.flags & YMO_HTTP_FLAG_REQUEST_KEEPALIVE ) { + if( !(exchange->request.flags & YMO_HTTP_FLAG_VERSION_1_1) ) { ymo_http_hdr_table_insert(&response->headers, "Connection", "Keep-alive"); } } else { - if( exchange->flags & YMO_HTTP_FLAG_VERSION_1_1 ) { + if( exchange->request.flags & YMO_HTTP_FLAG_VERSION_1_1 ) { ymo_http_hdr_table_insert(&response->headers, "Connection", "close"); } } @@ -204,7 +204,7 @@ static ymo_status_t check_headers( /* Adjust the state if the client was audacious enough to send * Expect: 100-continue: */ - if( exchange->flags & YMO_HTTP_FLAG_EXPECT ) { + if( exchange->request.flags & YMO_HTTP_FLAG_EXPECT ) { next_state = HTTP_STATE_EXPECT; } @@ -218,7 +218,7 @@ static ymo_status_t check_headers( exchange->request.content_length); return EFBIG; #endif /* 0 */ - } else if( exchange->flags & YMO_HTTP_REQUEST_CHUNKED ) { + } else if( exchange->request.flags & YMO_HTTP_REQUEST_CHUNKED ) { exchange->chunk_current = exchange->chunk_hdr; next_state = HTTP_STATE_BODY_CHUNK_HEADER; } @@ -228,7 +228,7 @@ static ymo_status_t check_headers( * * TODO: move this to user code now that we have header_cb? */ - if( exchange->flags & YMO_HTTP_FLAG_EXPECT ) { + if( exchange->request.flags & YMO_HTTP_FLAG_EXPECT ) { next_state = HTTP_STATE_EXPECT; } @@ -510,7 +510,7 @@ ssize_t ymo_parse_http_headers( switch( exchange->h_id ) { case HDR_ID_CONNECTION: /* 1.1: default to keep-alive unless "close": */ - if( exchange->flags & YMO_HTTP_FLAG_VERSION_1_1 ) { + if( exchange->request.flags & YMO_HTTP_FLAG_VERSION_1_1 ) { /* TODO: we know the lengths of these. Use * a ymo_strncmp function which checks length * first? @@ -519,13 +519,13 @@ ssize_t ymo_parse_http_headers( * be super close, so... what's the benefit? */ if( !strcasecmp(exchange->hdr_value, "close") ) { - exchange->flags &= \ + exchange->request.flags &= \ YMO_HTTP_FLAG_REQUEST_CLOSE; } } else { /* 1.0: default to close unless "keep-alive": */ if( !strcasecmp(exchange->hdr_value, "keep-alive") ) { - exchange->flags |= \ + exchange->request.flags |= \ YMO_HTTP_FLAG_REQUEST_KEEPALIVE; } } @@ -547,14 +547,14 @@ ssize_t ymo_parse_http_headers( break; case HDR_ID_EXPECT: if( !strcasecmp(exchange->hdr_value, "100-continue") ) { - exchange->flags |= YMO_HTTP_FLAG_EXPECT; + exchange->request.flags |= YMO_HTTP_FLAG_EXPECT; } break; case HDR_ID_UPGRADE: - exchange->flags |= YMO_HTTP_FLAG_UPGRADE; + exchange->request.flags |= YMO_HTTP_FLAG_UPGRADE; case HDR_ID_TRANSFER_ENCODING: if( !strcasecmp(exchange->hdr_value, "chunked")) { - exchange->flags |= YMO_HTTP_REQUEST_CHUNKED; + exchange->request.flags |= YMO_HTTP_REQUEST_CHUNKED; } break; default: @@ -669,7 +669,7 @@ ssize_t ymo_parse_http_body( current += body_available; if( !exchange->body_remain ) { - if( exchange->flags & YMO_HTTP_REQUEST_CHUNKED ) { + if( exchange->request.flags & YMO_HTTP_REQUEST_CHUNKED ) { exchange->state = HTTP_STATE_BODY_CHUNK_TRAILER; exchange->next_state = HTTP_STATE_BODY_CHUNK_HEADER; } else { diff --git a/mod/http/ymo_http_response.h b/mod/http/ymo_http_response.h index 65c4d0f..14aff0e 100644 --- a/mod/http/ymo_http_response.h +++ b/mod/http/ymo_http_response.h @@ -65,7 +65,7 @@ struct ymo_http_response { ymo_bucket_t* body_tail; ymo_proto_t* proto_new; ymo_http_status_t status; - ymo_http_flags_t flags; /* TODO: move into exchange? */ + ymo_http_flags_t flags; }; diff --git a/mod/http/ymo_http_session.c b/mod/http/ymo_http_session.c index 8324750..9b9264d 100644 --- a/mod/http/ymo_http_session.c +++ b/mod/http/ymo_http_session.c @@ -28,7 +28,6 @@ #include "yimmo.h" #include "ymo_log.h" #include "ymo_alloc.h" -#include "ymo_std_http.h" #include "ymo_http_session.h" #include "ymo_http_exchange.h" #include "ymo_http_response.h" diff --git a/mod/http/ymo_proto_http.c b/mod/http/ymo_proto_http.c index c05b594..25c855b 100644 --- a/mod/http/ymo_proto_http.c +++ b/mod/http/ymo_proto_http.c @@ -32,7 +32,6 @@ #include "ymo_server.h" #include "ymo_conn.h" #include "ymo_alloc.h" -#include "ymo_std_http.h" #include "ymo_proto_http.h" #include "ymo_http_session.h" #include "ymo_http_parse.h" @@ -303,7 +302,7 @@ static ymo_status_t ymo_http_handler( /* Is this an upgrade exchange? */ ymo_http_upgrade_status_t upgrade_status = YMO_HTTP_UPGRADE_IGNORE; - if( exchange->flags & YMO_HTTP_FLAG_UPGRADE ) { + if( exchange->request.flags & YMO_HTTP_FLAG_UPGRADE ) { const char* hdr_upgrade = NULL; hdr_upgrade = ymo_http_hdr_table_get_id( &exchange->request.headers, HDR_ID_UPGRADE); @@ -555,16 +554,15 @@ ssize_t ymo_proto_http_read( exchange->request.query, exchange->request.fragment, exchange->request.content_length); - ymo_server_t* server = ymo_conn_server(conn); ymo_status_t status = ymo_http_handler( - server, conn, http_proto_data, + conn->server, conn, http_proto_data, http_session, exchange); if( status != YMO_OKAY && !YMO_IS_BLOCKED(status) ) { errno = status; return -1; } - if( ymo_server_get_state(server) == YMO_SERVER_STOP_GRACEFUL ) { + if( ymo_server_get_state(conn->server) == YMO_SERVER_STOP_GRACEFUL ) { /* if the server's shutting down and we just handled a exchange, * stop reading from this connection: */ @@ -599,8 +597,8 @@ ssize_t ymo_proto_http_read( } /* Untoggle expect so we don't come back here: */ - exchange->flags &= ~(YMO_HTTP_FLAG_EXPECT); - if( exchange->flags & YMO_HTTP_REQUEST_CHUNKED ) { + exchange->request.flags &= ~(YMO_HTTP_FLAG_EXPECT); + if( exchange->request.flags & YMO_HTTP_REQUEST_CHUNKED ) { exchange->state = HTTP_STATE_BODY_CHUNK_HEADER; } else { exchange->state = HTTP_STATE_BODY;