Author: jhorwitz
Date: Sat Dec 15 17:58:35 2007
New Revision: 276
Modified:
mod_parrot/trunk/src/mod_parrot.c
Log:
port new HLL handler logic to all apache phases
Modified: mod_parrot/trunk/src/mod_parrot.c
==============================================================================
--- mod_parrot/trunk/src/mod_parrot.c (original)
+++ mod_parrot/trunk/src/mod_parrot.c Sat Dec 15 17:58:35 2007
@@ -161,6 +161,20 @@
return NULL;
}
+/* This macro checks whether we should handle a particular phase, and if so,
+ * sets the HLL and handler name accordingly.
+ */
+#define SET_HLL_HANDLER(x) \
+ if (!dircfg->x) return DECLINED; \
+ hll = NULL; \
+ hll = dircfg->x->hll ? dircfg->x->hll : dircfg->hll; \
+ if (!hll) { \
+ if (!(hll = (get_request_hll(r, r->handler, r->content_type)))) { \
+ return DECLINED; \
+ } \
+ } \
+ hll_handler = dircfg->x ? dircfg->x->id : (char *)r->handler;
+
static int modparrot_handler(request_rec *r)
{
modparrot_dir_config *dircfg;
@@ -175,24 +189,20 @@
dircfg = (modparrot_dir_config *)ap_get_module_config(r->per_dir_config, &parrot_module);
cfg = ap_get_module_config(r->server->module_config, &parrot_module);
- /* search for a valid HLL, working from the bottom up */
+ /* we don't use SET_HLL_HANDLER here because it may still be appropriate
+ * to run this handler without a corresponding ParrotHandler directive.
+ * This is true for type maps and handler maps.
+ */
hll = NULL;
-
- /* for ParrotLanguage and HLL specified in Parrot*Handler */
- /* this lets us use "parrot-code" but override PIR with another HLL */
if (dircfg->handler) {
hll = dircfg->handler->hll ? dircfg->handler->hll : dircfg->hll;
}
-
- /* if still no HLL, check for custom handler strings and mime types */
if (!hll) {
if (!(hll = (get_request_hll(r, r->handler, r->content_type)))) {
- /* nothing left to check -- decline the request */
return DECLINED;
}
}
- /* set HLL handler */
hll_handler = dircfg->handler ? dircfg->handler->id : (char *)r->handler;
/* set default content type */
@@ -210,6 +220,7 @@
dircfg->handler->id);
return HTTP_INTERNAL_SERVER_ERROR;
}
+
ctxp->r = r;
/* call HLL handler */
@@ -322,16 +333,13 @@
modparrot_srv_config *cfg;
modparrot_context *ctxp;
int handler_status;
- char *sub, *hll;
+ char *sub, *hll, *hll_handler;
/* get apache configs */
dircfg = (modparrot_dir_config *)ap_get_module_config(r->per_dir_config, &parrot_module);
cfg = ap_get_module_config(r->server->module_config, &parrot_module);
- /* politely decline request if not our handler */
- if (!dircfg->header_parser_handler) {
- return DECLINED;
- }
+ SET_HLL_HANDLER(header_parser_handler);
/* initialize context */
if (!(ctxp = init_ctx(r->server))) {
@@ -343,13 +351,10 @@
/* call HLL handler */
sub = "_header_parser_handler";
- hll = dircfg->header_parser_handler->hll ?
- dircfg->header_parser_handler->hll : "PIR";
-
- if (!modparrot_hll_handler(ctxp->interp, hll, sub,
- dircfg->header_parser_handler->id, &handler_status)) {
+ if (!modparrot_hll_handler(ctxp->interp, hll, sub, hll_handler,
+ &handler_status)) {
MPLOG_ERRORF(r->server, "no subroutine found for handler '%s'",
- dircfg->header_parser_handler->id);
+ hll_handler);
release_ctx(ctxp);
return HTTP_INTERNAL_SERVER_ERROR;
}
@@ -535,16 +540,13 @@
modparrot_srv_config *cfg;
modparrot_context *ctxp;
int handler_status;
- char *sub, *hll;
+ char *sub, *hll, *hll_handler;
/* get apache configs */
dircfg = (modparrot_dir_config *)ap_get_module_config(r->per_dir_config, &parrot_module);
cfg = ap_get_module_config(r->server->module_config, &parrot_module);
- /* politely decline request if not our handler */
- if (!dircfg->fixup_handler) {
- return DECLINED;
- }
+ SET_HLL_HANDLER(fixup_handler);
/* initialize context */
if (!(ctxp = init_ctx(r->server))) {
@@ -556,12 +558,10 @@
/* call HLL handler */
sub = "_fixup_handler";
- hll = dircfg->fixup_handler->hll ? dircfg->fixup_handler->hll : "PIR";
-
- if (!modparrot_hll_handler(ctxp->interp, hll, sub,
- dircfg->fixup_handler->id, &handler_status)) {
+ if (!modparrot_hll_handler(ctxp->interp, hll, sub, hll_handler,
+ &handler_status)) {
MPLOG_ERRORF(r->server, "no subroutine found for handler '%s'",
- dircfg->fixup_handler->id);
+ hll_handler);
release_ctx(ctxp);
return HTTP_INTERNAL_SERVER_ERROR;
}
@@ -579,16 +579,13 @@
modparrot_srv_config *cfg;
modparrot_context *ctxp;
int handler_status;
- char *sub, *hll;
+ char *sub, *hll, *hll_handler;
/* get apache configs */
dircfg = (modparrot_dir_config *)ap_get_module_config(r->per_dir_config, &parrot_module);
cfg = ap_get_module_config(r->server->module_config, &parrot_module);
- /* politely decline request if not our handler */
- if (!dircfg->type_handler) {
- return DECLINED;
- }
+ SET_HLL_HANDLER(type_handler);
/* initialize context */
if (!(ctxp = init_ctx(r->server))) {
@@ -600,12 +597,10 @@
/* call HLL handler */
sub = "_type_handler";
- hll = dircfg->type_handler->hll ? dircfg->type_handler->hll : "PIR";
-
- if (!modparrot_hll_handler(ctxp->interp, hll, sub,
- dircfg->type_handler->id, &handler_status)) {
+ if (!modparrot_hll_handler(ctxp->interp, hll, sub, hll_handler,
+ &handler_status)) {
MPLOG_ERRORF(r->server, "no subroutine found for handler '%s'",
- dircfg->type_handler->id);
+ hll_handler);
release_ctx(ctxp);
return HTTP_INTERNAL_SERVER_ERROR;
}
@@ -623,7 +618,7 @@
modparrot_srv_config *cfg;
modparrot_context *ctxp;
int handler_status;
- char *sub, *hll;
+ char *sub, *hll, *hll_handler;
/* politely decline request if we shouldn't be handling this */
if (!SHOULD_HANDLE(r)) {
@@ -634,10 +629,7 @@
dircfg = (modparrot_dir_config *)ap_get_module_config(r->per_dir_config, &parrot_module);
cfg = ap_get_module_config(r->server->module_config, &parrot_module);
- /* politely decline request if not our handler */
- if (!dircfg->log_handler) {
- return DECLINED;
- }
+ SET_HLL_HANDLER(log_handler);
/* initialize context */
if (!(ctxp = init_ctx(r->server))) {
@@ -649,12 +641,10 @@
/* call HLL handler */
sub = "_log_handler";
- hll = dircfg->log_handler->hll ? dircfg->log_handler->hll : "PIR";
-
- if (!modparrot_hll_handler(ctxp->interp, hll, sub,
- dircfg->log_handler->id, &handler_status)) {
+ if (!modparrot_hll_handler(ctxp->interp, hll, sub, hll_handler,
+ &handler_status)) {
MPLOG_ERRORF(r->server, "no subroutine found for handler '%s'",
- dircfg->log_handler->id);
+ hll_handler);
release_ctx(ctxp);
return HTTP_INTERNAL_SERVER_ERROR;
}
@@ -672,16 +662,13 @@
modparrot_srv_config *cfg;
modparrot_context *ctxp;
int handler_status;
- char *sub, *hll;
+ char *sub, *hll, *hll_handler;
/* get apache configs */
dircfg = (modparrot_dir_config *)ap_get_module_config(r->per_dir_config, &parrot_module);
cfg = ap_get_module_config(r->server->module_config, &parrot_module);
- /* politely decline request if not our handler */
- if (!dircfg->access_handler) {
- return DECLINED;
- }
+ SET_HLL_HANDLER(access_handler);
/* initialize context */
if (!(ctxp = init_ctx(r->server))) {
@@ -694,12 +681,10 @@
/* call HLL handler */
sub = "_access_handler";
- hll = dircfg->access_handler->hll ?
- dircfg->access_handler->hll : dircfg->hll;
- if (!modparrot_hll_handler(ctxp->interp, hll, sub,
- dircfg->access_handler->id, &handler_status)) {
+ if (!modparrot_hll_handler(ctxp->interp, hll, sub, hll_handler,
+ &handler_status)) {
MPLOG_ERRORF(r->server, "no subroutine found for handler '%s'",
- dircfg->access_handler->id);
+ hll_handler);
release_ctx(ctxp);
return HTTP_INTERNAL_SERVER_ERROR;
}
@@ -717,16 +702,13 @@
modparrot_srv_config *cfg;
modparrot_context *ctxp;
int handler_status;
- char *sub, *hll;
+ char *sub, *hll, *hll_handler;
/* get apache configs */
dircfg = (modparrot_dir_config *)ap_get_module_config(r->per_dir_config, &parrot_module);
cfg = ap_get_module_config(r->server->module_config, &parrot_module);
- /* politely decline request if not our handler */
- if (!dircfg->authen_handler) {
- return DECLINED;
- }
+ SET_HLL_HANDLER(authen_handler);
/* initialize context */
if (!(ctxp = init_ctx(r->server))) {
@@ -739,12 +721,10 @@
/* call HLL handler */
sub = "_authen_handler";
- hll = dircfg->authen_handler->hll ?
- dircfg->authen_handler->hll : dircfg->hll;
- if (!modparrot_hll_handler(ctxp->interp, hll, sub,
- dircfg->authen_handler->id, &handler_status)) {
+ if (!modparrot_hll_handler(ctxp->interp, hll, sub, hll_handler,
+ &handler_status)) {
MPLOG_ERRORF(r->server, "no subroutine found for handler '%s'",
- dircfg->authen_handler->id);
+ hll_handler);
release_ctx(ctxp);
return HTTP_INTERNAL_SERVER_ERROR;
}
@@ -762,16 +742,13 @@
modparrot_srv_config *cfg;
modparrot_context *ctxp;
int handler_status;
- char *sub, *hll;
+ char *sub, *hll, *hll_handler;
/* get apache configs */
dircfg = (modparrot_dir_config *)ap_get_module_config(r->per_dir_config, &parrot_module);
cfg = ap_get_module_config(r->server->module_config, &parrot_module);
- /* politely decline request if not our handler */
- if (!dircfg->authz_handler) {
- return DECLINED;
- }
+ SET_HLL_HANDLER(authz_handler);
/* initialize context */
if (!(ctxp = init_ctx(r->server))) {
@@ -784,12 +761,10 @@
/* call HLL handler */
sub = "_authz_handler";
- hll = dircfg->authz_handler->hll ?
- dircfg->authz_handler->hll : dircfg->hll;
- if (!modparrot_hll_handler(ctxp->interp, hll, sub,
- dircfg->authz_handler->id, &handler_status)) {
+ if (!modparrot_hll_handler(ctxp->interp, hll, sub, hll_handler,
+ &handler_status)) {
MPLOG_ERRORF(r->server, "no subroutine found for handler '%s'",
- dircfg->authz_handler->id);
+ hll_handler);
release_ctx(ctxp);
return HTTP_INTERNAL_SERVER_ERROR;
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.