Changeset 1860 for trunk/gsdl/src/recpt/recptconfig.cpp
- Timestamp:
- 2001-01-26T07:26:45+13:00 (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/src/recpt/recptconfig.cpp
r1285 r1860 27 27 #include "fileutil.h" 28 28 #include "cfgread.h" 29 #include "cnfgator.h" 29 30 30 31 … … 40 41 #endif 41 42 43 class __site_configuration : public configurable { 44 private: 45 text_t *gsdlhome; 46 text_t *httpdomain; 47 text_t *httpprefix; 48 int *maxrequests; 49 public: 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 42 90 43 91 // reads site configuration file returning true on success … … 45 93 // gsdlsite.cfg should be in same directory as library executable 46 94 bool site_cfg_read (receptionist &recpt, text_t &gsdlhome, int &maxrequests) { 95 // initialise configurator, etc. 96 __site_configuration sitecfg (&gsdlhome, &maxrequests); 97 configurator gsdlconfigurator(&recpt); 47 98 99 gsdlconfigurator.add_configurable(&sitecfg); 100 101 // blank the gsdl home text 48 102 gsdlhome.clear(); 49 103 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")) { 79 105 return true; 80 106 } … … 82 108 } 83 109 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 112 bool 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); 87 117 88 118 gsdlhome.clear(); 119 httpdomain.clear(); 120 httpprefix.clear(); 89 121 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 } 93 126 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; 99 128 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 }112 129 return false; 113 130 } … … 121 138 // read in the main configuration file 122 139 bool rv = false; 140 123 141 text_t key, filename; 124 142 text_tarray cfgline; … … 126 144 filename = filename_cat (filename, "main.cfg"); 127 145 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); 151 147 } 152 148 … … 165 161 166 162 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); 190 164 } 191 165 }
Note:
See TracChangeset
for help on using the changeset viewer.