Mercurial > hg > nginx-vendor-current
comparison src/http/ngx_http_variables.c @ 668:9fbf3ad94cbf NGINX_1_1_18
nginx 1.1.18
*) Change: keepalive connections are no longer disabled for Safari by
default.
*) Feature: the $connection_requests variable.
*) Feature: $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd and
$tcpinfo_rcv_space variables.
*) Feature: the "worker_cpu_affinity" directive now works on FreeBSD.
*) Feature: the "xslt_param" and "xslt_string_param" directives.
Thanks to Samuel Behan.
*) Bugfix: in configure tests.
Thanks to Piotr Sikora.
*) Bugfix: in the ngx_http_xslt_filter_module.
*) Bugfix: nginx could not be built on Debian GNU/Hurd.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Wed, 28 Mar 2012 00:00:00 +0400 |
parents | e5fa0a4a7d27 |
children | ad45b044f1e5 |
comparison
equal
deleted
inserted
replaced
667:e0eabdb2bad1 | 668:9fbf3ad94cbf |
---|---|
32 ngx_http_variable_value_t *v, uintptr_t data); | 32 ngx_http_variable_value_t *v, uintptr_t data); |
33 static ngx_int_t ngx_http_variable_cookie(ngx_http_request_t *r, | 33 static ngx_int_t ngx_http_variable_cookie(ngx_http_request_t *r, |
34 ngx_http_variable_value_t *v, uintptr_t data); | 34 ngx_http_variable_value_t *v, uintptr_t data); |
35 static ngx_int_t ngx_http_variable_argument(ngx_http_request_t *r, | 35 static ngx_int_t ngx_http_variable_argument(ngx_http_request_t *r, |
36 ngx_http_variable_value_t *v, uintptr_t data); | 36 ngx_http_variable_value_t *v, uintptr_t data); |
37 #if (NGX_HAVE_TCP_INFO) | |
38 static ngx_int_t ngx_http_variable_tcpinfo(ngx_http_request_t *r, | |
39 ngx_http_variable_value_t *v, uintptr_t data); | |
40 #endif | |
37 | 41 |
38 static ngx_int_t ngx_http_variable_host(ngx_http_request_t *r, | 42 static ngx_int_t ngx_http_variable_host(ngx_http_request_t *r, |
39 ngx_http_variable_value_t *v, uintptr_t data); | 43 ngx_http_variable_value_t *v, uintptr_t data); |
40 static ngx_int_t ngx_http_variable_binary_remote_addr(ngx_http_request_t *r, | 44 static ngx_int_t ngx_http_variable_binary_remote_addr(ngx_http_request_t *r, |
41 ngx_http_variable_value_t *v, uintptr_t data); | 45 ngx_http_variable_value_t *v, uintptr_t data); |
257 0, 0, 0 }, | 261 0, 0, 0 }, |
258 | 262 |
259 { ngx_string("pid"), NULL, ngx_http_variable_pid, | 263 { ngx_string("pid"), NULL, ngx_http_variable_pid, |
260 0, 0, 0 }, | 264 0, 0, 0 }, |
261 | 265 |
266 #if (NGX_HAVE_TCP_INFO) | |
267 { ngx_string("tcpinfo_rtt"), NULL, ngx_http_variable_tcpinfo, | |
268 0, NGX_HTTP_VAR_NOCACHEABLE, 0 }, | |
269 | |
270 { ngx_string("tcpinfo_rttvar"), NULL, ngx_http_variable_tcpinfo, | |
271 1, NGX_HTTP_VAR_NOCACHEABLE, 0 }, | |
272 | |
273 { ngx_string("tcpinfo_snd_cwnd"), NULL, ngx_http_variable_tcpinfo, | |
274 2, NGX_HTTP_VAR_NOCACHEABLE, 0 }, | |
275 | |
276 { ngx_string("tcpinfo_rcv_space"), NULL, ngx_http_variable_tcpinfo, | |
277 3, NGX_HTTP_VAR_NOCACHEABLE, 0 }, | |
278 #endif | |
279 | |
262 { ngx_null_string, NULL, NULL, 0, 0, 0 } | 280 { ngx_null_string, NULL, NULL, 0, 0, 0 } |
263 }; | 281 }; |
264 | 282 |
265 | 283 |
266 ngx_http_variable_value_t ngx_http_variable_null_value = | 284 ngx_http_variable_value_t ngx_http_variable_null_value = |
382 v->get_handler = NULL; | 400 v->get_handler = NULL; |
383 v->data = 0; | 401 v->data = 0; |
384 v->flags = 0; | 402 v->flags = 0; |
385 v->index = cmcf->variables.nelts - 1; | 403 v->index = cmcf->variables.nelts - 1; |
386 | 404 |
387 return cmcf->variables.nelts - 1; | 405 return v->index; |
388 } | 406 } |
389 | 407 |
390 | 408 |
391 ngx_http_variable_value_t * | 409 ngx_http_variable_value_t * |
392 ngx_http_get_indexed_variable(ngx_http_request_t *r, ngx_uint_t index) | 410 ngx_http_get_indexed_variable(ngx_http_request_t *r, ngx_uint_t index) |
882 | 900 |
883 return NGX_OK; | 901 return NGX_OK; |
884 } | 902 } |
885 | 903 |
886 | 904 |
905 #if (NGX_HAVE_TCP_INFO) | |
906 | |
907 static ngx_int_t | |
908 ngx_http_variable_tcpinfo(ngx_http_request_t *r, ngx_http_variable_value_t *v, | |
909 uintptr_t data) | |
910 { | |
911 struct tcp_info ti; | |
912 socklen_t len; | |
913 uint32_t value; | |
914 | |
915 len = sizeof(struct tcp_info); | |
916 if (getsockopt(r->connection->fd, IPPROTO_TCP, TCP_INFO, &ti, &len) == -1) { | |
917 v->not_found = 1; | |
918 return NGX_OK; | |
919 } | |
920 | |
921 v->data = ngx_pnalloc(r->pool, NGX_INT32_LEN); | |
922 if (v->data == NULL) { | |
923 return NGX_ERROR; | |
924 } | |
925 | |
926 switch (data) { | |
927 case 0: | |
928 value = ti.tcpi_rtt; | |
929 break; | |
930 | |
931 case 1: | |
932 value = ti.tcpi_rttvar; | |
933 break; | |
934 | |
935 case 2: | |
936 value = ti.tcpi_snd_cwnd; | |
937 break; | |
938 | |
939 case 3: | |
940 value = ti.tcpi_rcv_space; | |
941 break; | |
942 | |
943 /* suppress warning */ | |
944 default: | |
945 value = 0; | |
946 break; | |
947 } | |
948 | |
949 v->len = ngx_sprintf(v->data, "%uD", value) - v->data; | |
950 v->valid = 1; | |
951 v->no_cacheable = 0; | |
952 v->not_found = 0; | |
953 | |
954 return NGX_OK; | |
955 } | |
956 | |
957 #endif | |
958 | |
959 | |
887 static ngx_int_t | 960 static ngx_int_t |
888 ngx_http_variable_host(ngx_http_request_t *r, ngx_http_variable_value_t *v, | 961 ngx_http_variable_host(ngx_http_request_t *r, ngx_http_variable_value_t *v, |
889 uintptr_t data) | 962 uintptr_t data) |
890 { | 963 { |
891 ngx_http_core_srv_conf_t *cscf; | 964 ngx_http_core_srv_conf_t *cscf; |
1198 | 1271 |
1199 static ngx_int_t | 1272 static ngx_int_t |
1200 ngx_http_variable_realpath_root(ngx_http_request_t *r, | 1273 ngx_http_variable_realpath_root(ngx_http_request_t *r, |
1201 ngx_http_variable_value_t *v, uintptr_t data) | 1274 ngx_http_variable_value_t *v, uintptr_t data) |
1202 { | 1275 { |
1276 u_char *real; | |
1203 size_t len; | 1277 size_t len; |
1204 ngx_str_t path; | 1278 ngx_str_t path; |
1205 ngx_http_core_loc_conf_t *clcf; | 1279 ngx_http_core_loc_conf_t *clcf; |
1206 u_char real[NGX_MAX_PATH]; | 1280 #if (NGX_HAVE_MAX_PATH) |
1281 u_char buffer[NGX_MAX_PATH]; | |
1282 #endif | |
1207 | 1283 |
1208 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | 1284 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
1209 | 1285 |
1210 if (clcf->root_lengths == NULL) { | 1286 if (clcf->root_lengths == NULL) { |
1211 path = clcf->root; | 1287 path = clcf->root; |
1223 if (ngx_conf_full_name((ngx_cycle_t *) ngx_cycle, &path, 0) != NGX_OK) { | 1299 if (ngx_conf_full_name((ngx_cycle_t *) ngx_cycle, &path, 0) != NGX_OK) { |
1224 return NGX_ERROR; | 1300 return NGX_ERROR; |
1225 } | 1301 } |
1226 } | 1302 } |
1227 | 1303 |
1228 if (ngx_realpath(path.data, real) == NULL) { | 1304 #if (NGX_HAVE_MAX_PATH) |
1305 real = buffer; | |
1306 #else | |
1307 real = NULL; | |
1308 #endif | |
1309 | |
1310 real = ngx_realpath(path.data, real); | |
1311 | |
1312 if (real == NULL) { | |
1229 ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno, | 1313 ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno, |
1230 ngx_realpath_n " \"%s\" failed", path.data); | 1314 ngx_realpath_n " \"%s\" failed", path.data); |
1231 return NGX_ERROR; | 1315 return NGX_ERROR; |
1232 } | 1316 } |
1233 | 1317 |
1234 len = ngx_strlen(real); | 1318 len = ngx_strlen(real); |
1235 | 1319 |
1236 v->data = ngx_pnalloc(r->pool, len); | 1320 v->data = ngx_pnalloc(r->pool, len); |
1237 if (v->data == NULL) { | 1321 if (v->data == NULL) { |
1322 #if !(NGX_HAVE_MAX_PATH) | |
1323 ngx_free(real); | |
1324 #endif | |
1238 return NGX_ERROR; | 1325 return NGX_ERROR; |
1239 } | 1326 } |
1240 | 1327 |
1241 v->len = len; | 1328 v->len = len; |
1242 v->valid = 1; | 1329 v->valid = 1; |
1243 v->no_cacheable = 0; | 1330 v->no_cacheable = 0; |
1244 v->not_found = 0; | 1331 v->not_found = 0; |
1245 | 1332 |
1246 ngx_memcpy(v->data, real, len); | 1333 ngx_memcpy(v->data, real, len); |
1334 | |
1335 #if !(NGX_HAVE_MAX_PATH) | |
1336 ngx_free(real); | |
1337 #endif | |
1247 | 1338 |
1248 return NGX_OK; | 1339 return NGX_OK; |
1249 } | 1340 } |
1250 | 1341 |
1251 | 1342 |