Changeset 7418


Ignore:
Timestamp:
2004-05-25T11:57:23+12:00 (20 years ago)
Author:
mdewsnip
Message:

(Human Info) Added another site_cfg_read and main_cfg_read with a collection argument so a specific collection can be checked first.

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

Legend:

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

    r7302 r7418  
    4646  text_t *httpdomain;
    4747  text_t *httpprefix;
     48  text_t *collection;
     49  text_tset *actions;
     50  text_tset *browsers;
    4851  int    *maxrequests;
    4952public:
     
    5255    httpdomain = NULL;
    5356    httpprefix = NULL;
     57    collection = NULL;
     58    actions = NULL;
     59    browsers = NULL;
    5460    maxrequests = _maxrequests;
    5561  }
     
    6066    httpdomain = _httpdomain;
    6167    httpprefix = _httpprefix;
     68    collection = NULL;
     69    actions = NULL;
     70    browsers = NULL;
    6271    maxrequests = NULL;
    6372  }
    6473
     74  __site_configuration (text_t *_gsdlhome, text_t *_httpdomain,
     75            text_t *_httpprefix, text_t *_collection) {
     76    gsdlhome    = _gsdlhome;
     77    httpdomain = _httpdomain;
     78    httpprefix = _httpprefix;
     79    collection = _collection;
     80    actions = NULL;
     81    browsers = NULL;
     82    maxrequests = NULL;
     83  }
     84
     85  __site_configuration (text_t *_httpprefix, text_tset *_actions, text_tset *_browsers) {
     86    gsdlhome    = NULL;
     87    httpdomain = NULL;
     88    httpprefix = _httpprefix;
     89    collection = NULL;
     90    actions = _actions;
     91    browsers = _browsers;
     92    maxrequests = NULL;
     93  }
     94
    6595  inline void configure (const text_t &key, const text_tarray &cfgline) {
    66     if (key == "gsdlhome") {
     96    if (gsdlhome != NULL && key == "gsdlhome") {
    6797      *gsdlhome = cfgline[0];
    6898    }
    6999
    70     if (key == "httpprefix" &&
    71     httpprefix != NULL) {
     100    if (httpprefix != NULL && key == "httpprefix") {
    72101      *httpprefix = cfgline[0];
    73102    }
    74103
    75     if (key == "httpdomain" &&
    76     httpdomain != NULL) {
     104    if (httpdomain != NULL && key == "httpdomain") {
    77105      *httpdomain = cfgline[0];
    78106    }
    79107
    80     if (key == "maxrequests" &&
    81     maxrequests != NULL) {
     108    if (collection != NULL && key == "collection") {
     109      *collection = cfgline[0];
     110    }
     111
     112    if (actions != NULL && key == "actions") {
     113      actions->clear();
     114      text_tarray::const_iterator thisAction = cfgline.begin();
     115      text_tarray::const_iterator endAction = cfgline.end();
     116      while (thisAction != endAction) {
     117    actions->insert(*thisAction);
     118    ++thisAction;
     119      }
     120    }
     121
     122    if (browsers != NULL && key == "browsers") {
     123      browsers->clear();
     124      text_tarray::const_iterator thisBrowser = cfgline.begin();
     125      text_tarray::const_iterator endBrowser = cfgline.end();
     126      while (thisBrowser != endBrowser) {
     127    browsers->insert(*thisBrowser);
     128    ++thisBrowser;
     129      }
     130    }
     131
     132    if (maxrequests != NULL && key == "maxrequests") {
    82133      *maxrequests = cfgline[0].getint();
    83134      if ((*maxrequests) < 1) {
     
    120171  httpprefix.clear();
    121172
    122   if (gsdlconfigurator.configure("gsdlsite.cfg")) {
     173  if (gsdlconfigurator.configure("gsdlsite.cfg") &&
     174      !gsdlhome.empty() && !httpdomain.empty() && !httpprefix.empty()) {
    123175    return true;
    124176  }
    125177
    126178  return false;
     179}
     180
     181// this version grabs gsdlhome, httpdomain, httpprefix, collection,
     182// returns false if it can't find gsdlhome, httpdomain and httpprefix
     183bool site_cfg_read (text_t &gsdlhome, text_t &httpdomain,
     184            text_t &httpprefix, text_t &collection) {
     185  // get gsdlhome etc
     186  __site_configuration sitecfg(&gsdlhome, &httpdomain, &httpprefix, &collection);
     187  configurator gsdlconfigurator(&sitecfg);
     188   
     189  gsdlhome.clear();
     190  httpdomain.clear();
     191  httpprefix.clear();
     192  collection.clear();
     193   
     194  if (gsdlconfigurator.configure("gsdlsite.cfg") &&
     195      !gsdlhome.empty() && !httpdomain.empty() && !httpprefix.empty()) {
     196    return true;
     197  }
     198  return false;
     199}
     200
     201void main_cfg_read (const text_t& collection, const text_t &gsdlhome, text_t &httpprefix, text_tset& actions, text_tset& browsers)
     202{
     203  __site_configuration sitecfg(&httpprefix, &actions, &browsers);
     204  configurator gsdlconfigurator(&sitecfg);
     205   
     206  httpprefix.clear();
     207  actions.clear();
     208  browsers.clear();
     209
     210  text_t filename;
     211   
     212  filename_cat (filename, gsdlhome, "collect", collection, "etc", "main.cfg");
     213  if (!file_exists(filename)) {
     214    filename_cat (filename, gsdlhome, "etc", "main.cfg");
     215    if (!file_exists (filename)) {
     216      filename.clear();
     217    }
     218  }
     219   
     220  if (!filename.empty()) gsdlconfigurator.configure(filename);
     221
     222
     223  if (!collection.empty()) {
     224    filename_cat (filename, gsdlhome, "collect", collection, "etc", "collect.cfg");
     225    if (!file_exists (filename)) {
     226      filename_cat (filename, gsdlhome, "etc", "collect.cfg");
     227      if (!file_exists (filename)) filename.clear();
     228    }
     229       
     230    if (!filename.empty()) gsdlconfigurator.configure(filename);
     231  }
    127232}
    128233
     
    140245  filename = filename_cat (gsdlhome, "etc");
    141246  filename = filename_cat (filename, "main.cfg");
    142   if (file_exists (filename)) {
     247  if (!collection.empty() && file_exists(filename)) {
    143248    rv = recpt.read_configfile(filename);
    144   }
    145  
     249  } else {
     250    filename_cat (filename, gsdlhome, "etc", "main.cfg");
     251    if (file_exists (filename)) {
     252      rv = recpt.read_configfile(filename);
     253    }
     254  }
     255
    146256  // Look for collect.cfg in GSDLHOME/collect/collection-name/etc directory
    147257  // (if this is for a particular collection), and then GSDLHOME/etc.
  • trunk/gsdl/src/recpt/recptconfig.h

    r1860 r7418  
    3838bool site_cfg_read (receptionist &recpt, text_t &gsdlhome, int &maxrequests);
    3939bool site_cfg_read (text_t &gsdlhome, text_t &httpdomain, text_t &httpprefix);
     40bool site_cfg_read (text_t &gsdlhome, text_t &httpdomain, text_t &httpprefix, text_t &collection);
     41
     42// read main.cfg for the actions and httpprefix
     43void main_cfg_read (const text_t& collection, const text_t &gsdlhome, text_t &httpprefix, text_tset& actions, text_tset& browsers);
    4044
    4145// main_cfg_read reads either collect.cfg or main.cfg and returning
Note: See TracChangeset for help on using the changeset viewer.