Mercurial > hg > nginx
comparison 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 |
comparison
equal
deleted
inserted
replaced
506:005e65646622 | 507:cd3117ad9aab |
---|---|
7 #include <ngx_config.h> | 7 #include <ngx_config.h> |
8 #include <ngx_core.h> | 8 #include <ngx_core.h> |
9 #include <ngx_http.h> | 9 #include <ngx_http.h> |
10 | 10 |
11 | 11 |
12 u_char *ngx_http_script_copy(ngx_http_request_t *r, u_char *buf, void *data) | 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) | |
13 { | 17 { |
14 u_char **p = data; | 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; | |
15 | 23 |
16 ngx_http_script_code_t *code; | 24 if (sources->nelts == 0) { |
25 return NGX_OK; | |
26 } | |
17 | 27 |
18 code = (ngx_http_script_code_t *) | 28 if (*lengths == NULL) { |
19 ((char *) data - sizeof(ngx_http_script_code_t)); | 29 *lengths = ngx_array_create(cf->pool, 64, 1); |
30 if (*lengths == NULL) { | |
31 return NGX_ERROR; | |
32 } | |
33 } | |
20 | 34 |
21 return ngx_cpymem(buf, *p, code->data_len); | 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; | |
22 } | 107 } |
23 | 108 |
24 | 109 |
25 u_char *ngx_http_script_header_in(ngx_http_request_t *r, | 110 #if 0 |
26 u_char *buf, void *data) | 111 |
112 static void * | |
113 ngx_http_script_start_code(ngx_pool_t *pool, ngx_array_t **codes, size_t size) | |
27 { | 114 { |
28 size_t *offset = data; | 115 if (*codes == NULL) { |
116 *codes = ngx_array_create(pool, 256, 1); | |
117 if (*codes == NULL) { | |
118 return NULL; | |
119 } | |
120 } | |
29 | 121 |
30 ngx_table_elt_t *h; | 122 return ngx_array_push_n(*codes, size); |
123 } | |
31 | 124 |
32 h = *(ngx_table_elt_t **) (((char *) r->headers_in) + *offset); | 125 #endif |
33 | 126 |
34 return ngx_cpymem(p, h->value.data, h->value.len); | 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; | |
35 } | 138 } |
36 | 139 |
37 | 140 |
38 u_char *ngx_http_script_request_line(ngx_http_request_t *r, | 141 void |
39 u_char *buf, void *data) | 142 ngx_http_script_copy(ngx_http_script_engine_t *e) |
40 { | 143 { |
41 return ngx_cpymem(p, r->request_line.data, r->request_line.len); | 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)); | |
42 } | 154 } |
43 | 155 |
44 | 156 |
45 u_char *ngx_http_script_status(ngx_http_request_t *r, u_char *buf, void *data) | 157 size_t |
158 ngx_http_script_copy_var_len(ngx_http_script_engine_t *e) | |
46 { | 159 { |
47 return ngx_sprintf(buf, "%ui", r->headers_out.status); | 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; | |
48 } | 174 } |
49 | 175 |
50 | 176 |
51 u_char *ngx_http_script_sent(ngx_http_request_t *r, u_char *buf, void *data) | 177 void |
178 ngx_http_script_copy_var(ngx_http_script_engine_t *e) | |
52 { | 179 { |
53 return ngx_sprintf(buf, "%O", r->connection->sent); | 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); | |
54 } | 194 } |