summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authornginx <nginx@nginx.org>2015-06-16 15:24:45 +0000
committerJon Kolb <kolbyjack@gmail.com>2015-06-16 15:24:45 +0000
commitf01c6309faeddd6cb719419376cb61c4da08b3e6 (patch)
tree1ca626f034ba419c612bf14664aac08192eecd32 /src/core
parent2db2346e9858b0e2bc441fe293f1581a1b3371ae (diff)
downloadnginx-1.9.tar.gz
Changes with nginx 1.9.2 16 Jun 2015v1.9.2nginx-1.9
*) Feature: the "backlog" parameter of the "listen" directives of the mail proxy and stream modules. *) Feature: the "allow" and "deny" directives in the stream module. *) Feature: the "proxy_bind" directive in the stream module. *) Feature: the "proxy_protocol" directive in the stream module. *) Feature: the -T switch. *) Feature: the REQUEST_SCHEME parameter added to the fastcgi.conf, fastcgi_params, scgi_params, and uwsgi_params standard configuration files. *) Bugfix: the "reuseport" parameter of the "listen" directive of the stream module did not work. *) Bugfix: OCSP stapling might return an expired OCSP response in some cases.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/nginx.c30
-rw-r--r--src/core/nginx.h4
-rw-r--r--src/core/ngx_conf_file.c47
-rw-r--r--src/core/ngx_conf_file.h7
-rw-r--r--src/core/ngx_core.h1
-rw-r--r--src/core/ngx_cycle.c8
-rw-r--r--src/core/ngx_cycle.h2
-rw-r--r--src/core/ngx_log.h15
-rw-r--r--src/core/ngx_parse_time.c276
-rw-r--r--src/core/ngx_parse_time.h22
-rw-r--r--src/core/ngx_proxy_protocol.c51
-rw-r--r--src/core/ngx_proxy_protocol.h4
12 files changed, 454 insertions, 13 deletions
diff --git a/src/core/nginx.c b/src/core/nginx.c
index 231a3daf5..3213527ec 100644
--- a/src/core/nginx.c
+++ b/src/core/nginx.c
@@ -176,9 +176,11 @@ static char **ngx_os_environ;
int ngx_cdecl
main(int argc, char *const *argv)
{
- ngx_int_t i;
+ ngx_buf_t *b;
ngx_log_t *log;
+ ngx_uint_t i;
ngx_cycle_t *cycle, init_cycle;
+ ngx_conf_dump_t *cd;
ngx_core_conf_t *ccf;
ngx_debug_init();
@@ -196,7 +198,7 @@ main(int argc, char *const *argv)
if (ngx_show_help) {
ngx_write_stderr(
- "Usage: nginx [-?hvVtq] [-s signal] [-c filename] "
+ "Usage: nginx [-?hvVtTq] [-s signal] [-c filename] "
"[-p prefix] [-g directives]" NGX_LINEFEED
NGX_LINEFEED
"Options:" NGX_LINEFEED
@@ -205,6 +207,8 @@ main(int argc, char *const *argv)
" -V : show version and configure options then exit"
NGX_LINEFEED
" -t : test configuration and exit" NGX_LINEFEED
+ " -T : test configuration, dump it and exit"
+ NGX_LINEFEED
" -q : suppress non-error messages "
"during configuration testing" NGX_LINEFEED
" -s signal : send signal to a master process: "
@@ -333,6 +337,23 @@ main(int argc, char *const *argv)
cycle->conf_file.data);
}
+ if (ngx_dump_config) {
+ cd = cycle->config_dump.elts;
+
+ for (i = 0; i < cycle->config_dump.nelts; i++) {
+
+ ngx_write_stdout("# configuration file ");
+ (void) ngx_write_fd(ngx_stdout, cd[i].name.data,
+ cd[i].name.len);
+ ngx_write_stdout(":" NGX_LINEFEED);
+
+ b = cd[i].buffer;
+
+ (void) ngx_write_fd(ngx_stdout, b->pos, b->last - b->pos);
+ ngx_write_stdout(NGX_LINEFEED);
+ }
+ }
+
return 0;
}
@@ -689,6 +710,11 @@ ngx_get_options(int argc, char *const *argv)
ngx_test_config = 1;
break;
+ case 'T':
+ ngx_test_config = 1;
+ ngx_dump_config = 1;
+ break;
+
case 'q':
ngx_quiet_mode = 1;
break;
diff --git a/src/core/nginx.h b/src/core/nginx.h
index ec818e042..4c9cf35cb 100644
--- a/src/core/nginx.h
+++ b/src/core/nginx.h
@@ -9,8 +9,8 @@
#define _NGINX_H_INCLUDED_
-#define nginx_version 1009001
-#define NGINX_VERSION "1.9.1"
+#define nginx_version 1009002
+#define NGINX_VERSION "1.9.2"
#define NGINX_VER "nginx/" NGINX_VERSION
#ifdef NGX_BUILD
diff --git a/src/core/ngx_conf_file.c b/src/core/ngx_conf_file.c
index ec3c1fae1..1c3238cf3 100644
--- a/src/core/ngx_conf_file.c
+++ b/src/core/ngx_conf_file.c
@@ -101,10 +101,13 @@ char *
ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename)
{
char *rv;
+ u_char *p;
+ off_t size;
ngx_fd_t fd;
ngx_int_t rc;
- ngx_buf_t buf;
+ ngx_buf_t buf, *tbuf;
ngx_conf_file_t *prev, conf_file;
+ ngx_conf_dump_t *cd;
enum {
parse_file = 0,
parse_block,
@@ -158,6 +161,39 @@ ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename)
type = parse_file;
+ if (ngx_dump_config
+#if (NGX_DEBUG)
+ || 1
+#endif
+ )
+ {
+ p = ngx_pstrdup(cf->cycle->pool, filename);
+ if (p == NULL) {
+ goto failed;
+ }
+
+ size = ngx_file_size(&cf->conf_file->file.info);
+
+ tbuf = ngx_create_temp_buf(cf->cycle->pool, (size_t) size);
+ if (tbuf == NULL) {
+ goto failed;
+ }
+
+ cd = ngx_array_push(&cf->cycle->config_dump);
+ if (cd == NULL) {
+ goto failed;
+ }
+
+ cd->name.len = filename->len;
+ cd->name.data = p;
+ cd->buffer = tbuf;
+
+ cf->conf_file->dump = tbuf;
+
+ } else {
+ cf->conf_file->dump = NULL;
+ }
+
} else if (cf->conf_file->file.fd != NGX_INVALID_FILE) {
type = parse_block;
@@ -437,7 +473,7 @@ ngx_conf_read_token(ngx_conf_t *cf)
ngx_uint_t found, need_space, last_space, sharp_comment, variable;
ngx_uint_t quoted, s_quoted, d_quoted, start_line;
ngx_str_t *word;
- ngx_buf_t *b;
+ ngx_buf_t *b, *dump;
found = 0;
need_space = 0;
@@ -450,6 +486,7 @@ ngx_conf_read_token(ngx_conf_t *cf)
cf->args->nelts = 0;
b = cf->conf_file->buffer;
+ dump = cf->conf_file->dump;
start = b->pos;
start_line = cf->conf_file->line;
@@ -531,6 +568,10 @@ ngx_conf_read_token(ngx_conf_t *cf)
b->pos = b->start + len;
b->last = b->pos + n;
start = b->start;
+
+ if (dump) {
+ dump->last = ngx_cpymem(dump->last, b->pos, size);
+ }
}
ch = *b->pos++;
@@ -680,7 +721,7 @@ ngx_conf_read_token(ngx_conf_t *cf)
return NGX_ERROR;
}
- word->data = ngx_pnalloc(cf->pool, b->pos - start + 1);
+ word->data = ngx_pnalloc(cf->pool, b->pos - 1 - start + 1);
if (word->data == NULL) {
return NGX_ERROR;
}
diff --git a/src/core/ngx_conf_file.h b/src/core/ngx_conf_file.h
index d73a6c8bf..ee4430674 100644
--- a/src/core/ngx_conf_file.h
+++ b/src/core/ngx_conf_file.h
@@ -146,10 +146,17 @@ typedef struct {
typedef struct {
ngx_file_t file;
ngx_buf_t *buffer;
+ ngx_buf_t *dump;
ngx_uint_t line;
} ngx_conf_file_t;
+typedef struct {
+ ngx_str_t name;
+ ngx_buf_t *buffer;
+} ngx_conf_dump_t;
+
+
typedef char *(*ngx_conf_handler_pt)(ngx_conf_t *cf,
ngx_command_t *dummy, void *conf);
diff --git a/src/core/ngx_core.h b/src/core/ngx_core.h
index a279c81d6..6b317056a 100644
--- a/src/core/ngx_core.h
+++ b/src/core/ngx_core.h
@@ -54,6 +54,7 @@ typedef void (*ngx_connection_handler_pt)(ngx_connection_t *c);
#include <ngx_process.h>
#include <ngx_user.h>
#include <ngx_parse.h>
+#include <ngx_parse_time.h>
#include <ngx_log.h>
#include <ngx_alloc.h>
#include <ngx_palloc.h>
diff --git a/src/core/ngx_cycle.c b/src/core/ngx_cycle.c
index b358f3dbe..ad4bf9254 100644
--- a/src/core/ngx_cycle.c
+++ b/src/core/ngx_cycle.c
@@ -24,6 +24,7 @@ static ngx_pool_t *ngx_temp_pool;
static ngx_event_t ngx_cleaner_event;
ngx_uint_t ngx_test_config;
+ngx_uint_t ngx_dump_config;
ngx_uint_t ngx_quiet_mode;
@@ -124,6 +125,13 @@ ngx_init_cycle(ngx_cycle_t *old_cycle)
cycle->paths.pool = pool;
+ if (ngx_array_init(&cycle->config_dump, pool, 1, sizeof(ngx_conf_dump_t))
+ != NGX_OK)
+ {
+ ngx_destroy_pool(pool);
+ return NULL;
+ }
+
if (old_cycle->open_files.part.nelts) {
n = old_cycle->open_files.part.nelts;
for (part = old_cycle->open_files.part.next; part; part = part->next) {
diff --git a/src/core/ngx_cycle.h b/src/core/ngx_cycle.h
index c601ea133..b77c1093f 100644
--- a/src/core/ngx_cycle.h
+++ b/src/core/ngx_cycle.h
@@ -52,6 +52,7 @@ struct ngx_cycle_s {
ngx_array_t listening;
ngx_array_t paths;
+ ngx_array_t config_dump;
ngx_list_t open_files;
ngx_list_t shared_memory;
@@ -124,6 +125,7 @@ extern volatile ngx_cycle_t *ngx_cycle;
extern ngx_array_t ngx_old_cycles;
extern ngx_module_t ngx_core_module;
extern ngx_uint_t ngx_test_config;
+extern ngx_uint_t ngx_dump_config;
extern ngx_uint_t ngx_quiet_mode;
diff --git a/src/core/ngx_log.h b/src/core/ngx_log.h
index cb80b5f83..618d3ad62 100644
--- a/src/core/ngx_log.h
+++ b/src/core/ngx_log.h
@@ -111,7 +111,7 @@ void ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
/*********************************/
-#else /* NO VARIADIC MACROS */
+#else /* no variadic macros */
#define NGX_HAVE_VARIADIC_MACROS 0
@@ -123,7 +123,7 @@ void ngx_cdecl ngx_log_debug_core(ngx_log_t *log, ngx_err_t err,
const char *fmt, ...);
-#endif /* VARIADIC MACROS */
+#endif /* variadic macros */
/*********************************/
@@ -166,7 +166,7 @@ void ngx_cdecl ngx_log_debug_core(ngx_log_t *log, ngx_err_t err,
arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)
-#else /* NO VARIADIC MACROS */
+#else /* no variadic macros */
#define ngx_log_debug0(level, log, err, fmt) \
if ((log)->log_level & level) \
@@ -211,7 +211,7 @@ void ngx_cdecl ngx_log_debug_core(ngx_log_t *log, ngx_err_t err,
#endif
-#else /* NO NGX_DEBUG */
+#else /* !NGX_DEBUG */
#define ngx_log_debug0(level, log, err, fmt)
#define ngx_log_debug1(level, log, err, fmt, arg1)
@@ -255,6 +255,13 @@ ngx_write_stderr(char *text)
}
+static ngx_inline void
+ngx_write_stdout(char *text)
+{
+ (void) ngx_write_fd(ngx_stdout, text, ngx_strlen(text));
+}
+
+
extern ngx_module_t ngx_errlog_module;
extern ngx_uint_t ngx_use_stderr;
diff --git a/src/core/ngx_parse_time.c b/src/core/ngx_parse_time.c
new file mode 100644
index 000000000..831cc71bf
--- /dev/null
+++ b/src/core/ngx_parse_time.c
@@ -0,0 +1,276 @@
+
+/*
+ * Copyright (C) Igor Sysoev
+ * Copyright (C) Nginx, Inc.
+ */
+
+
+#include <ngx_config.h>
+#include <ngx_core.h>
+
+
+static ngx_uint_t mday[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
+
+time_t
+ngx_parse_http_time(u_char *value, size_t len)
+{
+ u_char *p, *end;
+ ngx_int_t month;
+ ngx_uint_t day, year, hour, min, sec;
+ uint64_t time;
+ enum {
+ no = 0,
+ rfc822, /* Tue, 10 Nov 2002 23:50:13 */
+ rfc850, /* Tuesday, 10-Dec-02 23:50:13 */
+ isoc /* Tue Dec 10 23:50:13 2002 */
+ } fmt;
+
+ fmt = 0;
+ end = value + len;
+
+#if (NGX_SUPPRESS_WARN)
+ day = 32;
+ year = 2038;
+#endif
+
+ for (p = value; p < end; p++) {
+ if (*p == ',') {
+ break;
+ }
+
+ if (*p == ' ') {
+ fmt = isoc;
+ break;
+ }
+ }
+
+ for (p++; p < end; p++)
+ if (*p != ' ') {
+ break;
+ }
+
+ if (end - p < 18) {
+ return NGX_ERROR;
+ }
+
+ if (fmt != isoc) {
+ if (*p < '0' || *p > '9' || *(p + 1) < '0' || *(p + 1) > '9') {
+ return NGX_ERROR;
+ }
+
+ day = (*p - '0') * 10 + *(p + 1) - '0';
+ p += 2;
+
+ if (*p == ' ') {
+ if (end - p < 18) {
+ return NGX_ERROR;
+ }
+ fmt = rfc822;
+
+ } else if (*p == '-') {
+ fmt = rfc850;
+
+ } else {
+ return NGX_ERROR;
+ }
+
+ p++;
+ }
+
+ switch (*p) {
+
+ case 'J':
+ month = *(p + 1) == 'a' ? 0 : *(p + 2) == 'n' ? 5 : 6;
+ break;
+
+ case 'F':
+ month = 1;
+ break;
+
+ case 'M':
+ month = *(p + 2) == 'r' ? 2 : 4;
+ break;
+
+ case 'A':
+ month = *(p + 1) == 'p' ? 3 : 7;
+ break;
+
+ case 'S':
+ month = 8;
+ break;
+
+ case 'O':
+ month = 9;
+ break;
+
+ case 'N':
+ month = 10;
+ break;
+
+ case 'D':
+ month = 11;
+ break;
+
+ default:
+ return NGX_ERROR;
+ }
+
+ p += 3;
+
+ if ((fmt == rfc822 && *p != ' ') || (fmt == rfc850 && *p != '-')) {
+ return NGX_ERROR;
+ }
+
+ p++;
+
+ if (fmt == rfc822) {
+ if (*p < '0' || *p > '9' || *(p + 1) < '0' || *(p + 1) > '9'
+ || *(p + 2) < '0' || *(p + 2) > '9'
+ || *(p + 3) < '0' || *(p + 3) > '9')
+ {
+ return NGX_ERROR;
+ }
+
+ year = (*p - '0') * 1000 + (*(p + 1) - '0') * 100
+ + (*(p + 2) - '0') * 10 + *(p + 3) - '0';
+ p += 4;
+
+ } else if (fmt == rfc850) {
+ if (*p < '0' || *p > '9' || *(p + 1) < '0' || *(p + 1) > '9') {
+ return NGX_ERROR;
+ }
+
+ year = (*p - '0') * 10 + *(p + 1) - '0';
+ year += (year < 70) ? 2000 : 1900;
+ p += 2;
+ }
+
+ if (fmt == isoc) {
+ if (*p == ' ') {
+ p++;
+ }
+
+ if (*p < '0' || *p > '9') {
+ return NGX_ERROR;
+ }
+
+ day = *p++ - '0';
+
+ if (*p != ' ') {
+ if (*p < '0' || *p > '9') {
+ return NGX_ERROR;
+ }
+
+ day = day * 10 + *p++ - '0';
+ }
+
+ if (end - p < 14) {
+ return NGX_ERROR;
+ }
+ }
+
+ if (*p++ != ' ') {
+ return NGX_ERROR;
+ }
+
+ if (*p < '0' || *p > '9' || *(p + 1) < '0' || *(p + 1) > '9') {
+ return NGX_ERROR;
+ }
+
+ hour = (*p - '0') * 10 + *(p + 1) - '0';
+ p += 2;
+
+ if (*p++ != ':') {
+ return NGX_ERROR;
+ }
+
+ if (*p < '0' || *p > '9' || *(p + 1) < '0' || *(p + 1) > '9') {
+ return NGX_ERROR;
+ }
+
+ min = (*p - '0') * 10 + *(p + 1) - '0';
+ p += 2;
+
+ if (*p++ != ':') {
+ return NGX_ERROR;
+ }
+
+ if (*p < '0' || *p > '9' || *(p + 1) < '0' || *(p + 1) > '9') {
+ return NGX_ERROR;
+ }
+
+ sec = (*p - '0') * 10 + *(p + 1) - '0';
+
+ if (fmt == isoc) {
+ p += 2;
+
+ if (*p++ != ' ') {
+ return NGX_ERROR;
+ }
+
+ if (*p < '0' || *p > '9' || *(p + 1) < '0' || *(p + 1) > '9'
+ || *(p + 2) < '0' || *(p + 2) > '9'
+ || *(p + 3) < '0' || *(p + 3) > '9')
+ {
+ return NGX_ERROR;
+ }
+
+ year = (*p - '0') * 1000 + (*(p + 1) - '0') * 100
+ + (*(p + 2) - '0') * 10 + *(p + 3) - '0';
+ }
+
+ if (hour > 23 || min > 59 || sec > 59) {
+ return NGX_ERROR;
+ }
+
+ if (day == 29 && month == 1) {
+ if ((year & 3) || ((year % 100 == 0) && (year % 400) != 0)) {
+ return NGX_ERROR;
+ }
+
+ } else if (day > mday[month]) {
+ return NGX_ERROR;
+ }
+
+ /*
+ * shift new year to March 1 and start months from 1 (not 0),
+ * it is needed for Gauss' formula
+ */
+
+ if (--month <= 0) {
+ month += 12;
+ year -= 1;
+ }
+
+ /* Gauss' formula for Gregorian days since March 1, 1 BC */
+
+ time = (uint64_t) (
+ /* days in years including leap years since March 1, 1 BC */
+
+ 365 * year + year / 4 - year / 100 + year / 400
+
+ /* days before the month */
+
+ + 367 * month / 12 - 30
+
+ /* days before the day */
+
+ + day - 1
+
+ /*
+ * 719527 days were between March 1, 1 BC and March 1, 1970,
+ * 31 and 28 days were in January and February 1970
+ */
+
+ - 719527 + 31 + 28) * 86400 + hour * 3600 + min * 60 + sec;
+
+#if (NGX_TIME_T_SIZE <= 4)
+
+ if (time > 0x7fffffff) {
+ return NGX_ERROR;
+ }
+
+#endif
+
+ return (time_t) time;
+}
diff --git a/src/core/ngx_parse_time.h b/src/core/ngx_parse_time.h
new file mode 100644
index 000000000..aa542ebf5
--- /dev/null
+++ b/src/core/ngx_parse_time.h
@@ -0,0 +1,22 @@
+
+/*
+ * Copyright (C) Igor Sysoev
+ * Copyright (C) Nginx, Inc.
+ */
+
+
+#ifndef _NGX_PARSE_TIME_H_INCLUDED_
+#define _NGX_PARSE_TIME_H_INCLUDED_
+
+
+#include <ngx_config.h>
+#include <ngx_core.h>
+
+
+time_t ngx_parse_http_time(u_char *value, size_t len);
+
+/* compatibility */
+#define ngx_http_parse_time(value, len) ngx_parse_http_time(value, len)
+
+
+#endif /* _NGX_PARSE_TIME_H_INCLUDED_ */
diff --git a/src/core/ngx_proxy_protocol.c b/src/core/ngx_proxy_protocol.c
index 59ef010fc..f347e7f43 100644
--- a/src/core/ngx_proxy_protocol.c
+++ b/src/core/ngx_proxy_protocol.c
@@ -10,7 +10,7 @@
u_char *
-ngx_proxy_protocol_parse(ngx_connection_t *c, u_char *buf, u_char *last)
+ngx_proxy_protocol_read(ngx_connection_t *c, u_char *buf, u_char *last)
{
size_t len;
u_char ch, *p, *addr;
@@ -89,3 +89,52 @@ invalid:
return NULL;
}
+
+
+u_char *
+ngx_proxy_protocol_write(ngx_connection_t *c, u_char *buf, u_char *last)
+{
+ ngx_uint_t port, lport;
+
+ if (last - buf < NGX_PROXY_PROTOCOL_MAX_HEADER) {
+ return NULL;
+ }
+
+ if (ngx_connection_local_sockaddr(c, NULL, 0) != NGX_OK) {
+ return NULL;
+ }
+
+ switch (c->sockaddr->sa_family) {
+
+ case AF_INET:
+ buf = ngx_cpymem(buf, "PROXY TCP4 ", sizeof("PROXY TCP4 ") - 1);
+
+ port = ntohs(((struct sockaddr_in *) c->sockaddr)->sin_port);
+ lport = ntohs(((struct sockaddr_in *) c->local_sockaddr)->sin_port);
+
+ break;
+
+#if (NGX_HAVE_INET6)
+ case AF_INET6:
+ buf = ngx_cpymem(buf, "PROXY TCP6 ", sizeof("PROXY TCP6 ") - 1);
+
+ port = ntohs(((struct sockaddr_in6 *) c->sockaddr)->sin6_port);
+ lport = ntohs(((struct sockaddr_in6 *) c->local_sockaddr)->sin6_port);
+
+ break;
+#endif
+
+ default:
+ return ngx_cpymem(buf, "PROXY UNKNOWN" CRLF,
+ sizeof("PROXY UNKNOWN" CRLF) - 1);
+ }
+
+ buf += ngx_sock_ntop(c->sockaddr, c->socklen, buf, last - buf, 0);
+
+ *buf++ = ' ';
+
+ buf += ngx_sock_ntop(c->local_sockaddr, c->local_socklen, buf, last - buf,
+ 0);
+
+ return ngx_slprintf(buf, last, " %ui %ui" CRLF, port, lport);
+}
diff --git a/src/core/ngx_proxy_protocol.h b/src/core/ngx_proxy_protocol.h
index 4f3912512..fb848f683 100644
--- a/src/core/ngx_proxy_protocol.h
+++ b/src/core/ngx_proxy_protocol.h
@@ -16,7 +16,9 @@
#define NGX_PROXY_PROTOCOL_MAX_HEADER 107
-u_char *ngx_proxy_protocol_parse(ngx_connection_t *c, u_char *buf,
+u_char *ngx_proxy_protocol_read(ngx_connection_t *c, u_char *buf,
+ u_char *last);
+u_char *ngx_proxy_protocol_write(ngx_connection_t *c, u_char *buf,
u_char *last);