--- parser3/src/targets/apache13/modules/extra/Attic/mod_parser3.C 2001/03/21 14:06:49 1.2 +++ parser3/src/targets/apache13/modules/extra/Attic/mod_parser3.C 2001/03/21 17:16:34 1.7 @@ -1,11 +1,11 @@ /** @file - Parser: apache module. + Parser: apache 1.3 module. Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) Author: Alexander Petrosyan (http://design.ru/paf) - $Id: mod_parser3.C,v 1.2 2001/03/21 14:06:49 paf Exp $ + $Id: mod_parser3.C,v 1.7 2001/03/21 17:16:34 paf Exp $ */ #include "httpd.h" @@ -78,8 +78,8 @@ static table *static_calls_made = NULL; * freed each time we modify the trace. That way previous layers of trace * data don't get lost. */ -static pool *example_pool = NULL; -static pool *example_subpool = NULL; +static pool *parser3_pool = NULL; +static pool *parser3_subpool = NULL; /* * Declare ourselves so the configuration routines can find and know us. @@ -246,15 +246,15 @@ static void setup_module_cells() /* * If we haven't already allocated our module-private pool, do so now. */ - if (example_pool == NULL) { - example_pool = ap_make_sub_pool(NULL); + if (parser3_pool == NULL) { + parser3_pool = ap_make_sub_pool(NULL); }; /* * Likewise for the table of routine/environment pairs we visit outside of * request context. */ if (static_calls_made == NULL) { - static_calls_made = ap_make_table(example_pool, 16); + static_calls_made = ap_make_table(parser3_pool, 16); }; } @@ -312,7 +312,7 @@ static void trace_add(server_rec *s, req * Make a new sub-pool and copy any existing trace to it. Point the * trace cell at the copied value. */ - p = ap_make_sub_pool(example_pool); + p = ap_make_sub_pool(parser3_pool); if (trace != NULL) { trace = ap_pstrdup(p, trace); } @@ -320,10 +320,10 @@ static void trace_add(server_rec *s, req * Now, if we have a sub-pool from before, nuke it and replace with * the one we just allocated. */ - if (example_subpool != NULL) { - ap_destroy_pool(example_subpool); + if (parser3_subpool != NULL) { + ap_destroy_pool(parser3_subpool); } - example_subpool = p; + parser3_subpool = p; trace_copy = trace; } /* @@ -376,8 +376,8 @@ static void trace_add(server_rec *s, req * these co-routines are called for every single request, and the impact * on the size (and readability) of the error_log is considerable. */ -#define EXAMPLE_LOG_EACH 0 -#if EXAMPLE_LOG_EACH +#define parser3_LOG_EACH 0 +#if parser3_LOG_EACH if (s != NULL) { ap_log_error(APLOG_MARK, APLOG_DEBUG, s, "mod_example: %s", note); } @@ -448,24 +448,42 @@ static const char *cmd_example(cmd_parms // service funcs -int read_post(Pool& pool, char *buf, int max_bytes) { - return 0;/* @todo - int read_size=0; - do { - int chunk_size=read - (fileno(stdin), buf+read_size, min(0x400*0x400, max_bytes-read_size)); - if(chunk_size<0) - break; - read_size+=chunk_size; - } while(read_size(pool.info()); + return (const char *)ap_table_get(r->subprocess_env, name); +} - return read_size;*/ +uint read_post(Pool& pool, char *buf, uint max_bytes) { + request_rec *r=static_cast(pool.info()); + +/* ap_log_error(APLOG_MARK, APLOG_DEBUG, r->server, + "mod_parser3: read_post(max=%u)", max_bytes); +*/ + int retval; + if((retval = ap_setup_client_block(r, REQUEST_CHUNKED_ERROR))) + return 0; + if(!ap_should_client_block(r)) + return 0; + + uint total_read_bytes=0; + void (*handler)(int)=signal(SIGPIPE, SIG_IGN); + while (total_read_bytes(pool.info()); - if(strcmp(key, "content-type")==0) { + 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 * "text/plain"). You *must* also ensure that r->content_type is lower @@ -478,12 +496,18 @@ void add_header_attribute(Pool& pool, co void send_header(Pool& pool) { request_rec *r=static_cast(pool.info()); + + ap_hard_timeout("send header", r); ap_send_http_header(r); + ap_kill_timeout(r); } void send_body(Pool& pool, const char *buf, size_t size) { request_rec *r=static_cast(pool.info()); + + ap_hard_timeout("send body", r); ap_rwrite(buf, size, r); + ap_kill_timeout(r); } ///@todo initSocks(); @@ -503,12 +527,11 @@ static int parser3_handler(request_rec * */ r->no_cache=1; - ap_soft_timeout("send example call trace", r); PTRY { // global try const char *filespec_to_process=r->filename; - PTHROW(0, 0, - 0, - "no file to process"); + + ap_add_common_vars(r); + ap_add_cgi_vars(r); // Request info Request::Info request_info; @@ -524,12 +547,15 @@ static int parser3_handler(request_rec * request_info.path_translated=filespec_to_process; request_info.method=r->method; request_info.query_string=r->args; - request_info.uri=r->uri; - request_info.content_type=r->content_type; + 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"); + request_info.cookie= + (const char *)ap_table_get(r->subprocess_env, "HTTP_COOKIE"); // prepare to process request Request request(pool, @@ -548,7 +574,7 @@ static int parser3_handler(request_rec * strcat(sys_auto_path1, PATH_DELIMITER_STRING); #else // ~nobody - sys_auto_path1=getenv("HOME"); + sys_auto_path1=zgetenv("HOME"); #endif // beside by binary @@ -590,7 +616,6 @@ static int parser3_handler(request_rec * // unsuccessful finish } PEND_CATCH - ap_kill_timeout(r); /* * We did what we wanted to do, so tell the rest of the server we @@ -641,21 +666,19 @@ static int parser3_handler(request_rec * */ static void parser3_init(server_rec *s, pool *p) { - - char *sname = s->server_hostname; - static bool globals_inited=false; if(globals_inited) return; globals_inited=true; - static Pool pool; ///< global pool + static Pool pool; // global pool pool.set_storage(p); PTRY { // init global variables globals_init(pool); // Service funcs + service_funcs.get_env=get_env; service_funcs.read_post=read_post; service_funcs.add_header_attribute=add_header_attribute; service_funcs.send_header=send_header; @@ -670,37 +693,6 @@ static void parser3_init(server_rec *s, } /* - * 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); -} - -/* * This function is called when an heavy-weight process (such as a child) is * being run down or destroyed. As with the child-initialisation function, * any information that needs to be recorded must be in static cells, since @@ -712,7 +704,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 parser3_child_exit(server_rec *s, pool *p) { char *note; @@ -723,7 +715,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, "parser3_child_exit(", sname, ")", NULL); trace_add(s, NULL, NULL, note); } @@ -739,7 +731,7 @@ 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 *parser3_create_dir_config(pool *p, char *dirspec) { excfg *cfg; @@ -761,7 +753,7 @@ static void *example_create_dir_config(p */ 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, "parser3_create_dir_config()"); return (void *) cfg; } @@ -780,7 +772,7 @@ 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 *parser3_merge_dir_config(pool *p, void *parent_conf, void *newloc_conf) { @@ -812,7 +804,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, "parser3_merge_dir_config(\"", pconf->loc, "\",\"", nconf->loc, "\")", NULL); trace_add(NULL, NULL, merged_config, note); return (void *) merged_config; @@ -825,14 +817,14 @@ 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 *parser3_create_server_config(pool *p, server_rec *s) { excfg *cfg; char *sname = s->server_hostname; /* - * As with the example_create_dir_config() reoutine, we allocate and fill + * As with the parser3_create_dir_config() reoutine, we allocate and fill * in an empty record. */ cfg = (excfg *) ap_pcalloc(p, sizeof(excfg)); @@ -844,7 +836,7 @@ static void *example_create_server_confi */ 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, "parser3_create_server_config()"); return (void *) cfg; } @@ -861,7 +853,7 @@ 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 *parser3_merge_server_config(pool *p, void *server1_conf, void *server2_conf) { @@ -882,35 +874,13 @@ static void *example_merge_server_config /* * Trace our call, including what we were asked to merge. */ - note = ap_pstrcat(p, "example_merge_server_config(\"", s1conf->loc, "\",\"", + note = ap_pstrcat(p, "parser3_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; -} - -/* * This routine gives our module an opportunity to translate the URI into an * actual filename. If we don't do anything special, the server's default * rules (Alias directives and the like) will continue to be followed. @@ -918,7 +888,7 @@ 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 parser3_translate_handler(request_rec *r) { excfg *cfg; @@ -928,7 +898,7 @@ static int example_translate_handler(req * 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, "parser3_translate_handler()"); return DECLINED; } @@ -941,7 +911,7 @@ 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 parser3_check_user_id(request_rec *r) { excfg *cfg; @@ -950,7 +920,7 @@ static int example_check_user_id(request /* * Don't do anything except log the call. */ - trace_add(r->server, r, cfg, "example_check_user_id()"); + trace_add(r->server, r, cfg, "parser3_check_user_id()"); return DECLINED; } @@ -964,7 +934,7 @@ 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 parser3_auth_checker(request_rec *r) { excfg *cfg; @@ -974,7 +944,7 @@ static int example_auth_checker(request_ * 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, "parser3_auth_checker()"); return DECLINED; } @@ -987,93 +957,33 @@ 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) -{ - - excfg *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) +static int parser3_access_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()"); + trace_add(r->server, r, cfg, "parser3_access_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) +static int parser3_logger(request_rec *r) { excfg *cfg; cfg = our_dconfig(r); - trace_add(r->server, r, cfg, "example_logger()"); + trace_add(r->server, r, cfg, "parser3_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()"); - return DECLINED; -} /*--------------------------------------------------------------------------*/ /* */ @@ -1087,7 +997,7 @@ static int example_header_parser(request /* * List of directives specific to our module. */ -static const command_rec example_cmds[] = +static const command_rec parser3_cmds[] = { { "Example", /* directive name */ @@ -1142,29 +1052,29 @@ module MODULE_VAR_EXPORT parser3_module { STANDARD_MODULE_STUFF, parser3_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 */ + parser3_create_dir_config, /* per-directory config creator */ + parser3_merge_dir_config, /* dir config merger */ + parser3_create_server_config, /* server config creator */ + parser3_merge_server_config, /* server config merger */ + parser3_cmds, /* command table */ parser3_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 */ + parser3_translate_handler, /* [2] filename-to-URI translation */ + parser3_check_user_id, /* [5] check/validate user_id */ + parser3_auth_checker, /* [6] check user_id is valid *here* */ + parser3_access_checker, /* [4] check access by host address */ + 0, /* [7] MIME type checker/setter */ + 0, /* [8] fixups */ + parser3_logger /* [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 */ + ,parser3_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 };