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

1.1       parser      1: /** @file
                      2:        Parser: apache 1.3 module.
                      3: 
1.16      paf         4:        Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com)
1.17    ! paf         5:        Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.1       parser      6: 
1.17    ! paf         7:        $Id: mod_parser3.C,v 1.16 2002/02/08 07:27:50 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: 
1.15      paf       206: /// @test location provide with protocol. think about internal redirects
1.1       parser    207: void SAPI::add_header_attribute(Pool& pool, const char *key, const char *value) {
1.4       parser    208:        request_rec *r=static_cast<request_rec *>(pool.get_context());
1.1       parser    209: 
                    210:        if(strcasecmp(key, "location")==0) 
                    211:                r->status=302;
                    212: 
                    213:        if(strcasecmp(key, "content-type")==0) {
                    214:                /* r->content_type, *not* r->headers_out("Content-type").  If you don't
                    215:                 * set it, it will be filled in with the server's default type (typically
                    216:                 * "text/plain").  You *must* also ensure that r->content_type is lower
                    217:                 * case.
                    218:                 */
                    219:                r->content_type = value;
                    220:        } else if(strcasecmp(key, "status")==0) 
                    221:                r->status=atoi(value);
                    222:        else
                    223:                ap_table_addn(r->headers_out, key, value);
                    224: }
                    225: 
                    226: void SAPI::send_header(Pool& pool) {
1.4       parser    227:        request_rec *r=static_cast<request_rec *>(pool.get_context());
1.1       parser    228: 
                    229:     ap_hard_timeout("Send header", r);
                    230:     ap_send_http_header(r);
                    231:        ap_kill_timeout(r);
                    232: }
                    233: 
                    234: void SAPI::send_body(Pool& pool, const void *buf, size_t size) {
1.4       parser    235:        request_rec *r=static_cast<request_rec *>(pool.get_context());
1.1       parser    236: 
                    237:     ap_hard_timeout("Send body", r);
                    238:        ap_rwrite(buf, size, r);
                    239:        ap_kill_timeout(r);
                    240: }
                    241: 
                    242: //@}
                    243: 
                    244: /**
                    245:        main workhorse
                    246:        
                    247:        @todo intelligent cache-control
                    248: */
1.3       parser    249: static void real_parser_handler(Pool& pool, request_rec *r) {
                    250:        ap_add_common_vars(r);
                    251:        ap_add_cgi_vars(r);
                    252: 
                    253:        // Request info
                    254:        Request::Info request_info;
                    255:        request_info.document_root=SAPI::get_env(pool, "DOCUMENT_ROOT");
                    256:        request_info.path_translated=r->filename;
                    257:        request_info.method=r->method;
                    258:        request_info.query_string=r->args;
                    259:        request_info.uri=SAPI::get_env(pool, "REQUEST_URI");
                    260:        request_info.content_type=SAPI::get_env(pool, "CONTENT_TYPE");
                    261:        const char *content_length=SAPI::get_env(pool, "CONTENT_LENGTH");
                    262:        request_info.content_length=content_length?atoi(content_length):0;
                    263:        request_info.cookie=SAPI::get_env(pool, "HTTP_COOKIE");
                    264:        request_info.user_agent=SAPI::get_env(pool, "HTTP_USER_AGENT");
                    265: 
1.9       paf       266:     // config
                    267:        Parser_module_config *dcfg=our_dconfig(r);
                    268: 
1.3       parser    269:        //_asm int 3;
                    270:        // prepare to process request
                    271:        Request request(pool,
                    272:                request_info,
1.12      paf       273:                String::UL_HTML|String::UL_OPTIMIZE_BIT,
1.9       paf       274:                dcfg->parser_status_allowed
1.3       parser    275:                );
                    276:        
                    277:        // process the request
                    278:        request.core(
                    279:                dcfg->parser_root_config_filespec, true, // /path/to/admin/config
                    280:                dcfg->parser_site_config_filespec, true, // /path/to/site/config
                    281:                r->header_only!=0);
                    282: }
                    283: 
                    284: void call_real_parser_handler__do_SEH(Pool& pool, request_rec *r) {
1.5       parser    285: #if _MSC_VER & !defined(_DEBUG)
1.3       parser    286:        LPEXCEPTION_POINTERS system_exception=0;
                    287:        __try {
                    288: #endif
                    289:                real_parser_handler(pool, r);
                    290:                
1.5       parser    291: #if _MSC_VER & !defined(_DEBUG)
1.3       parser    292:        } __except (
                    293:                (system_exception=GetExceptionInformation()), 
                    294:                EXCEPTION_EXECUTE_HANDLER) {
                    295:                
                    296:                if(system_exception)
                    297:                        if(_EXCEPTION_RECORD *er=system_exception->ExceptionRecord)
                    298:                                throw Exception(0, 0,
1.5       parser    299:                                        0,
                    300:                                        "Exception 0x%08X at 0x%08X", er->ExceptionCode,  er->ExceptionAddress);
1.3       parser    301:                        else
                    302:                                throw Exception(0, 0, 0, "Exception <no exception record>");
                    303:                        else
                    304:                                throw Exception(0, 0, 0, "Exception <no exception information>");
                    305:        }
                    306: #endif
                    307: }
                    308: 
1.15      paf       309: /// @test r->finfo.st_mode check seems to work only on win32
1.1       parser    310: static int parser_handler(request_rec *r) {
1.6       parser    311:        //_asm int 3;
1.1       parser    312:     if(r->finfo.st_mode == 0) 
                    313:                return NOT_FOUND;
                    314:        
                    315:        Pool pool(r->pool);
                    316:        pool.set_context(r);
                    317: 
1.2       parser    318: #ifdef XML
                    319:        /**
                    320:         * Initialize Xerces and Xalan.
                    321:         *
                    322:         * Should be called only once per process before making
                    323:         * any other API calls.
                    324:         */
                    325:        //_asm int 3;
                    326:        XalanInitialize();
                    327:        pool.register_cleanup(callXalanTerminate, 0);
                    328: #endif
                    329: 
1.1       parser    330:        /* A flag which modules can set, to indicate that the data being
                    331:         * returned is volatile, and clients should be told not to cache it.
                    332:         */
1.14      paf       333: //     r->no_cache=1;
1.1       parser    334: 
1.3       parser    335:        try { // global try
                    336:                call_real_parser_handler__do_SEH(pool, r);
1.1       parser    337:                // successful finish
1.3       parser    338:        } catch(const Exception& e) { // global problem 
1.1       parser    339:                // don't allocate anything on pool here:
                    340:                //   possible pool' exception not catch-ed now
                    341:                //   and there could be out-of-memory exception
                    342:                const char *body=e.comment();
                    343:                // log it
                    344:                SAPI::log(pool, "exception in request exception handler: %s", body);
                    345: 
                    346:                //
                    347:                int content_length=strlen(body);
                    348: 
                    349:                // prepare header
                    350:                SAPI::add_header_attribute(pool, "content-type", "text/plain");
                    351:                char content_length_cstr[MAX_NUMBER];
                    352:                snprintf(content_length_cstr, MAX_NUMBER, "%u", content_length);
                    353:                SAPI::add_header_attribute(pool, "content-length", content_length_cstr);
                    354: 
                    355:                // send header
                    356:                SAPI::send_header(pool);
                    357: 
                    358:                // send body
                    359:                if(!r->header_only)
                    360:                        SAPI::send_body(pool, body, content_length);
                    361: 
                    362:                // unsuccessful finish
                    363:        }
                    364: 
                    365:     /*
                    366:      * We did what we wanted to do, so tell the rest of the server we
                    367:      * succeeded.
                    368:      */
                    369:     return OK;
                    370: }
                    371: 
1.11      paf       372: #if _MSC_VER
1.10      paf       373: int failed_new(size_t size) {
                    374:        SAPI::die("out of memory in 'new', failed to allocated %u bytes", size);
                    375:        return 0; // not reached
                    376: }
                    377: #endif
                    378: 
                    379: #ifdef HAVE_SET_NEW_HANDLER
                    380: void failed_new() {
                    381:     SAPI::die("out of memory in 'new'");
                    382: }
                    383: #endif
                    384: 
1.1       parser    385: /*--------------------------------------------------------------------------*/
                    386: /*                                                                          */
                    387: /* Now let's declare routines for each of the callback phase in order.      */
                    388: /* (That's the order in which they're listed in the callback list, *not     */
                    389: /* the order in which the server calls them!  See the command_rec           */
                    390: /* declaration near the bottom of this file.)  Note that these may be       */
                    391: /* called for situations that don't relate primarily to our function - in   */
                    392: /* other words, the fixup handler shouldn't assume that the request has     */
                    393: /* to do with "example" stuff.                                              */
                    394: /*                                                                          */
                    395: /* With the exception of the content handler, all of our routines will be   */
                    396: /* called for each request, unless an earlier handler from another module   */
                    397: /* aborted the sequence.                                                    */
                    398: /*                                                                          */
                    399: /* Handlers that are declared as "int" can return the following:            */
                    400: /*                                                                          */
                    401: /*  OK          Handler accepted the request and did its thing with it.     */
                    402: /*  DECLINED    Handler took no action.                                     */
                    403: /*  HTTP_mumble Handler looked at request and found it wanting.             */
                    404: /*                                                                          */
                    405: /* What the server does after calling a module handler depends upon the     */
                    406: /* handler's return value.  In all cases, if the handler returns            */
                    407: /* DECLINED, the server will continue to the next module with an handler    */
                    408: /* for the current phase.  However, if the handler return a non-OK,         */
                    409: /* non-DECLINED status, the server aborts the request right there.  If      */
                    410: /* the handler returns OK, the server's next action is phase-specific;      */
                    411: /* see the individual handler comments below for details.                   */
                    412: /*                                                                          */
                    413: /*--------------------------------------------------------------------------*/
                    414: /* 
                    415:  * This function is called during server initialisation.  Any information
                    416:  * that needs to be recorded must be in static cells, since there's no
                    417:  * configuration record.
                    418:  *
                    419:  * There is no return value.
                    420:  */
                    421: 
                    422: static void setup_module_cells() {
                    423:        static bool  globals_inited=false;
                    424:        if(globals_inited)
                    425:                return;
                    426:        globals_inited=true;
1.10      paf       427: 
                    428: #ifdef WIN32
                    429:        _set_new_handler(failed_new);
                    430: #endif
                    431: 
                    432: #ifdef HAVE_SET_NEW_HANDLER
                    433:        std::set_new_handler(failed_new);
                    434: #endif
1.1       parser    435: 
                    436:        /*
                    437:      * allocate our module-private pool.
                    438:      */
                    439:        static Pool pool(ap_make_sub_pool(NULL)); // global pool
1.3       parser    440:        /// no trying to __try here [yet]
                    441:        try {
1.1       parser    442:                // init socks
                    443:                init_socks(pool);
1.2       parser    444: 
                    445: #ifdef XML
                    446:                /**
                    447:                * Initialize Xerces and Xalan.
                    448:                *
                    449:                * Should be called only once per process before making
                    450:                * any other API calls.
                    451:                */
                    452:                XalanInitialize();
                    453:                pool.register_cleanup(callXalanTerminate, 0);
                    454: #endif
1.1       parser    455: 
                    456:                // init global classes
                    457:                init_methoded_array(pool);
                    458:                // init global variables
                    459:                pa_globals_init(pool);
1.3       parser    460:        } catch(const Exception& e) { // global problem 
1.7       parser    461:                SAPI::die("setup_module_cells failed: %s", e.comment());
1.1       parser    462:        }
                    463: }
                    464: 
                    465: static void parser_server_init(server_rec *s, pool *p) {
                    466: #if MODULE_MAGIC_NUMBER >= 19980527
                    467:        ap_add_version_component("Parser/"PARSER_VERSION);
                    468: #endif 
                    469: 
                    470:     /*
                    471:      * Set up any module cells that ought to be initialised.
                    472:      */
                    473:     setup_module_cells();
                    474: }
                    475: 
                    476: /*
                    477:  * This function gets called to create a per-directory configuration
                    478:  * record.  This will be called for the "default" server environment, and for
                    479:  * each directory for which the parser finds any of our directives applicable.
                    480:  * If a directory doesn't have any of our directives involved (i.e., they
                    481:  * aren't in the .htaccess file, or a <Location>, <Directory>, or related
                    482:  * block), this routine will *not* be called - the configuration for the
                    483:  * closest ancestor is used.
                    484:  *
                    485:  * The return value is a pointer to the created module-specific
                    486:  * structure.
                    487:  */
                    488: static void *parser_create_dir_config(pool *p, char *dirspec) {
1.13      paf       489:        //_asm int 3;
1.1       parser    490:        /*
                    491:      * Allocate the space for our record from the pool supplied.
                    492:      */
                    493:     Parser_module_config *cfg=
                    494:                (Parser_module_config *) ap_pcalloc(p, sizeof(Parser_module_config));
                    495:     /*
                    496:      * Now fill in the defaults.  If there are any `parent' configuration
                    497:      * records, they'll get merged as part of a separate callback.
                    498:      */
1.9       paf       499: 
1.1       parser    500:     return (void *) cfg;
                    501: }
                    502: 
                    503: /*
                    504:  * This function gets called to merge two per-directory configuration
                    505:  * records.  This is typically done to cope with things like .htaccess files
                    506:  * or <Location> directives for directories that are beneath one for which a
                    507:  * configuration record was already created.  The routine has the
                    508:  * responsibility of creating a new record and merging the contents of the
                    509:  * other two into it appropriately.  If the module doesn't declare a merge
                    510:  * routine, the record for the closest ancestor location (that has one) is
                    511:  * used exclusively.
                    512:  *
                    513:  * The routine MUST NOT modify any of its arguments!
                    514:  *
                    515:  * The return value is a pointer to the created module-specific structure
                    516:  * containing the merged values.
1.13      paf       517: 
                    518:    20011126 paf: noticed, that this is called even on virtual root merge with something "parent",
                    519:    while thought that that is part of merge_server...
                    520: 
1.1       parser    521:  */
                    522: static void *parser_merge_dir_config(pool *p, void *parent_conf,
                    523:                                       void *newloc_conf) {
1.13      paf       524:        //_asm int 3;
1.1       parser    525:     Parser_module_config *merged_config = 
                    526:                (Parser_module_config *) ap_pcalloc(p, sizeof(Parser_module_config));
                    527:     Parser_module_config *pconf = (Parser_module_config *) parent_conf;
                    528:     Parser_module_config *nconf = (Parser_module_config *) newloc_conf;
                    529: 
1.13      paf       530:     merged_config->parser_root_config_filespec = ap_pstrdup(p, nconf->parser_root_config_filespec?
                    531:                nconf->parser_root_config_filespec:pconf->parser_root_config_filespec);
                    532:     merged_config->parser_site_config_filespec = ap_pstrdup(p, nconf->parser_site_config_filespec?
                    533:                nconf->parser_site_config_filespec:pconf->parser_site_config_filespec);
1.9       paf       534:        merged_config->parser_status_allowed=
                    535:                pconf->parser_status_allowed ||
                    536:                nconf->parser_status_allowed;
1.13      paf       537: 
                    538:        /*
1.1       parser    539:      * Some things get copied directly from the more-specific record, rather
                    540:      * than getting merged.
                    541:      */
                    542: 
                    543:     return (void *) merged_config;
                    544: }
                    545: 
                    546: /*
                    547:  * This function gets called to create a per-server configuration
                    548:  * record.  It will always be called for the "default" server.
                    549:  *
                    550:  * The return value is a pointer to the created module-specific
                    551:  * structure.
                    552:  */
                    553: static void *parser_create_server_config(pool *p, server_rec *s) {
1.13      paf       554:        //_asm int 3;
1.1       parser    555:     /*
1.13      paf       556:      * As with the parser_create_dir_config() routine, we allocate and fill
1.1       parser    557:      * in an empty record.
                    558:      */
                    559:     Parser_module_config *cfg=
                    560:                (Parser_module_config *) ap_pcalloc(p, sizeof(Parser_module_config));
                    561: 
                    562:     return (void *) cfg;
                    563: }
                    564: 
                    565: /*
                    566:  * This function gets called to merge two per-server configuration
                    567:  * records.  This is typically done to cope with things like virtual hosts and
                    568:  * the default server configuration  The routine has the responsibility of
                    569:  * creating a new record and merging the contents of the other two into it
                    570:  * appropriately.  If the module doesn't declare a merge routine, the more
                    571:  * specific existing record is used exclusively.
                    572:  *
                    573:  * The routine MUST NOT modify any of its arguments!
                    574:  *
                    575:  * The return value is a pointer to the created module-specific structure
                    576:  * containing the merged values.
                    577:  */
                    578: static void *parser_merge_server_config(pool *p, void *server1_conf,
                    579:                                          void *server2_conf)
                    580: {
1.13      paf       581:        //_asm int 3;
1.1       parser    582: 
                    583:     Parser_module_config *merged_config = 
                    584:                (Parser_module_config *) ap_pcalloc(p, sizeof(Parser_module_config));
                    585:     Parser_module_config *s1conf = (Parser_module_config *) server1_conf;
                    586:     Parser_module_config *s2conf = (Parser_module_config *) server2_conf;
                    587: 
                    588:     /*
                    589:      * Our inheritance rules are our own, and part of our module's semantics.
                    590:      * Basically, just note whence we came.
                    591:      */
                    592:     merged_config->parser_root_config_filespec = ap_pstrdup(p, s2conf->parser_root_config_filespec?
                    593:                s2conf->parser_root_config_filespec:s1conf->parser_root_config_filespec);
                    594:     merged_config->parser_site_config_filespec = ap_pstrdup(p, s2conf->parser_site_config_filespec?
                    595:                s2conf->parser_site_config_filespec:s1conf->parser_site_config_filespec);
1.9       paf       596:        merged_config->parser_status_allowed=
                    597:                s1conf->parser_status_allowed || 
                    598:                s2conf->parser_status_allowed;
1.1       parser    599:  
                    600:        return (void *) merged_config;
                    601: }
                    602: 
                    603: /*
                    604:  * This routine gives our module an opportunity to translate the URI into an
                    605:  * actual filename.  If we don't do anything special, the server's default
                    606:  * rules (Alias directives and the like) will continue to be followed.
                    607:  *
                    608:  * The return value is OK, DECLINED, or HTTP_mumble.  If we return OK, no
                    609:  * further modules are called for this phase.
                    610:  */
                    611: static int parser_translate_handler(request_rec *r) {
                    612:     Parser_module_config *cfg=our_dconfig(r);
                    613:     return DECLINED;
                    614: }
                    615: 
                    616: /*
                    617:  * This routine is called to check the authentication information sent with
                    618:  * the request (such as looking up the user in a database and verifying that
                    619:  * the [encrypted] password sent matches the one in the database).
                    620:  *
                    621:  * The return value is OK, DECLINED, or some HTTP_mumble error (typically
                    622:  * HTTP_UNAUTHORIZED).  If we return OK, no other modules are given a chance
                    623:  * at the request during this phase.
                    624:  */
                    625: static int parser_check_user_id(request_rec *r) {
                    626:     Parser_module_config *cfg=our_dconfig(r);
                    627:     return DECLINED;
                    628: }
                    629: 
                    630: /*
                    631:  * This routine is called to check to see if the resource being requested
                    632:  * requires authorisation.
                    633:  *
                    634:  * The return value is OK, DECLINED, or HTTP_mumble.  If we return OK, no
                    635:  * other modules are called during this phase.
                    636:  *
                    637:  * If *all* modules return DECLINED, the request is aborted with a server
                    638:  * error.
                    639:  */
                    640: static int parser_auth_checker(request_rec *r) {
                    641:     Parser_module_config *cfg=our_dconfig(r);
                    642:     return DECLINED;
                    643: }
                    644: 
                    645: /*
                    646:  * This routine is called to check for any module-specific restrictions placed
                    647:  * upon the requested resource.  (See the mod_access module for an example.)
                    648:  *
                    649:  * The return value is OK, DECLINED, or HTTP_mumble.  All modules with an
                    650:  * handler for this phase are called regardless of whether their predecessors
                    651:  * return OK or DECLINED.  The first one to return any other status, however,
                    652:  * will abort the sequence (and the request) as usual.
                    653:  */
                    654: static int parser_access_checker(request_rec *r) {
                    655: 
                    656:     Parser_module_config *cfg=our_dconfig(r);
                    657:     return DECLINED;
                    658: }
                    659: 
                    660: /*--------------------------------------------------------------------------*/
                    661: /*                                                                          */
                    662: /* All of the routines have been declared now.  Here's the list of          */
                    663: /* directives specific to our module, and information about where they      */
                    664: /* may appear and how the command parser should pass them to us for         */
                    665: /* processing.  Note that care must be taken to ensure that there are NO    */
                    666: /* collisions of directive names between modules.                           */
                    667: /*                                                                          */
                    668: /*--------------------------------------------------------------------------*/
                    669: /* 
                    670:  * List of directives specific to our module.
                    671:  */
                    672: static const command_rec parser_cmds[] =
                    673: {
                    674:     {
1.9       paf       675:         "ParserRootConfig",              /* directive name */
1.1       parser    676:         (const char *(*)(void))((void *)cmd_parser_config), // config action routine
                    677:         (void*)true,                   /* argument to include in call */
                    678:         (int)(ACCESS_CONF|RSRC_CONF),             /* where available */
                    679:         TAKE1,                /* arguments */
                    680:         "Parser root config filespec (Admin)" // directive description
                    681:     },
                    682:     {
1.9       paf       683:         "ParserSiteConfig",              /* directive name */
1.1       parser    684:         (const char *(*)(void))((void *)cmd_parser_config), // config action routine
                    685:         (void*)false,                   /* argument to include in call */
                    686:         (int)(OR_OPTIONS),             /* where available */
                    687:         TAKE1,                /* arguments */
                    688:         "Parser site config filespec" // directive description
                    689:     },
1.9       paf       690:        {
                    691:                "ParserStatusAllowed",              /* directive name */
                    692:         (const char *(*)(void))((void *)cmd_parser_status_allowed), // config action routine
                    693:         (void*)0,                   /* argument to include in call */
                    694:         (int)(ACCESS_CONF),             /* where available */
                    695:         NO_ARGS,                /* arguments */
                    696:         "Parser status class can be used" // directive description
                    697:        },
1.1       parser    698:     {NULL}
                    699: };
                    700: 
                    701: /*--------------------------------------------------------------------------*/
                    702: /*                                                                          */
                    703: /* Now the list of content handlers available from this module.             */
                    704: /*                                                                          */
                    705: /*--------------------------------------------------------------------------*/
                    706: /* 
                    707:  * List of content handlers our module supplies.  Each handler is defined by
                    708:  * two parts: a name by which it can be referenced (such as by
                    709:  * {Add,Set}Handler), and the actual routine name.  The list is terminated by
                    710:  * a NULL block, since it can be of variable length.
                    711:  *
                    712:  * Note that content-handlers are invoked on a most-specific to least-specific
                    713:  * basis; that is, a handler that is declared for "text/plain" will be
                    714:  * invoked before one that was declared for "text / *".  Note also that
                    715:  * if a content-handler returns anything except DECLINED, no other
                    716:  * content-handlers will be called.
                    717:  */
                    718: static const handler_rec parser_handlers[] =
                    719: {
1.9       paf       720:     {"parser3-handler", parser_handler},
1.1       parser    721:     {NULL}
                    722: };
                    723: 
                    724: /*--------------------------------------------------------------------------*/
                    725: /*                                                                          */
                    726: /* Finally, the list of callback routines and data structures that          */
                    727: /* provide the hooks into our module from the other parts of the server.    */
                    728: /*                                                                          */
                    729: /*--------------------------------------------------------------------------*/
                    730: /* 
                    731:  * Module definition for configuration.  If a particular callback is not
                    732:  * needed, replace its routine name below with the word NULL.
                    733:  *
                    734:  * The number in brackets indicates the order in which the routine is called
                    735:  * during request processing.  Note that not all routines are necessarily
                    736:  * called (such as if a resource doesn't have access restrictions).
                    737:  */
1.9       paf       738: module MODULE_VAR_EXPORT parser3_module =
1.1       parser    739: {
                    740:     STANDARD_MODULE_STUFF,
                    741:     parser_server_init,          /* module initializer */
                    742:     parser_create_dir_config,    /* per-directory config creator */
                    743:     parser_merge_dir_config,     /* dir config merger */
                    744:     parser_create_server_config, /* server config creator */
                    745:     parser_merge_server_config,  /* server config merger */
                    746:     parser_cmds,                 /* command table */
                    747:     parser_handlers,             /* [9] list of handlers */
                    748:     parser_translate_handler,    /* [2] filename-to-URI translation */
                    749:     parser_check_user_id,        /* [5] check/validate user_id */
                    750:     parser_auth_checker,         /* [6] check user_id is valid *here* */
                    751:     parser_access_checker,       /* [4] check access by host address */
                    752:     0,                           /* [7] MIME type checker/setter */
                    753:     0,                           /* [8] fixups */
                    754:     0                            /* [10] logger */
                    755: };
                    756: 
                    757: #if defined(_MSC_VER)
                    758: #      define APACHE_WIN32_SRC "/parser3project/win32apache13/src"
                    759: #      ifdef _DEBUG
                    760: #              pragma comment(lib, APACHE_WIN32_SRC "/CoreD/ApacheCore.lib")
                    761: #      else
                    762: #              pragma comment(lib, APACHE_WIN32_SRC "/CoreR/ApacheCore.lib")
                    763: #      endif
                    764: #endif

E-mail: