Ignore:
Timestamp:
2000-07-13T10:21:53+12:00 (24 years ago)
Author:
sjboddie
Message:

merged changes to trunk into New_Config_Format branch

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/New_Config_Format-branch/gsdl/src/recpt/cgiwrapper.cpp

    r963 r1279  
    2828/*
    2929   $Log$
     30   Revision 1.22.4.1  2000/07/12 22:21:35  sjboddie
     31   merged changes to trunk into New_Config_Format branch
     32
     33   Revision 1.31  2000/07/12 04:51:05  nzdl
     34   added an error message when no "valid" collections are available
     35
     36   Revision 1.30  2000/07/05 21:49:31  sjboddie
     37   Receptionist now caches collection information to avoid making multiple
     38   get_collectinfo calls to collection server
     39
     40   Revision 1.29  2000/06/29 03:57:14  sjboddie
     41   Now append to error log (errout.txt) instead of overwriting it each time
     42
     43   Revision 1.28  2000/06/28 01:30:23  nzdl
     44   *** empty log message ***
     45
     46   Revision 1.27  2000/06/28 01:24:59  sjboddie
     47   got "POST" cgi data to work when using fastcgi
     48
     49   Revision 1.26  2000/05/12 03:09:26  sjboddie
     50   minor modifications to get web library compiling under VC++ 6.0
     51
     52   Revision 1.25  2000/04/14 04:45:19  sjboddie
     53   Modified the English of the debug output slightly
     54
     55   Revision 1.24  2000/04/14 03:10:35  sjboddie
     56   tidied up a few issues concerning the new debug info which showed
     57   up on windows
     58
     59   Revision 1.23  2000/04/14 02:52:05  sjboddie
     60   tidied up error messaging and set up some debugging info to be output
     61   when running library from command line
     62
    3063   Revision 1.22  2000/02/21 21:56:46  sjboddie
    3164   gsdlhome now comes from gsdlsite.cfg
     
    191224#endif
    192225
    193 
    194 static void page_errorsitecfg (text_t &errorpage, int mode) {
    195   errorpage += "Content-type: text/html\n\n";
    196 
    197   errorpage += "<html>\n";
    198   errorpage += "<head>\n";
    199   errorpage += "<title>Error</title>\n";
    200   errorpage += "</head>\n";
    201   errorpage += "<body>\n";
    202   errorpage += "<h2>Oops!</h2>\n";
     226static void format_error_string (text_t &errorpage, const text_t &errortext, bool debug) {
     227
     228  errorpage.clear();
     229
     230  if (debug) {
     231    errorpage += "\n";
     232    errorpage += "ERROR: " + errortext;
     233    errorpage += "\n";
     234   
     235  } else {
     236
     237    errorpage += "Content-type: text/html\n\n";
     238   
     239    errorpage += "<html>\n";
     240    errorpage += "<head>\n";
     241    errorpage += "<title>Error</title>\n";
     242    errorpage += "</head>\n";
     243    errorpage += "<body>\n";
     244    errorpage += "<h2>Oops!</h2>\n";
     245    errorpage += errortext;
     246    errorpage += "</body>\n";
     247    errorpage += "</html>\n";
     248  }
     249}
     250
     251static void page_errorcollect (const text_t &gsdlhome, text_t &errorpage, bool debug) {
     252
     253  text_t collectdir = filename_cat (gsdlhome, "collect");
     254
     255  text_t errortext = "No valid collections were found: Check that your collect directory\n";
     256  errortext += "(" + collectdir + ") is readable and contains at least one valid collection.\n";
     257  errortext += "Note that modelcol is NOT a valid collection.\n";
     258  errortext += "If the path to your collect directory is wrong edit the 'gsdlhome' field\n";
     259  errortext += "in your gsdlsite.cfg configuration file.\n";
     260
     261  format_error_string (errorpage, errortext, debug);
     262}
     263
     264static void page_errorsitecfg (text_t &errorpage, bool debug, int mode) {
     265
     266  text_t errortext;
     267
    203268  if (mode == 0) {
    204     errorpage += "The gsdlsite.cfg configuration file could not be found. This file\n";
    205     errorpage += "should contain configuration information relating to this\n";
    206     errorpage += "site's setup.\n";
    207     errorpage += "gsdlsite.cfg should reside in the same directory as this executable\n";
     269    errortext += "The gsdlsite.cfg configuration file could not be found. This\n";
     270    errortext += "file should contain configuration information relating to this\n";
     271    errortext += "site's setup.\n";
     272
    208273  } else if (mode == 1) {
    209     errorpage += "The gsdlsite.cfg configuration file does not contain a valid gsdlhome\n";
    210     errorpage += "entry.\n";
    211     errorpage += "gsdlsite.cfg resides in the same directory as this executable\n";
    212   }
    213   errorpage += "</body>\n";
    214   errorpage += "</html>\n";
     274    errortext += "The gsdlsite.cfg configuration file does not contain a valid\n";
     275    errortext += "gsdlhome entry.\n";
     276  }
     277
     278  if (debug) {
     279    errortext += "gsdlsite.cfg should reside in the directory from which the\n";
     280    errortext += "library executable was run.\n";
     281  } else {
     282    errortext += "gsdlsite.cfg should reside in the same directory as the library\n";
     283    errortext += "executable file.\n";
     284  }
     285
     286  format_error_string (errorpage, errortext, debug);
    215287}
    216288
    217289
    218290static void page_errormaincfg (const text_t &gsdlhome, const text_t &collection,
    219                    text_t &errorpage) {
    220   errorpage += "Content-type: text/html\n\n";
    221 
    222   errorpage += "<html>\n";
    223   errorpage += "<head>\n";
    224   errorpage += "<title>Error</title>\n";
    225   errorpage += "</head>\n";
    226   errorpage += "<body>\n";
    227   errorpage += "<h2>Oops!</h2>\n";
     291                   bool debug, text_t &errorpage) {
     292
     293  text_t errortext;
     294
    228295  if (collection.empty()) {
    229296    text_t main_cfg_file = filename_cat (gsdlhome, "etc", "main.cfg");
    230     errorpage += "The main.cfg configuration file could not be found. This file\n";
    231     errorpage += "should contain configuration information relating to the\n";
    232     errorpage += "setup of the interface. As this cgi script is not being run\n";
    233     errorpage += "in collection specific mode the file should reside at\n";
    234     errorpage += main_cfg_file + ".\n";
     297    errortext += "The main.cfg configuration file could not be found. This file\n";
     298    errortext += "should contain configuration information relating to the\n";
     299    errortext += "setup of the interface. As this receptionist is not being run\n";
     300    errortext += "in collection specific mode the file should reside at\n";
     301    errortext += main_cfg_file + ".\n";
    235302  } else {
    236303    text_t collect_cfg_file = filename_cat (gsdlhome, "collect", collection, "etc", "collect.cfg");
    237304    text_t main_collect_cfg_file = filename_cat (gsdlhome, "etc", "collect.cfg");
    238305    text_t main_cfg_file = filename_cat (gsdlhome, "etc", "main.cfg");
    239     errorpage += "Either the collect.cfg or main.cfg configuration file could\n";
    240     errorpage += "not be found. This file should contain configuration information\n";
    241     errorpage += "relating to the setup of the interface. As this cgi script is\n";
    242     errorpage += "being run in collection specific mode the file should reside\n";
    243     errorpage += "at either ";
    244     errorpage += collect_cfg_file + ",\n";
    245     errorpage += main_collect_cfg_file + " or " + main_cfg_file + ".\n";
    246   }
    247   errorpage += "</body>\n";
    248   errorpage += "</html>\n";
    249 }
    250 
    251 
    252 static void page_errorinit (const text_t &gsdlhome, text_t &errorpage) {
    253   errorpage += "Content-type: text/html\n\n";
    254 
    255   errorpage += "<html>\n";
    256   errorpage += "<head>\n";
    257   errorpage += "<title>Error</title>\n";
    258   errorpage += "</head>\n";
    259   errorpage += "<body>\n";
    260   errorpage += "<h2>Oops!</h2>\n";
    261   errorpage += "An error occurred during the initialisation of the Greenstone Digital\n";
    262   errorpage += "Library software. It is likely that the software has not been setup\n";
    263   errorpage += "correctly.\n";
     306    errortext += "Either the collect.cfg or main.cfg configuration file could\n";
     307    errortext += "not be found. This file should contain configuration information\n";
     308    errortext += "relating to the setup of the interface. As this receptionist is\n";
     309    errortext += "being run in collection specific mode the file should reside\n";
     310    errortext += "at either " + collect_cfg_file + ",\n";
     311    errortext += main_collect_cfg_file + " or " + main_cfg_file + ".\n";
     312  }
     313
     314  format_error_string (errorpage, errortext, debug);
     315}
     316
     317
     318static void page_errorinit (const text_t &gsdlhome, bool debug, text_t &errorpage) {
     319
     320  text_t errortext = "An error occurred during the initialisation of the Greenstone Digital\n";
     321  errortext += "Library software. It is likely that the software has not been setup\n";
     322  errortext += "correctly.\n";
    264323
    265324  text_t init_file = filename_cat (gsdlhome, "etc", "initout.txt");
     
    268327  delete ifile;
    269328  if (initin) {
    270     errorpage += "The initialisation error log, " + init_file + ", contains the\n";
    271     errorpage += "following information:\n\n";
    272     errorpage += "<pre>\n";
     329    errortext += "The initialisation error log, " + init_file + ", contains the\n";
     330    errortext += "following information:\n\n";
     331    if (!debug) errortext += "<pre>\n";
    273332
    274333    char c;
    275334    initin.get(c);
    276335    while (!initin.eof ()) {
    277       errorpage.push_back(c);
     336      errortext.push_back(c);
    278337      initin.get(c);
    279338    }
    280339   
    281     errorpage += "</pre>\n";
     340    if (!debug) errortext += "</pre>\n";
    282341
    283342    initin.close();
    284343
    285344  } else {
    286     errorpage += "Please consult " + init_file + " for more information.\n";
    287   }
    288 
    289   errorpage += "</body>\n";
    290   errorpage += "</html>\n";
    291 }
    292 
    293 static void page_errorparseargs (const text_t &gsdlhome, text_t &errorpage) {
    294   errorpage += "Content-type: text/html\n\n";
    295 
    296   errorpage += "<html>\n";
    297   errorpage += "<head>\n";
    298   errorpage += "<title>Error</title>\n";
    299   errorpage += "</head>\n";
    300   errorpage += "<body>\n";
    301   errorpage += "<h2>Oops!</h2>\n";
    302   errorpage += "An error occurred during the parsing of the cgi arguments.\n";
     345    errortext += "Please consult " + init_file + " for more information.\n";
     346  }
     347
     348  format_error_string (errorpage, errortext, debug);
     349}
     350
     351static void page_errorparseargs (const text_t &gsdlhome, bool debug, text_t &errorpage) {
     352
     353  text_t errortext = "An error occurred during the parsing of the cgi arguments.\n";
    303354
    304355  text_t error_file = filename_cat (gsdlhome, "etc", "errout.txt");
     
    307358  delete efile;
    308359  if (errin) {
    309     errorpage += "The error log, " + error_file + ", contains the\n";
    310     errorpage += "following information:\n\n";
    311     errorpage += "<pre>\n";
     360    errortext += "The error log, " + error_file + ", contains the\n";
     361    errortext += "following information:\n\n";
     362    if (!debug) errortext += "<pre>\n";
    312363
    313364    char c;
    314365    errin.get(c);
    315366    while (!errin.eof ()) {
    316       errorpage.push_back(c);
     367      errortext.push_back(c);
    317368      errin.get(c);
    318369    }
    319     errorpage += "</pre>\n";
     370    if (!debug) errortext += "</pre>\n";
    320371    errin.close();
    321372
    322373  } else {
    323     errorpage += "Please consult " + error_file + " for more information.\n";
    324   }
    325 
    326   errorpage += "</body>\n";
    327   errorpage += "</html>\n";
    328 }
    329 
    330 static void page_errorcgipage (const text_t &gsdlhome, text_t &errorpage) {
    331   errorpage += "Content-type: text/html\n\n";
    332 
    333   errorpage += "<html>\n";
    334   errorpage += "<head>\n";
    335   errorpage += "<title>Error</title>\n";
    336   errorpage += "</head>\n";
    337   errorpage += "<body>\n";
    338   errorpage += "<h2>Oops!</h2>\n";
    339   errorpage += "An error occurred during the construction of the cgi page.\n";
    340 
     374    errortext += "Please consult " + error_file + " for more information.\n";
     375  }
     376
     377  format_error_string (errorpage, errortext, debug);
     378}
     379
     380static void page_errorcgipage (const text_t &gsdlhome, bool debug, text_t &errorpage) {
     381
     382  text_t errortext = "An error occurred during the construction of the cgi page.\n";
    341383
    342384  text_t error_file = filename_cat (gsdlhome, "etc", "errout.txt");
     
    345387  delete efile;
    346388  if (errin) {
    347     errorpage += "The error log, " + error_file + ", contains the\n";
    348     errorpage += "following information:\n\n";
    349     errorpage += "<pre>\n";
     389    errortext += "The error log, " + error_file + ", contains the\n";
     390    errortext += "following information:\n\n";
     391    if (!debug) errortext += "<pre>\n";
    350392
    351393    char c;
    352394    errin.get(c);
    353395    while (!errin.eof ()) {
    354       errorpage.push_back(c);
     396      errortext.push_back(c);
    355397      errin.get(c);
    356398    }
    357     errorpage += "</pre>\n";
     399    if (!debug) errortext += "</pre>\n";
    358400    errin.close();
    359401
    360402  } else {
    361     errorpage += "Please consult " + error_file + " for more information.\n";
    362   }
    363 
    364   errorpage += "</body>\n";
    365   errorpage += "</html>\n";
    366 }
    367 
     403    errortext += "Please consult " + error_file + " for more information.\n";
     404  }
     405
     406  format_error_string (errorpage, errortext, debug);
     407}
     408
     409static void print_debug_info (receptionist &recpt) {
     410
     411  outconvertclass text_t2ascii;
     412  recptconf configinfo = recpt.get_configinfo ();
     413  text_t etc_dir = filename_cat (configinfo.gsdlhome, "etc");
     414
     415  cout << "\n";
     416  cout << text_t2ascii
     417       << "------------------------------------------------------------\n"
     418       << "Configuration and initialization completed successfully.\n"
     419       << "  Note that more debug information may be available in the\n"
     420       << "  initialization and error logs initout.txt and errout.txt\n"
     421       << "  in " << etc_dir << ".\n"
     422       << "------------------------------------------------------------\n\n";
     423
     424  bool colspec = false;
     425  if (configinfo.collection.empty()) {
     426    cout << "Receptionist is running in \"general\" (i.e. not \"collection\n"
     427     << "specific\") mode.\n";
     428  } else {
     429    cout << text_t2ascii
     430     << "Receptionist is running in \"collection specific\" mode.\n"
     431     << "  collection=" << configinfo.collection << "\n"
     432     << "  collection directory=" << configinfo.collectdir << "\n";
     433    colspec = true;
     434  }
     435 
     436  cout << text_t2ascii << "gsdlhome=" << configinfo.gsdlhome << "\n";
     437  if (!configinfo.gdbmhome.empty())
     438    cout << text_t2ascii << "gdbmhome=" << configinfo.gdbmhome << "\n";
     439  cout << text_t2ascii << "httpprefix=" << configinfo.httpprefix << "\n";
     440  cout << text_t2ascii << "httpimg=" << configinfo.httpimg << "\n";
     441  cout << text_t2ascii << "gwcgi=" << configinfo.gwcgi << "\n"
     442       << "  Note that unless gwcgi has been set from a configuration\n"
     443       << "  file it is dependent on environment variables set by your\n"
     444       << "  webserver. Therefore it may not have the same value when run\n"
     445       << "  from the command line as it would be when run from your\n"
     446       << "  web server.\n";
     447  if (configinfo.usecookies)
     448    cout << "cookies are enabled\n";
     449  else
     450    cout << "cookies are disabled\n";
     451  if (configinfo.logcgiargs)
     452    cout << "logging is enabled\n";
     453  else
     454    cout << "logging is disabled\n";
     455  cout << "------------------------------------------------------------\n\n";
     456
     457  text_tset::const_iterator this_mfile = configinfo.macrofiles.begin();
     458  text_tset::const_iterator end_mfile = configinfo.macrofiles.end();
     459  cout << "Macro Files:\n"
     460       << "------------\n";
     461  text_t mfile;
     462  bool found;
     463  while (this_mfile != end_mfile) {
     464    cout << text_t2ascii << *this_mfile;
     465    int spaces = (22 - (*this_mfile).size());
     466    if (spaces < 2) spaces = 2;
     467    text_t outspaces;
     468    for (int i = 0; i < spaces; i++) outspaces.push_back (' ');
     469    cout << text_t2ascii << outspaces;
     470
     471    found = false;
     472    if (colspec) {
     473      // collection specific - try collectdir/macros first
     474      mfile = filename_cat (configinfo.collectdir, "macros", *this_mfile);
     475      if (file_exists (mfile)) {
     476    cout << text_t2ascii << "found (" << mfile << ")\n";
     477    found = true;
     478      }
     479    }
     480 
     481    if (!found) {
     482      // try main macro directory
     483      mfile = filename_cat (configinfo.gsdlhome, "macros", *this_mfile);
     484      if (file_exists (mfile)) {
     485    cout << text_t2ascii << "found (" << mfile << ")\n";
     486    found = true;
     487      }
     488    }
     489
     490    if (!found)
     491      cout << text_t2ascii << "NOT FOUND\n";
     492
     493    this_mfile ++;
     494  }
     495
     496  cout << "------------------------------------------------------------\n\n"
     497       << "Collections:\n"
     498       << "------------\n"
     499       << "  Note that collections will only appear as \"running\" if\n"
     500       << "  their build.cfg files exist, are readable, contain a valid\n"
     501       << "  builddate field (i.e. > 0), and are in the collection's\n"
     502       << "  index directory (i.e. NOT the building directory)\n\n";
     503
     504  recptprotolistclass *protos = recpt.get_recptprotolist_ptr();
     505  recptprotolistclass::iterator rprotolist_here = protos->begin();
     506  recptprotolistclass::iterator rprotolist_end = protos->end();
     507  bool found_valid_col = false;
     508  while (rprotolist_here != rprotolist_end) {
     509    if ((*rprotolist_here).p != NULL) {
     510
     511      text_tarray collist;
     512      comerror_t err;
     513      (*rprotolist_here).p->get_collection_list (collist, err, cerr);
     514      if (err == noError) {
     515    text_tarray::iterator collist_here = collist.begin();
     516    text_tarray::iterator collist_end = collist.end();
     517
     518    while (collist_here != collist_end) {
     519     
     520      cout << text_t2ascii << *collist_here;
     521
     522      int spaces = (22 - (*collist_here).size());
     523      if (spaces < 2) spaces = 2;
     524      text_t outspaces;
     525      for (int i = 0; i < spaces; i++) outspaces.push_back (' ');
     526      cout << text_t2ascii << outspaces;
     527
     528      ColInfoResponse_t *cinfo = recpt.get_collectinfo_ptr ((*rprotolist_here).p, *collist_here, cerr);
     529      if (cinfo != NULL) {
     530        if (cinfo->isPublic) cout << "public ";
     531        else cout << "private";
     532
     533        if (cinfo->buildDate > 0) {
     534          cout << "   running    ";
     535          found_valid_col = true;
     536        } else {
     537          cout << "   not running";
     538        }
     539      }
     540
     541      cout << "\n";
     542
     543      collist_here ++;
     544    }
     545      }
     546    }
     547    rprotolist_here ++;
     548  }
     549 
     550  if (!found_valid_col) {
     551    cout << "WARNING: No \"running\" collections were found. You need to\n";
     552    cout << "         build one of the above collections\n";
     553  }
     554
     555  cout << "\n------------------------------------------------------------\n";
     556  cout << "------------------------------------------------------------\n\n";
     557  cout << "receptionist running in command line debug mode\n";
     558  cout << "enter cgi arguments as name=value pairs (e.g. 'a=p&p=home'):\n";
     559
     560}
    368561
    369562// cgiwrapper does everything necessary to output a page
     
    372565// should equal "".
    373566void cgiwrapper (receptionist &recpt, text_t collection) {
     567 
     568  int numrequests = 0;
     569  bool debug = false;
     570  recptconf configinfo = recpt.get_configinfo ();
     571
     572  // find out whether this is being run as a cgi-script
     573  // or a fastcgi script
    374574#ifdef USE_FASTCGI
    375575  fcgistreambuf outbuf;
    376 #endif
    377 
    378   // init stuff - we can't output error pages directly with
    379   // fastcgi so the pages are stored until we can output them
    380   text_t errorpage;
    381   outconvertclass text_t2ascii;
    382 
    383   // set defaults
    384   int maxrequests = 10000;
    385   recpt.configure ("collection", collection);
    386   recpt.configure ("httpimg", "/gsdl/images");
    387   char *script_name = getenv("SCRIPT_NAME");
    388   if (script_name != NULL) recpt.configure("gwcgi", script_name);
    389   else recpt.configure("gwcgi", "/cgi-bin/gw");
    390 
    391   // read in the configuration files.
    392   text_t gsdlhome;
    393   if (!site_cfg_read (recpt, gsdlhome, maxrequests)) {
    394     // couldn't find the site configuration file
    395     page_errorsitecfg (errorpage, 0);
    396   } else if (gsdlhome.empty()) {
    397     // no gsdlhome in gsdlsite.cfg
    398     page_errorsitecfg (errorpage, 1);
    399   } else if (!main_cfg_read (recpt, gsdlhome, collection)) {
    400     // couldn't find the main configuration file
    401     page_errormaincfg (gsdlhome, collection, errorpage);
    402   }
    403 
    404   // initialise the library software
    405   if (errorpage.empty()) {
    406     text_t init_file = filename_cat (gsdlhome, "etc", "initout.txt");
    407     char *iout = init_file.getcstr();
    408     ofstream initout (iout);
    409     delete iout;
    410     if (!recpt.init(initout)) {
    411       // an error occurred during the initialisation
    412       initout.close();
    413       page_errorinit(gsdlhome, errorpage);
    414     }
    415     initout.close();
    416   }
    417  
    418   // find out whether this is being run as a cgi-script
    419   // or a fastcgi script
    420   int numrequests = 0;
    421 #ifdef USE_FASTCGI
    422576  int isfastcgi = !FCGX_IsCGI();
    423577  FCGX_Stream *fcgiin, *fcgiout, *fcgierr;
     
    457611      } else {
    458612    // debugging from command line
    459     char cinURIStr[1024];
    460     cin.get(cinURIStr, 1024);
    461     argstr = cinURIStr;
     613    debug = true;
    462614      }
    463615    }
    464 
    465     // cgi scripts only deal with one request
    466     maxrequests = 1;
    467   }
     616  }
     617
     618  if (debug) {
     619    cout << "Configuring Greenstone...\n";
     620    cout << flush;
     621  }
     622
     623  // init stuff - we can't output error pages directly with
     624  // fastcgi so the pages are stored until we can output them
     625  text_t errorpage;
     626  outconvertclass text_t2ascii;
     627
     628  // set defaults
     629  int maxrequests = 10000;
     630  recpt.configure ("collection", collection);
     631  recpt.configure ("httpimg", "/gsdl/images");
     632  char *script_name = getenv("SCRIPT_NAME");
     633  if (script_name != NULL) recpt.configure("gwcgi", script_name);
     634  else recpt.configure("gwcgi", "/cgi-bin/gw");
     635
     636  // read in the configuration files.
     637  text_t gsdlhome;
     638  if (!site_cfg_read (recpt, gsdlhome, maxrequests)) {
     639    // couldn't find the site configuration file
     640    page_errorsitecfg (errorpage, debug, 0);
     641  } else if (gsdlhome.empty()) {
     642    // no gsdlhome in gsdlsite.cfg
     643    page_errorsitecfg (errorpage, debug, 1);
     644  } else if (!main_cfg_read (recpt, gsdlhome, collection)) {
     645    // couldn't find the main configuration file
     646    page_errormaincfg (gsdlhome, collection, debug, errorpage);
     647  } else  if (configinfo.collectinfo.empty()) {
     648    // don't have any collections
     649    page_errorcollect (gsdlhome, errorpage, debug);
     650  }
     651
     652  if (errorpage.empty()) {
     653
     654    // initialise the library software
     655    if (debug) {
     656      cout << "Initializing...\n";
     657      cout << flush;
     658    }
     659
     660    text_t init_file = filename_cat (gsdlhome, "etc", "initout.txt");
     661    char *iout = init_file.getcstr();
     662    ofstream initout (iout);
     663    delete iout;
     664    if (!recpt.init(initout)) {
     665      // an error occurred during the initialisation
     666      initout.close();
     667      page_errorinit(gsdlhome, debug, errorpage);
     668    }
     669    initout.close();
     670  }
     671
     672  if (debug && errorpage.empty()) {
     673    // get query string from command line
     674    print_debug_info (recpt);
     675    char cinURIStr[1024];
     676    cin.get(cinURIStr, 1024);
     677    argstr = cinURIStr;
     678  }
     679
     680  // cgi scripts only deal with one request
     681  if (!isfastcgi) maxrequests = 1;
    468682
    469683  // Page-request loop. If this is not being run as a fastcgi
     
    474688    if (isfastcgi) {
    475689      if (FCGX_Accept(&fcgiin, &fcgiout, &fcgierr, &fcgienvp) < 0) break;
    476       aURIStr = FCGX_GetParam("QUERY_STRING", fcgienvp);
    477       if (aURIStr != NULL) argstr = aURIStr;
    478       else argstr = "";
     690
     691      char *request_method_str = FCGX_GetParam ("REQUEST_METHOD", fcgienvp);
     692      char *content_length_str = FCGX_GetParam ("CONTENT_LENGTH", fcgienvp);
     693
     694      if (request_method_str != NULL && strcmp(request_method_str, "POST") == 0 &&
     695      content_length_str != NULL)  {
     696    // POST form data
     697    int content_length = text_t(content_length_str).getint();
     698    if (content_length > 0) {
     699      argstr.clear();
     700      int c;
     701      do {
     702        c = FCGX_GetChar (fcgiin);
     703        if (c < 0) break;
     704        argstr.push_back (c);
     705        content_length--;
     706      } while (content_length > 0);
     707    }
     708
     709      } else {
     710    // GET form data
     711    aURIStr = FCGX_GetParam("QUERY_STRING", fcgienvp);
     712    if (aURIStr != NULL) argstr = aURIStr;
     713    else argstr = "";
     714      }
    479715    }
    480716#endif
     
    528764      text_t error_file = filename_cat (gsdlhome, "etc", "errout.txt");
    529765      char *eout = error_file.getcstr();
    530       ofstream errout (eout);
     766      ofstream errout (eout, ios::app);
    531767      delete eout;
    532768      cerr = errout;
     
    536772      if (!recpt.parse_cgi_args (argstr, args, errout, fastcgienv)) {
    537773    errout.close ();
    538     page_errorparseargs(gsdlhome, errorpage);
     774    page_errorparseargs(gsdlhome, debug, errorpage);
    539775      } else {
    540776    if (!recpt.produce_cgi_page (args, pageout, errout, fastcgienv)) {
    541777      errout.close ();
    542       page_errorcgipage(gsdlhome, errorpage);
    543     } else {
    544       errout.close ();
     778      page_errorcgipage(gsdlhome, debug, errorpage);
    545779    }
    546780    recpt.log_cgi_args (args, errout, fastcgienv);
     781    errout.close ();
    547782      }
    548783    }
Note: See TracChangeset for help on using the changeset viewer.