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

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

E-mail: