--- parser3/src/targets/apache13/modules/extra/Attic/mod_parser3.C 2001/03/23 10:14:35 1.14 +++ parser3/src/targets/apache13/modules/extra/Attic/mod_parser3.C 2001/08/09 08:45:17 1.40 @@ -4,9 +4,8 @@ Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) Author: Alexander Petrosyan (http://design.ru/paf) - - $Id: mod_parser3.C,v 1.14 2001/03/23 10:14:35 paf Exp $ */ +static const char *RCSId="$Id: mod_parser3.C,v 1.40 2001/08/09 08:45:17 parser Exp $"; #include "httpd.h" #include "http_config.h" @@ -16,28 +15,41 @@ #include "http_protocol.h" #include "util_script.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 _DEBUG +# define DEBUG_PREFIX "debug_" +# define PARSER3_MODULE debug_parser3_module +#else +# define DEBUG_PREFIX +# define PARSER3_MODULE parser3_module +#endif + +/// apache parser module configuration [httpd.conf + .htaccess-es] struct Parser_module_config { - const char* parser_root_auto_path; /// filespec of admin's auto.p file - const char* parser_site_auto_path; /// filespec of site's auto.p file + const char* parser_root_auto_path; ///< filespec of admin's auto.p file + const char* parser_site_auto_path; ///< filespec of site's auto.p file }; /* * Declare ourselves so the configuration routines can find and know us. * 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. */ static Parser_module_config *our_dconfig(request_rec *r) { 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_auto_path(cmd_parms *cmd, void *mconfig, char *file_spec) { @@ -77,17 +89,28 @@ static const char *cmd_parser_auto_path( //@{ -/// service func decl -static const char *sapi_get_env(Pool& pool, const char *name) { +/// SAPI func decl +void SAPI::log(Pool& pool, const char *fmt, ...) { + request_rec *r=static_cast(pool.context()); + + va_list args; + va_start(args,fmt); + char buf[MAX_STRING]; + vsnprintf(buf, MAX_STRING, fmt, args); + ap_log_rerror(0, 0, APLOG_ERR | APLOG_NOERRNO, r, "%s", buf); + va_end(args); +} + +const char *SAPI::get_env(Pool& pool, const char *name) { request_rec *r=static_cast(pool.context()); return (const char *)ap_table_get(r->subprocess_env, name); } -static uint sapi_read_post(Pool& pool, char *buf, uint max_bytes) { +size_t SAPI::read_post(Pool& pool, char *buf, size_t max_bytes) { request_rec *r=static_cast(pool.context()); /* ap_log_error(APLOG_MARK, APLOG_DEBUG, r->server, - "mod_parser3: sapi_read_post(max=%u)", max_bytes); + "mod_parser3: SAPI::read_post(max=%u)", max_bytes); */ int retval; if((retval = ap_setup_client_block(r, REQUEST_CHUNKED_ERROR))) @@ -110,9 +133,12 @@ static uint sapi_read_post(Pool& pool, c return total_read_bytes; } -static void sapi_add_header_attribute(Pool& pool, const char *key, const char *value) { +void SAPI::add_header_attribute(Pool& pool, const char *key, const char *value) { request_rec *r=static_cast(pool.context()); + if(strcasecmp(key, "location")==0) + r->status=302; + if(strcasecmp(key, "content-type")==0) { /* r->content_type, *not* r->headers_out("Content-type"). If you don't * set it, it will be filled in with the server's default type (typically @@ -120,11 +146,13 @@ static void sapi_add_header_attribute(Po * case. */ r->content_type = value; - } else - ap_table_merge(r->headers_out, key, value); + } else if(strcasecmp(key, "status")==0) + r->status=atoi(value); + else + ap_table_addn(r->headers_out, key, value); } -static void sapi_send_header(Pool& pool) { +void SAPI::send_header(Pool& pool) { request_rec *r=static_cast(pool.context()); ap_hard_timeout("Send header", r); @@ -132,33 +160,27 @@ static void sapi_send_header(Pool& pool) ap_kill_timeout(r); } -static void sapi_send_body(Pool& pool, const char *buf, size_t size) { +void SAPI::send_body(Pool& pool, const void *buf, size_t size) { request_rec *r=static_cast(pool.context()); ap_hard_timeout("Send body", r); ap_rwrite(buf, size, r); ap_kill_timeout(r); } -//@} -/// SAPI -SAPI sapi={ - sapi_get_env, - sapi_read_post, - sapi_add_header_attribute, - sapi_send_header, - sapi_send_body -}; +//@} /** main workhorse @todo intelligent cache-control */ -static int parser_handler(request_rec *r) -{ - Pool pool; - pool.set_storage(r->pool); +static int parser_handler(request_rec *r) { +// _asm int 3; + if(r->finfo.st_mode == 0) + return NOT_FOUND; + + Pool pool(r->pool); pool.set_context(r); Parser_module_config *dcfg=our_dconfig(r); @@ -175,25 +197,21 @@ static int parser_handler(request_rec *r // Request info Request::Info request_info; - request_info.document_root=(const char *) - ap_table_get(r->subprocess_env, "DOCUMENT_ROOT"); + request_info.document_root=SAPI::get_env(pool, "DOCUMENT_ROOT"); request_info.path_translated=r->filename; 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.uri=SAPI::get_env(pool, "REQUEST_URI"); + request_info.content_type=SAPI::get_env(pool, "CONTENT_TYPE"); + const char *content_length=SAPI::get_env(pool, "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"); + request_info.cookie=SAPI::get_env(pool, "HTTP_COOKIE"); + request_info.user_agent=SAPI::get_env(pool, "HTTP_USER_AGENT"); // prepare to process request Request request(pool, request_info, - String::UL_HTML_TYPO + String::UL_USER_HTML ); // process the request @@ -207,21 +225,28 @@ static int parser_handler(request_rec *r // successful finish } PCATCH(e) { // global problem + // don't allocate anything on pool here: + // possible pool' exception not catch-ed now + // and there could be out-of-memory exception const char *body=e.comment(); + // log it + SAPI::log(pool, "exception in request exception handler: %s", body); + + // int content_length=strlen(body); // prepare header - sapi_add_header_attribute(pool, "content-type", "text/plain"); + SAPI::add_header_attribute(pool, "content-type", "text/plain"); char content_length_cstr[MAX_NUMBER]; - snprintf(content_length_cstr, MAX_NUMBER, "%lu", content_length); - sapi_add_header_attribute(pool, "content-length", content_length_cstr); + snprintf(content_length_cstr, MAX_NUMBER, "%u", content_length); + SAPI::add_header_attribute(pool, "content-length", content_length_cstr); // send header - sapi_send_header(pool); + SAPI::send_header(pool); // send body if(!r->header_only) - sapi_send_body(pool, body, content_length); + SAPI::send_body(pool, body, content_length); // unsuccessful finish } @@ -272,7 +297,7 @@ static int parser_handler(request_rec *r */ static void setup_module_cells() { - static bool globals_inited=false; + static bool globals_inited=false; if(globals_inited) return; globals_inited=true; @@ -280,25 +305,26 @@ static void setup_module_cells() { /* * allocate our module-private pool. */ - pool *module_pool=ap_make_sub_pool(NULL); - - static Pool pool; // global pool - pool.set_storage(module_pool); + static Pool pool(ap_make_sub_pool(NULL)); // global pool PTRY { + // init socks + init_socks(pool); + + // init global classes + init_methoded_array(pool); // init global variables - globals_init(pool); - - //... + pa_globals_init(pool); } PCATCH(e) { // global problem - const char *body=e.comment(); - // TODO: somehow report that error + ap_log_error(APLOG_MARK, APLOG_EMERG, 0, + "setup_module_cells failed: ", e.comment()); + exit(1); } PEND_CATCH } static void parser_server_init(server_rec *s, pool *p) { #if MODULE_MAGIC_NUMBER >= 19980527 - ap_add_version_component("Parser/" PARSER_VERSION); + ap_add_version_component("Parser/"PARSER_VERSION); #endif /* @@ -495,7 +521,7 @@ static int parser_access_checker(request static const command_rec parser_cmds[] = { { - "parser_root_auto_path", /* directive name */ + DEBUG_PREFIX"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 */ @@ -503,7 +529,7 @@ static const command_rec parser_cmds[] = "Parser root auto.p filespec (Admin)" // directive description }, { - "parser_site_auto_path", /* directive name */ + DEBUG_PREFIX"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 */ @@ -532,7 +558,7 @@ static const command_rec parser_cmds[] = */ static const handler_rec parser_handlers[] = { - {"parser3-handler", parser_handler}, + {DEBUG_PREFIX"parser3-handler", parser_handler}, {NULL} }; @@ -550,7 +576,7 @@ static const handler_rec parser_handlers * 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 parser3_module = +module MODULE_VAR_EXPORT PARSER3_MODULE = { STANDARD_MODULE_STUFF, parser_server_init, /* module initializer */