xref: /unit/src/nxt_http_parse.h (revision 67)
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 
1116Svbart@nginx.com typedef struct nxt_http_request_parse_s  nxt_http_request_parse_t;
12*67Svbart@nginx.com typedef struct nxt_http_field_s          nxt_http_field_t;
1316Svbart@nginx.com typedef struct nxt_http_fields_hash_s    nxt_http_fields_hash_t;
1416Svbart@nginx.com 
1560Svbart@nginx.com 
1660Svbart@nginx.com typedef union {
17*67Svbart@nginx.com    u_char                     str[8];
18*67Svbart@nginx.com    uint64_t                   ui64;
1960Svbart@nginx.com } nxt_http_ver_t;
2016Svbart@nginx.com 
2116Svbart@nginx.com 
2216Svbart@nginx.com struct nxt_http_request_parse_s {
23*67Svbart@nginx.com     nxt_int_t                 (*handler)(nxt_http_request_parse_t *rp,
24*67Svbart@nginx.com                                          u_char **pos, u_char *end);
25*67Svbart@nginx.com 
26*67Svbart@nginx.com     size_t                    offset;
2716Svbart@nginx.com 
28*67Svbart@nginx.com     nxt_str_t                 method;
2916Svbart@nginx.com 
30*67Svbart@nginx.com     u_char                    *target_start;
31*67Svbart@nginx.com     u_char                    *target_end;
32*67Svbart@nginx.com     u_char                    *exten_start;
33*67Svbart@nginx.com     u_char                    *args_start;
3416Svbart@nginx.com 
35*67Svbart@nginx.com     nxt_http_ver_t            version;
36*67Svbart@nginx.com 
37*67Svbart@nginx.com     union {
38*67Svbart@nginx.com         uint8_t               str[32];
39*67Svbart@nginx.com         uint64_t              ui64[4];
40*67Svbart@nginx.com     } field_key;
4116Svbart@nginx.com 
42*67Svbart@nginx.com     nxt_str_t                 field_name;
43*67Svbart@nginx.com     nxt_str_t                 field_value;
4416Svbart@nginx.com 
45*67Svbart@nginx.com     nxt_http_fields_hash_t    *fields_hash;
46*67Svbart@nginx.com 
47*67Svbart@nginx.com     nxt_list_t                *fields;
4816Svbart@nginx.com 
4916Svbart@nginx.com     /* target with "/." */
50*67Svbart@nginx.com     unsigned                  complex_target:1;
5116Svbart@nginx.com     /* target with "%" */
52*67Svbart@nginx.com     unsigned                  quoted_target:1;
5316Svbart@nginx.com     /* target with " " */
54*67Svbart@nginx.com     unsigned                  space_in_target:1;
5516Svbart@nginx.com     /* target with "+" */
56*67Svbart@nginx.com     unsigned                  plus_in_target:1;
5716Svbart@nginx.com };
5816Svbart@nginx.com 
5916Svbart@nginx.com 
6060Svbart@nginx.com typedef nxt_int_t (*nxt_http_field_handler_t)(void *ctx,
6160Svbart@nginx.com                                               nxt_http_field_t *field,
62*67Svbart@nginx.com                                               nxt_log_t *log);
6360Svbart@nginx.com 
6460Svbart@nginx.com 
6516Svbart@nginx.com typedef struct {
6616Svbart@nginx.com     nxt_str_t                 name;
6716Svbart@nginx.com     nxt_http_field_handler_t  handler;
6816Svbart@nginx.com     uintptr_t                 data;
6960Svbart@nginx.com } nxt_http_fields_hash_entry_t;
7060Svbart@nginx.com 
7160Svbart@nginx.com 
72*67Svbart@nginx.com struct nxt_http_field_s {
73*67Svbart@nginx.com     nxt_str_t                 name;
74*67Svbart@nginx.com     nxt_str_t                 value;
75*67Svbart@nginx.com     nxt_http_field_handler_t  handler;
76*67Svbart@nginx.com     uintptr_t                 data;
77*67Svbart@nginx.com };
78*67Svbart@nginx.com 
79*67Svbart@nginx.com 
8060Svbart@nginx.com nxt_inline nxt_int_t
8165Sigor@sysoev.ru nxt_http_parse_request_init(nxt_http_request_parse_t *rp, nxt_mp_t *mp)
8260Svbart@nginx.com {
8360Svbart@nginx.com     rp->fields = nxt_list_create(mp, 8, sizeof(nxt_http_field_t));
8460Svbart@nginx.com     if (nxt_slow_path(rp->fields == NULL)){
8560Svbart@nginx.com         return NXT_ERROR;
8660Svbart@nginx.com     }
8760Svbart@nginx.com 
8860Svbart@nginx.com     return NXT_OK;
8960Svbart@nginx.com }
9016Svbart@nginx.com 
9116Svbart@nginx.com 
9216Svbart@nginx.com nxt_int_t nxt_http_parse_request(nxt_http_request_parse_t *rp,
9316Svbart@nginx.com     nxt_buf_mem_t *b);
9460Svbart@nginx.com 
9560Svbart@nginx.com nxt_http_fields_hash_t *nxt_http_fields_hash_create(
9665Sigor@sysoev.ru     nxt_http_fields_hash_entry_t *entries, nxt_mp_t *mp);
97*67Svbart@nginx.com nxt_int_t nxt_http_fields_process(nxt_list_t *fields, void *ctx,
98*67Svbart@nginx.com                                   nxt_log_t *log);
9916Svbart@nginx.com 
10016Svbart@nginx.com 
10116Svbart@nginx.com #endif /* _NXT_HTTP_PARSER_H_INCLUDED_ */
102