comparison src/http/modules/ngx_http_ssi_filter.c @ 129:7a886b9a67dc

nginx-0.0.1-2003-08-10-20:14:37 import
author Igor Sysoev <igor@sysoev.ru>
date Sun, 10 Aug 2003 16:14:37 +0000
parents 1947c683490f
children 049e78b1f852
comparison
equal deleted inserted replaced
128:1947c683490f 129:7a886b9a67dc
58 58
59 59
60 static char comment_string[] = "<!--"; 60 static char comment_string[] = "<!--";
61 61
62 62
63 static int ngx_http_ssi_header_filter(ngx_http_request_t *r)
64 {
65 ngx_http_ssi_ctx_t *ctx;
66
67 /* if () */ {
68 ngx_http_create_ctx(r, ctx, ngx_http_ssi_filter_module,
69 sizeof(ngx_http_ssi_ctx_t), NGX_ERROR);
70 }
71
72 return NGX_OK;
73 }
74
75
63 static int ngx_http_ssi_body_filter(ngx_http_request_t *r, ngx_chain_t *in) 76 static int ngx_http_ssi_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
64 { 77 {
65 ngx_chain_t chain; 78 ngx_chain_t chain;
66 ngx_http_ssi_ctx_t *ctx; 79 ngx_http_ssi_ctx_t *ctx;
67 80
68 ctx = ngx_http_get_module_ctx(r, ngx_http_ssi_filter_module); 81 ctx = ngx_http_get_module_ctx(r, ngx_http_ssi_filter_module);
69 82
70 if (ctx == NULL) { 83 if ((ctx == NULL) || (in == NULL && ctx->out == NULL)) {
71 ngx_http_create_ctx(r, ctx, ngx_http_ssi_filter_module,
72 sizeof(ngx_http_ssi_ctx_t), NGX_ERROR);
73 }
74
75 if (in == NULL && ctx->out == NULL) {
76 return next_body_filter(r, NULL); 84 return next_body_filter(r, NULL);
77 } 85 }
78 86
87 if (ctx->hunk &&
88 (((ctx->hunk->type & NGX_HUNK_FILE)
89 && (ctx->hunk->file_pos < ctx->hunk->file_last))
90 || ((ctx->hunk->type & NGX_HUNK_IN_MEMORY)
91 && (ctx->hunk->pos < ctx->hunk->last))))
92 {
93 rc = next_body_filter(r, NULL);
94
95 if (rc == NGX_ERROR) {
96 return NGX_ERROR;
97 }
98
99 if (ctx->hunk->shadow) {
100 if (ctx->hunk->type & NGX_HUNK_FILE) {
101 ctx->hunk->shadow->file_pos = ctx->hunk->file_pos;
102 }
103
104 if (ctx->hunk->type & NGX_HUNK_IN_MEMORY) {
105 ctx->hunk->shadow->pos = ctx->hunk->pos;
106 }
107 }
108
109 if (rc == NGX_AGAIN) {
110 return NGX_AGAIN;
111 }
112
113
114 }
115
79 #if 0 116 #if 0
80 117
81 add in to ctx->out chain 118 add in to ctx->out chain
119
120 while (ctx->out) {
121 rc == ngx_http_ssi_exec(r, ctx);
122
123 if (rc != NGX_ERROR) {
124 return rc;
125 }
126
127 ctx->out = ctx->out->next;
128 }
129
130 #endif
131
132 return NGX_OK;
133 }
134
135
136 #if 0
137
82 138
83 while (ctx->out) { 139 while (ctx->out) {
84 rc = ngx_http_ssi_parse(r, ctx, ctx->out->hunk); 140 rc = ngx_http_ssi_parse(r, ctx, ctx->out->hunk);
85 141
142 if (rc == NGX_ERROR) {
143 return rc;
144 }
145
146 if (rc == NGX_OK) {
147 ngx_test_null(temp, ngx_calloc_hunk(r->pool), NGX_ERROR);
148 temp->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_TEMP;
149 temp->pos = comment_string;
150 temp->last = comment_string + looked;
151 }
152
86 if (rc == NGX_HTTP_SSI_DONE) { 153 if (rc == NGX_HTTP_SSI_DONE) {
154
155
156 - looked
157
87 chain.hunk = ctx->out->hunk; 158 chain.hunk = ctx->out->hunk;
88 chain.next = NULL; 159 chain.next = NULL;
89 160
90 rc = next_body_filter(r, &chain); 161 rc = next_body_filter(r, &chain);
162
91 if (rc != NGX_OK) { 163 if (rc != NGX_OK) {
164 ctx->out = ctx->out->next;
92 return rc; 165 return rc;
93 } 166 }
167
168 } else if (rc == NGX_HTTP_SSI_INVALID_COMMAND) {
169 } else if (rc == NGX_HTTP_SSI_INVALID_PARAM) {
170 } else if (rc == NGX_HTTP_SSI_INVALID_VALUE) {
171 } else if (rc == NGX_HTTP_SSI_LONG_VALUE) {
94 } 172 }
95 173
96 ctx->out = ctx->out->next; 174 ctx->out = ctx->out->next;
97 } 175 }
98 176
99 #endif 177 #endif
100 178
101 return NGX_OK; 179
180
181
182
183 #if 0
184
185 static int ngx_http_ssi_copy_opcode(ngx_http_request_t *r,
186 ngx_http_ssi_ctx_t *ctx, void *data)
187 {
188 ngx_http_ssi_copy_t *copy = data;
189
190 ngx_hunk_t *h;
191 ngx_chain_t chain;
192
193 h = ctx->out->hunk;
194
195 if (ctx->looked == 0 && ctx->pos == h->last) {
196 chain.hunk = h;
197 chain.next = NULL;
198
199 return next_body_filter(r, &chain);
200 }
201
202 if (ctx->hunk == NULL) {
203 ngx_test_null(ctx->hunk, ngx_calloc_hunk(r->pool), NGX_ERROR);
204 ctx->hunk->type = h->type & NGX_HUNK_STORAGE;
205 }
206
207
208 if (h->type & NGX_HUNK_FILE) {
209 if (copy->start <= h->file_pos) {
210 ctx->hunk->file_pos = h->file_pos;
211 } else if (copy->start < h->file_last) {
212 ctx->hunk->file_pos = copy->file_pos;
213 }
214
215 if (copy->end >= h->file_last) {
216 ctx->hunk->file_last = h->file_last;
217 } else if (copy->end > h->file_pos) {
218 }
219
220 }
221
222 if (h->type & NGX_HUNK_IN_MEMORY) {
223 if (copy->start <= ctx->offset + (h->pos - h->start)) {
224 ctx->hunk->pos = h->pos;
225 } else if (copy->start < ctx->offset + (h->last - h->start)) {
226 ctx->hunk->pos = h->start + (copy->start - ctx->offset);
227 }
228
229 if (copy->end >= ctx->offset + (h->last - h->start) {
230 ctx->hunk->last = h->last;
231 } else if (copy->end > ctx->offset + (h->pos - h->start)) {
232 ctx->hunk->last = h->start + (copy->end - ctx->offset);
233 }
234 }
235
236 /* TODO: NGX_HUNK_FLUSH */
237
238 if ((h->type & NGX_HUNK_LAST) && ctx->hunk->last == h->last)
239
240 /* LAST */
102 } 241 }
103 242
104 243 #endif
105
106 244
107 245
108 246
109 static int ngx_http_ssi_parse(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx, 247 static int ngx_http_ssi_parse(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx,
110 ngx_hunk_t *h) 248 ngx_hunk_t *h)
502 } 640 }
503 641
504 642
505 static int ngx_http_ssi_filter_init(ngx_cycle_t *cycle) 643 static int ngx_http_ssi_filter_init(ngx_cycle_t *cycle)
506 { 644 {
507 #if 0
508 next_header_filter = ngx_http_top_header_filter; 645 next_header_filter = ngx_http_top_header_filter;
509 ngx_http_top_header_filter = ngx_http_ssi_header_filter; 646 ngx_http_top_header_filter = ngx_http_ssi_header_filter;
510 #endif
511 647
512 next_body_filter = ngx_http_top_body_filter; 648 next_body_filter = ngx_http_top_body_filter;
513 ngx_http_top_body_filter = ngx_http_ssi_body_filter; 649 ngx_http_top_body_filter = ngx_http_ssi_body_filter;
514 650
515 return NGX_OK; 651 return NGX_OK;