Diff for /parser3/src/targets/cgi/parser3.C between versions 1.91 and 1.105

version 1.91, 2001/05/24 10:17:06 version 1.105, 2001/09/04 15:57:23
Line 1 Line 1
   //3
 /** @file  /** @file
         Parser: scripting and CGI main.          Parser: scripting and CGI main.
   
         Copyright(c) 2001 ArtLebedev Group(http://www.artlebedev.com)          Copyright(c) 2001 ArtLebedev Group(http://www.artlebedev.com)
   
         Author: Alexander Petrosyan <paf@design.ru>(http://design.ru/paf)          Author: Alexander Petrosyan <paf@design.ru>(http://design.ru/paf)
   
         $Id$  
 */  */
   static const char *RCSId="$Id$"; 
   
 #include "pa_config_includes.h"  #include "pa_config_includes.h"
   
Line 61  void SAPI::log(Pool& pool, const char *f Line 61  void SAPI::log(Pool& pool, const char *f
         if(argv0) {          if(argv0) {
                 // beside by binary                  // beside by binary
                 char file_spec[MAX_STRING];                  char file_spec[MAX_STRING];
                 strncpy(file_spec, argv0, MAX_STRING);  // filespec of my binary                  strncpy(file_spec, argv0, MAX_STRING-1);  file_spec[MAX_STRING-1]=0; // filespec of my binary
                 rsplit(file_spec, '/');  rsplit(file_spec, '\\');// strip filename                  rsplit(file_spec, '/');  rsplit(file_spec, '\\');// strip filename
                 strcat(file_spec, "/parser3.log");                  strcat(file_spec, "/parser3.log");
                 f=fopen(file_spec, "at");                  f=fopen(file_spec, "at");
Line 124  void SAPI::send_body(Pool& pool, const v Line 124  void SAPI::send_body(Pool& pool, const v
         stdout_write(buf, size);          stdout_write(buf, size);
 }  }
   
   //
   
   char *full_file_spec(char *file_name) {
           if(!strchr(file_name, '/')) {
                   static char cwd[MAX_STRING];  getcwd(cwd, MAX_STRING);
                   static char buf[MAX_STRING];
                   snprintf(buf, MAX_STRING, "%s/%s", cwd, file_name);
                   return buf;
           }
           return file_name;
   }
   
 /**  /**
         main workhorse          main workhorse
   
Line 137  int main(int argc, char *argv[]) { Line 149  int main(int argc, char *argv[]) {
   
         umask(2);          umask(2);
   
 #ifdef WIN32  
         setmode(fileno(stdin), _O_BINARY);  
         setmode(fileno(stdout), _O_BINARY);  
         setmode(fileno(stderr), _O_BINARY);  
 #endif  
   
         // were we started as CGI?          // were we started as CGI?
         cgi=          cgi=
                 getenv("SERVER_SOFTWARE") ||                   getenv("SERVER_SOFTWARE") || 
Line 163  int main(int argc, char *argv[]) { Line 169  int main(int argc, char *argv[]) {
                 }                  }
         }          }
   
   #ifdef WIN32
           setmode(fileno(stdin), _O_BINARY);
           setmode(fileno(stdout), _O_BINARY);
           setmode(fileno(stderr), _O_BINARY);
   #endif
   
         char *filespec_to_process=cgi?getenv("PATH_TRANSLATED"):argv[1];          char *filespec_to_process=cgi?getenv("PATH_TRANSLATED"):argv[1];
 #ifdef WIN32  #ifdef WIN32
         back_slashes_to_slashes(filespec_to_process);          back_slashes_to_slashes(filespec_to_process);
 #endif  #endif
           filespec_to_process=full_file_spec(filespec_to_process);
   
         const char *request_method=getenv("REQUEST_METHOD");          const char *request_method=getenv("REQUEST_METHOD");
         bool header_only=request_method && strcasecmp(request_method, "HEAD")==0;          bool header_only=request_method && strcasecmp(request_method, "HEAD")==0;
Line 198  int main(int argc, char *argv[]) { Line 211  int main(int argc, char *argv[]) {
                                 // IIS                                  // IIS
                                 size_t len=strlen(filespec_to_process)-strlen(path_info);                                  size_t len=strlen(filespec_to_process)-strlen(path_info);
                                 char *buf=(char *)pool.malloc(len+1);                                  char *buf=(char *)pool.malloc(len+1);
                                 strncpy(buf, filespec_to_process, len);                                  memcpy(buf, filespec_to_process, len); buf[len]=0;
                                 buf[len]=0;  
                                 request_info.document_root=buf;                                  request_info.document_root=buf;
                         } else                          } else
                                 PTHROW(0, 0,                                  PTHROW(0, 0,
Line 207  int main(int argc, char *argv[]) { Line 219  int main(int argc, char *argv[]) {
                                         "CGI: no PATH_INFO defined(in reinventing DOCUMENT_ROOT)");                                          "CGI: no PATH_INFO defined(in reinventing DOCUMENT_ROOT)");
                 } else {                  } else {
                         static char buf[MAX_STRING];                          static char buf[MAX_STRING];
                         strncpy(buf, filespec_to_process, MAX_STRING);                          strncpy(buf, filespec_to_process, MAX_STRING-1); buf[MAX_STRING-1]=0;
                         if(rsplit(buf, '/') || rsplit(buf, '\\')) // strip filename                          if(rsplit(buf, '/') || rsplit(buf, '\\')) // strip filename
                                 request_info.document_root=buf;                                  request_info.document_root=buf;
                         else                          else
Line 261  int main(int argc, char *argv[]) { Line 273  int main(int argc, char *argv[]) {
                         );                          );
                                   
                 // some root-controlled location                  // some root-controlled location
 #ifdef WIN32  #ifdef SYSCONFDIR
                   const char *root_auto_path=SYSCONFDIR;
   #else
   #       ifdef WIN32
                 // c:\windows                  // c:\windows
                 static char root_auto_path[MAX_STRING];                  static char root_auto_path[MAX_STRING];
                 GetWindowsDirectory(root_auto_path, MAX_STRING);                  GetWindowsDirectory(root_auto_path, MAX_STRING);
 #else  #       else
                 // ~nobody  todo: figure out a better place                  #error must be compiled either configure/make or MSVC++
                 const char *root_auto_path=SAPI::get_env(pool, "HOME");  #       endif
 #endif  #endif
                                   
                 // beside by binary                  // beside by binary
                 static char site_auto_path[MAX_STRING];                  static char site_auto_path[MAX_STRING];
                 strncpy(site_auto_path, argv0, MAX_STRING);  // filespec of my binary                  strncpy(site_auto_path, argv0, MAX_STRING-1);  site_auto_path[MAX_STRING-1]=0; // filespec of my binary
                 if(!(                  if(!(
                         rsplit(site_auto_path, '/') ||                           rsplit(site_auto_path, '/') || 
                         rsplit(site_auto_path, '\\'))) { // strip filename                          rsplit(site_auto_path, '\\'))) { // strip filename
Line 298  int main(int argc, char *argv[]) { Line 313  int main(int argc, char *argv[]) {
 #ifdef WIN32  #ifdef WIN32
                 SetUnhandledExceptionFilter(0);                  SetUnhandledExceptionFilter(0);
 #endif  #endif
   
   #ifndef WIN32
                   // 
                   if(!cgi)
                           SAPI::send_body(pool, "\n", 1);
   #endif
   
                 // successful finish                  // successful finish
                 return 0;                  return 0;
         } PCATCH(e) { // global problem           } PCATCH(e) { // global problem 
Line 329  int main(int argc, char *argv[]) { Line 351  int main(int argc, char *argv[]) {
                 if(!header_only)                  if(!header_only)
                         SAPI::send_body(pool, body, content_length);                          SAPI::send_body(pool, body, content_length);
   
   #ifndef WIN32
                   // 
                   if(!cgi)
                           SAPI::send_body(pool, "\n", 1);
   #endif
   
                 // unsuccessful finish                  // unsuccessful finish
                 return 1;                  return 1;
         }          }

Removed from v.1.91  
changed lines
  Added in v.1.105


E-mail: