|
|
| version 1.5, 2001/10/22 09:02:04 | version 1.13, 2001/11/26 12:14:09 |
|---|---|
| Line 2 | Line 2 |
| Parser: apache 1.3 module. | Parser: apache 1.3 module. |
| Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) | Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) |
| Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf) | Author: Alexander Petrosyan <paf@design.ru> (http://paf.design.ru) |
| $Id$ | $Id$ |
| */ | */ |
| Line 15 | Line 15 |
| #include "http_protocol.h" | #include "http_protocol.h" |
| #include "util_script.h" | #include "util_script.h" |
| #include "pa_config_includes.h" | |
| #if _MSC_VER | |
| # include <new.h> | |
| #endif | |
| #include "pa_sapi.h" | #include "pa_sapi.h" |
| #include "classes.h" | #include "classes.h" |
| #include "pa_common.h" | #include "pa_common.h" |
| Line 27 | Line 33 |
| #include <XalanTransformer/XalanCAPI.h> | #include <XalanTransformer/XalanCAPI.h> |
| #endif | #endif |
| #ifdef _DEBUG | |
| # define DEBUG_PREFIX "debug_" | |
| # define PARSER3_MODULE debug_parser3_module | |
| #else | |
| # define DEBUG_PREFIX | |
| # define PARSER3_MODULE parser3_module | |
| #endif | |
| // consts | // consts |
| extern const char *main_RCSIds[]; | extern const char *main_RCSIds[]; |
| Line 68 const char **RCSIds[]={ | Line 66 const char **RCSIds[]={ |
| struct Parser_module_config { | struct Parser_module_config { |
| const char* parser_root_config_filespec; ///< filespec of admin's config file | const char* parser_root_config_filespec; ///< filespec of admin's config file |
| const char* parser_site_config_filespec; ///< filespec of site's config file | const char* parser_site_config_filespec; ///< filespec of site's config file |
| bool parser_status_allowed; | |
| }; | }; |
| #ifdef XML | #ifdef XML |
| Line 92 void callXalanTerminate(void *) { | Line 91 void callXalanTerminate(void *) { |
| * Declare ourselves so the configuration routines can find and know us. | * Declare ourselves so the configuration routines can find and know us. |
| * We'll fill it in at the end of the module. | * We'll fill it in at the end of the module. |
| */ | */ |
| extern "C" module MODULE_VAR_EXPORT PARSER3_MODULE; | extern "C" module MODULE_VAR_EXPORT parser3_module; |
| /* | /* |
| * Locate our directory configuration record for the current request. | * Locate our directory configuration record for the current request. |
| */ | */ |
| static Parser_module_config *our_dconfig(request_rec *r) { | static Parser_module_config *our_dconfig(request_rec *r) { |
| return (Parser_module_config *) | return (Parser_module_config *) |
| ap_get_module_config(r->per_dir_config, &PARSER3_MODULE); | ap_get_module_config(r->per_dir_config, &parser3_module); |
| } | } |
| static const char *cmd_parser_config(cmd_parms *cmd, void *mconfig, char *file_spec) { | static const char *cmd_parser_config(cmd_parms *cmd, void *mconfig, char *file_spec) { |
| Line 110 static const char *cmd_parser_config(cmd | Line 109 static const char *cmd_parser_config(cmd |
| return NULL; | return NULL; |
| } | } |
| static const char *cmd_parser_status_allowed(cmd_parms *cmd, void *mconfig, char *file_spec) { | |
| //_asm int 3; | |
| Parser_module_config *cfg = (Parser_module_config *) mconfig; | |
| cfg->parser_status_allowed=true; | |
| return NULL; | |
| } | |
| /*--------------------------------------------------------------------------*/ | /*--------------------------------------------------------------------------*/ |
| Line 152 void SAPI::log(Pool& pool, const char *f | Line 159 void SAPI::log(Pool& pool, const char *f |
| va_end(args); | va_end(args); |
| } | } |
| void SAPI::die(const char *fmt, ...) { | |
| va_list args; | |
| va_start(args,fmt); | |
| char buf[MAX_STRING]; | |
| size_t size=vsnprintf(buf, MAX_STRING, fmt, args); | |
| remove_crlf(buf, buf+size); | |
| ap_log_error(APLOG_MARK, APLOG_EMERG, 0, "%s", buf); | |
| va_end(args); | |
| exit(1); | |
| } | |
| const char *SAPI::get_env(Pool& pool, const char *name) { | const char *SAPI::get_env(Pool& pool, const char *name) { |
| request_rec *r=static_cast<request_rec *>(pool.get_context()); | request_rec *r=static_cast<request_rec *>(pool.get_context()); |
| return (const char *)ap_table_get(r->subprocess_env, name); | return (const char *)ap_table_get(r->subprocess_env, name); |
| Line 243 static void real_parser_handler(Pool& po | Line 262 static void real_parser_handler(Pool& po |
| request_info.cookie=SAPI::get_env(pool, "HTTP_COOKIE"); | request_info.cookie=SAPI::get_env(pool, "HTTP_COOKIE"); |
| request_info.user_agent=SAPI::get_env(pool, "HTTP_USER_AGENT"); | request_info.user_agent=SAPI::get_env(pool, "HTTP_USER_AGENT"); |
| // config | |
| Parser_module_config *dcfg=our_dconfig(r); | |
| //_asm int 3; | //_asm int 3; |
| // prepare to process request | // prepare to process request |
| Request request(pool, | Request request(pool, |
| request_info, | request_info, |
| String::UL_USER_HTML | String::UL_HTML|String::UL_OPTIMIZE_BIT, |
| dcfg->parser_status_allowed | |
| ); | ); |
| // process the request | // process the request |
| Parser_module_config *dcfg=our_dconfig(r); | |
| request.core( | request.core( |
| dcfg->parser_root_config_filespec, true, // /path/to/admin/config | dcfg->parser_root_config_filespec, true, // /path/to/admin/config |
| dcfg->parser_site_config_filespec, true, // /path/to/site/config | dcfg->parser_site_config_filespec, true, // /path/to/site/config |
| Line 284 void call_real_parser_handler__do_SEH(Po | Line 306 void call_real_parser_handler__do_SEH(Po |
| } | } |
| static int parser_handler(request_rec *r) { | static int parser_handler(request_rec *r) { |
| // _asm int 3; | //_asm int 3; |
| if(r->finfo.st_mode == 0) | if(r->finfo.st_mode == 0) |
| return NOT_FOUND; | return NOT_FOUND; |
| Line 345 static int parser_handler(request_rec *r | Line 367 static int parser_handler(request_rec *r |
| return OK; | return OK; |
| } | } |
| #if _MSC_VER | |
| int failed_new(size_t size) { | |
| SAPI::die("out of memory in 'new', failed to allocated %u bytes", size); | |
| return 0; // not reached | |
| } | |
| #endif | |
| #ifdef HAVE_SET_NEW_HANDLER | |
| void failed_new() { | |
| SAPI::die("out of memory in 'new'"); | |
| } | |
| #endif | |
| /*--------------------------------------------------------------------------*/ | /*--------------------------------------------------------------------------*/ |
| /* */ | /* */ |
| /* Now let's declare routines for each of the callback phase in order. */ | /* Now let's declare routines for each of the callback phase in order. */ |
| Line 388 static void setup_module_cells() { | Line 423 static void setup_module_cells() { |
| return; | return; |
| globals_inited=true; | globals_inited=true; |
| #ifdef WIN32 | |
| _set_new_handler(failed_new); | |
| #endif | |
| #ifdef HAVE_SET_NEW_HANDLER | |
| std::set_new_handler(failed_new); | |
| #endif | |
| /* | /* |
| * allocate our module-private pool. | * allocate our module-private pool. |
| */ | */ |
| Line 413 static void setup_module_cells() { | Line 456 static void setup_module_cells() { |
| // init global variables | // init global variables |
| pa_globals_init(pool); | pa_globals_init(pool); |
| } catch(const Exception& e) { // global problem | } catch(const Exception& e) { // global problem |
| ap_log_error(APLOG_MARK, APLOG_EMERG, 0, | SAPI::die("setup_module_cells failed: %s", e.comment()); |
| "setup_module_cells failed: ", e.comment()); | |
| exit(1); | |
| } | } |
| } | } |
| Line 443 static void parser_server_init(server_re | Line 484 static void parser_server_init(server_re |
| * structure. | * structure. |
| */ | */ |
| static void *parser_create_dir_config(pool *p, char *dirspec) { | static void *parser_create_dir_config(pool *p, char *dirspec) { |
| //_asm int 3; | |
| /* | /* |
| * Allocate the space for our record from the pool supplied. | * Allocate the space for our record from the pool supplied. |
| */ | */ |
| Line 452 static void *parser_create_dir_config(po | Line 494 static void *parser_create_dir_config(po |
| * Now fill in the defaults. If there are any `parent' configuration | * Now fill in the defaults. If there are any `parent' configuration |
| * records, they'll get merged as part of a separate callback. | * records, they'll get merged as part of a separate callback. |
| */ | */ |
| cfg->parser_root_config_filespec = 0; | |
| cfg->parser_site_config_filespec = 0; | |
| return (void *) cfg; | return (void *) cfg; |
| } | } |
| Line 471 static void *parser_create_dir_config(po | Line 512 static void *parser_create_dir_config(po |
| * | * |
| * The return value is a pointer to the created module-specific structure | * The return value is a pointer to the created module-specific structure |
| * containing the merged values. | * containing the merged values. |
| 20011126 paf: noticed, that this is called even on virtual root merge with something "parent", | |
| while thought that that is part of merge_server... | |
| */ | */ |
| static void *parser_merge_dir_config(pool *p, void *parent_conf, | static void *parser_merge_dir_config(pool *p, void *parent_conf, |
| void *newloc_conf) { | void *newloc_conf) { |
| //_asm int 3; | |
| Parser_module_config *merged_config = | Parser_module_config *merged_config = |
| (Parser_module_config *) ap_pcalloc(p, sizeof(Parser_module_config)); | (Parser_module_config *) ap_pcalloc(p, sizeof(Parser_module_config)); |
| Parser_module_config *pconf = (Parser_module_config *) parent_conf; | Parser_module_config *pconf = (Parser_module_config *) parent_conf; |
| Parser_module_config *nconf = (Parser_module_config *) newloc_conf; | Parser_module_config *nconf = (Parser_module_config *) newloc_conf; |
| // always from parent | merged_config->parser_root_config_filespec = ap_pstrdup(p, nconf->parser_root_config_filespec? |
| merged_config->parser_root_config_filespec = ap_pstrdup(p, pconf->parser_root_config_filespec); | nconf->parser_root_config_filespec:pconf->parser_root_config_filespec); |
| /* | merged_config->parser_site_config_filespec = ap_pstrdup(p, nconf->parser_site_config_filespec? |
| nconf->parser_site_config_filespec:pconf->parser_site_config_filespec); | |
| merged_config->parser_status_allowed= | |
| pconf->parser_status_allowed || | |
| nconf->parser_status_allowed; | |
| /* | |
| * Some things get copied directly from the more-specific record, rather | * Some things get copied directly from the more-specific record, rather |
| * than getting merged. | * than getting merged. |
| */ | */ |
| merged_config->parser_site_config_filespec = ap_pstrdup(p, nconf->parser_site_config_filespec? | |
| nconf->parser_site_config_filespec:pconf->parser_site_config_filespec); | |
| return (void *) merged_config; | return (void *) merged_config; |
| } | } |
| Line 499 static void *parser_merge_dir_config(poo | Line 549 static void *parser_merge_dir_config(poo |
| * structure. | * structure. |
| */ | */ |
| static void *parser_create_server_config(pool *p, server_rec *s) { | static void *parser_create_server_config(pool *p, server_rec *s) { |
| //_asm int 3; | |
| /* | /* |
| * As with the parser_create_dir_config() reoutine, we allocate and fill | * As with the parser_create_dir_config() routine, we allocate and fill |
| * in an empty record. | * in an empty record. |
| */ | */ |
| Parser_module_config *cfg= | Parser_module_config *cfg= |
| (Parser_module_config *) ap_pcalloc(p, sizeof(Parser_module_config)); | (Parser_module_config *) ap_pcalloc(p, sizeof(Parser_module_config)); |
| cfg->parser_root_config_filespec = 0; | |
| cfg->parser_site_config_filespec = 0; | |
| return (void *) cfg; | return (void *) cfg; |
| } | } |
| Line 528 static void *parser_create_server_config | Line 576 static void *parser_create_server_config |
| static void *parser_merge_server_config(pool *p, void *server1_conf, | static void *parser_merge_server_config(pool *p, void *server1_conf, |
| void *server2_conf) | void *server2_conf) |
| { | { |
| //_asm int 3; | |
| Parser_module_config *merged_config = | Parser_module_config *merged_config = |
| (Parser_module_config *) ap_pcalloc(p, sizeof(Parser_module_config)); | (Parser_module_config *) ap_pcalloc(p, sizeof(Parser_module_config)); |
| Line 542 static void *parser_merge_server_config( | Line 591 static void *parser_merge_server_config( |
| s2conf->parser_root_config_filespec:s1conf->parser_root_config_filespec); | s2conf->parser_root_config_filespec:s1conf->parser_root_config_filespec); |
| merged_config->parser_site_config_filespec = ap_pstrdup(p, s2conf->parser_site_config_filespec? | merged_config->parser_site_config_filespec = ap_pstrdup(p, s2conf->parser_site_config_filespec? |
| s2conf->parser_site_config_filespec:s1conf->parser_site_config_filespec); | s2conf->parser_site_config_filespec:s1conf->parser_site_config_filespec); |
| merged_config->parser_status_allowed= | |
| s1conf->parser_status_allowed || | |
| s2conf->parser_status_allowed; | |
| return (void *) merged_config; | return (void *) merged_config; |
| } | } |
| Line 618 static int parser_access_checker(request | Line 670 static int parser_access_checker(request |
| static const command_rec parser_cmds[] = | static const command_rec parser_cmds[] = |
| { | { |
| { | { |
| DEBUG_PREFIX"ParserRootConfig", /* directive name */ | "ParserRootConfig", /* directive name */ |
| (const char *(*)(void))((void *)cmd_parser_config), // config action routine | (const char *(*)(void))((void *)cmd_parser_config), // config action routine |
| (void*)true, /* argument to include in call */ | (void*)true, /* argument to include in call */ |
| (int)(ACCESS_CONF|RSRC_CONF), /* where available */ | (int)(ACCESS_CONF|RSRC_CONF), /* where available */ |
| Line 626 static const command_rec parser_cmds[] = | Line 678 static const command_rec parser_cmds[] = |
| "Parser root config filespec (Admin)" // directive description | "Parser root config filespec (Admin)" // directive description |
| }, | }, |
| { | { |
| DEBUG_PREFIX"ParserSiteConfig", /* directive name */ | "ParserSiteConfig", /* directive name */ |
| (const char *(*)(void))((void *)cmd_parser_config), // config action routine | (const char *(*)(void))((void *)cmd_parser_config), // config action routine |
| (void*)false, /* argument to include in call */ | (void*)false, /* argument to include in call */ |
| (int)(OR_OPTIONS), /* where available */ | (int)(OR_OPTIONS), /* where available */ |
| TAKE1, /* arguments */ | TAKE1, /* arguments */ |
| "Parser site config filespec" // directive description | "Parser site config filespec" // directive description |
| }, | }, |
| { | |
| "ParserStatusAllowed", /* directive name */ | |
| (const char *(*)(void))((void *)cmd_parser_status_allowed), // config action routine | |
| (void*)0, /* argument to include in call */ | |
| (int)(ACCESS_CONF), /* where available */ | |
| NO_ARGS, /* arguments */ | |
| "Parser status class can be used" // directive description | |
| }, | |
| {NULL} | {NULL} |
| }; | }; |
| Line 655 static const command_rec parser_cmds[] = | Line 715 static const command_rec parser_cmds[] = |
| */ | */ |
| static const handler_rec parser_handlers[] = | static const handler_rec parser_handlers[] = |
| { | { |
| {DEBUG_PREFIX"parser3-handler", parser_handler}, | {"parser3-handler", parser_handler}, |
| {NULL} | {NULL} |
| }; | }; |
| Line 673 static const handler_rec parser_handlers | Line 733 static const handler_rec parser_handlers |
| * during request processing. Note that not all routines are necessarily | * during request processing. Note that not all routines are necessarily |
| * called (such as if a resource doesn't have access restrictions). | * called (such as if a resource doesn't have access restrictions). |
| */ | */ |
| module MODULE_VAR_EXPORT PARSER3_MODULE = | module MODULE_VAR_EXPORT parser3_module = |
| { | { |
| STANDARD_MODULE_STUFF, | STANDARD_MODULE_STUFF, |
| parser_server_init, /* module initializer */ | parser_server_init, /* module initializer */ |