diff options
author | Igor Sysoev <igor@sysoev.ru> | 2004-10-21 19:34:38 +0400 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2004-10-21 19:34:38 +0400 |
commit | c0edbcce58b03b89c70f1eb39cb44c74c4c7453a (patch) | |
tree | 1ce72a5b51d724a0c054e079c2b1507ca85a145d /src/core | |
parent | ac64333a44f39d5a658832517a106961f32f6aae (diff) |
nginx-0.1.2-RELEASE importrelease-0.1.2
*) Feature: the --user=USER, --group=GROUP, and --with-ld-opt=OPTIONS
options in configure.
*) Feature: the server_name directive supports *.domain.tld.
*) Bugfix: the portability improvements.
*) Bugfix: if configuration file was set in command line, the
reconfiguration was impossible; the bug had appeared in 0.1.1.
*) Bugfix: proxy module may get caught in an endless loop when sendfile
is not used.
*) Bugfix: with sendfile the response was not recoded according to the
charset module directives; the bug had appeared in 0.1.1.
*) Bugfix: very seldom bug in the kqueue processing.
*) Bugfix: the gzip module compressed the proxied responses that was
already compressed.
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/nginx.c | 39 | ||||
-rw-r--r-- | src/core/nginx.h | 2 | ||||
-rw-r--r-- | src/core/ngx_buf.c | 9 | ||||
-rw-r--r-- | src/core/ngx_buf.h | 1 | ||||
-rw-r--r-- | src/core/ngx_conf_file.c | 14 | ||||
-rw-r--r-- | src/core/ngx_config.h | 18 | ||||
-rw-r--r-- | src/core/ngx_connection.h | 2 | ||||
-rw-r--r-- | src/core/ngx_core.h | 2 | ||||
-rw-r--r-- | src/core/ngx_cycle.c | 12 | ||||
-rw-r--r-- | src/core/ngx_log.c | 10 | ||||
-rw-r--r-- | src/core/ngx_log.h | 12 | ||||
-rw-r--r-- | src/core/ngx_output_chain.c | 36 | ||||
-rw-r--r-- | src/core/ngx_string.c | 266 | ||||
-rw-r--r-- | src/core/ngx_string.h | 3 | ||||
-rw-r--r-- | src/core/ngx_times.c | 32 | ||||
-rw-r--r-- | src/core/ngx_times.h | 4 |
16 files changed, 394 insertions, 68 deletions
diff --git a/src/core/nginx.c b/src/core/nginx.c index 9d9108094..ab85b2373 100644 --- a/src/core/nginx.c +++ b/src/core/nginx.c @@ -104,7 +104,7 @@ int main(int argc, char *const *argv, char *const *envp) ngx_cycle_t *cycle, init_cycle; ngx_core_conf_t *ccf; -#if defined __FreeBSD__ +#if (NGX_FREEBSD) ngx_debug_init(); #endif @@ -112,7 +112,7 @@ int main(int argc, char *const *argv, char *const *envp) ngx_time_init(); -#if (HAVE_PCRE) +#if (NGX_PCRE) ngx_regex_init(); #endif @@ -136,11 +136,11 @@ int main(int argc, char *const *argv, char *const *envp) return 1; } - if (ngx_getopt(&init_cycle, argc, argv) == NGX_ERROR) { + if (ngx_save_argv(&init_cycle, argc, argv) == NGX_ERROR) { return 1; } - if (ngx_save_argv(&init_cycle, argc, argv) == NGX_ERROR) { + if (ngx_getopt(&init_cycle, argc, ngx_argv) == NGX_ERROR) { return 1; } @@ -175,7 +175,7 @@ int main(int argc, char *const *argv, char *const *envp) if (ngx_test_config) { ngx_log_error(NGX_LOG_INFO, log, 0, "the configuration file %s was tested successfully", - init_cycle.conf_file.data); + cycle->conf_file.data); return 0; } @@ -387,7 +387,7 @@ static ngx_int_t ngx_save_argv(ngx_cycle_t *cycle, int argc, char *const *argv) ngx_argc = argc; -#if __FreeBSD__ +#if (NGX_FREEBSD) ngx_argv = (char **) argv; @@ -462,28 +462,26 @@ static char *ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf) #if !(WIN32) -#if 0 if (ccf->user == (uid_t) NGX_CONF_UNSET) { - pwd = getpwnam("nobody"); + pwd = getpwnam(NGX_USER); if (pwd == NULL) { ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, - "getpwnam(\"nobody\") failed"); + "getpwnam(\"" NGX_USER "\") failed"); return NGX_CONF_ERROR; } ccf->user = pwd->pw_uid; - grp = getgrnam("nobody"); + grp = getgrnam(NGX_GROUP); if (grp == NULL) { ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, - "getgrnam(\"nobody\") failed"); + "getgrnam(\"" NGX_GROUP "\") failed"); return NGX_CONF_ERROR; } ccf->group = grp->gr_gid; } -#endif if (ccf->pid.len == 0) { ccf->pid.len = sizeof(NGX_PID_PATH) - 1; @@ -522,6 +520,7 @@ static char *ngx_set_user(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) ngx_core_conf_t *ccf = conf; + char *group; struct passwd *pwd; struct group *grp; ngx_str_t *value; @@ -530,6 +529,14 @@ static char *ngx_set_user(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) return "is duplicate"; } + if (geteuid() != 0) { + ngx_conf_log_error(NGX_LOG_WARN, cf, 0, + "the \"user\" directive makes sense only " + "if the master process runs " + "with super-user privileges, ignored"); + return NGX_CONF_OK; + } + value = (ngx_str_t *) cf->args->elts; pwd = getpwnam((const char *) value[1].data); @@ -541,14 +548,12 @@ static char *ngx_set_user(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) ccf->user = pwd->pw_uid; - if (cf->args->nelts == 2) { - return NGX_CONF_OK; - } + group = (char *) ((cf->args->nelts == 2) ? value[1].data : value[2].data); - grp = getgrnam((const char *) value[2].data); + grp = getgrnam(group); if (grp == NULL) { ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno, - "getgrnam(\"%s\") failed", value[2].data); + "getgrnam(\"%s\") failed", group); return NGX_CONF_ERROR; } diff --git a/src/core/nginx.h b/src/core/nginx.h index 82545e5c7..bac01fcc1 100644 --- a/src/core/nginx.h +++ b/src/core/nginx.h @@ -8,7 +8,7 @@ #define _NGINX_H_INCLUDED_ -#define NGINX_VER "nginx/0.1.1" +#define NGINX_VER "nginx/0.1.2" #define NGINX_VAR "NGINX" #define NGX_NEWPID_EXT ".newbin" diff --git a/src/core/ngx_buf.c b/src/core/ngx_buf.c index a536c04de..7d379890f 100644 --- a/src/core/ngx_buf.c +++ b/src/core/ngx_buf.c @@ -126,12 +126,11 @@ void ngx_chain_update_chains(ngx_chain_t **free, ngx_chain_t **busy, *busy = *out; } else { - for (tl = *busy; /* void */ ; tl = tl->next) { - if (tl->next == NULL) { - tl->next = *out; - break; - } + for (tl = *busy; tl->next; tl = tl->next) { + /* void */; } + + tl->next = *out; } *out = NULL; diff --git a/src/core/ngx_buf.h b/src/core/ngx_buf.h index 3e014d17a..e2d07190a 100644 --- a/src/core/ngx_buf.h +++ b/src/core/ngx_buf.h @@ -22,7 +22,6 @@ struct ngx_buf_s { off_t file_pos; off_t file_last; - int type; u_char *start; /* start of buffer */ u_char *end; /* end of buffer */ ngx_buf_tag_t tag; diff --git a/src/core/ngx_conf_file.c b/src/core/ngx_conf_file.c index 90a09d231..fb629a439 100644 --- a/src/core/ngx_conf_file.c +++ b/src/core/ngx_conf_file.c @@ -579,8 +579,18 @@ ngx_int_t ngx_conf_full_name(ngx_cycle_t *cycle, ngx_str_t *name) name->len = cycle->root.len + old.len; - if (!(name->data = ngx_palloc(cycle->pool, name->len + 1))) { - return NGX_ERROR; + if (cycle->connections) { + if (!(name->data = ngx_palloc(cycle->pool, name->len + 1))) { + return NGX_ERROR; + } + + } else { + + /* the init_cycle */ + + if (!(name->data = ngx_alloc(name->len + 1, cycle->log))) { + return NGX_ERROR; + } } p = ngx_cpymem(name->data, cycle->root.data, cycle->root.len), diff --git a/src/core/ngx_config.h b/src/core/ngx_config.h index 7e3e6828c..3590fae7a 100644 --- a/src/core/ngx_config.h +++ b/src/core/ngx_config.h @@ -8,30 +8,32 @@ #define _NGX_CONFIG_H_INCLUDED_ +#include <ngx_auto_headers.h> + + #if defined __DragonFly__ && !defined __FreeBSD__ #define __FreeBSD__ 4 #define __FreeBSD_version 480101 #endif -#if defined __FreeBSD__ +#if (NGX_FREEBSD) #include <ngx_freebsd_config.h> -#elif defined __linux__ +#elif (NGX_LINUX) #include <ngx_linux_config.h> - /* Solaris */ -#elif defined sun && (defined __svr4__ || defined __SVR4) +#elif (NGX_SOLARIS) #include <ngx_solaris_config.h> -#elif defined _WIN32 +#elif (NGX_WIN32) #include <ngx_win32_config.h> -#else /* posix */ +#else /* POSIX */ #include <ngx_posix_config.h> #endif @@ -89,8 +91,10 @@ typedef long ngx_flag_t; #define NGX_INT64_LEN sizeof("-9223372036854775808") - 1 #define NGX_OFF_T_LEN sizeof("-9223372036854775808") - 1 +#define NGX_MAX_INT_LEN (sizeof("-9223372036854775808") - 1) + -#if (SOLARIS) +#if (NGX_SOLARIS) /* TODO: auto_conf */ #define NGX_ALIGN (_MAX_ALIGNMENT - 1) /* platform word */ diff --git a/src/core/ngx_connection.h b/src/core/ngx_connection.h index 57c7a3375..8e2ba3970 100644 --- a/src/core/ngx_connection.h +++ b/src/core/ngx_connection.h @@ -40,7 +40,7 @@ typedef struct { time_t post_accept_timeout; /* should be here because of the deferred accept */ - unsigned new:1; + unsigned open:1; unsigned remain:1; unsigned ignore:1; diff --git a/src/core/ngx_core.h b/src/core/ngx_core.h index 02a4a17b9..79fb009bd 100644 --- a/src/core/ngx_core.h +++ b/src/core/ngx_core.h @@ -54,7 +54,7 @@ typedef void (*ngx_event_handler_pt)(ngx_event_t *ev); #include <ngx_file.h> #include <ngx_files.h> #include <ngx_crc.h> -#if (HAVE_PCRE) +#if (NGX_PCRE) #include <ngx_regex.h> #endif #include <ngx_rbtree.h> diff --git a/src/core/ngx_cycle.c b/src/core/ngx_cycle.c index 38f4ad505..a1402f123 100644 --- a/src/core/ngx_cycle.c +++ b/src/core/ngx_cycle.c @@ -158,6 +158,9 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle) conf.module_type = NGX_CORE_MODULE; conf.cmd_type = NGX_MAIN_CONF; +#if 0 + log->log_level = NGX_LOG_DEBUG_ALL; +#endif if (ngx_conf_parse(&conf, &cycle->conf_file) != NGX_CONF_OK) { ngx_destroy_pool(pool); @@ -223,9 +226,6 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle) NGX_FILE_RDWR, NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND); -#if 0 - log->log_level = NGX_LOG_DEBUG_ALL; -#endif ngx_log_debug3(NGX_LOG_DEBUG_CORE, log, 0, "log: %0X %d \"%s\"", &file[i], file[i].fd, file[i].name.data); @@ -310,14 +310,14 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle) } if (nls[n].fd == -1) { - nls[n].new = 1; + nls[n].open = 1; } } } else { ls = cycle->listening.elts; for (i = 0; i < cycle->listening.nelts; i++) { - ls[i].new = 1; + ls[i].open = 1; } } @@ -366,7 +366,7 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle) ls = cycle->listening.elts; for (i = 0; i < cycle->listening.nelts; i++) { - if (ls[i].fd == -1 || !ls[i].new) { + if (ls[i].fd == -1 || !ls[i].open) { continue; } diff --git a/src/core/ngx_log.c b/src/core/ngx_log.c index 9cf1d5605..f1c0e97f3 100644 --- a/src/core/ngx_log.c +++ b/src/core/ngx_log.c @@ -57,7 +57,7 @@ static const char *debug_levels[] = { }; -#if (HAVE_VARIADIC_MACROS) +#if (NGX_HAVE_VARIADIC_MACROS) void ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err, const char *fmt, ...) #else @@ -67,7 +67,7 @@ void ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err, { char errstr[MAX_ERROR_STR]; size_t len, max; -#if (HAVE_VARIADIC_MACROS) +#if (NGX_HAVE_VARIADIC_MACROS) va_list args; #endif @@ -97,7 +97,7 @@ void ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err, "*%u ", *(u_int *) log->data); } -#if (HAVE_VARIADIC_MACROS) +#if (NGX_HAVE_VARIADIC_MACROS) va_start(args, fmt); len += ngx_vsnprintf(errstr + len, max - len, fmt, args); @@ -187,7 +187,7 @@ static void ngx_log_write(ngx_log_t *log, char *errstr, size_t len) } -#if !(HAVE_VARIADIC_MACROS) +#if !(NGX_HAVE_VARIADIC_MACROS) void ngx_log_error(ngx_uint_t level, ngx_log_t *log, ngx_err_t err, const char *fmt, ...) @@ -253,7 +253,7 @@ ngx_log_t *ngx_log_init_stderr() #endif ngx_log.file = &ngx_stderr; - ngx_log.log_level = NGX_LOG_ERR; + ngx_log.log_level = NGX_LOG_NOTICE; return &ngx_log; } diff --git a/src/core/ngx_log.h b/src/core/ngx_log.h index e82995e75..5ddd8fc65 100644 --- a/src/core/ngx_log.h +++ b/src/core/ngx_log.h @@ -55,9 +55,9 @@ struct ngx_log_s { /*********************************/ -#if (HAVE_GCC_VARIADIC_MACROS) +#if (NGX_HAVE_GCC_VARIADIC_MACROS) -#define HAVE_VARIADIC_MACROS 1 +#define NGX_HAVE_VARIADIC_MACROS 1 #define ngx_log_error(level, log, args...) \ if (log->log_level >= level) ngx_log_error_core(level, log, args) @@ -67,9 +67,9 @@ void ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err, /*********************************/ -#elif (HAVE_C99_VARIADIC_MACROS) +#elif (NGX_HAVE_C99_VARIADIC_MACROS) -#define HAVE_VARIADIC_MACROS 1 +#define NGX_HAVE_VARIADIC_MACROS 1 #define ngx_log_error(level, log, ...) \ if (log->log_level >= level) ngx_log_error_core(level, log, __VA_ARGS__) @@ -81,7 +81,7 @@ void ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err, #else /* NO VARIADIC MACROS */ -#define HAVE_VARIADIC_MACROS 0 +#define NGX_HAVE_VARIADIC_MACROS 0 void ngx_log_error(ngx_uint_t level, ngx_log_t *log, ngx_err_t err, const char *fmt, ...); @@ -98,7 +98,7 @@ void ngx_assert_core(ngx_log_t *log, const char *fmt, ...); #if (NGX_DEBUG) -#if (HAVE_VARIADIC_MACROS) +#if (NGX_HAVE_VARIADIC_MACROS) #define ngx_log_debug0(level, log, err, fmt) \ if (log->log_level & level) \ diff --git a/src/core/ngx_output_chain.c b/src/core/ngx_output_chain.c index 74e38e184..23b7846b9 100644 --- a/src/core/ngx_output_chain.c +++ b/src/core/ngx_output_chain.c @@ -24,13 +24,13 @@ ngx_int_t ngx_output_chain(ngx_output_chain_ctx_t *ctx, ngx_chain_t *in) size_t size, bsize; ngx_chain_t *cl, *out, **last_out; - /* - * the short path for the case when the ctx->in chain is empty - * and the incoming chain is empty too or it has the single buf - * that does not require the copy - */ + if (ctx->in == NULL && ctx->busy == NULL) { - if (ctx->in == NULL) { + /* + * the short path for the case when the ctx->in and ctx->busy chains + * are empty, the incoming chain is empty too or has the single buf + * that does not require the copy + */ if (in == NULL) { return ctx->output_filter(ctx->filter_ctx, in); @@ -192,6 +192,7 @@ ngx_inline static ngx_int_t } if (!ctx->sendfile) { + if (!ngx_buf_in_memory(buf)) { return 1; } @@ -228,12 +229,19 @@ static ngx_int_t ngx_output_chain_copy_buf(ngx_buf_t *dst, ngx_buf_t *src, src->pos += size; dst->last += size; - if (src->in_file && sendfile) { - dst->in_file = 1; - dst->file = src->file; - dst->file_pos = src->file_pos; + if (src->in_file) { + + if (sendfile) { + dst->in_file = 1; + dst->file = src->file; + dst->file_pos = src->file_pos; + dst->file_last = src->file_pos + size; + + } else { + dst->in_file = 0; + } + src->file_pos += size; - dst->file_last = src->file_pos; } else { dst->in_file = 0; @@ -271,14 +279,14 @@ static ngx_int_t ngx_output_chain_copy_buf(ngx_buf_t *dst, ngx_buf_t *src, dst->in_file = 1; dst->file = src->file; dst->file_pos = src->file_pos; - src->file_pos += size; - dst->file_last = src->file_pos; + dst->file_last = src->file_pos + n; } else { dst->in_file = 0; - src->file_pos += n; } + src->file_pos += n; + if (src->last_buf && src->file_pos == src->file_last) { dst->last_buf = 1; } diff --git a/src/core/ngx_string.c b/src/core/ngx_string.c index 32a4079a0..8e4e09a3a 100644 --- a/src/core/ngx_string.c +++ b/src/core/ngx_string.c @@ -28,6 +28,238 @@ u_char *ngx_cpystrn(u_char *dst, u_char *src, size_t n) } +/* + * supported formats: + * %[0][width]O off_t + * %[0][width]T time_t + * %[0][width]S ssize_t + * %[0][width]uS size_t + * %[0][width]uxS size_t in hex + * %[0][width]l long + * %[0][width]d int + * %[0][width]i ngx_int_t + * %[0][width]ui ngx_uint_t + * %[0][width]uxi ngx_uint_t in hex + * %s null-terminated string + * %% % + * + */ + +u_char *ngx_sprintf(u_char *buf, char *fmt, ...) +{ + u_char *p, c, temp[NGX_MAX_INT_LEN]; + int d; + long l; + off_t offset; + size_t size, len; + ssize_t ssize; + time_t sec; + va_list arg; + ngx_int_t i; + ngx_uint_t ui, zero, width, sign, hexadecimal; + static u_char hex[] = "0123456789abcdef"; + + va_start(arg, fmt); + + while (*fmt) { + if (*fmt == '%') { + + zero = (*++fmt == '0') ? 1 : 0; + width = 0; + sign = 1; + hexadecimal = 0; + + p = temp + NGX_MAX_INT_LEN; + + while (*fmt >= '0' && *fmt <= '9') { + width = width * 10 + *fmt++ - '0'; + } + + + for ( ;; ) { + switch (*fmt) { + + case 'u': + sign = 0; + fmt++; + continue; + + case 'x': + hexadecimal = 1; + fmt++; + continue; + + default: + break; + } + + break; + } + + + switch (*fmt) { + + case 'O': + offset = va_arg(arg, off_t); + + if (offset < 0) { + *buf++ = '-'; + offset = -offset; + } + + do { + *--p = (u_char) (offset % 10 + '0'); + } while (offset /= 10); + + break; + + case 'T': + sec = va_arg(arg, time_t); + + if (sec < 0) { + *buf++ = '-'; + sec = -sec; + } + + do { + *--p = (u_char) (sec % 10 + '0'); + } while (sec /= 10); + + break; + + case 'S': + if (sign) { + ssize = va_arg(arg, ssize_t); + + if (ssize < 0) { + *buf++ = '-'; + size = (size_t) -ssize; + + } else { + size = (size_t) ssize; + } + + } else { + size = va_arg(arg, size_t); + } + + if (hexadecimal) { + do { + *--p = hex[size & 0xf]; + } while (size >>= 4); + + } else { + do { + *--p = (u_char) (size % 10 + '0'); + } while (size /= 10); + } + + break; + + case 'l': + l = va_arg(arg, long); + + if (l < 0) { + *buf++ = '-'; + l = -l; + } + + do { + *--p = (u_char) (l % 10 + '0'); + } while (l /= 10); + + break; + + case 'd': + d = va_arg(arg, int); + + if (d < 0) { + *buf++ = '-'; + d = -d; + } + + do { + *--p = (u_char) (d % 10 + '0'); + } while (d /= 10); + + break; + + case 'i': + if (sign) { + i = va_arg(arg, ngx_int_t); + + if (i < 0) { + *buf++ = '-'; + ui = (ngx_uint_t) -i; + + } else { + ui = (ngx_uint_t) i; + } + + } else { + ui = va_arg(arg, ngx_uint_t); + } + + if (hexadecimal) { + do { + *--p = hex[ui & 0xf]; + } while (ui >>= 4); + + } else { + do { + *--p = (u_char) (ui % 10 + '0'); + } while (ui /= 10); + } + + break; + + case 's': + p = va_arg(arg, u_char *); + + while (*p) { + *buf++ = *p++; + } + fmt++; + + continue; + + case '%': + *buf++ = '%'; + fmt++; + + continue; + + default: + *buf++ = *fmt++; + + continue; + } + + len = (temp + NGX_MAX_INT_LEN) - p; + + c = (u_char) (zero ? '0' : ' '); + + while (len++ < width) { + *buf++ = c; + } + + buf = ngx_cpymem(buf, p, ((temp + NGX_MAX_INT_LEN) - p)); + + fmt++; + + } else { + *buf++ = *fmt++; + } + } + + va_end(arg); + + *buf = '\0'; + + return buf; +} + + ngx_int_t ngx_rstrncmp(u_char *s1, u_char *s2, size_t n) { if (n == 0) { @@ -50,6 +282,40 @@ ngx_int_t ngx_rstrncmp(u_char *s1, u_char *s2, size_t n) } +ngx_int_t ngx_rstrncasecmp(u_char *s1, u_char *s2, size_t n) +{ + u_char c1, c2; + + if (n == 0) { + return 0; + } + + n--; + + for ( ;; ) { + c1 = s1[n]; + if (c1 >= 'a' && c1 <= 'z') { + c1 -= 'a' - 'A'; + } + + c2 = s2[n]; + if (c2 >= 'a' && c2 <= 'z') { + c2 -= 'a' - 'A'; + } + + if (c1 != c2) { + return c1 - c2; + } + + if (n == 0) { + return 0; + } + + n--; + } +} + + ngx_int_t ngx_atoi(u_char *line, size_t n) { ngx_int_t value; diff --git a/src/core/ngx_string.h b/src/core/ngx_string.h index e8e69c0c0..d7caaaf3d 100644 --- a/src/core/ngx_string.h +++ b/src/core/ngx_string.h @@ -70,7 +70,10 @@ typedef struct { #define ngx_memcmp memcmp u_char *ngx_cpystrn(u_char *dst, u_char *src, size_t n); +u_char *ngx_sprintf(u_char *buf, char *fmt, ...); + ngx_int_t ngx_rstrncmp(u_char *s1, u_char *s2, size_t n); +ngx_int_t ngx_rstrncasecmp(u_char *s1, u_char *s2, size_t n); ngx_int_t ngx_atoi(u_char *line, size_t n); ngx_int_t ngx_hextoi(u_char *line, size_t n); diff --git a/src/core/ngx_times.c b/src/core/ngx_times.c index 2ca31acc4..40dbbdbaf 100644 --- a/src/core/ngx_times.c +++ b/src/core/ngx_times.c @@ -212,12 +212,25 @@ void ngx_time_update(time_t s) } +u_char *ngx_http_time(u_char *buf, time_t t) +#if 0 size_t ngx_http_time(u_char *buf, time_t t) +#endif { ngx_tm_t tm; ngx_gmtime(t, &tm); + return ngx_sprintf(buf, "%s, %02d %s %4d %02d:%02d:%02d GMT", + week[tm.ngx_tm_wday], + tm.ngx_tm_mday, + months[tm.ngx_tm_mon - 1], + tm.ngx_tm_year, + tm.ngx_tm_hour, + tm.ngx_tm_min, + tm.ngx_tm_sec); + +#if 0 return ngx_snprintf((char *) buf, sizeof("Mon, 28 Sep 1970 06:00:00 GMT"), "%s, %02d %s %4d %02d:%02d:%02d GMT", week[tm.ngx_tm_wday], @@ -227,10 +240,14 @@ size_t ngx_http_time(u_char *buf, time_t t) tm.ngx_tm_hour, tm.ngx_tm_min, tm.ngx_tm_sec); +#endif } +u_char *ngx_http_cookie_time(u_char *buf, time_t t) +#if 0 size_t ngx_http_cookie_time(u_char *buf, time_t t) +#endif { ngx_tm_t tm; @@ -241,6 +258,20 @@ size_t ngx_http_cookie_time(u_char *buf, time_t t) * 2-digit years more than "37" */ + return ngx_sprintf(buf, + (tm.ngx_tm_year > 2037) ? + "%s, %02d-%s-%d %02d:%02d:%02d GMT": + "%s, %02d-%s-%02d %02d:%02d:%02d GMT", + week[tm.ngx_tm_wday], + tm.ngx_tm_mday, + months[tm.ngx_tm_mon - 1], + (tm.ngx_tm_year > 2037) ? tm.ngx_tm_year: + tm.ngx_tm_year % 100, + tm.ngx_tm_hour, + tm.ngx_tm_min, + tm.ngx_tm_sec); + +#if 0 if (tm.ngx_tm_year > 2037) { return ngx_snprintf((char *) buf, sizeof("Mon, 28-Sep-1970 06:00:00 GMT"), @@ -264,6 +295,7 @@ size_t ngx_http_cookie_time(u_char *buf, time_t t) tm.ngx_tm_min, tm.ngx_tm_sec); } +#endif } diff --git a/src/core/ngx_times.h b/src/core/ngx_times.h index e1d1515ee..5eabac536 100644 --- a/src/core/ngx_times.h +++ b/src/core/ngx_times.h @@ -14,8 +14,8 @@ void ngx_time_init(); void ngx_time_update(time_t s); -size_t ngx_http_time(u_char *buf, time_t t); -size_t ngx_http_cookie_time(u_char *buf, time_t t); +u_char *ngx_http_time(u_char *buf, time_t t); +u_char *ngx_http_cookie_time(u_char *buf, time_t t); void ngx_gmtime(time_t t, ngx_tm_t *tp); #if (NGX_THREADS) |