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

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

E-mail: