Changeset 799 for trunk


Ignore:
Timestamp:
1999-12-06T10:21:04+13:00 (24 years ago)
Author:
sjboddie
Message:

added support for multiple gsdlhomes and gdbmhomes

Location:
trunk/gsdl/src/recpt
Files:
2 edited

Legend:

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

    r789 r799  
    2828/*
    2929   $Log$
     30   Revision 1.42  1999/12/05 21:21:04  sjboddie
     31   added support for multiple gsdlhomes and gdbmhomes
     32
    3033   Revision 1.41  1999/11/25 21:44:16  sjboddie
    3134   fixed bug in logout
     
    220223void recptconf::clear () {
    221224  gsdlhome.clear();
     225  gdbmhome.clear();
     226  collectinfo.clear();
    222227  collection.clear();
    223228  collectdir.clear();
     
    360365    else if (key == "httpimg") configinfo.httpimg = cfgline[0];
    361366    else if (key == "gwcgi") configinfo.gwcgi = cfgline[0];
    362     else if (key == "macrofiles") configinfo.macrofiles = cfgline;
     367    else if (key == "macrofiles") {
     368      // want to append to macrofiles (i.e. may be several config files
     369      // contributing, maybe from several collections).
     370      text_tarray::const_iterator here = cfgline.begin();
     371      text_tarray::const_iterator end = cfgline.end();
     372      while (here != end) {
     373    configinfo.macrofiles.insert (*here);
     374    here ++;
     375      }
     376    }
    363377    else if (key == "saveconf") configinfo.saveconf = cfgline[0];
    364378    else if (key == "usecookies") configinfo.usecookies = (cfgline[0] == "true");
     
    369383    }
    370384    else if (key == "macroprecedence") configinfo.macroprecedence = cfgline[0];
    371 
     385    else if (key == "collectinfo") {
     386      if (cfgline.size() >= 3) {
     387    collectioninfo_t cinfo;
     388    cinfo.gsdl_gsdlhome = cfgline[1];
     389    cinfo.gsdl_gdbmhome = cfgline[2];
     390    configinfo.collectinfo[cfgline[0]] = cinfo;
     391      }
     392    }
    372393   
    373394    else if (key == "cgiarg") {
     
    771792}
    772793
     794text_t receptionist::expandmacros (const text_t &astring, cgiargsclass &args,
     795                   ostream &logout) {
     796  text_t outstring;
     797  outconvertclass text_t2ascii;
     798
     799  action *a = actions.getaction (args["a"]);
     800  prepare_page (a, args, text_t2ascii, logout);
     801  disp.expandstring ("Global", astring, outstring);
     802  return outstring;
     803}
     804
    773805// produce_cgi_page will call get_cgihead_info and
    774806// produce_content in the appropriate way to output a cgi header and
     
    786818  if (response == location) {
    787819    // location response (url may contain macros!!)
    788     text_t ex_location;
    789     action *a = actions.getaction (args["a"]);
    790     prepare_page (a, args, text_t2ascii, logout);
    791     disp.expandstring ("Global", response_data, ex_location);
    792     contentout << text_t2ascii << "Location: " << ex_location << "\n\n";
     820    response_data = expandmacros (response_data, args, logout);
     821    contentout << text_t2ascii << "Location: " << response_data << "\n\n";
    793822    contentout << flush;
    794823    return true;
     
    854883bool receptionist::produce_content (cgiargsclass &args, ostream &contentout,
    855884                    ostream &logout) {
     885 
    856886  // decide on the output conversion class
    857887  text_t &arg_w = args["w"];
     
    860890  if (outconverter == NULL) outconverter = &defaultoutconverter;
    861891  outconverter->reset();
     892
    862893
    863894  recptproto *collectproto = protocols.getrecptproto (args["c"], logout);
     
    916947           << "</html>\n";
    917948  }
    918 
    919949  return true;
    920950}
     
    951981  // load up the default macro files, the collection directory
    952982  // is searched first for the file (if this is being used in
    953   // collection specific mode) and then the main directory
     983  // collection specific mode) and then the main directory(s)
    954984  text_t colmacrodir = filename_cat (configinfo.collectdir, "macros");
     985
     986  text_tarray maindirs;
    955987  text_t gsdlmacrodir = filename_cat (configinfo.gsdlhome, "macros");
    956   text_tarray::iterator arrhere = configinfo.macrofiles.begin();
    957   text_tarray::iterator arrend = configinfo.macrofiles.end();
     988  maindirs.push_back (gsdlmacrodir);
     989  colinfo_tmap::iterator colhere = configinfo.collectinfo.begin();
     990  colinfo_tmap::iterator colend = configinfo.collectinfo.end();
     991  while (colhere != colend) {
     992    gsdlmacrodir = filename_cat ((*colhere).second.gsdl_gsdlhome, "macros");
     993    maindirs.push_back (gsdlmacrodir);
     994    colhere ++;
     995  }
     996
     997  text_tset::iterator arrhere = configinfo.macrofiles.begin();
     998  text_tset::iterator arrend = configinfo.macrofiles.end();
    958999  text_t filename;
    9591000  while (arrhere != arrend) {
    960     // filename is used as a flag to indicate whether
    961     // the macro file has been found
    962     filename.clear();
     1001    bool foundfile = false;
    9631002
    9641003    // try in the collection directory if this is being
     
    9661005    if (!configinfo.collection.empty()) {
    9671006      filename = filename_cat (colmacrodir, *arrhere);
    968       if (!file_exists (filename)) filename.clear ();
     1007      if (file_exists (filename)) {
     1008    disp.loaddefaultmacros(filename);
     1009    foundfile = true;
     1010      }
    9691011    }
    9701012
    9711013    // if we haven't found the macro file yet try in
    972     // the main macro directory
    973     if (filename.empty()) {
    974       filename = filename_cat (gsdlmacrodir, *arrhere);
    975       if (!file_exists (filename)) filename.clear ();
     1014    // the main macro directory(s)
     1015    // if file is found in more than one main directory
     1016    // we'll load all copies
     1017    if (!foundfile) {
     1018      text_tarray::const_iterator dirhere = maindirs.begin();
     1019      text_tarray::const_iterator dirend = maindirs.end();
     1020      while (dirhere != dirend) {
     1021    filename = filename_cat (*dirhere, *arrhere);
     1022    if (file_exists (filename)) {
     1023      disp.loaddefaultmacros(filename);
     1024      foundfile = true;
     1025    }
     1026    dirhere ++;
     1027      }
    9761028    }
    9771029
    9781030    // see if we found the file or not
    979     if (filename.empty()) {
     1031    if (!foundfile) {
    9801032      logout << text_t2ascii
    9811033         << "Error: the macro file \"" << *arrhere << "\" could not be found.\n";
    9821034      if (configinfo.collection.empty()) {
    983     logout << text_t2ascii
    984            << "It should be in " << gsdlmacrodir << ".\n\n";
     1035    text_t dirs;
     1036    joinchar (maindirs, ", ", dirs);
     1037    logout << text_t2ascii
     1038           << "It should be in either of the following directories ("
     1039           << dirs << ").\n\n";
     1040
    9851041      } else {
    9861042    logout << text_t2ascii
     
    9911047      disp.setlogout (savedlogout);
    9921048      return false;
    993 
    994     } else { // found the file
    995       disp.loaddefaultmacros(filename);
    996     }
    997 
     1049    }
    9981050    arrhere++;
    9991051  }
     
    10101062// error is found it will return false and no cgi page should
    10111063// be created using the arguments.
    1012 bool receptionist::check_mainargs (cgiargsclass &args, ostream &/*logout*/) {
     1064bool receptionist::check_mainargs (cgiargsclass &args, ostream &logout) {
    10131065  // if this receptionist is running in collection dependant mode
    10141066  // then it should always set the collection argument to the
    10151067  // collection
    10161068  if (!configinfo.collection.empty()) args["c"] = configinfo.collection;
     1069
     1070  // if cross-collection is turned on make "cc" default to
     1071  // all available collections and "c" default to any
     1072  // valid collection
     1073  if (args["ccs"] == "1") {
     1074    if (args["cc"].empty()) {
     1075      recptprotolistclass::iterator rprotolist_here = protocols.begin();
     1076      recptprotolistclass::iterator rprotolist_end = protocols.end();
     1077      bool first = true;
     1078      while (rprotolist_here != rprotolist_end) {
     1079    if ((*rprotolist_here).p != NULL) {
     1080      text_tarray collist;
     1081      comerror_t err;
     1082      (*rprotolist_here).p->get_collection_list (collist, err, logout);
     1083      if (err == noError) {
     1084        text_tarray::iterator collist_here = collist.begin();
     1085        text_tarray::iterator collist_end = collist.end();
     1086        while (collist_here != collist_end) {
     1087          if (!first) args["cc"].push_back (',');
     1088          else if (args["c"].empty()) args["c"] = *collist_here;
     1089          args["cc"] += *collist_here;
     1090          first = false;
     1091          collist_here ++;
     1092        }
     1093      }
     1094    }
     1095    rprotolist_here ++;
     1096      }
     1097    } else if (args["c"].empty()) {
     1098      text_t argcc = args["cc"];
     1099      decode_cgi_arg (argcc);
     1100      text_t::const_iterator it = argcc.begin();
     1101      args["c"] = substr (it, findchar (it, argcc.end(), ','));
     1102    }
     1103  }
    10171104
    10181105  // argument "v" can only be 0 or 1. Use the default value
  • trunk/gsdl/src/recpt/receptionist.h

    r760 r799  
    3838#include "recptproto.h"
    3939#include "converter.h"
     40#include "cfgread.h"
    4041
    4142// the MACROPRECEDENCE macro is used as a default. override
     
    5253struct recptconf {
    5354  text_t gsdlhome;
     55  text_t gdbmhome;   // will equal gsdlhome if not set
    5456  text_t collection; // will equal "" in 'general' mode
    5557  text_t collectdir; // will equal gsdlhome in 'general' mode
     58  colinfo_tmap collectinfo;
    5659  text_t httpprefix;
    5760  text_t httpimg;
    5861  text_t gwcgi;
    59   text_tarray macrofiles;
     62  text_tset macrofiles;
    6063  text_t saveconf;
    6164  bool usecookies;  // true if we want cookies set
     
    166169  virtual bool log_cgi_args (cgiargsclass &args, ostream &logout);
    167170
     171  text_t expandmacros (const text_t &astring, cgiargsclass &args,
     172               ostream &logout);
     173
    168174  // produce_cgi_page will call get_cgihead_info and
    169175  // produce_content in the appropriate way to output a cgi header and
Note: See TracChangeset for help on using the changeset viewer.