Mercurial > hg > nginx-quic
annotate src/stream/ngx_stream_variables.c @ 7107:d4b031cf32cf
HTTP/2: fixed debug log about indexed headers.
Previously, "get indexed header" message was logged when in fact only
header name was obtained using an index, and "get indexed header name"
was logged when full header representation (name and value) was obtained
using an index. Fixed version logs "get indexed name" and "get indexed
header" respectively.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 14 Sep 2017 19:06:05 +0300 |
parents | 2a288909abc6 |
children | 6d1f3bb72b07 |
rev | line source |
---|---|
6607 | 1 |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4 * Copyright (C) Nginx, Inc. | |
5 */ | |
6 | |
7 | |
8 #include <ngx_config.h> | |
9 #include <ngx_core.h> | |
10 #include <ngx_stream.h> | |
11 #include <nginx.h> | |
12 | |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
13 static ngx_stream_variable_t *ngx_stream_add_prefix_variable(ngx_conf_t *cf, |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
14 ngx_str_t *name, ngx_uint_t flags); |
6607 | 15 |
6608
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
16 static ngx_int_t ngx_stream_variable_binary_remote_addr( |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
17 ngx_stream_session_t *s, ngx_stream_variable_value_t *v, uintptr_t data); |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
18 static ngx_int_t ngx_stream_variable_remote_addr(ngx_stream_session_t *s, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
19 ngx_stream_variable_value_t *v, uintptr_t data); |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
20 static ngx_int_t ngx_stream_variable_remote_port(ngx_stream_session_t *s, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
21 ngx_stream_variable_value_t *v, uintptr_t data); |
6681
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
22 static ngx_int_t ngx_stream_variable_proxy_protocol_addr( |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
23 ngx_stream_session_t *s, ngx_stream_variable_value_t *v, uintptr_t data); |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
24 static ngx_int_t ngx_stream_variable_proxy_protocol_port( |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
25 ngx_stream_session_t *s, ngx_stream_variable_value_t *v, uintptr_t data); |
6608
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
26 static ngx_int_t ngx_stream_variable_server_addr(ngx_stream_session_t *s, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
27 ngx_stream_variable_value_t *v, uintptr_t data); |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
28 static ngx_int_t ngx_stream_variable_server_port(ngx_stream_session_t *s, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
29 ngx_stream_variable_value_t *v, uintptr_t data); |
6668
5e2821c2de46
Stream: the $bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6608
diff
changeset
|
30 static ngx_int_t ngx_stream_variable_bytes(ngx_stream_session_t *s, |
6608
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
31 ngx_stream_variable_value_t *v, uintptr_t data); |
6669
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
32 static ngx_int_t ngx_stream_variable_session_time(ngx_stream_session_t *s, |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
33 ngx_stream_variable_value_t *v, uintptr_t data); |
6674
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6670
diff
changeset
|
34 static ngx_int_t ngx_stream_variable_status(ngx_stream_session_t *s, |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6670
diff
changeset
|
35 ngx_stream_variable_value_t *v, uintptr_t data); |
6608
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
36 static ngx_int_t ngx_stream_variable_connection(ngx_stream_session_t *s, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
37 ngx_stream_variable_value_t *v, uintptr_t data); |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
38 |
6607 | 39 static ngx_int_t ngx_stream_variable_nginx_version(ngx_stream_session_t *s, |
40 ngx_stream_variable_value_t *v, uintptr_t data); | |
6608
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
41 static ngx_int_t ngx_stream_variable_hostname(ngx_stream_session_t *s, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
42 ngx_stream_variable_value_t *v, uintptr_t data); |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
43 static ngx_int_t ngx_stream_variable_pid(ngx_stream_session_t *s, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
44 ngx_stream_variable_value_t *v, uintptr_t data); |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
45 static ngx_int_t ngx_stream_variable_msec(ngx_stream_session_t *s, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
46 ngx_stream_variable_value_t *v, uintptr_t data); |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
47 static ngx_int_t ngx_stream_variable_time_iso8601(ngx_stream_session_t *s, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
48 ngx_stream_variable_value_t *v, uintptr_t data); |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
49 static ngx_int_t ngx_stream_variable_time_local(ngx_stream_session_t *s, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
50 ngx_stream_variable_value_t *v, uintptr_t data); |
6670
c6372a40c2a7
Stream: the $protocol variable.
Vladimir Homutov <vl@nginx.com>
parents:
6669
diff
changeset
|
51 static ngx_int_t ngx_stream_variable_protocol(ngx_stream_session_t *s, |
c6372a40c2a7
Stream: the $protocol variable.
Vladimir Homutov <vl@nginx.com>
parents:
6669
diff
changeset
|
52 ngx_stream_variable_value_t *v, uintptr_t data); |
6607 | 53 |
54 | |
55 static ngx_stream_variable_t ngx_stream_core_variables[] = { | |
56 | |
6608
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
57 { ngx_string("binary_remote_addr"), NULL, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
58 ngx_stream_variable_binary_remote_addr, 0, 0, 0 }, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
59 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
60 { ngx_string("remote_addr"), NULL, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
61 ngx_stream_variable_remote_addr, 0, 0, 0 }, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
62 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
63 { ngx_string("remote_port"), NULL, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
64 ngx_stream_variable_remote_port, 0, 0, 0 }, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
65 |
6681
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
66 { ngx_string("proxy_protocol_addr"), NULL, |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
67 ngx_stream_variable_proxy_protocol_addr, 0, 0, 0 }, |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
68 |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
69 { ngx_string("proxy_protocol_port"), NULL, |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
70 ngx_stream_variable_proxy_protocol_port, 0, 0, 0 }, |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
71 |
6608
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
72 { ngx_string("server_addr"), NULL, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
73 ngx_stream_variable_server_addr, 0, 0, 0 }, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
74 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
75 { ngx_string("server_port"), NULL, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
76 ngx_stream_variable_server_port, 0, 0, 0 }, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
77 |
6668
5e2821c2de46
Stream: the $bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6608
diff
changeset
|
78 { ngx_string("bytes_sent"), NULL, ngx_stream_variable_bytes, |
6608
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
79 0, 0, 0 }, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
80 |
6668
5e2821c2de46
Stream: the $bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6608
diff
changeset
|
81 { ngx_string("bytes_received"), NULL, ngx_stream_variable_bytes, |
5e2821c2de46
Stream: the $bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6608
diff
changeset
|
82 1, 0, 0 }, |
5e2821c2de46
Stream: the $bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6608
diff
changeset
|
83 |
6669
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
84 { ngx_string("session_time"), NULL, ngx_stream_variable_session_time, |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
85 0, NGX_STREAM_VAR_NOCACHEABLE, 0 }, |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
86 |
6674
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6670
diff
changeset
|
87 { ngx_string("status"), NULL, ngx_stream_variable_status, |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6670
diff
changeset
|
88 0, NGX_STREAM_VAR_NOCACHEABLE, 0 }, |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6670
diff
changeset
|
89 |
6608
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
90 { ngx_string("connection"), NULL, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
91 ngx_stream_variable_connection, 0, 0, 0 }, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
92 |
6607 | 93 { ngx_string("nginx_version"), NULL, ngx_stream_variable_nginx_version, |
94 0, 0, 0 }, | |
95 | |
6608
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
96 { ngx_string("hostname"), NULL, ngx_stream_variable_hostname, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
97 0, 0, 0 }, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
98 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
99 { ngx_string("pid"), NULL, ngx_stream_variable_pid, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
100 0, 0, 0 }, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
101 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
102 { ngx_string("msec"), NULL, ngx_stream_variable_msec, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
103 0, NGX_STREAM_VAR_NOCACHEABLE, 0 }, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
104 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
105 { ngx_string("time_iso8601"), NULL, ngx_stream_variable_time_iso8601, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
106 0, NGX_STREAM_VAR_NOCACHEABLE, 0 }, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
107 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
108 { ngx_string("time_local"), NULL, ngx_stream_variable_time_local, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
109 0, NGX_STREAM_VAR_NOCACHEABLE, 0 }, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
110 |
6670
c6372a40c2a7
Stream: the $protocol variable.
Vladimir Homutov <vl@nginx.com>
parents:
6669
diff
changeset
|
111 { ngx_string("protocol"), NULL, |
c6372a40c2a7
Stream: the $protocol variable.
Vladimir Homutov <vl@nginx.com>
parents:
6669
diff
changeset
|
112 ngx_stream_variable_protocol, 0, 0, 0 }, |
c6372a40c2a7
Stream: the $protocol variable.
Vladimir Homutov <vl@nginx.com>
parents:
6669
diff
changeset
|
113 |
7077
2a288909abc6
Variables: macros for null variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6899
diff
changeset
|
114 ngx_stream_null_variable |
6607 | 115 }; |
116 | |
117 | |
118 ngx_stream_variable_value_t ngx_stream_variable_null_value = | |
119 ngx_stream_variable(""); | |
120 ngx_stream_variable_value_t ngx_stream_variable_true_value = | |
121 ngx_stream_variable("1"); | |
122 | |
123 | |
6851
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
124 static ngx_uint_t ngx_stream_variable_depth = 100; |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
125 |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
126 |
6607 | 127 ngx_stream_variable_t * |
128 ngx_stream_add_variable(ngx_conf_t *cf, ngx_str_t *name, ngx_uint_t flags) | |
129 { | |
130 ngx_int_t rc; | |
131 ngx_uint_t i; | |
132 ngx_hash_key_t *key; | |
133 ngx_stream_variable_t *v; | |
134 ngx_stream_core_main_conf_t *cmcf; | |
135 | |
136 if (name->len == 0) { | |
137 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
138 "invalid variable name \"$\""); | |
139 return NULL; | |
140 } | |
141 | |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
142 if (flags & NGX_STREAM_VAR_PREFIX) { |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
143 return ngx_stream_add_prefix_variable(cf, name, flags); |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
144 } |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
145 |
6607 | 146 cmcf = ngx_stream_conf_get_module_main_conf(cf, ngx_stream_core_module); |
147 | |
148 key = cmcf->variables_keys->keys.elts; | |
149 for (i = 0; i < cmcf->variables_keys->keys.nelts; i++) { | |
150 if (name->len != key[i].key.len | |
151 || ngx_strncasecmp(name->data, key[i].key.data, name->len) != 0) | |
152 { | |
153 continue; | |
154 } | |
155 | |
156 v = key[i].value; | |
157 | |
158 if (!(v->flags & NGX_STREAM_VAR_CHANGEABLE)) { | |
159 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
160 "the duplicate \"%V\" variable", name); | |
161 return NULL; | |
162 } | |
163 | |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
164 v->flags &= flags | ~NGX_STREAM_VAR_WEAK; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
165 |
6607 | 166 return v; |
167 } | |
168 | |
169 v = ngx_palloc(cf->pool, sizeof(ngx_stream_variable_t)); | |
170 if (v == NULL) { | |
171 return NULL; | |
172 } | |
173 | |
174 v->name.len = name->len; | |
175 v->name.data = ngx_pnalloc(cf->pool, name->len); | |
176 if (v->name.data == NULL) { | |
177 return NULL; | |
178 } | |
179 | |
180 ngx_strlow(v->name.data, name->data, name->len); | |
181 | |
182 v->set_handler = NULL; | |
183 v->get_handler = NULL; | |
184 v->data = 0; | |
185 v->flags = flags; | |
186 v->index = 0; | |
187 | |
188 rc = ngx_hash_add_key(cmcf->variables_keys, &v->name, v, 0); | |
189 | |
190 if (rc == NGX_ERROR) { | |
191 return NULL; | |
192 } | |
193 | |
194 if (rc == NGX_BUSY) { | |
195 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
196 "conflicting variable name \"%V\"", name); | |
197 return NULL; | |
198 } | |
199 | |
200 return v; | |
201 } | |
202 | |
203 | |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
204 static ngx_stream_variable_t * |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
205 ngx_stream_add_prefix_variable(ngx_conf_t *cf, ngx_str_t *name, |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
206 ngx_uint_t flags) |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
207 { |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
208 ngx_uint_t i; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
209 ngx_stream_variable_t *v; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
210 ngx_stream_core_main_conf_t *cmcf; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
211 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
212 cmcf = ngx_stream_conf_get_module_main_conf(cf, ngx_stream_core_module); |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
213 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
214 v = cmcf->prefix_variables.elts; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
215 for (i = 0; i < cmcf->prefix_variables.nelts; i++) { |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
216 if (name->len != v[i].name.len |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
217 || ngx_strncasecmp(name->data, v[i].name.data, name->len) != 0) |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
218 { |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
219 continue; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
220 } |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
221 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
222 v = &v[i]; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
223 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
224 if (!(v->flags & NGX_STREAM_VAR_CHANGEABLE)) { |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
225 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
226 "the duplicate \"%V\" variable", name); |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
227 return NULL; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
228 } |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
229 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
230 v->flags &= flags | ~NGX_STREAM_VAR_WEAK; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
231 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
232 return v; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
233 } |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
234 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
235 v = ngx_array_push(&cmcf->prefix_variables); |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
236 if (v == NULL) { |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
237 return NULL; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
238 } |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
239 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
240 v->name.len = name->len; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
241 v->name.data = ngx_pnalloc(cf->pool, name->len); |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
242 if (v->name.data == NULL) { |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
243 return NULL; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
244 } |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
245 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
246 ngx_strlow(v->name.data, name->data, name->len); |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
247 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
248 v->set_handler = NULL; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
249 v->get_handler = NULL; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
250 v->data = 0; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
251 v->flags = flags; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
252 v->index = 0; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
253 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
254 return v; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
255 } |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
256 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
257 |
6607 | 258 ngx_int_t |
259 ngx_stream_get_variable_index(ngx_conf_t *cf, ngx_str_t *name) | |
260 { | |
261 ngx_uint_t i; | |
262 ngx_stream_variable_t *v; | |
263 ngx_stream_core_main_conf_t *cmcf; | |
264 | |
265 if (name->len == 0) { | |
266 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
267 "invalid variable name \"$\""); | |
268 return NGX_ERROR; | |
269 } | |
270 | |
271 cmcf = ngx_stream_conf_get_module_main_conf(cf, ngx_stream_core_module); | |
272 | |
273 v = cmcf->variables.elts; | |
274 | |
275 if (v == NULL) { | |
276 if (ngx_array_init(&cmcf->variables, cf->pool, 4, | |
277 sizeof(ngx_stream_variable_t)) | |
278 != NGX_OK) | |
279 { | |
280 return NGX_ERROR; | |
281 } | |
282 | |
283 } else { | |
284 for (i = 0; i < cmcf->variables.nelts; i++) { | |
285 if (name->len != v[i].name.len | |
286 || ngx_strncasecmp(name->data, v[i].name.data, name->len) != 0) | |
287 { | |
288 continue; | |
289 } | |
290 | |
291 return i; | |
292 } | |
293 } | |
294 | |
295 v = ngx_array_push(&cmcf->variables); | |
296 if (v == NULL) { | |
297 return NGX_ERROR; | |
298 } | |
299 | |
300 v->name.len = name->len; | |
301 v->name.data = ngx_pnalloc(cf->pool, name->len); | |
302 if (v->name.data == NULL) { | |
303 return NGX_ERROR; | |
304 } | |
305 | |
306 ngx_strlow(v->name.data, name->data, name->len); | |
307 | |
308 v->set_handler = NULL; | |
309 v->get_handler = NULL; | |
310 v->data = 0; | |
311 v->flags = 0; | |
312 v->index = cmcf->variables.nelts - 1; | |
313 | |
314 return v->index; | |
315 } | |
316 | |
317 | |
318 ngx_stream_variable_value_t * | |
319 ngx_stream_get_indexed_variable(ngx_stream_session_t *s, ngx_uint_t index) | |
320 { | |
321 ngx_stream_variable_t *v; | |
322 ngx_stream_core_main_conf_t *cmcf; | |
323 | |
324 cmcf = ngx_stream_get_module_main_conf(s, ngx_stream_core_module); | |
325 | |
326 if (cmcf->variables.nelts <= index) { | |
327 ngx_log_error(NGX_LOG_ALERT, s->connection->log, 0, | |
328 "unknown variable index: %ui", index); | |
329 return NULL; | |
330 } | |
331 | |
332 if (s->variables[index].not_found || s->variables[index].valid) { | |
333 return &s->variables[index]; | |
334 } | |
335 | |
336 v = cmcf->variables.elts; | |
337 | |
6851
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
338 if (ngx_stream_variable_depth == 0) { |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
339 ngx_log_error(NGX_LOG_ERR, s->connection->log, 0, |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
340 "cycle while evaluating variable \"%V\"", |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
341 &v[index].name); |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
342 return NULL; |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
343 } |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
344 |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
345 ngx_stream_variable_depth--; |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
346 |
6607 | 347 if (v[index].get_handler(s, &s->variables[index], v[index].data) |
348 == NGX_OK) | |
349 { | |
6851
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
350 ngx_stream_variable_depth++; |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
351 |
6607 | 352 if (v[index].flags & NGX_STREAM_VAR_NOCACHEABLE) { |
353 s->variables[index].no_cacheable = 1; | |
354 } | |
355 | |
356 return &s->variables[index]; | |
357 } | |
358 | |
6851
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
359 ngx_stream_variable_depth++; |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
360 |
6607 | 361 s->variables[index].valid = 0; |
362 s->variables[index].not_found = 1; | |
363 | |
364 return NULL; | |
365 } | |
366 | |
367 | |
368 ngx_stream_variable_value_t * | |
369 ngx_stream_get_flushed_variable(ngx_stream_session_t *s, ngx_uint_t index) | |
370 { | |
371 ngx_stream_variable_value_t *v; | |
372 | |
373 v = &s->variables[index]; | |
374 | |
375 if (v->valid || v->not_found) { | |
376 if (!v->no_cacheable) { | |
377 return v; | |
378 } | |
379 | |
380 v->valid = 0; | |
381 v->not_found = 0; | |
382 } | |
383 | |
384 return ngx_stream_get_indexed_variable(s, index); | |
385 } | |
386 | |
387 | |
388 ngx_stream_variable_value_t * | |
389 ngx_stream_get_variable(ngx_stream_session_t *s, ngx_str_t *name, | |
390 ngx_uint_t key) | |
391 { | |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
392 size_t len; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
393 ngx_uint_t i, n; |
6607 | 394 ngx_stream_variable_t *v; |
395 ngx_stream_variable_value_t *vv; | |
396 ngx_stream_core_main_conf_t *cmcf; | |
397 | |
398 cmcf = ngx_stream_get_module_main_conf(s, ngx_stream_core_module); | |
399 | |
400 v = ngx_hash_find(&cmcf->variables_hash, key, name->data, name->len); | |
401 | |
402 if (v) { | |
403 if (v->flags & NGX_STREAM_VAR_INDEXED) { | |
404 return ngx_stream_get_flushed_variable(s, v->index); | |
6851
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
405 } |
6607 | 406 |
6851
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
407 if (ngx_stream_variable_depth == 0) { |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
408 ngx_log_error(NGX_LOG_ERR, s->connection->log, 0, |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
409 "cycle while evaluating variable \"%V\"", name); |
6607 | 410 return NULL; |
411 } | |
6851
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
412 |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
413 ngx_stream_variable_depth--; |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
414 |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
415 vv = ngx_palloc(s->connection->pool, |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
416 sizeof(ngx_stream_variable_value_t)); |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
417 |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
418 if (vv && v->get_handler(s, vv, v->data) == NGX_OK) { |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
419 ngx_stream_variable_depth++; |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
420 return vv; |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
421 } |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
422 |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
423 ngx_stream_variable_depth++; |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
424 return NULL; |
6607 | 425 } |
426 | |
427 vv = ngx_palloc(s->connection->pool, sizeof(ngx_stream_variable_value_t)); | |
428 if (vv == NULL) { | |
429 return NULL; | |
430 } | |
431 | |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
432 len = 0; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
433 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
434 v = cmcf->prefix_variables.elts; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
435 n = cmcf->prefix_variables.nelts; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
436 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
437 for (i = 0; i < cmcf->prefix_variables.nelts; i++) { |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
438 if (name->len >= v[i].name.len && name->len > len |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
439 && ngx_strncmp(name->data, v[i].name.data, v[i].name.len) == 0) |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
440 { |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
441 len = v[i].name.len; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
442 n = i; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
443 } |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
444 } |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
445 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
446 if (n != cmcf->prefix_variables.nelts) { |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
447 if (v[n].get_handler(s, vv, (uintptr_t) name) == NGX_OK) { |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
448 return vv; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
449 } |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
450 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
451 return NULL; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
452 } |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
453 |
6607 | 454 vv->not_found = 1; |
455 | |
456 return vv; | |
457 } | |
458 | |
459 | |
460 static ngx_int_t | |
6608
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
461 ngx_stream_variable_binary_remote_addr(ngx_stream_session_t *s, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
462 ngx_stream_variable_value_t *v, uintptr_t data) |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
463 { |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
464 struct sockaddr_in *sin; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
465 #if (NGX_HAVE_INET6) |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
466 struct sockaddr_in6 *sin6; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
467 #endif |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
468 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
469 switch (s->connection->sockaddr->sa_family) { |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
470 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
471 #if (NGX_HAVE_INET6) |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
472 case AF_INET6: |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
473 sin6 = (struct sockaddr_in6 *) s->connection->sockaddr; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
474 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
475 v->len = sizeof(struct in6_addr); |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
476 v->valid = 1; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
477 v->no_cacheable = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
478 v->not_found = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
479 v->data = sin6->sin6_addr.s6_addr; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
480 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
481 break; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
482 #endif |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
483 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
484 default: /* AF_INET */ |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
485 sin = (struct sockaddr_in *) s->connection->sockaddr; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
486 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
487 v->len = sizeof(in_addr_t); |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
488 v->valid = 1; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
489 v->no_cacheable = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
490 v->not_found = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
491 v->data = (u_char *) &sin->sin_addr; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
492 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
493 break; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
494 } |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
495 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
496 return NGX_OK; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
497 } |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
498 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
499 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
500 static ngx_int_t |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
501 ngx_stream_variable_remote_addr(ngx_stream_session_t *s, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
502 ngx_stream_variable_value_t *v, uintptr_t data) |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
503 { |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
504 v->len = s->connection->addr_text.len; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
505 v->valid = 1; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
506 v->no_cacheable = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
507 v->not_found = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
508 v->data = s->connection->addr_text.data; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
509 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
510 return NGX_OK; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
511 } |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
512 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
513 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
514 static ngx_int_t |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
515 ngx_stream_variable_remote_port(ngx_stream_session_t *s, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
516 ngx_stream_variable_value_t *v, uintptr_t data) |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
517 { |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
518 ngx_uint_t port; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
519 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
520 v->len = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
521 v->valid = 1; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
522 v->no_cacheable = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
523 v->not_found = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
524 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
525 v->data = ngx_pnalloc(s->connection->pool, sizeof("65535") - 1); |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
526 if (v->data == NULL) { |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
527 return NGX_ERROR; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
528 } |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
529 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
530 port = ngx_inet_get_port(s->connection->sockaddr); |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
531 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
532 if (port > 0 && port < 65536) { |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
533 v->len = ngx_sprintf(v->data, "%ui", port) - v->data; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
534 } |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
535 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
536 return NGX_OK; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
537 } |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
538 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
539 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
540 static ngx_int_t |
6681
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
541 ngx_stream_variable_proxy_protocol_addr(ngx_stream_session_t *s, |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
542 ngx_stream_variable_value_t *v, uintptr_t data) |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
543 { |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
544 v->len = s->connection->proxy_protocol_addr.len; |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
545 v->valid = 1; |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
546 v->no_cacheable = 0; |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
547 v->not_found = 0; |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
548 v->data = s->connection->proxy_protocol_addr.data; |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
549 |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
550 return NGX_OK; |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
551 } |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
552 |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
553 |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
554 static ngx_int_t |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
555 ngx_stream_variable_proxy_protocol_port(ngx_stream_session_t *s, |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
556 ngx_stream_variable_value_t *v, uintptr_t data) |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
557 { |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
558 ngx_uint_t port; |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
559 |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
560 v->len = 0; |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
561 v->valid = 1; |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
562 v->no_cacheable = 0; |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
563 v->not_found = 0; |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
564 |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
565 v->data = ngx_pnalloc(s->connection->pool, sizeof("65535") - 1); |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
566 if (v->data == NULL) { |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
567 return NGX_ERROR; |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
568 } |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
569 |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
570 port = s->connection->proxy_protocol_port; |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
571 |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
572 if (port > 0 && port < 65536) { |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
573 v->len = ngx_sprintf(v->data, "%ui", port) - v->data; |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
574 } |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
575 |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
576 return NGX_OK; |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
577 } |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
578 |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
579 |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
580 static ngx_int_t |
6608
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
581 ngx_stream_variable_server_addr(ngx_stream_session_t *s, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
582 ngx_stream_variable_value_t *v, uintptr_t data) |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
583 { |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
584 ngx_str_t str; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
585 u_char addr[NGX_SOCKADDR_STRLEN]; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
586 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
587 str.len = NGX_SOCKADDR_STRLEN; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
588 str.data = addr; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
589 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
590 if (ngx_connection_local_sockaddr(s->connection, &str, 0) != NGX_OK) { |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
591 return NGX_ERROR; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
592 } |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
593 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
594 str.data = ngx_pnalloc(s->connection->pool, str.len); |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
595 if (str.data == NULL) { |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
596 return NGX_ERROR; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
597 } |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
598 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
599 ngx_memcpy(str.data, addr, str.len); |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
600 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
601 v->len = str.len; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
602 v->valid = 1; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
603 v->no_cacheable = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
604 v->not_found = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
605 v->data = str.data; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
606 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
607 return NGX_OK; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
608 } |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
609 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
610 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
611 static ngx_int_t |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
612 ngx_stream_variable_server_port(ngx_stream_session_t *s, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
613 ngx_stream_variable_value_t *v, uintptr_t data) |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
614 { |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
615 ngx_uint_t port; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
616 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
617 v->len = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
618 v->valid = 1; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
619 v->no_cacheable = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
620 v->not_found = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
621 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
622 if (ngx_connection_local_sockaddr(s->connection, NULL, 0) != NGX_OK) { |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
623 return NGX_ERROR; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
624 } |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
625 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
626 v->data = ngx_pnalloc(s->connection->pool, sizeof("65535") - 1); |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
627 if (v->data == NULL) { |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
628 return NGX_ERROR; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
629 } |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
630 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
631 port = ngx_inet_get_port(s->connection->local_sockaddr); |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
632 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
633 if (port > 0 && port < 65536) { |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
634 v->len = ngx_sprintf(v->data, "%ui", port) - v->data; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
635 } |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
636 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
637 return NGX_OK; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
638 } |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
639 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
640 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
641 static ngx_int_t |
6668
5e2821c2de46
Stream: the $bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6608
diff
changeset
|
642 ngx_stream_variable_bytes(ngx_stream_session_t *s, |
6608
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
643 ngx_stream_variable_value_t *v, uintptr_t data) |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
644 { |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
645 u_char *p; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
646 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
647 p = ngx_pnalloc(s->connection->pool, NGX_OFF_T_LEN); |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
648 if (p == NULL) { |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
649 return NGX_ERROR; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
650 } |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
651 |
6668
5e2821c2de46
Stream: the $bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6608
diff
changeset
|
652 if (data == 1) { |
5e2821c2de46
Stream: the $bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6608
diff
changeset
|
653 v->len = ngx_sprintf(p, "%O", s->received) - p; |
5e2821c2de46
Stream: the $bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6608
diff
changeset
|
654 |
5e2821c2de46
Stream: the $bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6608
diff
changeset
|
655 } else { |
5e2821c2de46
Stream: the $bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6608
diff
changeset
|
656 v->len = ngx_sprintf(p, "%O", s->connection->sent) - p; |
5e2821c2de46
Stream: the $bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6608
diff
changeset
|
657 } |
5e2821c2de46
Stream: the $bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6608
diff
changeset
|
658 |
6608
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
659 v->valid = 1; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
660 v->no_cacheable = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
661 v->not_found = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
662 v->data = p; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
663 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
664 return NGX_OK; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
665 } |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
666 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
667 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
668 static ngx_int_t |
6669
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
669 ngx_stream_variable_session_time(ngx_stream_session_t *s, |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
670 ngx_stream_variable_value_t *v, uintptr_t data) |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
671 { |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
672 u_char *p; |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
673 ngx_time_t *tp; |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
674 ngx_msec_int_t ms; |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
675 |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
676 p = ngx_pnalloc(s->connection->pool, NGX_TIME_T_LEN + 4); |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
677 if (p == NULL) { |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
678 return NGX_ERROR; |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
679 } |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
680 |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
681 tp = ngx_timeofday(); |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
682 |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
683 ms = (ngx_msec_int_t) |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
684 ((tp->sec - s->start_sec) * 1000 + (tp->msec - s->start_msec)); |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
685 ms = ngx_max(ms, 0); |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
686 |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
687 v->len = ngx_sprintf(p, "%T.%03M", (time_t) ms / 1000, ms % 1000) - p; |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
688 v->valid = 1; |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
689 v->no_cacheable = 0; |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
690 v->not_found = 0; |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
691 v->data = p; |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
692 |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
693 return NGX_OK; |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
694 } |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
695 |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
696 |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
697 static ngx_int_t |
6674
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6670
diff
changeset
|
698 ngx_stream_variable_status(ngx_stream_session_t *s, |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6670
diff
changeset
|
699 ngx_stream_variable_value_t *v, uintptr_t data) |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6670
diff
changeset
|
700 { |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6670
diff
changeset
|
701 v->data = ngx_pnalloc(s->connection->pool, NGX_INT_T_LEN); |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6670
diff
changeset
|
702 if (v->data == NULL) { |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6670
diff
changeset
|
703 return NGX_ERROR; |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6670
diff
changeset
|
704 } |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6670
diff
changeset
|
705 |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6670
diff
changeset
|
706 v->len = ngx_sprintf(v->data, "%03ui", s->status) - v->data; |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6670
diff
changeset
|
707 v->valid = 1; |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6670
diff
changeset
|
708 v->no_cacheable = 0; |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6670
diff
changeset
|
709 v->not_found = 0; |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6670
diff
changeset
|
710 |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6670
diff
changeset
|
711 return NGX_OK; |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6670
diff
changeset
|
712 } |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6670
diff
changeset
|
713 |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6670
diff
changeset
|
714 |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6670
diff
changeset
|
715 static ngx_int_t |
6608
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
716 ngx_stream_variable_connection(ngx_stream_session_t *s, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
717 ngx_stream_variable_value_t *v, uintptr_t data) |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
718 { |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
719 u_char *p; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
720 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
721 p = ngx_pnalloc(s->connection->pool, NGX_ATOMIC_T_LEN); |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
722 if (p == NULL) { |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
723 return NGX_ERROR; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
724 } |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
725 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
726 v->len = ngx_sprintf(p, "%uA", s->connection->number) - p; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
727 v->valid = 1; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
728 v->no_cacheable = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
729 v->not_found = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
730 v->data = p; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
731 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
732 return NGX_OK; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
733 } |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
734 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
735 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
736 static ngx_int_t |
6607 | 737 ngx_stream_variable_nginx_version(ngx_stream_session_t *s, |
738 ngx_stream_variable_value_t *v, uintptr_t data) | |
739 { | |
740 v->len = sizeof(NGINX_VERSION) - 1; | |
741 v->valid = 1; | |
742 v->no_cacheable = 0; | |
743 v->not_found = 0; | |
744 v->data = (u_char *) NGINX_VERSION; | |
745 | |
746 return NGX_OK; | |
747 } | |
748 | |
749 | |
6608
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
750 static ngx_int_t |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
751 ngx_stream_variable_hostname(ngx_stream_session_t *s, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
752 ngx_stream_variable_value_t *v, uintptr_t data) |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
753 { |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
754 v->len = ngx_cycle->hostname.len; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
755 v->valid = 1; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
756 v->no_cacheable = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
757 v->not_found = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
758 v->data = ngx_cycle->hostname.data; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
759 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
760 return NGX_OK; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
761 } |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
762 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
763 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
764 static ngx_int_t |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
765 ngx_stream_variable_pid(ngx_stream_session_t *s, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
766 ngx_stream_variable_value_t *v, uintptr_t data) |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
767 { |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
768 u_char *p; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
769 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
770 p = ngx_pnalloc(s->connection->pool, NGX_INT64_LEN); |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
771 if (p == NULL) { |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
772 return NGX_ERROR; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
773 } |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
774 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
775 v->len = ngx_sprintf(p, "%P", ngx_pid) - p; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
776 v->valid = 1; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
777 v->no_cacheable = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
778 v->not_found = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
779 v->data = p; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
780 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
781 return NGX_OK; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
782 } |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
783 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
784 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
785 static ngx_int_t |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
786 ngx_stream_variable_msec(ngx_stream_session_t *s, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
787 ngx_stream_variable_value_t *v, uintptr_t data) |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
788 { |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
789 u_char *p; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
790 ngx_time_t *tp; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
791 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
792 p = ngx_pnalloc(s->connection->pool, NGX_TIME_T_LEN + 4); |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
793 if (p == NULL) { |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
794 return NGX_ERROR; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
795 } |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
796 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
797 tp = ngx_timeofday(); |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
798 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
799 v->len = ngx_sprintf(p, "%T.%03M", tp->sec, tp->msec) - p; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
800 v->valid = 1; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
801 v->no_cacheable = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
802 v->not_found = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
803 v->data = p; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
804 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
805 return NGX_OK; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
806 } |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
807 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
808 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
809 static ngx_int_t |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
810 ngx_stream_variable_time_iso8601(ngx_stream_session_t *s, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
811 ngx_stream_variable_value_t *v, uintptr_t data) |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
812 { |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
813 u_char *p; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
814 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
815 p = ngx_pnalloc(s->connection->pool, ngx_cached_http_log_iso8601.len); |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
816 if (p == NULL) { |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
817 return NGX_ERROR; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
818 } |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
819 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
820 ngx_memcpy(p, ngx_cached_http_log_iso8601.data, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
821 ngx_cached_http_log_iso8601.len); |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
822 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
823 v->len = ngx_cached_http_log_iso8601.len; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
824 v->valid = 1; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
825 v->no_cacheable = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
826 v->not_found = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
827 v->data = p; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
828 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
829 return NGX_OK; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
830 } |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
831 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
832 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
833 static ngx_int_t |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
834 ngx_stream_variable_time_local(ngx_stream_session_t *s, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
835 ngx_stream_variable_value_t *v, uintptr_t data) |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
836 { |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
837 u_char *p; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
838 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
839 p = ngx_pnalloc(s->connection->pool, ngx_cached_http_log_time.len); |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
840 if (p == NULL) { |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
841 return NGX_ERROR; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
842 } |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
843 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
844 ngx_memcpy(p, ngx_cached_http_log_time.data, ngx_cached_http_log_time.len); |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
845 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
846 v->len = ngx_cached_http_log_time.len; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
847 v->valid = 1; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
848 v->no_cacheable = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
849 v->not_found = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
850 v->data = p; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
851 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
852 return NGX_OK; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
853 } |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
854 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
855 |
6670
c6372a40c2a7
Stream: the $protocol variable.
Vladimir Homutov <vl@nginx.com>
parents:
6669
diff
changeset
|
856 static ngx_int_t |
c6372a40c2a7
Stream: the $protocol variable.
Vladimir Homutov <vl@nginx.com>
parents:
6669
diff
changeset
|
857 ngx_stream_variable_protocol(ngx_stream_session_t *s, |
c6372a40c2a7
Stream: the $protocol variable.
Vladimir Homutov <vl@nginx.com>
parents:
6669
diff
changeset
|
858 ngx_stream_variable_value_t *v, uintptr_t data) |
c6372a40c2a7
Stream: the $protocol variable.
Vladimir Homutov <vl@nginx.com>
parents:
6669
diff
changeset
|
859 { |
c6372a40c2a7
Stream: the $protocol variable.
Vladimir Homutov <vl@nginx.com>
parents:
6669
diff
changeset
|
860 v->len = 3; |
c6372a40c2a7
Stream: the $protocol variable.
Vladimir Homutov <vl@nginx.com>
parents:
6669
diff
changeset
|
861 v->valid = 1; |
c6372a40c2a7
Stream: the $protocol variable.
Vladimir Homutov <vl@nginx.com>
parents:
6669
diff
changeset
|
862 v->no_cacheable = 0; |
c6372a40c2a7
Stream: the $protocol variable.
Vladimir Homutov <vl@nginx.com>
parents:
6669
diff
changeset
|
863 v->not_found = 0; |
c6372a40c2a7
Stream: the $protocol variable.
Vladimir Homutov <vl@nginx.com>
parents:
6669
diff
changeset
|
864 v->data = (u_char *) (s->connection->type == SOCK_DGRAM ? "UDP" : "TCP"); |
c6372a40c2a7
Stream: the $protocol variable.
Vladimir Homutov <vl@nginx.com>
parents:
6669
diff
changeset
|
865 |
c6372a40c2a7
Stream: the $protocol variable.
Vladimir Homutov <vl@nginx.com>
parents:
6669
diff
changeset
|
866 return NGX_OK; |
c6372a40c2a7
Stream: the $protocol variable.
Vladimir Homutov <vl@nginx.com>
parents:
6669
diff
changeset
|
867 } |
c6372a40c2a7
Stream: the $protocol variable.
Vladimir Homutov <vl@nginx.com>
parents:
6669
diff
changeset
|
868 |
c6372a40c2a7
Stream: the $protocol variable.
Vladimir Homutov <vl@nginx.com>
parents:
6669
diff
changeset
|
869 |
6607 | 870 void * |
871 ngx_stream_map_find(ngx_stream_session_t *s, ngx_stream_map_t *map, | |
872 ngx_str_t *match) | |
873 { | |
874 void *value; | |
875 u_char *low; | |
876 size_t len; | |
877 ngx_uint_t key; | |
878 | |
879 len = match->len; | |
880 | |
881 if (len) { | |
882 low = ngx_pnalloc(s->connection->pool, len); | |
883 if (low == NULL) { | |
884 return NULL; | |
885 } | |
886 | |
887 } else { | |
888 low = NULL; | |
889 } | |
890 | |
891 key = ngx_hash_strlow(low, match->data, len); | |
892 | |
893 value = ngx_hash_find_combined(&map->hash, key, low, len); | |
894 if (value) { | |
895 return value; | |
896 } | |
897 | |
898 #if (NGX_PCRE) | |
899 | |
900 if (len && map->nregex) { | |
901 ngx_int_t n; | |
902 ngx_uint_t i; | |
903 ngx_stream_map_regex_t *reg; | |
904 | |
905 reg = map->regex; | |
906 | |
907 for (i = 0; i < map->nregex; i++) { | |
908 | |
909 n = ngx_stream_regex_exec(s, reg[i].regex, match); | |
910 | |
911 if (n == NGX_OK) { | |
912 return reg[i].value; | |
913 } | |
914 | |
915 if (n == NGX_DECLINED) { | |
916 continue; | |
917 } | |
918 | |
919 /* NGX_ERROR */ | |
920 | |
921 return NULL; | |
922 } | |
923 } | |
924 | |
925 #endif | |
926 | |
927 return NULL; | |
928 } | |
929 | |
930 | |
931 #if (NGX_PCRE) | |
932 | |
933 static ngx_int_t | |
934 ngx_stream_variable_not_found(ngx_stream_session_t *s, | |
935 ngx_stream_variable_value_t *v, uintptr_t data) | |
936 { | |
937 v->not_found = 1; | |
938 return NGX_OK; | |
939 } | |
940 | |
941 | |
942 ngx_stream_regex_t * | |
943 ngx_stream_regex_compile(ngx_conf_t *cf, ngx_regex_compile_t *rc) | |
944 { | |
945 u_char *p; | |
946 size_t size; | |
947 ngx_str_t name; | |
948 ngx_uint_t i, n; | |
949 ngx_stream_variable_t *v; | |
950 ngx_stream_regex_t *re; | |
951 ngx_stream_regex_variable_t *rv; | |
952 ngx_stream_core_main_conf_t *cmcf; | |
953 | |
954 rc->pool = cf->pool; | |
955 | |
956 if (ngx_regex_compile(rc) != NGX_OK) { | |
957 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%V", &rc->err); | |
958 return NULL; | |
959 } | |
960 | |
961 re = ngx_pcalloc(cf->pool, sizeof(ngx_stream_regex_t)); | |
962 if (re == NULL) { | |
963 return NULL; | |
964 } | |
965 | |
966 re->regex = rc->regex; | |
967 re->ncaptures = rc->captures; | |
968 re->name = rc->pattern; | |
969 | |
970 cmcf = ngx_stream_conf_get_module_main_conf(cf, ngx_stream_core_module); | |
971 cmcf->ncaptures = ngx_max(cmcf->ncaptures, re->ncaptures); | |
972 | |
973 n = (ngx_uint_t) rc->named_captures; | |
974 | |
975 if (n == 0) { | |
976 return re; | |
977 } | |
978 | |
979 rv = ngx_palloc(rc->pool, n * sizeof(ngx_stream_regex_variable_t)); | |
980 if (rv == NULL) { | |
981 return NULL; | |
982 } | |
983 | |
984 re->variables = rv; | |
985 re->nvariables = n; | |
986 | |
987 size = rc->name_size; | |
988 p = rc->names; | |
989 | |
990 for (i = 0; i < n; i++) { | |
991 rv[i].capture = 2 * ((p[0] << 8) + p[1]); | |
992 | |
993 name.data = &p[2]; | |
994 name.len = ngx_strlen(name.data); | |
995 | |
996 v = ngx_stream_add_variable(cf, &name, NGX_STREAM_VAR_CHANGEABLE); | |
997 if (v == NULL) { | |
998 return NULL; | |
999 } | |
1000 | |
1001 rv[i].index = ngx_stream_get_variable_index(cf, &name); | |
1002 if (rv[i].index == NGX_ERROR) { | |
1003 return NULL; | |
1004 } | |
1005 | |
1006 v->get_handler = ngx_stream_variable_not_found; | |
1007 | |
1008 p += size; | |
1009 } | |
1010 | |
1011 return re; | |
1012 } | |
1013 | |
1014 | |
1015 ngx_int_t | |
1016 ngx_stream_regex_exec(ngx_stream_session_t *s, ngx_stream_regex_t *re, | |
1017 ngx_str_t *str) | |
1018 { | |
1019 ngx_int_t rc, index; | |
1020 ngx_uint_t i, n, len; | |
1021 ngx_stream_variable_value_t *vv; | |
1022 ngx_stream_core_main_conf_t *cmcf; | |
1023 | |
1024 cmcf = ngx_stream_get_module_main_conf(s, ngx_stream_core_module); | |
1025 | |
1026 if (re->ncaptures) { | |
1027 len = cmcf->ncaptures; | |
1028 | |
1029 if (s->captures == NULL) { | |
1030 s->captures = ngx_palloc(s->connection->pool, len * sizeof(int)); | |
1031 if (s->captures == NULL) { | |
1032 return NGX_ERROR; | |
1033 } | |
1034 } | |
1035 | |
1036 } else { | |
1037 len = 0; | |
1038 } | |
1039 | |
1040 rc = ngx_regex_exec(re->regex, str, s->captures, len); | |
1041 | |
1042 if (rc == NGX_REGEX_NO_MATCHED) { | |
1043 return NGX_DECLINED; | |
1044 } | |
1045 | |
1046 if (rc < 0) { | |
1047 ngx_log_error(NGX_LOG_ALERT, s->connection->log, 0, | |
1048 ngx_regex_exec_n " failed: %i on \"%V\" using \"%V\"", | |
1049 rc, str, &re->name); | |
1050 return NGX_ERROR; | |
1051 } | |
1052 | |
1053 for (i = 0; i < re->nvariables; i++) { | |
1054 | |
1055 n = re->variables[i].capture; | |
1056 index = re->variables[i].index; | |
1057 vv = &s->variables[index]; | |
1058 | |
1059 vv->len = s->captures[n + 1] - s->captures[n]; | |
1060 vv->valid = 1; | |
1061 vv->no_cacheable = 0; | |
1062 vv->not_found = 0; | |
1063 vv->data = &str->data[s->captures[n]]; | |
1064 | |
1065 #if (NGX_DEBUG) | |
1066 { | |
1067 ngx_stream_variable_t *v; | |
1068 | |
1069 v = cmcf->variables.elts; | |
1070 | |
1071 ngx_log_debug2(NGX_LOG_DEBUG_STREAM, s->connection->log, 0, | |
1072 "stream regex set $%V to \"%v\"", &v[index].name, vv); | |
1073 } | |
1074 #endif | |
1075 } | |
1076 | |
1077 s->ncaptures = rc * 2; | |
1078 s->captures_data = str->data; | |
1079 | |
1080 return NGX_OK; | |
1081 } | |
1082 | |
1083 #endif | |
1084 | |
1085 | |
1086 ngx_int_t | |
1087 ngx_stream_variables_add_core_vars(ngx_conf_t *cf) | |
1088 { | |
1089 ngx_stream_variable_t *cv, *v; | |
1090 ngx_stream_core_main_conf_t *cmcf; | |
1091 | |
1092 cmcf = ngx_stream_conf_get_module_main_conf(cf, ngx_stream_core_module); | |
1093 | |
1094 cmcf->variables_keys = ngx_pcalloc(cf->temp_pool, | |
1095 sizeof(ngx_hash_keys_arrays_t)); | |
1096 if (cmcf->variables_keys == NULL) { | |
1097 return NGX_ERROR; | |
1098 } | |
1099 | |
1100 cmcf->variables_keys->pool = cf->pool; | |
1101 cmcf->variables_keys->temp_pool = cf->pool; | |
1102 | |
1103 if (ngx_hash_keys_array_init(cmcf->variables_keys, NGX_HASH_SMALL) | |
1104 != NGX_OK) | |
1105 { | |
1106 return NGX_ERROR; | |
1107 } | |
1108 | |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1109 if (ngx_array_init(&cmcf->prefix_variables, cf->pool, 8, |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1110 sizeof(ngx_stream_variable_t)) |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1111 != NGX_OK) |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1112 { |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1113 return NGX_ERROR; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1114 } |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1115 |
6607 | 1116 for (cv = ngx_stream_core_variables; cv->name.len; cv++) { |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1117 v = ngx_stream_add_variable(cf, &cv->name, cv->flags); |
6607 | 1118 if (v == NULL) { |
1119 return NGX_ERROR; | |
1120 } | |
1121 | |
1122 *v = *cv; | |
1123 } | |
1124 | |
1125 return NGX_OK; | |
1126 } | |
1127 | |
1128 | |
1129 ngx_int_t | |
1130 ngx_stream_variables_init_vars(ngx_conf_t *cf) | |
1131 { | |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1132 size_t len; |
6607 | 1133 ngx_uint_t i, n; |
1134 ngx_hash_key_t *key; | |
1135 ngx_hash_init_t hash; | |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1136 ngx_stream_variable_t *v, *av, *pv; |
6607 | 1137 ngx_stream_core_main_conf_t *cmcf; |
1138 | |
1139 /* set the handlers for the indexed stream variables */ | |
1140 | |
1141 cmcf = ngx_stream_conf_get_module_main_conf(cf, ngx_stream_core_module); | |
1142 | |
1143 v = cmcf->variables.elts; | |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1144 pv = cmcf->prefix_variables.elts; |
6607 | 1145 key = cmcf->variables_keys->keys.elts; |
1146 | |
1147 for (i = 0; i < cmcf->variables.nelts; i++) { | |
1148 | |
1149 for (n = 0; n < cmcf->variables_keys->keys.nelts; n++) { | |
1150 | |
1151 av = key[n].value; | |
1152 | |
1153 if (v[i].name.len == key[n].key.len | |
1154 && ngx_strncmp(v[i].name.data, key[n].key.data, v[i].name.len) | |
1155 == 0) | |
1156 { | |
1157 v[i].get_handler = av->get_handler; | |
1158 v[i].data = av->data; | |
1159 | |
1160 av->flags |= NGX_STREAM_VAR_INDEXED; | |
1161 v[i].flags = av->flags; | |
1162 | |
1163 av->index = i; | |
1164 | |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1165 if (av->get_handler == NULL |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1166 || (av->flags & NGX_STREAM_VAR_WEAK)) |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1167 { |
6607 | 1168 break; |
1169 } | |
1170 | |
1171 goto next; | |
1172 } | |
1173 } | |
1174 | |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1175 len = 0; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1176 av = NULL; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1177 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1178 for (n = 0; n < cmcf->prefix_variables.nelts; n++) { |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1179 if (v[i].name.len >= pv[n].name.len && v[i].name.len > len |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1180 && ngx_strncmp(v[i].name.data, pv[n].name.data, pv[n].name.len) |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1181 == 0) |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1182 { |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1183 av = &pv[n]; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1184 len = pv[n].name.len; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1185 } |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1186 } |
6607 | 1187 |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1188 if (av) { |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1189 v[i].get_handler = av->get_handler; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1190 v[i].data = (uintptr_t) &v[i].name; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1191 v[i].flags = av->flags; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1192 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1193 goto next; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1194 } |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1195 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1196 if (v[i].get_handler == NULL) { |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1197 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1198 "unknown \"%V\" variable", &v[i].name); |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1199 return NGX_ERROR; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1200 } |
6607 | 1201 |
1202 next: | |
1203 continue; | |
1204 } | |
1205 | |
1206 | |
1207 for (n = 0; n < cmcf->variables_keys->keys.nelts; n++) { | |
1208 av = key[n].value; | |
1209 | |
1210 if (av->flags & NGX_STREAM_VAR_NOHASH) { | |
1211 key[n].key.data = NULL; | |
1212 } | |
1213 } | |
1214 | |
1215 | |
1216 hash.hash = &cmcf->variables_hash; | |
1217 hash.key = ngx_hash_key; | |
1218 hash.max_size = cmcf->variables_hash_max_size; | |
1219 hash.bucket_size = cmcf->variables_hash_bucket_size; | |
1220 hash.name = "variables_hash"; | |
1221 hash.pool = cf->pool; | |
1222 hash.temp_pool = NULL; | |
1223 | |
1224 if (ngx_hash_init(&hash, cmcf->variables_keys->keys.elts, | |
1225 cmcf->variables_keys->keys.nelts) | |
1226 != NGX_OK) | |
1227 { | |
1228 return NGX_ERROR; | |
1229 } | |
1230 | |
1231 cmcf->variables_keys = NULL; | |
1232 | |
1233 return NGX_OK; | |
1234 } |