version 1.1, 2013/10/14 10:32:47
|
version 1.1.1.2, 2014/06/15 20:20:06
|
Line 487 static handler_ctx * handler_ctx_init(void) {
|
Line 487 static handler_ctx * handler_ctx_init(void) {
|
handler_ctx * hctx; |
handler_ctx * hctx; |
|
|
hctx = calloc(1, sizeof(*hctx)); |
hctx = calloc(1, sizeof(*hctx)); |
assert(hctx); | force_assert(hctx); |
|
|
hctx->fde_ndx = -1; |
hctx->fde_ndx = -1; |
|
|
Line 634 static int fastcgi_extension_insert(fcgi_exts *ext, bu
|
Line 634 static int fastcgi_extension_insert(fcgi_exts *ext, bu
|
if (i == ext->used) { |
if (i == ext->used) { |
/* filextension is new */ |
/* filextension is new */ |
fe = calloc(1, sizeof(*fe)); |
fe = calloc(1, sizeof(*fe)); |
assert(fe); | force_assert(fe); |
fe->key = buffer_init(); |
fe->key = buffer_init(); |
fe->last_used_ndx = -1; |
fe->last_used_ndx = -1; |
buffer_copy_string_buffer(fe->key, key); |
buffer_copy_string_buffer(fe->key, key); |
Line 644 static int fastcgi_extension_insert(fcgi_exts *ext, bu
|
Line 644 static int fastcgi_extension_insert(fcgi_exts *ext, bu
|
if (ext->size == 0) { |
if (ext->size == 0) { |
ext->size = 8; |
ext->size = 8; |
ext->exts = malloc(ext->size * sizeof(*(ext->exts))); |
ext->exts = malloc(ext->size * sizeof(*(ext->exts))); |
assert(ext->exts); | force_assert(ext->exts); |
} else if (ext->used == ext->size) { |
} else if (ext->used == ext->size) { |
ext->size += 8; |
ext->size += 8; |
ext->exts = realloc(ext->exts, ext->size * sizeof(*(ext->exts))); |
ext->exts = realloc(ext->exts, ext->size * sizeof(*(ext->exts))); |
assert(ext->exts); | force_assert(ext->exts); |
} |
} |
ext->exts[ext->used++] = fe; |
ext->exts[ext->used++] = fe; |
} else { |
} else { |
Line 658 static int fastcgi_extension_insert(fcgi_exts *ext, bu
|
Line 658 static int fastcgi_extension_insert(fcgi_exts *ext, bu
|
if (fe->size == 0) { |
if (fe->size == 0) { |
fe->size = 4; |
fe->size = 4; |
fe->hosts = malloc(fe->size * sizeof(*(fe->hosts))); |
fe->hosts = malloc(fe->size * sizeof(*(fe->hosts))); |
assert(fe->hosts); | force_assert(fe->hosts); |
} else if (fe->size == fe->used) { |
} else if (fe->size == fe->used) { |
fe->size += 4; |
fe->size += 4; |
fe->hosts = realloc(fe->hosts, fe->size * sizeof(*(fe->hosts))); |
fe->hosts = realloc(fe->hosts, fe->size * sizeof(*(fe->hosts))); |
assert(fe->hosts); | force_assert(fe->hosts); |
} |
} |
|
|
fe->hosts[fe->used++] = fh; |
fe->hosts[fe->used++] = fh; |
Line 873 static int fcgi_spawn_connection(server *srv,
|
Line 873 static int fcgi_spawn_connection(server *srv,
|
|
|
#ifdef HAVE_SYS_UN_H |
#ifdef HAVE_SYS_UN_H |
fcgi_addr_un.sun_family = AF_UNIX; |
fcgi_addr_un.sun_family = AF_UNIX; |
strcpy(fcgi_addr_un.sun_path, proc->unixsocket->ptr); | if (proc->unixsocket->used > sizeof(fcgi_addr_un.sun_path)) { |
| log_error_write(srv, __FILE__, __LINE__, "sB", |
| "ERROR: Unix Domain socket filename too long:", |
| proc->unixsocket); |
| return -1; |
| } |
| memcpy(fcgi_addr_un.sun_path, proc->unixsocket->ptr, proc->unixsocket->used); |
|
|
#ifdef SUN_LEN |
#ifdef SUN_LEN |
servlen = SUN_LEN(&fcgi_addr_un); |
servlen = SUN_LEN(&fcgi_addr_un); |
Line 969 static int fcgi_spawn_connection(server *srv,
|
Line 975 static int fcgi_spawn_connection(server *srv,
|
if (setsockopt(fcgi_fd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)) < 0) { |
if (setsockopt(fcgi_fd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)) < 0) { |
log_error_write(srv, __FILE__, __LINE__, "ss", |
log_error_write(srv, __FILE__, __LINE__, "ss", |
"socketsockopt failed:", strerror(errno)); |
"socketsockopt failed:", strerror(errno)); |
|
close(fcgi_fd); |
return -1; |
return -1; |
} |
} |
|
|
Line 978 static int fcgi_spawn_connection(server *srv,
|
Line 985 static int fcgi_spawn_connection(server *srv,
|
"bind failed for:", |
"bind failed for:", |
proc->connection_name, |
proc->connection_name, |
strerror(errno)); |
strerror(errno)); |
|
close(fcgi_fd); |
return -1; |
return -1; |
} |
} |
|
|
if (-1 == listen(fcgi_fd, 1024)) { |
if (-1 == listen(fcgi_fd, 1024)) { |
log_error_write(srv, __FILE__, __LINE__, "ss", |
log_error_write(srv, __FILE__, __LINE__, "ss", |
"listen failed:", strerror(errno)); |
"listen failed:", strerror(errno)); |
|
close(fcgi_fd); |
return -1; |
return -1; |
} |
} |
|
|
Line 1161 SETDEFAULTS_FUNC(mod_fastcgi_set_defaults) {
|
Line 1170 SETDEFAULTS_FUNC(mod_fastcgi_set_defaults) {
|
data_unset *du; |
data_unset *du; |
size_t i = 0; |
size_t i = 0; |
buffer *fcgi_mode = buffer_init(); |
buffer *fcgi_mode = buffer_init(); |
|
fcgi_extension_host *host = NULL; |
|
|
config_values_t cv[] = { |
config_values_t cv[] = { |
{ "fastcgi.server", NULL, T_CONFIG_LOCAL, T_CONFIG_SCOPE_CONNECTION }, /* 0 */ |
{ "fastcgi.server", NULL, T_CONFIG_LOCAL, T_CONFIG_SCOPE_CONNECTION }, /* 0 */ |
Line 1169 SETDEFAULTS_FUNC(mod_fastcgi_set_defaults) {
|
Line 1179 SETDEFAULTS_FUNC(mod_fastcgi_set_defaults) {
|
{ NULL, NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET } |
{ NULL, NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET } |
}; |
}; |
|
|
p->config_storage = calloc(1, srv->config_context->used * sizeof(specific_config *)); | p->config_storage = calloc(1, srv->config_context->used * sizeof(plugin_config *)); |
|
|
for (i = 0; i < srv->config_context->used; i++) { |
for (i = 0; i < srv->config_context->used; i++) { |
plugin_config *s; |
plugin_config *s; |
Line 1188 SETDEFAULTS_FUNC(mod_fastcgi_set_defaults) {
|
Line 1198 SETDEFAULTS_FUNC(mod_fastcgi_set_defaults) {
|
ca = ((data_config *)srv->config_context->data[i])->value; |
ca = ((data_config *)srv->config_context->data[i])->value; |
|
|
if (0 != config_insert_values_global(srv, ca, cv)) { |
if (0 != config_insert_values_global(srv, ca, cv)) { |
return HANDLER_ERROR; | goto error; |
} |
} |
|
|
/* |
/* |
Line 1203 SETDEFAULTS_FUNC(mod_fastcgi_set_defaults) {
|
Line 1213 SETDEFAULTS_FUNC(mod_fastcgi_set_defaults) {
|
log_error_write(srv, __FILE__, __LINE__, "sss", |
log_error_write(srv, __FILE__, __LINE__, "sss", |
"unexpected type for key: ", "fastcgi.server", "array of strings"); |
"unexpected type for key: ", "fastcgi.server", "array of strings"); |
|
|
return HANDLER_ERROR; | goto error; |
} |
} |
|
|
|
|
Line 1221 SETDEFAULTS_FUNC(mod_fastcgi_set_defaults) {
|
Line 1231 SETDEFAULTS_FUNC(mod_fastcgi_set_defaults) {
|
"unexpected type for key: ", "fastcgi.server", |
"unexpected type for key: ", "fastcgi.server", |
"[", da->value->data[j]->key, "](string)"); |
"[", da->value->data[j]->key, "](string)"); |
|
|
return HANDLER_ERROR; | goto error; |
} |
} |
|
|
/* |
/* |
Line 1239 SETDEFAULTS_FUNC(mod_fastcgi_set_defaults) {
|
Line 1249 SETDEFAULTS_FUNC(mod_fastcgi_set_defaults) {
|
for (n = 0; n < da_ext->value->used; n++) { |
for (n = 0; n < da_ext->value->used; n++) { |
data_array *da_host = (data_array *)da_ext->value->data[n]; |
data_array *da_host = (data_array *)da_ext->value->data[n]; |
|
|
fcgi_extension_host *host; |
|
|
|
config_values_t fcv[] = { |
config_values_t fcv[] = { |
{ "host", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, /* 0 */ |
{ "host", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, /* 0 */ |
{ "docroot", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, /* 1 */ |
{ "docroot", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, /* 1 */ |
Line 1271 SETDEFAULTS_FUNC(mod_fastcgi_set_defaults) {
|
Line 1279 SETDEFAULTS_FUNC(mod_fastcgi_set_defaults) {
|
"fastcgi.server", |
"fastcgi.server", |
"[", da_host->key, "](string)"); |
"[", da_host->key, "](string)"); |
|
|
return HANDLER_ERROR; | goto error; |
} |
} |
|
|
host = fastcgi_host_init(); |
host = fastcgi_host_init(); |
Line 1308 SETDEFAULTS_FUNC(mod_fastcgi_set_defaults) {
|
Line 1316 SETDEFAULTS_FUNC(mod_fastcgi_set_defaults) {
|
fcv[15].destination = &(host->fix_root_path_name); |
fcv[15].destination = &(host->fix_root_path_name); |
|
|
if (0 != config_insert_values_internal(srv, da_host->value, fcv)) { |
if (0 != config_insert_values_internal(srv, da_host->value, fcv)) { |
return HANDLER_ERROR; | goto error; |
} |
} |
|
|
if ((!buffer_is_empty(host->host) || host->port) && |
if ((!buffer_is_empty(host->host) || host->port) && |
Line 1319 SETDEFAULTS_FUNC(mod_fastcgi_set_defaults) {
|
Line 1327 SETDEFAULTS_FUNC(mod_fastcgi_set_defaults) {
|
da_ext->key, " => (", |
da_ext->key, " => (", |
da_host->key, " ( ..."); |
da_host->key, " ( ..."); |
|
|
return HANDLER_ERROR; | goto error; |
} |
} |
|
|
if (!buffer_is_empty(host->unixsocket)) { |
if (!buffer_is_empty(host->unixsocket)) { |
Line 1333 SETDEFAULTS_FUNC(mod_fastcgi_set_defaults) {
|
Line 1341 SETDEFAULTS_FUNC(mod_fastcgi_set_defaults) {
|
da_ext->key, " => (", |
da_ext->key, " => (", |
da_host->key, " ( ..."); |
da_host->key, " ( ..."); |
|
|
return HANDLER_ERROR; | goto error; |
} |
} |
} else { |
} else { |
/* tcp/ip */ |
/* tcp/ip */ |
Line 1346 SETDEFAULTS_FUNC(mod_fastcgi_set_defaults) {
|
Line 1354 SETDEFAULTS_FUNC(mod_fastcgi_set_defaults) {
|
da_ext->key, " => (", |
da_ext->key, " => (", |
da_host->key, " ( ..."); |
da_host->key, " ( ..."); |
|
|
return HANDLER_ERROR; | goto error; |
} else if (host->port == 0) { |
} else if (host->port == 0) { |
log_error_write(srv, __FILE__, __LINE__, "sbsbsbs", |
log_error_write(srv, __FILE__, __LINE__, "sbsbsbs", |
"port has to be set in:", |
"port has to be set in:", |
Line 1354 SETDEFAULTS_FUNC(mod_fastcgi_set_defaults) {
|
Line 1362 SETDEFAULTS_FUNC(mod_fastcgi_set_defaults) {
|
da_ext->key, " => (", |
da_ext->key, " => (", |
da_host->key, " ( ..."); |
da_host->key, " ( ..."); |
|
|
return HANDLER_ERROR; | goto error; |
} |
} |
} |
} |
|
|
Line 1397 SETDEFAULTS_FUNC(mod_fastcgi_set_defaults) {
|
Line 1405 SETDEFAULTS_FUNC(mod_fastcgi_set_defaults) {
|
if (fcgi_spawn_connection(srv, p, host, proc)) { |
if (fcgi_spawn_connection(srv, p, host, proc)) { |
log_error_write(srv, __FILE__, __LINE__, "s", |
log_error_write(srv, __FILE__, __LINE__, "s", |
"[ERROR]: spawning fcgi failed."); |
"[ERROR]: spawning fcgi failed."); |
return HANDLER_ERROR; | fastcgi_process_free(proc); |
| goto error; |
} |
} |
|
|
fastcgi_status_init(srv, p->statuskey, host, proc); |
fastcgi_status_init(srv, p->statuskey, host, proc); |
|
|
proc->next = host->first; |
proc->next = host->first; |
if (host->first) host->first->prev = proc; | if (host->first) host->first->prev = proc; |
|
|
host->first = proc; |
host->first = proc; |
} |
} |
Line 1437 SETDEFAULTS_FUNC(mod_fastcgi_set_defaults) {
|
Line 1446 SETDEFAULTS_FUNC(mod_fastcgi_set_defaults) {
|
if (buffer_is_empty(host->docroot)) { |
if (buffer_is_empty(host->docroot)) { |
log_error_write(srv, __FILE__, __LINE__, "s", |
log_error_write(srv, __FILE__, __LINE__, "s", |
"ERROR: docroot is required for authorizer mode."); |
"ERROR: docroot is required for authorizer mode."); |
return HANDLER_ERROR; | goto error; |
} |
} |
} else { |
} else { |
log_error_write(srv, __FILE__, __LINE__, "sbs", |
log_error_write(srv, __FILE__, __LINE__, "sbs", |
Line 1448 SETDEFAULTS_FUNC(mod_fastcgi_set_defaults) {
|
Line 1457 SETDEFAULTS_FUNC(mod_fastcgi_set_defaults) {
|
|
|
/* if extension already exists, take it */ |
/* if extension already exists, take it */ |
fastcgi_extension_insert(s->exts, da_ext->key, host); |
fastcgi_extension_insert(s->exts, da_ext->key, host); |
|
host = NULL; |
} |
} |
} |
} |
} |
} |
} |
} |
|
|
buffer_free(fcgi_mode); |
buffer_free(fcgi_mode); |
|
|
return HANDLER_GO_ON; |
return HANDLER_GO_ON; |
|
|
|
error: |
|
if (NULL != host) fastcgi_host_free(host); |
|
buffer_free(fcgi_mode); |
|
return HANDLER_ERROR; |
} |
} |
|
|
static int fcgi_set_state(server *srv, handler_ctx *hctx, fcgi_connection_state_t state) { |
static int fcgi_set_state(server *srv, handler_ctx *hctx, fcgi_connection_state_t state) { |
Line 1623 static int fcgi_env_add(buffer *env, const char *key,
|
Line 1637 static int fcgi_env_add(buffer *env, const char *key,
|
} |
} |
|
|
static int fcgi_header(FCGI_Header * header, unsigned char type, size_t request_id, int contentLength, unsigned char paddingLength) { |
static int fcgi_header(FCGI_Header * header, unsigned char type, size_t request_id, int contentLength, unsigned char paddingLength) { |
assert(contentLength <= FCGI_MAX_LENGTH); | force_assert(contentLength <= FCGI_MAX_LENGTH); |
|
|
header->version = FCGI_VERSION_1; |
header->version = FCGI_VERSION_1; |
header->type = type; |
header->type = type; |
Line 1662 static connection_result_t fcgi_establish_connection(s
|
Line 1676 static connection_result_t fcgi_establish_connection(s
|
#ifdef HAVE_SYS_UN_H |
#ifdef HAVE_SYS_UN_H |
/* use the unix domain socket */ |
/* use the unix domain socket */ |
fcgi_addr_un.sun_family = AF_UNIX; |
fcgi_addr_un.sun_family = AF_UNIX; |
strcpy(fcgi_addr_un.sun_path, proc->unixsocket->ptr); | if (proc->unixsocket->used > sizeof(fcgi_addr_un.sun_path)) { |
| log_error_write(srv, __FILE__, __LINE__, "sB", |
| "ERROR: Unix Domain socket filename too long:", |
| proc->unixsocket); |
| return -1; |
| } |
| memcpy(fcgi_addr_un.sun_path, proc->unixsocket->ptr, proc->unixsocket->used); |
| |
#ifdef SUN_LEN |
#ifdef SUN_LEN |
servlen = SUN_LEN(&fcgi_addr_un); |
servlen = SUN_LEN(&fcgi_addr_un); |
#else |
#else |
Line 2086 static int fcgi_create_env(server *srv, handler_ctx *h
|
Line 2107 static int fcgi_create_env(server *srv, handler_ctx *h
|
req_c->file.name); |
req_c->file.name); |
} |
} |
|
|
assert(weHave != 0); | force_assert(weHave != 0); |
|
|
chunkqueue_append_file(hctx->wb, req_c->file.name, req_c->offset, weHave); |
chunkqueue_append_file(hctx->wb, req_c->file.name, req_c->offset, weHave); |
|
|
Line 2116 static int fcgi_create_env(server *srv, handler_ctx *h
|
Line 2137 static int fcgi_create_env(server *srv, handler_ctx *h
|
} |
} |
c = hctx->wb->last; |
c = hctx->wb->last; |
|
|
assert(c->type == FILE_CHUNK); | force_assert(c->type == FILE_CHUNK); |
assert(req_c->file.is_temp == 1); | force_assert(req_c->file.is_temp == 1); |
|
|
c->file.is_temp = 1; |
c->file.is_temp = 1; |
req_c->file.is_temp = 0; |
req_c->file.is_temp = 0; |
Line 2420 static int fastcgi_get_packet(server *srv, handler_ctx
|
Line 2441 static int fastcgi_get_packet(server *srv, handler_ctx
|
if ((packet->b->used == 0) || |
if ((packet->b->used == 0) || |
(packet->b->used - 1 < sizeof(FCGI_Header))) { |
(packet->b->used - 1 < sizeof(FCGI_Header))) { |
/* no header */ |
/* no header */ |
buffer_free(packet->b); |
|
|
|
if (hctx->plugin_data->conf.debug) { |
if (hctx->plugin_data->conf.debug) { |
log_error_write(srv, __FILE__, __LINE__, "sdsds", "FastCGI: header too small:", packet->b->used, "bytes <", sizeof(FCGI_Header), "bytes, waiting for more data"); |
log_error_write(srv, __FILE__, __LINE__, "sdsds", "FastCGI: header too small:", packet->b->used, "bytes <", sizeof(FCGI_Header), "bytes, waiting for more data"); |
} |
} |
|
|
|
buffer_free(packet->b); |
|
|
return -1; |
return -1; |
} |
} |
|
|
Line 2532 static int fcgi_demux_response(server *srv, handler_ct
|
Line 2554 static int fcgi_demux_response(server *srv, handler_ct
|
} |
} |
|
|
/* this should be catched by the b > 0 above */ |
/* this should be catched by the b > 0 above */ |
assert(r); | force_assert(r); |
|
|
b->used = r + 1; /* one extra for the fake \0 */ |
b->used = r + 1; /* one extra for the fake \0 */ |
b->ptr[b->used - 1] = '\0'; |
b->ptr[b->used - 1] = '\0'; |
Line 2722 static int fcgi_restart_dead_procs(server *srv, plugin
|
Line 2744 static int fcgi_restart_dead_procs(server *srv, plugin
|
case PROC_STATE_KILLED: |
case PROC_STATE_KILLED: |
case PROC_STATE_UNSET: |
case PROC_STATE_UNSET: |
/* this should never happen as long as adaptive spawing is disabled */ |
/* this should never happen as long as adaptive spawing is disabled */ |
assert(0); | force_assert(0); |
|
|
break; |
break; |
case PROC_STATE_RUNNING: |
case PROC_STATE_RUNNING: |
Line 3014 static handler_t fcgi_write_request(server *srv, handl
|
Line 3036 static handler_t fcgi_write_request(server *srv, handl
|
|
|
break; |
break; |
} |
} |
| /* fallthrough */ |
case FCGI_STATE_PREPARE_WRITE: |
case FCGI_STATE_PREPARE_WRITE: |
/* ok, we have the connection */ |
/* ok, we have the connection */ |
|
|
Line 3174 SUBREQUEST_FUNC(mod_fastcgi_handle_subrequest) {
|
Line 3196 SUBREQUEST_FUNC(mod_fastcgi_handle_subrequest) {
|
/* ok, create the request */ |
/* ok, create the request */ |
switch(fcgi_write_request(srv, hctx)) { |
switch(fcgi_write_request(srv, hctx)) { |
case HANDLER_ERROR: |
case HANDLER_ERROR: |
host = hctx->host; |
|
|
|
if (hctx->state == FCGI_STATE_INIT || |
if (hctx->state == FCGI_STATE_INIT || |
hctx->state == FCGI_STATE_CONNECT_DELAYED) { |
hctx->state == FCGI_STATE_CONNECT_DELAYED) { |
fcgi_restart_dead_procs(srv, p, host); |
fcgi_restart_dead_procs(srv, p, host); |