xref: /unit/src/nxt_http_parse.h (revision 481)
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 
11480Svbart@nginx.com typedef enum {
12480Svbart@nginx.com     NXT_HTTP_PARSE_INVALID = 1,
13480Svbart@nginx.com     NXT_HTTP_PARSE_TOO_LARGE_FIELD,
14480Svbart@nginx.com } nxt_http_parse_error_t;
15480Svbart@nginx.com 
16480Svbart@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;
25*481Svbart@nginx.com 
26*481Svbart@nginx.com     struct {
27*481Svbart@nginx.com         u_char                prefix[5];
28*481Svbart@nginx.com         u_char                major;
29*481Svbart@nginx.com         u_char                point;
30*481Svbart@nginx.com         u_char                minor;
31*481Svbart@nginx.com     } s;
3260Svbart@nginx.com } nxt_http_ver_t;
3316Svbart@nginx.com 
3416Svbart@nginx.com 
3516Svbart@nginx.com struct nxt_http_request_parse_s {
3667Svbart@nginx.com     nxt_int_t                 (*handler)(nxt_http_request_parse_t *rp,
3767Svbart@nginx.com                                          u_char **pos, u_char *end);
3867Svbart@nginx.com 
3967Svbart@nginx.com     size_t                    offset;
4016Svbart@nginx.com 
4167Svbart@nginx.com     nxt_str_t                 method;
4216Svbart@nginx.com 
4367Svbart@nginx.com     u_char                    *target_start;
4467Svbart@nginx.com     u_char                    *target_end;
4567Svbart@nginx.com     u_char                    *exten_start;
4667Svbart@nginx.com     u_char                    *args_start;
4716Svbart@nginx.com 
48112Smax.romanov@nginx.com     nxt_str_t                 path;
49112Smax.romanov@nginx.com     nxt_str_t                 args;
50112Smax.romanov@nginx.com     nxt_str_t                 exten;
51112Smax.romanov@nginx.com 
5267Svbart@nginx.com     nxt_http_ver_t            version;
5367Svbart@nginx.com 
54417Svbart@nginx.com     nxt_list_t                *fields;
55417Svbart@nginx.com     nxt_mp_t                  *mem_pool;
5616Svbart@nginx.com 
5767Svbart@nginx.com     nxt_str_t                 field_name;
5867Svbart@nginx.com     nxt_str_t                 field_value;
5916Svbart@nginx.com 
60417Svbart@nginx.com     uint32_t                  field_hash;
6116Svbart@nginx.com 
6216Svbart@nginx.com     /* target with "/." */
6367Svbart@nginx.com     unsigned                  complex_target:1;
6416Svbart@nginx.com     /* target with "%" */
6567Svbart@nginx.com     unsigned                  quoted_target:1;
6616Svbart@nginx.com     /* target with " " */
6767Svbart@nginx.com     unsigned                  space_in_target:1;
6816Svbart@nginx.com     /* target with "+" */
6967Svbart@nginx.com     unsigned                  plus_in_target:1;
7016Svbart@nginx.com };
7116Svbart@nginx.com 
7216Svbart@nginx.com 
7360Svbart@nginx.com typedef nxt_int_t (*nxt_http_field_handler_t)(void *ctx,
7460Svbart@nginx.com                                               nxt_http_field_t *field,
75417Svbart@nginx.com                                               uintptr_t data);
7660Svbart@nginx.com 
7760Svbart@nginx.com 
7816Svbart@nginx.com typedef struct {
7916Svbart@nginx.com     nxt_str_t                 name;
8016Svbart@nginx.com     nxt_http_field_handler_t  handler;
8116Svbart@nginx.com     uintptr_t                 data;
82417Svbart@nginx.com } nxt_http_field_proc_t;
8360Svbart@nginx.com 
8460Svbart@nginx.com 
8567Svbart@nginx.com struct nxt_http_field_s {
86417Svbart@nginx.com     uint16_t                  hash;
87417Svbart@nginx.com     uint8_t                   skip;             /* 1 bit */
88417Svbart@nginx.com     uint8_t                   name_length;
89417Svbart@nginx.com     uint32_t                  value_length;
90417Svbart@nginx.com     u_char                    *name;
91417Svbart@nginx.com     u_char                    *value;
9267Svbart@nginx.com };
9367Svbart@nginx.com 
9467Svbart@nginx.com 
95417Svbart@nginx.com nxt_int_t nxt_http_parse_request_init(nxt_http_request_parse_t *rp,
96417Svbart@nginx.com     nxt_mp_t *mp);
9716Svbart@nginx.com nxt_int_t nxt_http_parse_request(nxt_http_request_parse_t *rp,
9816Svbart@nginx.com     nxt_buf_mem_t *b);
99422Svbart@nginx.com nxt_int_t nxt_http_parse_fields(nxt_http_request_parse_t *rp,
100422Svbart@nginx.com     nxt_buf_mem_t *b);
10160Svbart@nginx.com 
102417Svbart@nginx.com nxt_int_t nxt_http_fields_hash(nxt_lvlhsh_t *hash, nxt_mp_t *mp,
103417Svbart@nginx.com     nxt_http_field_proc_t items[], nxt_uint_t count);
104417Svbart@nginx.com nxt_uint_t nxt_http_fields_hash_collisions(nxt_lvlhsh_t *hash, nxt_mp_t *mp,
105417Svbart@nginx.com     nxt_http_field_proc_t items[], nxt_uint_t count, nxt_bool_t level);
106417Svbart@nginx.com nxt_int_t nxt_http_fields_process(nxt_list_t *fields, nxt_lvlhsh_t *hash,
107417Svbart@nginx.com     void *ctx);
10816Svbart@nginx.com 
10916Svbart@nginx.com 
11016Svbart@nginx.com #endif /* _NXT_HTTP_PARSER_H_INCLUDED_ */
111