annotate src/core/ngx_array.c @ 58:b55cbf18157e NGINX_0_1_29

nginx 0.1.29 *) Feature: the ngx_http_ssi_module supports "include virtual" command. *) Feature: the ngx_http_ssi_module supports the condition command like 'if expr="$NAME"' and "else" and "endif" commands. Only one nested level is supported. *) Feature: the ngx_http_ssi_module supports the DATE_LOCAL and DATE_GMT variables and "config timefmt" command. *) Feature: the "ssi_ignore_recycled_buffers" directive. *) Bugfix: the "echo" command did not show the default value for the empty QUERY_STRING variable. *) Change: the ngx_http_proxy_module was rewritten. *) Feature: the "proxy_redirect", "proxy_pass_request_headers", "proxy_pass_request_body", and "proxy_method" directives. *) Feature: the "proxy_set_header" directive. The "proxy_x_var" was canceled and must be replaced with the proxy_set_header directive. *) Change: the "proxy_preserve_host" is canceled and must be replaced with the "proxy_set_header Host $host" and the "proxy_redirect off" directives, the "proxy_set_header Host $host:$proxy_port" directive and the appropriate proxy_redirect directives. *) Change: the "proxy_set_x_real_ip" is canceled and must be replaced with the "proxy_set_header X-Real-IP $remote_addr" directive. *) Change: the "proxy_add_x_forwarded_for" is canceled and must be replaced with the "proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for" directive. *) Change: the "proxy_set_x_url" is canceled and must be replaced with the "proxy_set_header X-URL http://$host:$server_port$request_uri" directive. *) Feature: the "fastcgi_param" directive. *) Change: the "fastcgi_root", "fastcgi_set_var" and "fastcgi_params" directive are canceled and must be replaced with the fastcgi_param directives. *) Feature: the "index" directive can use the variables. *) Feature: the "index" directive can be used at http and server levels. *) Change: the last index only in the "index" directive can be absolute. *) Feature: the "rewrite" directive can use the variables. *) Feature: the "internal" directive. *) Feature: the CONTENT_LENGTH, CONTENT_TYPE, REMOTE_PORT, SERVER_ADDR, SERVER_PORT, SERVER_PROTOCOL, DOCUMENT_ROOT, SERVER_NAME, REQUEST_METHOD, REQUEST_URI, and REMOTE_USER variables. *) Change: nginx now passes the invalid lines in a client request headers or a backend response header. *) Bugfix: if the backend did not transfer response for a long time and the "send_timeout" was less than "proxy_read_timeout", then nginx returned the 408 response. *) Bugfix: the segmentation fault was occurred if the backend sent an invalid line in response header; bug appeared in 0.1.26. *) Bugfix: the segmentation fault may occurred in FastCGI fault tolerance configuration. *) Bugfix: the "expires" directive did not remove the previous "Expires" and "Cache-Control" headers. *) Bugfix: nginx did not take into account trailing dot in "Host" header line. *) Bugfix: the ngx_http_auth_module did not work under Linux. *) Bugfix: the rewrite directive worked incorrectly, if the arguments were in a request. *) Bugfix: nginx could not be built on MacOS X.
author Igor Sysoev <http://sysoev.ru>
date Thu, 12 May 2005 00:00:00 +0400
parents 72eb30262aac
children bb61aa162c6b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2 /*
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
3 * Copyright (C) Igor Sysoev
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
4 */
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
5
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
6
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
7 #include <ngx_config.h>
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
8 #include <ngx_core.h>
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
9
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
10
34
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
11 ngx_array_t *ngx_array_create(ngx_pool_t *p, ngx_uint_t n, size_t size)
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
12 {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
13 ngx_array_t *a;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
14
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents: 34
diff changeset
15 a = ngx_palloc(p, sizeof(ngx_array_t));
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents: 34
diff changeset
16 if (a == NULL) {
34
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
17 return NULL;
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
18 }
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
19
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents: 34
diff changeset
20 a->elts = ngx_palloc(p, n * size);
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents: 34
diff changeset
21 if (a->elts == NULL) {
34
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
22 return NULL;
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
23 }
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
24
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
25 a->nelts = 0;
34
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
26 a->size = size;
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
27 a->nalloc = n;
34
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
28 a->pool = p;
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
29
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
30 return a;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
31 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
32
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
33
34
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
34 void ngx_array_destroy(ngx_array_t *a)
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
35 {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
36 ngx_pool_t *p;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
37
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
38 p = a->pool;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
39
34
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
40 if ((u_char *) a->elts + a->size * a->nalloc == p->last) {
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
41 p->last -= a->size * a->nalloc;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
42 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
43
34
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
44 if ((u_char *) a + sizeof(ngx_array_t) == p->last) {
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
45 p->last = (u_char *) a;
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
46 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
47 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
48
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
49
34
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
50 void *ngx_array_push(ngx_array_t *a)
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
51 {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
52 void *elt, *new;
34
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
53 size_t size;
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
54 ngx_pool_t *p;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
55
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
56 if (a->nelts == a->nalloc) {
34
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
57
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
58 /* the array is full */
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
59
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
60 size = a->size * a->nalloc;
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
61
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
62 p = a->pool;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
63
34
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
64 if ((u_char *) a->elts + size == p->last && p->last + a->size <= p->end)
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
65 {
34
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
66 /*
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
67 * the array allocation is the last in the pool
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
68 * and there is space for new allocation
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
69 */
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
70
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
71 p->last += a->size;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
72 a->nalloc++;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
73
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
74 } else {
34
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
75 /* allocate a new array */
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
76
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents: 34
diff changeset
77 new = ngx_palloc(p, 2 * size);
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents: 34
diff changeset
78 if (new == NULL) {
34
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
79 return NULL;
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
80 }
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
81
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
82 ngx_memcpy(new, a->elts, size);
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
83 a->elts = new;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
84 a->nalloc *= 2;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
85 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
86 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
87
34
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
88 elt = (u_char *) a->elts + a->size * a->nelts;
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
89 a->nelts++;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
90
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
91 return elt;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
92 }
34
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
93
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
94
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
95 void *ngx_array_push_n(ngx_array_t *a, ngx_uint_t n)
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
96 {
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
97 void *elt, *new;
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
98 size_t size;
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
99 ngx_uint_t nalloc;
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
100 ngx_pool_t *p;
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
101
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
102 size = n * a->size;
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
103
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
104 if (a->nelts + n > a->nalloc) {
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
105
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
106 /* the array is full */
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
107
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
108 p = a->pool;
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
109
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
110 if ((u_char *) a->elts + a->size * a->nalloc == p->last
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
111 && p->last + size <= p->end)
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
112 {
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
113 /*
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
114 * the array allocation is the last in the pool
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
115 * and there is space for new allocation
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
116 */
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
117
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
118 p->last += size;
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
119 a->nalloc += n;
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
120
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
121 } else {
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
122 /* allocate a new array */
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
123
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
124 nalloc = 2 * ((n >= a->nalloc) ? n : a->nalloc);
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
125
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents: 34
diff changeset
126 new = ngx_palloc(p, nalloc * a->size);
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents: 34
diff changeset
127 if (new == NULL) {
34
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
128 return NULL;
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
129 }
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
130
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
131 ngx_memcpy(new, a->elts, a->nelts * a->size);
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
132 a->elts = new;
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
133 a->nalloc = nalloc;
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
134 }
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
135 }
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
136
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
137 elt = (u_char *) a->elts + a->size * a->nelts;
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
138 a->nelts += n;
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
139
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
140 return elt;
aab2ea7c0458 nginx 0.1.17
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
141 }