xref: /unit/src/nxt_http_parse.h (revision 480)
116Svbart@nginx.com 
216Svbart@nginx.com /*
316Svbart@nginx.com  * Copyright (C) NGINX, Inc.
416Svbart@nginx.com  * Copyright (C) Valentin V. Bartenev
516Svbart@nginx.com  */
616Svbart@nginx.com 
716Svbart@nginx.com #ifndef _NXT_HTTP_PARSER_H_INCLUDED_
816Svbart@nginx.com #define _NXT_HTTP_PARSER_H_INCLUDED_
916Svbart@nginx.com 
1016Svbart@nginx.com 
11*480Svbart@nginx.com typedef enum {
12*480Svbart@nginx.com     NXT_HTTP_PARSE_INVALID = 1,
13*480Svbart@nginx.com     NXT_HTTP_PARSE_TOO_LARGE_FIELD,
14*480Svbart@nginx.com } nxt_http_parse_error_t;
15*480Svbart@nginx.com 
16*480Svbart@nginx.com 
1716Svbart@nginx.com typedef struct nxt_http_request_parse_s  nxt_http_request_parse_t;
1867Svbart@nginx.com typedef struct nxt_http_field_s          nxt_http_field_t;
1916Svbart@nginx.com typedef struct nxt_http_fields_hash_s    nxt_http_fields_hash_t;
2016Svbart@nginx.com 
2160Svbart@nginx.com 
2260Svbart@nginx.com typedef union {
23417Svbart@nginx.com     u_char                    str[8];
24417Svbart@nginx.com     uint64_t                  ui64;
2560Svbart@nginx.com } nxt_http_ver_t;
2616Svbart@nginx.com 
2716Svbart@nginx.com 
2816Svbart@nginx.com struct nxt_http_request_parse_s {
2967Svbart@nginx.com     nxt_int_t                 (*handler)(nxt_http_request_parse_t *rp,
3067Svbart@nginx.com                                          u_char **pos, u_char *end);
3167Svbart@nginx.com 
3267Svbart@nginx.com     size_t                    offset;
3316Svbart@nginx.com 
3467Svbart@nginx.com     nxt_str_t                 method;
3516Svbart@nginx.com 
3667Svbart@nginx.com     u_char                    *target_start;
3767Svbart@nginx.com     u_char                    *target_end;
3867Svbart@nginx.com     u_char                    *exten_start;
3967Svbart@nginx.com     u_char                    *args_start;
4016Svbart@nginx.com 
41112Smax.romanov@nginx.com     nxt_str_t                 path;
42112Smax.romanov@nginx.com     nxt_str_t                 args;
43112Smax.romanov@nginx.com     nxt_str_t                 exten;
44112Smax.romanov@nginx.com 
4567Svbart@nginx.com     nxt_http_ver_t            version;
4667Svbart@nginx.com 
47417Svbart@nginx.com     nxt_list_t                *fields;
48417Svbart@nginx.com     nxt_mp_t                  *mem_pool;
4916Svbart@nginx.com 
5067Svbart@nginx.com     nxt_str_t                 field_name;
5167Svbart@nginx.com     nxt_str_t                 field_value;
5216Svbart@nginx.com 
53417Svbart@nginx.com     uint32_t                  field_hash;
5416Svbart@nginx.com 
5516Svbart@nginx.com     /* target with "/." */
5667Svbart@nginx.com     unsigned                  complex_target:1;
5716Svbart@nginx.com     /* target with "%" */
5867Svbart@nginx.com     unsigned                  quoted_target:1;
5916Svbart@nginx.com     /* target with " " */
6067Svbart@nginx.com     unsigned                  space_in_target:1;
6116Svbart@nginx.com     /* target with "+" */
6267Svbart@nginx.com     unsigned                  plus_in_target:1;
6316Svbart@nginx.com };
6416Svbart@nginx.com 
6516Svbart@nginx.com 
6660Svbart@nginx.com typedef nxt_int_t (*nxt_http_field_handler_t)(void *ctx,
6760Svbart@nginx.com                                               nxt_http_field_t *field,
68417Svbart@nginx.com                                               uintptr_t data);
6960Svbart@nginx.com 
7060Svbart@nginx.com 
7116Svbart@nginx.com typedef struct {
7216Svbart@nginx.com     nxt_str_t                 name;
7316Svbart@nginx.com     nxt_http_field_handler_t  handler;
7416Svbart@nginx.com     uintptr_t                 data;
75417Svbart@nginx.com } nxt_http_field_proc_t;
7660Svbart@nginx.com 
7760Svbart@nginx.com 
7867Svbart@nginx.com struct nxt_http_field_s {
79417Svbart@nginx.com     uint16_t                  hash;
80417Svbart@nginx.com     uint8_t                   skip;             /* 1 bit */
81417Svbart@nginx.com     uint8_t                   name_length;
82417Svbart@nginx.com     uint32_t                  value_length;
83417Svbart@nginx.com     u_char                    *name;
84417Svbart@nginx.com     u_char                    *value;
8567Svbart@nginx.com };
8667Svbart@nginx.com 
8767Svbart@nginx.com 
88417Svbart@nginx.com nxt_int_t nxt_http_parse_request_init(nxt_http_request_parse_t *rp,
89417Svbart@nginx.com     nxt_mp_t *mp);
9016Svbart@nginx.com nxt_int_t nxt_http_parse_request(nxt_http_request_parse_t *rp,
9116Svbart@nginx.com     nxt_buf_mem_t *b);
92422Svbart@nginx.com nxt_int_t nxt_http_parse_fields(nxt_http_request_parse_t *rp,
93422Svbart@nginx.com     nxt_buf_mem_t *b);
9460Svbart@nginx.com 
95417Svbart@nginx.com nxt_int_t nxt_http_fields_hash(nxt_lvlhsh_t *hash, nxt_mp_t *mp,
96417Svbart@nginx.com     nxt_http_field_proc_t items[], nxt_uint_t count);
97417Svbart@nginx.com nxt_uint_t nxt_http_fields_hash_collisions(nxt_lvlhsh_t *hash, nxt_mp_t *mp,
98417Svbart@nginx.com     nxt_http_field_proc_t items[], nxt_uint_t count, nxt_bool_t level);
99417Svbart@nginx.com nxt_int_t nxt_http_fields_process(nxt_list_t *fields, nxt_lvlhsh_t *hash,
100417Svbart@nginx.com     void *ctx);
10116Svbart@nginx.com 
10216Svbart@nginx.com 
10316Svbart@nginx.com #endif /* _NXT_HTTP_PARSER_H_INCLUDED_ */
104