From 0308b0cc9fab95f0f12aa874ae1fcded31d7f573 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Sun, 28 Aug 2016 23:23:10 -0400 Subject: add content-type parser --- include/fhp/fhp.h | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'include/fhp/fhp.h') diff --git a/include/fhp/fhp.h b/include/fhp/fhp.h index 3aa020d..6225843 100644 --- a/include/fhp/fhp.h +++ b/include/fhp/fhp.h @@ -96,6 +96,7 @@ typedef enum { FHP_TOKEN_HEADER_TRANSFER_ENCODING, FHP_TOKEN_HEADER_CONTENT_LENGTH, + FHP_TOKEN_HEADER_CONTENT_TYPE, FHP_TOKEN_HEADERS_END, @@ -127,7 +128,7 @@ typedef enum { // env functions // -#define FHP_ENV_NUM_HASHES 17 +#define FHP_ENV_NUM_HASHES 20 typedef struct { uint32_t hashes[FHP_ENV_NUM_HASHES]; @@ -164,6 +165,32 @@ fhp_cl_parser_push(fhp_cl_parser_t *, uint8_t * const, size_t); fhp_err_t fhp_cl_parser_done(fhp_cl_parser_t * const, uint64_t * const); +// +// content-type parser functions +// + +typedef enum { + FHP_CONTENT_TYPE_NONE, + FHP_CONTENT_TYPE_APPLICATION_X_WWW_FORM_URLENCODED, + FHP_CONTENT_TYPE_MULTIPART_FORM_DATA, + FHP_CONTENT_TYPE_OTHER, + FHP_CONTENT_TYPE_LAST +} fhp_content_type_t; + +typedef struct { + fhp_env_t *env; + uint32_t hash; +} fhp_ct_parser_t; + +fhp_err_t +fhp_ct_parser_init(fhp_ct_parser_t * const, fhp_env_t * const); + +fhp_err_t +fhp_ct_parser_push(fhp_ct_parser_t *, uint8_t * const, size_t); + +fhp_err_t +fhp_ct_parser_done(fhp_ct_parser_t * const, fhp_content_type_t * const); + // // transfer-encoding parser functions // @@ -257,6 +284,7 @@ typedef enum { FHP_HEADER_VALUE_PARSER_NONE, FHP_HEADER_VALUE_PARSER_TRANSFER_ENCODING, FHP_HEADER_VALUE_PARSER_CONTENT_LENGTH, + FHP_HEADER_VALUE_PARSER_CONTENT_TYPE, FHP_HEADER_VALUE_PARSER_LAST } fhp_header_value_parser_t; @@ -302,6 +330,7 @@ struct fhp_ctx_t_ { union { fhp_te_parser_t te; fhp_cl_parser_t cl; + fhp_ct_parser_t ct; } parsers; // request body type @@ -310,6 +339,8 @@ struct fhp_ctx_t_ { // content length uint64_t content_length; + fhp_content_type_t content_type; + // transfer encodings uint32_t tes[FHP_CTX_MAX_TRANSFER_ENCODINGS]; size_t num_tes; -- cgit v1.2.3