Mercurial > hg > nginx
changeset 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 | a490ad05164d |
files | src/core/ngx_hunk.h src/http/modules/ngx_http_ssi_filter.c |
diffstat | 2 files changed, 156 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/src/core/ngx_hunk.h +++ b/src/core/ngx_hunk.h @@ -22,6 +22,10 @@ /* the hunk is in file */ #define NGX_HUNK_FILE 0x0100 +#define NGX_HUNK_STORAGE (NGX_HUNK_IN_MEMORY + |NGX_HUNK_TEMP|NGX_HUNK_MEMORY|NGX_HUNK_MMAP + |NGX_HUNK_RECYCLED|NGX_HUNK_FILE) + /* hunk flags */ /* in thread state flush means to write the hunk completely before return */
--- a/src/http/modules/ngx_http_ssi_filter.c +++ b/src/http/modules/ngx_http_ssi_filter.c @@ -60,6 +60,19 @@ static int (*next_body_filter) (ngx_http static char comment_string[] = "<!--"; +static int ngx_http_ssi_header_filter(ngx_http_request_t *r) +{ + ngx_http_ssi_ctx_t *ctx; + + /* if () */ { + ngx_http_create_ctx(r, ctx, ngx_http_ssi_filter_module, + sizeof(ngx_http_ssi_ctx_t), NGX_ERROR); + } + + return NGX_OK; +} + + static int ngx_http_ssi_body_filter(ngx_http_request_t *r, ngx_chain_t *in) { ngx_chain_t chain; @@ -67,13 +80,37 @@ static int ngx_http_ssi_body_filter(ngx_ ctx = ngx_http_get_module_ctx(r, ngx_http_ssi_filter_module); - if (ctx == NULL) { - ngx_http_create_ctx(r, ctx, ngx_http_ssi_filter_module, - sizeof(ngx_http_ssi_ctx_t), NGX_ERROR); + if ((ctx == NULL) || (in == NULL && ctx->out == NULL)) { + return next_body_filter(r, NULL); } - if (in == NULL && ctx->out == NULL) { - return next_body_filter(r, NULL); + if (ctx->hunk && + (((ctx->hunk->type & NGX_HUNK_FILE) + && (ctx->hunk->file_pos < ctx->hunk->file_last)) + || ((ctx->hunk->type & NGX_HUNK_IN_MEMORY) + && (ctx->hunk->pos < ctx->hunk->last)))) + { + rc = next_body_filter(r, NULL); + + if (rc == NGX_ERROR) { + return NGX_ERROR; + } + + if (ctx->hunk->shadow) { + if (ctx->hunk->type & NGX_HUNK_FILE) { + ctx->hunk->shadow->file_pos = ctx->hunk->file_pos; + } + + if (ctx->hunk->type & NGX_HUNK_IN_MEMORY) { + ctx->hunk->shadow->pos = ctx->hunk->pos; + } + } + + if (rc == NGX_AGAIN) { + return NGX_AGAIN; + } + + } #if 0 @@ -81,16 +118,10 @@ static int ngx_http_ssi_body_filter(ngx_ add in to ctx->out chain while (ctx->out) { - rc = ngx_http_ssi_parse(r, ctx, ctx->out->hunk); + rc == ngx_http_ssi_exec(r, ctx); - if (rc == NGX_HTTP_SSI_DONE) { - chain.hunk = ctx->out->hunk; - chain.next = NULL; - - rc = next_body_filter(r, &chain); - if (rc != NGX_OK) { - return rc; - } + if (rc != NGX_ERROR) { + return rc; } ctx->out = ctx->out->next; @@ -102,8 +133,115 @@ static int ngx_http_ssi_body_filter(ngx_ } +#if 0 + while (ctx->out) { + rc = ngx_http_ssi_parse(r, ctx, ctx->out->hunk); + + if (rc == NGX_ERROR) { + return rc; + } + + if (rc == NGX_OK) { + ngx_test_null(temp, ngx_calloc_hunk(r->pool), NGX_ERROR); + temp->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_TEMP; + temp->pos = comment_string; + temp->last = comment_string + looked; + } + + if (rc == NGX_HTTP_SSI_DONE) { + + + - looked + + chain.hunk = ctx->out->hunk; + chain.next = NULL; + + rc = next_body_filter(r, &chain); + + if (rc != NGX_OK) { + ctx->out = ctx->out->next; + return rc; + } + + } else if (rc == NGX_HTTP_SSI_INVALID_COMMAND) { + } else if (rc == NGX_HTTP_SSI_INVALID_PARAM) { + } else if (rc == NGX_HTTP_SSI_INVALID_VALUE) { + } else if (rc == NGX_HTTP_SSI_LONG_VALUE) { + } + + ctx->out = ctx->out->next; + } + +#endif + + + + + +#if 0 + +static int ngx_http_ssi_copy_opcode(ngx_http_request_t *r, + ngx_http_ssi_ctx_t *ctx, void *data) +{ + ngx_http_ssi_copy_t *copy = data; + + ngx_hunk_t *h; + ngx_chain_t chain; + + h = ctx->out->hunk; + + if (ctx->looked == 0 && ctx->pos == h->last) { + chain.hunk = h; + chain.next = NULL; + + return next_body_filter(r, &chain); + } + + if (ctx->hunk == NULL) { + ngx_test_null(ctx->hunk, ngx_calloc_hunk(r->pool), NGX_ERROR); + ctx->hunk->type = h->type & NGX_HUNK_STORAGE; + } + + + if (h->type & NGX_HUNK_FILE) { + if (copy->start <= h->file_pos) { + ctx->hunk->file_pos = h->file_pos; + } else if (copy->start < h->file_last) { + ctx->hunk->file_pos = copy->file_pos; + } + + if (copy->end >= h->file_last) { + ctx->hunk->file_last = h->file_last; + } else if (copy->end > h->file_pos) { + } + + } + + if (h->type & NGX_HUNK_IN_MEMORY) { + if (copy->start <= ctx->offset + (h->pos - h->start)) { + ctx->hunk->pos = h->pos; + } else if (copy->start < ctx->offset + (h->last - h->start)) { + ctx->hunk->pos = h->start + (copy->start - ctx->offset); + } + + if (copy->end >= ctx->offset + (h->last - h->start) { + ctx->hunk->last = h->last; + } else if (copy->end > ctx->offset + (h->pos - h->start)) { + ctx->hunk->last = h->start + (copy->end - ctx->offset); + } + } + + /* TODO: NGX_HUNK_FLUSH */ + + if ((h->type & NGX_HUNK_LAST) && ctx->hunk->last == h->last) + + /* LAST */ +} + +#endif + static int ngx_http_ssi_parse(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx, @@ -504,10 +642,8 @@ static int ngx_http_ssi_parse(ngx_http_r static int ngx_http_ssi_filter_init(ngx_cycle_t *cycle) { -#if 0 next_header_filter = ngx_http_top_header_filter; ngx_http_top_header_filter = ngx_http_ssi_header_filter; -#endif next_body_filter = ngx_http_top_body_filter; ngx_http_top_body_filter = ngx_http_ssi_body_filter;