Mercurial > hg > nginx
annotate src/stream/ngx_stream_variables.c @ 7292:f9661f56c717
Allowed digits, '+', '-', and '.' in scheme names as per RFC 3986.
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Thu, 24 May 2018 12:06:35 +0300 |
parents | 0b1eb40de6da |
children | 06b01840bd42 |
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 | |
7226 | 164 if (!(flags & NGX_STREAM_VAR_WEAK)) { |
165 v->flags &= ~NGX_STREAM_VAR_WEAK; | |
166 } | |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
167 |
6607 | 168 return v; |
169 } | |
170 | |
171 v = ngx_palloc(cf->pool, sizeof(ngx_stream_variable_t)); | |
172 if (v == NULL) { | |
173 return NULL; | |
174 } | |
175 | |
176 v->name.len = name->len; | |
177 v->name.data = ngx_pnalloc(cf->pool, name->len); | |
178 if (v->name.data == NULL) { | |
179 return NULL; | |
180 } | |
181 | |
182 ngx_strlow(v->name.data, name->data, name->len); | |
183 | |
184 v->set_handler = NULL; | |
185 v->get_handler = NULL; | |
186 v->data = 0; | |
187 v->flags = flags; | |
188 v->index = 0; | |
189 | |
190 rc = ngx_hash_add_key(cmcf->variables_keys, &v->name, v, 0); | |
191 | |
192 if (rc == NGX_ERROR) { | |
193 return NULL; | |
194 } | |
195 | |
196 if (rc == NGX_BUSY) { | |
197 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
198 "conflicting variable name \"%V\"", name); | |
199 return NULL; | |
200 } | |
201 | |
202 return v; | |
203 } | |
204 | |
205 | |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
206 static ngx_stream_variable_t * |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
207 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
|
208 ngx_uint_t flags) |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
209 { |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
210 ngx_uint_t i; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
211 ngx_stream_variable_t *v; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
212 ngx_stream_core_main_conf_t *cmcf; |
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 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
|
215 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
216 v = cmcf->prefix_variables.elts; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
217 for (i = 0; i < cmcf->prefix_variables.nelts; i++) { |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
218 if (name->len != v[i].name.len |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
219 || 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
|
220 { |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
221 continue; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
222 } |
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 v = &v[i]; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
225 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
226 if (!(v->flags & NGX_STREAM_VAR_CHANGEABLE)) { |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
227 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
228 "the duplicate \"%V\" variable", name); |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
229 return NULL; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
230 } |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
231 |
7226 | 232 if (!(flags & NGX_STREAM_VAR_WEAK)) { |
233 v->flags &= ~NGX_STREAM_VAR_WEAK; | |
234 } | |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
235 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
236 return v; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
237 } |
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 v = ngx_array_push(&cmcf->prefix_variables); |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
240 if (v == NULL) { |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
241 return NULL; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
242 } |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
243 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
244 v->name.len = name->len; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
245 v->name.data = ngx_pnalloc(cf->pool, name->len); |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
246 if (v->name.data == NULL) { |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
247 return NULL; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
248 } |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
249 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
250 ngx_strlow(v->name.data, name->data, name->len); |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
251 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
252 v->set_handler = NULL; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
253 v->get_handler = NULL; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
254 v->data = 0; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
255 v->flags = flags; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
256 v->index = 0; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
257 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
258 return v; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
259 } |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
260 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
261 |
6607 | 262 ngx_int_t |
263 ngx_stream_get_variable_index(ngx_conf_t *cf, ngx_str_t *name) | |
264 { | |
265 ngx_uint_t i; | |
266 ngx_stream_variable_t *v; | |
267 ngx_stream_core_main_conf_t *cmcf; | |
268 | |
269 if (name->len == 0) { | |
270 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
271 "invalid variable name \"$\""); | |
272 return NGX_ERROR; | |
273 } | |
274 | |
275 cmcf = ngx_stream_conf_get_module_main_conf(cf, ngx_stream_core_module); | |
276 | |
277 v = cmcf->variables.elts; | |
278 | |
279 if (v == NULL) { | |
280 if (ngx_array_init(&cmcf->variables, cf->pool, 4, | |
281 sizeof(ngx_stream_variable_t)) | |
282 != NGX_OK) | |
283 { | |
284 return NGX_ERROR; | |
285 } | |
286 | |
287 } else { | |
288 for (i = 0; i < cmcf->variables.nelts; i++) { | |
289 if (name->len != v[i].name.len | |
290 || ngx_strncasecmp(name->data, v[i].name.data, name->len) != 0) | |
291 { | |
292 continue; | |
293 } | |
294 | |
295 return i; | |
296 } | |
297 } | |
298 | |
299 v = ngx_array_push(&cmcf->variables); | |
300 if (v == NULL) { | |
301 return NGX_ERROR; | |
302 } | |
303 | |
304 v->name.len = name->len; | |
305 v->name.data = ngx_pnalloc(cf->pool, name->len); | |
306 if (v->name.data == NULL) { | |
307 return NGX_ERROR; | |
308 } | |
309 | |
310 ngx_strlow(v->name.data, name->data, name->len); | |
311 | |
312 v->set_handler = NULL; | |
313 v->get_handler = NULL; | |
314 v->data = 0; | |
315 v->flags = 0; | |
316 v->index = cmcf->variables.nelts - 1; | |
317 | |
318 return v->index; | |
319 } | |
320 | |
321 | |
322 ngx_stream_variable_value_t * | |
323 ngx_stream_get_indexed_variable(ngx_stream_session_t *s, ngx_uint_t index) | |
324 { | |
325 ngx_stream_variable_t *v; | |
326 ngx_stream_core_main_conf_t *cmcf; | |
327 | |
328 cmcf = ngx_stream_get_module_main_conf(s, ngx_stream_core_module); | |
329 | |
330 if (cmcf->variables.nelts <= index) { | |
331 ngx_log_error(NGX_LOG_ALERT, s->connection->log, 0, | |
332 "unknown variable index: %ui", index); | |
333 return NULL; | |
334 } | |
335 | |
336 if (s->variables[index].not_found || s->variables[index].valid) { | |
337 return &s->variables[index]; | |
338 } | |
339 | |
340 v = cmcf->variables.elts; | |
341 | |
6851
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
342 if (ngx_stream_variable_depth == 0) { |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
343 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
|
344 "cycle while evaluating variable \"%V\"", |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
345 &v[index].name); |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
346 return NULL; |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
347 } |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
348 |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
349 ngx_stream_variable_depth--; |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
350 |
6607 | 351 if (v[index].get_handler(s, &s->variables[index], v[index].data) |
352 == NGX_OK) | |
353 { | |
6851
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
354 ngx_stream_variable_depth++; |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
355 |
6607 | 356 if (v[index].flags & NGX_STREAM_VAR_NOCACHEABLE) { |
357 s->variables[index].no_cacheable = 1; | |
358 } | |
359 | |
360 return &s->variables[index]; | |
361 } | |
362 | |
6851
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
363 ngx_stream_variable_depth++; |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
364 |
6607 | 365 s->variables[index].valid = 0; |
366 s->variables[index].not_found = 1; | |
367 | |
368 return NULL; | |
369 } | |
370 | |
371 | |
372 ngx_stream_variable_value_t * | |
373 ngx_stream_get_flushed_variable(ngx_stream_session_t *s, ngx_uint_t index) | |
374 { | |
375 ngx_stream_variable_value_t *v; | |
376 | |
377 v = &s->variables[index]; | |
378 | |
379 if (v->valid || v->not_found) { | |
380 if (!v->no_cacheable) { | |
381 return v; | |
382 } | |
383 | |
384 v->valid = 0; | |
385 v->not_found = 0; | |
386 } | |
387 | |
388 return ngx_stream_get_indexed_variable(s, index); | |
389 } | |
390 | |
391 | |
392 ngx_stream_variable_value_t * | |
393 ngx_stream_get_variable(ngx_stream_session_t *s, ngx_str_t *name, | |
394 ngx_uint_t key) | |
395 { | |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
396 size_t len; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
397 ngx_uint_t i, n; |
6607 | 398 ngx_stream_variable_t *v; |
399 ngx_stream_variable_value_t *vv; | |
400 ngx_stream_core_main_conf_t *cmcf; | |
401 | |
402 cmcf = ngx_stream_get_module_main_conf(s, ngx_stream_core_module); | |
403 | |
404 v = ngx_hash_find(&cmcf->variables_hash, key, name->data, name->len); | |
405 | |
406 if (v) { | |
407 if (v->flags & NGX_STREAM_VAR_INDEXED) { | |
408 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
|
409 } |
6607 | 410 |
6851
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
411 if (ngx_stream_variable_depth == 0) { |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
412 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
|
413 "cycle while evaluating variable \"%V\"", name); |
6607 | 414 return NULL; |
415 } | |
6851
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
416 |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
417 ngx_stream_variable_depth--; |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
418 |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
419 vv = ngx_palloc(s->connection->pool, |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
420 sizeof(ngx_stream_variable_value_t)); |
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 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
|
423 ngx_stream_variable_depth++; |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
424 return vv; |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
425 } |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
426 |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
427 ngx_stream_variable_depth++; |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6681
diff
changeset
|
428 return NULL; |
6607 | 429 } |
430 | |
431 vv = ngx_palloc(s->connection->pool, sizeof(ngx_stream_variable_value_t)); | |
432 if (vv == NULL) { | |
433 return NULL; | |
434 } | |
435 | |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
436 len = 0; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
437 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
438 v = cmcf->prefix_variables.elts; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
439 n = cmcf->prefix_variables.nelts; |
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 for (i = 0; i < cmcf->prefix_variables.nelts; i++) { |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
442 if (name->len >= v[i].name.len && name->len > len |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
443 && 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
|
444 { |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
445 len = v[i].name.len; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
446 n = i; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
447 } |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
448 } |
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 if (n != cmcf->prefix_variables.nelts) { |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
451 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
|
452 return vv; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
453 } |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
454 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
455 return NULL; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
456 } |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
457 |
6607 | 458 vv->not_found = 1; |
459 | |
460 return vv; | |
461 } | |
462 | |
463 | |
464 static ngx_int_t | |
6608
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
465 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
|
466 ngx_stream_variable_value_t *v, uintptr_t data) |
7111 | 467 { |
6608
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
468 struct sockaddr_in *sin; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
469 #if (NGX_HAVE_INET6) |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
470 struct sockaddr_in6 *sin6; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
471 #endif |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
472 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
473 switch (s->connection->sockaddr->sa_family) { |
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 #if (NGX_HAVE_INET6) |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
476 case AF_INET6: |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
477 sin6 = (struct sockaddr_in6 *) s->connection->sockaddr; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
478 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
479 v->len = sizeof(struct in6_addr); |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
480 v->valid = 1; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
481 v->no_cacheable = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
482 v->not_found = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
483 v->data = sin6->sin6_addr.s6_addr; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
484 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
485 break; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
486 #endif |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
487 |
7121
924b6ef942bf
Fixed handling of unix sockets in $binary_remote_addr.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7111
diff
changeset
|
488 #if (NGX_HAVE_UNIX_DOMAIN) |
924b6ef942bf
Fixed handling of unix sockets in $binary_remote_addr.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7111
diff
changeset
|
489 case AF_UNIX: |
924b6ef942bf
Fixed handling of unix sockets in $binary_remote_addr.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7111
diff
changeset
|
490 |
924b6ef942bf
Fixed handling of unix sockets in $binary_remote_addr.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7111
diff
changeset
|
491 v->len = s->connection->addr_text.len; |
924b6ef942bf
Fixed handling of unix sockets in $binary_remote_addr.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7111
diff
changeset
|
492 v->valid = 1; |
924b6ef942bf
Fixed handling of unix sockets in $binary_remote_addr.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7111
diff
changeset
|
493 v->no_cacheable = 0; |
924b6ef942bf
Fixed handling of unix sockets in $binary_remote_addr.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7111
diff
changeset
|
494 v->not_found = 0; |
924b6ef942bf
Fixed handling of unix sockets in $binary_remote_addr.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7111
diff
changeset
|
495 v->data = s->connection->addr_text.data; |
924b6ef942bf
Fixed handling of unix sockets in $binary_remote_addr.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7111
diff
changeset
|
496 |
924b6ef942bf
Fixed handling of unix sockets in $binary_remote_addr.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7111
diff
changeset
|
497 break; |
924b6ef942bf
Fixed handling of unix sockets in $binary_remote_addr.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7111
diff
changeset
|
498 #endif |
924b6ef942bf
Fixed handling of unix sockets in $binary_remote_addr.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7111
diff
changeset
|
499 |
6608
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
500 default: /* AF_INET */ |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
501 sin = (struct sockaddr_in *) s->connection->sockaddr; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
502 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
503 v->len = sizeof(in_addr_t); |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
504 v->valid = 1; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
505 v->no_cacheable = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
506 v->not_found = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
507 v->data = (u_char *) &sin->sin_addr; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
508 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
509 break; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
510 } |
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 return NGX_OK; |
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 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
515 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
516 static ngx_int_t |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
517 ngx_stream_variable_remote_addr(ngx_stream_session_t *s, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
518 ngx_stream_variable_value_t *v, uintptr_t data) |
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 = s->connection->addr_text.len; |
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 v->data = s->connection->addr_text.data; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
525 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
526 return NGX_OK; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
527 } |
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 static ngx_int_t |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
531 ngx_stream_variable_remote_port(ngx_stream_session_t *s, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
532 ngx_stream_variable_value_t *v, uintptr_t data) |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
533 { |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
534 ngx_uint_t port; |
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 v->len = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
537 v->valid = 1; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
538 v->no_cacheable = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
539 v->not_found = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
540 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
541 v->data = ngx_pnalloc(s->connection->pool, sizeof("65535") - 1); |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
542 if (v->data == NULL) { |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
543 return NGX_ERROR; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
544 } |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
545 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
546 port = ngx_inet_get_port(s->connection->sockaddr); |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
547 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
548 if (port > 0 && port < 65536) { |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
549 v->len = ngx_sprintf(v->data, "%ui", port) - v->data; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
550 } |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
551 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
552 return NGX_OK; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
553 } |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
554 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
555 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
556 static ngx_int_t |
6681
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
557 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
|
558 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
|
559 { |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
560 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
|
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 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
|
565 |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
566 return NGX_OK; |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
567 } |
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 static ngx_int_t |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
571 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
|
572 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
|
573 { |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
574 ngx_uint_t port; |
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 v->len = 0; |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
577 v->valid = 1; |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
578 v->no_cacheable = 0; |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
579 v->not_found = 0; |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
580 |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
581 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
|
582 if (v->data == NULL) { |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
583 return NGX_ERROR; |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
584 } |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
585 |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
586 port = s->connection->proxy_protocol_port; |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
587 |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
588 if (port > 0 && port < 65536) { |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
589 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
|
590 } |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
591 |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
592 return NGX_OK; |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
593 } |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
594 |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
595 |
b9f78a4e3597
Stream: $proxy_protocol_addr and $proxy_protocol_port.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6674
diff
changeset
|
596 static ngx_int_t |
6608
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
597 ngx_stream_variable_server_addr(ngx_stream_session_t *s, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
598 ngx_stream_variable_value_t *v, uintptr_t data) |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
599 { |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
600 ngx_str_t str; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
601 u_char addr[NGX_SOCKADDR_STRLEN]; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
602 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
603 str.len = NGX_SOCKADDR_STRLEN; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
604 str.data = addr; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
605 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
606 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
|
607 return NGX_ERROR; |
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 str.data = ngx_pnalloc(s->connection->pool, str.len); |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
611 if (str.data == NULL) { |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
612 return NGX_ERROR; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
613 } |
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_memcpy(str.data, addr, str.len); |
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 = str.len; |
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 v->data = str.data; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
622 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
623 return NGX_OK; |
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 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
627 static ngx_int_t |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
628 ngx_stream_variable_server_port(ngx_stream_session_t *s, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
629 ngx_stream_variable_value_t *v, uintptr_t data) |
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 ngx_uint_t port; |
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 v->len = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
634 v->valid = 1; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
635 v->no_cacheable = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
636 v->not_found = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
637 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
638 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
|
639 return NGX_ERROR; |
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 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
642 v->data = ngx_pnalloc(s->connection->pool, sizeof("65535") - 1); |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
643 if (v->data == NULL) { |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
644 return NGX_ERROR; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
645 } |
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 port = ngx_inet_get_port(s->connection->local_sockaddr); |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
648 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
649 if (port > 0 && port < 65536) { |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
650 v->len = ngx_sprintf(v->data, "%ui", port) - v->data; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
651 } |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
652 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
653 return NGX_OK; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
654 } |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
655 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
656 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
657 static ngx_int_t |
6668
5e2821c2de46
Stream: the $bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6608
diff
changeset
|
658 ngx_stream_variable_bytes(ngx_stream_session_t *s, |
6608
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
659 ngx_stream_variable_value_t *v, uintptr_t data) |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
660 { |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
661 u_char *p; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
662 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
663 p = ngx_pnalloc(s->connection->pool, NGX_OFF_T_LEN); |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
664 if (p == NULL) { |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
665 return NGX_ERROR; |
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 |
6668
5e2821c2de46
Stream: the $bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6608
diff
changeset
|
668 if (data == 1) { |
5e2821c2de46
Stream: the $bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6608
diff
changeset
|
669 v->len = ngx_sprintf(p, "%O", s->received) - p; |
5e2821c2de46
Stream: the $bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6608
diff
changeset
|
670 |
5e2821c2de46
Stream: the $bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6608
diff
changeset
|
671 } else { |
5e2821c2de46
Stream: the $bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6608
diff
changeset
|
672 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
|
673 } |
5e2821c2de46
Stream: the $bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6608
diff
changeset
|
674 |
6608
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
675 v->valid = 1; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
676 v->no_cacheable = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
677 v->not_found = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
678 v->data = p; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
679 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
680 return NGX_OK; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
681 } |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
682 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
683 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
684 static ngx_int_t |
6669
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
685 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
|
686 ngx_stream_variable_value_t *v, uintptr_t data) |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
687 { |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
688 u_char *p; |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
689 ngx_time_t *tp; |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
690 ngx_msec_int_t ms; |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
691 |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
692 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
|
693 if (p == NULL) { |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
694 return NGX_ERROR; |
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 tp = ngx_timeofday(); |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
698 |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
699 ms = (ngx_msec_int_t) |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
700 ((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
|
701 ms = ngx_max(ms, 0); |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
702 |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
703 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
|
704 v->valid = 1; |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
705 v->no_cacheable = 0; |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
706 v->not_found = 0; |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
707 v->data = p; |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
708 |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
709 return NGX_OK; |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
710 } |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
711 |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
712 |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6668
diff
changeset
|
713 static ngx_int_t |
6674
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6670
diff
changeset
|
714 ngx_stream_variable_status(ngx_stream_session_t *s, |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6670
diff
changeset
|
715 ngx_stream_variable_value_t *v, uintptr_t data) |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6670
diff
changeset
|
716 { |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6670
diff
changeset
|
717 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
|
718 if (v->data == NULL) { |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6670
diff
changeset
|
719 return NGX_ERROR; |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6670
diff
changeset
|
720 } |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6670
diff
changeset
|
721 |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6670
diff
changeset
|
722 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
|
723 v->valid = 1; |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6670
diff
changeset
|
724 v->no_cacheable = 0; |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6670
diff
changeset
|
725 v->not_found = 0; |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6670
diff
changeset
|
726 |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6670
diff
changeset
|
727 return NGX_OK; |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6670
diff
changeset
|
728 } |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6670
diff
changeset
|
729 |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6670
diff
changeset
|
730 |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6670
diff
changeset
|
731 static ngx_int_t |
6608
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
732 ngx_stream_variable_connection(ngx_stream_session_t *s, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
733 ngx_stream_variable_value_t *v, uintptr_t data) |
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 u_char *p; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
736 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
737 p = ngx_pnalloc(s->connection->pool, NGX_ATOMIC_T_LEN); |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
738 if (p == NULL) { |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
739 return NGX_ERROR; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
740 } |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
741 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
742 v->len = ngx_sprintf(p, "%uA", s->connection->number) - p; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
743 v->valid = 1; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
744 v->no_cacheable = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
745 v->not_found = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
746 v->data = p; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
747 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
748 return NGX_OK; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
749 } |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
750 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
751 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
752 static ngx_int_t |
6607 | 753 ngx_stream_variable_nginx_version(ngx_stream_session_t *s, |
754 ngx_stream_variable_value_t *v, uintptr_t data) | |
755 { | |
756 v->len = sizeof(NGINX_VERSION) - 1; | |
757 v->valid = 1; | |
758 v->no_cacheable = 0; | |
759 v->not_found = 0; | |
760 v->data = (u_char *) NGINX_VERSION; | |
761 | |
762 return NGX_OK; | |
763 } | |
764 | |
765 | |
6608
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
766 static ngx_int_t |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
767 ngx_stream_variable_hostname(ngx_stream_session_t *s, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
768 ngx_stream_variable_value_t *v, uintptr_t data) |
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 v->len = ngx_cycle->hostname.len; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
771 v->valid = 1; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
772 v->no_cacheable = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
773 v->not_found = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
774 v->data = ngx_cycle->hostname.data; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
775 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
776 return NGX_OK; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
777 } |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
778 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
779 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
780 static ngx_int_t |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
781 ngx_stream_variable_pid(ngx_stream_session_t *s, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
782 ngx_stream_variable_value_t *v, uintptr_t data) |
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 u_char *p; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
785 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
786 p = ngx_pnalloc(s->connection->pool, NGX_INT64_LEN); |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
787 if (p == NULL) { |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
788 return NGX_ERROR; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
789 } |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
790 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
791 v->len = ngx_sprintf(p, "%P", ngx_pid) - p; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
792 v->valid = 1; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
793 v->no_cacheable = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
794 v->not_found = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
795 v->data = p; |
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 return NGX_OK; |
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 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
800 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
801 static ngx_int_t |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
802 ngx_stream_variable_msec(ngx_stream_session_t *s, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
803 ngx_stream_variable_value_t *v, uintptr_t data) |
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 u_char *p; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
806 ngx_time_t *tp; |
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 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
|
809 if (p == NULL) { |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
810 return NGX_ERROR; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
811 } |
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 tp = ngx_timeofday(); |
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 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
|
816 v->valid = 1; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
817 v->no_cacheable = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
818 v->not_found = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
819 v->data = p; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
820 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
821 return NGX_OK; |
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 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
824 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
825 static ngx_int_t |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
826 ngx_stream_variable_time_iso8601(ngx_stream_session_t *s, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
827 ngx_stream_variable_value_t *v, uintptr_t data) |
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 u_char *p; |
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 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
|
832 if (p == NULL) { |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
833 return NGX_ERROR; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
834 } |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
835 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
836 ngx_memcpy(p, ngx_cached_http_log_iso8601.data, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
837 ngx_cached_http_log_iso8601.len); |
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 v->len = ngx_cached_http_log_iso8601.len; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
840 v->valid = 1; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
841 v->no_cacheable = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
842 v->not_found = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
843 v->data = p; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
844 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
845 return NGX_OK; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
846 } |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
847 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
848 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
849 static ngx_int_t |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
850 ngx_stream_variable_time_local(ngx_stream_session_t *s, |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
851 ngx_stream_variable_value_t *v, uintptr_t data) |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
852 { |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
853 u_char *p; |
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 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
|
856 if (p == NULL) { |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
857 return NGX_ERROR; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
858 } |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
859 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
860 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
|
861 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
862 v->len = ngx_cached_http_log_time.len; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
863 v->valid = 1; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
864 v->no_cacheable = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
865 v->not_found = 0; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
866 v->data = p; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
867 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
868 return NGX_OK; |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
869 } |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
870 |
eb4293155e87
Stream: core module variables.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
871 |
6670
c6372a40c2a7
Stream: the $protocol variable.
Vladimir Homutov <vl@nginx.com>
parents:
6669
diff
changeset
|
872 static ngx_int_t |
c6372a40c2a7
Stream: the $protocol variable.
Vladimir Homutov <vl@nginx.com>
parents:
6669
diff
changeset
|
873 ngx_stream_variable_protocol(ngx_stream_session_t *s, |
c6372a40c2a7
Stream: the $protocol variable.
Vladimir Homutov <vl@nginx.com>
parents:
6669
diff
changeset
|
874 ngx_stream_variable_value_t *v, uintptr_t data) |
c6372a40c2a7
Stream: the $protocol variable.
Vladimir Homutov <vl@nginx.com>
parents:
6669
diff
changeset
|
875 { |
c6372a40c2a7
Stream: the $protocol variable.
Vladimir Homutov <vl@nginx.com>
parents:
6669
diff
changeset
|
876 v->len = 3; |
c6372a40c2a7
Stream: the $protocol variable.
Vladimir Homutov <vl@nginx.com>
parents:
6669
diff
changeset
|
877 v->valid = 1; |
c6372a40c2a7
Stream: the $protocol variable.
Vladimir Homutov <vl@nginx.com>
parents:
6669
diff
changeset
|
878 v->no_cacheable = 0; |
c6372a40c2a7
Stream: the $protocol variable.
Vladimir Homutov <vl@nginx.com>
parents:
6669
diff
changeset
|
879 v->not_found = 0; |
c6372a40c2a7
Stream: the $protocol variable.
Vladimir Homutov <vl@nginx.com>
parents:
6669
diff
changeset
|
880 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
|
881 |
c6372a40c2a7
Stream: the $protocol variable.
Vladimir Homutov <vl@nginx.com>
parents:
6669
diff
changeset
|
882 return NGX_OK; |
c6372a40c2a7
Stream: the $protocol variable.
Vladimir Homutov <vl@nginx.com>
parents:
6669
diff
changeset
|
883 } |
c6372a40c2a7
Stream: the $protocol variable.
Vladimir Homutov <vl@nginx.com>
parents:
6669
diff
changeset
|
884 |
c6372a40c2a7
Stream: the $protocol variable.
Vladimir Homutov <vl@nginx.com>
parents:
6669
diff
changeset
|
885 |
6607 | 886 void * |
887 ngx_stream_map_find(ngx_stream_session_t *s, ngx_stream_map_t *map, | |
888 ngx_str_t *match) | |
889 { | |
890 void *value; | |
891 u_char *low; | |
892 size_t len; | |
893 ngx_uint_t key; | |
894 | |
895 len = match->len; | |
896 | |
897 if (len) { | |
898 low = ngx_pnalloc(s->connection->pool, len); | |
899 if (low == NULL) { | |
900 return NULL; | |
901 } | |
902 | |
903 } else { | |
904 low = NULL; | |
905 } | |
906 | |
907 key = ngx_hash_strlow(low, match->data, len); | |
908 | |
909 value = ngx_hash_find_combined(&map->hash, key, low, len); | |
910 if (value) { | |
911 return value; | |
912 } | |
913 | |
914 #if (NGX_PCRE) | |
915 | |
916 if (len && map->nregex) { | |
917 ngx_int_t n; | |
918 ngx_uint_t i; | |
919 ngx_stream_map_regex_t *reg; | |
920 | |
921 reg = map->regex; | |
922 | |
923 for (i = 0; i < map->nregex; i++) { | |
924 | |
925 n = ngx_stream_regex_exec(s, reg[i].regex, match); | |
926 | |
927 if (n == NGX_OK) { | |
928 return reg[i].value; | |
929 } | |
930 | |
931 if (n == NGX_DECLINED) { | |
932 continue; | |
933 } | |
934 | |
935 /* NGX_ERROR */ | |
936 | |
937 return NULL; | |
938 } | |
939 } | |
940 | |
941 #endif | |
942 | |
943 return NULL; | |
944 } | |
945 | |
946 | |
947 #if (NGX_PCRE) | |
948 | |
949 static ngx_int_t | |
950 ngx_stream_variable_not_found(ngx_stream_session_t *s, | |
951 ngx_stream_variable_value_t *v, uintptr_t data) | |
952 { | |
953 v->not_found = 1; | |
954 return NGX_OK; | |
955 } | |
956 | |
957 | |
958 ngx_stream_regex_t * | |
959 ngx_stream_regex_compile(ngx_conf_t *cf, ngx_regex_compile_t *rc) | |
960 { | |
961 u_char *p; | |
962 size_t size; | |
963 ngx_str_t name; | |
964 ngx_uint_t i, n; | |
965 ngx_stream_variable_t *v; | |
966 ngx_stream_regex_t *re; | |
967 ngx_stream_regex_variable_t *rv; | |
968 ngx_stream_core_main_conf_t *cmcf; | |
969 | |
970 rc->pool = cf->pool; | |
971 | |
972 if (ngx_regex_compile(rc) != NGX_OK) { | |
973 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%V", &rc->err); | |
974 return NULL; | |
975 } | |
976 | |
977 re = ngx_pcalloc(cf->pool, sizeof(ngx_stream_regex_t)); | |
978 if (re == NULL) { | |
979 return NULL; | |
980 } | |
981 | |
982 re->regex = rc->regex; | |
983 re->ncaptures = rc->captures; | |
984 re->name = rc->pattern; | |
985 | |
986 cmcf = ngx_stream_conf_get_module_main_conf(cf, ngx_stream_core_module); | |
987 cmcf->ncaptures = ngx_max(cmcf->ncaptures, re->ncaptures); | |
988 | |
989 n = (ngx_uint_t) rc->named_captures; | |
990 | |
991 if (n == 0) { | |
992 return re; | |
993 } | |
994 | |
995 rv = ngx_palloc(rc->pool, n * sizeof(ngx_stream_regex_variable_t)); | |
996 if (rv == NULL) { | |
997 return NULL; | |
998 } | |
999 | |
1000 re->variables = rv; | |
1001 re->nvariables = n; | |
1002 | |
1003 size = rc->name_size; | |
1004 p = rc->names; | |
1005 | |
1006 for (i = 0; i < n; i++) { | |
1007 rv[i].capture = 2 * ((p[0] << 8) + p[1]); | |
1008 | |
1009 name.data = &p[2]; | |
1010 name.len = ngx_strlen(name.data); | |
1011 | |
1012 v = ngx_stream_add_variable(cf, &name, NGX_STREAM_VAR_CHANGEABLE); | |
1013 if (v == NULL) { | |
1014 return NULL; | |
1015 } | |
1016 | |
1017 rv[i].index = ngx_stream_get_variable_index(cf, &name); | |
1018 if (rv[i].index == NGX_ERROR) { | |
1019 return NULL; | |
1020 } | |
1021 | |
1022 v->get_handler = ngx_stream_variable_not_found; | |
1023 | |
1024 p += size; | |
1025 } | |
1026 | |
1027 return re; | |
1028 } | |
1029 | |
1030 | |
1031 ngx_int_t | |
1032 ngx_stream_regex_exec(ngx_stream_session_t *s, ngx_stream_regex_t *re, | |
1033 ngx_str_t *str) | |
1034 { | |
1035 ngx_int_t rc, index; | |
1036 ngx_uint_t i, n, len; | |
1037 ngx_stream_variable_value_t *vv; | |
1038 ngx_stream_core_main_conf_t *cmcf; | |
1039 | |
1040 cmcf = ngx_stream_get_module_main_conf(s, ngx_stream_core_module); | |
1041 | |
1042 if (re->ncaptures) { | |
1043 len = cmcf->ncaptures; | |
1044 | |
1045 if (s->captures == NULL) { | |
1046 s->captures = ngx_palloc(s->connection->pool, len * sizeof(int)); | |
1047 if (s->captures == NULL) { | |
1048 return NGX_ERROR; | |
1049 } | |
1050 } | |
1051 | |
1052 } else { | |
1053 len = 0; | |
1054 } | |
1055 | |
1056 rc = ngx_regex_exec(re->regex, str, s->captures, len); | |
1057 | |
1058 if (rc == NGX_REGEX_NO_MATCHED) { | |
1059 return NGX_DECLINED; | |
1060 } | |
1061 | |
1062 if (rc < 0) { | |
1063 ngx_log_error(NGX_LOG_ALERT, s->connection->log, 0, | |
1064 ngx_regex_exec_n " failed: %i on \"%V\" using \"%V\"", | |
1065 rc, str, &re->name); | |
1066 return NGX_ERROR; | |
1067 } | |
1068 | |
1069 for (i = 0; i < re->nvariables; i++) { | |
1070 | |
1071 n = re->variables[i].capture; | |
1072 index = re->variables[i].index; | |
1073 vv = &s->variables[index]; | |
1074 | |
1075 vv->len = s->captures[n + 1] - s->captures[n]; | |
1076 vv->valid = 1; | |
1077 vv->no_cacheable = 0; | |
1078 vv->not_found = 0; | |
1079 vv->data = &str->data[s->captures[n]]; | |
1080 | |
1081 #if (NGX_DEBUG) | |
1082 { | |
1083 ngx_stream_variable_t *v; | |
1084 | |
1085 v = cmcf->variables.elts; | |
1086 | |
1087 ngx_log_debug2(NGX_LOG_DEBUG_STREAM, s->connection->log, 0, | |
1088 "stream regex set $%V to \"%v\"", &v[index].name, vv); | |
1089 } | |
1090 #endif | |
1091 } | |
1092 | |
1093 s->ncaptures = rc * 2; | |
1094 s->captures_data = str->data; | |
1095 | |
1096 return NGX_OK; | |
1097 } | |
1098 | |
1099 #endif | |
1100 | |
1101 | |
1102 ngx_int_t | |
1103 ngx_stream_variables_add_core_vars(ngx_conf_t *cf) | |
1104 { | |
1105 ngx_stream_variable_t *cv, *v; | |
1106 ngx_stream_core_main_conf_t *cmcf; | |
1107 | |
1108 cmcf = ngx_stream_conf_get_module_main_conf(cf, ngx_stream_core_module); | |
1109 | |
1110 cmcf->variables_keys = ngx_pcalloc(cf->temp_pool, | |
1111 sizeof(ngx_hash_keys_arrays_t)); | |
1112 if (cmcf->variables_keys == NULL) { | |
1113 return NGX_ERROR; | |
1114 } | |
1115 | |
1116 cmcf->variables_keys->pool = cf->pool; | |
1117 cmcf->variables_keys->temp_pool = cf->pool; | |
1118 | |
1119 if (ngx_hash_keys_array_init(cmcf->variables_keys, NGX_HASH_SMALL) | |
1120 != NGX_OK) | |
1121 { | |
1122 return NGX_ERROR; | |
1123 } | |
1124 | |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1125 if (ngx_array_init(&cmcf->prefix_variables, cf->pool, 8, |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1126 sizeof(ngx_stream_variable_t)) |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1127 != NGX_OK) |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1128 { |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1129 return NGX_ERROR; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1130 } |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1131 |
6607 | 1132 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
|
1133 v = ngx_stream_add_variable(cf, &cv->name, cv->flags); |
6607 | 1134 if (v == NULL) { |
1135 return NGX_ERROR; | |
1136 } | |
1137 | |
1138 *v = *cv; | |
1139 } | |
1140 | |
1141 return NGX_OK; | |
1142 } | |
1143 | |
1144 | |
1145 ngx_int_t | |
1146 ngx_stream_variables_init_vars(ngx_conf_t *cf) | |
1147 { | |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1148 size_t len; |
6607 | 1149 ngx_uint_t i, n; |
1150 ngx_hash_key_t *key; | |
1151 ngx_hash_init_t hash; | |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1152 ngx_stream_variable_t *v, *av, *pv; |
6607 | 1153 ngx_stream_core_main_conf_t *cmcf; |
1154 | |
1155 /* set the handlers for the indexed stream variables */ | |
1156 | |
1157 cmcf = ngx_stream_conf_get_module_main_conf(cf, ngx_stream_core_module); | |
1158 | |
1159 v = cmcf->variables.elts; | |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1160 pv = cmcf->prefix_variables.elts; |
6607 | 1161 key = cmcf->variables_keys->keys.elts; |
1162 | |
1163 for (i = 0; i < cmcf->variables.nelts; i++) { | |
1164 | |
1165 for (n = 0; n < cmcf->variables_keys->keys.nelts; n++) { | |
1166 | |
1167 av = key[n].value; | |
1168 | |
1169 if (v[i].name.len == key[n].key.len | |
1170 && ngx_strncmp(v[i].name.data, key[n].key.data, v[i].name.len) | |
1171 == 0) | |
1172 { | |
1173 v[i].get_handler = av->get_handler; | |
1174 v[i].data = av->data; | |
1175 | |
1176 av->flags |= NGX_STREAM_VAR_INDEXED; | |
1177 v[i].flags = av->flags; | |
1178 | |
1179 av->index = i; | |
1180 | |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1181 if (av->get_handler == NULL |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1182 || (av->flags & NGX_STREAM_VAR_WEAK)) |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1183 { |
6607 | 1184 break; |
1185 } | |
1186 | |
1187 goto next; | |
1188 } | |
1189 } | |
1190 | |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1191 len = 0; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1192 av = NULL; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1193 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1194 for (n = 0; n < cmcf->prefix_variables.nelts; n++) { |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1195 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
|
1196 && 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
|
1197 == 0) |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1198 { |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1199 av = &pv[n]; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1200 len = pv[n].name.len; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1201 } |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1202 } |
6607 | 1203 |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1204 if (av) { |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1205 v[i].get_handler = av->get_handler; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1206 v[i].data = (uintptr_t) &v[i].name; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1207 v[i].flags = av->flags; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1208 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1209 goto next; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1210 } |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1211 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1212 if (v[i].get_handler == NULL) { |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1213 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1214 "unknown \"%V\" variable", &v[i].name); |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1215 return NGX_ERROR; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
1216 } |
6607 | 1217 |
1218 next: | |
1219 continue; | |
1220 } | |
1221 | |
1222 | |
1223 for (n = 0; n < cmcf->variables_keys->keys.nelts; n++) { | |
1224 av = key[n].value; | |
1225 | |
1226 if (av->flags & NGX_STREAM_VAR_NOHASH) { | |
1227 key[n].key.data = NULL; | |
1228 } | |
1229 } | |
1230 | |
1231 | |
1232 hash.hash = &cmcf->variables_hash; | |
1233 hash.key = ngx_hash_key; | |
1234 hash.max_size = cmcf->variables_hash_max_size; | |
1235 hash.bucket_size = cmcf->variables_hash_bucket_size; | |
1236 hash.name = "variables_hash"; | |
1237 hash.pool = cf->pool; | |
1238 hash.temp_pool = NULL; | |
1239 | |
1240 if (ngx_hash_init(&hash, cmcf->variables_keys->keys.elts, | |
1241 cmcf->variables_keys->keys.nelts) | |
1242 != NGX_OK) | |
1243 { | |
1244 return NGX_ERROR; | |
1245 } | |
1246 | |
1247 cmcf->variables_keys = NULL; | |
1248 | |
1249 return NGX_OK; | |
1250 } |