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

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

E-mail: