--- parser3/src/targets/apache13/Attic/mod_parser3.C 2001/11/08 11:52:34 1.9 +++ parser3/src/targets/apache13/Attic/mod_parser3.C 2002/08/01 11:41:20 1.26 @@ -1,12 +1,20 @@ /** @file Parser: apache 1.3 module. - Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) - Author: Alexander Petrosyan (http://paf.design.ru) - - $Id: mod_parser3.C,v 1.9 2001/11/08 11:52:34 paf Exp $ + Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com) + Author: Alexandr Petrosian (http://paf.design.ru) */ +static const char* IDENT_MOD_PARSER3_C="$Date: 2002/08/01 11:41:20 $"; + +#include "pa_config_includes.h" + +#if _MSC_VER +# include +#endif + +#include "pa_globals.h" + #include "httpd.h" #include "http_config.h" #include "http_core.h" @@ -15,72 +23,19 @@ #include "http_protocol.h" #include "util_script.h" +#include "pa_common.h" #include "pa_sapi.h" #include "classes.h" -#include "pa_common.h" -#include "pa_globals.h" #include "pa_request.h" #include "pa_version.h" #include "pa_socks.h" -#ifdef XML -#include -#endif - -// consts - -extern const char *main_RCSIds[]; -#ifdef USE_SMTP -extern const char *smtp_RCSIds[]; -#endif -extern const char *gd_RCSIds[]; -extern const char *classes_RCSIds[]; -extern const char *types_RCSIds[]; -extern const char *ApacheModuleParser3_RCSIds[]; -#ifdef XML -extern const char *xalan_patched_RCSIds[]; -#endif -const char **RCSIds[]={ - main_RCSIds, -#ifdef USE_SMTP - smtp_RCSIds, -#endif - gd_RCSIds, - classes_RCSIds, - types_RCSIds, - ApacheModuleParser3_RCSIds, -#ifdef XML - xalan_patched_RCSIds, -#endif - 0 -}; - - /// apache parser module configuration [httpd.conf + .htaccess-es] struct Parser_module_config { - 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_config_filespec; ///< filespec of site's config file bool parser_status_allowed; }; -#ifdef XML -/** - * Terminate Xalan and Xerces. - * - * Should be called only once per process after deleting all - * instances of XalanTransformer. Once a process has called - * this function, it cannot use the API for the remaining - * lifetime of the process. - - - this requirement is fullfilled by using Pool::register_cleanup - */ -void callXalanTerminate(void *) { - //_asm int 3; - XalanTerminate(); -} -#endif - /* * Declare ourselves so the configuration routines can find and know us. * We'll fill it in at the end of the module. @@ -99,7 +54,7 @@ static const char *cmd_parser_config(cmd Parser_module_config *cfg = (Parser_module_config *) mconfig; // remember assigned filespec into cfg - (cmd->info?cfg->parser_root_config_filespec:cfg->parser_site_config_filespec)=file_spec; + cfg->parser_config_filespec=file_spec; return NULL; } @@ -170,6 +125,35 @@ const char *SAPI::get_env(Pool& pool, co return (const char *)ap_table_get(r->subprocess_env, name); } +#ifndef DOXYGEN +struct SAPI_environment_append_info { + Pool *pool; + const char **cur; +}; +#endif +static const char *mk_env_pair(Pool& pool, const char *key, const char *value) { + char *result=(char *)pool.malloc(strlen(key)+1/*=*/+strlen(value)+1/*0*/); + strcpy(result, key); strcat(result, "="); strcat(result, value); + return result; +} +static int SAPI_environment_append(void *d, const char *k, const char *val) { + if( k && val ) { + SAPI_environment_append_info& info= + *static_cast(d); + *info.cur++=mk_env_pair(*info.pool, k, val); + } + return 1/*true*/; +} +const char *const *SAPI::environment(Pool& pool) { + request_rec *r=static_cast(pool.get_context()); + const table *t=r->subprocess_env; + const char **result= + (const char **)pool.malloc(sizeof(char *)*(ap_table_elts(t)->nelts+1/*0*/)); + SAPI_environment_append_info info={&pool, result}; + ap_table_do(SAPI_environment_append, &info, t, 0); *info.cur=0; // mark EOE + return result; +} + size_t SAPI::read_post(Pool& pool, char *buf, size_t max_bytes) { request_rec *r=static_cast(pool.get_context()); @@ -197,6 +181,7 @@ size_t SAPI::read_post(Pool& pool, char return total_read_bytes; } +/// @test location provide with protocol. think about internal redirects void SAPI::add_header_attribute(Pool& pool, const char *key, const char *value) { request_rec *r=static_cast(pool.get_context()); @@ -254,7 +239,7 @@ static void real_parser_handler(Pool& po const char *content_length=SAPI::get_env(pool, "CONTENT_LENGTH"); request_info.content_length=content_length?atoi(content_length):0; request_info.cookie=SAPI::get_env(pool, "HTTP_COOKIE"); - request_info.user_agent=SAPI::get_env(pool, "HTTP_USER_AGENT"); + request_info.mail_received=false; // config Parser_module_config *dcfg=our_dconfig(r); @@ -263,14 +248,13 @@ static void real_parser_handler(Pool& po // prepare to process request Request request(pool, request_info, - String::UL_USER_HTML, + String::UL_HTML|String::UL_OPTIMIZE_BIT, dcfg->parser_status_allowed ); // process the request request.core( - dcfg->parser_root_config_filespec, true, // /path/to/admin/config - dcfg->parser_site_config_filespec, true, // /path/to/site/config + dcfg->parser_config_filespec, true, // /path/to/config r->header_only!=0); } @@ -288,17 +272,18 @@ void call_real_parser_handler__do_SEH(Po if(system_exception) if(_EXCEPTION_RECORD *er=system_exception->ExceptionRecord) - throw Exception(0, 0, + throw Exception(0, 0, "Exception 0x%08X at 0x%08X", er->ExceptionCode, er->ExceptionAddress); else - throw Exception(0, 0, 0, "Exception "); + throw Exception(0, 0, "Exception "); else - throw Exception(0, 0, 0, "Exception "); + throw Exception(0, 0, "Exception "); } #endif } +/// @test r->finfo.st_mode check seems to work only on win32 static int parser_handler(request_rec *r) { //_asm int 3; if(r->finfo.st_mode == 0) @@ -307,22 +292,10 @@ static int parser_handler(request_rec *r Pool pool(r->pool); pool.set_context(r); -#ifdef XML - /** - * Initialize Xerces and Xalan. - * - * Should be called only once per process before making - * any other API calls. - */ - //_asm int 3; - XalanInitialize(); - pool.register_cleanup(callXalanTerminate, 0); -#endif - /* 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; +// r->no_cache=1; try { // global try call_real_parser_handler__do_SEH(pool, r); @@ -361,6 +334,19 @@ static int parser_handler(request_rec *r 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. */ @@ -404,6 +390,14 @@ static void setup_module_cells() { return; 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. */ @@ -413,17 +407,6 @@ static void setup_module_cells() { // init socks init_socks(pool); -#ifdef XML - /** - * Initialize Xerces and Xalan. - * - * Should be called only once per process before making - * any other API calls. - */ - XalanInitialize(); - pool.register_cleanup(callXalanTerminate, 0); -#endif - // init global classes init_methoded_array(pool); // init global variables @@ -457,6 +440,7 @@ static void parser_server_init(server_re * structure. */ static void *parser_create_dir_config(pool *p, char *dirspec) { + //_asm int 3; /* * Allocate the space for our record from the pool supplied. */ @@ -466,9 +450,6 @@ static void *parser_create_dir_config(po * Now fill in the defaults. If there are any `parent' configuration * records, they'll get merged as part of a separate callback. */ - cfg->parser_root_config_filespec = 0; - cfg->parser_site_config_filespec = 0; - cfg->parser_status_allowed=false; return (void *) cfg; } @@ -487,25 +468,29 @@ static void *parser_create_dir_config(po * * The return value is a pointer to the created module-specific structure * 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, void *newloc_conf) { + //_asm int 3; 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; - // always from parent - merged_config->parser_root_config_filespec = ap_pstrdup(p, pconf->parser_root_config_filespec); + merged_config->parser_config_filespec = ap_pstrdup(p, nconf->parser_config_filespec? + nconf->parser_config_filespec:pconf->parser_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 * 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; } @@ -518,17 +503,14 @@ static void *parser_merge_dir_config(poo * structure. */ 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. */ Parser_module_config *cfg= (Parser_module_config *) ap_pcalloc(p, sizeof(Parser_module_config)); - cfg->parser_root_config_filespec = 0; - cfg->parser_site_config_filespec = 0; - cfg->parser_status_allowed=false; - return (void *) cfg; } @@ -548,6 +530,7 @@ static void *parser_create_server_config static void *parser_merge_server_config(pool *p, void *server1_conf, void *server2_conf) { + //_asm int 3; Parser_module_config *merged_config = (Parser_module_config *) ap_pcalloc(p, sizeof(Parser_module_config)); @@ -558,10 +541,8 @@ static void *parser_merge_server_config( * Our inheritance rules are our own, and part of our module's semantics. * Basically, just note whence we came. */ - merged_config->parser_root_config_filespec = ap_pstrdup(p, s2conf->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? - s2conf->parser_site_config_filespec:s1conf->parser_site_config_filespec); + merged_config->parser_config_filespec = ap_pstrdup(p, s2conf->parser_config_filespec? + s2conf->parser_config_filespec:s1conf->parser_config_filespec); merged_config->parser_status_allowed= s1conf->parser_status_allowed || s2conf->parser_status_allowed; @@ -641,20 +622,12 @@ static int parser_access_checker(request static const command_rec parser_cmds[] = { { - "ParserRootConfig", /* directive name */ - (const char *(*)(void))((void *)cmd_parser_config), // config action routine - (void*)true, /* argument to include in call */ - (int)(ACCESS_CONF|RSRC_CONF), /* where available */ - TAKE1, /* arguments */ - "Parser root config filespec (Admin)" // directive description - }, - { - "ParserSiteConfig", /* directive name */ + "ParserConfig", /* directive name */ (const char *(*)(void))((void *)cmd_parser_config), // config action routine - (void*)false, /* argument to include in call */ + (void*)0, /* argument to include in call */ (int)(OR_OPTIONS), /* where available */ TAKE1, /* arguments */ - "Parser site config filespec" // directive description + "Parser config filespec" // directive description }, { "ParserStatusAllowed", /* directive name */ @@ -724,7 +697,7 @@ module MODULE_VAR_EXPORT parser3_module }; #if defined(_MSC_VER) -# define APACHE_WIN32_SRC "/parser3project/win32apache13/src" +# define APACHE_WIN32_SRC "/parser3project/win32/apache13/src" # ifdef _DEBUG # pragma comment(lib, APACHE_WIN32_SRC "/CoreD/ApacheCore.lib") # else