Ignore:
Timestamp:
2000-02-03T14:45:48+13:00 (24 years ago)
Author:
sjboddie
Message:

lots of stuff

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/src/w32server/cgiwrapper.cpp

    r611 r902  
    99#include "wincgiutils.h"
    1010#include "settings.h"
     11#include "fileutil.h"
    1112
    1213#include "gsdlconf.h"
     
    3132#include "mggdbmsource.h"
    3233
    33 
    3434// actions
     35#include "action.h"
     36#include "statusaction.h"
    3537#include "pageaction.h"
    3638#include "pingaction.h"
    3739#include "queryaction.h"
    3840#include "documentaction.h"
    39 #include "statusaction.h"
     41#include "authenaction.h"
    4042#include "usersaction.h"
    41 #include "authenaction.h"
    42 #include "tipaction.h"
     43#include "extlinkaction.h"
     44//#include "buildaction.h"
     45
     46// browsers
     47#include "browserclass.h"
     48#include "vlistbrowserclass.h"
     49#include "hlistbrowserclass.h"
     50#include "datelistbrowserclass.h"
     51#include "invbrowserclass.h"
     52#include "pagedbrowserclass.h"
     53#include "htmlbrowserclass.h"
    4354
    4455// filters
     
    115126
    116127int logstreambuf::sync () {
    117   if (gs_keep_log || gs_show_console) {
     128  if (gsdl_keep_log || gsdl_show_console) {
    118129    log_message ("LOCAL LIB MESSAGE: ");
    119130        log_message_N (pbase(), out_waiting());
     
    143154DWORD lastlibaccesstime;
    144155DWORD baseavailvirtual;
    145 
    146156
    147157static void page_errorsitecfg (const text_t &gsdlhome, const text_t &collection) {
     
    318328  cerr = &logstream;
    319329  cout = &textstream;
    320  
     330
    321331  // collection should be set to "" unless in
    322332  // collection specific mode
    323333  text_t collection = "";
     334  text_tset gsdlhomes;
     335  text_tarray collections;
     336  colinfo_tmap::const_iterator this_info = gsdl_collectinfo.begin();
     337  colinfo_tmap::const_iterator end_info = gsdl_collectinfo.end();
    324338
    325339  // note the current time
    326340  lastlibaccesstime = GetTickCount();
    327  
     341
    328342  // before we do the init we should make sure
    329343  // that we can find the relevant directories
    330   if (!checkdir (GSDL_GSDLHOME "\\")) return 0;
    331   if (!checkdir (GSDL_GSDLHOME "\\macros\\")) return 0;
    332  
    333   // add a collection server for each collection
    334   text_tarray collections;
    335   ifstream collist (GSDL_GSDLHOME "/etc/collections.txt");
    336   if (!collist) {
    337     exit(1);
    338   }
    339   char col[100];
    340   while (!collist.eof()) {
    341     collist.getline (col, 100);
    342     if (col[0] != '\0')
    343       collections.push_back (col);
    344   }
    345   collist.close();
    346 
     344  if (!checkdir (gsdl_gsdlhome + "\\")) return 0;
     345  if (!checkdir (gsdl_gsdlhome + "\\macros\\")) return 0;
     346
     347  if (collection.empty()) {
     348
     349    // get all collections from each gsdlhome (this relies
     350    // on there not being more than one collection with the same
     351    // name)
     352    read_dir (filename_cat (gsdl_gsdlhome, "collect"), collections);
     353    gsdlhomes.insert (gsdl_gsdlhome);
     354    while (this_info != end_info) {
     355      if (gsdlhomes.find ((*this_info).second.gsdl_gsdlhome) == gsdlhomes.end()) {
     356    read_dir (filename_cat ((*this_info).second.gsdl_gsdlhome, "collect"), collections);
     357    gsdlhomes.insert ((*this_info).second.gsdl_gsdlhome);
     358      }
     359      this_info ++;
     360    }
     361  } else {
     362    collections.push_back (collection);
     363  }
     364 
    347365  text_tarray::const_iterator thiscol = collections.begin();
    348366  text_tarray::const_iterator endcol = collections.end();
    349  
     367
    350368  while (thiscol != endcol) {
    351    
     369
    352370    // this memory is created but never destroyed
    353371    // we're also not doing any error checking to make sure we didn't
     
    396414 
    397415  mapinconvertclass *gbinconvert = new mapinconvertclass();
    398   gbinconvert->setmapfile (GSDL_GSDLHOME, "gbku", 0x25a1);
     416  gbinconvert->setmapfile (gsdl_gsdlhome, "gbku", 0x25a1);
    399417  mapoutconvertclass *gboutconvert = new mapoutconvertclass();
    400   gboutconvert->setmapfile (GSDL_GSDLHOME, "ugbk", 0xa1f5);
     418  gboutconvert->setmapfile (gsdl_gsdlhome, "ugbk", 0xa1f5);
    401419  recpt.add_converter ("g", gbinconvert, gboutconvert);
    402420 
     
    407425 
    408426  pageaction *apageaction = new pageaction();
    409   apageaction->set_receptionist (&recpt);
    410427  recpt.add_action (apageaction);
    411428 
     
    421438  usersaction *ausersaction = new usersaction();
    422439  recpt.add_action (ausersaction);
     440
     441  extlinkaction *anextlinkaction = new extlinkaction();
     442  recpt.add_action (anextlinkaction);
     443
     444  //  buildaction *abuildaction = new buildaction();
     445  //  abuildaction->set_receptionist (&recpt);
     446  //  recpt.add_action (abuildaction);
    423447 
    424448  authenaction *aauthenaction = new authenaction();
    425449  aauthenaction->set_receptionist(&recpt);
    426450  recpt.add_action (aauthenaction);
    427  
    428   tipaction *atipaction = new tipaction();
    429   recpt.add_action (atipaction);
     451
     452
     453  // list of browsers
     454  vlistbrowserclass *avlistbrowserclass = new vlistbrowserclass();
     455  recpt.add_browser (avlistbrowserclass);
     456  recpt.setdefaultbrowser ("VList");
     457
     458  hlistbrowserclass *ahlistbrowserclass = new hlistbrowserclass();
     459  recpt.add_browser (ahlistbrowserclass);
     460
     461  datelistbrowserclass *adatelistbrowserclass = new datelistbrowserclass();
     462  recpt.add_browser (adatelistbrowserclass);
     463
     464  invbrowserclass *ainvbrowserclass = new invbrowserclass();
     465  recpt.add_browser (ainvbrowserclass);
     466
     467  pagedbrowserclass *apagedbrowserclass = new pagedbrowserclass();
     468  recpt.add_browser (apagedbrowserclass);
     469
     470  htmlbrowserclass *ahtmlbrowserclass = new htmlbrowserclass();
     471  recpt.add_browser (ahtmlbrowserclass);
    430472 
    431473  // set defaults
    432   recpt.configure ("gsdlhome", GSDL_GSDLHOME);
     474  recpt.configure ("gsdlhome", gsdl_gsdlhome);
    433475  recpt.configure ("collection", collection);
    434476
    435477  int maxrequests = 1;
    436   if (!site_cfg_read (recpt, GSDL_GSDLHOME, collection, maxrequests)) {
    437     // couldn't find the site configuration file
    438     page_errorsitecfg (GSDL_GSDLHOME, collection);
    439     return 0;
    440   } else if (!main_cfg_read (recpt, GSDL_GSDLHOME, collection)) {
    441     // couldn't find the main configuration file
    442     page_errormaincfg (GSDL_GSDLHOME, collection);
    443     return 0;
     478  text_tset seenhomes;
     479  this_info = gsdl_collectinfo.begin();
     480
     481  // configure any collections with gsdlhome (or gdbmhome)
     482  // different from the default
     483  while (this_info != end_info) {
     484    if (((*this_info).second.gsdl_gsdlhome != gsdl_gsdlhome) ||
     485    ((*this_info).second.gsdl_gdbmhome != gsdl_gdbmhome) &&
     486    (seenhomes.find ((*this_info).second.gsdl_gsdlhome +
     487             (*this_info).second.gsdl_gdbmhome) == seenhomes.end())) {
     488      text_tarray tmpconf;
     489      tmpconf.push_back ((*this_info).first);
     490      tmpconf.push_back ((*this_info).second.gsdl_gsdlhome);
     491      tmpconf.push_back ((*this_info).second.gsdl_gdbmhome);
     492      recpt.configure ("collectinfo", tmpconf);
     493      seenhomes.insert ((*this_info).second.gsdl_gsdlhome +
     494            (*this_info).second.gsdl_gdbmhome);
     495    }
     496    this_info ++;
     497  }
     498
     499  // read in config files of each gsdlhome (in no particular order)
     500  // those read in last will override those read earlier
     501  // collections being used together in this way should be
     502  // careful not to have site.cfg or main.cfg files that might
     503  // screw with each other.
     504  text_tset::const_iterator thome = gsdlhomes.begin();
     505  text_tset::const_iterator ehome = gsdlhomes.end();
     506  while (thome != ehome) {
     507    if (!site_cfg_read (recpt, *thome, collection, maxrequests)) {
     508      // couldn't find the site configuration file
     509      page_errorsitecfg (*thome, collection);
     510      return 0;
     511    } else if (!main_cfg_read (recpt, *thome, collection)) {
     512      // couldn't find the main configuration file
     513      page_errormaincfg (*thome, collection);
     514      return 0;
     515    }
     516    thome ++;
    444517  }
    445518
     
    450523  if (!recpt.init(cerr)) {
    451524    // an error occurred during the initialisation
    452     page_errorinit(GSDL_GSDLHOME);
     525    page_errorinit(gsdl_gsdlhome);
    453526    return 0;
    454527  }
     
    465538
    466539static void rememberpref (char *tailstr) {
    467   strcpy(gs_enterlib, tailstr);
    468 
    469   // add "a=p&p=home"
    470   strcat(gs_enterlib, "&a=p&p=home");
     540
     541  //  gsdl_enterlib = tailstr;
    471542}
    472543
     
    493564
    494565  // set up file name
    495   text_t filenamet = text_t(GSDL_GSDLHOME) + filename;
     566  text_t filenamet = text_t(gsdl_gsdlhome) + filename;
    496567  text_t::iterator here = filenamet.begin();
    497568  text_t::iterator end = filenamet.end();
     
    538609  // has been no errors so far
    539610  cgiargsclass args;
    540   if (!recpt.parse_cgi_args (TailStr, args, cerr)) {
    541     page_errorparseargs(GSDL_GSDLHOME);
     611  text_tmap empty; // don't use this (it's for fastcgi on unix)
     612  if (!recpt.parse_cgi_args (TailStr, args, cerr, empty)) {
     613    page_errorparseargs(gsdl_gsdlhome);
    542614    return;
    543615  }
     
    547619  text_t response_data;
    548620
    549   recpt.get_cgihead_info (args, response, response_data, cerr);
    550   char *response_data_c = response_data.getcstr();
     621  recpt.get_cgihead_info (args, response, response_data, cerr, empty);
    551622
    552623  if (response == location) {
    553624    // location response
    554     if (send_header(strcat("@", response_data_c), RInfo) < 0) return;
    555     // textstream << text_t2ascii << "Location: " << response_data << "\n\n";
     625    response_data = "@" + recpt.expandmacros (response_data, args, cerr);
     626    char *response_data_c = response_data.getcstr();
     627    send_header(response_data_c, RInfo);
     628    delete response_data_c;
     629    return;
    556630  } else if (response == content) {
    557631    // content response
    558     if (send_header(response_data_c, RInfo) < 0) return;
     632    char *response_data_c = response_data.getcstr();
     633    if (send_header(response_data_c, RInfo) < 0) {
     634      delete response_data_c;
     635      return;
     636    }
     637    delete response_data_c;
    559638  } else {
    560639    // unknown response
     
    565644  textstream.tsbreset();
    566645  textstream.setrequestinfo (RInfo);
    567   delete response_data_c;
    568646 
    569647  if (!recpt.produce_content (args, cout, cerr)) {
    570     page_errorcgipage(GSDL_GSDLHOME);
     648    page_errorcgipage(gsdl_gsdlhome);
    571649    return;
    572650  }
    573   recpt.log_cgi_args (args, cerr);
     651  recpt.log_cgi_args (args, cerr, empty);
    574652
    575653  cout << flush;
     
    598676    // log the difference in access times
    599677    DWORD thislibaccesstime = GetTickCount();
    600     if (gs_keep_log||gs_show_console) {
     678    if (gsdl_keep_log||gsdl_show_console) {
    601679      sprintf(tmpstr, "DELTA LIB ACCESS TIME: %i\n", (int)(thislibaccesstime - lastlibaccesstime));
    602680      log_message (tmpstr);
     
    605683   
    606684    // log this request
    607     if (gs_keep_log||gs_show_console) {
     685    if (gsdl_keep_log||gsdl_show_console) {
    608686      sprintf (tmpstr, "LOCAL LIB: %s\n", tailstr);
    609687      log_message (tmpstr);
     
    616694   
    617695    // log memory information
    618     if (gs_keep_log||gs_show_console) {
     696    if (gsdl_keep_log||gsdl_show_console) {
    619697      MEMORYSTATUS memstatus;
    620698      memstatus.dwLength = sizeof(MEMORYSTATUS);
     
    627705  } else {
    628706    // local file
    629     if (gs_keep_log||gs_show_console) {
     707    if (gsdl_keep_log||gsdl_show_console) {
    630708      sprintf (tmpstr, "LOCAL FILE: %s\n", tailstr);
    631709      log_message (tmpstr);
Note: See TracChangeset for help on using the changeset viewer.