Author: jhorwitz
Date: Thu Dec 13 18:55:26 2007
New Revision: 270
Modified:
mod_parrot/trunk/include/modparrot_config.h
mod_parrot/trunk/src/mod_parrot.c
mod_parrot/trunk/src/modparrot_config.c
Log:
ParrotAddType apache directive maps mime types to HLLs
ParrotAddHandler apache directive maps handler names to HLLs
added support for the above for response handlers (others to follow)
Modified: mod_parrot/trunk/include/modparrot_config.h
==============================================================================
--- mod_parrot/trunk/include/modparrot_config.h (original)
+++ mod_parrot/trunk/include/modparrot_config.h Thu Dec 13 18:55:26 2007
@@ -32,6 +32,8 @@
int trace_flags;
char *include_path;
apr_array_header_t *preload;
+ apr_table_t *handler_map;
+ apr_table_t *type_map;
modparrot_handler_info *open_logs_handler;
modparrot_handler_info *child_init_handler;
modparrot_handler_info *child_exit_handler;
@@ -94,3 +96,5 @@
const char *modparrot_cmd_language(cmd_parms *, void *, const char *);
const char *modparrot_cmd_load(cmd_parms *, void *, const char *);
const char *modparrot_cmd_include_path(cmd_parms *, void *, const char *);
+const char *modparrot_cmd_add_type(cmd_parms *, void *, const char *, const char *);
+const char *modparrot_cmd_add_handler(cmd_parms *, void *, const char *, const char *);
Modified: mod_parrot/trunk/src/mod_parrot.c
==============================================================================
--- mod_parrot/trunk/src/mod_parrot.c (original)
+++ mod_parrot/trunk/src/mod_parrot.c Thu Dec 13 18:55:26 2007
@@ -39,7 +39,6 @@
#define MODPARROT_VERSION "0.3"
#define DEFAULT_HANDLER "_handler"
-#define DEFAULT_HLL_HANDLER "PIR"
#define SHOULD_HANDLE(x) (x->handler ? \
(strncmp(x->handler, MODPARROT_MAGIC, strlen(MODPARROT_MAGIC)) ? 0 : 1) : 0)
@@ -135,12 +134,33 @@
{
char hll_namespace[255];
- if (!hll) hll = DEFAULT_HLL_HANDLER;
+ if (!hll) hll = MODPARROT_DEFAULT_HLL;
sprintf(hll_namespace, "ModParrot::HLL::%s", hll);
modparrot_call_sub_IS(interp, hll_namespace, hll_handler, ret, handler);
return(1);
}
+static char *get_request_hll(request_rec *r, const char *handler,
+ const char *content_type)
+{
+ modparrot_srv_config *cfg;
+ char *hll;
+
+ cfg = ap_get_module_config(r->server->module_config, &parrot_module);
+
+ /* check handler name */
+ hll = (char *)apr_table_get(cfg->handler_map, handler);
+ if (hll) return hll;
+
+ /* check mime type */
+ if (content_type) {
+ hll = (char *)apr_table_get(cfg->type_map, content_type);
+ if (hll) return hll;
+ }
+
+ return NULL;
+}
+
static int modparrot_handler(request_rec *r)
{
modparrot_dir_config *dircfg;
@@ -149,19 +169,29 @@
int handler_status;
char *sub, *hll;
- /* politely decline request if we shouldn't be handling this */
- if (!SHOULD_HANDLE(r)) {
- return DECLINED;
- }
+ if (!r->handler) return DECLINED;
/* 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 parrot response handler */
- if (!dircfg->handler) {
- return DECLINED;
+ /* search for a valid HLL, working from the bottom up */
+ 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 default content type */
r->content_type = "text/html";
@@ -181,7 +211,6 @@
/* call HLL handler */
sub = "_handler";
- hll = dircfg->handler->hll ? dircfg->handler->hll : dircfg->hll;
if (!modparrot_hll_handler(ctxp->interp, hll, sub, dircfg->handler->id,
&handler_status)) {
MPLOG_ERRORF(r->server,
@@ -1058,6 +1087,20 @@
RSRC_CONF,
"set the Parrot include path"
),
+ AP_INIT_ITERATE2(
+ "ParrotAddType",
+ modparrot_cmd_add_type,
+ NULL,
+ RSRC_CONF,
+ "associate a MIME type with a mod_parrot HLL"
+ ),
+ AP_INIT_ITERATE2(
+ "ParrotAddHandler",
+ modparrot_cmd_add_handler,
+ NULL,
+ RSRC_CONF,
+ "associate a handler string with a mod_parrot HLL"
+ ),
{ NULL }
};
Modified: mod_parrot/trunk/src/modparrot_config.c
==============================================================================
--- mod_parrot/trunk/src/modparrot_config.c (original)
+++ mod_parrot/trunk/src/modparrot_config.c Thu Dec 13 18:55:26 2007
@@ -45,6 +45,11 @@
cfg->init_path = MODPARROT_DEFAULT_INIT;
cfg->preload = apr_array_make(p, 2, sizeof(modparrot_handler_info));
cfg->include_path = NULL;
+ cfg->type_map = apr_table_make(p, 2);
+ cfg->handler_map = apr_table_make(p, 2);
+
+ /* set default HLL to PIR */
+ apr_table_set(cfg->handler_map, MODPARROT_MAGIC, MODPARROT_DEFAULT_HLL);
return (void *)cfg;
}
@@ -377,3 +382,21 @@
cfg->include_path = (char *)apr_pstrdup(cmd->pool, path);
return NULL;
}
+
+const char *modparrot_cmd_add_type(cmd_parms *cmd, void *mconfig, const char *hll, const char *mtype)
+{
+ modparrot_srv_config *cfg;
+
+ cfg = GET_SERVER_CONFIG(cmd);
+ apr_table_set(cfg->type_map, mtype, hll);
+ return NULL;
+}
+
+const char *modparrot_cmd_add_handler(cmd_parms *cmd, void *mconfig, const char *hll, const char *handler)
+{
+ modparrot_srv_config *cfg;
+
+ cfg = GET_SERVER_CONFIG(cmd);
+ apr_table_set(cfg->handler_map, handler, hll);
+ return NULL;
+}
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.