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