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/receptionist.cpp

    r950 r1279  
    2828/*
    2929   $Log$
     30   Revision 1.47.4.1  2000/07/12 22:21:44  sjboddie
     31   merged changes to trunk into New_Config_Format branch
     32
     33   Revision 1.53  2000/07/05 21:49:34  sjboddie
     34   Receptionist now caches collection information to avoid making multiple
     35   get_collectinfo calls to collection server
     36
     37   Revision 1.52  2000/07/04 02:15:22  sjboddie
     38   fixed bug causing segmentation fault when an invalid collection
     39   was supplied as the "c" cgi argument
     40
     41   Revision 1.51  2000/05/28 09:15:34  sjboddie
     42   a few small changes to get an initial release of the local library
     43
     44   Revision 1.50  2000/05/12 03:09:25  sjboddie
     45   minor modifications to get web library compiling under VC++ 6.0
     46
     47   Revision 1.49  2000/05/04 05:18:46  sjboddie
     48   attempting to get end-user collection building to work under windows
     49
     50   Revision 1.48  2000/04/14 02:52:06  sjboddie
     51   tidied up error messaging and set up some debugging info to be output
     52   when running library from command line
     53
    3054   Revision 1.47  2000/02/17 22:26:17  sjboddie
    3155   set macros for displaying macrons in utf8
     
    227251#include "cgiutils.h"
    228252#include "htmlutils.h"
     253#include "gsdltools.h"
    229254#include "OIDtools.h"
    230255#include <assert.h>
    231256#include <time.h>
    232257#include <stdio.h>
     258#if defined (GSDL_USE_IOS_H)
    233259#include <fstream.h>
     260#else
     261#include <fstream>
     262#endif
    234263
    235264#if defined (__WIN32_)
     
    244273  collectdir.clear();
    245274  httpprefix.clear();
    246   httpimg.clear();
     275  httpimg = "/images";
    247276  gwcgi.clear();
    248277  macrofiles.erase(macrofiles.begin(), macrofiles.end());
     
    264293}
    265294
    266 
     295void collectioninfo_t::clear () {
     296  gsdl_gsdlhome.clear();
     297  gsdl_gdbmhome.clear();
     298
     299  info_loaded = false;
     300  info.clear();
     301}
    267302
    268303receptionist::receptionist () {
     
    781816  utf8outconvertclass text_t2utf8;
    782817  char *lfile = filename.getcstr();
     818
    783819  ofstream log (lfile, ios::app);
    784820 
     
    904940bool receptionist::produce_content (cgiargsclass &args, ostream &contentout,
    905941                    ostream &logout) {
    906  
     942
    907943  // decide on the output conversion class
    908944  text_t &arg_w = args["w"];
     
    10051041  text_t colmacrodir = filename_cat (configinfo.collectdir, "macros");
    10061042
    1007   text_tarray maindirs;
     1043  text_tset maindirs;
    10081044  text_t gsdlmacrodir = filename_cat (configinfo.gsdlhome, "macros");
    1009   maindirs.push_back (gsdlmacrodir);
     1045  maindirs.insert (gsdlmacrodir);
    10101046  colinfo_tmap::iterator colhere = configinfo.collectinfo.begin();
    10111047  colinfo_tmap::iterator colend = configinfo.collectinfo.end();
    10121048  while (colhere != colend) {
    1013     gsdlmacrodir = filename_cat ((*colhere).second.gsdl_gsdlhome, "macros");
    1014     maindirs.push_back (gsdlmacrodir);
     1049    if (!((*colhere).second.gsdl_gsdlhome).empty()) {
     1050      gsdlmacrodir = filename_cat ((*colhere).second.gsdl_gsdlhome, "macros");
     1051      maindirs.insert (gsdlmacrodir);
     1052    }
    10151053    colhere ++;
    10161054  }
     
    10371075    // we'll load all copies
    10381076    if (!foundfile) {
    1039       text_tarray::const_iterator dirhere = maindirs.begin();
    1040       text_tarray::const_iterator dirend = maindirs.end();
     1077      text_tset::const_iterator dirhere = maindirs.begin();
     1078      text_tset::const_iterator dirend = maindirs.end();
    10411079      while (dirhere != dirend) {
    10421080    filename = filename_cat (*dirhere, *arrhere);
     
    10951133
    10961134    text_t &arg_c = args["c"];
    1097     ColInfoResponse_t cinfo;
    1098     comerror_t err;
    10991135    recptproto *collectproto = protocols.getrecptproto (arg_c, logout);
    1100     collectproto->get_collectinfo (arg_c, cinfo, err, logout);
    1101 
    1102     if (!cinfo.ccsCols.empty()) {
    1103       args["ccs"] = 1;
    1104       if (args["cc"].empty()) {
    1105     text_tarray::const_iterator col_here = cinfo.ccsCols.begin();
    1106     text_tarray::const_iterator col_end = cinfo.ccsCols.end();
    1107     bool first = true;
    1108     while (col_here != col_end) {
    1109       // make sure it's a valid collection
    1110       if (protocols.getrecptproto (*col_here, logout) != NULL) {
    1111         if (!first) args["cc"].push_back (',');
    1112         args["cc"] += *col_here;
    1113         first = false;
     1136    if (collectproto == NULL) {
     1137      // oops, this collection isn't valid
     1138      outconvertclass text_t2ascii;
     1139      logout << text_t2ascii << "ERROR: Invalid collection: " << arg_c << "\n";
     1140      args["c"].clear();
     1141
     1142    } else {
     1143
     1144      ColInfoResponse_t *cinfo = get_collectinfo_ptr (collectproto, arg_c, logout);
     1145
     1146      if (cinfo != NULL) {
     1147    if (!cinfo->ccsCols.empty()) {
     1148      args["ccs"] = 1;
     1149      if (args["cc"].empty()) {
     1150        text_tarray::const_iterator col_here = cinfo->ccsCols.begin();
     1151        text_tarray::const_iterator col_end = cinfo->ccsCols.end();
     1152        bool first = true;
     1153        while (col_here != col_end) {
     1154          // make sure it's a valid collection
     1155          if (protocols.getrecptproto (*col_here, logout) != NULL) {
     1156        if (!first) args["cc"].push_back (',');
     1157        args["cc"] += *col_here;
     1158        first = false;
     1159          }
     1160          col_here ++;
     1161        }
    11141162      }
    1115       col_here ++;
    11161163    }
     1164      } else {
     1165    logout << "ERROR (receptionist::check_mainargs): get_collectinfo_ptr returned NULL\n";
    11171166      }
    11181167    }
     
    12261275  text_t &collection = args["c"];
    12271276
    1228   disp.setmacro ("gsdlhome", "Global", configinfo.gsdlhome);
     1277  disp.setmacro ("gsdlhome", "Global", dm_safe(configinfo.gsdlhome));
    12291278  disp.setmacro ("gwcgi", "Global", configinfo.gwcgi);
    12301279  disp.setmacro ("httpimg", "Global", configinfo.httpimg);
     
    12991348  }
    13001349}
     1350
     1351// gets collection info from cache if found or
     1352// calls collection server (and updates cache)
     1353// returns NULL if there's an error
     1354ColInfoResponse_t *receptionist::get_collectinfo_ptr (recptproto *collectproto,
     1355                              const text_t &collection,
     1356                              ostream &logout) {
     1357 
     1358  // check the cache
     1359  colinfo_tmap::iterator it = configinfo.collectinfo.find (collection);
     1360  if ((it != configinfo.collectinfo.end()) && ((*it).second.info_loaded)) {
     1361    // found it
     1362    return &((*it).second.info);
     1363  }
     1364
     1365  // not cached, get info from collection server
     1366  if (collectproto == NULL) {
     1367    logout << "ERROR: receptionist::get_collectinfo_ptr passed null collectproto\n";
     1368    return NULL;
     1369  }
     1370   
     1371  comerror_t err;
     1372  if (it == configinfo.collectinfo.end()) {
     1373    collectioninfo_t cinfo;
     1374    collectproto->get_collectinfo (collection, cinfo.info, err, logout);
     1375    if (err != noError) {
     1376      outconvertclass text_t2ascii;
     1377      logout << text_t2ascii << "ERROR (receptionist::getcollectinfo_ptr): \""
     1378         << get_comerror_string (err) << "\"while getting collectinfo\n";
     1379      return NULL;
     1380    }
     1381    cinfo.info_loaded = true;
     1382    configinfo.collectinfo[collection] = cinfo;
     1383    return &(configinfo.collectinfo[collection].info);
     1384  } else {
     1385    collectproto->get_collectinfo (collection, (*it).second.info, err, logout);
     1386    if (err != noError) {
     1387      outconvertclass text_t2ascii;
     1388      logout << text_t2ascii << "ERROR (receptionist::getcollectinfo_ptr): \""
     1389         << get_comerror_string (err) << "\"while getting collectinfo\n";
     1390      return NULL;
     1391    }
     1392    (*it).second.info_loaded = true;
     1393    return &((*it).second.info);
     1394  }
     1395}
Note: See TracChangeset for help on using the changeset viewer.