summaryrefslogtreecommitdiff
path: root/ct-parser.c
blob: 0eb98b3ad8c78504bce7b493d96ef17e4b43a14e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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;
}