Annotation of parser3/src/targets/apache13/mod_parser3.C, revision 1.13

1.1       parser      1: /** @file
                      2:        Parser: apache 1.3 module.
                      3: 
                      4:        Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
1.8       paf         5:        Author: Alexander Petrosyan <paf@design.ru> (http://paf.design.ru)
1.1       parser      6: 
1.13    ! paf         7:        $Id: mod_parser3.C,v 1.12 2001/11/19 12:17:06 paf Exp $
1.1       parser      8: */
                      9: 
                     10: #include "httpd.h"
                     11: #include "http_config.h"
                     12: #include "http_core.h"
                     13: #include "http_log.h"
                     14: #include "http_main.h"
                     15: #include "http_protocol.h"
                     16: #include "util_script.h"
                     17: 
1.10      paf        18: #include "pa_config_includes.h"
                     19: 
1.11      paf        20: #if _MSC_VER
1.10      paf        21: #      include <new.h>
                     22: #endif
                     23: 
1.1       parser     24: #include "pa_sapi.h"
                     25: #include "classes.h"
                     26: #include "pa_common.h"
                     27: #include "pa_globals.h"
                     28: #include "pa_request.h"
                     29: #include "pa_version.h"
                     30: #include "pa_socks.h"
                     31: 
1.2       parser     32: #ifdef XML
                     33: #include <XalanTransformer/XalanCAPI.h>
                     34: #endif
                     35: 
1.1       parser     36: // consts
                     37: 
                     38: extern const char *main_RCSIds[];
                     39: #ifdef USE_SMTP
                     40: extern const char *smtp_RCSIds[];
                     41: #endif
                     42: extern const char *gd_RCSIds[];
                     43: extern const char *classes_RCSIds[];
                     44: extern const char *types_RCSIds[];
                     45: extern const char *ApacheModuleParser3_RCSIds[];
                     46: #ifdef XML
                     47: extern const char *xalan_patched_RCSIds[];
                     48: #endif
                     49: const char **RCSIds[]={
                     50:        main_RCSIds,
                     51: #ifdef USE_SMTP
                     52:        smtp_RCSIds,
                     53: #endif
                     54:        gd_RCSIds,
                     55:        classes_RCSIds,
                     56:        types_RCSIds,
                     57:        ApacheModuleParser3_RCSIds,
                     58: #ifdef XML
                     59:        xalan_patched_RCSIds,
                     60: #endif
                     61:        0
                     62: };
                     63: 
                     64: 
                     65: /// apache parser module configuration [httpd.conf + .htaccess-es]
                     66: struct Parser_module_config {
                     67:     const char* parser_root_config_filespec; ///< filespec of admin's config file
                     68:     const char* parser_site_config_filespec; ///< filespec of site's config file
1.9       paf        69:        bool parser_status_allowed;
1.1       parser     70: };
                     71: 
1.2       parser     72: #ifdef XML
                     73: /**
                     74:  * Terminate Xalan and Xerces.
                     75:  *
                     76:  * Should be called only once per process after deleting all
                     77:  * instances of XalanTransformer.  Once a process has called
                     78:  * this function, it cannot use the API for the remaining
                     79:  * lifetime of the process.
                     80: 
                     81:        
                     82:        this requirement is fullfilled by using Pool::register_cleanup
                     83:  */
                     84: void callXalanTerminate(void *) {
                     85:        //_asm int 3;
                     86:        XalanTerminate();
                     87: }
                     88: #endif
                     89: 
1.1       parser     90: /*
                     91:  * Declare ourselves so the configuration routines can find and know us.
                     92:  * We'll fill it in at the end of the module.
                     93:  */
1.9       paf        94: extern "C" module MODULE_VAR_EXPORT parser3_module;
1.1       parser     95: 
                     96: /*
                     97:  * Locate our directory configuration record for the current request.
                     98:  */
                     99: static Parser_module_config *our_dconfig(request_rec *r) {
                    100:     return (Parser_module_config *) 
1.9       paf       101:                ap_get_module_config(r->per_dir_config, &parser3_module);
1.1       parser    102: }
                    103: 
                    104: static const char *cmd_parser_config(cmd_parms *cmd, void *mconfig, char *file_spec) {
                    105:     Parser_module_config *cfg = (Parser_module_config *) mconfig;
                    106: 
                    107:        // remember assigned filespec into cfg
                    108:        (cmd->info?cfg->parser_root_config_filespec:cfg->parser_site_config_filespec)=file_spec;
                    109: 
                    110:     return NULL;
                    111: }
1.9       paf       112: static const char *cmd_parser_status_allowed(cmd_parms *cmd, void *mconfig, char *file_spec) {
                    113:        //_asm int 3;
                    114:     Parser_module_config *cfg = (Parser_module_config *) mconfig;
                    115: 
                    116:        cfg->parser_status_allowed=true;
                    117: 
                    118:     return NULL;
                    119: }
1.1       parser    120: 
                    121: 
                    122: /*--------------------------------------------------------------------------*/
                    123: /*                                                                          */
                    124: /* Now we declare our content handlers, which are invoked when the server   */
                    125: /* encounters a document which our module is supposed to have a chance to   */
                    126: /* see.  (See mod_mime's SetHandler and AddHandler directives, and the      */
                    127: /* mod_info and mod_status examples, for more details.)                     */
                    128: /*                                                                          */
                    129: /* Since content handlers are dumping data directly into the connexion      */
                    130: /* (using the r*() routines, such as rputs() and rprintf()) without         */
                    131: /* intervention by other parts of the server, they need to make             */
                    132: /* sure any accumulated HTTP headers are sent first.  This is done by       */
                    133: /* calling send_http_header().  Otherwise, no header will be sent at all,   */
                    134: /* and the output sent to the client will actually be HTTP-uncompliant.     */
                    135: /*--------------------------------------------------------------------------*/
                    136: /* 
                    137:  * Sample content handler.  All this does is display the call list that has
                    138:  * been built up so far.
                    139:  *
                    140:  * The return value instructs the caller concerning what happened and what to
                    141:  * do next:
                    142:  *  OK ("we did our thing")
                    143:  *  DECLINED ("this isn't something with which we want to get involved")
                    144:  *  HTTP_mumble ("an error status should be reported")
                    145:  */
                    146: 
                    147: 
                    148: //@{
                    149: /// SAPI func decl
                    150: void SAPI::log(Pool& pool, const char *fmt, ...) {
1.4       parser    151:        request_rec *r=static_cast<request_rec *>(pool.get_context());
1.1       parser    152: 
                    153:     va_list args;
                    154:     va_start(args,fmt);
                    155:        char buf[MAX_STRING];
                    156:        size_t size=vsnprintf(buf, MAX_STRING, fmt, args);
                    157:        remove_crlf(buf, buf+size);
                    158:        ap_log_rerror(0, 0, APLOG_ERR | APLOG_NOERRNO, r, "%s", buf);
                    159:     va_end(args);
                    160: }
                    161: 
1.7       parser    162: void SAPI::die(const char *fmt, ...) {
                    163:     va_list args;
                    164:     va_start(args,fmt);
                    165:        char buf[MAX_STRING];
                    166:        size_t size=vsnprintf(buf, MAX_STRING, fmt, args);
                    167:        remove_crlf(buf, buf+size);
                    168:        ap_log_error(APLOG_MARK, APLOG_EMERG, 0, "%s", buf);
                    169:     va_end(args);
                    170: 
                    171:        exit(1);
                    172: }
                    173: 
1.1       parser    174: const char *SAPI::get_env(Pool& pool, const char *name) {
1.4       parser    175:        request_rec *r=static_cast<request_rec *>(pool.get_context());
1.1       parser    176:        return (const char *)ap_table_get(r->subprocess_env, name);
                    177: }
                    178: 
                    179: size_t SAPI::read_post(Pool& pool, char *buf, size_t max_bytes) {
1.4       parser    180:        request_rec *r=static_cast<request_rec *>(pool.get_context());
1.1       parser    181: 
                    182: /*    ap_log_error(APLOG_MARK, APLOG_DEBUG, r->server, 
                    183:                "mod_parser3: SAPI::read_post(max=%u)", max_bytes);
                    184: */
                    185:        int retval;
                    186:     if((retval = ap_setup_client_block(r, REQUEST_CHUNKED_ERROR)))
                    187:                return 0;
                    188:        if(!ap_should_client_block(r))
                    189:                return 0;
                    190: 
                    191:        uint total_read_bytes=0;
                    192:        void (*handler)(int)=signal(SIGPIPE, SIG_IGN);
                    193:        while (total_read_bytes<max_bytes) {
                    194:                ap_hard_timeout("Read POST information", r); /* start timeout timer */
                    195:                uint read_bytes=
                    196:                        ap_get_client_block(r, buf+total_read_bytes, max_bytes-total_read_bytes);
                    197:                ap_reset_timeout(r);
                    198:                if (read_bytes<=0)
                    199:                        break;
                    200:                total_read_bytes+=read_bytes;
                    201:        }
                    202:        signal(SIGPIPE, handler);       
                    203:        return total_read_bytes;
                    204: }
                    205: 
                    206: void SAPI::add_header_attribute(Pool& pool, const char *key, const char *value) {
1.4       parser    207:        request_rec *r=static_cast<request_rec *>(pool.get_context());
1.1       parser    208: 
                    209:        if(strcasecmp(key, "location")==0) 
                    210:                r->status=302;
                    211: 
                    212:        if(strcasecmp(key, "content-type")==0) {
                    213:                /* r->content_type, *not* r->headers_out("Content-type").  If you don't
                    214:                 * set it, it will be filled in with the server's default type (typically
                    215:                 * "text/plain").  You *must* also ensure that r->content_type is lower
                    216:                 * case.
                    217:                 */
                    218:                r->content_type = value;
                    219:        } else if(strcasecmp(key, "status")==0) 
                    220:                r->status=atoi(value);
                    221:        else
                    222:                ap_table_addn(r->headers_out, key, value);
                    223: }
                    224: 
                    225: void SAPI::send_header(Pool& pool) {
1.4       parser    226:        request_rec *r=static_cast<request_rec *>(pool.get_context());
1.1       parser    227: 
                    228:     ap_hard_timeout("Send header", r);
                    229:     ap_send_http_header(r);
                    230:        ap_kill_timeout(r);
                    231: }
                    232: 
                    233: void SAPI::send_body(Pool& pool, const void *buf, size_t size) {
1.4       parser    234:        request_rec *r=static_cast<request_rec *>(pool.get_context());
1.1       parser    235: 
                    236:     ap_hard_timeout("Send body", r);
                    237:        ap_rwrite(buf, size, r);
                    238:        ap_kill_timeout(r);
                    239: }
                    240: 
                    241: //@}
                    242: 
                    243: /**
                    244:        main workhorse
                    245:        
                    246:        @todo intelligent cache-control
                    247: */
1.3       parser    248: static void real_parser_handler(Pool& pool, request_rec *r) {
                    249:        ap_add_common_vars(r);
                    250:        ap_add_cgi_vars(r);
                    251: 
                    252:        // Request info
                    253:        Request::Info request_info;
                    254:        request_info.document_root=SAPI::get_env(pool, "DOCUMENT_ROOT");
                    255:        request_info.path_translated=r->filename;
                    256:        request_info.method=r->method;
                    257:        request_info.query_string=r->args;
                    258:        request_info.uri=SAPI::get_env(pool, "REQUEST_URI");
                    259:        request_info.content_type=SAPI::get_env(pool, "CONTENT_TYPE");
                    260:        const char *content_length=SAPI::get_env(pool, "CONTENT_LENGTH");
                    261:        request_info.content_length=content_length?atoi(content_length):0;
                    262:        request_info.cookie=SAPI::get_env(pool, "HTTP_COOKIE");
                    263:        request_info.user_agent=SAPI::get_env(pool, "HTTP_USER_AGENT");
                    264: 
1.9       paf       265:     // config
                    266:        Parser_module_config *dcfg=our_dconfig(r);
                    267: 
1.3       parser    268:        //_asm int 3;
                    269:        // prepare to process request
                    270:        Request request(pool,
                    271:                request_info,
1.12      paf       272:                String::UL_HTML|String::UL_OPTIMIZE_BIT,
1.9       paf       273:                dcfg->parser_status_allowed
1.3       parser    274:                );
                    275:        
                    276:        // process the request
                    277:        request.core(
                    278:                dcfg->parser_root_config_filespec, true, // /path/to/admin/config
                    279:                dcfg->parser_site_config_filespec, true, // /path/to/site/config
                    280:                r->header_only!=0);
                    281: }
                    282: 
                    283: void call_real_parser_handler__do_SEH(Pool& pool, request_rec *r) {
1.5       parser    284: #if _MSC_VER & !defined(_DEBUG)
1.3       parser    285:        LPEXCEPTION_POINTERS system_exception=0;
                    286:        __try {
                    287: #endif
                    288:                real_parser_handler(pool, r);
                    289:                
1.5       parser    290: #if _MSC_VER & !defined(_DEBUG)
1.3       parser    291:        } __except (
                    292:                (system_exception=GetExceptionInformation()), 
                    293:                EXCEPTION_EXECUTE_HANDLER) {
                    294:                
                    295:                if(system_exception)
                    296:                        if(_EXCEPTION_RECORD *er=system_exception->ExceptionRecord)
                    297:                                throw Exception(0, 0,
1.5       parser    298:                                        0,
                    299:                                        "Exception 0x%08X at 0x%08X", er->ExceptionCode,  er->ExceptionAddress);
1.3       parser    300:                        else
                    301:                                throw Exception(0, 0, 0, "Exception <no exception record>");
                    302:                        else
                    303:                                throw Exception(0, 0, 0, "Exception <no exception information>");
                    304:        }
                    305: #endif
                    306: }
                    307: 
1.1       parser    308: static int parser_handler(request_rec *r) {
1.6       parser    309:        //_asm int 3;
1.1       parser    310:     if(r->finfo.st_mode == 0) 
                    311:                return NOT_FOUND;
                    312:        
                    313:        Pool pool(r->pool);
                    314:        pool.set_context(r);
                    315: 
1.2       parser    316: #ifdef XML
                    317:        /**
                    318:         * Initialize Xerces and Xalan.
                    319:         *
                    320:         * Should be called only once per process before making
                    321:         * any other API calls.
                    322:         */
                    323:        //_asm int 3;
                    324:        XalanInitialize();
                    325:        pool.register_cleanup(callXalanTerminate, 0);
                    326: #endif
                    327: 
1.1       parser    328:        /* A flag which modules can set, to indicate that the data being
                    329:         * returned is volatile, and clients should be told not to cache it.
                    330:         */
                    331:        r->no_cache=1;
                    332: 
1.3       parser    333:        try { // global try
                    334:                call_real_parser_handler__do_SEH(pool, r);
1.1       parser    335:                // successful finish
1.3       parser    336:        } catch(const Exception& e) { // global problem 
1.1       parser    337:                // don't allocate anything on pool here:
                    338:                //   possible pool' exception not catch-ed now
                    339:                //   and there could be out-of-memory exception
                    340:                const char *body=e.comment();
                    341:                // log it
                    342:                SAPI::log(pool, "exception in request exception handler: %s", body);
                    343: 
                    344:                //
                    345:                int content_length=strlen(body);
                    346: 
                    347:                // prepare header
                    348:                SAPI::add_header_attribute(pool, "content-type", "text/plain");
                    349:                char content_length_cstr[MAX_NUMBER];
                    350:                snprintf(content_length_cstr, MAX_NUMBER, "%u", content_length);
                    351:                SAPI::add_header_attribute(pool, "content-length", content_length_cstr);
                    352: 
                    353:                // send header
                    354:                SAPI::send_header(pool);
                    355: 
                    356:                // send body
                    357:                if(!r->header_only)
                    358:                        SAPI::send_body(pool, body, content_length);
                    359: 
                    360:                // unsuccessful finish
                    361:        }
                    362: 
                    363:     /*
                    364:      * We did what we wanted to do, so tell the rest of the server we
                    365:      * succeeded.
                    366:      */
                    367:     return OK;
                    368: }
                    369: 
1.11      paf       370: #if _MSC_VER
1.10      paf       371: int failed_new(size_t size) {
                    372:        SAPI::die("out of memory in 'new', failed to allocated %u bytes", size);
                    373:        return 0; // not reached
                    374: }
                    375: #endif
                    376: 
                    377: #ifdef HAVE_SET_NEW_HANDLER
                    378: void failed_new() {
                    379:     SAPI::die("out of memory in 'new'");
                    380: }
                    381: #endif
                    382: 
1.1       parser    383: /*--------------------------------------------------------------------------*/
                    384: /*                                                                          */
                    385: /* Now let's declare routines for each of the callback phase in order.      */
                    386: /* (That's the order in which they're listed in the callback list, *not     */
                    387: /* the order in which the server calls them!  See the command_rec           */
                    388: /* declaration near the bottom of this file.)  Note that these may be       */
                    389: /* called for situations that don't relate primarily to our function - in   */
                    390: /* other words, the fixup handler shouldn't assume that the request has     */
                    391: /* to do with "example" stuff.                                              */
                    392: /*                                                                          */
                    393: /* With the exception of the content handler, all of our routines will be   */
                    394: /* called for each request, unless an earlier handler from another module   */
                    395: /* aborted the sequence.                                                    */
                    396: /*                                                                          */
                    397: /* Handlers that are declared as "int" can return the following:            */
                    398: /*                                                                          */
                    399: /*  OK          Handler accepted the request and did its thing with it.     */
                    400: /*  DECLINED    Handler took no action.                                     */
                    401: /*  HTTP_mumble Handler looked at request and found it wanting.             */
                    402: /*                                                                          */
                    403: /* What the server does after calling a module handler depends upon the     */
                    404: /* handler's return value.  In all cases, if the handler returns            */
                    405: /* DECLINED, the server will continue to the next module with an handler    */
                    406: /* for the current phase.  However, if the handler return a non-OK,         */
                    407: /* non-DECLINED status, the server aborts the request right there.  If      */
                    408: /* the handler returns OK, the server's next action is phase-specific;      */
                    409: /* see the individual handler comments below for details.                   */
                    410: /*                                                                          */
                    411: /*--------------------------------------------------------------------------*/
                    412: /* 
                    413:  * This function is called during server initialisation.  Any information
                    414:  * that needs to be recorded must be in static cells, since there's no
                    415:  * configuration record.
                    416:  *
                    417:  * There is no return value.
                    418:  */
                    419: 
                    420: static void setup_module_cells() {
                    421:        static bool  globals_inited=false;
                    422:        if(globals_inited)
                    423:                return;
                    424:        globals_inited=true;
1.10      paf       425: 
                    426: #ifdef WIN32
                    427:        _set_new_handler(failed_new);
                    428: #endif
                    429: 
                    430: #ifdef HAVE_SET_NEW_HANDLER
                    431:        std::set_new_handler(failed_new);
                    432: #endif
1.1       parser    433: 
                    434:        /*
                    435:      * allocate our module-private pool.
                    436:      */
                    437:        static Pool pool(ap_make_sub_pool(NULL)); // global pool
1.3       parser    438:        /// no trying to __try here [yet]
                    439:        try {
1.1       parser    440:                // init socks
                    441:                init_socks(pool);
1.2       parser    442: 
                    443: #ifdef XML
                    444:                /**
                    445:                * Initialize Xerces and Xalan.
                    446:                *
                    447:                * Should be called only once per process before making
                    448:                * any other API calls.
                    449:                */
                    450:                XalanInitialize();
                    451:                pool.register_cleanup(callXalanTerminate, 0);
                    452: #endif
1.1       parser    453: 
                    454:                // init global classes
                    455:                init_methoded_array(pool);
                    456:                // init global variables
                    457:                pa_globals_init(pool);
1.3       parser    458:        } catch(const Exception& e) { // global problem 
1.7       parser    459:                SAPI::die("setup_module_cells failed: %s", e.comment());
1.1       parser    460:        }
                    461: }
                    462: 
                    463: static void parser_server_init(server_rec *s, pool *p) {
                    464: #if MODULE_MAGIC_NUMBER >= 19980527
                    465:        ap_add_version_component("Parser/"PARSER_VERSION);
                    466: #endif 
                    467: 
                    468:     /*
                    469:      * Set up any module cells that ought to be initialised.
                    470:      */
                    471:     setup_module_cells();
                    472: }
                    473: 
                    474: /*
                    475:  * This function gets called to create a per-directory configuration
                    476:  * record.  This will be called for the "default" server environment, and for
                    477:  * each directory for which the parser finds any of our directives applicable.
                    478:  * If a directory doesn't have any of our directives involved (i.e., they
                    479:  * aren't in the .htaccess file, or a <Location>, <Directory>, or related
                    480:  * block), this routine will *not* be called - the configuration for the
                    481:  * closest ancestor is used.
                    482:  *
                    483:  * The return value is a pointer to the created module-specific
                    484:  * structure.
                    485:  */
                    486: static void *parser_create_dir_config(pool *p, char *dirspec) {
1.13    ! paf       487:        //_asm int 3;
1.1       parser    488:        /*
                    489:      * Allocate the space for our record from the pool supplied.
                    490:      */
                    491:     Parser_module_config *cfg=
                    492:                (Parser_module_config *) ap_pcalloc(p, sizeof(Parser_module_config));
                    493:     /*
                    494:      * Now fill in the defaults.  If there are any `parent' configuration
                    495:      * records, they'll get merged as part of a separate callback.
                    496:      */
1.9       paf       497: 
1.1       parser    498:     return (void *) cfg;
                    499: }
                    500: 
                    501: /*
                    502:  * This function gets called to merge two per-directory configuration
                    503:  * records.  This is typically done to cope with things like .htaccess files
                    504:  * or <Location> directives for directories that are beneath one for which a
                    505:  * configuration record was already created.  The routine has the
                    506:  * responsibility of creating a new record and merging the contents of the
                    507:  * other two into it appropriately.  If the module doesn't declare a merge
                    508:  * routine, the record for the closest ancestor location (that has one) is
                    509:  * used exclusively.
                    510:  *
                    511:  * The routine MUST NOT modify any of its arguments!
                    512:  *
                    513:  * The return value is a pointer to the created module-specific structure
                    514:  * containing the merged values.
1.13    ! paf       515: 
        !           516:    20011126 paf: noticed, that this is called even on virtual root merge with something "parent",
        !           517:    while thought that that is part of merge_server...
        !           518: 
1.1       parser    519:  */
                    520: static void *parser_merge_dir_config(pool *p, void *parent_conf,
                    521:                                       void *newloc_conf) {
1.13    ! paf       522:        //_asm int 3;
1.1       parser    523:     Parser_module_config *merged_config = 
                    524:                (Parser_module_config *) ap_pcalloc(p, sizeof(Parser_module_config));
                    525:     Parser_module_config *pconf = (Parser_module_config *) parent_conf;
                    526:     Parser_module_config *nconf = (Parser_module_config *) newloc_conf;
                    527: 
1.13    ! paf       528:     merged_config->parser_root_config_filespec = ap_pstrdup(p, nconf->parser_root_config_filespec?
        !           529:                nconf->parser_root_config_filespec:pconf->parser_root_config_filespec);
        !           530:     merged_config->parser_site_config_filespec = ap_pstrdup(p, nconf->parser_site_config_filespec?
        !           531:                nconf->parser_site_config_filespec:pconf->parser_site_config_filespec);
1.9       paf       532:        merged_config->parser_status_allowed=
                    533:                pconf->parser_status_allowed ||
                    534:                nconf->parser_status_allowed;
1.13    ! paf       535: 
        !           536:        /*
1.1       parser    537:      * Some things get copied directly from the more-specific record, rather
                    538:      * than getting merged.
                    539:      */
                    540: 
                    541:     return (void *) merged_config;
                    542: }
                    543: 
                    544: /*
                    545:  * This function gets called to create a per-server configuration
                    546:  * record.  It will always be called for the "default" server.
                    547:  *
                    548:  * The return value is a pointer to the created module-specific
                    549:  * structure.
                    550:  */
                    551: static void *parser_create_server_config(pool *p, server_rec *s) {
1.13    ! paf       552:        //_asm int 3;
1.1       parser    553:     /*
1.13    ! paf       554:      * As with the parser_create_dir_config() routine, we allocate and fill
1.1       parser    555:      * in an empty record.
                    556:      */
                    557:     Parser_module_config *cfg=
                    558:                (Parser_module_config *) ap_pcalloc(p, sizeof(Parser_module_config));
                    559: 
                    560:     return (void *) cfg;
                    561: }
                    562: 
                    563: /*
                    564:  * This function gets called to merge two per-server configuration
                    565:  * records.  This is typically done to cope with things like virtual hosts and
                    566:  * the default server configuration  The routine has the responsibility of
                    567:  * creating a new record and merging the contents of the other two into it
                    568:  * appropriately.  If the module doesn't declare a merge routine, the more
                    569:  * specific existing record is used exclusively.
                    570:  *
                    571:  * The routine MUST NOT modify any of its arguments!
                    572:  *
                    573:  * The return value is a pointer to the created module-specific structure
                    574:  * containing the merged values.
                    575:  */
                    576: static void *parser_merge_server_config(pool *p, void *server1_conf,
                    577:                                          void *server2_conf)
                    578: {
1.13    ! paf       579:        //_asm int 3;
1.1       parser    580: 
                    581:     Parser_module_config *merged_config = 
                    582:                (Parser_module_config *) ap_pcalloc(p, sizeof(Parser_module_config));
                    583:     Parser_module_config *s1conf = (Parser_module_config *) server1_conf;
                    584:     Parser_module_config *s2conf = (Parser_module_config *) server2_conf;
                    585: 
                    586:     /*
                    587:      * Our inheritance rules are our own, and part of our module's semantics.
                    588:      * Basically, just note whence we came.
                    589:      */
                    590:     merged_config->parser_root_config_filespec = ap_pstrdup(p, s2conf->parser_root_config_filespec?
                    591:                s2conf->parser_root_config_filespec:s1conf->parser_root_config_filespec);
                    592:     merged_config->parser_site_config_filespec = ap_pstrdup(p, s2conf->parser_site_config_filespec?
                    593:                s2conf->parser_site_config_filespec:s1conf->parser_site_config_filespec);
1.9       paf       594:        merged_config->parser_status_allowed=
                    595:                s1conf->parser_status_allowed || 
                    596:                s2conf->parser_status_allowed;
1.1       parser    597:  
                    598:        return (void *) merged_config;
                    599: }
                    600: 
                    601: /*
                    602:  * This routine gives our module an opportunity to translate the URI into an
                    603:  * actual filename.  If we don't do anything special, the server's default
                    604:  * rules (Alias directives and the like) will continue to be followed.
                    605:  *
                    606:  * The return value is OK, DECLINED, or HTTP_mumble.  If we return OK, no
                    607:  * further modules are called for this phase.
                    608:  */
                    609: static int parser_translate_handler(request_rec *r) {
                    610:     Parser_module_config *cfg=our_dconfig(r);
                    611:     return DECLINED;
                    612: }
                    613: 
                    614: /*
                    615:  * This routine is called to check the authentication information sent with
                    616:  * the request (such as looking up the user in a database and verifying that
                    617:  * the [encrypted] password sent matches the one in the database).
                    618:  *
                    619:  * The return value is OK, DECLINED, or some HTTP_mumble error (typically
                    620:  * HTTP_UNAUTHORIZED).  If we return OK, no other modules are given a chance
                    621:  * at the request during this phase.
                    622:  */
                    623: static int parser_check_user_id(request_rec *r) {
                    624:     Parser_module_config *cfg=our_dconfig(r);
                    625:     return DECLINED;
                    626: }
                    627: 
                    628: /*
                    629:  * This routine is called to check to see if the resource being requested
                    630:  * requires authorisation.
                    631:  *
                    632:  * The return value is OK, DECLINED, or HTTP_mumble.  If we return OK, no
                    633:  * other modules are called during this phase.
                    634:  *
                    635:  * If *all* modules return DECLINED, the request is aborted with a server
                    636:  * error.
                    637:  */
                    638: static int parser_auth_checker(request_rec *r) {
                    639:     Parser_module_config *cfg=our_dconfig(r);
                    640:     return DECLINED;
                    641: }
                    642: 
                    643: /*
                    644:  * This routine is called to check for any module-specific restrictions placed
                    645:  * upon the requested resource.  (See the mod_access module for an example.)
                    646:  *
                    647:  * The return value is OK, DECLINED, or HTTP_mumble.  All modules with an
                    648:  * handler for this phase are called regardless of whether their predecessors
                    649:  * return OK or DECLINED.  The first one to return any other status, however,
                    650:  * will abort the sequence (and the request) as usual.
                    651:  */
                    652: static int parser_access_checker(request_rec *r) {
                    653: 
                    654:     Parser_module_config *cfg=our_dconfig(r);
                    655:     return DECLINED;
                    656: }
                    657: 
                    658: /*--------------------------------------------------------------------------*/
                    659: /*                                                                          */
                    660: /* All of the routines have been declared now.  Here's the list of          */
                    661: /* directives specific to our module, and information about where they      */
                    662: /* may appear and how the command parser should pass them to us for         */
                    663: /* processing.  Note that care must be taken to ensure that there are NO    */
                    664: /* collisions of directive names between modules.                           */
                    665: /*                                                                          */
                    666: /*--------------------------------------------------------------------------*/
                    667: /* 
                    668:  * List of directives specific to our module.
                    669:  */
                    670: static const command_rec parser_cmds[] =
                    671: {
                    672:     {
1.9       paf       673:         "ParserRootConfig",              /* directive name */
1.1       parser    674:         (const char *(*)(void))((void *)cmd_parser_config), // config action routine
                    675:         (void*)true,                   /* argument to include in call */
                    676:         (int)(ACCESS_CONF|RSRC_CONF),             /* where available */
                    677:         TAKE1,                /* arguments */
                    678:         "Parser root config filespec (Admin)" // directive description
                    679:     },
                    680:     {
1.9       paf       681:         "ParserSiteConfig",              /* directive name */
1.1       parser    682:         (const char *(*)(void))((void *)cmd_parser_config), // config action routine
                    683:         (void*)false,                   /* argument to include in call */
                    684:         (int)(OR_OPTIONS),             /* where available */
                    685:         TAKE1,                /* arguments */
                    686:         "Parser site config filespec" // directive description
                    687:     },
1.9       paf       688:        {
                    689:                "ParserStatusAllowed",              /* directive name */
                    690:         (const char *(*)(void))((void *)cmd_parser_status_allowed), // config action routine
                    691:         (void*)0,                   /* argument to include in call */
                    692:         (int)(ACCESS_CONF),             /* where available */
                    693:         NO_ARGS,                /* arguments */
                    694:         "Parser status class can be used" // directive description
                    695:        },
1.1       parser    696:     {NULL}
                    697: };
                    698: 
                    699: /*--------------------------------------------------------------------------*/
                    700: /*                                                                          */
                    701: /* Now the list of content handlers available from this module.             */
                    702: /*                                                                          */
                    703: /*--------------------------------------------------------------------------*/
                    704: /* 
                    705:  * List of content handlers our module supplies.  Each handler is defined by
                    706:  * two parts: a name by which it can be referenced (such as by
                    707:  * {Add,Set}Handler), and the actual routine name.  The list is terminated by
                    708:  * a NULL block, since it can be of variable length.
                    709:  *
                    710:  * Note that content-handlers are invoked on a most-specific to least-specific
                    711:  * basis; that is, a handler that is declared for "text/plain" will be
                    712:  * invoked before one that was declared for "text / *".  Note also that
                    713:  * if a content-handler returns anything except DECLINED, no other
                    714:  * content-handlers will be called.
                    715:  */
                    716: static const handler_rec parser_handlers[] =
                    717: {
1.9       paf       718:     {"parser3-handler", parser_handler},
1.1       parser    719:     {NULL}
                    720: };
                    721: 
                    722: /*--------------------------------------------------------------------------*/
                    723: /*                                                                          */
                    724: /* Finally, the list of callback routines and data structures that          */
                    725: /* provide the hooks into our module from the other parts of the server.    */
                    726: /*                                                                          */
                    727: /*--------------------------------------------------------------------------*/
                    728: /* 
                    729:  * Module definition for configuration.  If a particular callback is not
                    730:  * needed, replace its routine name below with the word NULL.
                    731:  *
                    732:  * The number in brackets indicates the order in which the routine is called
                    733:  * during request processing.  Note that not all routines are necessarily
                    734:  * called (such as if a resource doesn't have access restrictions).
                    735:  */
1.9       paf       736: module MODULE_VAR_EXPORT parser3_module =
1.1       parser    737: {
                    738:     STANDARD_MODULE_STUFF,
                    739:     parser_server_init,          /* module initializer */
                    740:     parser_create_dir_config,    /* per-directory config creator */
                    741:     parser_merge_dir_config,     /* dir config merger */
                    742:     parser_create_server_config, /* server config creator */
                    743:     parser_merge_server_config,  /* server config merger */
                    744:     parser_cmds,                 /* command table */
                    745:     parser_handlers,             /* [9] list of handlers */
                    746:     parser_translate_handler,    /* [2] filename-to-URI translation */
                    747:     parser_check_user_id,        /* [5] check/validate user_id */
                    748:     parser_auth_checker,         /* [6] check user_id is valid *here* */
                    749:     parser_access_checker,       /* [4] check access by host address */
                    750:     0,                           /* [7] MIME type checker/setter */
                    751:     0,                           /* [8] fixups */
                    752:     0                            /* [10] logger */
                    753: };
                    754: 
                    755: #if defined(_MSC_VER)
                    756: #      define APACHE_WIN32_SRC "/parser3project/win32apache13/src"
                    757: #      ifdef _DEBUG
                    758: #              pragma comment(lib, APACHE_WIN32_SRC "/CoreD/ApacheCore.lib")
                    759: #      else
                    760: #              pragma comment(lib, APACHE_WIN32_SRC "/CoreR/ApacheCore.lib")
                    761: #      endif
                    762: #endif

E-mail: