xref: /unit/src/nxt_http_parse.h (revision 60)
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;
1216Svbart@nginx.com typedef struct nxt_http_fields_hash_s    nxt_http_fields_hash_t;
1316Svbart@nginx.com 
14*60Svbart@nginx.com 
15*60Svbart@nginx.com typedef union {
16*60Svbart@nginx.com    u_char             str[8];
17*60Svbart@nginx.com    uint64_t           ui64;
18*60Svbart@nginx.com } nxt_http_ver_t;
1916Svbart@nginx.com 
2016Svbart@nginx.com 
21*60Svbart@nginx.com typedef struct {
22*60Svbart@nginx.com     union {
23*60Svbart@nginx.com         uint8_t       str[32];
24*60Svbart@nginx.com         uint64_t      ui64[4];
25*60Svbart@nginx.com     } key;
26*60Svbart@nginx.com 
27*60Svbart@nginx.com     nxt_str_t         name;
28*60Svbart@nginx.com     nxt_str_t         value;
29*60Svbart@nginx.com } nxt_http_field_t;
3016Svbart@nginx.com 
3116Svbart@nginx.com 
3216Svbart@nginx.com struct nxt_http_request_parse_s {
33*60Svbart@nginx.com     nxt_int_t         (*handler)(nxt_http_request_parse_t *rp,
34*60Svbart@nginx.com                                  u_char **pos, u_char *end);
3516Svbart@nginx.com 
36*60Svbart@nginx.com     size_t            offset;
3716Svbart@nginx.com 
38*60Svbart@nginx.com     nxt_str_t         method;
3916Svbart@nginx.com 
40*60Svbart@nginx.com     u_char            *target_start;
41*60Svbart@nginx.com     u_char            *target_end;
42*60Svbart@nginx.com     u_char            *exten_start;
43*60Svbart@nginx.com     u_char            *args_start;
4416Svbart@nginx.com 
45*60Svbart@nginx.com     nxt_http_ver_t    version;
4616Svbart@nginx.com 
47*60Svbart@nginx.com     nxt_http_field_t  field;
48*60Svbart@nginx.com     nxt_list_t        *fields;
4916Svbart@nginx.com 
5016Svbart@nginx.com     /* target with "/." */
51*60Svbart@nginx.com     unsigned          complex_target:1;
5216Svbart@nginx.com     /* target with "%" */
53*60Svbart@nginx.com     unsigned          quoted_target:1;
5416Svbart@nginx.com     /* target with " " */
55*60Svbart@nginx.com     unsigned          space_in_target:1;
5616Svbart@nginx.com     /* target with "+" */
57*60Svbart@nginx.com     unsigned          plus_in_target:1;
5816Svbart@nginx.com };
5916Svbart@nginx.com 
6016Svbart@nginx.com 
61*60Svbart@nginx.com typedef nxt_int_t (*nxt_http_field_handler_t)(void *ctx,
62*60Svbart@nginx.com                                               nxt_http_field_t *field,
63*60Svbart@nginx.com                                               uintptr_t data, nxt_log_t *log);
64*60Svbart@nginx.com 
65*60Svbart@nginx.com 
6616Svbart@nginx.com typedef struct {
6716Svbart@nginx.com     nxt_str_t                 name;
6816Svbart@nginx.com     nxt_http_field_handler_t  handler;
6916Svbart@nginx.com     uintptr_t                 data;
70*60Svbart@nginx.com } nxt_http_fields_hash_entry_t;
71*60Svbart@nginx.com 
72*60Svbart@nginx.com 
73*60Svbart@nginx.com nxt_inline nxt_int_t
74*60Svbart@nginx.com nxt_http_parse_request_init(nxt_http_request_parse_t *rp, nxt_mem_pool_t *mp)
75*60Svbart@nginx.com {
76*60Svbart@nginx.com     rp->fields = nxt_list_create(mp, 8, sizeof(nxt_http_field_t));
77*60Svbart@nginx.com     if (nxt_slow_path(rp->fields == NULL)){
78*60Svbart@nginx.com         return NXT_ERROR;
79*60Svbart@nginx.com     }
80*60Svbart@nginx.com 
81*60Svbart@nginx.com     return NXT_OK;
82*60Svbart@nginx.com }
8316Svbart@nginx.com 
8416Svbart@nginx.com 
8516Svbart@nginx.com nxt_int_t nxt_http_parse_request(nxt_http_request_parse_t *rp,
8616Svbart@nginx.com     nxt_buf_mem_t *b);
87*60Svbart@nginx.com 
88*60Svbart@nginx.com nxt_http_fields_hash_t *nxt_http_fields_hash_create(
89*60Svbart@nginx.com     nxt_http_fields_hash_entry_t *entries, nxt_mem_pool_t *mp);
90*60Svbart@nginx.com nxt_http_fields_hash_entry_t *nxt_http_fields_hash_lookup(
91*60Svbart@nginx.com     nxt_http_fields_hash_t *hash, nxt_http_field_t *field);
92*60Svbart@nginx.com 
93*60Svbart@nginx.com nxt_int_t nxt_http_fields_process(nxt_list_t *fields,
94*60Svbart@nginx.com     nxt_http_fields_hash_t *hash, void *ctx, nxt_log_t *log);
9516Svbart@nginx.com 
9616Svbart@nginx.com 
9716Svbart@nginx.com #endif /* _NXT_HTTP_PARSER_H_INCLUDED_ */
98