Mercurial > hg > nginx
annotate src/http/ngx_http_script.c @ 507:cd3117ad9aab release-0.1.28
nginx-0.1.28-RELEASE import
*) Bugfix: nginx hogs CPU while proxying the huge files.
*) Bugfix: nginx could not be built by gcc 4.0 on Linux.
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Fri, 08 Apr 2005 15:18:55 +0000 |
parents | c52408583801 |
children | 9b8c906f6e63 |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
99
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
99
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
99
diff
changeset
|
4 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
99
diff
changeset
|
5 |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
6 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 #include <ngx_config.h> |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_core.h> |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #include <ngx_http.h> |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
507 | 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) | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
17 { |
507 | 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 } | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
58 |
507 | 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 | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
79 |
507 | 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 } | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
91 |
507 | 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; | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
107 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
108 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
109 |
507 | 110 #if 0 |
111 | |
112 static void * | |
113 ngx_http_script_start_code(ngx_pool_t *pool, ngx_array_t **codes, size_t size) | |
479 | 114 { |
507 | 115 if (*codes == NULL) { |
116 *codes = ngx_array_create(pool, 256, 1); | |
117 if (*codes == NULL) { | |
118 return NULL; | |
119 } | |
120 } | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
121 |
507 | 122 return ngx_array_push_n(*codes, size); |
123 } | |
124 | |
125 #endif | |
126 | |
479 | 127 |
507 | 128 size_t |
129 ngx_http_script_copy_len(ngx_http_script_engine_t *e) | |
130 { | |
131 ngx_http_script_copy_code_t *code; | |
479 | 132 |
507 | 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; | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
138 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
139 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
140 |
507 | 141 void |
142 ngx_http_script_copy(ngx_http_script_engine_t *e) | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
143 { |
507 | 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)); | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
154 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
155 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
156 |
507 | 157 size_t |
158 ngx_http_script_copy_var_len(ngx_http_script_engine_t *e) | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
159 { |
507 | 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; | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
174 } |
479 | 175 |
176 | |
507 | 177 void |
178 ngx_http_script_copy_var(ngx_http_script_engine_t *e) | |
479 | 179 { |
507 | 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); | |
479 | 194 } |