nginx-0.0.1-2003-10-23-19:54:19 import

This commit is contained in:
Igor Sysoev 2003-10-23 15:54:19 +00:00
parent f107910a9e
commit 8556e6da41
6 changed files with 239 additions and 221 deletions

View File

@ -19,7 +19,6 @@ static int argument_number[] = {
NGX_CONF_TAKE7,
NGX_CONF_TAKE8,
NGX_CONF_TAKE9,
NGX_CONF_TAKE10
};
static int ngx_conf_read_token(ngx_conf_t *cf);
@ -625,47 +624,22 @@ char *ngx_conf_set_size_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
char *p = conf;
int size, len, scale, *np;
char last;
int *np;
ngx_str_t *value;
np = (int *) (p + cmd->offset);
if (*np != NGX_CONF_UNSET) {
return "is duplicate";
}
value = (ngx_str_t *) cf->args->elts;
len = value[1].len;
last = value[1].data[len - 1];
switch (last) {
case 'K':
case 'k':
len--;
scale = 1024;
break;
case 'M':
case 'm':
len--;
scale = 1024 * 1024;
break;
default:
scale = 1;
}
size = ngx_atoi(value[1].data, len);
if (size == NGX_ERROR) {
*np = ngx_parse_size(&value[1]);
if (*np == NGX_ERROR) {
return "invalid value";
}
size *= scale;
*np = size;
if (cmd->bounds) {
return cmd->bounds->check(cf, cmd->bounds, np);
}
@ -685,90 +659,20 @@ char *ngx_conf_set_msec_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
np = (int *) (p + cmd->offset);
if (*np != NGX_CONF_UNSET) {
return "is duplicate";
}
value = (ngx_str_t *) cf->args->elts;
start = value[1].data;
len = 0;
total = 0;
for (i = 0; /* void */ ; i++) {
if (i < value[1].len) {
if (value[1].data[i] != ' ') {
len++;
continue;
}
if (value[1].data[i] == ' ' && len == 0) {
start = &value[1].data[i + 1];
continue;
}
}
if (len == 0) {
break;
}
last = value[1].data[i - 1];
switch (last) {
case 'm':
len--;
max = 35791;
scale = 1000 * 60;
break;
case 'h':
len--;
max = 596;
scale = 1000 * 60 * 60;
break;
case 'd':
len--;
max = 24;
scale = 1000 * 60 * 60 * 24;
break;
case 's':
len--;
if (value[1].data[i - 2] == 'm') {
len--;
max = 2147483647;
scale = 1;
break;
}
/* fall thru */
default:
max = 2147483;
scale = 1000;
}
size = ngx_atoi(start, len);
if (size < 0) {
return "invalid value";
}
if ((u_int) size > max) {
return "value must be less than 597 hours";
}
total += size * scale;
if (i >= value[1].len) {
break;
}
len = 0;
start = &value[1].data[i + 1];
*np = ngx_parse_time(&value[1], 0);
if (*np == NGX_ERROR) {
return "invalid value";
}
*np = total;
if (*np == NGX_PARSE_LARGE_TIME) {
return "value must be less than 597 hours";
}
if (cmd->bounds) {
return cmd->bounds->check(cf, cmd->bounds, np);
@ -789,102 +693,20 @@ char *ngx_conf_set_sec_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
np = (int *) (p + cmd->offset);
if (*np != NGX_CONF_UNSET) {
return "is duplicate";
}
value = (ngx_str_t *) cf->args->elts;
start = value[1].data;
len = 0;
total = 0;
for (i = 0; /* void */ ; i++) {
if (i < value[1].len) {
if (value[1].data[i] != ' ') {
len++;
continue;
}
if (value[1].data[i] == ' ' && len == 0) {
start = &value[1].data[i + 1];
continue;
}
}
if (len == 0) {
break;
}
last = value[1].data[i - 1];
switch (last) {
case 'm':
len--;
max = 35791394;
scale = 60;
break;
case 'h':
len--;
max = 596523;
scale = 60 * 60;
break;
case 'd':
len--;
max = 24855;
scale = 60 * 60 * 24;
break;
case 'w':
len--;
max = 3550;
scale = 60 * 60 * 24 * 7;
break;
case 'M':
len--;
max = 828;
scale = 60 * 60 * 24 * 30;
break;
case 'y':
len--;
max = 68;
scale = 60 * 60 * 24 * 365;
break;
case 's':
len--;
/* fall thru */
default:
max = 2147483647;
scale = 1;
}
size = ngx_atoi(start, len);
if (size < 0) {
return "invalid value";
}
if ((u_int) size > max) {
return "value must be less than 68 years";
}
total += size * scale;
if (i >= value[1].len) {
break;
}
len = 0;
start = &value[1].data[i + 1];
*np = ngx_parse_time(&value[1], 1);
if (*np == NGX_ERROR) {
return "invalid value";
}
*np = total;
if (*np == NGX_PARSE_LARGE_TIME) {
return "value must be less than 68 years";
}
if (cmd->bounds) {
return cmd->bounds->check(cf, cmd->bounds, np);
@ -898,14 +720,11 @@ char *ngx_conf_set_bufs_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
char *p = conf;
int len, scale;
char last;
ngx_str_t *value;
ngx_bufs_t *bufs;
bufs = (ngx_bufs_t *) (p + cmd->offset);
if (bufs->num) {
return "is duplicate";
}
@ -917,33 +736,11 @@ char *ngx_conf_set_bufs_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
return "invalid value";
}
len = value[2].len;
last = value[2].data[len - 1];
switch (last) {
case 'K':
case 'k':
len--;
scale = 1024;
break;
case 'M':
case 'm':
len--;
scale = 1024 * 1024;
break;
default:
scale = 1;
}
bufs->size = ngx_atoi(value[2].data, len);
bufs->size = ngx_parse_size(&value[2]);
if (bufs->size == NGX_ERROR || bufs->size == 0) {
return "invalid value";
}
bufs->size *= scale;
return NGX_CONF_OK;
}

View File

@ -22,7 +22,6 @@
#define NGX_CONF_TAKE7 0x00000080
#define NGX_CONF_TAKE8 0x00000100
#define NGX_CONF_TAKE9 0x00000200
#define NGX_CONF_TAKE10 0x00000400
#define NGX_CONF_TAKE1234 (NGX_CONF_TAKE1|NGX_CONF_TAKE2|NGX_CONF_TAKE3 \
|NGX_CONF_TAKE4)

View File

@ -19,6 +19,7 @@ typedef struct ngx_event_s ngx_event_t;
typedef struct ngx_connection_s ngx_connection_t;
#include <ngx_string.h>
#include <ngx_parse.h>
#include <ngx_log.h>
#include <ngx_alloc.h>
#include <ngx_hunk.h>

205
src/core/ngx_parse.c Normal file
View File

@ -0,0 +1,205 @@
#include <ngx_config.h>
#include <ngx_core.h>
int ngx_parse_size(ngx_str_t *line)
{
int len, scale, size;
char last;
len = line->len;
last = line->data[len - 1];
switch (last) {
case 'K':
case 'k':
len--;
scale = 1024;
break;
case 'M':
case 'm':
len--;
scale = 1024 * 1024;
break;
default:
scale = 1;
}
size = ngx_atoi(line->data, len);
if (size == NGX_ERROR) {
return NGX_ERROR;
}
size *= scale;
return size;
}
int ngx_parse_time(ngx_str_t *line, int sec)
{
int value, total, len, scale;
u_int max, i;
char *start, last;
enum {
st_start = 0,
st_year,
st_month,
st_week,
st_day,
st_hour,
st_min,
st_sec,
st_msec,
st_last
} step;
start = line->data;
len = 0;
total = 0;
step = sec ? st_start : st_month;
for (i = 0; /* void */ ; i++) {
if (i < line->len) {
if (line->data[i] != ' ') {
len++;
continue;
}
if (line->data[i] == ' ' && len == 0) {
start = &line->data[i + 1];
continue;
}
}
if (len == 0) {
break;
}
last = line->data[i - 1];
switch (last) {
case 'y':
if (step > st_start) {
return NGX_ERROR;
}
step = st_year;
len--;
max = 68;
scale = 60 * 60 * 24 * 365;
break;
case 'M':
if (step > st_year) {
return NGX_ERROR;
}
step = st_month;
len--;
max = 828;
scale = 60 * 60 * 24 * 30;
break;
case 'w':
if (step > st_month) {
return NGX_ERROR;
}
step = st_week;
len--;
max = 3550;
scale = 60 * 60 * 24 * 7;
break;
case 'd':
if (step > st_week) {
return NGX_ERROR;
}
step = st_day;
len--;
max = 24855;
scale = 60 * 60 * 24;
break;
case 'h':
if (step > st_day) {
return NGX_ERROR;
}
step = st_hour;
len--;
max = 596523;
scale = 60 * 60;
break;
case 'm':
if (step > st_hour) {
return NGX_ERROR;
}
step = st_min;
len--;
max = 35791394;
scale = 60;
break;
case 's':
len--;
if (line->data[i - 2] == 'm') {
if (sec || step > st_sec) {
return NGX_ERROR;
}
step = st_msec;
len--;
max = 2147483647;
scale = 1;
break;
}
if (step > st_min) {
return NGX_ERROR;
}
step = st_sec;
max = 2147483647;
scale = 1;
break;
default:
step = st_last;
max = 2147483647;
scale = 1;
}
value = ngx_atoi(start, len);
if (value == NGX_ERROR) {
return NGX_ERROR;
}
if (step != st_msec && !sec) {
scale *= 1000;
max /= 1000;
}
if ((u_int) value > max) {
return NGX_PARSE_LARGE_TIME;
}
total += value * scale;
if ((u_int) total > 2147483647) {
return NGX_PARSE_LARGE_TIME;
}
if (i >= line->len) {
break;
}
len = 0;
start = &line->data[i + 1];
}
return total;
}

16
src/core/ngx_parse.h Normal file
View File

@ -0,0 +1,16 @@
#ifndef _NGX_PARSE_H_INCLUDED_
#define _NGX_PARSE_H_INCLUDED_
#include <ngx_config.h>
#include <ngx_core.h>
#define NGX_PARSE_LARGE_TIME -2
int ngx_parse_size(ngx_str_t *line);
int ngx_parse_time(ngx_str_t *line, int sec);
#endif /* _NGX_PARSE_H_INCLUDED_ */

View File

@ -247,7 +247,7 @@ static int ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
*
* 8K is for zlib deflate_state (~6K).
*
* TODO: 64-bit, round to PAGE_SIZE
* TODO: 64-bit, round to PAGE_SIZE, autoconf of deflate_state size
*/
ctx->allocated = 8192 + (1 << (wbits + 2)) + (1 << (memlevel + 9));