Ignore:
Timestamp:
2001-01-26T07:26:45+13:00 (23 years ago)
Author:
cs025
Message:

Included CORBA branch for first time

File:
1 edited

Legend:

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

    r1285 r1860  
    2727#include "fileutil.h"
    2828#include "cfgread.h"
     29#include "cnfgator.h"
    2930
    3031
     
    4041#endif
    4142
     43class __site_configuration : public configurable {
     44private:
     45  text_t *gsdlhome;
     46  text_t *httpdomain;
     47  text_t *httpprefix;
     48  int    *maxrequests;
     49public:
     50  __site_configuration (text_t *_gsdlhome, int *_maxrequests) {
     51    gsdlhome = _gsdlhome;
     52    httpdomain = NULL;
     53    httpprefix = NULL;
     54    maxrequests = _maxrequests;
     55  }
     56
     57  __site_configuration (text_t *_gsdlhome, text_t *_httpdomain,
     58                        text_t *_httpprefix) {
     59    gsdlhome    = _gsdlhome;
     60    httpdomain = _httpdomain;
     61    httpprefix = _httpprefix;
     62    maxrequests = NULL;
     63  }
     64
     65  inline void configure (const text_t &key, const text_tarray &cfgline) {
     66    if (key == "gsdlhome") {
     67      *gsdlhome = cfgline[0];
     68    }
     69
     70    if (key == "httpprefix" &&
     71    httpprefix != NULL) {
     72      *httpprefix = cfgline[0];
     73    }
     74
     75    if (key == "httpdomain" &&
     76    httpdomain != NULL) {
     77      *httpdomain = cfgline[0];
     78    }
     79
     80    if (key == "maxrequests" &&
     81    maxrequests != NULL) {
     82      *maxrequests = cfgline[0].getint();
     83      if ((*maxrequests) < 1) {
     84    *maxrequests = 1;
     85      }
     86    }
     87  }
     88};
     89
    4290
    4391// reads site configuration file returning true on success
     
    4593// gsdlsite.cfg should be in same directory as library executable
    4694bool site_cfg_read (receptionist &recpt, text_t &gsdlhome, int &maxrequests) {
     95  // initialise configurator, etc.
     96  __site_configuration sitecfg (&gsdlhome, &maxrequests);
     97  configurator         gsdlconfigurator(&recpt);
    4798
     99  gsdlconfigurator.add_configurable(&sitecfg);
     100
     101  // blank the gsdl home text
    48102  gsdlhome.clear();
    49103
    50   // Look for gsdlsite.cfg in same directory that executable is in.
    51   text_tarray cfgline;
    52   text_t key;
    53 
    54 #ifdef GSDL_USE_IOS_H
    55   ifstream confin ("gsdlsite.cfg", ios::in | ios::nocreate);
    56 #else
    57   ifstream confin ("gsdlsite.cfg", ios::in);
    58 #endif
    59 
    60   if (confin) {
    61     while (read_cfg_line(confin, cfgline) >= 0) {
    62       if (cfgline.size () >= 2) {
    63     key = cfgline[0];
    64     cfgline.erase(cfgline.begin());
    65    
    66     if (key == "maxrequests") {
    67       maxrequests = cfgline[0].getint();
    68       if (maxrequests < 1) maxrequests = 1;
    69     }
    70 
    71     if (key == "gsdlhome")
    72       gsdlhome = cfgline[0];
    73 
    74     // configure the receptionist
    75     recpt.configure (key, cfgline);
    76       }
    77     }
    78     confin.close ();
     104  if (gsdlconfigurator.configure("gsdlsite.cfg")) {
    79105    return true;
    80106  }
     
    82108}
    83109
    84 // this version just grabs gsdlhome, returning true
    85 // unless unable to read gsdlsite.cfg
    86 bool site_cfg_read (text_t &gsdlhome) {
     110// this version grabs gsdlhome, httpdomain and httpprefix,
     111// returns false if it can't find all of them
     112bool site_cfg_read (text_t &gsdlhome, text_t &httpdomain,
     113            text_t &httpprefix) {
     114  // get gsdlhome etc
     115  __site_configuration sitecfg(&gsdlhome, &httpdomain, &httpprefix);
     116  configurator gsdlconfigurator(&sitecfg);
    87117
    88118  gsdlhome.clear();
     119  httpdomain.clear();
     120  httpprefix.clear();
    89121
    90   // Look for gsdlsite.cfg in same directory that executable is in.
    91   text_tarray cfgline;
    92   text_t key;
     122  if (gsdlconfigurator.configure("gsdlsite.cfg") &&
     123      !gsdlhome.empty() && !httpdomain.empty() && !httpprefix.empty()) {
     124    return true;
     125  }
    93126
    94 #ifdef GSDL_USE_IOS_H
    95   ifstream confin ("gsdlsite.cfg", ios::in | ios::nocreate);
    96 #else
    97   ifstream confin ("gsdlsite.cfg", ios::in);
    98 #endif
     127  return true;
    99128
    100   if (confin) {
    101     while (read_cfg_line(confin, cfgline) >= 0) {
    102       if (cfgline.size () >= 2) {
    103     if (cfgline[0] == "gsdlhome") {
    104       gsdlhome = cfgline[1];
    105       break;
    106     }
    107       }
    108     }
    109     return true;
    110     confin.close ();
    111   }
    112129  return false;
    113130}
     
    121138  // read in the main configuration file
    122139  bool rv = false;
     140
    123141  text_t key, filename;
    124142  text_tarray cfgline;
     
    126144  filename = filename_cat (filename, "main.cfg");
    127145  if (file_exists (filename)) {
    128     char *cstr = filename.getcstr();
    129    
    130 #ifdef GSDL_USE_IOS_H
    131     ifstream confin (cstr, ios::in | ios::nocreate);
    132 #else
    133     ifstream confin (cstr, ios::in);
    134 #endif
    135 
    136     delete cstr;
    137  
    138     if (confin) {
    139       while (read_cfg_line(confin, cfgline) >= 0) {
    140     if (cfgline.size () >= 2) {
    141       key = cfgline[0];
    142       cfgline.erase(cfgline.begin());
    143    
    144       // configure the receptionist
    145       recpt.configure (key, cfgline);
    146     }
    147       }
    148       confin.close ();
    149       rv = true;
    150     }
     146    rv = recpt.read_configfile(filename);
    151147  }
    152148 
     
    165161
    166162    if (!filename.empty()) {
    167       char *cstr = filename.getcstr();
    168 
    169 #ifdef GSDL_USE_IOS_H
    170       ifstream confin (cstr, ios::in | ios::nocreate);
    171 #else
    172       ifstream confin (cstr, ios::in);
    173 #endif
    174      
    175       delete cstr;
    176      
    177       if (confin) {
    178     while (read_cfg_line(confin, cfgline) >= 0) {
    179       if (cfgline.size () >= 2) {
    180         key = cfgline[0];
    181         cfgline.erase(cfgline.begin());
    182        
    183         // configure the receptionist
    184         recpt.configure (key, cfgline);
    185       }
    186     }
    187     confin.close ();
    188     rv = true;
    189       }
     163      rv |= recpt.read_configfile(filename);
    190164    }
    191165  }
Note: See TracChangeset for help on using the changeset viewer.