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 --- ct-parser.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 ct-parser.c (limited to 'ct-parser.c') diff --git a/ct-parser.c b/ct-parser.c new file mode 100644 index 0000000..0eb98b3 --- /dev/null +++ b/ct-parser.c @@ -0,0 +1,49 @@ +#include "internal.h" + +// +// content-type parser +// + +fhp_err_t +fhp_ct_parser_init( + fhp_ct_parser_t * const p, + fhp_env_t * const env +) { + // init parser + p->env = env; + p->hash = fhp_hash_init(); + + // return succes + return FHP_OK; +} + +fhp_err_t +fhp_ct_parser_push( + fhp_ct_parser_t *p, + uint8_t * const buf, + size_t len +) { + p->hash = fhp_lc_hash_push(p->hash, buf, len); + + // return succes + return FHP_OK; +} + +fhp_err_t +fhp_ct_parser_done( + fhp_ct_parser_t * const p, + fhp_content_type_t * const ret_val +) { + if (ret_val) { + if (p->hash == p->env->hashes[FHP_STR_APPLICATION_X_WWW_FORM_URLENCODED]) { + *ret_val = FHP_CONTENT_TYPE_APPLICATION_X_WWW_FORM_URLENCODED; + } else if (p->hash == p->env->hashes[FHP_STR_MULTIPART_FORM_DATA]) { + *ret_val = FHP_CONTENT_TYPE_MULTIPART_FORM_DATA; + } else { + *ret_val = FHP_CONTENT_TYPE_OTHER; + } + } + + // return success + return FHP_OK; +} -- cgit v1.2.3