aboutsummaryrefslogtreecommitdiff
path: root/src/core/ngx_parse.c
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2008-04-17 14:23:20 +0000
committerIgor Sysoev <igor@sysoev.ru>2008-04-17 14:23:20 +0000
commitf57b24e70f605f7d28f5a26e352b48e10e42f9d2 (patch)
tree9d103ce6a1a6c15c8fa3bc7fdfb27843b925ce7a /src/core/ngx_parse.c
parent2e39e289e11cd895f1a98eb8868b91a387b7badf (diff)
downloadnginx-f57b24e70f605f7d28f5a26e352b48e10e42f9d2.tar.gz
nginx-f57b24e70f605f7d28f5a26e352b48e10e42f9d2.zip
allow time without spaces in ngx_parse_time()
Diffstat (limited to 'src/core/ngx_parse.c')
-rw-r--r--src/core/ngx_parse.c100
1 files changed, 44 insertions, 56 deletions
diff --git a/src/core/ngx_parse.c b/src/core/ngx_parse.c
index e8a6f13be..6c4640cf7 100644
--- a/src/core/ngx_parse.c
+++ b/src/core/ngx_parse.c
@@ -93,12 +93,11 @@ ngx_parse_offset(ngx_str_t *line)
ngx_int_t
-ngx_parse_time(ngx_str_t *line, ngx_int_t sec)
+ngx_parse_time(ngx_str_t *line, ngx_uint_t sec)
{
- size_t len;
- u_char *start, last;
+ u_char *p, *last;
ngx_int_t value, total, scale;
- ngx_uint_t max, i;
+ ngx_uint_t max, valid;
enum {
st_start = 0,
st_year,
@@ -112,39 +111,30 @@ ngx_parse_time(ngx_str_t *line, ngx_int_t sec)
st_last
} step;
-
- start = line->data;
- len = 0;
+ valid = 0;
+ value = 0;
total = 0;
step = sec ? st_start : st_month;
+ scale = sec ? 1 : 1000;
- for (i = 0; /* void */ ; i++) {
-
- if (i < line->len) {
- if (line->data[i] != ' ') {
- len++;
- continue;
- }
+ p = line->data;
+ last = p + line->len;
- if (line->data[i] == ' ' && len == 0) {
- start = &line->data[i + 1];
- continue;
- }
- }
+ while (p < last) {
- if (len == 0) {
- break;
+ if (*p >= '0' && *p <= '9') {
+ value = value * 10 + (*p++ - '0');
+ valid = 1;
+ continue;
}
- last = line->data[i - 1];
+ switch (*p++) {
- switch (last) {
case 'y':
if (step > st_start) {
return NGX_ERROR;
}
step = st_year;
- len--;
max = 68;
scale = 60 * 60 * 24 * 365;
break;
@@ -154,7 +144,6 @@ ngx_parse_time(ngx_str_t *line, ngx_int_t sec)
return NGX_ERROR;
}
step = st_month;
- len--;
max = 828;
scale = 60 * 60 * 24 * 30;
break;
@@ -164,7 +153,6 @@ ngx_parse_time(ngx_str_t *line, ngx_int_t sec)
return NGX_ERROR;
}
step = st_week;
- len--;
max = 3550;
scale = 60 * 60 * 24 * 7;
break;
@@ -174,7 +162,6 @@ ngx_parse_time(ngx_str_t *line, ngx_int_t sec)
return NGX_ERROR;
}
step = st_day;
- len--;
max = 24855;
scale = 60 * 60 * 24;
break;
@@ -184,52 +171,49 @@ ngx_parse_time(ngx_str_t *line, ngx_int_t sec)
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 (*p == 's') {
if (sec || step > st_sec) {
return NGX_ERROR;
}
+ p++;
step = st_msec;
- len--;
max = 2147483647;
scale = 1;
break;
}
- if (step > st_min) {
+ if (step > st_hour) {
return NGX_ERROR;
}
+ step = st_min;
+ max = 35791394;
+ scale = 60;
+ break;
+ case 's':
+ if (step > st_min) {
+ return NGX_ERROR;
+ }
step = st_sec;
max = 2147483647;
scale = 1;
break;
- default:
+ case ' ':
+ if (step > st_min) {
+ return NGX_ERROR;
+ }
step = st_last;
max = 2147483647;
scale = 1;
- }
+ break;
- value = ngx_atoi(start, len);
- if (value == NGX_ERROR) {
+ default:
return NGX_ERROR;
}
@@ -238,23 +222,27 @@ ngx_parse_time(ngx_str_t *line, ngx_int_t sec)
max /= 1000;
}
- if ((u_int) value > max) {
- return NGX_PARSE_LARGE_TIME;
+ if ((ngx_uint_t) value > max) {
+ return NGX_ERROR;
}
total += value * scale;
- if ((u_int) total > 2147483647) {
- return NGX_PARSE_LARGE_TIME;
+ if ((ngx_uint_t) total > 2147483647) {
+ return NGX_ERROR;
}
- if (i >= line->len) {
- break;
+ value = 0;
+ scale = sec ? 1 : 1000;
+
+ while (p < last && *p == ' ') {
+ p++;
}
+ }
- len = 0;
- start = &line->data[i + 1];
+ if (valid) {
+ return total + value * scale;
}
- return total;
+ return NGX_ERROR;
}