1
2 /*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) NGINX, Inc.
5 */
6
7 #include <nxt_main.h>
8
9
10 static nxt_int_t nxt_upstream_header_hash_test(nxt_lvlhsh_query_t *lhq,
11 void *data);
12
13
14 const nxt_lvlhsh_proto_t nxt_upstream_header_hash_proto nxt_aligned(64) = {
15 NXT_LVLHSH_DEFAULT,
16 0,
17 nxt_upstream_header_hash_test,
18 nxt_mem_lvlhsh_alloc,
19 nxt_mem_lvlhsh_free,
20 };
21
22
23 nxt_int_t
nxt_upstream_header_hash_add(nxt_mp_t * mp,nxt_lvlhsh_t * lh,const nxt_upstream_name_value_t * unv,nxt_uint_t n)24 nxt_upstream_header_hash_add(nxt_mp_t *mp, nxt_lvlhsh_t *lh,
25 const nxt_upstream_name_value_t *unv, nxt_uint_t n)
26 {
27 nxt_lvlhsh_query_t lhq;
28
29 while (n != 0) {
30 lhq.key_hash = nxt_djb_hash(unv->name, unv->len);
31 lhq.replace = 1;
32 lhq.key.len = unv->len;
33 lhq.key.data = (u_char *) unv->name;
34 lhq.value = (void *) unv;
35 lhq.proto = &nxt_upstream_header_hash_proto;
36 lhq.pool = mp;
37
38 if (nxt_lvlhsh_insert(lh, &lhq) != NXT_OK) {
39 return NXT_ERROR;
40 }
41
42 unv++;
43 n--;
44 }
45
46 return NXT_OK;
47 }
48
49
50 static nxt_int_t
nxt_upstream_header_hash_test(nxt_lvlhsh_query_t * lhq,void * data)51 nxt_upstream_header_hash_test(nxt_lvlhsh_query_t *lhq, void *data)
52 {
53 nxt_upstream_name_value_t *unv;
54
55 unv = data;
56
57 if (lhq->key.len == unv->len
58 && nxt_memcasecmp(lhq->key.data, unv->name, unv->len) == 0)
59 {
60 return NXT_OK;
61 }
62
63 return NXT_DECLINED;
64 }
65
66
67 nxt_int_t
nxt_upstream_name_value_ignore(nxt_upstream_source_t * us,nxt_name_value_t * nv)68 nxt_upstream_name_value_ignore(nxt_upstream_source_t *us, nxt_name_value_t *nv)
69 {
70 return NXT_OK;
71 }
72