mirror of
https://github.com/nginx/nginx.git
synced 2025-06-07 17:52:38 +08:00
nginx-0.0.1-2002-12-26-10:24:21 import
This commit is contained in:
parent
3a17f24836
commit
960ffa42cb
@ -56,12 +56,13 @@ int main(int argc, char *const *argv)
|
||||
|
||||
/* TODO: read config */
|
||||
|
||||
#if 0
|
||||
#if 1
|
||||
ngx_memzero(&conf, sizeof(ngx_conf_t));
|
||||
ngx_test_null(conf.args,
|
||||
ngx_create_array(ngx_pool, 10, sizeof(ngx_str_t)), 1);
|
||||
conf.pool = ngx_pool;
|
||||
conf.log = &ngx_log;
|
||||
conf.modules = ngx_http_modules;
|
||||
|
||||
conf_file.len = sizeof("nginx.conf") - 1;
|
||||
conf_file.data = "nginx.conf";
|
||||
|
@ -12,7 +12,10 @@ static int argument_number[] = {
|
||||
NGX_CONF_TAKE2
|
||||
};
|
||||
|
||||
#if 1
|
||||
static int ngx_conf_read_token(ngx_conf_t *cf);
|
||||
static ngx_command_t *ngx_conf_find_token(ngx_conf_t *cf,
|
||||
ngx_http_module_t **modules);
|
||||
|
||||
|
||||
int ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename)
|
||||
{
|
||||
@ -20,6 +23,7 @@ int ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename)
|
||||
char *error;
|
||||
ngx_fd_t fd;
|
||||
ngx_conf_file_t *prev;
|
||||
ngx_command_t *cmd;
|
||||
|
||||
if (filename) {
|
||||
|
||||
@ -56,16 +60,12 @@ int ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename)
|
||||
for ( ;; ) {
|
||||
rc = ngx_conf_read_token(cf);
|
||||
|
||||
/* ??? NGX_OK, NGX_ERROR, NGX_CONF_FILE_DONE, NGX_CONF_BLOCK_DONE */
|
||||
/* NGX_OK, NGX_ERROR, NGX_CONF_FILE_DONE, NGX_CONF_BLOCK_DONE */
|
||||
|
||||
if (rc != NGX_OK) {
|
||||
if (rc == NGX_ERROR || rc == NGX_CONF_FILE_DONE) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* ????
|
||||
"listen address:port;"
|
||||
"location /images/ {" */
|
||||
|
||||
if (cf->handler) {
|
||||
|
||||
if ((*cf->handler)(cf) == NGX_ERROR) {
|
||||
@ -75,6 +75,8 @@ int ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename)
|
||||
continue;
|
||||
}
|
||||
|
||||
cmd = ngx_conf_find_token(cf);
|
||||
|
||||
#if 0
|
||||
cmd = ngx_conf_find_token(cf);
|
||||
if (cmd == NULL) {
|
||||
@ -164,14 +166,13 @@ int ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename)
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
|
||||
int ngx_conf_read_token(ngx_conf_t *cf)
|
||||
static int ngx_conf_read_token(ngx_conf_t *cf)
|
||||
{
|
||||
char *start, ch, *src, *dst;
|
||||
int found, need_space, last_space, len, quoted, s_quoted, d_quoted;
|
||||
int len;
|
||||
int found, need_space, last_space, sharp_comment;
|
||||
int quoted, s_quoted, d_quoted;
|
||||
ssize_t n;
|
||||
ngx_str_t *word;
|
||||
ngx_hunk_t *h;
|
||||
@ -179,6 +180,7 @@ int ngx_conf_read_token(ngx_conf_t *cf)
|
||||
found = 0;
|
||||
need_space = 0;
|
||||
last_space = 1;
|
||||
sharp_comment = 0;
|
||||
quoted = s_quoted = d_quoted = 0;
|
||||
|
||||
cf->args->nelts = 0;
|
||||
@ -192,7 +194,7 @@ ngx_log_debug(cf->log, "TOKEN START");
|
||||
if (h->pos.mem >= h->last.mem) {
|
||||
if (cf->conf_file->file.offset
|
||||
>= ngx_file_size(cf->conf_file->file.info)) {
|
||||
return NGX_FILE_DONE;
|
||||
return NGX_CONF_FILE_DONE;
|
||||
}
|
||||
|
||||
if (h->pos.mem - start) {
|
||||
@ -223,6 +225,14 @@ ngx_log_debug(cf->log, "%d:%d:%d:%d:%d '%c'" _
|
||||
|
||||
if (ch == LF) {
|
||||
cf->conf_file->line++;
|
||||
|
||||
if (sharp_comment) {
|
||||
sharp_comment = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (sharp_comment) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (quoted) {
|
||||
@ -255,8 +265,31 @@ ngx_log_debug(cf->log, "%d:%d:%d:%d:%d '%c'" _
|
||||
|
||||
case ';':
|
||||
case '{':
|
||||
if (cf->args->nelts == 0) {
|
||||
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
|
||||
"unexpected '%c' in %s:%d",
|
||||
ch, cf->conf_file->file.name.data,
|
||||
cf->conf_file->line);
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
return NGX_OK;
|
||||
|
||||
case '}':
|
||||
if (cf->args->nelts > 0) {
|
||||
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
|
||||
"unexpected '}' in %s:%d",
|
||||
cf->conf_file->file.name.data,
|
||||
cf->conf_file->line);
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
return NGX_CONF_BLOCK_DONE;
|
||||
|
||||
case '#':
|
||||
sharp_comment = 1;
|
||||
continue;
|
||||
|
||||
case '\\':
|
||||
quoted = 1;
|
||||
last_space = 0;
|
||||
@ -334,28 +367,60 @@ ngx_log_debug(cf->log, "FOUND %d:'%s'" _ word->len _ word->data);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
char *ngx_conf_set_size_slot(char *conf, int offset, char *value)
|
||||
static ngx_command_t *ngx_conf_find_token(ngx_conf_t *cf)
|
||||
{
|
||||
int i;
|
||||
ngx_command_t *cmd;
|
||||
|
||||
for (i = 0; cf->modules[i]; i++) {
|
||||
cmd = cf->modules[i]->commands;
|
||||
if (cmd == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
while (cmd->name) {
|
||||
|
||||
ngx_log_debug(cf->log, "command '%s'" _ cmd->name);
|
||||
|
||||
cmd++;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
char *ngx_conf_set_size_slot(ngx_conf_t *cf, char *conf)
|
||||
{
|
||||
int size;
|
||||
ngx_str_t *value;
|
||||
|
||||
size = atoi(value);
|
||||
if (size < 0)
|
||||
value = (ngx_str_t *) cf->args->elts;
|
||||
|
||||
size = atoi(value.data);
|
||||
if (size < 0) {
|
||||
return "value must be greater or equal to zero";
|
||||
}
|
||||
|
||||
*(int *) (conf + cf->offset) = size;
|
||||
|
||||
*(int *) (conf + offset) = size;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *ngx_conf_set_time_slot(char *conf, int offset, char *value)
|
||||
|
||||
char *ngx_conf_set_time_slot(ngx_conf_t *cf, char *conf)
|
||||
{
|
||||
int size;
|
||||
ngx_str_t *value;
|
||||
|
||||
size = atoi(value);
|
||||
if (size < 0)
|
||||
value = (ngx_str_t *) cf->args->elts;
|
||||
|
||||
size = atoi(value.data);
|
||||
if (size < 0) {
|
||||
return "value must be greater or equal to zero";
|
||||
}
|
||||
|
||||
*(int *) (conf + offset) = size;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
@ -6,10 +6,12 @@
|
||||
#include <ngx_files.h>
|
||||
#include <ngx_log.h>
|
||||
#include <ngx_file.h>
|
||||
#include <ngx_string.h>
|
||||
#include <ngx_alloc.h>
|
||||
#include <ngx_hunk.h>
|
||||
#include <ngx_array.h>
|
||||
|
||||
|
||||
#define NGX_CONF_NOARGS 1
|
||||
#define NGX_CONF_TAKE1 2
|
||||
#define NGX_CONF_TAKE2 4
|
||||
@ -19,8 +21,28 @@
|
||||
#define NGX_CONF_UNSET -1
|
||||
|
||||
|
||||
#define NGX_BLOCK_DONE 1
|
||||
#define NGX_FILE_DONE 2
|
||||
#define NGX_CONF_BLOCK_DONE 1
|
||||
#define NGX_CONF_FILE_DONE 2
|
||||
|
||||
|
||||
typedef struct ngx_conf_s ngx_conf_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
ngx_str_t name;
|
||||
char *(*set)(ngx_conf_t *cf);
|
||||
int offset;
|
||||
int zone;
|
||||
int type;
|
||||
} ngx_command_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
void *ctx;
|
||||
ngx_command_t *commands;
|
||||
int type;
|
||||
int (*init_module)(ngx_pool_t *p);
|
||||
} ngx_module_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
@ -29,7 +51,7 @@ typedef struct {
|
||||
int line;
|
||||
} ngx_conf_file_t;
|
||||
|
||||
typedef struct ngx_conf_s ngx_conf_t;
|
||||
|
||||
struct ngx_conf_s {
|
||||
char *name;
|
||||
ngx_array_t *args;
|
||||
@ -38,27 +60,17 @@ struct ngx_conf_s {
|
||||
ngx_conf_file_t *conf_file;
|
||||
ngx_log_t *log;
|
||||
|
||||
ngx_module_t *modules;
|
||||
|
||||
void *ctx;
|
||||
int (*handler)(ngx_conf_t *cf);
|
||||
};
|
||||
|
||||
|
||||
|
||||
typedef struct {
|
||||
char *name;
|
||||
char *(*set)();
|
||||
int offset;
|
||||
int zone;
|
||||
int type;
|
||||
char *description;
|
||||
} ngx_command_t;
|
||||
int ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename);
|
||||
|
||||
|
||||
int ngx_conf_read_token(ngx_conf_t *cf);
|
||||
|
||||
|
||||
char *ngx_conf_set_size_slot(char *conf, int offset, char *value);
|
||||
char *ngx_conf_set_time_slot(char *conf, int offset, char *value);
|
||||
char *ngx_conf_set_size_slot(ngx_conf_t *cf);
|
||||
|
||||
|
||||
#endif _NGX_HTTP_CONFIG_FILE_H_INCLUDED_
|
||||
|
@ -10,8 +10,11 @@ typedef struct {
|
||||
char *data;
|
||||
} ngx_str_t;
|
||||
|
||||
#if (WIN32)
|
||||
|
||||
#define ngx_string(str) { sizeof(str) - 1, str }
|
||||
|
||||
|
||||
#if (WIN32)
|
||||
|
||||
#define ngx_memzero ZeroMemory
|
||||
|
||||
|
@ -189,7 +189,7 @@ int ngx_devpoll_process_events(ngx_log_t *log)
|
||||
ngx_err_t err;
|
||||
ngx_event_t *ev;
|
||||
ngx_connection_t *c;
|
||||
struct dvpoll dvpoll;
|
||||
struct dvpoll dvp;
|
||||
struct timeval tv;
|
||||
|
||||
if (timer_queue.timer_next != &timer_queue) {
|
||||
@ -212,10 +212,10 @@ int ngx_devpoll_process_events(ngx_log_t *log)
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
dvpoll.dp_fds = event_list;
|
||||
dvpoll.dp_nfds = nevents;
|
||||
dvpoll.dp_timeout = timer;
|
||||
events = ioctl(dp, DP_POLL, &dvpoll);
|
||||
dvp.dp_fds = event_list;
|
||||
dvp.dp_nfds = nevents;
|
||||
dvp.dp_timeout = timer;
|
||||
events = ioctl(dp, DP_POLL, &dvp);
|
||||
|
||||
if (events == -1) {
|
||||
ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, "ioctl(DP_POLL) failed");
|
||||
|
@ -14,8 +14,10 @@ int ngx_devpoll_process_events(ngx_log_t *log);
|
||||
|
||||
|
||||
#if 0
|
||||
/* DEBUG */
|
||||
/* Solaris */
|
||||
|
||||
#define POLLREMOVE 0x0800
|
||||
|
||||
#define DP_POLL 0xD001
|
||||
|
||||
struct dvpoll {
|
||||
|
@ -22,7 +22,7 @@ static int max_write;
|
||||
static int max_fd;
|
||||
#endif
|
||||
|
||||
static unsigned int nevents;
|
||||
static u_int nevents;
|
||||
|
||||
static ngx_event_t **event_index;
|
||||
static ngx_event_t **ready_index;
|
||||
@ -174,8 +174,8 @@ int ngx_select_del_event(ngx_event_t *ev, int event, u_int flags)
|
||||
|
||||
int ngx_select_process_events(ngx_log_t *log)
|
||||
{
|
||||
int i, ready, found, nready;
|
||||
u_int timer, delta;
|
||||
int ready, found, nready;
|
||||
u_int i, timer, delta;
|
||||
ngx_event_t *ev;
|
||||
ngx_connection_t *c;
|
||||
struct timeval tv, *tp;
|
||||
|
@ -180,23 +180,32 @@ typedef struct {
|
||||
} ngx_http_log_ctx_t;
|
||||
|
||||
|
||||
typedef int (*ngx_http_output_header_filter_p)(ngx_http_request_t *r);
|
||||
|
||||
typedef int (*ngx_http_output_body_filter_p)
|
||||
(ngx_http_request_t *r, ngx_chain_t *chain);
|
||||
|
||||
|
||||
|
||||
typedef struct {
|
||||
int index;
|
||||
|
||||
void *(*create_srv_conf)(ngx_pool_t *p);
|
||||
void *(*create_loc_conf)(ngx_pool_t *p);
|
||||
ngx_command_t *commands;
|
||||
|
||||
int (*init_module)(ngx_pool_t *p);
|
||||
|
||||
int (*translate_handler)(ngx_http_request_t *r);
|
||||
|
||||
int (*output_header_filter) (ngx_http_request_t *r);
|
||||
int (*next_output_header_filter) (ngx_http_request_t *r);
|
||||
|
||||
ngx_http_output_body_filter_p output_body_filter;
|
||||
ngx_http_output_body_filter_p next_output_body_filter;
|
||||
|
||||
#if 0
|
||||
int (*output_body_filter)();
|
||||
int (*next_output_body_filter)
|
||||
(ngx_http_request_t *r, ngx_chain_t *ch);
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
int (*next_output_body_filter)(int (**next_filter)
|
||||
@ -205,10 +214,19 @@ typedef struct {
|
||||
} ngx_http_module_t;
|
||||
|
||||
|
||||
#define NGX_HTTP_MODULE 0
|
||||
#define NGX_HTTP_MODULE 0x80000000
|
||||
|
||||
#define NGX_HTTP_MODULE_TYPE 0x50545448 /* "HTTP" */
|
||||
|
||||
|
||||
/* STUB */
|
||||
#define ngx_get_module_loc_conf(r, module) r->loc_conf[module.index]
|
||||
#define ngx_get_module_ctx(r, module) r->ctx[module.index]
|
||||
/**/
|
||||
|
||||
#define ngx_http_get_module_srv_conf(r, module) r->srv_conf[module.index]
|
||||
#define ngx_http_get_module_loc_conf(r, module) r->loc_conf[module.index]
|
||||
#define ngx_http_get_module_ctx(r, module) r->ctx[module.index]
|
||||
|
||||
#define ngx_http_create_ctx(r, cx, module, size) \
|
||||
do { \
|
||||
|
@ -10,51 +10,48 @@
|
||||
#include <ngx_http_output_filter.h>
|
||||
|
||||
|
||||
int ngx_http_output_filter(ngx_http_request_t *r, ngx_hunk_t *hunk);
|
||||
static int ngx_http_output_filter(ngx_http_request_t *r, ngx_hunk_t *hunk);
|
||||
static int ngx_http_output_filter_copy_hunk(ngx_hunk_t *dst, ngx_hunk_t *src);
|
||||
#if 0
|
||||
static int ngx_http_output_filter_init(
|
||||
int (**next_filter)(ngx_http_request_t *r, ngx_chain_t *ch));
|
||||
#endif
|
||||
static void *ngx_http_output_filter_create_conf(ngx_pool_t *pool);
|
||||
|
||||
|
||||
static ngx_command_t ngx_http_output_filter_commands[] = {
|
||||
|
||||
{"output_buffer", ngx_conf_set_size_slot,
|
||||
{ngx_string("output_buffer"),
|
||||
ngx_conf_set_size_slot,
|
||||
offsetof(ngx_http_output_filter_conf_t, hunk_size),
|
||||
NGX_HTTP_LOC_CONF, NGX_CONF_TAKE1,
|
||||
"set output filter buffer size"},
|
||||
|
||||
{NULL}
|
||||
NGX_HTTP_LOC_CONF,
|
||||
NGX_CONF_TAKE1},
|
||||
|
||||
{ngx_string(""), NULL, 0, 0, 0}
|
||||
};
|
||||
|
||||
|
||||
ngx_http_module_t ngx_http_output_filter_module = {
|
||||
static ngx_http_module_t ngx_http_output_filter_module_ctx = {
|
||||
NGX_HTTP_MODULE,
|
||||
|
||||
NULL, /* create server config */
|
||||
ngx_http_output_filter_create_conf, /* create location config */
|
||||
ngx_http_output_filter_commands, /* module directives */
|
||||
|
||||
NULL, /* init module */
|
||||
NULL, /* translate handler */
|
||||
|
||||
NULL, /* output header filter */
|
||||
NULL, /* next output header filter */
|
||||
ngx_http_output_filter, /* output body filter */
|
||||
(ngx_http_output_body_filter_p) ngx_http_output_filter,
|
||||
/* output body filter */
|
||||
NULL /* next output body filter */
|
||||
};
|
||||
|
||||
|
||||
#if 0
|
||||
static int (*ngx_http_output_next_filter)(ngx_http_request_t *r,
|
||||
ngx_chain_t *ch);
|
||||
#endif
|
||||
ngx_module_t ngx_http_output_filter_module = {
|
||||
&ngx_http_output_filter_module_ctx, /* module context */
|
||||
ngx_http_output_filter_commands, /* module directives */
|
||||
NGX_HTTP_MODULE_TYPE, /* module type */
|
||||
NULL /* init module */
|
||||
};
|
||||
|
||||
|
||||
int ngx_http_output_filter(ngx_http_request_t *r, ngx_hunk_t *hunk)
|
||||
static int ngx_http_output_filter(ngx_http_request_t *r, ngx_hunk_t *hunk)
|
||||
{
|
||||
int rc, once;
|
||||
size_t size;
|
||||
@ -64,21 +61,18 @@ int ngx_http_output_filter(ngx_http_request_t *r, ngx_hunk_t *hunk)
|
||||
ngx_http_output_filter_conf_t *conf;
|
||||
|
||||
ctx = (ngx_http_output_filter_ctx_t *)
|
||||
ngx_get_module_ctx(r->main ? r->main : r,
|
||||
ngx_http_output_filter_module);
|
||||
ngx_http_get_module_ctx(r->main ? r->main : r,
|
||||
ngx_http_output_filter_module_ctx);
|
||||
|
||||
if (ctx == NULL) {
|
||||
ngx_http_create_ctx(r, ctx,
|
||||
ngx_http_output_filter_module,
|
||||
ngx_http_output_filter_module_ctx,
|
||||
sizeof(ngx_http_output_filter_ctx_t));
|
||||
|
||||
#if 0
|
||||
ctx->next_filter = ngx_http_output_next_filter;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (hunk && (hunk->type & NGX_HUNK_LAST))
|
||||
if (hunk && (hunk->type & NGX_HUNK_LAST)) {
|
||||
ctx->last = 1;
|
||||
}
|
||||
|
||||
for (once = 1; once || ctx->in; once = 0) {
|
||||
|
||||
@ -87,19 +81,17 @@ int ngx_http_output_filter(ngx_http_request_t *r, ngx_hunk_t *hunk)
|
||||
|
||||
/* add hunk to input chain */
|
||||
if (once && hunk) {
|
||||
for (ce = ctx->in; ce->next; ce = ce->next)
|
||||
for (ce = ctx->in; ce->next; ce = ce->next) {
|
||||
/* void */ ;
|
||||
}
|
||||
|
||||
ngx_add_hunk_to_chain(ce->next, hunk, r->pool, NGX_ERROR);
|
||||
}
|
||||
|
||||
/* our hunk is still busy */
|
||||
if (ctx->hunk->pos.mem < ctx->hunk->last.mem) {
|
||||
rc = ngx_http_output_filter_module.
|
||||
rc = ngx_http_output_filter_module_ctx.
|
||||
next_output_body_filter(r, NULL);
|
||||
#if 0
|
||||
rc = ctx->next_filter(r, NULL);
|
||||
#endif
|
||||
|
||||
/* our hunk is free */
|
||||
} else {
|
||||
@ -107,11 +99,13 @@ int ngx_http_output_filter(ngx_http_request_t *r, ngx_hunk_t *hunk)
|
||||
|
||||
rc = ngx_http_output_filter_copy_hunk(ctx->hunk, ctx->in->hunk);
|
||||
#if (NGX_FILE_AIO_READ)
|
||||
if (rc == NGX_AGAIN)
|
||||
if (rc == NGX_AGAIN) {
|
||||
return rc;
|
||||
}
|
||||
#endif
|
||||
if (rc == NGX_ERROR)
|
||||
if (rc == NGX_ERROR) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* whole hunk is copied so we send to next filter chain part
|
||||
up to next hunk that need to be copied */
|
||||
@ -119,13 +113,16 @@ int ngx_http_output_filter(ngx_http_request_t *r, ngx_hunk_t *hunk)
|
||||
ctx->out.next = ctx->in->next;
|
||||
|
||||
for (ce = ctx->in->next; ce; ce = ce->next) {
|
||||
if (ce->hunk->type & NGX_HUNK_FILE)
|
||||
if (ce->hunk->type & NGX_HUNK_FILE) {
|
||||
break;
|
||||
}
|
||||
|
||||
if ((ce->hunk->type & (NGX_HUNK_MEMORY|NGX_HUNK_MMAP))
|
||||
&& (r->filter & NGX_HTTP_FILTER_NEED_TEMP))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ctx->out.next = ce;
|
||||
|
||||
@ -133,33 +130,29 @@ int ngx_http_output_filter(ngx_http_request_t *r, ngx_hunk_t *hunk)
|
||||
ctx->out.next = NULL;
|
||||
}
|
||||
|
||||
rc = ngx_http_output_filter_module.
|
||||
rc = ngx_http_output_filter_module_ctx.
|
||||
next_output_body_filter(r, &ctx->out);
|
||||
#if 0
|
||||
rc = ctx->next_filter(r, &ctx->out);
|
||||
#endif;
|
||||
}
|
||||
|
||||
/* delete completed hunks from input chain */
|
||||
for (ce = ctx->in; ce; ce = ce->next) {
|
||||
if (ce->hunk->pos.file == ce->hunk->last.file)
|
||||
if (ce->hunk->pos.file == ce->hunk->last.file) {
|
||||
ctx->in = ce->next;
|
||||
}
|
||||
}
|
||||
|
||||
if (rc == NGX_OK && ctx->hunk)
|
||||
if (rc == NGX_OK && ctx->hunk) {
|
||||
ctx->hunk->pos.mem = ctx->hunk->last.mem = ctx->hunk->start;
|
||||
else
|
||||
} else {
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* input chain is empty */
|
||||
} else {
|
||||
|
||||
if (hunk == NULL) {
|
||||
rc = ngx_http_output_filter_module.
|
||||
rc = ngx_http_output_filter_module_ctx.
|
||||
next_output_body_filter(r, NULL);
|
||||
#if 0
|
||||
rc = ctx->next_filter(r, NULL);
|
||||
#endif;
|
||||
|
||||
} else {
|
||||
|
||||
@ -175,11 +168,8 @@ int ngx_http_output_filter(ngx_http_request_t *r, ngx_hunk_t *hunk)
|
||||
ngx_add_hunk_to_chain(ctx->in, hunk, r->pool,
|
||||
NGX_ERROR);
|
||||
|
||||
rc = ngx_http_output_filter_module.
|
||||
rc = ngx_http_output_filter_module_ctx.
|
||||
next_output_body_filter(r, NULL);
|
||||
#if 0
|
||||
rc = ctx->next_filter(r, NULL);
|
||||
#endif
|
||||
|
||||
} else {
|
||||
if (ctx->hunk == NULL) {
|
||||
@ -187,12 +177,14 @@ int ngx_http_output_filter(ngx_http_request_t *r, ngx_hunk_t *hunk)
|
||||
if (hunk->type & NGX_HUNK_LAST) {
|
||||
|
||||
conf = (ngx_http_output_filter_conf_t *)
|
||||
ngx_get_module_loc_conf(r->main ? r->main : r,
|
||||
ngx_http_output_filter_module);
|
||||
ngx_http_get_module_loc_conf(
|
||||
r->main ? r->main : r,
|
||||
ngx_http_output_filter_module_ctx);
|
||||
|
||||
size = hunk->last.mem - hunk->pos.mem;
|
||||
if (size > conf->hunk_size)
|
||||
if (size > conf->hunk_size) {
|
||||
size = conf->hunk_size;
|
||||
}
|
||||
|
||||
} else {
|
||||
size = conf->hunk_size;
|
||||
@ -215,21 +207,20 @@ int ngx_http_output_filter(ngx_http_request_t *r, ngx_hunk_t *hunk)
|
||||
return rc;
|
||||
}
|
||||
#endif
|
||||
if (rc == NGX_ERROR)
|
||||
if (rc == NGX_ERROR) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (hunk->pos.mem < hunk->last.mem)
|
||||
if (hunk->pos.mem < hunk->last.mem) {
|
||||
ngx_add_hunk_to_chain(ctx->in, hunk, r->pool,
|
||||
NGX_ERROR);
|
||||
}
|
||||
|
||||
ctx->out.hunk = ctx->hunk;
|
||||
ctx->out.next = NULL;
|
||||
|
||||
rc = ngx_http_output_filter_module.
|
||||
rc = ngx_http_output_filter_module_ctx.
|
||||
next_output_body_filter(r, &ctx->out);
|
||||
#if 0
|
||||
rc = ctx->next_filter(r, &ctx->out);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@ -237,11 +228,8 @@ int ngx_http_output_filter(ngx_http_request_t *r, ngx_hunk_t *hunk)
|
||||
ctx->out.hunk = hunk;
|
||||
ctx->out.next = NULL;
|
||||
|
||||
rc = ngx_http_output_filter_module.
|
||||
rc = ngx_http_output_filter_module_ctx.
|
||||
next_output_body_filter(r, &ctx->out);
|
||||
#if 0
|
||||
rc = ctx->next_filter(r, &ctx->out);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -250,13 +238,15 @@ int ngx_http_output_filter(ngx_http_request_t *r, ngx_hunk_t *hunk)
|
||||
ctx->hunk->pos.mem = ctx->hunk->last.mem = ctx->hunk->start;
|
||||
}
|
||||
|
||||
if (rc == NGX_OK && ctx->last)
|
||||
if (rc == NGX_OK && ctx->last) {
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
if (rc == NGX_OK) {
|
||||
if (ctx->hunk)
|
||||
if (ctx->hunk) {
|
||||
ctx->hunk->pos.mem = ctx->hunk->last.mem = ctx->hunk->start;
|
||||
#if level_event
|
||||
}
|
||||
#if (!NGX_ONESHOT_EVENT)
|
||||
ngx_del_event(r->connection->write, NGX_WRITE_EVENT);
|
||||
#endif
|
||||
}
|
||||
@ -271,8 +261,9 @@ static int ngx_http_output_filter_copy_hunk(ngx_hunk_t *dst, ngx_hunk_t *src)
|
||||
ssize_t n;
|
||||
|
||||
size = src->last.mem - src->pos.mem;
|
||||
if (size > dst->end - dst->pos.mem)
|
||||
if (size > dst->end - dst->pos.mem) {
|
||||
size = dst->end - dst->pos.mem;
|
||||
}
|
||||
|
||||
if (src->type & NGX_HUNK_FILE) {
|
||||
n = ngx_read_file(src->file, dst->pos.mem, size, src->pos.file);
|
||||
@ -301,10 +292,9 @@ static int ngx_http_output_filter_copy_hunk(ngx_hunk_t *dst, ngx_hunk_t *src)
|
||||
dst->last.mem += size;
|
||||
}
|
||||
|
||||
#if 1
|
||||
if (src->type & NGX_HUNK_LAST)
|
||||
if (src->type & NGX_HUNK_LAST) {
|
||||
dst->type |= NGX_HUNK_LAST;
|
||||
#endif
|
||||
}
|
||||
|
||||
return NGX_OK;
|
||||
}
|
||||
@ -322,14 +312,3 @@ static void *ngx_http_output_filter_create_conf(ngx_pool_t *pool)
|
||||
|
||||
return conf;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static int ngx_http_output_filter_init(
|
||||
int (**next_filter)(ngx_http_request_t *r, ngx_chain_t *ch))
|
||||
{
|
||||
ngx_http_output_next_filter = *next_filter;
|
||||
*next_filter = NULL;
|
||||
|
||||
return NGX_OK;
|
||||
}
|
||||
#endif
|
||||
|
@ -14,10 +14,8 @@ typedef struct {
|
||||
size_t hunk_size;
|
||||
} ngx_http_output_filter_conf_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
#if 0
|
||||
int (*next_filter)(ngx_http_request_t *r, ngx_chain_t *ch);
|
||||
#endif
|
||||
ngx_hunk_t *hunk;
|
||||
ngx_chain_t *in;
|
||||
ngx_chain_t out;
|
||||
@ -25,9 +23,7 @@ typedef struct {
|
||||
} ngx_http_output_filter_ctx_t;
|
||||
|
||||
|
||||
int ngx_http_output_filter(ngx_http_request_t *r, ngx_hunk_t *hunk);
|
||||
|
||||
extern ngx_http_module_t ngx_http_output_filter_module;
|
||||
extern ngx_module_t ngx_http_output_filter_module;
|
||||
|
||||
|
||||
#endif /* _NGX_HTTP_OUTPUT_FILTER_H_INCLUDED_ */
|
||||
|
Loading…
Reference in New Issue
Block a user