Index: branches/New_Config_Format-branch/gsdl/src/recpt/cgiwrapper.cpp
===================================================================
--- branches/New_Config_Format-branch/gsdl/src/recpt/cgiwrapper.cpp	(revision 1083)
+++ branches/New_Config_Format-branch/gsdl/src/recpt/cgiwrapper.cpp	(revision 1279)
@@ -28,4 +28,37 @@
 /*
    $Log$
+   Revision 1.22.4.1  2000/07/12 22:21:35  sjboddie
+   merged changes to trunk into New_Config_Format branch
+
+   Revision 1.31  2000/07/12 04:51:05  nzdl
+   added an error message when no "valid" collections are available
+
+   Revision 1.30  2000/07/05 21:49:31  sjboddie
+   Receptionist now caches collection information to avoid making multiple
+   get_collectinfo calls to collection server
+
+   Revision 1.29  2000/06/29 03:57:14  sjboddie
+   Now append to error log (errout.txt) instead of overwriting it each time
+
+   Revision 1.28  2000/06/28 01:30:23  nzdl
+   *** empty log message ***
+
+   Revision 1.27  2000/06/28 01:24:59  sjboddie
+   got "POST" cgi data to work when using fastcgi
+
+   Revision 1.26  2000/05/12 03:09:26  sjboddie
+   minor modifications to get web library compiling under VC++ 6.0
+
+   Revision 1.25  2000/04/14 04:45:19  sjboddie
+   Modified the English of the debug output slightly
+
+   Revision 1.24  2000/04/14 03:10:35  sjboddie
+   tidied up a few issues concerning the new debug info which showed
+   up on windows
+
+   Revision 1.23  2000/04/14 02:52:05  sjboddie
+   tidied up error messaging and set up some debugging info to be output
+   when running library from command line
+
    Revision 1.22  2000/02/21 21:56:46  sjboddie
    gsdlhome now comes from gsdlsite.cfg
@@ -191,75 +224,101 @@
 #endif
 
-
-static void page_errorsitecfg (text_t &errorpage, int mode) {
-  errorpage += "Content-type: text/html\n\n";
-
-  errorpage += "<html>\n";
-  errorpage += "<head>\n";
-  errorpage += "<title>Error</title>\n";
-  errorpage += "</head>\n";
-  errorpage += "<body>\n";
-  errorpage += "<h2>Oops!</h2>\n";
+static void format_error_string (text_t &errorpage, const text_t &errortext, bool debug) {
+
+  errorpage.clear();
+
+  if (debug) {
+    errorpage += "\n";
+    errorpage += "ERROR: " + errortext;
+    errorpage += "\n";
+    
+  } else {
+
+    errorpage += "Content-type: text/html\n\n";
+    
+    errorpage += "<html>\n";
+    errorpage += "<head>\n";
+    errorpage += "<title>Error</title>\n";
+    errorpage += "</head>\n";
+    errorpage += "<body>\n";
+    errorpage += "<h2>Oops!</h2>\n";
+    errorpage += errortext;
+    errorpage += "</body>\n";
+    errorpage += "</html>\n";
+  }
+}
+
+static void page_errorcollect (const text_t &gsdlhome, text_t &errorpage, bool debug) {
+
+  text_t collectdir = filename_cat (gsdlhome, "collect");
+
+  text_t errortext = "No valid collections were found: Check that your collect directory\n";
+  errortext += "(" + collectdir + ") is readable and contains at least one valid collection.\n";
+  errortext += "Note that modelcol is NOT a valid collection.\n";
+  errortext += "If the path to your collect directory is wrong edit the 'gsdlhome' field\n";
+  errortext += "in your gsdlsite.cfg configuration file.\n";
+
+  format_error_string (errorpage, errortext, debug);
+}
+
+static void page_errorsitecfg (text_t &errorpage, bool debug, int mode) {
+
+  text_t errortext;
+
   if (mode == 0) {
-    errorpage += "The gsdlsite.cfg configuration file could not be found. This file\n";
-    errorpage += "should contain configuration information relating to this\n";
-    errorpage += "site's setup.\n";
-    errorpage += "gsdlsite.cfg should reside in the same directory as this executable\n";
+    errortext += "The gsdlsite.cfg configuration file could not be found. This\n";
+    errortext += "file should contain configuration information relating to this\n";
+    errortext += "site's setup.\n";
+
   } else if (mode == 1) {
-    errorpage += "The gsdlsite.cfg configuration file does not contain a valid gsdlhome\n";
-    errorpage += "entry.\n";
-    errorpage += "gsdlsite.cfg resides in the same directory as this executable\n";
-  }
-  errorpage += "</body>\n";
-  errorpage += "</html>\n";
+    errortext += "The gsdlsite.cfg configuration file does not contain a valid\n";
+    errortext += "gsdlhome entry.\n";
+  }
+
+  if (debug) {
+    errortext += "gsdlsite.cfg should reside in the directory from which the\n";
+    errortext += "library executable was run.\n";
+  } else {
+    errortext += "gsdlsite.cfg should reside in the same directory as the library\n";
+    errortext += "executable file.\n";
+  }
+
+  format_error_string (errorpage, errortext, debug);
 }
 
 
 static void page_errormaincfg (const text_t &gsdlhome, const text_t &collection,
-			       text_t &errorpage) {
-  errorpage += "Content-type: text/html\n\n";
-
-  errorpage += "<html>\n";
-  errorpage += "<head>\n";
-  errorpage += "<title>Error</title>\n";
-  errorpage += "</head>\n";
-  errorpage += "<body>\n";
-  errorpage += "<h2>Oops!</h2>\n";
+			       bool debug, text_t &errorpage) {
+
+  text_t errortext;
+
   if (collection.empty()) {
     text_t main_cfg_file = filename_cat (gsdlhome, "etc", "main.cfg");
-    errorpage += "The main.cfg configuration file could not be found. This file\n";
-    errorpage += "should contain configuration information relating to the\n";
-    errorpage += "setup of the interface. As this cgi script is not being run\n";
-    errorpage += "in collection specific mode the file should reside at\n";
-    errorpage += main_cfg_file + ".\n";
+    errortext += "The main.cfg configuration file could not be found. This file\n";
+    errortext += "should contain configuration information relating to the\n";
+    errortext += "setup of the interface. As this receptionist is not being run\n";
+    errortext += "in collection specific mode the file should reside at\n";
+    errortext += main_cfg_file + ".\n";
   } else {
     text_t collect_cfg_file = filename_cat (gsdlhome, "collect", collection, "etc", "collect.cfg");
     text_t main_collect_cfg_file = filename_cat (gsdlhome, "etc", "collect.cfg");
     text_t main_cfg_file = filename_cat (gsdlhome, "etc", "main.cfg");
-    errorpage += "Either the collect.cfg or main.cfg configuration file could\n";
-    errorpage += "not be found. This file should contain configuration information\n";
-    errorpage += "relating to the setup of the interface. As this cgi script is\n";
-    errorpage += "being run in collection specific mode the file should reside\n";
-    errorpage += "at either ";
-    errorpage += collect_cfg_file + ",\n";
-    errorpage += main_collect_cfg_file + " or " + main_cfg_file + ".\n";
-  }
-  errorpage += "</body>\n";
-  errorpage += "</html>\n";
-}
-
-
-static void page_errorinit (const text_t &gsdlhome, text_t &errorpage) {
-  errorpage += "Content-type: text/html\n\n";
-
-  errorpage += "<html>\n";
-  errorpage += "<head>\n";
-  errorpage += "<title>Error</title>\n";
-  errorpage += "</head>\n";
-  errorpage += "<body>\n";
-  errorpage += "<h2>Oops!</h2>\n";
-  errorpage += "An error occurred during the initialisation of the Greenstone Digital\n";
-  errorpage += "Library software. It is likely that the software has not been setup\n";
-  errorpage += "correctly.\n";
+    errortext += "Either the collect.cfg or main.cfg configuration file could\n";
+    errortext += "not be found. This file should contain configuration information\n";
+    errortext += "relating to the setup of the interface. As this receptionist is\n";
+    errortext += "being run in collection specific mode the file should reside\n";
+    errortext += "at either " + collect_cfg_file + ",\n";
+    errortext += main_collect_cfg_file + " or " + main_cfg_file + ".\n";
+  }
+
+  format_error_string (errorpage, errortext, debug);
+}
+
+
+static void page_errorinit (const text_t &gsdlhome, bool debug, text_t &errorpage) {
+
+  text_t errortext = "An error occurred during the initialisation of the Greenstone Digital\n";
+  errortext += "Library software. It is likely that the software has not been setup\n";
+  errortext += "correctly.\n";
 
   text_t init_file = filename_cat (gsdlhome, "etc", "initout.txt");
@@ -268,37 +327,29 @@
   delete ifile;
   if (initin) {
-    errorpage += "The initialisation error log, " + init_file + ", contains the\n";
-    errorpage += "following information:\n\n";
-    errorpage += "<pre>\n";
+    errortext += "The initialisation error log, " + init_file + ", contains the\n";
+    errortext += "following information:\n\n";
+    if (!debug) errortext += "<pre>\n";
 
     char c;
     initin.get(c);
     while (!initin.eof ()) {
-      errorpage.push_back(c);
+      errortext.push_back(c);
       initin.get(c);
     }
     
-    errorpage += "</pre>\n";
+    if (!debug) errortext += "</pre>\n";
 
     initin.close();
 
   } else {
-    errorpage += "Please consult " + init_file + " for more information.\n";
-  }
-
-  errorpage += "</body>\n";
-  errorpage += "</html>\n";
-}
-
-static void page_errorparseargs (const text_t &gsdlhome, text_t &errorpage) {
-  errorpage += "Content-type: text/html\n\n";
-
-  errorpage += "<html>\n";
-  errorpage += "<head>\n";
-  errorpage += "<title>Error</title>\n";
-  errorpage += "</head>\n";
-  errorpage += "<body>\n";
-  errorpage += "<h2>Oops!</h2>\n";
-  errorpage += "An error occurred during the parsing of the cgi arguments.\n";
+    errortext += "Please consult " + init_file + " for more information.\n";
+  }
+
+  format_error_string (errorpage, errortext, debug);
+}
+
+static void page_errorparseargs (const text_t &gsdlhome, bool debug, text_t &errorpage) {
+
+  text_t errortext = "An error occurred during the parsing of the cgi arguments.\n";
 
   text_t error_file = filename_cat (gsdlhome, "etc", "errout.txt");
@@ -307,36 +358,27 @@
   delete efile;
   if (errin) {
-    errorpage += "The error log, " + error_file + ", contains the\n";
-    errorpage += "following information:\n\n";
-    errorpage += "<pre>\n";
+    errortext += "The error log, " + error_file + ", contains the\n";
+    errortext += "following information:\n\n";
+    if (!debug) errortext += "<pre>\n";
 
     char c;
     errin.get(c);
     while (!errin.eof ()) {
-      errorpage.push_back(c);
+      errortext.push_back(c);
       errin.get(c);
     }
-    errorpage += "</pre>\n";
+    if (!debug) errortext += "</pre>\n";
     errin.close();
 
   } else {
-    errorpage += "Please consult " + error_file + " for more information.\n";
-  }
-
-  errorpage += "</body>\n";
-  errorpage += "</html>\n";
-}
-
-static void page_errorcgipage (const text_t &gsdlhome, text_t &errorpage) {
-  errorpage += "Content-type: text/html\n\n";
-
-  errorpage += "<html>\n";
-  errorpage += "<head>\n";
-  errorpage += "<title>Error</title>\n";
-  errorpage += "</head>\n";
-  errorpage += "<body>\n";
-  errorpage += "<h2>Oops!</h2>\n";
-  errorpage += "An error occurred during the construction of the cgi page.\n";
-
+    errortext += "Please consult " + error_file + " for more information.\n";
+  }
+
+  format_error_string (errorpage, errortext, debug);
+}
+
+static void page_errorcgipage (const text_t &gsdlhome, bool debug, text_t &errorpage) {
+
+  text_t errortext = "An error occurred during the construction of the cgi page.\n";
 
   text_t error_file = filename_cat (gsdlhome, "etc", "errout.txt");
@@ -345,25 +387,176 @@
   delete efile;
   if (errin) {
-    errorpage += "The error log, " + error_file + ", contains the\n";
-    errorpage += "following information:\n\n";
-    errorpage += "<pre>\n";
+    errortext += "The error log, " + error_file + ", contains the\n";
+    errortext += "following information:\n\n";
+    if (!debug) errortext += "<pre>\n";
 
     char c;
     errin.get(c);
     while (!errin.eof ()) {
-      errorpage.push_back(c);
+      errortext.push_back(c);
       errin.get(c);
     }
-    errorpage += "</pre>\n";
+    if (!debug) errortext += "</pre>\n";
     errin.close();
 
   } else {
-    errorpage += "Please consult " + error_file + " for more information.\n";
-  }
-
-  errorpage += "</body>\n";
-  errorpage += "</html>\n";
-}
-
+    errortext += "Please consult " + error_file + " for more information.\n";
+  }
+
+  format_error_string (errorpage, errortext, debug);
+}
+
+static void print_debug_info (receptionist &recpt) {
+
+  outconvertclass text_t2ascii;
+  recptconf configinfo = recpt.get_configinfo ();
+  text_t etc_dir = filename_cat (configinfo.gsdlhome, "etc");
+
+  cout << "\n";
+  cout << text_t2ascii
+       << "------------------------------------------------------------\n"
+       << "Configuration and initialization completed successfully.\n"
+       << "  Note that more debug information may be available in the\n"
+       << "  initialization and error logs initout.txt and errout.txt\n"
+       << "  in " << etc_dir << ".\n"
+       << "------------------------------------------------------------\n\n";
+
+  bool colspec = false;
+  if (configinfo.collection.empty()) {
+    cout << "Receptionist is running in \"general\" (i.e. not \"collection\n"
+	 << "specific\") mode.\n";
+  } else {
+    cout << text_t2ascii 
+	 << "Receptionist is running in \"collection specific\" mode.\n"
+	 << "  collection=" << configinfo.collection << "\n"
+	 << "  collection directory=" << configinfo.collectdir << "\n";
+    colspec = true;
+  }
+  
+  cout << text_t2ascii << "gsdlhome=" << configinfo.gsdlhome << "\n";
+  if (!configinfo.gdbmhome.empty())
+    cout << text_t2ascii << "gdbmhome=" << configinfo.gdbmhome << "\n";
+  cout << text_t2ascii << "httpprefix=" << configinfo.httpprefix << "\n";
+  cout << text_t2ascii << "httpimg=" << configinfo.httpimg << "\n";
+  cout << text_t2ascii << "gwcgi=" << configinfo.gwcgi << "\n"
+       << "  Note that unless gwcgi has been set from a configuration\n"
+       << "  file it is dependent on environment variables set by your\n"
+       << "  webserver. Therefore it may not have the same value when run\n"
+       << "  from the command line as it would be when run from your\n"
+       << "  web server.\n";
+  if (configinfo.usecookies) 
+    cout << "cookies are enabled\n";
+  else 
+    cout << "cookies are disabled\n";
+  if (configinfo.logcgiargs) 
+    cout << "logging is enabled\n";
+  else 
+    cout << "logging is disabled\n";
+  cout << "------------------------------------------------------------\n\n";
+
+  text_tset::const_iterator this_mfile = configinfo.macrofiles.begin();
+  text_tset::const_iterator end_mfile = configinfo.macrofiles.end();
+  cout << "Macro Files:\n"
+       << "------------\n";
+  text_t mfile;
+  bool found;
+  while (this_mfile != end_mfile) {
+    cout << text_t2ascii << *this_mfile;
+    int spaces = (22 - (*this_mfile).size());
+    if (spaces < 2) spaces = 2;
+    text_t outspaces;
+    for (int i = 0; i < spaces; i++) outspaces.push_back (' ');
+    cout << text_t2ascii << outspaces;
+
+    found = false;
+    if (colspec) {
+      // collection specific - try collectdir/macros first
+      mfile = filename_cat (configinfo.collectdir, "macros", *this_mfile);
+      if (file_exists (mfile)) {
+	cout << text_t2ascii << "found (" << mfile << ")\n";
+	found = true;
+      }
+    }
+ 
+    if (!found) {
+      // try main macro directory
+      mfile = filename_cat (configinfo.gsdlhome, "macros", *this_mfile);
+      if (file_exists (mfile)) {
+	cout << text_t2ascii << "found (" << mfile << ")\n";
+	found = true;
+      }
+    }
+
+    if (!found)
+      cout << text_t2ascii << "NOT FOUND\n";
+
+    this_mfile ++;
+  }
+
+  cout << "------------------------------------------------------------\n\n"
+       << "Collections:\n"
+       << "------------\n"
+       << "  Note that collections will only appear as \"running\" if\n"
+       << "  their build.cfg files exist, are readable, contain a valid\n"
+       << "  builddate field (i.e. > 0), and are in the collection's\n"
+       << "  index directory (i.e. NOT the building directory)\n\n";
+
+  recptprotolistclass *protos = recpt.get_recptprotolist_ptr();
+  recptprotolistclass::iterator rprotolist_here = protos->begin();
+  recptprotolistclass::iterator rprotolist_end = protos->end();
+  bool found_valid_col = false;
+  while (rprotolist_here != rprotolist_end) {
+    if ((*rprotolist_here).p != NULL) {
+
+      text_tarray collist;
+      comerror_t err;
+      (*rprotolist_here).p->get_collection_list (collist, err, cerr);
+      if (err == noError) {
+	text_tarray::iterator collist_here = collist.begin();
+	text_tarray::iterator collist_end = collist.end();
+
+	while (collist_here != collist_end) {
+	  
+	  cout << text_t2ascii << *collist_here;
+
+	  int spaces = (22 - (*collist_here).size());
+	  if (spaces < 2) spaces = 2;
+	  text_t outspaces;
+	  for (int i = 0; i < spaces; i++) outspaces.push_back (' ');
+	  cout << text_t2ascii << outspaces;
+
+	  ColInfoResponse_t *cinfo = recpt.get_collectinfo_ptr ((*rprotolist_here).p, *collist_here, cerr);
+	  if (cinfo != NULL) {
+	    if (cinfo->isPublic) cout << "public ";
+	    else cout << "private";
+
+	    if (cinfo->buildDate > 0) {
+	      cout << "   running    ";
+	      found_valid_col = true;
+	    } else {
+	      cout << "   not running";
+	    }
+	  }
+
+	  cout << "\n";
+
+	  collist_here ++;
+	}
+      }
+    }
+    rprotolist_here ++;
+  }
+  
+  if (!found_valid_col) {
+    cout << "WARNING: No \"running\" collections were found. You need to\n";
+    cout << "         build one of the above collections\n";
+  }
+
+  cout << "\n------------------------------------------------------------\n";
+  cout << "------------------------------------------------------------\n\n";
+  cout << "receptionist running in command line debug mode\n";
+  cout << "enter cgi arguments as name=value pairs (e.g. 'a=p&p=home'):\n";
+
+}
 
 // cgiwrapper does everything necessary to output a page
@@ -372,52 +565,13 @@
 // should equal "".
 void cgiwrapper (receptionist &recpt, text_t collection) {
+  
+  int numrequests = 0;
+  bool debug = false;
+  recptconf configinfo = recpt.get_configinfo ();
+
+  // find out whether this is being run as a cgi-script
+  // or a fastcgi script
 #ifdef USE_FASTCGI
   fcgistreambuf outbuf;
-#endif
-
-  // init stuff - we can't output error pages directly with
-  // fastcgi so the pages are stored until we can output them
-  text_t errorpage;
-  outconvertclass text_t2ascii;
-
-  // set defaults
-  int maxrequests = 10000;
-  recpt.configure ("collection", collection);
-  recpt.configure ("httpimg", "/gsdl/images");
-  char *script_name = getenv("SCRIPT_NAME");
-  if (script_name != NULL) recpt.configure("gwcgi", script_name);
-  else recpt.configure("gwcgi", "/cgi-bin/gw");
-
-  // read in the configuration files.
-  text_t gsdlhome;
-  if (!site_cfg_read (recpt, gsdlhome, maxrequests)) {
-    // couldn't find the site configuration file
-    page_errorsitecfg (errorpage, 0);
-  } else if (gsdlhome.empty()) {
-    // no gsdlhome in gsdlsite.cfg
-    page_errorsitecfg (errorpage, 1);
-  } else if (!main_cfg_read (recpt, gsdlhome, collection)) {
-    // couldn't find the main configuration file
-    page_errormaincfg (gsdlhome, collection, errorpage);
-  }
-
-  // initialise the library software
-  if (errorpage.empty()) {
-    text_t init_file = filename_cat (gsdlhome, "etc", "initout.txt");
-    char *iout = init_file.getcstr();
-    ofstream initout (iout);
-    delete iout;
-    if (!recpt.init(initout)) {
-      // an error occurred during the initialisation
-      initout.close();
-      page_errorinit(gsdlhome, errorpage);
-    }
-    initout.close();
-  }
-  
-  // find out whether this is being run as a cgi-script
-  // or a fastcgi script
-  int numrequests = 0;
-#ifdef USE_FASTCGI
   int isfastcgi = !FCGX_IsCGI();
   FCGX_Stream *fcgiin, *fcgiout, *fcgierr;
@@ -457,13 +611,73 @@
       } else {
 	// debugging from command line
-	char cinURIStr[1024];
-	cin.get(cinURIStr, 1024);
-	argstr = cinURIStr;
+	debug = true;
       }
     }
-
-    // cgi scripts only deal with one request
-    maxrequests = 1;
-  }
+  }
+
+  if (debug) {
+    cout << "Configuring Greenstone...\n";
+    cout << flush;
+  }
+
+  // init stuff - we can't output error pages directly with
+  // fastcgi so the pages are stored until we can output them
+  text_t errorpage;
+  outconvertclass text_t2ascii;
+
+  // set defaults
+  int maxrequests = 10000;
+  recpt.configure ("collection", collection);
+  recpt.configure ("httpimg", "/gsdl/images");
+  char *script_name = getenv("SCRIPT_NAME");
+  if (script_name != NULL) recpt.configure("gwcgi", script_name);
+  else recpt.configure("gwcgi", "/cgi-bin/gw");
+
+  // read in the configuration files.
+  text_t gsdlhome;
+  if (!site_cfg_read (recpt, gsdlhome, maxrequests)) {
+    // couldn't find the site configuration file
+    page_errorsitecfg (errorpage, debug, 0);
+  } else if (gsdlhome.empty()) {
+    // no gsdlhome in gsdlsite.cfg
+    page_errorsitecfg (errorpage, debug, 1);
+  } else if (!main_cfg_read (recpt, gsdlhome, collection)) {
+    // couldn't find the main configuration file
+    page_errormaincfg (gsdlhome, collection, debug, errorpage);
+  } else  if (configinfo.collectinfo.empty()) {
+    // don't have any collections
+    page_errorcollect (gsdlhome, errorpage, debug);
+  }
+
+  if (errorpage.empty()) {
+
+    // initialise the library software
+    if (debug) {
+      cout << "Initializing...\n";
+      cout << flush;
+    }
+
+    text_t init_file = filename_cat (gsdlhome, "etc", "initout.txt");
+    char *iout = init_file.getcstr();
+    ofstream initout (iout);
+    delete iout;
+    if (!recpt.init(initout)) {
+      // an error occurred during the initialisation
+      initout.close();
+      page_errorinit(gsdlhome, debug, errorpage);
+    }
+    initout.close();
+  }
+
+  if (debug && errorpage.empty()) {
+    // get query string from command line
+    print_debug_info (recpt);
+    char cinURIStr[1024];
+    cin.get(cinURIStr, 1024);
+    argstr = cinURIStr;
+  }
+
+  // cgi scripts only deal with one request
+  if (!isfastcgi) maxrequests = 1;
 
   // Page-request loop. If this is not being run as a fastcgi
@@ -474,7 +688,29 @@
     if (isfastcgi) {
       if (FCGX_Accept(&fcgiin, &fcgiout, &fcgierr, &fcgienvp) < 0) break;
-      aURIStr = FCGX_GetParam("QUERY_STRING", fcgienvp);
-      if (aURIStr != NULL) argstr = aURIStr;
-      else argstr = "";
+
+      char *request_method_str = FCGX_GetParam ("REQUEST_METHOD", fcgienvp);
+      char *content_length_str = FCGX_GetParam ("CONTENT_LENGTH", fcgienvp);
+
+      if (request_method_str != NULL && strcmp(request_method_str, "POST") == 0 &&
+	  content_length_str != NULL)  {
+	// POST form data
+	int content_length = text_t(content_length_str).getint();
+	if (content_length > 0) {
+	  argstr.clear();
+	  int c;
+	  do {
+	    c = FCGX_GetChar (fcgiin);
+	    if (c < 0) break;
+	    argstr.push_back (c);
+	    content_length--;
+	  } while (content_length > 0);
+	}
+
+      } else {
+	// GET form data
+	aURIStr = FCGX_GetParam("QUERY_STRING", fcgienvp);
+	if (aURIStr != NULL) argstr = aURIStr;
+	else argstr = "";
+      }
     }
 #endif
@@ -528,5 +764,5 @@
       text_t error_file = filename_cat (gsdlhome, "etc", "errout.txt");
       char *eout = error_file.getcstr();
-      ofstream errout (eout);
+      ofstream errout (eout, ios::app);
       delete eout;
       cerr = errout;
@@ -536,13 +772,12 @@
       if (!recpt.parse_cgi_args (argstr, args, errout, fastcgienv)) {
 	errout.close ();
-	page_errorparseargs(gsdlhome, errorpage);
+	page_errorparseargs(gsdlhome, debug, errorpage);
       } else {
 	if (!recpt.produce_cgi_page (args, pageout, errout, fastcgienv)) {
 	  errout.close ();
-	  page_errorcgipage(gsdlhome, errorpage);
-	} else {
-	  errout.close ();
+	  page_errorcgipage(gsdlhome, debug, errorpage);
 	}
 	recpt.log_cgi_args (args, errout, fastcgienv);
+	errout.close ();
       }
     }
