--- parser3/src/targets/cgi/parser3.C 2001/04/03 05:23:43 1.52 +++ parser3/src/targets/cgi/parser3.C 2001/04/09 15:49:01 1.61 @@ -5,7 +5,7 @@ Author: Alexander Petrosyan (http://design.ru/paf) - $Id: parser3.C,v 1.52 2001/04/03 05:23:43 paf Exp $ + $Id: parser3.C,v 1.61 2001/04/09 15:49:01 paf Exp $ */ #include "pa_config_includes.h" @@ -24,6 +24,8 @@ #include "pa_common.h" #include "pa_globals.h" #include "pa_request.h" +#include "pa_socks.h" +#include "pa_exec.h" /// IIS refuses to read bigger chunks const size_t READ_POST_CHUNK_SIZE=0x400*0x400; // 1M @@ -53,12 +55,45 @@ static LONG WINAPI TopLevelExceptionFilt #endif // SAPI +// appends to parser3.log located beside my binary +void SAPI::log(Pool& pool, const char *fmt, ...) { + bool opened; + FILE *f=0; + + if(argv0) { + // beside by binary + char file_spec[MAX_STRING]; + strncpy(file_spec, argv0, MAX_STRING); // filespec of my binary + rsplit(file_spec, '/'); rsplit(file_spec, '\\');// strip filename + strcat(file_spec, "/parser3.log"); + f=fopen(file_spec, "at"); + } + opened=f!=0; + if(!opened) + f=stderr; + + // prefix + time_t t=time(0); + const char *stamp=ctime(&t); + fprintf(f, "[%.*s] ", strlen(stamp)-1, stamp); + // message + va_list args; + va_start(args,fmt); + vfprintf(f, fmt, args); + va_end(args); + // newline + fprintf(f, "\n"); + + if(opened) + fclose(f); +} + const char *SAPI::get_env(Pool& pool, const char *name) { return getenv(name); } -uint SAPI::read_post(Pool& pool, char *buf, uint max_bytes) { - uint read_size=0; +size_t SAPI::read_post(Pool& pool, char *buf, size_t max_bytes) { + size_t read_size=0; do { int chunk_size=read(fileno(stdin), buf+read_size, min(READ_POST_CHUNK_SIZE, max_bytes-read_size)); @@ -75,7 +110,7 @@ void SAPI::add_header_attribute(Pool& po printf("%s: %s\n", key, value); } -/// @todo parser4: intelligent cache-control +/// @todo intelligent cache-control void SAPI::send_header(Pool& pool) { if(cgi) { puts("expires: Fri, 23 Mar 2001 09:32:23 GMT"); @@ -85,47 +120,21 @@ void SAPI::send_header(Pool& pool) { } } -void SAPI::send_body(Pool& pool, const char *buf, size_t size) { +void SAPI::send_body(Pool& pool, const void *buf, size_t size) { stdout_write(buf, size); } -// appends to parser3.log located beside my binary -void SAPI::log(Pool& pool, const char *fmt, ...) { - bool opened; - FILE *f=0; - - if(argv0) { - // beside by binary - char file_spec[MAX_STRING]; - strncpy(file_spec, argv0, MAX_STRING); // filespec of my binary - rsplit(file_spec, '/'); rsplit(file_spec, '\\');// strip filename - strcat(file_spec, "/parser3.log"); - f=fopen(file_spec, "at"); - } - opened=f!=0; - if(!opened) - f=stderr; - - // prefix - time_t t=time(0); - const char *stamp=ctime(&t); - fprintf(f, "[%.*s] ", strlen(stamp)-1, stamp); - // message - va_list args; - va_start(args,fmt); - vfprintf(f, fmt, args); - va_end(args); - // newline - fprintf(f, "\n"); - - if(opened) - fclose(f); +int SAPI::execute(const String& file_spec, + const Hash *env, + const Array *argv, + const String& in, String& out, String& err) { + return pa_exec(file_spec, env, argv, in, out, err); } /** main workhorse - @todo parser4: + @todo IIS: remove trailing default-document[index.html] from $request.uri. to do that we need to consult metabase, wich is tested but seems slow. @@ -169,6 +178,9 @@ int main(int argc, char *argv[]) { //TODO: initSocks(); #endif + // + init_socks(pool); + // init global variables pa_globals_init(pool); @@ -233,7 +245,7 @@ int main(int argc, char *argv[]) { // prepare to process request Request request(pool, request_info, - cgi ? String::UL_HTML_TYPO : String::UL_CLEAN + 1||cgi ? String::UL_HTML_TYPO : String::UL_CLEAN ); // some root-controlled location @@ -257,6 +269,9 @@ int main(int argc, char *argv[]) { site_auto_path, false, header_only); + // + done_socks(); + // must be last in PTRY{}PCATCH #ifdef WIN32 SetUnhandledExceptionFilter(0); @@ -282,7 +297,7 @@ int main(int argc, char *argv[]) { // prepare header SAPI::add_header_attribute(pool, "content-type", "text/plain"); char content_length_cstr[MAX_NUMBER]; - snprintf(content_length_cstr, MAX_NUMBER, "%lu", content_length); + snprintf(content_length_cstr, MAX_NUMBER, "%u", content_length); SAPI::add_header_attribute(pool, "content-length", content_length_cstr); // send header