summaryrefslogtreecommitdiff
path: root/ct-parser.c
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2016-08-28 23:23:10 -0400
committerPaul Duncan <pabs@pablotron.org>2016-08-28 23:23:10 -0400
commit0308b0cc9fab95f0f12aa874ae1fcded31d7f573 (patch)
tree47e40528e1439e161b3f855e2bab7c7233b6d94a /ct-parser.c
parent845ddb43da8aa2a8c80a9d9638d63386ddf97d7e (diff)
downloadlibfhp-0308b0cc9fab95f0f12aa874ae1fcded31d7f573.tar.bz2
libfhp-0308b0cc9fab95f0f12aa874ae1fcded31d7f573.zip
add content-type parser
Diffstat (limited to 'ct-parser.c')
-rw-r--r--ct-parser.c49
1 files changed, 49 insertions, 0 deletions
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;
+}