xref: /unit/src/nxt_upstream_source.h (revision 0:a63ceefd6ab0)
1 
2 /*
3  * Copyright (C) Igor Sysoev
4  * Copyright (C) NGINX, Inc.
5  */
6 
7 #ifndef _NXT_UPSTREAM_SOURCE_H_INCLUDED_
8 #define _NXT_UPSTREAM_SOURCE_H_INCLUDED_
9 
10 
11 typedef struct {
12     uint32_t                           hash;
13 
14     unsigned                           value_len:23;
15     unsigned                           skip:1;
16     unsigned                           name_len:8;
17 
18     u_char                             *value_start;
19     u_char                             *name_start;
20 } nxt_name_value_t;
21 
22 
23 typedef struct {
24     nxt_list_t                         *list;
25     nxt_lvlhsh_t                       hash;
26 
27     uint16_t                           status;    /* 16 bits */
28 
29     nxt_off_t                          content_length;
30 } nxt_upstream_header_in_t;
31 
32 
33 typedef nxt_int_t (*nxt_upstream_name_value_handler_t)(
34     nxt_upstream_source_t *us, nxt_name_value_t *nv);
35 
36 
37 typedef struct {
38     nxt_upstream_name_value_handler_t  handler;
39 
40     uint8_t                            len;
41     /*
42      * A name is inlined to test it with one memory access.
43      * The struct size is aligned to 32 bytes.
44      */
45 #if (NXT_64BIT)
46     u_char                             name[23];
47 #else
48     u_char                             name[27];
49 #endif
50 } nxt_upstream_name_value_t;
51 
52 
53 struct nxt_upstream_source_s {
54     nxt_upstream_peer_t                *peer;
55 
56     const nxt_upstream_state_t         *state;
57 
58     void                               *protocol_source;
59     void                               *data;
60     nxt_work_queue_t                   *work_queue;
61 
62     nxt_buf_pool_t                     buffers;
63 
64     nxt_lvlhsh_t                       header_hash;
65     nxt_stream_source_t                *stream;
66 };
67 
68 
69 #define NXT_UPSTREAM_NAME_VALUE_MIN_SIZE                                      \
70     offsetof(nxt_http_upstream_header_t, name)
71 
72 #define nxt_upstream_name_value(s)   sizeof(s) - 1, s
73 
74 
75 NXT_EXPORT nxt_int_t nxt_upstream_header_hash_add(nxt_mem_pool_t *mp,
76     nxt_lvlhsh_t *lh, const nxt_upstream_name_value_t *unv, nxt_uint_t n);
77 NXT_EXPORT nxt_int_t nxt_upstream_name_value_ignore(nxt_upstream_source_t *us,
78     nxt_name_value_t *nv);
79 
80 NXT_EXPORT extern const nxt_lvlhsh_proto_t  nxt_upstream_header_hash_proto;
81 
82 
83 #endif /* _NXT_UPSTREAM_SOURCE_H_INCLUDED_ */
84