nginx-0.0.10-2004-08-31-19:32:52 import

This commit is contained in:
Igor Sysoev 2004-08-31 15:32:52 +00:00
parent 9660d415a0
commit a94339e252
4 changed files with 83 additions and 36 deletions

View file

@ -663,7 +663,8 @@ char *ngx_conf_set_str_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{ {
char *p = conf; char *p = conf;
ngx_str_t *field, *value; ngx_str_t *field, *value;
ngx_conf_post_t *post;
field = (ngx_str_t *) (p + cmd->offset); field = (ngx_str_t *) (p + cmd->offset);
@ -675,6 +676,11 @@ char *ngx_conf_set_str_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
*field = value[1]; *field = value[1];
if (cmd->post) {
post = cmd->post;
return post->post_handler(cf, post, field);
}
return NGX_CONF_OK; return NGX_CONF_OK;
} }

View file

@ -122,42 +122,42 @@ static ngx_command_t ngx_http_gzip_filter_commands[] = {
ngx_conf_set_flag_slot, ngx_conf_set_flag_slot,
NGX_HTTP_LOC_CONF_OFFSET, NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_gzip_conf_t, enable), offsetof(ngx_http_gzip_conf_t, enable),
NULL}, NULL },
{ ngx_string("gzip_buffers"), { ngx_string("gzip_buffers"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2, NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2,
ngx_conf_set_bufs_slot, ngx_conf_set_bufs_slot,
NGX_HTTP_LOC_CONF_OFFSET, NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_gzip_conf_t, bufs), offsetof(ngx_http_gzip_conf_t, bufs),
NULL}, NULL },
{ ngx_string("gzip_comp_level"), { ngx_string("gzip_comp_level"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
ngx_conf_set_num_slot, ngx_conf_set_num_slot,
NGX_HTTP_LOC_CONF_OFFSET, NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_gzip_conf_t, level), offsetof(ngx_http_gzip_conf_t, level),
&ngx_http_gzip_comp_level_bounds}, &ngx_http_gzip_comp_level_bounds },
{ ngx_string("gzip_window"), { ngx_string("gzip_window"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
ngx_conf_set_size_slot, ngx_conf_set_size_slot,
NGX_HTTP_LOC_CONF_OFFSET, NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_gzip_conf_t, wbits), offsetof(ngx_http_gzip_conf_t, wbits),
&ngx_http_gzip_set_window_p}, &ngx_http_gzip_set_window_p },
{ ngx_string("gzip_hash"), { ngx_string("gzip_hash"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
ngx_conf_set_size_slot, ngx_conf_set_size_slot,
NGX_HTTP_LOC_CONF_OFFSET, NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_gzip_conf_t, memlevel), offsetof(ngx_http_gzip_conf_t, memlevel),
&ngx_http_gzip_set_hash_p}, &ngx_http_gzip_set_hash_p },
{ ngx_string("gzip_no_buffer"), { ngx_string("gzip_no_buffer"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
ngx_conf_set_flag_slot, ngx_conf_set_flag_slot,
NGX_HTTP_LOC_CONF_OFFSET, NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_gzip_conf_t, no_buffer), offsetof(ngx_http_gzip_conf_t, no_buffer),
NULL}, NULL },
{ ngx_string("gzip_http_version"), { ngx_string("gzip_http_version"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_ANY, NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_ANY,
@ -178,7 +178,7 @@ static ngx_command_t ngx_http_gzip_filter_commands[] = {
ngx_conf_set_size_slot, ngx_conf_set_size_slot,
NGX_HTTP_LOC_CONF_OFFSET, NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_gzip_conf_t, min_length), offsetof(ngx_http_gzip_conf_t, min_length),
NULL}, NULL },
ngx_null_command ngx_null_command
}; };

View file

@ -51,6 +51,7 @@ static ngx_int_t ngx_http_userid_pre_conf(ngx_conf_t *cf);
static void *ngx_http_userid_create_conf(ngx_conf_t *cf); static void *ngx_http_userid_create_conf(ngx_conf_t *cf);
static char *ngx_http_userid_merge_conf(ngx_conf_t *cf, void *parent, static char *ngx_http_userid_merge_conf(ngx_conf_t *cf, void *parent,
void *child); void *child);
char *ngx_conf_check_domain(ngx_conf_t *cf, void *post, void *data);
char *ngx_http_userid_expires(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); char *ngx_http_userid_expires(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
@ -73,6 +74,10 @@ static ngx_conf_enum_t ngx_http_userid_state[] = {
}; };
static ngx_conf_post_handler_pt ngx_conf_check_domain_p =
ngx_conf_check_domain;
static ngx_command_t ngx_http_userid_commands[] = { static ngx_command_t ngx_http_userid_commands[] = {
{ ngx_string("userid"), { ngx_string("userid"),
@ -80,42 +85,42 @@ static ngx_command_t ngx_http_userid_commands[] = {
ngx_conf_set_enum_slot, ngx_conf_set_enum_slot,
NGX_HTTP_LOC_CONF_OFFSET, NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_userid_conf_t, enable), offsetof(ngx_http_userid_conf_t, enable),
ngx_http_userid_state}, ngx_http_userid_state },
{ ngx_string("userid_service"), { ngx_string("userid_service"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
ngx_conf_set_num_slot, ngx_conf_set_num_slot,
NGX_HTTP_LOC_CONF_OFFSET, NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_userid_conf_t, service), offsetof(ngx_http_userid_conf_t, service),
NULL}, NULL },
{ ngx_string("userid_name"), { ngx_string("userid_name"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
ngx_conf_set_str_slot, ngx_conf_set_str_slot,
NGX_HTTP_LOC_CONF_OFFSET, NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_userid_conf_t, name), offsetof(ngx_http_userid_conf_t, name),
NULL}, NULL },
{ ngx_string("userid_domain"), { ngx_string("userid_domain"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
ngx_conf_set_str_slot, ngx_conf_set_str_slot,
NGX_HTTP_LOC_CONF_OFFSET, NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_userid_conf_t, domain), offsetof(ngx_http_userid_conf_t, domain),
NULL}, &ngx_conf_check_domain_p },
{ ngx_string("userid_path"), { ngx_string("userid_path"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
ngx_conf_set_str_slot, ngx_conf_set_str_slot,
NGX_HTTP_LOC_CONF_OFFSET, NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_userid_conf_t, path), offsetof(ngx_http_userid_conf_t, path),
NULL}, NULL },
{ ngx_string("userid_expires"), { ngx_string("userid_expires"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
ngx_http_userid_expires, ngx_http_userid_expires,
NGX_HTTP_LOC_CONF_OFFSET, NGX_HTTP_LOC_CONF_OFFSET,
0, 0,
NULL}, NULL },
ngx_null_command ngx_null_command
}; };
@ -165,8 +170,7 @@ static ngx_int_t ngx_http_userid_filter(ngx_http_request_t *r)
} }
ngx_http_create_ctx(r, ctx, ngx_http_userid_filter_module, ngx_http_create_ctx(r, ctx, ngx_http_userid_filter_module,
sizeof(ngx_http_userid_ctx_t), sizeof(ngx_http_userid_ctx_t), NGX_ERROR);
NGX_HTTP_INTERNAL_SERVER_ERROR);
rc = ngx_http_userid_get_uid(r, ctx, conf); rc = ngx_http_userid_get_uid(r, ctx, conf);
@ -174,8 +178,8 @@ static ngx_int_t ngx_http_userid_filter(ngx_http_request_t *r)
return rc; return rc;
} }
if (conf->enable == NGX_HTTP_USERID_LOG /* || ctx->uid_got[3] != 0 */) { if (conf->enable == NGX_HTTP_USERID_LOG || ctx->uid_got[3] != 0) {
return NGX_OK; return ngx_http_next_header_filter(r);
} }
rc = ngx_http_userid_set_uid(r, ctx, conf); rc = ngx_http_userid_set_uid(r, ctx, conf);
@ -276,11 +280,13 @@ static ngx_int_t ngx_http_userid_set_uid(ngx_http_request_t *r,
ngx_http_userid_conf_t *conf) ngx_http_userid_conf_t *conf)
{ {
u_char *cookie, *p; u_char *cookie, *p;
size_t len; size_t len;
uint32_t service; socklen_t slen;
ngx_str_t src, dst; struct sockaddr_in addr_in;
ngx_table_elt_t *set_cookie; uint32_t service;
ngx_str_t src, dst;
ngx_table_elt_t *set_cookie;
/* TODO: mutex for sequencers */ /* TODO: mutex for sequencers */
@ -298,7 +304,21 @@ static ngx_int_t ngx_http_userid_set_uid(ngx_http_request_t *r,
} else { } else {
if (conf->service == NGX_CONF_UNSET) { if (conf->service == NGX_CONF_UNSET) {
if (r->in_addr == 0) {
slen = sizeof(struct sockaddr_in);
if (getsockname(r->connection->fd,
(struct sockaddr *) &addr_in, &slen) == -1)
{
ngx_log_error(NGX_LOG_CRIT, r->connection->log,
ngx_socket_errno,
"getsockname() failed");
}
r->in_addr = addr_in.sin_addr.s_addr;
}
ctx->uid_set[0] = htonl(r->in_addr); ctx->uid_set[0] = htonl(r->in_addr);
} else { } else {
ctx->uid_set[0] = htonl(conf->service); ctx->uid_set[0] = htonl(conf->service);
} }
@ -327,7 +347,7 @@ static ngx_int_t ngx_http_userid_set_uid(ngx_http_request_t *r,
} }
if (!(cookie = ngx_palloc(r->pool, len))) { if (!(cookie = ngx_palloc(r->pool, len))) {
return NGX_HTTP_INTERNAL_SERVER_ERROR; return NGX_ERROR;
} }
p = ngx_cpymem(cookie, conf->name.data, conf->name.len); p = ngx_cpymem(cookie, conf->name.data, conf->name.len);
@ -366,7 +386,7 @@ static ngx_int_t ngx_http_userid_set_uid(ngx_http_request_t *r,
set_cookie = ngx_http_add_header(&r->headers_out, ngx_http_headers_out); set_cookie = ngx_http_add_header(&r->headers_out, ngx_http_headers_out);
if (set_cookie == NULL) { if (set_cookie == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR; return NGX_ERROR;
} }
set_cookie->key.len = sizeof("Set-Cookie") - 1; set_cookie->key.len = sizeof("Set-Cookie") - 1;
@ -520,6 +540,19 @@ static char *ngx_http_userid_merge_conf(ngx_conf_t *cf, void *parent,
} }
char *ngx_conf_check_domain(ngx_conf_t *cf, void *post, void *data)
{
ngx_str_t *domain = data;
if (domain->len == 4 && ngx_strcmp(domain->data, "none") == 0) {
domain->len = 1;
domain->data = ".";
}
return NGX_CONF_OK;
}
char *ngx_http_userid_expires(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) char *ngx_http_userid_expires(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{ {
ngx_http_userid_conf_t *ucf = conf; ngx_http_userid_conf_t *ucf = conf;

View file

@ -617,18 +617,25 @@ static void ngx_http_proxy_connect(ngx_http_proxy_ctx_t *p)
} }
if (r->request_body->buf) { if (r->request_body->buf) {
if (!(output->free = ngx_alloc_chain_link(r->pool))) { if (r->request_body->temp_file->file.fd != NGX_INVALID_FILE) {
ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR);
return; if (!(output->free = ngx_alloc_chain_link(r->pool))) {
ngx_http_proxy_finalize_request(p,
NGX_HTTP_INTERNAL_SERVER_ERROR);
return;
}
output->free->buf = r->request_body->buf;
output->free->next = NULL;
output->allocated = 1;
r->request_body->buf->pos = r->request_body->buf->start;
r->request_body->buf->last = r->request_body->buf->start;
r->request_body->buf->tag = (ngx_buf_tag_t) &ngx_http_proxy_module;
} else {
r->request_body->buf->pos = r->request_body->buf->start;
} }
output->free->buf = r->request_body->buf;
output->free->next = NULL;
output->allocated = 1;
r->request_body->buf->pos = r->request_body->buf->start;
r->request_body->buf->last = r->request_body->buf->start;
r->request_body->buf->tag = (ngx_buf_tag_t) &ngx_http_proxy_module;
} }
p->request_sent = 0; p->request_sent = 0;
@ -647,6 +654,7 @@ static void ngx_http_proxy_connect(ngx_http_proxy_ctx_t *p)
ngx_http_proxy_process_upstream_status_line(c->read); ngx_http_proxy_process_upstream_status_line(c->read);
return; return;
} }
#endif #endif
ngx_http_proxy_send_request(p); ngx_http_proxy_send_request(p);