--- parser3/src/targets/apache/mod_parser3.c 2010/11/22 23:42:09 1.7 +++ parser3/src/targets/apache/mod_parser3.c 2026/04/25 13:38:46 1.26 @@ -1,16 +1,10 @@ /** @file Parser: apache 1.3 and 2.2 module - Copyright (c) 2001-2010 ArtLebedev Group (http://www.artlebedev.com) - Author: Alexandr Petrosian (http://paf.design.ru) + Copyright (c) 2001-2026 Art. Lebedev Studio (https://www.artlebedev.com) + Authors: Konstantin Morshnev , Alexandr Petrosian */ -static const char * const IDENT_MOD_PARSER3_C="$Date: 2010/11/22 23:42:09 $"; - -#ifdef WIN32 -#include -#endif - #include "httpd.h" #include "http_config.h" #include "http_core.h" @@ -21,6 +15,8 @@ static const char * const IDENT_MOD_PARS #include "pa_httpd.h" +volatile const char * IDENT_MOD_PARSER3_C="$Id: mod_parser3.c,v 1.26 2026/04/25 13:38:46 moko Exp $" IDENT_PA_HTTPD_H; + #define PARSER3_HANDLER "parser3-handler" /* @@ -29,6 +25,7 @@ static const char * const IDENT_MOD_PARS #ifdef STANDARD20_MODULE_STUFF #include "apr_strings.h" +#include "ap_mpm.h" #define ap_pcalloc apr_pcalloc #define ap_pstrdup apr_pstrdup @@ -54,6 +51,7 @@ static const char * const IDENT_MOD_PARS #ifdef STANDARD20_MODULE_STUFF module AP_MODULE_DECLARE_DATA parser3_module; +static int is_threaded = 0; #else module MODULE_VAR_EXPORT parser3_module; #endif @@ -65,7 +63,7 @@ static Parser_module_config *our_dconfig return (Parser_module_config *) 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, const char *file_spec) { Parser_module_config *cfg = (Parser_module_config *) mconfig; cfg->parser_config_filespec=file_spec; return NULL; @@ -79,28 +77,42 @@ static int parser_handler(request_rec *r #ifdef STANDARD20_MODULE_STUFF if(strcmp(r->handler, PARSER3_HANDLER)) return DECLINED; + + if(is_threaded){ + const char *message="Parser3 module requires 'a2enmod mpm_prefork'"; + r->status=HTTP_INTERNAL_SERVER_ERROR; + r->content_type="text/plain"; + ap_rwrite(message, strlen(message), r); + return OK; + } #endif - // converting to parser version - pa_request_rec pr={ - r, - r->pool, - r->header_only, - &r->status, - r->method, - r->headers_out, - r->subprocess_env, - &r->content_type, - r->uri, - r->filename, - r->path_info, - r->args, + + // we setup module here to avoid GPF on init with php5-xsl installed + pa_setup_module_cells(); + + { + // converting to parser version + pa_request_rec pr={ + r, + r->pool, + r->header_only, + &r->status, + r->method, + r->headers_out, + r->subprocess_env, + &r->content_type, + r->uri, + r->filename, + r->path_info, + r->args, #ifdef STANDARD20_MODULE_STUFF - r->finfo.filetype == 0 + r->finfo.filetype == 0 #else - r->finfo.st_mode == 0 + r->finfo.st_mode == 0 #endif - }; - return pa_parser_handler(&pr, our_dconfig(r)); + }; + return pa_parser_handler(&pr, our_dconfig(r)); + } } /* @@ -108,12 +120,11 @@ static int parser_handler(request_rec *r */ #ifdef STANDARD20_MODULE_STUFF -static void parser_module_init(apr_pool_t *p, server_rec *s) { +static void parser_child_init(apr_pool_t *p, server_rec *s) { #else static void parser_module_init(server_rec *s, apr_pool_t *p) { #endif - ap_log_perror(APLOG_MARK, APLOG_EMERG, 0, p, "parser inited %d", getpid()); - pa_setup_module_cells(); +// ap_log_perror(APLOG_MARK, APLOG_EMERG, 0, p, "parser inited %d", getpid()); } /* @@ -146,14 +157,7 @@ static void *parser_create_server_config */ static const command_rec parser_cmds[] = { - { - "ParserConfig", /* directive name */ - (const char* (*)(void))((void *)cmd_parser_config), // config action routine - (void*)0, /* argument to include in call */ - (int)(OR_OPTIONS), /* where available */ - TAKE1, /* arguments */ - "Parser config filespec" // directive description - }, + {"ParserConfig", (const char *(*)(cmd_parms *, void *))cmd_parser_config, 0, OR_OPTIONS, TAKE1, "Parser config filespec"}, {NULL} }; @@ -181,9 +185,10 @@ static const handler_rec parser_handlers */ static void parser_register_hooks(apr_pool_t* pool) { -// ap_hook_post_config(parser_server_init, NULL, NULL, APR_HOOK_MIDDLE); + int mpm_query_info; + is_threaded = ap_mpm_query(AP_MPMQ_IS_THREADED, &mpm_query_info) == APR_SUCCESS && mpm_query_info != AP_MPMQ_NOT_SUPPORTED; ap_hook_handler(parser_handler, NULL, NULL, APR_HOOK_MIDDLE); - ap_hook_child_init(parser_module_init, NULL, NULL, APR_HOOK_MIDDLE); + ap_hook_child_init(parser_child_init, NULL, NULL, APR_HOOK_MIDDLE); }; module AP_MODULE_DECLARE_DATA parser3_module = @@ -218,32 +223,19 @@ module MODULE_VAR_EXPORT parser3_module }; #if defined(_MSC_VER) -# define APACHE_WIN32_SRC "../../../../win32/apache13/src" +# define APACHE_WIN32_SRC "../../../../win32/apache22/" # ifdef _DEBUG -# pragma comment(lib, APACHE_WIN32_SRC "/CoreD/ApacheCore.lib") +# pragma comment(lib, APACHE_WIN32_SRC "srclib/apr/Debug/libapr-1.lib") +# pragma comment(lib, APACHE_WIN32_SRC "Debug/libhttpd.lib") # else -# pragma comment(lib, APACHE_WIN32_SRC "/CoreR/ApacheCore.lib") +# pragma comment(lib, APACHE_WIN32_SRC "srclib/apr/Release/libapr-1.lib") +# pragma comment(lib, APACHE_WIN32_SRC "Release/libhttpd.lib") # endif #endif // interface to C++ -#define PA_APLOG_EMERG 0 /* system is unusable */ -#define PA_APLOG_ALERT 1 /* action must be taken immediately */ -#define PA_APLOG_CRIT 2 /* critical conditions */ -#define PA_APLOG_ERR 3 /* error conditions */ -#define PA_APLOG_WARNING 4 /* warning conditions */ -#define PA_APLOG_NOTICE 5 /* normal but significant condition */ -#define PA_APLOG_INFO 6 /* informational */ -#define PA_APLOG_DEBUG 7 /* debug-level messages */ - -#define PA_APLOG_LEVELMASK 7 /* mask off the level value */ - -#define PA_APLOG_NOERRNO (PA_APLOG_LEVELMASK + 1) - -#define PA_APLOG_MARK __FILE__,__LINE__ - void pa_ap_log_rerror(const char *file, int line, int level, const pa_request_rec *s, const char *fmt, ...) { const char* str; va_list l; @@ -251,11 +243,15 @@ void pa_ap_log_rerror(const char *file, str=va_arg(l, const char*); va_end(l); - ap_log_rerror(file, line, level, + ap_log_rerror(file, line, +#if (AP_SERVER_MAJORVERSION_NUMBER == 2) && (AP_SERVER_MINORVERSION_NUMBER >= 4) + APLOG_MODULE_INDEX, +#endif + level, #ifdef STANDARD20_MODULE_STUFF - 0, + 0, #endif - (request_rec*)s->real_request_rec, "%s", str); + (request_rec*)s->real_request_rec, "%s", str); } @@ -266,11 +262,15 @@ void pa_ap_log_error(const char *file, i str=va_arg(l, const char*); va_end(l); - ap_log_error(file, line, level, + ap_log_error(file, line, +#if (AP_SERVER_MAJORVERSION_NUMBER == 2) && (AP_SERVER_MINORVERSION_NUMBER >= 4) + APLOG_MODULE_INDEX, +#endif + level, #ifdef STANDARD20_MODULE_STUFF - 0, + 0, #endif - (server_rec*)s, "%s", str); + (server_rec*)s, "%s", str); } // ap_alloc.h @@ -287,7 +287,7 @@ int pa_ap_table_size(const pa_table *t) } void pa_ap_table_do(int (*comp) (void *, const char *, const char *), void *rec, const pa_table *t, ...) { - ap_table_do(comp, rec, (apr_table_t*)t, 0); + ap_table_do(comp, rec, (apr_table_t*)t, NULL); } char * pa_ap_pstrdup(pa_pool *p, const char *s) { @@ -322,7 +322,7 @@ int pa_ap_rwrite(const void *buf, int nb void pa_ap_hard_timeout(const char *s, pa_request_rec *r) { // Apache 2 uses non-blocking I/O #ifndef STANDARD20_MODULE_STUFF - ap_hard_timeout(s, (request_rec*)r->real_request_rec); + ap_hard_timeout((char *)s, (request_rec*)r->real_request_rec); #endif } void pa_ap_reset_timeout(pa_request_rec *r) { @@ -345,13 +345,12 @@ void pa_ap_add_common_vars(pa_request_re ap_add_common_vars((request_rec*)r->real_request_rec); } -#ifndef WIN32 // signal.h void (*pa_signal (int sig, void (*disp)(int)))(int) { +#ifndef _MSC_VER if(sig==PA_SIGPIPE && disp==PA_SIG_IGN) return signal(SIGPIPE, SIG_IGN); - +#endif return 0; } -#endif