Changeset 150 for trunk/gsdl/src/recpt


Ignore:
Timestamp:
1999-02-05T23:42:50+13:00 (25 years ago)
Author:
rjmcnab
Message:

Continued working on receptionist

Location:
trunk/gsdl/src/recpt
Files:
2 added
2 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/src/recpt/action.cpp

    r146 r150  
    1212/*
    1313   $Log$
     14   Revision 1.3  1999/02/05 10:42:41  rjmcnab
     15
     16   Continued working on receptionist
     17
    1418   Revision 1.2  1999/02/04 10:00:53  rjmcnab
    1519
     
    8488  aptr.a = theaction;
    8589  actionptrs[theaction->get_action_name()] = aptr;
     90  aptr.a = NULL; // control has passed on
    8691}
    8792
  • trunk/gsdl/src/recpt/cgiargs.cpp

    r146 r150  
    1212/*
    1313   $Log$
     14   Revision 1.4  1999/02/05 10:42:41  rjmcnab
     15
     16   Continued working on receptionist
     17
    1418   Revision 1.3  1999/02/04 10:00:54  rjmcnab
    1519
     
    157161       << "\" was defined as being a single character option\n"
    158162       << "but a multiple character default was given.\n\n";
    159   }
     163    return false;  // found a problem
     164  }
     165
     166  // make sure there is no clashes in the savedarginfo
     167  if ((orginfo->savedarginfo==cgiarginfo::mustnot &&
     168       info.savedarginfo==cgiarginfo::must) ||
     169      (orginfo->savedarginfo==cgiarginfo::must &&
     170       info.savedarginfo==cgiarginfo::mustnot)) {
     171    logout << text_t2ascii << "Error: it was specified that cgi argument \""
     172       << info.shortname << "\" should be saved in the state\n"
     173       << "information and that it should not be save in the state information.\n\n";
     174    return false; // found a clash
     175  }
     176  // the only time orginfo->savedarginfo can change is when it is set
     177  // to "can"
     178  if (orginfo->savedarginfo == cgiarginfo::can)
     179    orginfo->savedarginfo = info.savedarginfo;
     180
    160181
    161182  if (orginfo->defaultstatus > info.defaultstatus) {
    162183    return true;
    163184  }
    164 
    165185  orginfo->defaultstatus = info.defaultstatus;
    166186  orginfo->argdefault = info.argdefault;
     187
    167188  return true;
    168189}
     
    187208}
    188209
     210const cgiarginfo *cgiargsinfoclass::getarginfo (const text_t &key) const {
     211  const_iterator here = argsinfo.find (key);
     212  if (here == argsinfo.end()) return NULL;
     213
     214  return &((*here).second);
     215}
     216
     217
     218
     219// utilities related to cgi arguments
     220
     221
     222static text_t::const_iterator get_next_save_arg (text_t::const_iterator first,
     223                       text_t::const_iterator last,
     224                       text_t &argname) {
     225  first = getdelimitstr (first, last, '-', argname);
     226  return first;
     227}
     228
     229
     230
     231
     232
     233// check_save_conf_str checks the configuration string for
     234// the saved args and makes sure it does not conflict with
     235// the information about the arguments. If an error is encountered
     236// it will return false and the program should not produce any
     237// output.
     238bool check_save_conf_str (const text_t &saveconf,
     239              const cgiargsinfoclass &argsinfo,
     240              ostream &logout) {
     241  outconvertclass text_t2ascii;
     242
     243  text_tset argsset;
     244  text_t::const_iterator saveconfhere = saveconf.begin ();
     245  text_t::const_iterator saveconfend = saveconf.end ();
     246  text_t argname;
     247  const cgiarginfo *info;
     248
     249  // first check to make sure all saved arguments can be saved
     250 
     251  while (saveconfhere != saveconfend) {
     252    saveconfhere = get_next_save_arg (saveconfhere, saveconfend, argname);
     253
     254    if (!argname.empty()) {
     255      // save the argument name for later
     256      argsset.insert (argname);
     257
     258      // check the argument
     259      info =  argsinfo.getarginfo (argname);
     260      if (info == NULL) {
     261    logout << text_t2ascii << "Error: the cgi argument \"" << argname
     262           << "\" is used in the configuration string for the\n"
     263           << "saved arguments but does not exist as a valid argument.\n\n";
     264    return false;
     265      }
     266      if (info->savedarginfo == cgiarginfo::mustnot) {
     267    logout << text_t2ascii << "Error: the cgi argument \"" << argname
     268           << "\" is used in the configuration string for the\n"
     269           << "saved arguments but has been specified as an argument whose\n"
     270           << "state must not be saved.\n\n";
     271    return false;
     272      }
     273    }
     274  }
     275
     276
     277  // next check that all saved arguments that should be saved
     278  // are saved
     279  cgiargsinfoclass::const_iterator argsinfohere = argsinfo.begin ();
     280  cgiargsinfoclass::const_iterator argsinfoend = argsinfo.end ();
     281
     282  while (argsinfohere != argsinfoend) {
     283    if (((*argsinfohere).second.savedarginfo == cgiarginfo::must) &&
     284    (argsset.find((*argsinfohere).second.shortname) == argsset.end())) {
     285      logout << text_t2ascii << "Error: the cgi argument \""
     286         << (*argsinfohere).second.shortname << "\" was specified as needing to\n"
     287         << "be save but was not listed in the saved arguments.\n\n";
     288      return false;
     289    }
     290
     291    argsinfohere++;
     292  }
     293 
     294  return true; // made it, no clashes
     295}
     296
     297
     298
     299// create_save_conf_str will create a configuration string
     300// based on the information in argsinfo. This method of configuration
     301// is not recomended as small changes can produce large changes in
     302// the resulting configuration string (for instance a totally different
     303// ordering)
     304text_t create_save_conf_str (const cgiargsinfoclass &argsinfo,
     305                 ostream &logout);
     306
     307// expand_save_args will expand the saved arguments based
     308// on saveconf placing the results in args if they are not
     309// already defined. If it encounters an error it will return false
     310// and output more information to logout.
     311bool expand_save_args (const text_t &saveconf,
     312               cgiargsclass &args,
     313               ostream &logout);
     314
     315// adds the default values for those arguments which have not
     316// been specified
     317void add_default_args (const cgiargsinfoclass &argsinfo,
     318               cgiargsclass &args,
     319               ostream &logout);
     320
  • trunk/gsdl/src/recpt/cgiargs.h

    r146 r150  
    124124  defaultstatus_t defaultstatus;
    125125  text_t argdefault;   // a default value
     126
     127  // savedarginfo_t indicates whether the argument should be saved
     128  // between pages (e.g. using the compressed argument) or not. The
     129  // value of an argument can change from "can" to "mustnot" and
     130  // "can" to "must" but not "mustnot" to "must" or "must" to "mustnot".
     131  enum savedarginfo_t {mustnot, can, must};
     132
     133  savedarginfo_t savedarginfo;
    126134};
    127135
     
    174182
    175183  cgiarginfo *getarginfo (const text_t &key);
     184  const cgiarginfo *getarginfo (const text_t &key) const;
    176185  cgiarginfo &operator[] (const text_t &key) {return argsinfo[key];}
    177186};
     
    179188
    180189
     190// utilities related to cgi arguments
     191
     192// check_compress_conf_str checks the configuration string for
     193// the compressed args and makes sure it does not conflict with
     194// the information about the arguments. If an error is encountered
     195// it will return false and the program should not produce any
     196// output.
     197bool check_compress_conf_str (const text_t &compressconf,
     198                  const cgiargsinfoclass &argsinfo,
     199                  ostream &logout);
     200
     201// create_compress_conf_str will create a configuration string
     202// based on the information in argsinfo. This method of configuration
     203// is not recomended as small changes can produce large changes in
     204// the resulting configuration string (for instance a totally different
     205// ordering)
     206text_t create_compress_conf_str (const cgiargsinfoclass &argsinfo,
     207                 ostream &logout);
     208
     209// expand_compress_args will expand the compressed arguments based
     210// on compressconf placing the results in args if they are not
     211// already defined. If it encounters an error it will return false
     212// and output more information to logout.
     213bool expand_compress_args (const text_t &compressconf,
     214               cgiargsclass &args,
     215               ostream &logout);
     216
     217// adds the default values for those arguments which have not
     218// been specified
     219void add_default_args (const cgiargsinfoclass &argsinfo,
     220               cgiargsclass &args,
     221               ostream &logout);
     222
     223
    181224#endif
  • trunk/gsdl/src/recpt/cgiutils.cpp

    r108 r150  
    1212/*
    1313   $Log$
     14   Revision 1.2  1999/02/05 10:42:43  rjmcnab
     15
     16   Continued working on receptionist
     17
    1418   Revision 1.1  1999/01/08 08:40:56  rjmcnab
    1519
     
    2125
    2226 */
    23 
    24 static char *RCSID = "$Id$";
    2527
    2628
     
    128130    } else if (c == ' ') {
    129131      // space
    130       outtext.push_back("+");
     132      outtext.push_back('+');
    131133    } else {
    132134      // everything else
  • trunk/gsdl/src/recpt/cgiwrapper.cpp

    r146 r150  
    1212/*
    1313   $Log$
     14   Revision 1.3  1999/02/05 10:42:44  rjmcnab
     15
     16   Continued working on receptionist
     17
    1418   Revision 1.2  1999/02/04 10:00:56  rjmcnab
    1519
     
    3438#include "gsdlconf.h"
    3539#include "cgiwrapper.h"
     40#include "recptconfig.h"
    3641#include <stdlib.h>
     42
    3743
    3844#if defined(GSDL_USE_OBJECTSPACE)
     
    4753#endif
    4854
    49 #include "cfgread.h"
    50 #include "fileutil.h"
    51 
    5255#ifdef USE_FASTCGI
    5356#include "fcgiapp.h"
     
    108111
    109112
    110 // returns true on success
    111 static bool site_cfg_read (receptionist &recpt, const text_t &collection,
    112                const text_t &filename, int &maxrequests) {
    113   text_tarray cfgline;
    114   char *cstr = filename.getcstr();
    115   ifstream confin (cstr);
    116   delete cstr;
    117 
    118   maxrequests = 10000;
    119 
    120   if (confin) {
    121     while (read_cfg_line(confin, cfgline) >= 0) {
    122       if (cfgline.size () >= 2) {
    123     if (cfgline[0] == "gsdlhome") {
    124       if (collection.empty()) recpt.set_gsdlhome(cfgline[1]);
    125       else recpt.set_gsdlhome(cfgline[1], collection);
    126     }
    127     else if (cfgline[0] == "httpimg") recpt.set_httpimg(cfgline[1]);
    128     else if (cfgline[0] == "gwcgi") recpt.set_gwcgi(cfgline[1]);
    129     else if (cfgline[0] == "maxrequests") {
    130       maxrequests = cfgline[1].getint();
    131       if (maxrequests < 1) maxrequests = 1;
    132     }
    133       }
    134     }
    135     confin.close ();
    136     return true;
    137   }
    138   return false;
    139 }
    140 
    141 
    142 static void page_errorconfigfile (const text_t &collection) {
     113static void page_errorsitecfg (const text_t &gsdlhome, const text_t &collection) {
     114  outconvertclass text_t2ascii;
     115
    143116  cout << "Content-type: text/html\n\n";
    144117
     
    154127  if (collection.empty()) {
    155128    cout << "As this cgi script is not being run in collection specific mode,\n";
    156     cout << "the file should reside at " GSDL_GSDLHOME "/etc/site.cfg.\n";
     129    cout << "the file should reside at ";
     130    cout << text_t2ascii << gsdlhome;
     131    cout << "/etc/site.cfg.\n";
    157132  } else {
    158     char *cstr = collection.getcstr();
    159133    cout << "As this cgi script is being run in collection specific mode,\n";
    160     cout << "the file can reside in " GSDL_GSDLHOME "/collect/" << cstr
    161      << "/etc/site.cfg or " GSDL_GSDLHOME "/etc/site.cfg.\n";
    162     delete cstr;
     134    cout << text_t2ascii << "the file can reside in " << gsdlhome << "/collect/"
     135     << collection << "/etc/site.cfg or " << gsdlhome << "/etc/site.cfg.\n";
    163136  }
    164137  cout << "</body>\n";
     
    167140
    168141
    169 static void page_errorinit () {
     142static void page_errormaincfg (const text_t &gsdlhome, const text_t &collection) {
     143  outconvertclass text_t2ascii;
     144
     145  cout << "Content-type: text/html\n\n";
     146
     147  cout << "<html>\n";
     148  cout << "<head>\n";
     149  cout << "<title>Error</title>\n";
     150  cout << "</head>\n";
     151  cout << "<body>\n";
     152  cout << "<h2>Oops!</h2>\n";
     153  if (collection.empty()) {
     154    cout << "The main.cfg configuration file could not be found. This file\n";
     155    cout << "should contain configuration information relating to the\n";
     156    cout << "setup of the interface. As this cgi script is not being run\n";
     157    cout << "in collection specific mode the file should reside at\n";
     158    cout << text_t2ascii << gsdlhome << "/etc/main.cfg.\n";
     159  } else {
     160    cout << "Neither the collect.cfg or main.cfg configuration files could\n";
     161    cout << "not be found. This file should contain configuration information\n";
     162    cout << "relating to the setup of the interface. As this cgi script is\n";
     163    cout << "being run in collection specific mode the file should reside\n";
     164    cout << "at either ";
     165    cout << text_t2ascii << gsdlhome << "/collect/" << collection
     166     << "/etc/collect.cfg, " << gsdlhome << "/etc/collect.cfg or "
     167     << gsdlhome << "/etc/main.cfg.\n";
     168  }
     169  cout << "</body>\n";
     170  cout << "</html>\n";
     171}
     172
     173
     174static void page_errorinit (const text_t &gsdlhome) {
     175  outconvertclass text_t2ascii;
     176
    170177  cout << "Content-type: text/html\n\n";
    171178
     
    178185  cout << "An error occurred during the initialisation of the Greenstone Digital\n";
    179186  cout << "Library software. It is likely that the software has not been setup\n";
    180   cout << "correctly, consult " GSDL_GSDLHOME "/etc/initout.txt for more information.\n";
     187  cout << "correctly, consult ";
     188  cout << text_t2ascii << gsdlhome << "/etc/initout.txt for more information.\n";
    181189  cout << "</body>\n";
    182190  cout << "</html>\n";
     
    204212  else recpt.set_gwcgi("/cgi-bin/gw");
    205213
    206   // read in the site configuration file. Try to find it in the
    207   // GSDLHOME/collect/collection-name/etc directory
    208   // (if this is for a particular collection), and then GSDLHOME/etc.
    209   bool configfileread = false;
    210   text_t filename;
    211   if (!collection.empty()) {
    212     filename = filename_cat (GSDL_GSDLHOME, "collect");
    213     filename = filename_cat (filename, collection);
    214     filename = filename_cat (filename, "etc");
    215     filename = filename_cat (filename, "site.cfg");
    216     configfileread = site_cfg_read (recpt, collection, filename, maxrequests);
    217   }
    218   if (!configfileread) {
    219     filename = filename_cat (GSDL_GSDLHOME, "etc");
    220     filename = filename_cat (filename, "site.cfg");
    221     if (!site_cfg_read (recpt, collection, filename, maxrequests)) {
    222       // couldn't find the site configuration file
    223       page_errorconfigfile (collection);
    224       return;
    225     }
     214  // read in the configuration files.
     215  if (!site_cfg_read (recpt, GSDL_GSDLHOME, collection, maxrequests)) {
     216    // couldn't find the site configuration file
     217    page_errorsitecfg (GSDL_GSDLHOME, collection);
     218    return;
     219  }
     220  if (!main_cfg_read (recpt, GSDL_GSDLHOME, collection)) {
     221    // couldn't find the main configuration file
     222    page_errormaincfg (GSDL_GSDLHOME, collection);
     223    return;
    226224  }
    227225
    228226  // initialise the library software
    229227  ofstream initout (GSDL_GSDLHOME "/etc/initout.txt");
    230   if (!recpt.digest(initout)) {
     228  if (!recpt.init(initout)) {
    231229    // an error occurred during the initialisation
    232230    initout.close();
    233     page_errorinit();
     231    page_errorinit(GSDL_GSDLHOME);
    234232    return;
    235233  }
  • trunk/gsdl/src/recpt/receptionist.cpp

    r146 r150  
    1212/*
    1313   $Log$
     14   Revision 1.4  1999/02/05 10:42:46  rjmcnab
     15
     16   Continued working on receptionist
     17
    1418   Revision 1.3  1999/02/04 10:00:56  rjmcnab
    1519
     
    2832#include "fileutil.h"
    2933#include <assert.h>
     34#include <time.h>
    3035
    3136
     
    7883// meaningless output), instead an error page should be
    7984// produced by the calling code.
    80 bool receptionist::digest (ostream &logout) {
     85bool receptionist::init (ostream &logout) {
    8186  // redirect the error output to logout
    8287  //  disp.setlogout (&logout);
     
    8691  //  cfg_info.defaultpage = "about";
    8792  //  cfg_info.defaultencoding = "w";
    88 
    89   // read in the configuration files etc/collect.cfg and index/build.cfg
    90   // entries in build.cfg should override those in collect.cfg
    91   //  filename = filename_cat (collectdir, "etc");
    92   //  filename = filename_cat (filename, "collect.cfg");
    93   //  cfg_read(filename);
    9493
    9594  // load up the default macro files, the collection directory
     
    108107  //  }
    109108
    110   //  srand(time(NULL));
     109  srand(time(NULL));
    111110
    112111  //  utf8outconvert.set_rzws(1);
    113112  //  gboutconvert.set_rzws(1);
    114113
    115   //  return collect_init(collection);
    116114  return true;
    117115}
  • trunk/gsdl/src/recpt/receptionist.h

    r146 r150  
    4747  void set_gwcgi (const text_t &thegwcgi);
    4848
    49   // digest should be called after setgsdhome has been called.
     49  // init should be called after setgsdhome has been called.
    5050  // It returns true on success and false on failure. If false is
    5151  // returned getpage should not be called (without producing
    5252  // meaningless output), instead an error page should be
    5353  // produced by the calling code.
    54   bool digest (ostream &logout);
     54  bool init (ostream &logout);
    5555 
    5656  // There are two ways to produce a page. You can either call parse_cgi_args,
Note: See TracChangeset for help on using the changeset viewer.