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

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

E-mail: