Annotation of parser3/src/targets/cgi/parser3.C, revision 1.3

1.1       paf         1: /*
                      2:        Parser
                      3:        Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
                      4:        Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
                      5: 
1.3     ! paf         6:        $Id: parser3.C,v 1.2 2001/03/13 17:54:14 paf Exp $
1.1       paf         7: */
                      8: 
1.3     ! paf         9: #include "pa_config.h"
        !            10: 
        !            11: #ifdef WIN32
        !            12: #      include <windows.h>
        !            13: #      include <io.h>
        !            14: #endif
        !            15: #include <stdlib.h>
        !            16: 
1.1       paf        17: #include "core.h"
1.2       paf        18: #include "pa_request.h"
                     19: #include "pa_common.h"
1.1       paf        20: 
1.3     ! paf        21: #ifdef WIN32
        !            22: // TODO:  LONG WINAPI TopLevelExceptionFilter (
        !            23: #endif
        !            24: 
1.1       paf        25: int main(int argc, char *argv[]) {
1.3     ! paf        26: #ifdef WIN32
        !            27:        _fmode=_O_BINARY;                       /*sets default for file streams to binary */
        !            28:        setmode(_fileno(stdin), O_BINARY);              /* make the stdio mode be binary */
        !            29:        setmode(_fileno(stdout), O_BINARY);             /* make the stdio mode be binary */
        !            30:        setmode(_fileno(stderr), O_BINARY);             /* make the stdio mode be binary */
        !            31: 
        !            32:        //TODO: SetUnhandledExceptionFilter(&TopLevelExceptionFilter);
        !            33:        //TODO: initSocks();
        !            34: #endif
        !            35: 
        !            36:        
1.2       paf        37:        Pool pool;
                     38:        core(pool);
                     39: 
1.3     ! paf        40:        // were we started as CGI?
1.2       paf        41:        bool cgi=
                     42:                getenv("SERVER_SOFTWARE") || 
                     43:                getenv("SERVER_NAME") || 
                     44:                getenv("GATEWAY_INTERFACE") || 
                     45:                getenv("REQUEST_METHOD");
                     46: 
                     47:        // TODO: ifdef WIN32 flip \\ to /
1.3     ! paf        48:        const char *document_root="Y:/parser3/src/";
        !            49:        const char *page_filespec="Y:/parser3/src/test.p";
1.2       paf        50: 
                     51:        // request
                     52:        Request request(pool,
1.3     ! paf        53:                cgi ? String::Untaint_lang::HTML_TYPO : String::Untaint_lang::NO,
1.2       paf        54:                document_root,
                     55:                page_filespec
                     56:                );
1.3     ! paf        57:        
1.2       paf        58:        bool error;
1.3     ! paf        59:        // some root-controlled location
        !            60:        char *sys_auto_path1;
        !            61: #ifdef WIN32
        !            62:        sys_auto_path1=(char *)pool.malloc(MAX_STRING);
        !            63:        GetWindowsDirectory(sys_auto_path1, MAX_STRING-1/*for \*/);
        !            64:        strcat(sys_auto_path1, '\\');
        !            65: #else
        !            66:        sys_auto_path1=getenv("HOME");
        !            67: #endif
        !            68:        
        !            69:        // beside by binary
        !            70:        const char *sys_auto_path2=(char *)pool.malloc(MAX_STRING);
        !            71:        strncpy(sys_auto_path2, argv[0]);  // filespec of my binary
        !            72:        rsplit(sys_auto_path2, '\\');  rsplit(sys_auto_path2, '/'); // strip filename
        !            73:        
        !            74:        char *result=request.core(
        !            75:                sys_auto_path1, 
        !            76:                sys_auto_path2);
        !            77:        
        !            78:        if(cgi) {
        !            79:                const char *content_type="text/html";
        !            80:                printf(
        !            81:                        "Content-type: %s\n"
        !            82:                        "Content-length: %d\n"
        !            83:                        "\n", 
        !            84:                                content_type,
        !            85:                                strlen(result));
        !            86:                stdout_write(result);
        !            87:        } else
1.2       paf        88:                printf("%s", result);
                     89: 
1.1       paf        90:        return 0;
                     91: }

E-mail: