Changeset 155
- Timestamp:
- 1999-02-08T14:28:04+13:00 (25 years ago)
- Location:
- trunk/gsdl/src/recpt
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/src/recpt/Makefile
r151 r155 36 36 37 37 HEADERS = receptionist.h cgiwrapper.h cgiargs.h action.h \ 38 converter.h recptconfig.h cgiutils.h 38 converter.h recptconfig.h cgiutils.h htmlgen.h statusaction.h 39 39 40 40 SOURCES = receptionist.cpp cgiwrapper.cpp cgiargs.cpp recptmain.cpp action.cpp \ 41 converter.cpp recptconfig.cpp cgiutils.cpp 41 converter.cpp recptconfig.cpp cgiutils.cpp htmlgen.cpp statusaction.cpp 42 42 43 43 OBJECTS = receptionist.o cgiwrapper.o cgiargs.o recptmain.o action.o \ 44 converter.o recptconfig.o cgiutils.o 44 converter.o recptconfig.o cgiutils.o htmlgen.o statusaction.o 45 45 46 46 EXEC = recpt … … 70 70 71 71 receptionist.o: receptionist.h ../../lib/gsdlconf.h ../../lib/site.h 72 receptionist.o: ../../lib/text_t.h cgiargs.h ../../lib/fileutil.h 72 receptionist.o: ../../lib/text_t.h cgiargs.h ../../lib/display.h action.h 73 receptionist.o: ../../lib/fileutil.h cgiutils.h 73 74 cgiwrapper.o: ../../lib/gsdlconf.h ../../lib/site.h cgiwrapper.h 74 cgiwrapper.o: receptionist.h ../../lib/text_t.h cgiargs.h recptconfig.h 75 cgiwrapper.o: receptionist.h ../../lib/text_t.h cgiargs.h ../../lib/display.h 76 cgiwrapper.o: action.h recptconfig.h statusaction.h 75 77 cgiwrapper.o: ../../packages/fcgi/include/fcgiapp.h 76 78 cgiwrapper.o: ../../packages/fcgi/include/fcgi_config.h … … 78 80 cgiargs.o: ../../lib/gsdlunicode.h 79 81 recptmain.o: receptionist.h ../../lib/gsdlconf.h ../../lib/site.h 80 recptmain.o: ../../lib/text_t.h cgiargs.h cgiwrapper.h 82 recptmain.o: ../../lib/text_t.h cgiargs.h ../../lib/display.h action.h 83 recptmain.o: cgiwrapper.h 81 84 action.o: action.h ../../lib/gsdlconf.h ../../lib/site.h ../../lib/text_t.h 82 action.o: cgiargs.h 85 action.o: cgiargs.h ../../lib/display.h 83 86 converter.o: converter.h ../../lib/gsdlconf.h ../../lib/site.h 84 87 converter.o: ../../lib/text_t.h ../../lib/gsdlunicode.h 85 88 recptconfig.o: recptconfig.h ../../lib/gsdlconf.h ../../lib/site.h 86 89 recptconfig.o: ../../lib/text_t.h receptionist.h cgiargs.h 87 recptconfig.o: ../../lib/fileutil.h ../../lib/cfgread.h 88 cgiutils.o: cgiutils.h ../../lib/text_t.h ../../lib/gsdlconf.h 89 cgiutils.o: ../../lib/site.h cgiargs.h 90 recptconfig.o: ../../lib/display.h action.h ../../lib/fileutil.h 91 recptconfig.o: ../../lib/cfgread.h 92 cgiutils.o: cgiutils.h ../../lib/gsdlconf.h ../../lib/site.h 93 cgiutils.o: ../../lib/text_t.h cgiargs.h 94 htmlgen.o: htmlgen.h ../../lib/gsdlconf.h ../../lib/site.h ../../lib/text_t.h 95 htmlgen.o: ../../lib/display.h ../../packages/mg-1.3d/lib/unitool.h 96 statusaction.o: statusaction.h ../../lib/gsdlconf.h ../../lib/site.h action.h 97 statusaction.o: ../../lib/text_t.h cgiargs.h ../../lib/display.h 98 statusaction.o: receptionist.h -
trunk/gsdl/src/recpt/action.cpp
r150 r155 12 12 /* 13 13 $Log$ 14 Revision 1.4 1999/02/08 01:27:59 rjmcnab 15 16 Got the receptionist producing something using the statusaction. 17 14 18 Revision 1.3 1999/02/05 10:42:41 rjmcnab 15 19 … … 36 40 37 41 42 // define all the macros which are related to pages generated 43 // by this action 44 void action::define_internal_macros (displayclass &/*disp*/, cgiargsclass &/*args*/, 45 ostream &/*logout*/) { 46 } 47 38 48 action::action () { 39 49 } … … 49 59 } 50 60 61 // check_cgiargs should be called before get_cgihead_info, 62 // define_external_macros, and do_action. If an error is found 63 // a message will be written to logout, if the error is severe 64 // then the function will return false and no page content 65 // should be produced based on the arguments. 66 bool action::check_cgiargs (cgiargsclass &args, ostream &logout) { 67 return true; 68 } 69 51 70 // get_cgihead_info determines the cgi header information for 52 71 // a set of cgi arguments. If response contains location then … … 54 73 // contains content then reponse_data contains the content-type. 55 74 // Note that images can now be produced by the receptionist. 56 void action::get_cgihead_info (cgiargsclass & args, response_t &response,57 text_t &response_data, ostream & logout) {75 void action::get_cgihead_info (cgiargsclass &/*args*/, response_t &response, 76 text_t &response_data, ostream &/*logout*/) { 58 77 response = location; 59 78 response_data = "http://www.nzdl.org"; 60 79 } 61 80 81 // define all the macros which might be used by other actions 82 // to produce pages. These macros should be well documented. 83 void action::define_external_macros (displayclass &/*disp*/, cgiargsclass &/*args*/, 84 ostream &/*logout*/) { 85 } 86 62 87 // returns false if there was an error which prevented the action 63 88 // from outputing anything. 64 bool action::do_action (cgiargsclass & args, outconvertclass &outconvert,65 ostream & textout, ostream &logout) {89 bool action::do_action (cgiargsclass &/*args*/, outconvertclass &/*outconvert*/, 90 ostream &/*textout*/, ostream &/*logout*/) { 66 91 return true; 67 92 } 68 93 69 94 // configure should be called once for each configuration line 70 void action::configure (const text_tarray &cfgline) { 95 // the default version configures the default for any arguments 96 // which this action uses 97 void action::configure (const text_t &key, const text_tarray &cfgline) { 98 cgiarginfo *info = NULL; 99 if ((key == "argdefault") && (cfgline.size() == 2) && 100 ((info = argsinfo.getarginfo(cfgline[0])) != NULL)) { 101 if (info->defaultstatus <= cgiarginfo::config) { 102 info->defaultstatus = cgiarginfo::config; 103 info->argdefault = cfgline[1]; 104 } 105 } 71 106 } 72 107 73 108 109 110 actionmapclass::actionmapclass () { 111 } 74 112 75 113 // theaction becomes the property of this class after addaction … … 98 136 return (*here).second.a; 99 137 } 138 -
trunk/gsdl/src/recpt/action.h
r146 r155 17 17 #include "text_t.h" 18 18 #include "cgiargs.h" 19 #include "display.h" 19 20 20 21 #if defined(GSDL_USE_OBJECTSPACE) … … 31 32 cgiargsinfoclass argsinfo; 32 33 34 // define all the macros which are related to pages generated 35 // by this action 36 virtual void define_internal_macros (displayclass &disp, cgiargsclass &args, 37 ostream &logout); 38 33 39 public: 34 40 action (); … … 40 46 virtual text_t get_action_name (); 41 47 42 // response_t is used to inform the calling code what type of 43 // cgi header it should produce 44 // eventually this should reside in cgiutils.h 45 enum response_t {location, content}; 48 // check_cgiargs should be called before get_cgihead_info, 49 // define_external_macros, and do_action. If an error is found 50 // a message will be written to logout, if the error is severe 51 // then the function will return false and no page content 52 // should be produced based on the arguments. 53 virtual bool check_cgiargs (cgiargsclass &args, ostream &logout); 46 54 47 55 // get_cgihead_info determines the cgi header information for … … 53 61 text_t &response_data, ostream &logout); 54 62 63 // define all the macros which might be used by other actions 64 // to produce pages. These macros should be well documented. 65 virtual void define_external_macros (displayclass &disp, cgiargsclass &args, 66 ostream &logout); 67 55 68 // returns false if there was an error which prevented the action 56 69 // from outputing anything. … … 59 72 60 73 // configure should be called once for each configuration line 61 virtual void configure (const text_t array &cfgline);74 virtual void configure (const text_t &key, const text_tarray &cfgline); 62 75 63 76 // getargsinfo should be called after all configuration files -
trunk/gsdl/src/recpt/cgiutils.cpp
r150 r155 12 12 /* 13 13 $Log$ 14 Revision 1.3 1999/02/08 01:28:00 rjmcnab 15 16 Got the receptionist producing something using the statusaction. 17 14 18 Revision 1.2 1999/02/05 10:42:43 rjmcnab 15 19 … … 92 96 93 97 // split up the cgi arguments 94 void parse_cgi_args (text_t argstr, cgiargsclass &args) {98 void split_cgi_args (text_t argstr, cgiargsclass &args) { 95 99 args.clear(); 96 100 … … 143 147 return outtext; 144 148 } 149 150 151 152 153 static text_t::const_iterator get_next_save_arg (text_t::const_iterator first, 154 text_t::const_iterator last, 155 text_t &argname) { 156 first = getdelimitstr (first, last, '-', argname); 157 return first; 158 } 159 160 161 // check_save_conf_str checks the configuration string for 162 // the saved args and makes sure it does not conflict with 163 // the information about the arguments. If an error is encountered 164 // it will return false and the program should not produce any 165 // output. 166 bool check_save_conf_str (const text_t &saveconf, 167 const cgiargsinfoclass &argsinfo, 168 ostream &logout) { 169 outconvertclass text_t2ascii; 170 171 text_tset argsset; 172 text_t::const_iterator saveconfhere = saveconf.begin (); 173 text_t::const_iterator saveconfend = saveconf.end (); 174 text_t argname; 175 const cgiarginfo *info; 176 177 // first check to make sure all saved arguments can be saved 178 179 while (saveconfhere != saveconfend) { 180 saveconfhere = get_next_save_arg (saveconfhere, saveconfend, argname); 181 182 if (!argname.empty()) { 183 // save the argument name for later 184 argsset.insert (argname); 185 186 // check the argument 187 info = argsinfo.getarginfo (argname); 188 if (info == NULL) { 189 logout << text_t2ascii << "Error: the cgi argument \"" << argname 190 << "\" is used in the configuration string for the\n" 191 << "saved arguments but does not exist as a valid argument.\n\n"; 192 return false; 193 } 194 if (info->savedarginfo == cgiarginfo::mustnot) { 195 logout << text_t2ascii << "Error: the cgi argument \"" << argname 196 << "\" is used in the configuration string for the\n" 197 << "saved arguments but has been specified as an argument whose\n" 198 << "state must not be saved.\n\n"; 199 return false; 200 } 201 } 202 } 203 204 205 // next check that all saved arguments that should be saved 206 // are saved 207 cgiargsinfoclass::const_iterator argsinfohere = argsinfo.begin (); 208 cgiargsinfoclass::const_iterator argsinfoend = argsinfo.end (); 209 210 while (argsinfohere != argsinfoend) { 211 if (((*argsinfohere).second.savedarginfo == cgiarginfo::must) && 212 (argsset.find((*argsinfohere).second.shortname) == argsset.end())) { 213 logout << text_t2ascii << "Error: the cgi argument \"" 214 << (*argsinfohere).second.shortname << "\" was specified as needing to\n" 215 << "be save but was not listed in the saved arguments.\n\n"; 216 return false; 217 } 218 219 argsinfohere++; 220 } 221 222 return true; // made it, no clashes 223 } 224 225 226 // create_save_conf_str will create a configuration string 227 // based on the information in argsinfo. This method of configuration 228 // is not recomended as small changes can produce large changes in 229 // the resulting configuration string (for instance a totally different 230 // ordering). Only arguments which "must" be saved are included in 231 // the resulting string. 232 text_t create_save_conf_str (const cgiargsinfoclass &argsinfo, 233 ostream &/*logout*/) { 234 cgiargsinfoclass::const_iterator argsinfohere = argsinfo.begin (); 235 cgiargsinfoclass::const_iterator argsinfoend = argsinfo.end (); 236 text_t saveconf; 237 bool first = true; 238 239 while (argsinfohere != argsinfoend) { 240 // save this argument if it must be saved 241 if ((*argsinfohere).second.savedarginfo == cgiarginfo::must) { 242 if (!first) saveconf.push_back ('-'); 243 else first = false; 244 saveconf += (*argsinfohere).second.shortname; 245 } 246 247 argsinfohere++; 248 } 249 250 return saveconf; 251 } 252 253 254 // expand_save_args will expand the saved arguments based 255 // on saveconf placing the results in args if they are not 256 // already defined. If it encounters an error it will return false 257 // and output more information to logout. 258 bool expand_save_args (const cgiargsinfoclass &argsinfo, 259 const text_t &saveconf, 260 cgiargsclass &args, 261 ostream &logout) { 262 outconvertclass text_t2ascii; 263 264 text_t *arg_e = args.getarg("e"); 265 if (arg_e == NULL) return true; // no compressed arguments 266 if (arg_e->empty()) return true; // no compressed arguments 267 268 text_t argname, argvalue; 269 const cgiarginfo *argnameinfo; 270 271 text_t::const_iterator saveconfhere = saveconf.begin(); 272 text_t::const_iterator saveconfend = saveconf.end(); 273 274 text_t::iterator arg_ehere = arg_e->begin(); 275 text_t::iterator arg_eend = arg_e->end(); 276 while (saveconfhere != saveconfend && arg_ehere != arg_eend) { 277 saveconfhere = get_next_save_arg (saveconfhere, saveconfend, argname); 278 279 if (!argname.empty()) { 280 // found another entry 281 argnameinfo = argsinfo.getarginfo (argname); 282 283 if (argnameinfo == NULL) { 284 // no information about the argument could be found 285 // we can't keep going because we don't know whether 286 // this argument is a single or multiple character value 287 logout << text_t2ascii << "Error: the cgi argument \"" << argname 288 << "\" was specified as being a compressed argument\n" 289 << "but no information about it could be found within the " 290 << "cgiargsinfoclass.\n"; 291 return false; 292 293 } else { 294 // found the argument information 295 if (argnameinfo->multiplechar) { 296 arg_ehere = getdelimitstr (arg_ehere, arg_eend, '-', argvalue); 297 if (!argvalue.empty()) args.setdefaultarg (argname, argvalue); 298 } else { 299 args.setdefaultcarg (argname,*arg_ehere); 300 arg_ehere++; 301 } 302 } 303 } 304 } 305 306 return true; 307 } 308 309 310 // adds the default values for those arguments which have not 311 // been specified 312 void add_default_args (const cgiargsinfoclass &argsinfo, 313 cgiargsclass &args, 314 ostream &/*logout*/) { 315 cgiargsinfoclass::const_iterator argsinfohere = argsinfo.begin (); 316 cgiargsinfoclass::const_iterator argsinfoend = argsinfo.end (); 317 318 while (argsinfohere != argsinfoend) { 319 if ((*argsinfohere).second.defaultstatus != cgiarginfo::none) { 320 args.setdefaultarg ((*argsinfohere).second.shortname, 321 (*argsinfohere).second.argdefault); 322 } 323 argsinfohere++; 324 } 325 } 326 327 328 // compress_save_args will compress the arguments and return 329 // them in compressed_args. If an error was encountered 330 // compressed_args will be set to to "", an error will be 331 // written to logout, and the function will return false. 332 bool compress_save_args (const cgiargsinfoclass &argsinfo, 333 const text_t &saveconf, 334 cgiargsclass &args, 335 text_t &compressed_args, 336 ostream &logout) { 337 outconvertclass text_t2ascii; 338 339 compressed_args.clear(); 340 341 text_t argname, argvalue; 342 const cgiarginfo *argnameinfo; 343 344 text_t::const_iterator saveconfhere = saveconf.begin(); 345 text_t::const_iterator saveconfend = saveconf.end(); 346 347 while (saveconfhere != saveconfend) { 348 saveconfhere = get_next_save_arg (saveconfhere, saveconfend, argname); 349 350 if (!argname.empty()) { 351 // found another entry 352 argnameinfo = argsinfo.getarginfo (argname); 353 354 if (argnameinfo == NULL) { 355 // no information about the argument could be found 356 // we can't keep going because we don't know whether 357 // this argument is a single or multiple character value 358 logout << text_t2ascii << "Error: the cgi argument \"" << argname 359 << "\" was specified as being a compressed argument\n" 360 << "but no information about it could be found within the " 361 << "cgiargsinfoclass.\n"; 362 compressed_args.clear(); 363 return false; 364 365 } else { 366 // found the argument information 367 if (argnameinfo->multiplechar) { 368 // multiple character argument 369 compressed_args += args[argname]; 370 if (saveconfhere != saveconfend) compressed_args.push_back ('-'); 371 372 } else { 373 // single character argument 374 if (args[argname].size() == 0) { 375 logout << text_t2ascii << "Error: the cgi argument \"" << argname 376 << "\" was specified as being a compressed argument which\n" 377 << "should have a one character value but it was empty.\n\n"; 378 compressed_args.clear (); 379 return false; 380 381 } else if (args[argname].size() > 1) { 382 logout << text_t2ascii << "Error: the cgi argument \"" << argname 383 << "\" was specified as being a compressed argument which\n" 384 << "should have a one character value but it had multiple characters.\n\n"; 385 compressed_args.clear (); 386 return false; 387 } 388 389 // everything is ok 390 compressed_args += args[argname]; 391 } 392 } 393 } 394 } 395 396 return true; 397 } 398 399 400 // args_tounicode converts any arguments which are not in unicode 401 // to unicode using inconvert 402 void args_tounicode (cgiargsclass &args, inconvertclass &inconvert) { 403 cgiargsclass::iterator here = args.begin(); 404 cgiargsclass::iterator end = args.end(); 405 406 while (here != end) { 407 if ((*here).second.getencoding() > 0) { 408 (*here).second = inconvert.convert((*here).second); 409 } 410 411 here++; 412 } 413 } -
trunk/gsdl/src/recpt/cgiwrapper.cpp
r150 r155 12 12 /* 13 13 $Log$ 14 Revision 1.4 1999/02/08 01:28:01 rjmcnab 15 16 Got the receptionist producing something using the statusaction. 17 14 18 Revision 1.3 1999/02/05 10:42:44 rjmcnab 15 19 … … 39 43 #include "cgiwrapper.h" 40 44 #include "recptconfig.h" 45 #include "action.h" 46 #include "statusaction.h" 41 47 #include <stdlib.h> 42 48 … … 111 117 112 118 113 static void page_errorsitecfg (const text_t &gsdlhome, const text_t &collection) { 114 outconvertclass text_t2ascii; 115 116 cout << "Content-type: text/html\n\n"; 117 118 cout << "<html>\n"; 119 cout << "<head>\n"; 120 cout << "<title>Error</title>\n"; 121 cout << "</head>\n"; 122 cout << "<body>\n"; 123 cout << "<h2>Oops!</h2>\n"; 124 cout << "The site.cfg configuration file could not be found. This file\n"; 125 cout << "should contain configuration information relating to this\n"; 126 cout << "site's setup. "; 119 static void page_errorsitecfg (const text_t &gsdlhome, const text_t &collection, 120 text_t &errorpage) { 121 errorpage += "Content-type: text/html\n\n"; 122 123 errorpage += "<html>\n"; 124 errorpage += "<head>\n"; 125 errorpage += "<title>Error</title>\n"; 126 errorpage += "</head>\n"; 127 errorpage += "<body>\n"; 128 errorpage += "<h2>Oops!</h2>\n"; 129 errorpage += "The site.cfg configuration file could not be found. This file\n"; 130 errorpage += "should contain configuration information relating to this\n"; 131 errorpage += "site's setup. "; 127 132 if (collection.empty()) { 128 cout <<"As this cgi script is not being run in collection specific mode,\n";129 cout <<"the file should reside at ";130 cout << text_t2ascii <<gsdlhome;131 cout <<"/etc/site.cfg.\n";133 errorpage += "As this cgi script is not being run in collection specific mode,\n"; 134 errorpage += "the file should reside at "; 135 errorpage += gsdlhome; 136 errorpage += "/etc/site.cfg.\n"; 132 137 } else { 133 cout << "As this cgi script is being run in collection specific mode,\n"; 134 cout << text_t2ascii << "the file can reside in " << gsdlhome << "/collect/" 135 << collection << "/etc/site.cfg or " << gsdlhome << "/etc/site.cfg.\n"; 136 } 137 cout << "</body>\n"; 138 cout << "</html>\n"; 139 } 140 141 142 static void page_errormaincfg (const text_t &gsdlhome, const text_t &collection) { 143 outconvertclass text_t2ascii; 144 145 cout << "Content-type: text/html\n\n"; 146 147 cout << "<html>\n"; 148 cout << "<head>\n"; 149 cout << "<title>Error</title>\n"; 150 cout << "</head>\n"; 151 cout << "<body>\n"; 152 cout << "<h2>Oops!</h2>\n"; 138 errorpage += "As this cgi script is being run in collection specific mode,\n"; 139 errorpage += "the file can reside in "; 140 errorpage += gsdlhome; 141 errorpage += "/collect/"; 142 errorpage += collection; 143 errorpage += "/etc/site.cfg or "; 144 errorpage += gsdlhome; 145 errorpage += "/etc/site.cfg.\n"; 146 } 147 errorpage += "</body>\n"; 148 errorpage += "</html>\n"; 149 } 150 151 152 static void page_errormaincfg (const text_t &gsdlhome, const text_t &collection, 153 text_t &errorpage) { 154 errorpage += "Content-type: text/html\n\n"; 155 156 errorpage += "<html>\n"; 157 errorpage += "<head>\n"; 158 errorpage += "<title>Error</title>\n"; 159 errorpage += "</head>\n"; 160 errorpage += "<body>\n"; 161 errorpage += "<h2>Oops!</h2>\n"; 153 162 if (collection.empty()) { 154 cout << "The main.cfg configuration file could not be found. This file\n"; 155 cout << "should contain configuration information relating to the\n"; 156 cout << "setup of the interface. As this cgi script is not being run\n"; 157 cout << "in collection specific mode the file should reside at\n"; 158 cout << text_t2ascii << gsdlhome << "/etc/main.cfg.\n"; 163 errorpage += "The main.cfg configuration file could not be found. This file\n"; 164 errorpage += "should contain configuration information relating to the\n"; 165 errorpage += "setup of the interface. As this cgi script is not being run\n"; 166 errorpage += "in collection specific mode the file should reside at\n"; 167 errorpage += gsdlhome; 168 errorpage += "/etc/main.cfg.\n"; 159 169 } else { 160 cout << "Neither the collect.cfg or main.cfg configuration files could\n"; 161 cout << "not be found. This file should contain configuration information\n"; 162 cout << "relating to the setup of the interface. As this cgi script is\n"; 163 cout << "being run in collection specific mode the file should reside\n"; 164 cout << "at either "; 165 cout << text_t2ascii << gsdlhome << "/collect/" << collection 166 << "/etc/collect.cfg, " << gsdlhome << "/etc/collect.cfg or " 167 << gsdlhome << "/etc/main.cfg.\n"; 168 } 169 cout << "</body>\n"; 170 cout << "</html>\n"; 171 } 172 173 174 static void page_errorinit (const text_t &gsdlhome) { 175 outconvertclass text_t2ascii; 176 177 cout << "Content-type: text/html\n\n"; 178 179 cout << "<html>\n"; 180 cout << "<head>\n"; 181 cout << "<title>Error</title>\n"; 182 cout << "</head>\n"; 183 cout << "<body>\n"; 184 cout << "<h2>Oops!</h2>\n"; 185 cout << "An error occurred during the initialisation of the Greenstone Digital\n"; 186 cout << "Library software. It is likely that the software has not been setup\n"; 187 cout << "correctly, consult "; 188 cout << text_t2ascii << gsdlhome << "/etc/initout.txt for more information.\n"; 189 cout << "</body>\n"; 190 cout << "</html>\n"; 170 errorpage += "Neither the collect.cfg or main.cfg configuration files could\n"; 171 errorpage += "not be found. This file should contain configuration information\n"; 172 errorpage += "relating to the setup of the interface. As this cgi script is\n"; 173 errorpage += "being run in collection specific mode the file should reside\n"; 174 errorpage += "at either "; 175 errorpage += gsdlhome; 176 errorpage += "/collect/"; 177 errorpage += collection; 178 errorpage += "/etc/collect.cfg, "; 179 errorpage += gsdlhome; 180 errorpage += "/etc/collect.cfg or "; 181 errorpage += gsdlhome; 182 errorpage += "/etc/main.cfg.\n"; 183 } 184 errorpage += "</body>\n"; 185 errorpage += "</html>\n"; 186 } 187 188 189 static void page_errorinit (const text_t &gsdlhome, text_t &errorpage) { 190 errorpage += "Content-type: text/html\n\n"; 191 192 errorpage += "<html>\n"; 193 errorpage += "<head>\n"; 194 errorpage += "<title>Error</title>\n"; 195 errorpage += "</head>\n"; 196 errorpage += "<body>\n"; 197 errorpage += "<h2>Oops!</h2>\n"; 198 errorpage += "An error occurred during the initialisation of the Greenstone Digital\n"; 199 errorpage += "Library software. It is likely that the software has not been setup\n"; 200 errorpage += "correctly.\n"; 201 202 ifstream initin (GSDL_GSDLHOME "/etc/initout.txt"); 203 if (initin) { 204 errorpage += "The initialisation error log, " GSDL_GSDLHOME "/etc/initout.txt, contains the\n"; 205 errorpage += "following information:\n\n"; 206 errorpage += "<pre>\n"; 207 208 char c; 209 initin.get(c); 210 while (!initin.eof ()) { 211 errorpage.push_back(c); 212 initin.get(c); 213 } 214 215 errorpage += "</pre>\n"; 216 217 initin.close(); 218 219 } else { 220 errorpage += "Please consult " GSDL_GSDLHOME "/etc/initout.txt for more information.\n"; 221 } 222 223 errorpage += "</body>\n"; 224 errorpage += "</html>\n"; 225 } 226 227 static void page_errorparseargs (const text_t &gsdlhome, text_t &errorpage) { 228 errorpage += "Content-type: text/html\n\n"; 229 230 errorpage += "<html>\n"; 231 errorpage += "<head>\n"; 232 errorpage += "<title>Error</title>\n"; 233 errorpage += "</head>\n"; 234 errorpage += "<body>\n"; 235 errorpage += "<h2>Oops!</h2>\n"; 236 errorpage += "An error occurred during the parsing of the cgi arguments.\n"; 237 238 ifstream errin (GSDL_GSDLHOME "/etc/errout.txt"); 239 if (errin) { 240 errorpage += "The error log, " GSDL_GSDLHOME "/etc/errout.txt, contains the\n"; 241 errorpage += "following information:\n\n"; 242 errorpage += "<pre>\n"; 243 244 char c; 245 errin.get(c); 246 while (!errin.eof ()) { 247 errorpage.push_back(c); 248 errin.get(c); 249 } 250 errorpage += "</pre>\n"; 251 errin.close(); 252 253 } else { 254 errorpage += "Please consult " GSDL_GSDLHOME "/etc/errout.txt for more information.\n"; 255 } 256 257 errorpage += "</body>\n"; 258 errorpage += "</html>\n"; 259 } 260 261 static void page_errorcgipage (const text_t &gsdlhome, text_t &errorpage) { 262 errorpage += "Content-type: text/html\n\n"; 263 264 errorpage += "<html>\n"; 265 errorpage += "<head>\n"; 266 errorpage += "<title>Error</title>\n"; 267 errorpage += "</head>\n"; 268 errorpage += "<body>\n"; 269 errorpage += "<h2>Oops!</h2>\n"; 270 errorpage += "An error occurred during the construction of the cgi page.\n"; 271 272 ifstream errin (GSDL_GSDLHOME "/etc/errout.txt"); 273 if (errin) { 274 errorpage += "The error log, " GSDL_GSDLHOME "/etc/errout.txt, contains the\n"; 275 errorpage += "following information:\n\n"; 276 errorpage += "<pre>\n"; 277 278 char c; 279 errin.get(c); 280 while (!errin.eof ()) { 281 errorpage.push_back(c); 282 errin.get(c); 283 } 284 errorpage += "</pre>\n"; 285 errin.close(); 286 287 } else { 288 errorpage += "Please consult " GSDL_GSDLHOME "/etc/errout.txt for more information.\n"; 289 } 290 291 errorpage += "</body>\n"; 292 errorpage += "</html>\n"; 191 293 } 192 294 … … 201 303 #endif 202 304 203 // init stuff 305 // init stuff - we can't output error pages directly with 306 // fastcgi so the pages are stored until we can output them 307 text_t errorpage; 308 outconvertclass text_t2ascii; 309 310 // the the list of actions 311 statusaction *astatusaction = new statusaction; 312 if (astatusaction != NULL) { 313 astatusaction->set_receptionist (&recpt); 314 recpt.add_action (astatusaction); 315 } 204 316 205 317 // set defaults … … 215 327 if (!site_cfg_read (recpt, GSDL_GSDLHOME, collection, maxrequests)) { 216 328 // couldn't find the site configuration file 217 page_errorsitecfg (GSDL_GSDLHOME, collection); 218 return; 219 } 220 if (!main_cfg_read (recpt, GSDL_GSDLHOME, collection)) { 329 page_errorsitecfg (GSDL_GSDLHOME, collection, errorpage); 330 } else if (!main_cfg_read (recpt, GSDL_GSDLHOME, collection)) { 221 331 // couldn't find the main configuration file 222 page_errormaincfg (GSDL_GSDLHOME, collection); 223 return; 332 page_errormaincfg (GSDL_GSDLHOME, collection, errorpage); 224 333 } 225 334 226 335 // initialise the library software 227 ofstream initout (GSDL_GSDLHOME "/etc/initout.txt"); 228 if (!recpt.init(initout)) { 229 // an error occurred during the initialisation 336 if (errorpage.empty()) { 337 ofstream initout (GSDL_GSDLHOME "/etc/initout.txt"); 338 if (!recpt.init(initout)) { 339 // an error occurred during the initialisation 340 initout.close(); 341 page_errorinit(GSDL_GSDLHOME, errorpage); 342 } 230 343 initout.close(); 231 page_errorinit(GSDL_GSDLHOME); 232 return; 233 } 234 initout.close(); 344 } 235 345 236 346 // find out whether this is being run as a cgi-script … … 248 358 // script 249 359 text_t argstr = ""; 360 cgiargsclass args; 250 361 char *aURIStr; 251 362 if (!isfastcgi) { … … 282 393 #define pageout cout 283 394 #endif 284 ofstream errout (GSDL_GSDLHOME "/etc/errout.txt"); 285 cerr = errout; 395 396 if (errorpage.empty()) { 397 ofstream errout (GSDL_GSDLHOME "/etc/errout.txt"); 398 cerr = errout; 286 399 287 // get the query page 288 recpt.produce_cgi_page (argstr, pageout, errout); 400 // parse the cgi arguments and produce the resulting page if there 401 // has been no errors so far 402 if (!recpt.parse_cgi_args (argstr, args, errout)) { 403 errout.close (); 404 page_errorparseargs(GSDL_GSDLHOME, errorpage); 405 } else { 406 if (!recpt.produce_cgi_page (args, pageout, errout)) { 407 errout.close (); 408 page_errorcgipage(GSDL_GSDLHOME, errorpage); 409 } else { 410 errout.close (); 411 } 412 } 413 } 414 // there was an error, output the error page 415 if (!errorpage.empty()) { 416 pageout << text_t2ascii << errorpage; 417 errorpage.clear(); 418 numrequests = maxrequests; // make this the last page 419 } 420 pageout << flush; 289 421 290 422 // finish with the output streams 291 errout.close();292 423 #ifdef USE_FASTCGI 293 424 if (isfastcgi) FCGX_Finish(); -
trunk/gsdl/src/recpt/htmlgen.cpp
r108 r155 12 12 /* 13 13 $Log$ 14 Revision 1.2 1999/02/08 01:28:02 rjmcnab 15 16 Got the receptionist producing something using the statusaction. 17 14 18 Revision 1.1 1999/01/08 08:40:56 rjmcnab 15 19 … … 22 26 */ 23 27 24 static char *RCSID = "$Id$"; 28 #include "htmlgen.h" 29 #include "unitool.h" 25 30 26 27 #include "htmlgen.h" 31 #if defined(GSDL_USE_OBJECTSPACE) 32 # include <ospace\std\map> 33 #elif defined(GSDL_USE_STL_H) 34 # include <map.h> 35 #else 36 # include <map> 37 #endif 28 38 29 39 30 40 41 // highlighttext highlights query terms in text string and 42 // outputs the resulting text string 43 void highlighttext (text_tarray &termvars, displayclass &disp, text_t &text, 44 outconvertclass &outconvert, ostream &textout, ostream &logout) { 45 map<text_t, int, lttext_t> terms; 46 map<text_t, int, lttext_t>::const_iterator it; 47 for (unsigned int i = 0; i < termvars.size(); i++) { 48 terms[termvars[i]] = 1; 49 } 31 50 51 // get the text to start and end a hightlight 52 text_t starthighlight = "<b><u>"; 53 text_t endhighlight = "</u></b>"; 54 if (disp.isdefaultmacro("Global", "starthighlight")) 55 disp.expandstring("Global", "_starthighlight_", starthighlight); 56 if (disp.isdefaultmacro("Global", "endhighlight")) 57 disp.expandstring("Global", "_endhighlight_", endhighlight); 58 59 60 text_t::iterator here = text.begin(); 61 text_t::iterator end = text.end(); 62 text_t word, buffer; 63 while (here != end) { 64 if (is_unicode_letdig(*here)) { 65 // not word boundary 66 word.push_back(*here); 67 here++; 68 69 } else { 70 // found word boundary 71 // add last word if there was one 72 if (!word.empty()) { 73 it = terms.find(word); 74 if (it != terms.end()) { 75 word = starthighlight + word + endhighlight; 76 } 77 buffer += word; 78 word.clear(); 79 } 80 81 if (*here == '<') { 82 // skip over rest of html tag 83 while ((here != end) && (*here != '>')) { 84 buffer.push_back(*here); 85 here++; 86 } 87 } 88 89 buffer.push_back(*here); 90 here++; 91 92 if (buffer.size() > 1024) { 93 textout << outconvert << buffer; 94 buffer.clear(); 95 } 96 } 97 } 98 textout << outconvert << buffer; 99 } 100 101 -
trunk/gsdl/src/recpt/htmlgen.h
r108 r155 14 14 #define HTMLGEN_H 15 15 16 #include "gsdlconf.h" 17 #include "text_t.h" 18 #include "display.h" 19 20 #if defined(GSDL_USE_OBJECTSPACE) 21 # include <ospace\std\iostream> 22 #elif defined(GSDL_USE_IOS_H) 23 # include <iostream.h> 24 #else 25 # include <iostream> 26 #endif 16 27 17 28 18 29 30 // highlighttext highlights query terms in text string and 31 // outputs the resulting text string 32 void highlighttext (text_tarray &termvars, displayclass &disp, text_t &text, 33 outconvertclass &outconvert, ostream &textout, ostream &logout); 34 35 19 36 #endif -
trunk/gsdl/src/recpt/htmlutils.cpp
r108 r155 12 12 /* 13 13 $Log$ 14 Revision 1.2 1999/02/08 01:28:02 rjmcnab 15 16 Got the receptionist producing something using the statusaction. 17 14 18 Revision 1.1 1999/01/08 08:40:58 rjmcnab 15 19 … … 22 26 */ 23 27 24 static char *RCSID = "$Id$";25 26 28 27 29 #include "htmlutils.h" -
trunk/gsdl/src/recpt/receptionist.cpp
r150 r155 12 12 /* 13 13 $Log$ 14 Revision 1.5 1999/02/08 01:28:02 rjmcnab 15 16 Got the receptionist producing something using the statusaction. 17 14 18 Revision 1.4 1999/02/05 10:42:46 rjmcnab 15 19 … … 31 35 #include "receptionist.h" 32 36 #include "fileutil.h" 37 #include "cgiutils.h" 33 38 #include <assert.h> 34 39 #include <time.h> … … 61 66 } 62 67 63 64 // sets the http address of the images directory. This is used to 65 // speed up the access to the images which are a part of the general 66 // interface. If this is not set the interface will have to get the 67 // images via gwcgi which will be a lot slower (especially if the 68 // browser does not cache the images). 69 void receptionist::set_httpimg (const text_t &thehttpimg) { 70 httpimg = thehttpimg; 71 } 72 73 // sets the http address of the gateway cgi program (ie. the program 74 // that contains this receptionist). 75 void receptionist::set_gwcgi (const text_t &thegwcgi) { 76 gwcgi = thegwcgi; 77 } 78 68 // configure_actions should be called for each line in the 69 // configuration files to configure the actions. The configuration 70 // should take place after all the actions have been added. 71 void receptionist::configure_actions (const text_t &key, const text_tarray &cfgline) { 72 actionptrmap::iterator here = actions.begin (); 73 actionptrmap::iterator end = actions.end (); 74 75 while (here != end) { 76 assert ((*here).second.a != NULL); 77 if ((*here).second.a != NULL) 78 (*here).second.a->configure(key, cfgline); 79 80 here++; 81 } 82 } 79 83 80 84 // init should be called after setgsdhome has been called. … … 84 88 // produced by the calling code. 85 89 bool receptionist::init (ostream &logout) { 86 // redirect the error output to logout 87 // disp.setlogout (&logout); 88 89 // set default values for the configuration file 90 // cfg_info.defaultaction = "p"; 91 // cfg_info.defaultpage = "about"; 92 // cfg_info.defaultencoding = "w"; 93 94 // load up the default macro files, the collection directory 95 // is searched first for the file and then the main directory 96 // text_t colmacrodir = filename_cat (collectdir, "macros"); 97 // text_t gsdlmacrodir = filename_cat (gsdlhome, "macros"); 98 // text_tarray::iterator arrhere = cfg_info.macrofiles.begin(); 99 // text_tarray::iterator arrend = cfg_info.macrofiles.end(); 100 // while (arrhere != arrend) { 101 // filename = filename_cat (colmacrodir, *arrhere); 102 // if (!file_exists (filename)) { 103 // filename = filename_cat (gsdlmacrodir, *arrhere); 104 // } 105 // disp.loaddefaultmacros(filename); 106 // arrhere++; 107 // } 108 109 srand(time(NULL)); 90 // read in the macro files 91 if (!read_macrofiles (logout)) return false; 92 93 // defined the main cgi arguments 94 if (!define_mainargs (logout)) return false; 95 96 // add the cgi arguments from the actions 97 actionptrmap::iterator here = actions.begin (); 98 actionptrmap::iterator end = actions.end (); 99 while (here != end) { 100 assert ((*here).second.a != NULL); 101 if ((*here).second.a != NULL) { 102 if (!argsinfo.addarginfo (&logout, (*here).second.a->getargsinfo())) 103 return false; 104 } 105 here++; 106 } 107 108 // create a saveconf string if there isn't one already 109 if (saveconf.empty()) 110 saveconf = create_save_conf_str (argsinfo, logout); 111 112 // check the saveconf string 113 if (!check_save_conf_str (saveconf, argsinfo, logout)) 114 return false; 115 116 // set a random seed 117 srand (time(NULL)); 110 118 111 119 // utf8outconvert.set_rzws(1); … … 116 124 117 125 118 // produce_cgi_page will call parse_cgi_args, get_cgihead_info and 126 // parse_cgi_args parses cgi arguments into an argument class. 127 // This function should be called for each page request. It returns false 128 // if there was a major problem with the cgi arguments. 129 bool receptionist::parse_cgi_args (const text_t &argstr, cgiargsclass &args, 130 ostream &logout) { 131 outconvertclass text_t2ascii; 132 133 // get an initial list of cgi arguments 134 args.clear(); 135 split_cgi_args (argstr, args); 136 137 // expand the compressed argument (if there was one) 138 if (!expand_save_args (argsinfo, saveconf, args, logout)) return false; 139 140 // add the defaults 141 add_default_args (argsinfo, args, logout); 142 143 // check the main cgi arguments 144 if (!check_mainargs (args, logout)) return false; 145 146 // check the arguments for the action 147 action *a = actions.getaction (args["a"]); 148 if (a != NULL) { 149 if (!a->check_cgiargs (args, logout)) return false; 150 } else { 151 // the action was not found!! 152 logout << text_t2ascii << "Error: the action \"" << args["a"] 153 << "\" could not be found.\n"; 154 return false; 155 } 156 157 return true; 158 } 159 160 161 // produce_cgi_page will call get_cgihead_info and 119 162 // produce_content in the appropriate way to output a cgi header and 120 // the page content (if needed). 121 void receptionist::produce_cgi_page (const text_t &argstr, ostream &contentout, 163 // the page content (if needed). If a page could not be created it 164 // will return false 165 bool receptionist::produce_cgi_page (cgiargsclass &args, ostream &contentout, 122 166 ostream &logout) { 123 contentout << "Content-type: text/plain\n\nHello\n"; 167 outconvertclass text_t2ascii; 168 169 response_t response; 170 text_t response_data; 171 172 // produce cgi header 173 get_cgihead_info (args, response, response_data, logout); 174 if (response == location) { 175 // I've forgotten how to do this :-/ 176 return true; 177 } else if (response == content) { 178 // content response 179 contentout << text_t2ascii << "Content-type: " << response_data << "\n\n"; 180 } else { 181 // unknown response 182 logout << "Error: get_cgihead_info returned an unknown response type.\n"; 183 return false; 184 } 185 186 // produce cgi page 187 if (!produce_content (args, contentout, logout)) return false; 188 189 // flush contentout 124 190 contentout << flush; 125 } 126 127 128 // parse_cgi_args parses cgi arguments into an argument class. 129 // This function should be called for each page request. 130 void receptionist::parse_cgi_args (const text_t &argstr, cgiargsclass &args, 131 ostream &logout) { 191 return true; 132 192 } 133 193 … … 140 200 void receptionist::get_cgihead_info (cgiargsclass &args, response_t &response, 141 201 text_t &response_data, ostream &logout) { 202 outconvertclass text_t2ascii; 203 204 // get the action 205 action *a = actions.getaction (args["a"]); 206 if (a != NULL) { 207 a->get_cgihead_info (args, response, response_data, logout); 208 209 } else { 210 // the action was not found!! 211 logout << text_t2ascii << "Error receptionist::get_cgihead_info: the action \"" 212 << args["a"] << "\" could not be found.\n"; 213 response = content; 214 response_data = "text/html"; 215 } 142 216 } 143 217 144 218 145 219 // produce the page content 146 voidreceptionist::produce_content (cgiargsclass &args, ostream &contentout,220 bool receptionist::produce_content (cgiargsclass &args, ostream &contentout, 147 221 ostream &logout) { 222 outconvertclass text_t2ascii; 223 224 // decide on the output conversion class 225 226 // produce the page using the desired action 227 action *a = actions.getaction (args["a"]); 228 if (a != NULL) { 229 if (!a->do_action (args, text_t2ascii, contentout, logout)) 230 return false; 231 232 } else { 233 // the action was not found!! 234 logout << text_t2ascii << "Error receptionist::produce_content: the action \"" 235 << args["a"] << "\" could not be found.\n"; 236 237 contentout << text_t2ascii << "<html>\n"; 238 contentout << text_t2ascii << "<head>\n"; 239 contentout << text_t2ascii << "<title>Error</title>\n"; 240 contentout << text_t2ascii << "</head>\n"; 241 contentout << text_t2ascii << "<body>\n"; 242 contentout << text_t2ascii << "<h2>Oops!</h2>\n"; 243 contentout << text_t2ascii << "Undefined Page. The action \"" 244 << args["a"] << "\" could not be found.\n"; 245 contentout << text_t2ascii << "</body>\n"; 246 contentout << text_t2ascii << "</html>\n"; 247 } 248 249 return true; 148 250 } 149 251 … … 154 256 return ""; 155 257 } 258 259 260 // will read in all the macro files. If one is not found an 261 // error message will be written to logout and the method will 262 // return false. 263 bool receptionist::read_macrofiles (ostream &logout) { 264 outconvertclass text_t2ascii; 265 266 // redirect the error output to logout 267 disp.setlogout (&logout); 268 269 // load up the default macro files, the collection directory 270 // is searched first for the file (if this is being used in 271 // collection specific mode) and then the main directory 272 text_t colmacrodir = filename_cat (collectdir, "macros"); 273 text_t gsdlmacrodir = filename_cat (gsdlhome, "macros"); 274 text_tarray::iterator arrhere = macrofiles.begin(); 275 text_tarray::iterator arrend = macrofiles.end(); 276 text_t filename; 277 while (arrhere != arrend) { 278 // filename is used as a flag to indicate whether 279 // the macro file has been found 280 filename.clear(); 281 282 // try in the collection directory if this is being 283 // run in collection specific mode 284 if (!collection.empty()) { 285 filename = filename_cat (colmacrodir, *arrhere); 286 if (!file_exists (filename)) filename.clear (); 287 } 288 289 // if we haven't found the macro file yet try in 290 // the main macro directory 291 if (filename.empty()) { 292 filename = filename_cat (gsdlmacrodir, *arrhere); 293 if (!file_exists (filename)) filename.clear (); 294 } 295 296 // see if we found the file or not 297 if (filename.empty()) { 298 logout << text_t2ascii 299 << "Error: the macro file \"" << *arrhere << "\" could not be found.\n"; 300 if (collection.empty()) { 301 logout << text_t2ascii 302 << "It should be in " << gsdlmacrodir << ".\n\n"; 303 } else { 304 logout << text_t2ascii 305 << "It should be in either " << colmacrodir << " or in " 306 << gsdlmacrodir << ".\n\n"; 307 } 308 return false; 309 310 } else { // found the file 311 disp.loaddefaultmacros(filename); 312 } 313 314 arrhere++; 315 } 316 317 // success 318 return true; 319 } 320 321 322 // Will define the main general arguments used by the receptionist. 323 // If an error occurs a message will be written to logout and the 324 // method will return false. 325 bool receptionist::define_mainargs (ostream &logout) { 326 // create a list of cgi arguments 327 cgiarginfo ainfo; 328 329 ainfo.shortname = "e"; 330 ainfo.longname = "compressed arguments"; 331 ainfo.multiplechar = true; 332 ainfo.defaultstatus = cgiarginfo::good; 333 ainfo.argdefault = ""; 334 ainfo.savedarginfo = cgiarginfo::mustnot; 335 if (!argsinfo.addarginfo (&logout, ainfo)) return false; 336 337 ainfo.shortname = "a"; 338 ainfo.longname = "action"; 339 ainfo.multiplechar = true; 340 ainfo.defaultstatus = cgiarginfo::none; 341 ainfo.argdefault = ""; 342 ainfo.savedarginfo = cgiarginfo::must; 343 if (!argsinfo.addarginfo (&logout, ainfo)) return false; 344 345 // w=western 346 ainfo.shortname = "w"; 347 ainfo.longname = "encoding"; 348 ainfo.multiplechar = true; 349 ainfo.defaultstatus = cgiarginfo::weak; 350 ainfo.argdefault = "w"; 351 ainfo.savedarginfo = cgiarginfo::must; 352 if (!argsinfo.addarginfo (&logout, ainfo)) return false; 353 354 ainfo.shortname = "nw"; 355 ainfo.longname = "new encoding"; 356 ainfo.multiplechar = true; 357 ainfo.defaultstatus = cgiarginfo::none; 358 ainfo.argdefault = ""; 359 ainfo.savedarginfo = cgiarginfo::mustnot; 360 if (!argsinfo.addarginfo (&logout, ainfo)) return false; 361 362 ainfo.shortname = "c"; 363 ainfo.longname = "collection"; 364 ainfo.multiplechar = true; 365 if (collection.empty()) { 366 ainfo.defaultstatus = cgiarginfo::none; 367 ainfo.argdefault = ""; 368 ainfo.savedarginfo = cgiarginfo::must; 369 } else { 370 ainfo.defaultstatus = cgiarginfo::good; 371 ainfo.argdefault = collection; 372 ainfo.savedarginfo = cgiarginfo::can; 373 } 374 if (!argsinfo.addarginfo (&logout, ainfo)) return false; 375 376 // 0=text+graphics, 1=text 377 ainfo.shortname = "v"; 378 ainfo.longname = "version"; 379 ainfo.multiplechar = false; 380 ainfo.defaultstatus = cgiarginfo::weak; 381 ainfo.argdefault = "0"; 382 ainfo.savedarginfo = cgiarginfo::can; 383 if (!argsinfo.addarginfo (&logout, ainfo)) return false; 384 385 // 0=normal, 1=big 386 ainfo.shortname = "f"; 387 ainfo.longname = "query box size"; 388 ainfo.multiplechar = false; 389 ainfo.defaultstatus = cgiarginfo::weak; 390 ainfo.argdefault = "0"; 391 ainfo.savedarginfo = cgiarginfo::can; 392 if (!argsinfo.addarginfo (&logout, ainfo)) return false; 393 394 // the interface language name should use the ISO 639 395 // standard 396 ainfo.shortname = "l"; 397 ainfo.longname = "interface language"; 398 ainfo.multiplechar = true; 399 ainfo.defaultstatus = cgiarginfo::weak; 400 ainfo.argdefault = "en"; 401 ainfo.savedarginfo = cgiarginfo::must; 402 if (!argsinfo.addarginfo (&logout, ainfo)) return false; 403 404 return true; 405 } 406 407 408 // check_mainargs will check all the main arguments. If a major 409 // error is found it will return false and no cgi page should 410 // be created using the arguments. 411 bool receptionist::check_mainargs (cgiargsclass &args, ostream &logout) { 412 // if this receptionist is running in collection dependant mode 413 // then it should always set the collection argument to the 414 // collection 415 if (!collection.empty()) args["c"] = collection; 416 417 // argument "v" can only be 0 or 1. Use the default value 418 // if it is out of range 419 int arg_v = args.getintarg ("v"); 420 if (arg_v != 0 && arg_v != 1) { 421 cgiarginfo *vinfo = argsinfo.getarginfo ("v"); 422 if (vinfo != NULL) args["v"] = vinfo->argdefault; 423 } 424 425 // argument "f" can only be 0 or 1. Use the default value 426 // if it is out of range 427 int arg_f = args.getintarg ("f"); 428 if (arg_f != 0 && arg_f != 1) { 429 cgiarginfo *finfo = argsinfo.getarginfo ("f"); 430 if (finfo != NULL) args["f"] = finfo->argdefault; 431 } 432 433 return true; 434 } -
trunk/gsdl/src/recpt/receptionist.h
r150 r155 17 17 #include "text_t.h" 18 18 #include "cgiargs.h" 19 #include "display.h" 20 #include "action.h" 19 21 20 22 #ifndef MACROPRECEDENCE … … 31 33 // is being run for multiple collections ("general" mode). 32 34 void set_gsdlhome (const text_t &thegsdlhome); 35 text_t get_gsdlhome () {return gsdlhome;} 33 36 34 37 // this version of set_gsdlhome should be used if the receptionist 35 38 // is being run for a single collection ("collection specific" mode). 36 39 void set_gsdlhome (const text_t &thegsdlhome, const text_t &thecollection); 40 text_t get_collection () {return collection;} 37 41 38 42 // sets the http address of the images directory. This is used to … … 41 45 // images via gwcgi which will be a lot slower (especially if the 42 46 // browser does not cache the images). 43 void set_httpimg (const text_t &thehttpimg); 47 void set_httpimg (const text_t &thehttpimg) {httpimg=thehttpimg;} 48 text_t get_httpimg () {return httpimg;} 44 49 45 50 // sets the http address of the gateway cgi program (ie. the program 46 51 // that contains this receptionist). 47 void set_gwcgi (const text_t &thegwcgi); 52 void set_gwcgi (const text_t &thegwcgi) {gwcgi=thegwcgi;} 53 text_t get_gwcgi () {return gwcgi;} 54 55 // set_macrofiles defines the macro files which will be read when 56 // the init function is called. 57 void set_macrofiles (const text_tarray &themacrofiles) {macrofiles=themacrofiles;} 58 text_tarray get_macrofiles () {return macrofiles;} 59 60 // set_saveconf defines what should be included in the compressed 61 // arguments. This string should consist of cgi argument names 62 // seperated by "-". 63 void set_saveconf (const text_t &thesaveconf) {saveconf=thesaveconf;} 64 text_t get_saveconf () {return saveconf;} 65 66 // add_action makes another action available to the receptionist 67 // the action becomes the property of the receptionist 68 void add_action (action *theaction) {actions.addaction(theaction);} 69 70 // configure_actions should be called for each line in the 71 // configuration files to configure the actions. The configuration 72 // should take place after all the actions have been added. 73 void configure_actions (const text_t &key, const text_tarray &cfgline); 48 74 49 75 // init should be called after setgsdhome has been called. … … 55 81 56 82 // There are two ways to produce a page. You can either call parse_cgi_args, 57 // get_cgihead_info, and produce_content or you can just call p roduce_cgi_page58 // which will be satisfactory in most cases. You might want to call83 // get_cgihead_info, and produce_content or you can just call parse_cgi_args and 84 // produce_cgi_page (which will be satisfactory in most cases). You might want to call 59 85 // parse_cgi_args, get_cgihead_info, and produce_content when you want to 60 // call get_compressed_arg or interface directly with a web server for which 61 // the standard header is inappropriate. 62 63 // produce_cgi_page will call parse_cgi_args, get_cgihead_info and 64 // produce_content in the appropriate way to output a cgi header and 65 // the page content (if needed). 66 void produce_cgi_page (const text_t &argstr, ostream &contentout, 67 ostream &logout); 86 // interface directly with a web server for which the standard header is inappropriate. 68 87 69 88 // parse_cgi_args parses cgi arguments into an argument class. 70 // This function should be called for each page request. 71 void parse_cgi_args (const text_t &argstr, cgiargsclass &args, ostream &logout); 89 // This function should be called for each page request. It returns false 90 // if there was a major problem with the cgi arguments. 91 bool parse_cgi_args (const text_t &argstr, cgiargsclass &args, ostream &logout); 72 92 73 // response_t is used to inform the calling code what type of 74 // cgi header it should produce 75 // eventually this should reside in cgiutils.h 76 enum response_t {location, content}; 93 // produce_cgi_page will call get_cgihead_info and 94 // produce_content in the appropriate way to output a cgi header and 95 // the page content (if needed). If a page could not be created it 96 // will return false 97 bool produce_cgi_page (cgiargsclass &args, ostream &contentout, 98 ostream &logout); 77 99 78 100 // get_cgihead_info determines the cgi header information for … … 85 107 86 108 // produce the page content 87 voidproduce_content (cgiargsclass &args, ostream &contentout,109 bool produce_content (cgiargsclass &args, ostream &contentout, 88 110 ostream &logout); 89 111 … … 99 121 text_t gwcgi; 100 122 123 displayclass disp; 124 text_tarray macrofiles; 101 125 126 text_t saveconf; 127 cgiargsinfoclass argsinfo; 128 actionmapclass actions; 129 130 // will read in all the macro files. If one is not found an 131 // error message will be written to logout and the method will 132 // return false. 133 bool read_macrofiles (ostream &logout); 102 134 135 // Will define the main general arguments used by the receptionist. 136 // If an error occurs a message will be written to logout and the 137 // method will return false. 138 virtual bool define_mainargs (ostream &logout); 139 140 // check_mainargs will check all the main arguments. If a major 141 // error is found it will return false and no cgi page should 142 // be created using the arguments. 143 virtual bool check_mainargs (cgiargsclass &args, ostream &logout); 103 144 }; 104 145 105 146 106 107 147 #endif -
trunk/gsdl/src/recpt/recptconfig.cpp
r149 r155 12 12 /* 13 13 $Log$ 14 Revision 1.2 1999/02/08 01:28:04 rjmcnab 15 16 Got the receptionist producing something using the statusaction. 17 14 18 Revision 1.1 1999/02/05 06:50:32 rjmcnab 15 19 … … 60 64 // read in the site configuration file 61 65 text_tarray cfgline; 66 text_t key; 62 67 char *cstr = filename.getcstr(); 63 68 ifstream confin (cstr); … … 67 72 while (read_cfg_line(confin, cfgline) >= 0) { 68 73 if (cfgline.size () >= 2) { 69 if (cfgline[0] == "gsdlhome") { 70 if (collection.empty()) recpt.set_gsdlhome(cfgline[1]); 71 else recpt.set_gsdlhome(cfgline[1], collection); 74 key = cfgline[0]; 75 cfgline.erase(cfgline.begin()); 76 77 if (key == "gsdlhome") { 78 if (collection.empty()) recpt.set_gsdlhome(cfgline[0]); 79 else recpt.set_gsdlhome(cfgline[0], collection); 72 80 } 73 else if ( cfgline[0] == "httpimg") recpt.set_httpimg(cfgline[1]);74 else if ( cfgline[0] == "gwcgi") recpt.set_gwcgi(cfgline[1]);75 else if ( cfgline[0]== "maxrequests") {76 maxrequests = cfgline[ 1].getint();81 else if (key == "httpimg") recpt.set_httpimg(cfgline[0]); 82 else if (key == "gwcgi") recpt.set_gwcgi(cfgline[0]); 83 else if (key == "maxrequests") { 84 maxrequests = cfgline[0].getint(); 77 85 if (maxrequests < 1) maxrequests = 1; 78 86 } 87 88 // configure all the actions 89 recpt.configure_actions (key, cfgline); 79 90 } 80 91 } … … 112 123 113 124 // read in the site configuration file 125 text_t key; 114 126 text_tarray cfgline; 115 127 char *cstr = filename.getcstr(); … … 120 132 while (read_cfg_line(confin, cfgline) >= 0) { 121 133 if (cfgline.size () >= 2) { 122 // not finished yet 134 key = cfgline[0]; 135 cfgline.erase(cfgline.begin()); 136 if (key == "macrofiles") recpt.set_macrofiles (cfgline); 137 138 // configure all the actions 139 recpt.configure_actions (key, cfgline); 123 140 } 124 141 }
Note:
See TracChangeset
for help on using the changeset viewer.