Mercurial > hg > nginx-mail
comparison src/http/ngx_http_script.c @ 56:3050baa54a26 NGINX_0_1_28
nginx 0.1.28
*) Bugfix: nginx hogs CPU while proxying the huge files.
*) Bugfix: nginx could not be built by gcc 4.0 on Linux.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Fri, 08 Apr 2005 00:00:00 +0400 |
parents | |
children | b55cbf18157e |
comparison
equal
deleted
inserted
replaced
55:729de7d75018 | 56:3050baa54a26 |
---|---|
1 | |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4 */ | |
5 | |
6 | |
7 #include <ngx_config.h> | |
8 #include <ngx_core.h> | |
9 #include <ngx_http.h> | |
10 | |
11 | |
12 ngx_int_t | |
13 ngx_http_script_compile_lite(ngx_conf_t *cf, ngx_array_t *sources, | |
14 ngx_array_t **lengths, ngx_array_t **values, | |
15 ngx_http_script_compile_lite_start_pt start, | |
16 ngx_http_script_compile_lite_end_pt end) | |
17 { | |
18 uintptr_t *code; | |
19 ngx_uint_t i; | |
20 ngx_table_elt_t *src; | |
21 ngx_http_variable_t *var; | |
22 ngx_http_script_var_code_t *var_code; | |
23 | |
24 if (sources->nelts == 0) { | |
25 return NGX_OK; | |
26 } | |
27 | |
28 if (*lengths == NULL) { | |
29 *lengths = ngx_array_create(cf->pool, 64, 1); | |
30 if (*lengths == NULL) { | |
31 return NGX_ERROR; | |
32 } | |
33 } | |
34 | |
35 if (*values == NULL) { | |
36 *values = ngx_array_create(cf->pool, 256, 1); | |
37 if (*values == NULL) { | |
38 return NGX_ERROR; | |
39 } | |
40 } | |
41 | |
42 src = sources->elts; | |
43 for (i = 0; i < sources->nelts; i++) { | |
44 | |
45 if (src[i].value.data[0] == '$') { | |
46 if (start(&src[i], *lengths, *values, 0) != NGX_OK) { | |
47 return NGX_ERROR; | |
48 } | |
49 | |
50 src[i].value.len--; | |
51 src[i].value.data++; | |
52 | |
53 var = ngx_http_add_variable(cf, &src[i].value, 0); | |
54 | |
55 if (var == NULL) { | |
56 return NGX_ERROR; | |
57 } | |
58 | |
59 var_code = ngx_array_push_n(*lengths, | |
60 sizeof(ngx_http_script_var_code_t)); | |
61 if (var_code == NULL) { | |
62 return NGX_ERROR; | |
63 } | |
64 | |
65 var_code->code = (ngx_http_script_code_pt) | |
66 ngx_http_script_copy_var_len; | |
67 var_code->index = var->index; | |
68 | |
69 | |
70 var_code = ngx_array_push_n(*values, | |
71 sizeof(ngx_http_script_var_code_t)); | |
72 if (var_code == NULL) { | |
73 return NGX_ERROR; | |
74 } | |
75 | |
76 var_code->code = ngx_http_script_copy_var; | |
77 var_code->index = var->index; | |
78 | |
79 | |
80 if (end(*lengths, *values) != NGX_OK) { | |
81 return NGX_ERROR; | |
82 } | |
83 | |
84 continue; | |
85 } | |
86 | |
87 if (start(&src[i], *lengths, *values, 1) != NGX_OK) { | |
88 return NGX_ERROR; | |
89 } | |
90 } | |
91 | |
92 code = ngx_array_push_n(*lengths, sizeof(uintptr_t)); | |
93 if (code == NULL) { | |
94 return NGX_ERROR; | |
95 } | |
96 | |
97 *code = (uintptr_t) NULL; | |
98 | |
99 code = ngx_array_push_n(*values, sizeof(uintptr_t)); | |
100 if (code == NULL) { | |
101 return NGX_ERROR; | |
102 } | |
103 | |
104 *code = (uintptr_t) NULL; | |
105 | |
106 return NGX_OK; | |
107 } | |
108 | |
109 | |
110 #if 0 | |
111 | |
112 static void * | |
113 ngx_http_script_start_code(ngx_pool_t *pool, ngx_array_t **codes, size_t size) | |
114 { | |
115 if (*codes == NULL) { | |
116 *codes = ngx_array_create(pool, 256, 1); | |
117 if (*codes == NULL) { | |
118 return NULL; | |
119 } | |
120 } | |
121 | |
122 return ngx_array_push_n(*codes, size); | |
123 } | |
124 | |
125 #endif | |
126 | |
127 | |
128 size_t | |
129 ngx_http_script_copy_len(ngx_http_script_engine_t *e) | |
130 { | |
131 ngx_http_script_copy_code_t *code; | |
132 | |
133 code = (ngx_http_script_copy_code_t *) e->lite.ip; | |
134 | |
135 e->lite.ip += sizeof(ngx_http_script_copy_code_t); | |
136 | |
137 return code->len; | |
138 } | |
139 | |
140 | |
141 void | |
142 ngx_http_script_copy(ngx_http_script_engine_t *e) | |
143 { | |
144 ngx_http_script_copy_code_t *code; | |
145 | |
146 code = (ngx_http_script_copy_code_t *) e->lite.ip; | |
147 | |
148 e->lite.pos = ngx_cpymem(e->lite.pos, | |
149 e->lite.ip + sizeof(ngx_http_script_copy_code_t), | |
150 code->len); | |
151 | |
152 e->lite.ip += sizeof(ngx_http_script_copy_code_t) | |
153 + ((code->len + sizeof(uintptr_t) - 1) & ~(sizeof(uintptr_t) - 1)); | |
154 } | |
155 | |
156 | |
157 size_t | |
158 ngx_http_script_copy_var_len(ngx_http_script_engine_t *e) | |
159 { | |
160 ngx_http_variable_value_t *value; | |
161 ngx_http_script_var_code_t *code; | |
162 | |
163 code = (ngx_http_script_var_code_t *) e->lite.ip; | |
164 | |
165 e->lite.ip += sizeof(ngx_http_script_var_code_t); | |
166 | |
167 value = ngx_http_get_indexed_variable(e->lite.request, code->index); | |
168 | |
169 if (value == NULL || value == NGX_HTTP_VARIABLE_NOT_FOUND) { | |
170 return 0; | |
171 } | |
172 | |
173 return value->text.len; | |
174 } | |
175 | |
176 | |
177 void | |
178 ngx_http_script_copy_var(ngx_http_script_engine_t *e) | |
179 { | |
180 ngx_http_variable_value_t *value; | |
181 ngx_http_script_var_code_t *code; | |
182 | |
183 code = (ngx_http_script_var_code_t *) e->lite.ip; | |
184 | |
185 e->lite.ip += sizeof(ngx_http_script_var_code_t); | |
186 | |
187 value = ngx_http_get_indexed_variable(e->lite.request, code->index); | |
188 | |
189 if (value == NULL || value == NGX_HTTP_VARIABLE_NOT_FOUND) { | |
190 return; | |
191 } | |
192 | |
193 e->lite.pos = ngx_cpymem(e->lite.pos, value->text.data, value->text.len); | |
194 } |