--- parser3/src/targets/cgi/parser3.C 2001/03/22 11:19:15 1.30 +++ parser3/src/targets/cgi/parser3.C 2001/03/23 08:47:49 1.35 @@ -5,7 +5,7 @@ Author: Alexander Petrosyan (http://design.ru/paf) - $Id: parser3.C,v 1.30 2001/03/22 11:19:15 paf Exp $ + $Id: parser3.C,v 1.35 2001/03/23 08:47:49 paf Exp $ */ #ifdef HAVE_CONFIG_H @@ -45,15 +45,10 @@ static LONG WINAPI TopLevelExceptionFilt ) { char buf[MAX_STRING]; if(ExceptionInfo && ExceptionInfo->ExceptionRecord) { - struct _EXCEPTION_RECORD *r=ExceptionInfo->ExceptionRecord; - - int printed=0; - printed+=snprintf(buf+printed, MAX_STRING-printed, "Exception 0x%X at 0x%p", - r->ExceptionCode, - r->ExceptionAddress); - for(unsigned int i=0; iNumberParameters; i++) - printed+=snprintf(buf+printed, MAX_STRING-printed, ", 0x%X", - r->ExceptionInformation[i]); + struct _EXCEPTION_RECORD *rr=ExceptionInfo->ExceptionRecord; + snprintf(buf, MAX_STRING, "Exception %#X at %p", + er->ExceptionCode, + er->ExceptionAddress); } else strcpy(buf, "Exception "); @@ -100,9 +95,14 @@ static void add_header_attribute(const c printf("%s: %s\n", key, value); } +/// @todo intelligent cache-control static void send_header(const char *buf, size_t size) { - if(cgi) // header | body delimiter + if(cgi) { + puts("Cache-Control: no-cache"); + + // header | body delimiter puts(""); + } } static void send_body(const char *buf, size_t size) { @@ -122,12 +122,13 @@ static void send_body(const char *buf, s // main int main(int argc, char *argv[]) { - // TODO:umask(2); -//\#ifdef WIN32 + umask(2); + +#ifdef WIN32 setmode(fileno(stdin), _O_BINARY); setmode(fileno(stdout), _O_BINARY); setmode(fileno(stderr), _O_BINARY); -//\#endif +#endif // were we started as CGI? cgi= @@ -149,6 +150,8 @@ int main(int argc, char *argv[]) { fix_slashes(filespec_to_process); //\#endif + const char *request_method=getenv("REQUEST_METHOD"); + bool header_only=request_method && strcasecmp(request_method, "HEAD")==0; PTRY { // global try // must be first in PTRY{}PCATCH #ifdef WIN32 @@ -177,7 +180,7 @@ int main(int argc, char *argv[]) { } request_info.document_root=document_root; request_info.path_translated=filespec_to_process; - request_info.method=getenv("REQUEST_METHOD"); + request_info.method=request_method; request_info.query_string=getenv("QUERY_STRING"); request_info.uri=getenv("REQUEST_URI"); request_info.content_type=getenv("CONTENT_TYPE"); @@ -198,7 +201,6 @@ int main(int argc, char *argv[]) { // c:\windows root_auto_path=(char *)pool.malloc(MAX_STRING); GetWindowsDirectory(root_auto_path, MAX_STRING); - strcat(root_auto_path, "/"); #else // ~nobody root_auto_path=getenv("HOME"); @@ -208,15 +210,12 @@ int main(int argc, char *argv[]) { char *site_auto_path=(char *)pool.malloc(MAX_STRING); strncpy(site_auto_path, argv[0], MAX_STRING); // filespec of my binary rsplit(site_auto_path, '/'); rsplit(site_auto_path, '\\');// strip filename - strcat(site_auto_path, "/"); // process the request - request.core(pool.exception(), + request.core( root_auto_path, false, - site_auto_path, false); - // no actions with request' data past this point - // request.exception not not handled here, but all - // request' data are associated with it's pool=exception + site_auto_path, false, + header_only); // must be last in PTRY{}PCATCH #ifdef WIN32 @@ -230,15 +229,18 @@ int main(int argc, char *argv[]) { const char *body=e.comment(); int content_length=strlen(body); - // header - (*service_funcs.output_header_attribute)("content-type", "text/plain"); + // prepare header + add_header_attribute("content-type", "text/plain"); char content_length_cstr[MAX_NUMBER]; - snprintf(content_length_cstr, MAX_NUMBER, "%d", content_length); - (*service_funcs.output_header_attribute)("content-length", - content_length_cstr); + snprintf(content_length_cstr, MAX_NUMBER, "%lu", content_length); + add_header_attribute("content-length", content_length_cstr); + + // send header + send_header(pool); // body - (*service_funcs.output_body)(body, content_length); + if(!header_only) + send_body(body, content_length); // unsuccessful finish return 1;