Lines Matching refs:con

231 static int cgi_response_parse(server *srv, connection *con, plugin_data *p, buffer *in) {  in cgi_response_parse()  argument
267 con->parsed_response |= HTTP_STATUS; in cgi_response_parse()
268 con->http_status = status; in cgi_response_parse()
285 if (NULL == (ds = (data_string *)array_get_unused_element(con->response.headers, TYPE_STRING))) { in cgi_response_parse()
291 array_insert_unique(con->response.headers, (data_unset *)ds); in cgi_response_parse()
296 con->parsed_response |= HTTP_DATE; in cgi_response_parse()
301 con->http_status = strtol(value, NULL, 10); in cgi_response_parse()
302 con->parsed_response |= HTTP_STATUS; in cgi_response_parse()
307 con->parsed_response |= HTTP_LOCATION; in cgi_response_parse()
312 con->response.keep_alive = (0 == strcasecmp(value, "Keep-Alive")) ? 1 : 0; in cgi_response_parse()
313 con->parsed_response |= HTTP_CONNECTION; in cgi_response_parse()
318 con->response.content_length = strtol(value, NULL, 10); in cgi_response_parse()
319 con->parsed_response |= HTTP_CONTENT_LENGTH; in cgi_response_parse()
329 if ((con->parsed_response & HTTP_LOCATION) && in cgi_response_parse()
330 !(con->parsed_response & HTTP_STATUS)) { in cgi_response_parse()
331 con->http_status = 302; in cgi_response_parse()
340 connection *con = hctx->remote_conn; in cgi_demux_response() local
349 if (ioctl(con->fd, FIONREAD, &toread) || toread == 0 || toread <= 4*1024) { in cgi_demux_response()
363 log_error_write(srv, __FILE__, __LINE__, "sdd", strerror(errno), con->fd, hctx->fd); in cgi_demux_response()
370 con->file_finished = 1; in cgi_demux_response()
373 http_chunk_append_mem(srv, con, NULL, 0); in cgi_demux_response()
374 joblist_append(srv, con); in cgi_demux_response()
384 if (con->file_started == 0) { in cgi_demux_response()
457 if (con->request.http_version == HTTP_VERSION_1_1) { in cgi_demux_response()
458 con->response.transfer_encoding = HTTP_TRANSFER_ENCODING_CHUNKED; in cgi_demux_response()
461 http_chunk_append_mem(srv, con, hctx->response_header->ptr, hctx->response_header->used); in cgi_demux_response()
462 joblist_append(srv, con); in cgi_demux_response()
487 cgi_response_parse(srv, con, p, hctx->response_header); in cgi_demux_response()
490 if (con->request.http_version == HTTP_VERSION_1_1 && in cgi_demux_response()
491 !(con->parsed_response & HTTP_CONTENT_LENGTH)) { in cgi_demux_response()
492 con->response.transfer_encoding = HTTP_TRANSFER_ENCODING_CHUNKED; in cgi_demux_response()
496 http_chunk_append_mem(srv, con, bstart, blen + 1); in cgi_demux_response()
497 joblist_append(srv, con); in cgi_demux_response()
501 con->file_started = 1; in cgi_demux_response()
504 http_chunk_append_mem(srv, con, hctx->response->ptr, hctx->response->used); in cgi_demux_response()
505 joblist_append(srv, con); in cgi_demux_response()
509 …log_error_write(srv, __FILE__, __LINE__, "ddss", con->fd, hctx->fd, connection_get_state(con->stat… in cgi_demux_response()
520 connection *con; in cgi_connection_close() local
525 con = hctx->remote_conn; in cgi_connection_close()
527 if (con->mode != p->id) return HANDLER_GO_ON; in cgi_connection_close()
552 con->plugin_ctx[p->id] = NULL; in cgi_connection_close()
587 if (0 == con->file_started) { in cgi_connection_close()
588 connection_set_state(srv, con, CON_STATE_HANDLE_REQUEST); in cgi_connection_close()
589 con->http_status = 500; in cgi_connection_close()
590 con->mode = DIRECT; in cgi_connection_close()
592 con->file_finished = 1; in cgi_connection_close()
616 static handler_t cgi_connection_close_callback(server *srv, connection *con, void *p_d) { in cgi_connection_close_callback() argument
619 return cgi_connection_close(srv, con->plugin_ctx[p->id]); in cgi_connection_close_callback()
625 connection *con = hctx->remote_conn; in cgi_handle_fdevent() local
627 joblist_append(srv, con); in cgi_handle_fdevent()
630 …log_error_write(srv, __FILE__, __LINE__, "ddss", con->fd, hctx->fd, connection_get_state(con->stat… in cgi_handle_fdevent()
643 …log_error_write(srv, __FILE__, __LINE__, "ddss", con->fd, hctx->fd, connection_get_state(con->stat… in cgi_handle_fdevent()
651 if (0 == con->file_started) { in cgi_handle_fdevent()
652 connection_set_state(srv, con, CON_STATE_HANDLE_REQUEST); in cgi_handle_fdevent()
653 con->http_status = 500; in cgi_handle_fdevent()
654 con->mode = DIRECT; in cgi_handle_fdevent()
656 con->file_finished = 1; in cgi_handle_fdevent()
671 if (con->file_started == 0 && in cgi_handle_fdevent()
673 con->file_started = 1; in cgi_handle_fdevent()
674 http_chunk_append_mem(srv, con, hctx->response_header->ptr, hctx->response_header->used); in cgi_handle_fdevent()
675 joblist_append(srv, con); in cgi_handle_fdevent()
678 if (con->file_finished == 0) { in cgi_handle_fdevent()
679 http_chunk_append_mem(srv, con, NULL, 0); in cgi_handle_fdevent()
680 joblist_append(srv, con); in cgi_handle_fdevent()
683 con->file_finished = 1; in cgi_handle_fdevent()
685 if (chunkqueue_is_empty(con->write_queue)) { in cgi_handle_fdevent()
687 connection_set_state(srv, con, CON_STATE_RESPONSE_END); in cgi_handle_fdevent()
694 log_error_write(srv, __FILE__, __LINE__, "sddd", "got HUP from cgi", con->fd, hctx->fd, revents); in cgi_handle_fdevent()
700 con->file_finished = 1; in cgi_handle_fdevent()
738 static int cgi_create_env(server *srv, connection *con, plugin_data *p, buffer *cgi_handler) { in cgi_create_env() argument
785 server_socket *srv_sock = con->srv_socket; in cgi_create_env()
806 if (buffer_is_empty(con->conf.server_tag)) { in cgi_create_env()
809 cgi_env_add(&env, CONST_STR_LEN("SERVER_SOFTWARE"), CONST_BUF_LEN(con->conf.server_tag)); in cgi_create_env()
812 if (!buffer_is_empty(con->server_name)) { in cgi_create_env()
813 size_t len = con->server_name->used - 1; in cgi_create_env()
815 if (con->server_name->ptr[0] == '[') { in cgi_create_env()
816 const char *colon = strstr(con->server_name->ptr, "]:"); in cgi_create_env()
817 if (colon) len = (colon + 1) - con->server_name->ptr; in cgi_create_env()
819 const char *colon = strchr(con->server_name->ptr, ':'); in cgi_create_env()
820 if (colon) len = colon - con->server_name->ptr; in cgi_create_env()
823 cgi_env_add(&env, CONST_STR_LEN("SERVER_NAME"), con->server_name->ptr, len); in cgi_create_env()
838 s = get_http_version_name(con->request.http_version); in cgi_create_env()
874 s = get_http_method_name(con->request.http_method); in cgi_create_env()
877 if (!buffer_is_empty(con->request.pathinfo)) { in cgi_create_env()
878 cgi_env_add(&env, CONST_STR_LEN("PATH_INFO"), CONST_BUF_LEN(con->request.pathinfo)); in cgi_create_env()
881 if (!buffer_is_empty(con->uri.query)) { in cgi_create_env()
882 cgi_env_add(&env, CONST_STR_LEN("QUERY_STRING"), CONST_BUF_LEN(con->uri.query)); in cgi_create_env()
884 if (!buffer_is_empty(con->request.orig_uri)) { in cgi_create_env()
885 cgi_env_add(&env, CONST_STR_LEN("REQUEST_URI"), CONST_BUF_LEN(con->request.orig_uri)); in cgi_create_env()
889 switch (con->dst_addr.plain.sa_family) { in cgi_create_env()
892 s = inet_ntop(con->dst_addr.plain.sa_family, in cgi_create_env()
893 (const void *) &(con->dst_addr.ipv6.sin6_addr), in cgi_create_env()
897 s = inet_ntop(con->dst_addr.plain.sa_family, in cgi_create_env()
898 (const void *) &(con->dst_addr.ipv4.sin_addr), in cgi_create_env()
903 s = inet_ntoa(con->dst_addr.ipv4.sin_addr); in cgi_create_env()
914 …ntohs(con->dst_addr.plain.sa_family == AF_INET6 ? con->dst_addr.ipv6.sin6_port : con->dst_addr.ipv… in cgi_create_env()
916 ntohs(con->dst_addr.ipv4.sin_port) in cgi_create_env()
921 if (!buffer_is_empty(con->authed_user)) { in cgi_create_env()
923 CONST_BUF_LEN(con->authed_user)); in cgi_create_env()
933 LI_ltostr(buf, con->request.content_length); in cgi_create_env()
935 cgi_env_add(&env, CONST_STR_LEN("SCRIPT_FILENAME"), CONST_BUF_LEN(con->physical.path)); in cgi_create_env()
936 cgi_env_add(&env, CONST_STR_LEN("SCRIPT_NAME"), CONST_BUF_LEN(con->uri.path)); in cgi_create_env()
937 cgi_env_add(&env, CONST_STR_LEN("DOCUMENT_ROOT"), CONST_BUF_LEN(con->physical.basedir)); in cgi_create_env()
954 for (n = 0; n < con->request.headers->used; n++) { in cgi_create_env()
957 ds = (data_string *)con->request.headers->data[n]; in cgi_create_env()
988 for (n = 0; n < con->environment->used; n++) { in cgi_create_env()
991 ds = (data_string *)con->environment->data[n]; in cgi_create_env()
1032 args[i++] = con->physical.path->ptr; in cgi_create_env()
1036 if (NULL != (c = strrchr(con->physical.path->ptr, '/'))) { in cgi_create_env()
1040 if (-1 == chdir(con->physical.path->ptr)) { in cgi_create_env()
1041 …log_error_write(srv, __FILE__, __LINE__, "ssb", "chdir failed:", strerror(errno), con->physical.pa… in cgi_create_env()
1076 if (con->request.content_length) { in cgi_create_env()
1077 chunkqueue *cq = con->request_content_queue; in cgi_create_env()
1080 assert(chunkqueue_length(cq) == (off_t)con->request.content_length); in cgi_create_env()
1120 con->http_status = 507; in cgi_create_env()
1125 con->http_status = 403; in cgi_create_env()
1134 con->http_status = 507; in cgi_create_env()
1139 con->http_status = 403; in cgi_create_env()
1153 con->http_status = 500; in cgi_create_env()
1163 con->mode = p->id; in cgi_create_env()
1164 buffer_reset(con->physical.path); in cgi_create_env()
1168 hctx->remote_conn = con; in cgi_create_env()
1174 con->plugin_ctx[p->id] = hctx; in cgi_create_env()
1191 con->plugin_ctx[p->id] = NULL; in cgi_create_env()
1208 static int mod_cgi_patch_connection(server *srv, connection *con, plugin_data *p) { in mod_cgi_patch_connection() argument
1221 if (!config_check_cond(srv, con, dc)) continue; in mod_cgi_patch_connection()
1242 buffer *fn = con->physical.path; in URIHANDLER_FUNC()
1245 if (con->mode != DIRECT) return HANDLER_GO_ON; in URIHANDLER_FUNC()
1249 mod_cgi_patch_connection(srv, con, p); in URIHANDLER_FUNC()
1251 …if (HANDLER_ERROR == stat_cache_get_entry(srv, con, con->physical.path, &sce)) return HANDLER_GO_O… in URIHANDLER_FUNC()
1265 if (cgi_create_env(srv, con, p, ds->value)) { in URIHANDLER_FUNC()
1266 con->mode = DIRECT; in URIHANDLER_FUNC()
1267 con->http_status = 500; in URIHANDLER_FUNC()
1269 buffer_reset(con->physical.path); in URIHANDLER_FUNC()
1345 handler_ctx *hctx = con->plugin_ctx[p->id]; in SUBREQUEST_FUNC()
1347 if (con->mode != p->id) return HANDLER_GO_ON; in SUBREQUEST_FUNC()
1356 if (!con->file_started) return HANDLER_WAIT_FOR_EVENT; in SUBREQUEST_FUNC()
1365 if (con->file_started) return HANDLER_FINISHED; in SUBREQUEST_FUNC()
1371 if (errno == ECHILD && con->file_started == 0) { in SUBREQUEST_FUNC()
1379 con->mode = DIRECT; in SUBREQUEST_FUNC()
1380 con->http_status = 500; in SUBREQUEST_FUNC()
1393 con->plugin_ctx[p->id] = NULL; in SUBREQUEST_FUNC()
1403 if (con->file_started) return HANDLER_FINISHED; in SUBREQUEST_FUNC()
1413 con->http_status = 500; in SUBREQUEST_FUNC()
1414 con->mode = DIRECT; in SUBREQUEST_FUNC()
1425 con->plugin_ctx[p->id] = NULL; in SUBREQUEST_FUNC()