|
|
| version 1.2, 2001/03/13 17:54:14 | version 1.3, 2001/03/13 18:32:48 |
|---|---|
| Line 6 | Line 6 |
| $Id$ | $Id$ |
| */ | */ |
| #include "pa_config.h" | |
| #ifdef WIN32 | |
| # include <windows.h> | |
| # include <io.h> | |
| #endif | |
| #include <stdlib.h> | |
| #include "core.h" | #include "core.h" |
| #include "pa_request.h" | #include "pa_request.h" |
| #include "pa_common.h" | #include "pa_common.h" |
| #ifdef WIN32 | |
| // TODO: LONG WINAPI TopLevelExceptionFilter ( | |
| #endif | |
| int main(int argc, char *argv[]) { | int main(int argc, char *argv[]) { |
| #ifdef WIN32 | |
| _fmode=_O_BINARY; /*sets default for file streams to binary */ | |
| setmode(_fileno(stdin), O_BINARY); /* make the stdio mode be binary */ | |
| setmode(_fileno(stdout), O_BINARY); /* make the stdio mode be binary */ | |
| setmode(_fileno(stderr), O_BINARY); /* make the stdio mode be binary */ | |
| //TODO: SetUnhandledExceptionFilter(&TopLevelExceptionFilter); | |
| //TODO: initSocks(); | |
| #endif | |
| Pool pool; | Pool pool; |
| core(pool); | core(pool); |
| // were we started as CGI? | |
| bool cgi= | bool cgi= |
| getenv("SERVER_SOFTWARE") || | getenv("SERVER_SOFTWARE") || |
| getenv("SERVER_NAME") || | getenv("SERVER_NAME") || |
| Line 21 int main(int argc, char *argv[]) { | Line 45 int main(int argc, char *argv[]) { |
| getenv("REQUEST_METHOD"); | getenv("REQUEST_METHOD"); |
| // TODO: ifdef WIN32 flip \\ to / | // TODO: ifdef WIN32 flip \\ to / |
| char *document_root="Y:/parser3/src/"; | const char *document_root="Y:/parser3/src/"; |
| char *page_filespec="Y:/parser3/src/test.p"; | const char *page_filespec="Y:/parser3/src/test.p"; |
| // request | // request |
| Request request(pool, | Request request(pool, |
| cgi?String::Untaint_lang::HTML_TYPO:String::Untaint_lang::NO, // :) | cgi ? String::Untaint_lang::HTML_TYPO : String::Untaint_lang::NO, |
| document_root, | document_root, |
| page_filespec | page_filespec |
| ); | ); |
| bool error; | bool error; |
| char *result=request.core(error); | // some root-controlled location |
| char *sys_auto_path1; | |
| if(error) | #ifdef WIN32 |
| printf("ERROR: %s", result); | sys_auto_path1=(char *)pool.malloc(MAX_STRING); |
| else | GetWindowsDirectory(sys_auto_path1, MAX_STRING-1/*for \*/); |
| strcat(sys_auto_path1, '\\'); | |
| #else | |
| sys_auto_path1=getenv("HOME"); | |
| #endif | |
| // beside by binary | |
| const char *sys_auto_path2=(char *)pool.malloc(MAX_STRING); | |
| strncpy(sys_auto_path2, argv[0]); // filespec of my binary | |
| rsplit(sys_auto_path2, '\\'); rsplit(sys_auto_path2, '/'); // strip filename | |
| char *result=request.core( | |
| sys_auto_path1, | |
| sys_auto_path2); | |
| if(cgi) { | |
| const char *content_type="text/html"; | |
| printf( | |
| "Content-type: %s\n" | |
| "Content-length: %d\n" | |
| "\n", | |
| content_type, | |
| strlen(result)); | |
| stdout_write(result); | |
| } else | |
| printf("%s", result); | printf("%s", result); |
| return 0; | return 0; |