Annotation of parser3/src/targets/isapi/parser3isapi.C, revision 1.89

1.29      paf         1: /** @file
                      2:        Parser: IIS extension.
                      3: 
1.87      paf         4:        Copyright (c) 2000,2001-2004 ArtLebedev Group (http://www.artlebedev.com)
1.63      paf         5:        Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.77      paf         6: */
1.29      paf         7: 
1.89    ! paf         8: static const char * const IDENT_PARSER3ISAPI_C="$Date: 2004/03/01 14:27:41 $";
1.29      paf         9: 
1.1       paf        10: #ifndef _MSC_VER
1.10      paf        11: #      error compile ISAPI module with MSVC [no urge for now to make it autoconf-ed (PAF)]
1.1       paf        12: #endif
1.43      parser     13: 
                     14: #include "pa_config_includes.h"
1.1       paf        15: 
1.9       paf        16: #include "pa_sapi.h"
1.1       paf        17: #include "pa_globals.h"
                     18: #include "pa_request.h"
                     19: #include "pa_version.h"
1.24      paf        20: #include "pa_socks.h"
1.1       paf        21: 
1.64      paf        22: #include <windows.h>
                     23: #include <process.h>
                     24: 
                     25: #include <httpext.h>
1.51      parser     26: 
1.1       paf        27: #define MAX_STATUS_LENGTH sizeof("xxxx LONGEST STATUS DESCRIPTION")
1.44      parser     28: 
                     29: // consts
1.1       paf        30: 
1.83      paf        31: const char* IIS51vars[]={
1.73      paf        32:        "APPL_MD_PATH", "APPL_PHYSICAL_PATH",
                     33:        "AUTH_PASSWORD", "AUTH_TYPE", "AUTH_USER",
                     34:        "CERT_COOKIE", "CERT_FLAGS", "CERT_ISSUER", "CERT_KEYSIZE", "CERT_SECRETKEYSIZE",
                     35:        "CERT_SERIALNUMBER", "CERT_SERVER_ISSUER", "CERT_SERVER_SUBJECT", "CERT_SUBJECT",
                     36:        "CONTENT_LENGTH", "CONTENT_TYPE",
                     37:        "LOGON_USER",
                     38:        "HTTPS", "HTTPS_KEYSIZE", "HTTPS_SECRETKEYSIZE", "HTTPS_SERVER_ISSUER", "HTTPS_SERVER_SUBJECT",
                     39:        "INSTANCE_ID",  "INSTANCE_META_PATH",
                     40:        "PATH_INFO",    "PATH_TRANSLATED",
                     41:        "QUERY_STRING",
                     42:        "REMOTE_ADDR", "REMOTE_HOST", "REMOTE_USER", "REQUEST_METHOD",
                     43:        "SCRIPT_NAME",
                     44:        "SERVER_NAME", "SERVER_PORT", "SERVER_PORT_SECURE", "SERVER_PROTOCOL", "SERVER_SOFTWARE",
                     45:        "URL",
                     46: };
                     47: const int IIS51var_count=sizeof(IIS51vars)/sizeof(*IIS51vars);
                     48: 
1.65      paf        49: // globals
                     50: 
                     51: char argv0[MAX_STRING]="";
                     52: 
1.18      paf        53: // SAPI
                     54: 
1.38      parser     55: #ifndef DOXYGEN
                     56: /*
1.18      paf        57:        ISAPI SAPI functions receive this context information. 
1.38      parser     58:        see Pool::set_context
1.18      paf        59: */
1.83      paf        60: class SAPI_Info {
                     61: public:
1.3       paf        62:        LPEXTENSION_CONTROL_BLOCK lpECB;
                     63:        String *header;
                     64:        DWORD http_response_code;
                     65: };
1.38      parser     66: #endif
1.3       paf        67: 
1.26      paf        68: // goes to 'cs-uri-query' log file field. webmaster: switch it ON[default OFF].
1.83      paf        69: void SAPI::log(SAPI_Info& SAPI_info, const char* fmt, ...) {
1.26      paf        70:        va_list args;
                     71:        va_start(args,fmt);
                     72:        char buf[MAX_STRING];
1.83      paf        73:        const char* prefix="PARSER_ERROR:";
1.26      paf        74:        strcpy(buf, prefix);
1.47      parser     75:        char *start=buf+strlen(prefix);
1.51      parser     76:        DWORD size=vsnprintf(start, MAX_STRING-strlen(prefix), fmt, args);
1.47      parser     77:        remove_crlf(start, start+size);
                     78: 
1.83      paf        79:        SAPI_info.lpECB->ServerSupportFunction(SAPI_info.lpECB->ConnID, 
1.26      paf        80:                HSE_APPEND_LOG_PARAMETER, buf, &size, 0);
1.55      parser     81: }
                     82: 
                     83: /// @todo event log
1.85      paf        84: static void abort(const char* fmt, va_list args) {
1.83      paf        85:        if(FILE *log=fopen("c:\\parser3die.log", "at")) {
1.65      paf        86:                vfprintf(log, fmt, args);
                     87:                fclose(log);
                     88:        }
1.81      paf        89:        // exit & try to produce core dump
                     90:        abort();
1.26      paf        91: }
1.83      paf        92: void SAPI::die(const char* fmt, ...) {
                     93:        va_list args;
                     94:        va_start(args, fmt);
1.85      paf        95:        ::abort(fmt, args);
1.83      paf        96:        va_end(args);
                     97: }
1.26      paf        98: 
1.83      paf        99: void SAPI::abort(const char* fmt, ...) {
                    100:        va_list args;
                    101:        va_start(args, fmt);
1.85      paf       102:        ::abort(fmt, args);
1.83      paf       103:        va_end(args);
                    104: }
1.1       paf       105: 
1.83      paf       106: char* SAPI::get_env(SAPI_Info& SAPI_info, const char* name) {
                    107:        char *variable_buf=new(PointerFreeGC) char[MAX_STRING];
1.1       paf       108:        DWORD variable_len = MAX_STRING-1;
                    109: 
1.83      paf       110:        if(SAPI_info.lpECB->GetServerVariable(SAPI_info.lpECB->ConnID, const_cast<char *>(name), 
1.1       paf       111:                variable_buf, &variable_len)) {
1.73      paf       112:                if(*variable_buf) { // saw returning len=1 && *buf=0 :(
                    113:                        variable_buf[variable_len]=0;
                    114:                        return variable_buf;
                    115:                }
1.7       paf       116:        } else if (GetLastError()==ERROR_INSUFFICIENT_BUFFER) {
1.83      paf       117:                variable_buf=new(PointerFreeGC) char[variable_len+1];
1.7       paf       118:                
1.83      paf       119:                if(SAPI_info.lpECB->GetServerVariable(SAPI_info.lpECB->ConnID, const_cast<char *>(name), 
1.7       paf       120:                        variable_buf, &variable_len)) {
1.73      paf       121:                        if(*variable_buf) {
                    122:                                variable_buf[variable_len]=0;
                    123:                                return variable_buf;
                    124:                        }
1.7       paf       125:                }
1.1       paf       126:        }
1.7       paf       127:                
1.1       paf       128:        return 0;
                    129: }
                    130: 
1.83      paf       131: static int grep_char(const char* s, char c) {
1.72      paf       132:        int result=0;
                    133:        if(s) {
                    134:                while(s=strchr(s, c)) {
                    135:                        s++; // skip found c
                    136:                        result++;
                    137:                }
                    138:        }
                    139:        return result;
                    140: }
1.83      paf       141: static const char* mk_env_pair(const char* key, const char* value) {
                    142:        char *result=new(PointerFreeGC) char[strlen(key)+1/*=*/+strlen(value)+1/*0*/];
1.72      paf       143:        strcpy(result, key); strcat(result, "="); strcat(result, value);
                    144:        return result;
                    145: }
1.83      paf       146: const char* const *SAPI::environment(SAPI_Info& info) {
1.72      paf       147:        // we know this buf is writable
1.83      paf       148:        char* all_http_vars=SAPI::get_env(info, "ALL_HTTP");
1.72      paf       149:        const int http_var_count=grep_char(all_http_vars, '\n')+1/*\n for theoretical(never saw) this \0*/;
                    150:        
1.83      paf       151:        const char* *result=new const char*[IIS51var_count+http_var_count+1/*0*/];
                    152:        const char* *cur=result;
1.72      paf       153: 
                    154:        // IIS5.1 vars
                    155:        for(int i=0; i<IIS51var_count; i++) {
1.83      paf       156:                const char* key=IIS51vars[i];
                    157:                if(const char* value=SAPI::get_env(info, key))
                    158:                        *cur++=mk_env_pair(key, value);
1.72      paf       159:        }
                    160: 
                    161:        // HTTP_* vars
                    162:        if(char *s=all_http_vars) {
                    163:                while(char *key=lsplit(&s, '\n'))
                    164:                        if(char *value=lsplit(key, ':'))
1.83      paf       165:                                *cur++=mk_env_pair(key, value);
1.72      paf       166:        }
                    167:        
                    168:        // mark EOE
                    169:        *cur=0; 
                    170: 
                    171:        return result;
                    172: }
                    173: 
1.83      paf       174: size_t SAPI::read_post(SAPI_Info& SAPI_info, char *buf, size_t max_bytes) {
1.1       paf       175:        DWORD read_from_buf=0;
                    176:        DWORD read_from_input=0;
                    177:        DWORD total_read=0;
                    178: 
1.83      paf       179:        read_from_buf=min(SAPI_info.lpECB->cbAvailable, max_bytes);
                    180:        memcpy(buf, SAPI_info.lpECB->lpbData, read_from_buf);
1.1       paf       181:        total_read+=read_from_buf;
                    182: 
                    183:        if(read_from_buf<max_bytes &&
1.83      paf       184:                read_from_buf<SAPI_info.lpECB->cbTotalBytes) {
1.1       paf       185:                DWORD cbRead=0, cbSize;
                    186: 
1.3       paf       187:                read_from_input=min(max_bytes-read_from_buf, 
1.83      paf       188:                        SAPI_info.lpECB->cbTotalBytes-read_from_buf);
1.1       paf       189:                while(cbRead < read_from_input) {
                    190:                        cbSize=read_from_input - cbRead;
1.83      paf       191:                        if(!SAPI_info.lpECB->ReadClient(SAPI_info.lpECB->ConnID, 
1.3       paf       192:                                buf+read_from_buf+cbRead, &cbSize) || 
1.1       paf       193:                                cbSize==0) 
                    194:                                break;
                    195:                        cbRead+=cbSize;
                    196:                }
                    197:                total_read+=cbRead;
                    198:        }
                    199:        return total_read;
                    200: }
                    201: 
1.83      paf       202: void SAPI::add_header_attribute(SAPI_Info& SAPI_info, 
                    203:                                const char* dont_store_key, const char* dont_store_value) {
                    204:        if(strcasecmp(dont_store_key, "location")==0) 
                    205:                SAPI_info.http_response_code=302;
                    206: 
                    207:        if(strcasecmp(dont_store_key, "status")==0) 
                    208:                SAPI_info.http_response_code=atoi(dont_store_value);
                    209:        else
                    210:                (*SAPI_info.header) << pa_strdup(dont_store_key) << ": " << pa_strdup(dont_store_value) << "\r\n";
1.1       paf       211: }
                    212: 
1.23      paf       213: /// @todo intelligent cache-control
1.83      paf       214: void SAPI::send_header(SAPI_Info& SAPI_info) {
1.64      paf       215:        HSE_SEND_HEADER_EX_INFO header_info;
1.1       paf       216: 
                    217:        char status_buf[MAX_STATUS_LENGTH];
1.83      paf       218:        switch(SAPI_info.http_response_code) {
1.1       paf       219:                case 200:
                    220:                        header_info.pszStatus="200 OK";
                    221:                        break;
                    222:                case 302:
                    223:                        header_info.pszStatus="302 Moved Temporarily";
                    224:                        break;
1.8       paf       225:                case 401:// useless untill parser auth mech
1.1       paf       226:                        header_info.pszStatus="401 Authorization Required";
1.8       paf       227:                        break;
1.1       paf       228:                default:
1.3       paf       229:                        snprintf(status_buf, MAX_STATUS_LENGTH, 
1.83      paf       230:                                "%d Undescribed", SAPI_info.http_response_code);
1.1       paf       231:                        header_info.pszStatus=status_buf;
                    232:                        break;
                    233:        }
                    234:        header_info.cchStatus=strlen(header_info.pszStatus);
1.83      paf       235:        *SAPI_info.header << "\r\n"; // ISAPI v<5 did quite well without it
                    236:        header_info.pszHeader=SAPI_info.header->cstr();
                    237:        header_info.cchHeader=SAPI_info.header->length();
1.5       paf       238:        header_info.fKeepConn=true;
1.1       paf       239: 
1.83      paf       240:        SAPI_info.lpECB->dwHttpStatusCode=SAPI_info.http_response_code;
1.1       paf       241: 
1.83      paf       242:        SAPI_info.lpECB->ServerSupportFunction(SAPI_info.lpECB->ConnID, 
1.3       paf       243:                HSE_REQ_SEND_RESPONSE_HEADER_EX, &header_info, NULL, NULL);
1.1       paf       244: }
                    245: 
1.83      paf       246: void SAPI::send_body(SAPI_Info& SAPI_info, const void *buf, size_t size) {
1.1       paf       247:        DWORD num_bytes=size;
1.83      paf       248:        SAPI_info.lpECB->WriteClient(SAPI_info.lpECB->ConnID, 
1.23      paf       249:                const_cast<void *>(buf), &num_bytes, HSE_IO_SYNC);
1.1       paf       250: }
1.16      paf       251: 
1.1       paf       252: 
1.15      paf       253: static bool parser_init() {
1.1       paf       254:        static bool globals_inited=false;
                    255:        if(globals_inited)
1.15      paf       256:                return true;
1.1       paf       257:        globals_inited=true;
                    258: 
1.53      parser    259:        try {
1.27      paf       260:                // init socks
1.89    ! paf       261:                pa_socks_init();
1.1       paf       262:                // init global variables
1.83      paf       263:                pa_globals_init();
1.65      paf       264: 
1.15      paf       265:                // successful finish
                    266:                return true;
1.53      parser    267:        } catch(const Exception& e) { // global problem 
1.85      paf       268:                //const char* body=e.comment();
1.15      paf       269:                
                    270:                // unsuccessful finish
                    271:                return false;
1.1       paf       272:        }
                    273: }
                    274: 
1.89    ! paf       275: static void parser_done() {
        !           276:        // finalize global variables
        !           277:        pa_globals_done();
        !           278: 
        !           279:        // 
        !           280:        pa_socks_done();
        !           281: }
        !           282: 
1.1       paf       283: /// ISAPI //
                    284: BOOL WINAPI GetExtensionVersion(HSE_VERSION_INFO *pVer) {
                    285:        pVer->dwExtensionVersion = HSE_VERSION;
1.36      parser    286:        strncpy(pVer->lpszExtensionDesc, "Parser "PARSER_VERSION, HSE_MAX_EXT_DLL_NAME_LEN-1);
                    287:        pVer->lpszExtensionDesc[HSE_MAX_EXT_DLL_NAME_LEN-1]=0;
1.15      paf       288:        return parser_init();
1.89    ! paf       289: }
        !           290: // dwFlags & HSE_TERM_MUST_UNLOAD means we can't return false
        !           291: BOOL WINAPI TerminateExtension(
        !           292:   DWORD /*dwFlags*/
        !           293: )
        !           294: {
        !           295:        parser_done();
        !           296: 
        !           297:        return TRUE;
1.1       paf       298: }
                    299: 
1.6       paf       300: /** 
                    301:        ISAPI // main workhorse
                    302: 
1.23      paf       303:        @todo 
1.10      paf       304:                IIS: remove trailing default-document[index.html] from $request.uri.
                    305:                to do that we need to consult metabase,
1.12      paf       306:                wich is tested&works but seems slow runtime 
                    307:                and not could-be-quickly-implemented if prepared.
1.37      parser    308:        @test
                    309:                PARSER_VERSION from outside
1.6       paf       310: */
1.53      parser    311: 
1.83      paf       312: void real_parser_handler(SAPI_Info& SAPI_info, bool header_only) {
1.88      paf       313:        // collect garbage from prev request
                    314: #ifndef PA_DEBUG_DISABLE_GC
                    315:        {
                    316:                int saved=GC_dont_gc;
                    317:                GC_dont_gc=0;
                    318:                GC_gcollect();
                    319:                GC_dont_gc=saved;
                    320:        }
                    321: #endif
                    322:        
1.83      paf       323:        SAPI_info.header=new String;
                    324:        LPEXTENSION_CONTROL_BLOCK lpECB=SAPI_info.lpECB;
1.53      parser    325:        
                    326:        // Request info
1.83      paf       327:        Request_info request_info;  memset(&request_info, 0, sizeof(request_info));
1.53      parser    328: 
                    329:        size_t path_translated_buf_size=strlen(lpECB->lpszPathTranslated)+1;
1.83      paf       330:        char *filespec_to_process=pa_strdup(lpECB->lpszPathTranslated, path_translated_buf_size);
1.53      parser    331: #ifdef WIN32
                    332:        back_slashes_to_slashes(filespec_to_process);
                    333: #endif
                    334: 
1.83      paf       335:        if(const char* path_info=SAPI::get_env(SAPI_info, "PATH_INFO")) {
1.53      parser    336:                // IIS
                    337:                size_t len=strlen(filespec_to_process)-strlen(path_info);
1.83      paf       338:                char *buf=new(PointerFreeGC) char[len+1];
1.53      parser    339:                strncpy(buf, filespec_to_process, len); buf[len]=0;
                    340:                request_info.document_root=buf;
                    341:        } else
1.67      paf       342:                throw Exception("parser.runtime",
1.53      parser    343:                        0,
                    344:                        "ISAPI: no PATH_INFO defined (in reinventing DOCUMENT_ROOT)");
                    345: 
                    346:        request_info.path_translated=filespec_to_process;
                    347:        request_info.method=lpECB->lpszMethod;
                    348:        request_info.query_string=lpECB->lpszQueryString;
                    349:        if(lpECB->lpszQueryString && *lpECB->lpszQueryString) {
1.83      paf       350:                char *reconstructed_uri=new(PointerFreeGC) char[
1.53      parser    351:                        strlen(lpECB->lpszPathInfo)+1/*'?'*/+
1.83      paf       352:                        strlen(lpECB->lpszQueryString)+1/*0*/];
1.53      parser    353:                strcpy(reconstructed_uri, lpECB->lpszPathInfo);
                    354:                strcat(reconstructed_uri, "?");
                    355:                strcat(reconstructed_uri, lpECB->lpszQueryString);
                    356:                request_info.uri=reconstructed_uri;
                    357:        } else
                    358:                request_info.uri=lpECB->lpszPathInfo;
                    359:        
                    360:        request_info.content_type=lpECB->lpszContentType;
                    361:        request_info.content_length=lpECB->cbTotalBytes;
1.83      paf       362:        request_info.cookie=SAPI::get_env(SAPI_info, "HTTP_COOKIE");
1.76      paf       363:        request_info.mail_received=false;
1.53      parser    364:        
                    365:        // prepare to process request
1.83      paf       366:        Request request(SAPI_info, 
1.53      parser    367:                request_info,
1.83      paf       368:                String::Language(String::L_HTML|String::L_OPTIMIZE_BIT),
                    369:                true /* status_allowed */);
1.53      parser    370: 
1.65      paf       371:        // beside by binary
1.75      paf       372:        static char beside_binary_path[MAX_STRING];
                    373:        strncpy(beside_binary_path, argv0, MAX_STRING-1);  beside_binary_path[MAX_STRING-1]=0; // filespec of my binary
1.65      paf       374:        if(!(
1.75      paf       375:                rsplit(beside_binary_path, '/') || 
                    376:                rsplit(beside_binary_path, '\\'))) { // strip filename
1.65      paf       377:                // no path, just filename
1.75      paf       378:                beside_binary_path[0]='.'; beside_binary_path[1]=0;
1.65      paf       379:        }       
1.74      paf       380:        char config_filespec[MAX_STRING];
                    381:        snprintf(config_filespec, MAX_STRING, 
1.65      paf       382:                "%s/%s", 
1.75      paf       383:                beside_binary_path, AUTO_FILE_NAME);
1.79      paf       384:        bool fail_on_config_read_problem=entry_exists(config_filespec);
1.65      paf       385: 
1.53      parser    386:        // process the request
                    387:        request.core(
1.79      paf       388:                config_filespec, fail_on_config_read_problem, // /path/to/first/auto.p
1.53      parser    389:                header_only);
                    390: }
                    391: 
1.83      paf       392: void call_real_parser_handler__do_SEH(SAPI_Info& SAPI_info, bool header_only) {
1.54      parser    393: #if _MSC_VER & !defined(_DEBUG)
1.53      parser    394:        LPEXCEPTION_POINTERS system_exception=0;
                    395:        __try {
                    396: #endif
1.83      paf       397:                real_parser_handler(SAPI_info, header_only);
1.53      parser    398:                
1.54      parser    399: #if _MSC_VER & !defined(_DEBUG)
1.53      parser    400:        } __except (
                    401:                (system_exception=GetExceptionInformation()), 
                    402:                EXCEPTION_EXECUTE_HANDLER) {
                    403:                
                    404:                if(system_exception)
                    405:                        if(_EXCEPTION_RECORD *er=system_exception->ExceptionRecord)
1.67      paf       406:                                throw Exception(0,
1.53      parser    407:                                0,
                    408:                                "Exception 0x%08X at 0x%08X", er->ExceptionCode,  er->ExceptionAddress);
                    409:                        else
1.67      paf       410:                                throw Exception(0, 0, "Exception <no exception record>");
1.53      parser    411:                        else
1.67      paf       412:                                throw Exception(0, 0, "Exception <no exception information>");
1.53      parser    413:        }
                    414: #endif
                    415: }
                    416: 
1.83      paf       417: DWORD WINAPI HttpExtensionProc(LPEXTENSION_CONTROL_BLOCK lpECB) {
                    418:        //_asm int 3;
                    419:        SAPI_Info SAPI_info={
1.15      paf       420:                lpECB,
1.83      paf       421:                0, // filling later: so that if there would be error pool would have SAPI_info
1.80      paf       422:                200 // default http_response_code [lpECB->dwHttpStatusCode seems to be always 0, even on 404 redirect to /404.html]
1.15      paf       423:        };
1.71      paf       424: 
1.1       paf       425:        bool header_only=strcasecmp(lpECB->lpszMethod, "HEAD")==0;
1.53      parser    426:        try { // global try
1.83      paf       427:                call_real_parser_handler__do_SEH(SAPI_info, header_only);
1.2       paf       428:                // successful finish
1.53      parser    429:        } catch(const Exception& e) { // global problem
1.12      paf       430:                // don't allocate anything on pool here:
                    431:                //   possible pool' exception not catch-ed now
1.31      paf       432:                        //   and there could be out-of-memory exception
1.83      paf       433:                const char* body=e.comment();
1.16      paf       434:                // log it
1.83      paf       435:                SAPI::log(SAPI_info, "exception in request exception handler: %s", body);
1.16      paf       436: 
                    437:                //
1.1       paf       438:                int content_length=strlen(body);
                    439: 
1.12      paf       440:                // prepare header // not using SAPI func wich allocates on pool
                    441:                char header_buf[MAX_STRING];
                    442:                int header_len=snprintf(header_buf, MAX_STRING,
1.30      paf       443:                        "content-type: text/plain\r\n"
1.86      paf       444:                        "content-length: %u\r\n"
1.69      paf       445: //                     "expires: Fri, 23 Mar 2001 09:32:23 GMT\r\n"
1.30      paf       446:                        "\r\n",
1.12      paf       447:                        content_length);
                    448: 
                    449:                HSE_SEND_HEADER_EX_INFO header_info;
                    450:                header_info.pszStatus="200 OK";
                    451:                header_info.cchStatus=strlen(header_info.pszStatus);
                    452:                header_info.pszHeader=header_buf;
                    453:                header_info.cchHeader=header_len;
                    454:                header_info.fKeepConn=true;
                    455:                
1.1       paf       456:                // send header
1.12      paf       457:                lpECB->dwHttpStatusCode=200;
                    458:                lpECB->ServerSupportFunction(lpECB->ConnID, 
                    459:                        HSE_REQ_SEND_RESPONSE_HEADER_EX, &header_info, NULL, NULL);
1.1       paf       460: 
                    461:                // send body
                    462:                if(!header_only)
1.83      paf       463:                        SAPI::send_body(SAPI_info, body, content_length);
1.1       paf       464: 
                    465:                // unsuccessful finish
                    466:        }
1.65      paf       467: /*
1.83      paf       468:                const char* body="test";
1.65      paf       469: 
                    470:                //
                    471:                int content_length=strlen(body);
                    472: 
                    473:                // prepare header // not using SAPI func wich allocates on pool
                    474:                char header_buf[MAX_STRING];
                    475:                int header_len=snprintf(header_buf, MAX_STRING,
                    476:                        "content-type: text/plain\r\n"
1.86      paf       477:                        "content-length: %u\r\n"
1.65      paf       478:                        "expires: Fri, 23 Mar 2001 09:32:23 GMT\r\n"
                    479:                        "\r\n",
                    480:                        content_length);
                    481:                HSE_SEND_HEADER_EX_INFO header_info;
                    482:                header_info.pszStatus="200 OK";
                    483:                header_info.cchStatus=strlen(header_info.pszStatus);
                    484:                header_info.pszHeader=header_buf;
                    485:                header_info.cchHeader=header_len;
                    486:                header_info.fKeepConn=true;
                    487:                
                    488:        // send header
                    489:                lpECB->dwHttpStatusCode=200;
                    490:                lpECB->ServerSupportFunction(lpECB->ConnID, 
                    491:                        HSE_REQ_SEND_RESPONSE_HEADER_EX, &header_info, NULL, NULL);
                    492: 
                    493:                // send body
                    494:        DWORD num_bytes=content_length;
                    495:        lpECB->WriteClient(lpECB->ConnID, 
                    496:                (void *)body, &num_bytes, HSE_IO_SYNC);
                    497: */
1.71      paf       498:        return HSE_STATUS_SUCCESS_AND_KEEP_CONN;
1.1       paf       499: }
1.65      paf       500: 
                    501: BOOL WINAPI DllMain(
                    502:   HINSTANCE hinstDLL,  // handle to the DLL module
1.85      paf       503:   DWORD /*fdwReason*/,     // reason for calling function
                    504:   LPVOID /*lpvReserved*/   // reserved
1.65      paf       505:   ) {
                    506: 
                    507:        GetModuleFileName(
                    508:          hinstDLL,    // handle to module
                    509:          argv0,  // file name of module
                    510:          sizeof(argv0)         // size of buffer
                    511:        );
                    512: 
                    513:        return TRUE;
                    514: }

E-mail: