diff --git a/fcgi_request.c b/fcgi_request.c index 313e86f..0573e3e 100644 --- a/fcgi_request.c +++ b/fcgi_request.c @@ -118,13 +118,13 @@ const char *fcgi_util_socket_make_addr(apr_pool_t *p, fcgi_request_t *fr) &fr->socket_addr_len, host, port); } -int fcgi_request_create(request_rec *r, fcgi_request_t **frP) +int fcgi_request_create(request_rec *r, char *action, fcgi_request_t **frP) { apr_pool_t *p = r->pool; fcgi_request_t *fr = apr_pcalloc(p, sizeof(fcgi_request_t)); /* setup server socket struct */ - fr->server = apr_pstrdup(p, r->handler + 5); + fr->server = apr_pstrdup(p, action); const char *err = fcgi_util_socket_make_addr(p, fr); diff --git a/fcgi_request.h b/fcgi_request.h index 7418345..73479b2 100644 --- a/fcgi_request.h +++ b/fcgi_request.h @@ -17,7 +17,7 @@ typedef struct { int socket_fd; /* socket descriptor to FastCGI server */ } fcgi_request_t; -int fcgi_request_create(request_rec *r, fcgi_request_t **frP); +int fcgi_request_create(request_rec *r, char *action, fcgi_request_t **frP); int fcgi_request_process(fcgi_request_t *fr); diff --git a/mod_fastcgi_handler.c b/mod_fastcgi_handler.c index 7f661f7..d7b0ae2 100644 --- a/mod_fastcgi_handler.c +++ b/mod_fastcgi_handler.c @@ -6,14 +6,25 @@ static int fastcgi_handler(request_rec *r) { - if (strncmp(r->handler, "fcgi:", 5)) - return DECLINED; + fastcgi_handler_cfg *conf = (fastcgi_handler_cfg *) + ap_get_module_config(r->per_dir_config, &fastcgi_handler_module); + const char *action; + + action = r->handler; + if (!action || strncmp(action, "fcgi:", 5)) { + const char *type; + type = ap_field_noparam(r->pool, r->content_type); + if (type) + action = apr_table_get(conf->action_types, type); + if (!action || strncmp(action, "fcgi:", 5)) + return DECLINED; + } fcgi_request_t *fr = NULL; int ret; /* Step 1: create a new FastCGI request object */ - if ((ret = fcgi_request_create(r, &fr)) != OK) { + if ((ret = fcgi_request_create(r, action+5, &fr)) != OK) { return ret; } @@ -32,6 +43,7 @@ void *fastcgi_handler_create_dir_config(apr_pool_t *p, char *dir) fastcgi_handler_cfg *cfg = apr_pcalloc(p, sizeof(fastcgi_handler_cfg)); cfg->idle_timeout = -1; + cfg->action_types = apr_table_make(p, 4); return cfg; } @@ -46,12 +58,28 @@ void *fastcgi_handler_merge_dir_config(apr_pool_t *p, void *parent, void *curren cfg->idle_timeout = current_cfg->idle_timeout == -1 ? parent_cfg->idle_timeout : current_cfg->idle_timeout; + cfg->action_types = apr_table_overlay(p, current_cfg->action_types, + parent_cfg->action_types); + return cfg; } +static +const char *add_action(cmd_parms *cmd, void *m_v, + const char *type, const char *script) +{ + fastcgi_handler_cfg *cfg = (fastcgi_handler_cfg *)m_v; + + apr_table_setn(cfg->action_types, type, script); + + return NULL; +} + static const command_rec fastcgi_handler_cmds[] = { + AP_INIT_TAKE2("FcgiAction", add_action, NULL, RSRC_CONF, + "a media type followed by a fcgi:socket"), { NULL } }; @@ -61,7 +89,7 @@ void fastcgi_handler_register_hooks(apr_pool_t * p) ap_hook_handler(fastcgi_handler, NULL, NULL, APR_HOOK_MIDDLE); } -module AP_MODULE_DECLARE_DATA fastcgi_handler_module = +AP_DECLARE_MODULE(fastcgi_handler_module) = { STANDARD20_MODULE_STUFF, fastcgi_handler_create_dir_config, diff --git a/mod_fastcgi_handler.h b/mod_fastcgi_handler.h index ee52f8d..545564a 100644 --- a/mod_fastcgi_handler.h +++ b/mod_fastcgi_handler.h @@ -9,6 +9,7 @@ #define FCGI_DEFAULT_IDLE_TIMEOUT 30 typedef struct { + apr_table_t *action_types; int idle_timeout; } fastcgi_handler_cfg;