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

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

E-mail: