xref: /unit/src/nxt_http_parse.h (revision 112)
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;
1267Svbart@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 {
1767Svbart@nginx.com    u_char                     str[8];
1867Svbart@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 {
2367Svbart@nginx.com     nxt_int_t                 (*handler)(nxt_http_request_parse_t *rp,
2467Svbart@nginx.com                                          u_char **pos, u_char *end);
2567Svbart@nginx.com 
2667Svbart@nginx.com     size_t                    offset;
2716Svbart@nginx.com 
2867Svbart@nginx.com     nxt_str_t                 method;
2916Svbart@nginx.com 
3067Svbart@nginx.com     u_char                    *target_start;
3167Svbart@nginx.com     u_char                    *target_end;
3267Svbart@nginx.com     u_char                    *exten_start;
3367Svbart@nginx.com     u_char                    *args_start;
3416Svbart@nginx.com 
35*112Smax.romanov@nginx.com     nxt_str_t                 path;
36*112Smax.romanov@nginx.com     nxt_str_t                 args;
37*112Smax.romanov@nginx.com     nxt_str_t                 exten;
38*112Smax.romanov@nginx.com 
3967Svbart@nginx.com     nxt_http_ver_t            version;
4067Svbart@nginx.com 
4167Svbart@nginx.com     union {
4267Svbart@nginx.com         uint8_t               str[32];
4367Svbart@nginx.com         uint64_t              ui64[4];
4467Svbart@nginx.com     } field_key;
4516Svbart@nginx.com 
4667Svbart@nginx.com     nxt_str_t                 field_name;
4767Svbart@nginx.com     nxt_str_t                 field_value;
4816Svbart@nginx.com 
4967Svbart@nginx.com     nxt_http_fields_hash_t    *fields_hash;
5067Svbart@nginx.com 
5167Svbart@nginx.com     nxt_list_t                *fields;
52*112Smax.romanov@nginx.com     nxt_mp_t                  *mem_pool;
5316Svbart@nginx.com 
5416Svbart@nginx.com     /* target with "/." */
5567Svbart@nginx.com     unsigned                  complex_target:1;
5616Svbart@nginx.com     /* target with "%" */
5767Svbart@nginx.com     unsigned                  quoted_target:1;
5816Svbart@nginx.com     /* target with " " */
5967Svbart@nginx.com     unsigned                  space_in_target:1;
6016Svbart@nginx.com     /* target with "+" */
6167Svbart@nginx.com     unsigned                  plus_in_target:1;
6216Svbart@nginx.com };
6316Svbart@nginx.com 
6416Svbart@nginx.com 
6560Svbart@nginx.com typedef nxt_int_t (*nxt_http_field_handler_t)(void *ctx,
6660Svbart@nginx.com                                               nxt_http_field_t *field,
6767Svbart@nginx.com                                               nxt_log_t *log);
6860Svbart@nginx.com 
6960Svbart@nginx.com 
7016Svbart@nginx.com typedef struct {
7116Svbart@nginx.com     nxt_str_t                 name;
7216Svbart@nginx.com     nxt_http_field_handler_t  handler;
7316Svbart@nginx.com     uintptr_t                 data;
7460Svbart@nginx.com } nxt_http_fields_hash_entry_t;
7560Svbart@nginx.com 
7660Svbart@nginx.com 
7767Svbart@nginx.com struct nxt_http_field_s {
7867Svbart@nginx.com     nxt_str_t                 name;
7967Svbart@nginx.com     nxt_str_t                 value;
8067Svbart@nginx.com     nxt_http_field_handler_t  handler;
8167Svbart@nginx.com     uintptr_t                 data;
8267Svbart@nginx.com };
8367Svbart@nginx.com 
8467Svbart@nginx.com 
8560Svbart@nginx.com nxt_inline nxt_int_t
8665Sigor@sysoev.ru nxt_http_parse_request_init(nxt_http_request_parse_t *rp, nxt_mp_t *mp)
8760Svbart@nginx.com {
88*112Smax.romanov@nginx.com     rp->mem_pool = mp;
89*112Smax.romanov@nginx.com 
9060Svbart@nginx.com     rp->fields = nxt_list_create(mp, 8, sizeof(nxt_http_field_t));
9160Svbart@nginx.com     if (nxt_slow_path(rp->fields == NULL)){
9260Svbart@nginx.com         return NXT_ERROR;
9360Svbart@nginx.com     }
9460Svbart@nginx.com 
9560Svbart@nginx.com     return NXT_OK;
9660Svbart@nginx.com }
9716Svbart@nginx.com 
9816Svbart@nginx.com 
9916Svbart@nginx.com nxt_int_t nxt_http_parse_request(nxt_http_request_parse_t *rp,
10016Svbart@nginx.com     nxt_buf_mem_t *b);
10160Svbart@nginx.com 
10260Svbart@nginx.com nxt_http_fields_hash_t *nxt_http_fields_hash_create(
10365Sigor@sysoev.ru     nxt_http_fields_hash_entry_t *entries, nxt_mp_t *mp);
10467Svbart@nginx.com nxt_int_t nxt_http_fields_process(nxt_list_t *fields, void *ctx,
10567Svbart@nginx.com                                   nxt_log_t *log);
10616Svbart@nginx.com 
10716Svbart@nginx.com 
10816Svbart@nginx.com #endif /* _NXT_HTTP_PARSER_H_INCLUDED_ */
109