nginx-0.0.1-2003-05-30-18:27:59 import

This commit is contained in:
Igor Sysoev 2003-05-30 14:27:59 +00:00
parent 1393325df8
commit aa3436c04c
15 changed files with 180 additions and 140 deletions

View File

@ -1,31 +1,17 @@
#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_listen.h>
#include <nginx.h>
#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_connection.h>
#include <ngx_os_init.h>
#include <ngx_server.h>
#include <ngx_listen.h>
#include <ngx_conf_file.h>
/* STUB */
#include <ngx_http.h>
/* */
static void ngx_set_signals(ngx_log_t *log);
static void ngx_open_listening_sockets(ngx_log_t *log);
static int ngx_open_listening_sockets(ngx_log_t *log);
/* STUB */
int ngx_max_conn = 512;
u_int ngx_sendfile_flags;
ngx_server_t ngx_server;
/* */
ngx_log_t ngx_log;
ngx_pool_t *ngx_pool;
void ****ngx_conf_ctx;
@ -34,8 +20,8 @@ void ****ngx_conf_ctx;
ngx_os_io_t ngx_io;
int ngx_max_module;
void *ctx_conf;
int ngx_max_module;
void *ctx_conf;
int ngx_connection_counter;
@ -109,7 +95,9 @@ int main(int argc, char *const *argv)
}
}
ngx_open_listening_sockets(&ngx_log);
if (ngx_open_listening_sockets(&ngx_log) == NGX_ERROR) {
return 1;
}
/* TODO: daemon, once only */
@ -127,7 +115,7 @@ int main(int argc, char *const *argv)
}
static void ngx_open_listening_sockets(ngx_log_t *log)
static int ngx_open_listening_sockets(ngx_log_t *log)
{
int times, failed, reuseaddr, i;
ngx_err_t err;
@ -161,7 +149,7 @@ static void ngx_open_listening_sockets(ngx_log_t *log)
if (s == -1) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
ngx_socket_n " %s falied", ls[i].addr_text.data);
exit(1);
return NGX_ERROR;
}
if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR,
@ -169,7 +157,7 @@ static void ngx_open_listening_sockets(ngx_log_t *log)
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
"setsockopt(SO_REUSEADDR) %s failed",
ls[i].addr_text.data);
exit(1);
return NGX_ERROR;
}
/* TODO: close on exit */
@ -179,7 +167,7 @@ static void ngx_open_listening_sockets(ngx_log_t *log)
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
ngx_nonblocking_n " %s failed",
ls[i].addr_text.data);
exit(1);
return NGX_ERROR;
}
}
@ -189,7 +177,7 @@ static void ngx_open_listening_sockets(ngx_log_t *log)
"bind() to %s failed", ls[i].addr_text.data);
if (err != NGX_EADDRINUSE)
exit(1);
return NGX_ERROR;
if (ngx_close_socket(s) == -1)
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
@ -203,7 +191,7 @@ static void ngx_open_listening_sockets(ngx_log_t *log)
if (listen(s, ls[i].backlog) == -1) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
"listen() to %s failed", ls[i].addr_text.data);
exit(1);
return NGX_ERROR;
}
/* TODO: deferred accept */
@ -222,6 +210,8 @@ static void ngx_open_listening_sockets(ngx_log_t *log)
if (failed) {
ngx_log_error(NGX_LOG_EMERG, log, 0, "can not bind(), exiting");
exit(1);
return NGX_ERROR;
}
return NGX_OK;
}

View File

@ -20,7 +20,7 @@ static int ngx_conf_read_token(ngx_conf_t *cf);
char *ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename)
{
int m, rc, found;
int m, rc, found, valid;
char *rv;
void *conf, **confp;
ngx_str_t *name;
@ -139,15 +139,33 @@ ngx_log_debug(cf->log, "command '%s'" _ cmd->name.data);
/* is the directive's argument count right ? */
if (!(cmd->type & NGX_CONF_ANY)
&& ((cmd->type & NGX_CONF_FLAG && cf->args->nelts != 2)
|| (!(cmd->type & NGX_CONF_FLAG)
&& !(cmd->type
& argument_number[cf->args->nelts - 1])
)
)
)
{
if (cmd->type & argument_number[cf->args->nelts - 1]) {
valid = 1;
} else if (cmd->type & NGX_CONF_ANY1) {
if (cf->args->nelts != 1) {
valid = 1;
} else {
valid = 0;
}
} else if (cmd->type & NGX_CONF_FLAG) {
if (cf->args->nelts == 2) {
valid = 1;
} else {
valid = 0;
}
} else if (cmd->type & NGX_CONF_ANY) {
valid = 1;
} else {
valid = 0;
}
if (!valid) {
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
"invalid number arguments in "
"directive \"%s\" in %s:%d",
@ -441,10 +459,12 @@ ngx_log_debug(cf->log, "FOUND %d:'%s'" _ word->len _ word->data);
char *ngx_conf_set_flag_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
char *p = conf;
int flag;
ngx_str_t *value;
if (*(int *) (conf + cmd->offset) != NGX_CONF_UNSET) {
if (*(int *) (p + cmd->offset) != NGX_CONF_UNSET) {
return "is duplicate";
}
@ -457,10 +477,13 @@ char *ngx_conf_set_flag_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
flag = 0;
} else {
return "must be \"on\" or \"off\"";
ngx_snprintf(ngx_conf_errstr, sizeof(ngx_conf_errstr) - 1,
"invalid value \"%s\", it must be \"on\" or \"off\"",
value[1].data);
return ngx_conf_errstr;
}
*(int *) (conf + cmd->offset) = flag;
*(int *) (p + cmd->offset) = flag;
return NGX_CONF_OK;
}
@ -468,9 +491,11 @@ char *ngx_conf_set_flag_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
char *ngx_conf_set_str_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
char *p = conf;
ngx_str_t *field, *value;
field = (ngx_str_t *) (conf + cmd->offset);
field = (ngx_str_t *) (p + cmd->offset);
if (field->data) {
return "is duplicate";
@ -487,10 +512,12 @@ char *ngx_conf_set_str_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
char *ngx_conf_set_num_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
char *p = conf;
int num, len;
ngx_str_t *value;
if (*(int *) (conf + cmd->offset) != NGX_CONF_UNSET) {
if (*(int *) (p + cmd->offset) != NGX_CONF_UNSET) {
return "is duplicate";
}
@ -500,10 +527,10 @@ char *ngx_conf_set_num_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
num = ngx_atoi(value[1].data, len);
if (num == NGX_ERROR) {
return "invalid value";
return "invalid number";
}
*(int *) (conf + cmd->offset) = num;
*(int *) (p + cmd->offset) = num;
return NGX_CONF_OK;
}
@ -511,11 +538,13 @@ char *ngx_conf_set_num_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
char *ngx_conf_set_size_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
char *p = conf;
int size, len, scale;
char last;
ngx_str_t *value;
if (*(int *) (conf + cmd->offset) != NGX_CONF_UNSET) {
if (*(int *) (p + cmd->offset) != NGX_CONF_UNSET) {
return "is duplicate";
}
@ -548,7 +577,7 @@ char *ngx_conf_set_size_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
size *= scale;
*(int *) (conf + cmd->offset) = size;
*(int *) (p + cmd->offset) = size;
return NGX_CONF_OK;
}
@ -556,12 +585,14 @@ char *ngx_conf_set_size_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
char *ngx_conf_set_msec_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
char *p = conf;
int size, total, len, scale;
u_int max, i;
char last, *start;
ngx_str_t *value;
if (*(int *) (conf + cmd->offset) != NGX_CONF_UNSET) {
if (*(int *) (p + cmd->offset) != NGX_CONF_UNSET) {
return "is duplicate";
}
@ -643,7 +674,7 @@ char *ngx_conf_set_msec_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
start = &value[1].data[i + 1];
}
*(int *) (conf + cmd->offset) = total;
*(int *) (p + cmd->offset) = total;
return NGX_CONF_OK;
}
@ -651,12 +682,14 @@ char *ngx_conf_set_msec_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
char *ngx_conf_set_sec_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
char *p = conf;
int size, total, len, scale;
u_int max, i;
char last, *start;
ngx_str_t *value;
if (*(int *) (conf + cmd->offset) != NGX_CONF_UNSET) {
if (*(int *) (p + cmd->offset) != NGX_CONF_UNSET) {
return "is duplicate";
}
@ -750,7 +783,7 @@ char *ngx_conf_set_sec_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
start = &value[1].data[i + 1];
}
*(int *) (conf + cmd->offset) = total;
*(int *) (p + cmd->offset) = total;
return NGX_CONF_OK;
}

View File

@ -24,8 +24,9 @@
#define NGX_CONF_TAKE2 0x00000004
#define NGX_CONF_ARGS_NUMBER 0x0000ffff
#define NGX_CONF_ANY 0x00010000
#define NGX_CONF_BLOCK 0x00020000
#define NGX_CONF_FLAG 0x00040000
#define NGX_CONF_ANY1 0x00020000
#define NGX_CONF_BLOCK 0x00040000
#define NGX_CONF_FLAG 0x00080000
#define NGX_MAIN_CONF 0x01000000
@ -83,7 +84,7 @@ typedef struct {
typedef char *(*ngx_conf_handler_pt)(ngx_conf_t *cf,
ngx_command_t *dummy, char *conf);
ngx_command_t *dummy, void *conf);
struct ngx_conf_s {

View File

@ -43,7 +43,7 @@ typedef struct ngx_event_s ngx_event_t;
#define NGX_MAXHOSTNAMELEN 32
#define NGX_MAXHOSTNAMELEN 64
/*
#define NGX_MAXHOSTNAMELEN MAXHOSTNAMELEN
*/

View File

@ -46,7 +46,7 @@ typedef struct {
#endif
#define ngx_memcpy(dst, src, n) memcpy(dst, src, n)
#define ngx_cpymem(dst, src, n) memcpy(dst, src, n) + n
#define ngx_cpymem(dst, src, n) ((char *) memcpy(dst, src, n)) + n
char *ngx_cpystrn(char *dst, char *src, size_t n);
int ngx_rstrncmp(char *s1, char *s2, size_t n);

View File

@ -63,7 +63,8 @@ void ngx_event_accept(ngx_event_t *ev)
return;
}
if (s >= ecf->connections) {
/* disable warnings: Win32 SOCKET is u_int while UNIX socket is int */
if ((unsigned) s >= (unsigned) ecf->connections) {
ngx_log_error(NGX_LOG_ALERT, ev->log, 0,
"accept() %s returned socket #%d while "

View File

@ -14,7 +14,7 @@ static char *ngx_http_index_set_index(ngx_conf_t *cf, ngx_command_t *cmd,
static ngx_command_t ngx_http_index_commands[] = {
{ngx_string("index"),
NGX_HTTP_LOC_CONF|NGX_CONF_ANY,
NGX_HTTP_LOC_CONF|NGX_CONF_ANY1,
ngx_http_index_set_index,
NGX_HTTP_LOC_CONF_OFFSET,
0,
@ -280,7 +280,7 @@ static char *ngx_http_index_set_index(ngx_conf_t *cf, ngx_command_t *cmd,
for (i = 1; i < cf->args->nelts; i++) {
if (value[i].len == 0) {
ngx_snprintf(ngx_conf_errstr, sizeof(ngx_conf_errstr) - 1,
"index \"%s\" is invalid", value[1].data);
"index \"%s\" is invalid", value[i].data);
return ngx_conf_errstr;
}

View File

@ -151,14 +151,14 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
and its location{}s' loc_conf's */
cmcf = ctx->main_conf[ngx_http_core_module.ctx_index];
cscfp = (ngx_http_core_srv_conf_t **)cmcf->servers.elts;
cscfp = cmcf->servers.elts;
for (m = 0; ngx_modules[m]; m++) {
if (ngx_modules[m]->type != NGX_HTTP_MODULE) {
continue;
}
module = (ngx_http_module_t *) ngx_modules[m]->ctx;
module = ngx_modules[m]->ctx;
mi = ngx_modules[m]->ctx_index;
/* init http{} main_conf's */
@ -227,18 +227,18 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
NGX_CONF_ERROR);
/* "server" directives */
cscfp = (ngx_http_core_srv_conf_t **) cmcf->servers.elts;
cscfp = cmcf->servers.elts;
for (s = 0; s < cmcf->servers.nelts; s++) {
/* "listen" directives */
lscf = (ngx_http_listen_t *) cscfp[s]->listen.elts;
lscf = cscfp[s]->listen.elts;
for (l = 0; l < cscfp[s]->listen.nelts; l++) {
port_found = 0;
/* AF_INET only */
in_port = (ngx_http_in_port_t *) in_ports.elts;
in_port = in_ports.elts;
for (p = 0; p < in_ports.nelts; p++) {
if (lscf[l].port == in_port[p].port) {
@ -248,7 +248,7 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
port_found = 1;
addr_found = 0;
in_addr = (ngx_http_in_addr_t *) in_port[p].addrs.elts;
in_addr = in_port[p].addrs.elts;
for (a = 0; a < in_port[p].addrs.nelts; a++) {
if (lscf[l].addr == in_addr[a].addr) {
@ -256,8 +256,7 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
/* the address is already bound to this port */
/* "server_name" directives */
s_name = (ngx_http_server_name_t *)
cscfp[s]->server_names.elts;
s_name = cscfp[s]->server_names.elts;
for (n = 0; n < cscfp[s]->server_names.nelts; n++) {
/* add the server name and server core module
@ -394,17 +393,17 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
/* AF_INET only */
in_port = (ngx_http_in_port_t *) in_ports.elts;
in_port = in_ports.elts;
for (p = 0; p < in_ports.nelts; p++) {
/* check whether the all server names point to the same server */
in_addr = (ngx_http_in_addr_t *) in_port[p].addrs.elts;
in_addr = in_port[p].addrs.elts;
for (a = 0; a < in_port[p].addrs.nelts; a++) {
virtual_names = 0;
name = (ngx_http_server_name_t *) in_addr[a].names.elts;
name = in_addr[a].names.elts;
for (n = 0; n < in_addr[a].names.nelts; n++) {
if (in_addr[a].core_srv_conf != name[n].core_srv_conf) {
virtual_names = 1;
@ -430,7 +429,7 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
a = 0;
}
in_addr = (ngx_http_in_addr_t *) in_port[p].addrs.elts;
in_addr = in_port[p].addrs.elts;
while (a < in_port[p].addrs.nelts) {
ngx_test_null(ls, ngx_push_array(&ngx_listening_sockets),
@ -443,7 +442,7 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
addr_in->sin_family = AF_INET;
addr_in->sin_addr.s_addr = in_addr[a].addr;
addr_in->sin_port = htons(in_port[p].port);
addr_in->sin_port = htons((u_short) in_port[p].port);
ngx_test_null(ls->addr_text.data,
ngx_palloc(cf->pool, INET_ADDRSTRLEN + 6),
@ -478,7 +477,7 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
if (in_port[p].addrs.nelts > 1) {
in_addr = (ngx_http_in_addr_t *) in_port[p].addrs.elts;
in_addr = in_port[p].addrs.elts;
if (in_addr[in_port[p].addrs.nelts - 1].addr != INADDR_ANY) {
/* if this port has not the "*:port" binding then create
@ -523,14 +522,19 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
}
/* DEBUG STUFF */
in_port = (ngx_http_in_port_t *) in_ports.elts;
in_port = in_ports.elts;
for (p = 0; p < in_ports.nelts; p++) {
ngx_log_debug(cf->log, "port: %d" _ in_port[p].port);
in_addr = (ngx_http_in_addr_t *) in_port[p].addrs.elts;
in_addr = in_port[p].addrs.elts;
for (a = 0; a < in_port[p].addrs.nelts; a++) {
char ip[20];
ngx_inet_ntop(AF_INET, (char *) &in_addr[a].addr, ip, 20);
ngx_log_debug(cf->log, "%s %08x" _ ip _ in_addr[a].core_srv_conf);
s_name = in_addr[a].names.elts;
for (n = 0; n < in_addr[a].names.nelts; n++) {
ngx_log_debug(cf->log, "%s %08x" _ s_name[n].name.data _
s_name[n].core_srv_conf);
}
}
}
/**/

View File

@ -32,6 +32,7 @@ static int ngx_cmp_locations(const void *first, const void *second);
static char *ngx_location_block(ngx_conf_t *cf, ngx_command_t *cmd,
void *dummy);
static char *ngx_types_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
static char *ngx_set_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf);
static char *ngx_set_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
static char *ngx_set_server_name(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
@ -103,7 +104,7 @@ static ngx_command_t ngx_http_core_commands[] = {
NULL},
{ngx_string("server_name"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_ANY,
NGX_HTTP_SRV_CONF|NGX_CONF_ANY1,
ngx_set_server_name,
NGX_HTTP_SRV_CONF_OFFSET,
0,
@ -281,8 +282,6 @@ int ngx_http_core_translate_handler(ngx_http_request_t *r)
char *location, *last;
ngx_err_t err;
ngx_table_elt_t *h;
ngx_http_in_port_t *in_port;
ngx_http_server_name_t *s_name;
ngx_http_core_srv_conf_t *cscf;
ngx_http_core_loc_conf_t *clcf;
@ -669,9 +668,24 @@ static char *ngx_location_block(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
}
static char *ngx_set_type(ngx_conf_t *cf, ngx_command_t *dummy, char *conf)
static char *ngx_types_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_core_loc_conf_t *lcf = (ngx_http_core_loc_conf_t *) conf;
char *rv;
ngx_conf_t pcf;
pcf = *cf;
cf->handler = ngx_set_type;
cf->handler_conf = conf;
rv = ngx_conf_parse(cf, NULL);
*cf = pcf;
return rv;
}
static char *ngx_set_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
{
ngx_http_core_loc_conf_t *lcf = conf;
int i, key;
ngx_str_t *args;
@ -705,21 +719,6 @@ static char *ngx_set_type(ngx_conf_t *cf, ngx_command_t *dummy, char *conf)
}
static char *ngx_types_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
char *rv;
ngx_conf_t pcf;
pcf = *cf;
cf->handler = ngx_set_type;
cf->handler_conf = conf;
rv = ngx_conf_parse(cf, NULL);
*cf = pcf;
return rv;
}
static void *ngx_http_core_create_main_conf(ngx_pool_t *pool)
{
ngx_http_core_main_conf_t *cmcf;
@ -775,9 +774,10 @@ static void *ngx_http_core_create_srv_conf(ngx_pool_t *pool)
static char *ngx_http_core_merge_srv_conf(ngx_pool_t *pool,
void *parent, void *child)
{
ngx_http_core_srv_conf_t *prev = (ngx_http_core_srv_conf_t *) parent;
ngx_http_core_srv_conf_t *conf = (ngx_http_core_srv_conf_t *) child;
ngx_http_core_srv_conf_t *prev = parent;
ngx_http_core_srv_conf_t *conf = child;
int len;
ngx_err_t err;
ngx_http_listen_t *l;
ngx_http_server_name_t *n;
@ -798,9 +798,12 @@ static char *ngx_http_core_merge_srv_conf(ngx_pool_t *pool,
if (gethostname(n->name.data, NGX_MAXHOSTNAMELEN) == -1) {
err = ngx_errno;
ngx_snprintf(ngx_conf_errstr, sizeof(ngx_conf_errstr) - 1,
"gethostname() failed (%d: %s)",
err, ngx_strerror(err));
len = ngx_snprintf(ngx_conf_errstr, sizeof(ngx_conf_errstr) - 1,
"gethostname() failed (%d: ", err);
len += ngx_strerror_r(err, ngx_conf_errstr + len,
sizeof(ngx_conf_errstr) - len - 1);
ngx_conf_errstr[len++] = ')';
ngx_conf_errstr[len++] = '\0';
return ngx_conf_errstr;
}
@ -862,8 +865,8 @@ static ngx_http_type_t default_types[] = {
static char *ngx_http_core_merge_loc_conf(ngx_pool_t *pool,
void *parent, void *child)
{
ngx_http_core_loc_conf_t *prev = (ngx_http_core_loc_conf_t *) parent;
ngx_http_core_loc_conf_t *conf = (ngx_http_core_loc_conf_t *) child;
ngx_http_core_loc_conf_t *prev = parent;
ngx_http_core_loc_conf_t *conf = child;
int i, key;
ngx_http_type_t *t;
@ -919,7 +922,7 @@ static char *ngx_http_core_merge_loc_conf(ngx_pool_t *pool,
static char *ngx_set_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_core_srv_conf_t *scf = (ngx_http_core_srv_conf_t *) conf;
ngx_http_core_srv_conf_t *scf = conf;
char *addr;
u_int p;
@ -963,11 +966,11 @@ static char *ngx_set_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
} else if ((ls->port == NGX_ERROR && p != 0) /* "listen host:NONNUMBER" */
|| (ls->port < 1 || ls->port > 65536)) { /* "listen 99999" */
ngx_snprintf(ngx_conf_errstr, sizeof(ngx_conf_errstr) - 1,
"invalid port \"%s\", "
"it must be a number between 1 and 65535",
&addr[p]);
return ngx_conf_errstr;
ngx_snprintf(ngx_conf_errstr, sizeof(ngx_conf_errstr) - 1,
"invalid port \"%s\", "
"it must be a number between 1 and 65535",
&addr[p]);
return ngx_conf_errstr;
} else if (p == 0) {
ls->addr = INADDR_ANY;
@ -993,21 +996,30 @@ static char *ngx_set_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
static char *ngx_set_server_name(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_core_srv_conf_t *scf = (ngx_http_core_srv_conf_t *) conf;
ngx_http_core_srv_conf_t *scf = conf;
ngx_str_t *args;
int i;
ngx_str_t *value;
ngx_http_server_name_t *sn;
/* TODO: several names */
/* TODO: warn about duplicate 'server_name' directives */
ngx_test_null(sn, ngx_push_array(&scf->server_names), NGX_CONF_ERROR);
value = cf->args->elts;
args = cf->args->elts;
for (i = 1; i < cf->args->nelts; i++) {
if (value[i].len == 0) {
ngx_snprintf(ngx_conf_errstr, sizeof(ngx_conf_errstr) - 1,
"server name \"%s\" is invalid", value[i].data);
return ngx_conf_errstr;
}
sn->name.len = args[1].len;
sn->name.data = args[1].data;
sn->core_srv_conf = scf;
ngx_test_null(sn, ngx_push_array(&scf->server_names), NGX_CONF_ERROR);
sn->name.len = value[i].len;
sn->name.data = value[i].data;
sn->core_srv_conf = scf;
}
return NGX_CONF_OK;
}

View File

@ -1,16 +1,10 @@
#include <ngx_config.h>
#include <ngx_core.h>
#include <nginx.h>
#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_string.h>
#include <ngx_table.h>
#include <ngx_hunk.h>
#include <ngx_conf_file.h>
#include <ngx_http.h>
#include <ngx_http_config.h>
#include <ngx_http_write_filter.h>

View File

@ -119,7 +119,7 @@ int ngx_http_output_filter(ngx_http_request_t *r, ngx_hunk_t *hunk)
if (hunk->type & NGX_HUNK_IN_MEMORY) {
size = hunk->last - hunk->pos;
} else {
size = hunk->file_last - hunk->file_pos;
size = (size_t) (hunk->file_last - hunk->file_pos);
}
if (size > conf->hunk_size) {
@ -201,8 +201,8 @@ int ngx_http_output_filter(ngx_http_request_t *r, ngx_hunk_t *hunk)
size = ctx->incoming->hunk->last - ctx->incoming->hunk->pos;
} else {
size = ctx->incoming->hunk->file_last
- ctx->incoming->hunk->file_pos;
size = (size_t) (ctx->incoming->hunk->file_last
- ctx->incoming->hunk->file_pos);
}
/* delete the completed hunk from the incoming chain */
@ -241,7 +241,7 @@ static int ngx_http_output_filter_copy_hunk(ngx_hunk_t *dst, ngx_hunk_t *src)
if (src->type & NGX_HUNK_IN_MEMORY) {
size = src->last - src->pos;
} else {
size = src->file_last - src->file_pos;
size = (size_t) (src->file_last - src->file_pos);
}
if (size > (dst->end - dst->pos)) {

View File

@ -1,9 +1,9 @@
#include <nginx.h>
#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_string.h>
#include <nginx.h>
#include <ngx_http.h>
#include <ngx_http_output_filter.h>

View File

@ -24,7 +24,9 @@ typedef int ngx_err_t;
#define ngx_socket_errno errno
#define ngx_set_socket_errno(err) errno = err
#if 0
#define ngx_strerror(err) strerror(err)
#endif
#define ngx_strerror_r(err, errstr, size) \
ngx_cpystrn(errstr, strerror(err), size) - (errstr)

View File

@ -1,13 +1,13 @@
/*
TODO:
add WSA error messages
add WSA error messages for NT and 98
test for English only messages
*/
#include <ngx_config.h>
#include <ngx_string.h>
#include <ngx_errno.h>
#include <ngx_core.h>
int ngx_strerror_r(ngx_err_t err, char *errstr, size_t size)
{

View File

@ -53,8 +53,8 @@
int ngx_file_type(char *filename, ngx_file_info_t *fi);
#define ngx_file_type_n "GetFileAttributes"
#define ngx_stat_fd(fd, fi) GetFileInformationByHandle(fd, fi)
#define ngx_stat_fd_n "GetFileInformationByHandle"
#define ngx_stat_fd(fd, fi) GetFileInformationByHandle(fd, fi)
#define ngx_stat_fd_n "GetFileInformationByHandle"
#define ngx_is_dir(fi) (fi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
#define ngx_is_file(fi) !(fi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
@ -73,7 +73,10 @@ int ngx_file_type(char *filename, ngx_file_info_t *fi);
ssize_t ngx_read_file(ngx_file_t *file, char *buf, size_t size, off_t offset);
#define ngx_read_file_n "ReadFile()"
#define ngx_read_file_n "ReadFile()"
#define STDERR_FILENO (HANDLE) 2
#endif /* _NGX_FILES_H_INCLUDED_ */