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

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

E-mail: