(pool.info());
+
+ ap_hard_timeout("Send body", r);
+ ap_rwrite(buf, size, r);
+ ap_kill_timeout(r);
+}
+//@}
+
+/// Service funcs
+Service_funcs service_funcs={
+ get_env,
+ read_post,
+ add_header_attribute,
+ send_header,
+ send_body
+};
+
+/// main workhorse
+static int parser_handler(request_rec *r)
+{
+ Pool pool;
+ pool.set_storage(r->pool);
+ pool.set_info(r);
+
+ Parser_module_config *dcfg=our_dconfig(r);
+
+
+ /* A flag which modules can set, to indicate that the data being
+ * returned is volatile, and clients should be told not to cache it.
+ */
+ r->no_cache=1;
+
+ PTRY { // global try
+ const char *filespec_to_process=r->filename;
+
+ ap_add_common_vars(r);
+ ap_add_cgi_vars(r);
+
+ // Request info
+ Request::Info request_info;
+ const char *document_root=
+ (const char *)ap_table_get(r->subprocess_env, "DOCUMENT_ROOT");
+ if(!document_root) {
+ static char fake_document_root[MAX_STRING];
+ strncpy(fake_document_root, filespec_to_process, MAX_STRING);
+ rsplit(fake_document_root, '/'); rsplit(fake_document_root, '\\');// strip filename
+ document_root=fake_document_root;
+ }
+ request_info.document_root=document_root;
+ request_info.path_translated=filespec_to_process;
+ request_info.method=r->method;
+ request_info.query_string=r->args;
+ request_info.uri=
+ (const char *)ap_table_get(r->subprocess_env, "REQUEST_URI");
+ request_info.content_type=
+ (const char *)ap_table_get(r->subprocess_env, "CONTENT_TYPE");
+ const char *content_length =
+ (const char *)ap_table_get(r->subprocess_env, "CONTENT_LENGTH");
+ request_info.content_length=(content_length?atoi(content_length):0);
+ request_info.cookie=
+ (const char *)ap_table_get(r->subprocess_env, "HTTP_COOKIE");
+
+ // prepare to process request
+ Request request(pool,
+ request_info,
+ String::UL_HTML_TYPO
+ );
+
+ ap_log_error(APLOG_MARK, APLOG_DEBUG, r->server,
+ "mod_parser3: handler(%s|%s)", dcfg->parser_root_auto_path,
+ dcfg->parser_site_auto_path);
+
+ // process the request
+ request.core(
+ dcfg->parser_root_auto_path, true, // /path/to/admin/auto.p
+ dcfg->parser_site_auto_path, true, // /path/to/site/auto.p
+ r->header_only!=0);
+ // no actions with request' data past this point
+ // request.exception not not handled here, but all
+ // request' data are associated with it's pool=exception
+
+ // successful finish
+ } PCATCH(e) { // global problem
+ const char *body=e.comment();
+ int content_length=strlen(body);
+
+ // prepare header
+ (*service_funcs.add_header_attribute)(pool, "content-type", "text/plain");
+ char content_length_cstr[MAX_NUMBER];
+ snprintf(content_length_cstr, MAX_NUMBER, "%d", content_length);
+ (*service_funcs.add_header_attribute)(pool, "content-length",
+ content_length_cstr);
+
+ // send header
+ (*service_funcs.send_header)(pool);
+
+ // send body
+ if(!r->header_only)
+ (*service_funcs.send_body)(pool, body, content_length);
+
+ // unsuccessful finish
+ }
+ PEND_CATCH
- /*
- * Now send our actual output. Since we tagged this as being
- * "text/html", we need to embed any HTML.
- */
- ap_rputs(DOCTYPE_HTML_3_2, r);
- ap_rputs("\n", r);
- ap_rputs(" \n", r);
- ap_rputs(" mod_example Module Content-Handler Output\n", r);
- ap_rputs(" \n", r);
- ap_rputs(" \n", r);
- ap_rputs(" \n", r);
- ap_rputs(" mod_example Module Content-Handler Output\n", r);
- ap_rputs("
\n", r);
- ap_rputs(" \n", r);
- ap_rprintf(r, " Apache HTTP Server version: \"%s\"\n",
- ap_get_server_version());
- ap_rputs("
\n", r);
- ap_rprintf(r, " Server built: \"%s\"\n", ap_get_server_built());
- ap_rputs("
\n", r);;
- ap_rputs(" \n", r);
- ap_rputs(" The format for the callback trace is:\n", r);
- ap_rputs("
\n", r);
- ap_rputs(" \n", r);
- ap_rputs(" - n.<routine-name>", r);
- ap_rputs("(<routine-data>)\n", r);
- ap_rputs("
\n", r);
- ap_rputs(" - [<applies-to>]\n", r);
- ap_rputs("
\n", r);
- ap_rputs("
\n", r);
- ap_rputs(" \n", r);
- ap_rputs(" The <routine-data> is supplied by\n", r);
- ap_rputs(" the routine when it requests the trace,\n", r);
- ap_rputs(" and the <applies-to> is extracted\n", r);
- ap_rputs(" from the configuration record at the time of the trace.\n", r);
- ap_rputs(" SVR() indicates a server environment\n", r);
- ap_rputs(" (blank means the main or default server, otherwise it's\n", r);
- ap_rputs(" the name of the VirtualHost); DIR()\n", r);
- ap_rputs(" indicates a location in the URL or filesystem\n", r);
- ap_rputs(" namespace.\n", r);
- ap_rputs("
\n", r);
- ap_rprintf(r, " Static callbacks so far:
\n \n%s
\n",
- trace);
- ap_rputs(" Request-specific callbacks so far:
\n", r);
- ap_rprintf(r, " \n%s
\n", ap_table_get(r->notes, TRACE_NOTE));
- ap_rputs(" Environment for this call:
\n", r);
- ap_rputs(" \n", r);
- ap_rprintf(r, " - Applies-to: %s\n
\n", dcfg->loc);
- ap_rprintf(r, " - \"Example\" directive declared here: %s\n
\n",
- (dcfg->local ? "YES" : "NO"));
- ap_rprintf(r, " - \"Example\" inherited: %s\n
\n",
- (dcfg->congenital ? "YES" : "NO"));
- ap_rputs("
\n", r);
- ap_rputs(" \n", r);
- ap_rputs("\n", r);
- /*
- * We're all done, so cancel the timeout we set. Since this is probably
- * the end of the request we *could* assume this would be done during
- * post-processing - but it's possible that another handler might be
- * called and inherit our outstanding timer. Not good; to each its own.
- */
- ap_kill_timeout(r);
/*
* We did what we wanted to do, so tell the rest of the server we
* succeeded.
@@ -628,57 +631,33 @@ static int example_handler(request_rec *
* There is no return value.
*/
+
/*
* All our module-initialiser does is add its trace to the log.
*/
-static void example_init(server_rec *s, pool *p)
+static void parser_init(server_rec *s, pool *p)
{
-
- char *note;
- char *sname = s->server_hostname;
-
- /*
- * Set up any module cells that ought to be initialised.
- */
- setup_module_cells();
- /*
- * The arbitrary text we add to our trace entry indicates for which server
- * we're being called.
- */
- sname = (sname != NULL) ? sname : "";
- note = ap_pstrcat(p, "example_init(", sname, ")", NULL);
- trace_add(s, NULL, NULL, note);
-}
-
-/*
- * This function is called during server initialisation when an heavy-weight
- * process (such as a child) is being initialised. As with the
- * module-initialisation function, any information that needs to be recorded
- * must be in static cells, since there's no configuration record.
- *
- * There is no return value.
- */
-
-/*
- * All our process-initialiser does is add its trace to the log.
- */
-static void example_child_init(server_rec *s, pool *p)
-{
-
- char *note;
- char *sname = s->server_hostname;
-
- /*
- * Set up any module cells that ought to be initialised.
- */
- setup_module_cells();
- /*
- * The arbitrary text we add to our trace entry indicates for which server
- * we're being called.
- */
- sname = (sname != NULL) ? sname : "";
- note = ap_pstrcat(p, "example_child_init(", sname, ")", NULL);
- trace_add(s, NULL, NULL, note);
+#if MODULE_MAGIC_NUMBER >= 19980527
+ ap_add_version_component("Parser/" PARSER_VERSION);
+#endif
+
+ static bool globals_inited=false;
+ if(globals_inited)
+ return;
+ globals_inited=true;
+
+ static Pool pool; // global pool
+ pool.set_storage(p);
+ PTRY {
+ // init global variables
+ globals_init(pool);
+
+ //...
+ } PCATCH(e) { // global problem
+ const char *body=e.comment();
+ // somehow report that error
+ }
+ PEND_CATCH
}
/*
@@ -693,7 +672,7 @@ static void example_child_init(server_re
/*
* All our process-death routine does is add its trace to the log.
*/
-static void example_child_exit(server_rec *s, pool *p)
+static void parser_child_exit(server_rec *s, pool *p)
{
char *note;
@@ -704,7 +683,7 @@ static void example_child_exit(server_re
* we're being called.
*/
sname = (sname != NULL) ? sname : "";
- note = ap_pstrcat(p, "example_child_exit(", sname, ")", NULL);
+ note = ap_pstrcat(p, "parser_child_exit(", sname, ")", NULL);
trace_add(s, NULL, NULL, note);
}
@@ -720,29 +699,29 @@ static void example_child_exit(server_re
* The return value is a pointer to the created module-specific
* structure.
*/
-static void *example_create_dir_config(pool *p, char *dirspec)
+static void *parser_create_dir_config(pool *p, char *dirspec)
{
- excfg *cfg;
+ Parser_module_config *cfg;
char *dname = dirspec;
/*
* Allocate the space for our record from the pool supplied.
*/
- cfg = (excfg *) ap_pcalloc(p, sizeof(excfg));
+ cfg = (Parser_module_config *) ap_pcalloc(p, sizeof(Parser_module_config));
/*
* Now fill in the defaults. If there are any `parent' configuration
* records, they'll get merged as part of a separate callback.
*/
- cfg->local = 0;
- cfg->congenital = 0;
+ cfg->parser_root_auto_path = 0;
+ cfg->parser_site_auto_path = 0;
cfg->cmode = CONFIG_MODE_DIRECTORY;
/*
* Finally, add our trace to the callback list.
*/
dname = (dname != NULL) ? dname : "";
cfg->loc = ap_pstrcat(p, "DIR(", dname, ")", NULL);
- trace_add(NULL, NULL, cfg, "example_create_dir_config()");
+ trace_add(NULL, NULL, cfg, "parser_create_dir_config()");
return (void *) cfg;
}
@@ -761,28 +740,27 @@ static void *example_create_dir_config(p
* The return value is a pointer to the created module-specific structure
* containing the merged values.
*/
-static void *example_merge_dir_config(pool *p, void *parent_conf,
+static void *parser_merge_dir_config(pool *p, void *parent_conf,
void *newloc_conf)
{
- excfg *merged_config = (excfg *) ap_pcalloc(p, sizeof(excfg));
- excfg *pconf = (excfg *) parent_conf;
- excfg *nconf = (excfg *) newloc_conf;
+ Parser_module_config *merged_config = (Parser_module_config *) ap_pcalloc(p, sizeof(Parser_module_config));
+ Parser_module_config *pconf = (Parser_module_config *) parent_conf;
+ Parser_module_config *nconf = (Parser_module_config *) newloc_conf;
char *note;
+
+ // always from parent
+ merged_config->parser_root_auto_path = ap_pstrdup(p, pconf->parser_root_auto_path);
/*
* Some things get copied directly from the more-specific record, rather
* than getting merged.
*/
- merged_config->local = nconf->local;
+ merged_config->parser_site_auto_path = ap_pstrdup(p, nconf->parser_site_auto_path?
+ nconf->parser_site_auto_path:pconf->parser_site_auto_path);
+
merged_config->loc = ap_pstrdup(p, nconf->loc);
/*
- * Others, like the setting of the `congenital' flag, get ORed in. The
- * setting of that particular flag, for instance, is TRUE if it was ever
- * true anywhere in the upstream configuration.
- */
- merged_config->congenital = (pconf->congenital | pconf->local);
- /*
* If we're merging records for two different types of environment (server
* and directory), mark the new record appropriately. Otherwise, inherit
* the current value.
@@ -793,7 +771,7 @@ static void *example_merge_dir_config(po
* Now just record our being called in the trace list. Include the
* locations we were asked to merge.
*/
- note = ap_pstrcat(p, "example_merge_dir_config(\"", pconf->loc, "\",\"",
+ note = ap_pstrcat(p, "parser_merge_dir_config(\"", pconf->loc, "\",\"",
nconf->loc, "\")", NULL);
trace_add(NULL, NULL, merged_config, note);
return (void *) merged_config;
@@ -806,26 +784,26 @@ static void *example_merge_dir_config(po
* The return value is a pointer to the created module-specific
* structure.
*/
-static void *example_create_server_config(pool *p, server_rec *s)
+static void *parser_create_server_config(pool *p, server_rec *s)
{
- excfg *cfg;
+ Parser_module_config *cfg;
char *sname = s->server_hostname;
/*
- * As with the example_create_dir_config() reoutine, we allocate and fill
+ * As with the parser_create_dir_config() reoutine, we allocate and fill
* in an empty record.
*/
- cfg = (excfg *) ap_pcalloc(p, sizeof(excfg));
- cfg->local = 0;
- cfg->congenital = 0;
+ cfg = (Parser_module_config *) ap_pcalloc(p, sizeof(Parser_module_config));
+ cfg->parser_root_auto_path = 0;
+ cfg->parser_site_auto_path = 0;
cfg->cmode = CONFIG_MODE_SERVER;
/*
* Note that we were called in the trace list.
*/
sname = (sname != NULL) ? sname : "";
cfg->loc = ap_pstrcat(p, "SVR(", sname, ")", NULL);
- trace_add(s, NULL, cfg, "example_create_server_config()");
+ trace_add(s, NULL, cfg, "parser_create_server_config()");
return (void *) cfg;
}
@@ -842,14 +820,13 @@ static void *example_create_server_confi
* The return value is a pointer to the created module-specific structure
* containing the merged values.
*/
-static void *example_merge_server_config(pool *p, void *server1_conf,
+static void *parser_merge_server_config(pool *p, void *server1_conf,
void *server2_conf)
{
- excfg *merged_config = (excfg *) ap_pcalloc(p, sizeof(excfg));
- excfg *s1conf = (excfg *) server1_conf;
- excfg *s2conf = (excfg *) server2_conf;
- char *note;
+ Parser_module_config *merged_config = (Parser_module_config *) ap_pcalloc(p, sizeof(Parser_module_config));
+ Parser_module_config *s1conf = (Parser_module_config *) server1_conf;
+ Parser_module_config *s2conf = (Parser_module_config *) server2_conf;
/*
* Our inheritance rules are our own, and part of our module's semantics.
@@ -857,38 +834,13 @@ static void *example_merge_server_config
*/
merged_config->cmode =
(s1conf->cmode == s2conf->cmode) ? s1conf->cmode : CONFIG_MODE_COMBO;
- merged_config->local = s2conf->local;
- merged_config->congenital = (s1conf->congenital | s1conf->local);
+ merged_config->parser_root_auto_path = ap_pstrdup(p, s2conf->parser_root_auto_path?
+ s2conf->parser_root_auto_path:s1conf->parser_root_auto_path);
+ merged_config->parser_site_auto_path = ap_pstrdup(p, s2conf->parser_site_auto_path?
+ s2conf->parser_site_auto_path:s1conf->parser_site_auto_path);
merged_config->loc = ap_pstrdup(p, s2conf->loc);
- /*
- * Trace our call, including what we were asked to merge.
- */
- note = ap_pstrcat(p, "example_merge_server_config(\"", s1conf->loc, "\",\"",
- s2conf->loc, "\")", NULL);
- trace_add(NULL, NULL, merged_config, note);
- return (void *) merged_config;
-}
-
-/*
- * This routine is called after the request has been read but before any other
- * phases have been processed. This allows us to make decisions based upon
- * the input header fields.
- *
- * The return value is OK, DECLINED, or HTTP_mumble. If we return OK, no
- * further modules are called for this phase.
- */
-static int example_post_read_request(request_rec *r)
-{
-
- excfg *cfg;
-
- cfg = our_dconfig(r);
- /*
- * We don't actually *do* anything here, except note the fact that we were
- * called.
- */
- trace_add(r->server, r, cfg, "example_post_read_request()");
- return DECLINED;
+
+ return (void *) merged_config;
}
/*
@@ -899,17 +851,17 @@ static int example_post_read_request(req
* The return value is OK, DECLINED, or HTTP_mumble. If we return OK, no
* further modules are called for this phase.
*/
-static int example_translate_handler(request_rec *r)
+static int parser_translate_handler(request_rec *r)
{
- excfg *cfg;
+ Parser_module_config *cfg;
cfg = our_dconfig(r);
/*
* We don't actually *do* anything here, except note the fact that we were
* called.
*/
- trace_add(r->server, r, cfg, "example_translate_handler()");
+ trace_add(r->server, r, cfg, "parser_translate_handler()");
return DECLINED;
}
@@ -922,16 +874,16 @@ static int example_translate_handler(req
* HTTP_UNAUTHORIZED). If we return OK, no other modules are given a chance
* at the request during this phase.
*/
-static int example_check_user_id(request_rec *r)
+static int parser_check_user_id(request_rec *r)
{
- excfg *cfg;
+ Parser_module_config *cfg;
cfg = our_dconfig(r);
/*
* Don't do anything except log the call.
*/
- trace_add(r->server, r, cfg, "example_check_user_id()");
+ trace_add(r->server, r, cfg, "parser_check_user_id()");
return DECLINED;
}
@@ -945,17 +897,17 @@ static int example_check_user_id(request
* If *all* modules return DECLINED, the request is aborted with a server
* error.
*/
-static int example_auth_checker(request_rec *r)
+static int parser_auth_checker(request_rec *r)
{
- excfg *cfg;
+ Parser_module_config *cfg;
cfg = our_dconfig(r);
/*
* Log the call and return OK, or access will be denied (even though we
* didn't actually do anything).
*/
- trace_add(r->server, r, cfg, "example_auth_checker()");
+ trace_add(r->server, r, cfg, "parser_auth_checker()");
return DECLINED;
}
@@ -968,91 +920,13 @@ static int example_auth_checker(request_
* return OK or DECLINED. The first one to return any other status, however,
* will abort the sequence (and the request) as usual.
*/
-static int example_access_checker(request_rec *r)
+static int parser_access_checker(request_rec *r)
{
- excfg *cfg;
+ Parser_module_config *cfg;
cfg = our_dconfig(r);
- trace_add(r->server, r, cfg, "example_access_checker()");
- return DECLINED;
-}
-
-/*
- * This routine is called to determine and/or set the various document type
- * information bits, like Content-type (via r->content_type), language, et
- * cetera.
- *
- * The return value is OK, DECLINED, or HTTP_mumble. If we return OK, no
- * further modules are given a chance at the request for this phase.
- */
-static int example_type_checker(request_rec *r)
-{
-
- excfg *cfg;
-
- cfg = our_dconfig(r);
- /*
- * Log the call, but don't do anything else - and report truthfully that
- * we didn't do anything.
- */
- trace_add(r->server, r, cfg, "example_type_checker()");
- return DECLINED;
-}
-
-/*
- * This routine is called to perform any module-specific fixing of header
- * fields, et cetera. It is invoked just before any content-handler.
- *
- * The return value is OK, DECLINED, or HTTP_mumble. If we return OK, the
- * server will still call any remaining modules with an handler for this
- * phase.
- */
-static int example_fixer_upper(request_rec *r)
-{
-
- excfg *cfg;
-
- cfg = our_dconfig(r);
- /*
- * Log the call and exit.
- */
- trace_add(r->server, r, cfg, "example_fixer_upper()");
- return OK;
-}
-
-/*
- * This routine is called to perform any module-specific logging activities
- * over and above the normal server things.
- *
- * The return value is OK, DECLINED, or HTTP_mumble. If we return OK, any
- * remaining modules with an handler for this phase will still be called.
- */
-static int example_logger(request_rec *r)
-{
-
- excfg *cfg;
-
- cfg = our_dconfig(r);
- trace_add(r->server, r, cfg, "example_logger()");
- return DECLINED;
-}
-
-/*
- * This routine is called to give the module a chance to look at the request
- * headers and take any appropriate specific actions early in the processing
- * sequence.
- *
- * The return value is OK, DECLINED, or HTTP_mumble. If we return OK, any
- * remaining modules with handlers for this phase will still be called.
- */
-static int example_header_parser(request_rec *r)
-{
-
- excfg *cfg;
-
- cfg = our_dconfig(r);
- trace_add(r->server, r, cfg, "example_header_parser()");
+ trace_add(r->server, r, cfg, "parser_access_checker()");
return DECLINED;
}
@@ -1068,16 +942,23 @@ static int example_header_parser(request
/*
* List of directives specific to our module.
*/
-static const command_rec example_cmds[] =
+static const command_rec parser_cmds[] =
{
{
- "Example", /* directive name */
- cmd_example, /* config action routine */
- NULL, /* argument to include in call */
- OR_OPTIONS, /* where available */
- NO_ARGS, /* arguments */
- "Example directive - no arguments"
- /* directive description */
+ "parser_root_auto_path", /* directive name */
+ (const char *(*)(void))((void *)cmd_parser_auto_path), // config action routine
+ (void*)true, /* argument to include in call */
+ (int)(ACCESS_CONF|RSRC_CONF), /* where available */
+ TAKE1, /* arguments */
+ "Parser root auto.p filespec (Admin)" // directive description
+ },
+ {
+ "parser_site_auto_path", /* directive name */
+ (const char *(*)(void))((void *)cmd_parser_auto_path), // config action routine
+ (void*)false, /* argument to include in call */
+ (int)(OR_OPTIONS), /* where available */
+ TAKE1, /* arguments */
+ "Parser site auto.p filespec" // directive description
},
{NULL}
};
@@ -1099,9 +980,9 @@ static const command_rec example_cmds[]
* if a content-handler returns anything except DECLINED, no other
* content-handlers will be called.
*/
-static const handler_rec example_handlers[] =
+static const handler_rec parser_handlers[] =
{
- {"example-handler", example_handler},
+ {"parser3-handler", parser_handler},
{NULL}
};
@@ -1119,33 +1000,33 @@ static const handler_rec example_handler
* during request processing. Note that not all routines are necessarily
* called (such as if a resource doesn't have access restrictions).
*/
-module MODULE_VAR_EXPORT example_module =
+module MODULE_VAR_EXPORT parser3_module =
{
STANDARD_MODULE_STUFF,
- example_init, /* module initializer */
- example_create_dir_config, /* per-directory config creator */
- example_merge_dir_config, /* dir config merger */
- example_create_server_config, /* server config creator */
- example_merge_server_config, /* server config merger */
- example_cmds, /* command table */
- example_handlers, /* [9] list of handlers */
- example_translate_handler, /* [2] filename-to-URI translation */
- example_check_user_id, /* [5] check/validate user_id */
- example_auth_checker, /* [6] check user_id is valid *here* */
- example_access_checker, /* [4] check access by host address */
- example_type_checker, /* [7] MIME type checker/setter */
- example_fixer_upper, /* [8] fixups */
- example_logger, /* [10] logger */
+ parser_init, /* module initializer */
+ parser_create_dir_config, /* per-directory config creator */
+ parser_merge_dir_config, /* dir config merger */
+ parser_create_server_config, /* server config creator */
+ parser_merge_server_config, /* server config merger */
+ parser_cmds, /* command table */
+ parser_handlers, /* [9] list of handlers */
+ parser_translate_handler, /* [2] filename-to-URI translation */
+ parser_check_user_id, /* [5] check/validate user_id */
+ parser_auth_checker, /* [6] check user_id is valid *here* */
+ parser_access_checker, /* [4] check access by host address */
+ 0, /* [7] MIME type checker/setter */
+ 0, /* [8] fixups */
+ 0 /* [10] logger */
#if MODULE_MAGIC_NUMBER >= 19970103
- example_header_parser, /* [3] header parser */
+ ,0 /* [3] header parser */
#endif
#if MODULE_MAGIC_NUMBER >= 19970719
- example_child_init, /* process initializer */
+ ,0 /* process initializer */
#endif
#if MODULE_MAGIC_NUMBER >= 19970728
- example_child_exit, /* process exit/cleanup */
+ ,parser_child_exit /* process exit/cleanup */
#endif
#if MODULE_MAGIC_NUMBER >= 19970902
- example_post_read_request /* [1] post read_request handling */
+ ,0 /* [1] post read_request handling */
#endif
};