Ignore:
Timestamp:
1999-02-22T11:33:58+13:00 (25 years ago)
Author:
rjmcnab
Message:

Lots of stuff :-)

File:
1 edited

Legend:

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

    r158 r165  
    1212/*
    1313   $Log$
     14   Revision 1.7  1999/02/21 22:33:55  rjmcnab
     15
     16   Lots of stuff :-)
     17
    1418   Revision 1.6  1999/02/11 01:24:05  rjmcnab
    1519
     
    4448
    4549
    46 // this version of set_gsdlhome should be used if the receptionist
    47 // is being run for multiple collections ("general" mode).
    48 void receptionist::set_gsdlhome (const text_t &thegsdlhome) {
    49   gsdlhome = thegsdlhome;
    50   collectdir = thegsdlhome;
    51   collection = "";
    52 }
    53 
    54 
    55 // this version of set_gsdlhome should be used if the receptionist
    56 // is being run for a single collection ("collection specific" mode).
    57 void receptionist::set_gsdlhome (const text_t &thegsdlhome, const text_t &thecollection) {
    58   gsdlhome = thegsdlhome;
    59   collection = thecollection;
    60 
    61   // decide where collectdir is by searching for collect.cfg
    62   // look in $GSDLHOME/collect/collection-name/etc/collect.cfg and
    63   // then $GSDLHOME/etc/collect.cfg
    64   collectdir = filename_cat (gsdlhome, "collect");
    65   collectdir = filename_cat (collectdir, collection);
    66   text_t filename = filename_cat (collectdir, "etc");
    67   filename = filename_cat (filename, "collect.cfg");
    68 
    69   if (!file_exists(filename)) collectdir = gsdlhome;
    70 }
    71 
    72 // configure_actions should be called for each line in the
    73 // configuration files to configure the actions. The configuration
    74 // should take place after all the actions have been added.
    75 void receptionist::configure_actions (const text_t &key, const text_tarray &cfgline) {
    76   actionptrmap::iterator here = actions.begin ();
    77   actionptrmap::iterator end = actions.end ();
    78 
    79   while (here != end) {
    80     assert ((*here).second.a != NULL);
    81     if ((*here).second.a != NULL)
    82       (*here).second.a->configure(key, cfgline);
    83 
    84     here++;
    85   }
    86 }
    87 
    88 // init should be called after setgsdhome has been called.
     50
     51// configure should be called for each line in the
     52// configuration files to configure the receptionist and everything
     53// it contains. The configuration should take place after everything
     54// has been added but before the initialisation.
     55void receptionist::configure (const text_t &key, const text_tarray &cfgline) {
     56  // configure the receptionist
     57  if (cfgline.size() >= 1) {
     58    if (key == "gsdlhome") configinfo.gsdlhome = cfgline[0];
     59    else if (key == "collection") configinfo.collection = cfgline[0];
     60    else if (key == "collectdir") configinfo.collectdir = cfgline[0];
     61    else if (key == "httpimg") configinfo.httpimg = cfgline[0];
     62    else if (key == "gwcgi") configinfo.gwcgi = cfgline[0];
     63    else if (key == "macrofiles") configinfo.macrofiles = cfgline;
     64    else if (key == "saveconf") configinfo.saveconf = cfgline[0];
     65  }
     66
     67  // configure the actions
     68  actionptrmap::iterator actionhere = actions.begin ();
     69  actionptrmap::iterator actionend = actions.end ();
     70
     71  while (actionhere != actionend) {
     72    assert ((*actionhere).second.a != NULL);
     73    if ((*actionhere).second.a != NULL)
     74      (*actionhere).second.a->configure(key, cfgline);
     75
     76    actionhere++;
     77  }
     78
     79  // configure the protocols
     80  recptprotolistclass::iterator protohere = protocols.begin ();
     81  recptprotolistclass::iterator protoend = protocols.end ();
     82
     83  while (protohere != protoend) {
     84    assert ((*protohere).p != NULL);
     85    if ((*protohere).p != NULL)
     86      (*protohere).p->configure(key, cfgline);
     87   
     88    protohere++;
     89  }
     90}
     91
     92void receptionist::configure (const text_t &key, const text_t &value) {
     93  text_tarray cfgline;
     94  cfgline.push_back (value);
     95  configure(key, cfgline);
     96}
     97
     98
     99// init should be called after all the actions, protocols, and
     100// converters have been added to the receptionist and after everything
     101// has been configured but before any pages are created.
    89102// It returns true on success and false on failure. If false is
    90103// returned getpage should not be called (without producing
     
    92105// produced by the calling code.
    93106bool receptionist::init (ostream &logout) {
     107  // first configure collectdir
     108  text_t thecollectdir = configinfo.gsdlhome;
     109  if (!configinfo.collection.empty()) {
     110    // collection specific mode
     111    if (!configinfo.collectdir.empty()) {
     112      // has already been configured
     113      thecollectdir = configinfo.collectdir;
     114    } else {
     115      // decide where collectdir is by searching for collect.cfg
     116      // look in $GSDLHOME/collect/collection-name/etc/collect.cfg and
     117      // then $GSDLHOME/etc/collect.cfg
     118      text_t thecollectdir = filename_cat (configinfo.gsdlhome, "collect");
     119      thecollectdir = filename_cat (thecollectdir, configinfo.collection);
     120      text_t filename = filename_cat (thecollectdir, "etc");
     121      filename = filename_cat (filename, "collect.cfg");
     122      if (!file_exists(filename)) thecollectdir = configinfo.gsdlhome;
     123    }
     124  }
     125  configure("collectdir", thecollectdir);
     126
    94127  // read in the macro files
    95128  if (!read_macrofiles (logout)) return false;
     
    97130  // defined the main cgi arguments
    98131  if (!define_mainargs (logout)) return false;
     132
     133  // there must be at least one action defined
     134  if (actions.empty()) {
     135    logout << "Error: no actions have been added to the receptionist\n";
     136    return false;
     137  }
    99138
    100139  // add the cgi arguments from the actions
     
    111150
    112151  // create a saveconf string if there isn't one already
    113   if (saveconf.empty())
    114     saveconf = create_save_conf_str (argsinfo, logout);
     152  if (configinfo.saveconf.empty())
     153    configinfo.saveconf = create_save_conf_str (argsinfo, logout);
    115154
    116155  // check the saveconf string
    117   if (!check_save_conf_str (saveconf, argsinfo, logout))
     156  if (!check_save_conf_str (configinfo.saveconf, argsinfo, logout))
    118157    return false;
    119158
     
    121160  srand (time(NULL));
    122161
    123   //  utf8outconvert.set_rzws(1);
    124   //  gboutconvert.set_rzws(1);
     162  // make the output converters remove all the zero-width spaces
     163  convertinfoclass::iterator converthere = converters.begin ();
     164  convertinfoclass::iterator convertend = converters.end ();
     165  text_t defaultconvertname;
     166  while (converthere != convertend) {
     167    assert ((*converthere).second.outconverter != NULL);
     168    if ((*converthere).second.outconverter != NULL) {
     169      (*converthere).second.outconverter->set_rzws(1);
     170      if (defaultconvertname.empty())
     171    defaultconvertname = (*converthere).second.name;
     172    }
     173    converthere++;
     174  }
     175
     176  // set default converter if no good one has been defined
     177  if (!defaultconvertname.empty()) {
     178    cgiarginfo *ainfo = argsinfo.getarginfo ("w");
     179    if ((ainfo != NULL) && (ainfo->defaultstatus < cgiarginfo::good)) {
     180      ainfo->defaultstatus = cgiarginfo::good;
     181      ainfo->argdefault = defaultconvertname;
     182    }
     183  }
     184 
     185  // init the actions
     186  actionptrmap::iterator actionhere = actions.begin ();
     187  actionptrmap::iterator actionend = actions.end ();
     188  while (actionhere != actionend) {
     189    if (((*actionhere).second.a == NULL) ||
     190    !(*actionhere).second.a->init(logout)) return false;
     191    actionhere++;
     192  }
     193
     194  // init the protocols
     195  recptprotolistclass::iterator protohere = protocols.begin ();
     196  recptprotolistclass::iterator protoend = protocols.end ();
     197  while (protohere != protoend) {
     198    if (((*protohere).p == NULL) ||
     199    !(*protohere).p->init(logout)) return false;
     200    protohere++;
     201  }
    125202
    126203  return true;
     
    140217
    141218  // expand the compressed argument (if there was one)
    142   if (!expand_save_args (argsinfo, saveconf, args, logout)) return false;
     219  if (!expand_save_args (argsinfo, configinfo.saveconf, args, logout)) return false;
    143220
    144221  // add the defaults
     
    158235    return false;
    159236  }
     237
     238  // get the input encoding
     239  text_t &arg_w = args["w"];
     240  inconvertclass defaultinconvert;
     241  inconvertclass *inconvert = converters.get_inconverter (arg_w);
     242  if (inconvert == NULL) inconvert = &defaultinconvert;
     243
     244  // see if the next page will have a different encoding
     245  if (args.getarg("nw") != NULL) args["w"] = args["nw"];
     246
     247  // convert arguments which aren't in unicode to unicode
     248  args_tounicode (args, *inconvert);
    160249
    161250  return true;
     
    224313bool receptionist::produce_content (cgiargsclass &args, ostream &contentout,
    225314                    ostream &logout) {
    226   outconvertclass text_t2ascii;
    227 
    228315  // decide on the output conversion class
     316  text_t &arg_w = args["w"];
     317  rzwsoutconvertclass defaultoutconverter;
     318  rzwsoutconvertclass *outconverter = converters.get_outconverter (arg_w);
     319  if (outconverter == NULL) outconverter = &defaultoutconverter;
     320  outconverter->reset();
     321
     322  // decide on the protocol used for communicating with
     323  // the collection server
     324  recptproto *collectproto = NULL;
     325  if (!args["c"].empty()) {
     326    collectproto = protocols.getrecptproto (args["c"], logout);
     327  }
    229328
    230329  // produce the page using the desired action
    231330  action *a = actions.getaction (args["a"]);
    232331  if (a != NULL) {
    233     if (!a->do_action (args, text_t2ascii, contentout, logout))
     332    if (!a->do_action (args, (*outconverter), collectproto, contentout, logout))
    234333      return false;
    235334
    236335  } else {
    237336    // the action was not found!!
     337    outconvertclass text_t2ascii;
     338
    238339    logout << text_t2ascii << "Error receptionist::produce_content: the action \""
    239340       << args["a"] << "\" could not be found.\n";
    240341   
    241     contentout << text_t2ascii << "<html>\n";
    242     contentout << text_t2ascii << "<head>\n";
    243     contentout << text_t2ascii << "<title>Error</title>\n";
    244     contentout << text_t2ascii << "</head>\n";
    245     contentout << text_t2ascii << "<body>\n";
    246     contentout << text_t2ascii << "<h2>Oops!</h2>\n";
    247     contentout << text_t2ascii << "Undefined Page. The action \""
    248            << args["a"] << "\" could not be found.\n";
    249     contentout << text_t2ascii << "</body>\n";
    250     contentout << text_t2ascii << "</html>\n";
     342    contentout << (*outconverter)
     343           << "<html>\n"
     344           << "<head>\n"
     345           << "<title>Error</title>\n"
     346           << "</head>\n"
     347           << "<body>\n"
     348           << "<h2>Oops!</h2>\n"
     349           << "Undefined Page. The action \""
     350           << args["a"] << "\" could not be found.\n"
     351           << "</body>\n"
     352           << "</html>\n";
    251353  }
    252354
     
    274376  // is searched first for the file (if this is being used in
    275377  // collection specific mode) and then the main directory
    276   text_t colmacrodir = filename_cat (collectdir, "macros");
    277   text_t gsdlmacrodir = filename_cat (gsdlhome, "macros");
    278   text_tarray::iterator arrhere = macrofiles.begin();
    279   text_tarray::iterator arrend = macrofiles.end();
     378  text_t colmacrodir = filename_cat (configinfo.collectdir, "macros");
     379  text_t gsdlmacrodir = filename_cat (configinfo.gsdlhome, "macros");
     380  text_tarray::iterator arrhere = configinfo.macrofiles.begin();
     381  text_tarray::iterator arrend = configinfo.macrofiles.end();
    280382  text_t filename;
    281383  while (arrhere != arrend) {
     
    286388    // try in the collection directory if this is being
    287389    // run in collection specific mode
    288     if (!collection.empty()) {
     390    if (!configinfo.collection.empty()) {
    289391      filename = filename_cat (colmacrodir, *arrhere);
    290392      if (!file_exists (filename)) filename.clear ();
     
    302404      logout << text_t2ascii
    303405         << "Error: the macro file \"" << *arrhere << "\" could not be found.\n";
    304       if (collection.empty()) {
     406      if (configinfo.collection.empty()) {
    305407    logout << text_t2ascii
    306408           << "It should be in " << gsdlmacrodir << ".\n\n";
     
    367469  ainfo.longname = "collection";
    368470  ainfo.multiplechar = true;
    369   if (collection.empty()) {
     471  if (configinfo.collection.empty()) {
    370472    ainfo.defaultstatus = cgiarginfo::none;
    371473    ainfo.argdefault = "";
     
    373475  } else {
    374476    ainfo.defaultstatus = cgiarginfo::good;
    375     ainfo.argdefault = collection;
     477    ainfo.argdefault = configinfo.collection;
    376478    ainfo.savedarginfo = cgiarginfo::can;
    377479  }
     
    417519  // then it should always set the collection argument to the
    418520  // collection
    419   if (!collection.empty()) args["c"] = collection;
     521  if (!configinfo.collection.empty()) args["c"] = configinfo.collection;
    420522
    421523  // argument "v" can only be 0 or 1. Use the default value
Note: See TracChangeset for help on using the changeset viewer.