Changeset 146
- Timestamp:
- 1999-02-04T23:00:57+13:00 (25 years ago)
- Location:
- trunk/gsdl/src/recpt
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/src/recpt/action.cpp
r108 r146 12 12 /* 13 13 $Log$ 14 Revision 1.2 1999/02/04 10:00:53 rjmcnab 15 16 Developed the idea of an "action" and having them define the cgi arguments 17 which they need and how those cgi arguments function. 18 14 19 Revision 1.1 1999/01/08 08:40:52 rjmcnab 15 20 … … 22 27 */ 23 28 24 static char *RCSID = "$Id$"; 29 30 #include "action.h" 31 #include <assert.h> 25 32 26 33 27 #include "action.h" 34 action::action () { 35 } 36 37 action::~action () { 38 } 39 40 // returns the "a" argument value that will specify this action 41 // this name should be short but does not have to be one character 42 // long 43 text_t action::get_action_name () { 44 return "nzdl"; 45 } 46 47 // get_cgihead_info determines the cgi header information for 48 // a set of cgi arguments. If response contains location then 49 // response_data contains the redirect address. If reponse 50 // contains content then reponse_data contains the content-type. 51 // Note that images can now be produced by the receptionist. 52 void action::get_cgihead_info (cgiargsclass &args, response_t &response, 53 text_t &response_data, ostream &logout) { 54 response = location; 55 response_data = "http://www.nzdl.org"; 56 } 57 58 // returns false if there was an error which prevented the action 59 // from outputing anything. 60 bool action::do_action (cgiargsclass &args, outconvertclass &outconvert, 61 ostream &textout, ostream &logout) { 62 return true; 63 } 64 65 // configure should be called once for each configuration line 66 void action::configure (const text_tarray &cfgline) { 67 } 28 68 29 69 30 70 71 // theaction becomes the property of this class after addaction 72 // therefore theaction should always be created using new but 73 // not deleted after the call to addaction. 74 void actionmapclass::addaction (action *theaction) { 75 // can't add a null action 76 assert (theaction != NULL); 77 if (theaction == NULL) return; 78 79 // can't add an action with no name 80 assert (!(theaction->get_action_name()).empty()); 81 if ((theaction->get_action_name()).empty()) return; 31 82 83 actionptr aptr; 84 aptr.a = theaction; 85 actionptrs[theaction->get_action_name()] = aptr; 86 } 87 88 // getaction will return NULL if the action could not be found 89 action *actionmapclass::getaction (const text_t &key) { 90 iterator here = actionptrs.find (key); 91 if (here == actionptrs.end()) return NULL; 92 93 return (*here).second.a; 94 } -
trunk/gsdl/src/recpt/action.h
r108 r146 14 14 #define ACTION_H 15 15 16 #include "gsdlconf.h" 17 #include "text_t.h" 18 #include "cgiargs.h" 16 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 27 28 29 class action { 30 protected: 31 cgiargsinfoclass argsinfo; 32 33 public: 34 action (); 35 virtual ~action (); 36 37 // returns the "a" argument value that will specify this action 38 // this name should be short but does not have to be one character 39 // long 40 virtual text_t get_action_name (); 41 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}; 46 47 // get_cgihead_info determines the cgi header information for 48 // a set of cgi arguments. If response contains location then 49 // response_data contains the redirect address. If reponse 50 // contains content then reponse_data contains the content-type. 51 // Note that images can now be produced by the receptionist. 52 virtual void get_cgihead_info (cgiargsclass &args, response_t &response, 53 text_t &response_data, ostream &logout); 54 55 // returns false if there was an error which prevented the action 56 // from outputing anything. 57 virtual bool do_action (cgiargsclass &args, outconvertclass &outconvert, 58 ostream &textout, ostream &logout); 59 60 // configure should be called once for each configuration line 61 virtual void configure (const text_tarray &cfgline); 62 63 // getargsinfo should be called after all configuration files 64 // have been read 65 cgiargsinfoclass getargsinfo () {return argsinfo;}; 66 }; 67 68 69 // actionptr is used to keep track of pointers to actions 70 // sub classes of action might not be the same size so 71 // you probably don't want to treat a sub class as a standard 72 // "action" class when it comes to copying etc -- anyone got 73 // a better way to do this ???? 74 class actionptr { 75 public: 76 action *a; 77 78 actionptr () {a=NULL;} 79 ~actionptr () {if (a!=NULL) delete a; a=NULL;} 80 }; 81 82 typedef map<text_t, actionptr, lttext_t> actionptrmap; 83 84 // contains a list of actions indexed by their name 85 class actionmapclass { 86 protected: 87 actionptrmap actionptrs; 88 89 public: 90 // type support for actionptrmap 91 typedef actionptrmap::iterator iterator; 92 typedef actionptrmap::const_iterator const_iterator; 93 typedef actionptrmap::reference reference; 94 typedef actionptrmap::const_reference const_reference; 95 typedef actionptrmap::size_type size_type; 96 97 typedef actionptrmap::difference_type difference_type; 98 typedef actionptrmap::const_reverse_iterator const_reverse_iterator; 99 typedef actionptrmap::reverse_iterator reverse_iterator; 100 101 // constructors 102 actionmapclass (); 103 104 // basic container support 105 iterator begin () {return actionptrs.begin();} 106 const_iterator begin () const {return actionptrs.begin();} 107 iterator end () {return actionptrs.end();} 108 const_iterator end () const {return actionptrs.end();} 109 110 void erase(iterator pos) {actionptrs.erase(pos);} 111 void erase(iterator first, iterator last) {actionptrs.erase(first, last);} 112 actionmapclass &operator=(const actionmapclass &x) {actionptrs=x.actionptrs;return *this;} 113 114 bool empty () const {return actionptrs.empty();} 115 size_type size() const {return actionptrs.size();} 116 117 118 // added functionality 119 void clear () {actionptrs.erase(actionptrs.begin(),actionptrs.end());} 120 121 // theaction becomes the property of this class after addaction 122 // therefore theaction should always be created using new but 123 // not deleted after the call to addaction. 124 void addaction (action *theaction); 125 126 // getaction will return NULL if the action could not be found 127 action *getaction (const text_t &key); 128 }; 17 129 18 130 -
trunk/gsdl/src/recpt/cgiargs.cpp
r112 r146 12 12 /* 13 13 $Log$ 14 Revision 1.3 1999/02/04 10:00:54 rjmcnab 15 16 Developed the idea of an "action" and having them define the cgi arguments 17 which they need and how those cgi arguments function. 18 14 19 Revision 1.2 1999/01/12 01:51:06 rjmcnab 15 20 … … 32 37 33 38 // constructors 34 cgiargsclass::cgiargsclass () 35 { 39 cgiargsclass::cgiargsclass () { 36 40 } 37 41 … … 110 114 111 115 116 117 cgiarginfo::cgiarginfo () { 118 multiplechar = false; 119 defaultstatus = weak; 120 } 121 122 123 // constructor 124 cgiargsinfoclass::cgiargsinfoclass () { 125 } 126 127 // addarginfo will combine the information with the present 128 // information. If name clashes were detected then the information 129 // will be written to logout and addarginfo will return false. No 130 // processing with the arguments should be done if this happens 131 // as the results will be meaningless. 132 bool cgiargsinfoclass::addarginfo (ostream &logout, const cgiarginfo &info) { 133 outconvertclass text_t2ascii; 134 135 cgiarginfo *orginfo = getarginfo (info.shortname); 136 if (orginfo == NULL) { 137 argsinfo[info.shortname] = info; 138 return true; // no clashes 139 } 140 141 if (orginfo->longname != info.longname) { 142 logout << text_t2ascii << "Error: cgi argument name clash for argument \"" 143 << info.shortname << "\".\nOne long name was\n \"" << orginfo->longname 144 << "\"\nand the other was\n \"" << info.longname << "\".\n\n"; 145 return false; // found a clash 146 } 147 148 if (orginfo->multiplechar != info.multiplechar) { 149 logout << text_t2ascii << "Error: cgi argument \"" << info.shortname 150 << "\" was given as being a single character option\n" 151 << "and a multiple character option.\n\n"; 152 return false; // found a clash 153 } 154 155 if (!info.multiplechar && info.argdefault.size() > 1) { 156 logout << text_t2ascii << "Error: cgi argument \"" << info.shortname 157 << "\" was defined as being a single character option\n" 158 << "but a multiple character default was given.\n\n"; 159 } 160 161 if (orginfo->defaultstatus > info.defaultstatus) { 162 return true; 163 } 164 165 orginfo->defaultstatus = info.defaultstatus; 166 orginfo->argdefault = info.argdefault; 167 return true; 168 } 169 170 bool cgiargsinfoclass::addarginfo (ostream &logout, const cgiargsinfoclass &info) { 171 const_iterator here = info.begin (); 172 const_iterator end = info.end (); 173 174 while (here != end) { 175 if (!addarginfo (logout, (*here).second)) return false; 176 here++; 177 } 178 179 return true; // made it, no clashes 180 } 181 182 cgiarginfo *cgiargsinfoclass::getarginfo (const text_t &key) { 183 iterator here = argsinfo.find (key); 184 if (here == argsinfo.end()) return NULL; 185 186 return &((*here).second); 187 } 188 -
trunk/gsdl/src/recpt/cgiargs.h
r114 r146 34 34 35 35 36 36 37 typedef map<text_t, text_t, lttext_t> textmap; 37 38 38 39 // cgiargsclass is used to store a particular set 40 // of cgi arguments. 39 41 class cgiargsclass 40 42 { … … 90 92 }; 91 93 92 93 94 // stream operators to print cgi arguments for debugging purposes 94 95 ostream &operator<<(ostream &outs, const cgiargsclass &args); 95 96 96 97 98 99 // cgiarginfo holds information relating to a cgi argument 100 class cgiarginfo { 101 public: 102 cgiarginfo (); 103 104 // shortname is the name used in cgi arguments 105 text_t shortname; 106 107 // longname is the name used when giving information 108 // about the argument and to spot name duplication 109 text_t longname; 110 111 // multiplechar should be set to true if the value can be 112 // more than one character long 113 bool multiplechar; 114 115 // defaultstatus_t indicates how good the default is when different 116 // defaults are given for one argument. "weak" is a basic guess that doesn't 117 // hold much weight, "good" is a better guess, "config" was a default 118 // given in a configuration file, and "imperative" means it must not 119 // be overriden at any costs (unless there is another "imperative"...) 120 // Note: I assume that the comparison weak < good < config < imperative 121 // holds :-/ 122 enum defaultstatus_t {weak, good, config, imperative}; 123 124 defaultstatus_t defaultstatus; 125 text_t argdefault; // a default value 126 }; 127 128 129 typedef map<text_t, cgiarginfo, lttext_t> argsinfomap; 130 131 // contains a list of cgi argument information 132 class cgiargsinfoclass { 133 protected: 134 argsinfomap argsinfo; 135 136 public: 137 // type support for arginfomap 138 typedef argsinfomap::iterator iterator; 139 typedef argsinfomap::const_iterator const_iterator; 140 typedef argsinfomap::reference reference; 141 typedef argsinfomap::const_reference const_reference; 142 typedef argsinfomap::size_type size_type; 143 typedef argsinfomap::difference_type difference_type; 144 typedef argsinfomap::const_reverse_iterator const_reverse_iterator; 145 typedef argsinfomap::reverse_iterator reverse_iterator; 146 147 // constructors 148 cgiargsinfoclass (); 149 150 // basic container support 151 iterator begin () {return argsinfo.begin();} 152 const_iterator begin () const {return argsinfo.begin();} 153 iterator end () {return argsinfo.end();} 154 const_iterator end () const {return argsinfo.end();} 155 156 void erase(iterator pos) {argsinfo.erase(pos);} 157 void erase(iterator first, iterator last) {argsinfo.erase(first, last);} 158 cgiargsinfoclass &operator=(const cgiargsinfoclass &x) {argsinfo=x.argsinfo;return *this;} 159 160 bool empty () const {return argsinfo.empty();} 161 size_type size() const {return argsinfo.size();} 162 163 164 // added functionality 165 void clear () {argsinfo.erase(argsinfo.begin(),argsinfo.end());} 166 167 // addarginfo will combine the information with the present 168 // information. If name clashes were detected then the information 169 // will be written to logout and addarginfo will return false. No 170 // processing with the arguments should be done if this happens 171 // as the results will be meaningless. 172 bool addarginfo (ostream &logout, const cgiarginfo &info); 173 bool addarginfo (ostream &logout, const cgiargsinfoclass &info); 174 175 cgiarginfo *getarginfo (const text_t &key); 176 cgiarginfo &operator[] (const text_t &key) {return argsinfo[key];} 177 }; 178 179 180 97 181 #endif -
trunk/gsdl/src/recpt/cgiwrapper.cpp
r144 r146 12 12 /* 13 13 $Log$ 14 Revision 1.2 1999/02/04 10:00:56 rjmcnab 15 16 Developed the idea of an "action" and having them define the cgi arguments 17 which they need and how those cgi arguments function. 18 14 19 Revision 1.1 1999/02/04 01:16:17 rjmcnab 15 20 … … 223 228 // initialise the library software 224 229 ofstream initout (GSDL_GSDLHOME "/etc/initout.txt"); 225 if (!recpt. init(initout)) {230 if (!recpt.digest(initout)) { 226 231 // an error occurred during the initialisation 227 232 initout.close(); -
trunk/gsdl/src/recpt/receptionist.cpp
r145 r146 12 12 /* 13 13 $Log$ 14 Revision 1.3 1999/02/04 10:00:56 rjmcnab 15 16 Developed the idea of an "action" and having them define the cgi arguments 17 which they need and how those cgi arguments function. 18 14 19 Revision 1.2 1999/02/04 01:17:27 rjmcnab 15 20 … … 73 78 // meaningless output), instead an error page should be 74 79 // produced by the calling code. 75 bool receptionist:: init (ostream &logout) {80 bool receptionist::digest (ostream &logout) { 76 81 // redirect the error output to logout 77 disp.setlogout (&logout);82 // disp.setlogout (&logout); 78 83 79 84 // set default values for the configuration file 80 cfg_info.defaultaction = "p";81 cfg_info.defaultpage = "about";82 cfg_info.defaultencoding = "w";85 // cfg_info.defaultaction = "p"; 86 // cfg_info.defaultpage = "about"; 87 // cfg_info.defaultencoding = "w"; 83 88 84 89 // read in the configuration files etc/collect.cfg and index/build.cfg 85 90 // entries in build.cfg should override those in collect.cfg 86 filename = filename_cat (collectdir, "etc");87 filename = filename_cat (filename, "collect.cfg");88 cfg_read(filename);91 // filename = filename_cat (collectdir, "etc"); 92 // filename = filename_cat (filename, "collect.cfg"); 93 // cfg_read(filename); 89 94 90 95 // load up the default macro files, the collection directory 91 96 // is searched first for the file and then the main directory 92 text_t colmacrodir = filename_cat (collectdir, "macros");93 text_t gsdlmacrodir = filename_cat (gsdlhome, "macros");94 text_tarray::iterator arrhere = cfg_info.macrofiles.begin();95 text_tarray::iterator arrend = cfg_info.macrofiles.end();96 while (arrhere != arrend) {97 filename = filename_cat (colmacrodir, *arrhere);98 if (!file_exists (filename)) {99 filename = filename_cat (gsdlmacrodir, *arrhere);100 }101 disp.loaddefaultmacros(filename);102 arrhere++;103 }97 // text_t colmacrodir = filename_cat (collectdir, "macros"); 98 // text_t gsdlmacrodir = filename_cat (gsdlhome, "macros"); 99 // text_tarray::iterator arrhere = cfg_info.macrofiles.begin(); 100 // text_tarray::iterator arrend = cfg_info.macrofiles.end(); 101 // while (arrhere != arrend) { 102 // filename = filename_cat (colmacrodir, *arrhere); 103 // if (!file_exists (filename)) { 104 // filename = filename_cat (gsdlmacrodir, *arrhere); 105 // } 106 // disp.loaddefaultmacros(filename); 107 // arrhere++; 108 // } 104 109 105 srand(time(NULL));110 // srand(time(NULL)); 106 111 107 utf8outconvert.set_rzws(1);108 gboutconvert.set_rzws(1);112 // utf8outconvert.set_rzws(1); 113 // gboutconvert.set_rzws(1); 109 114 110 return collect_init(collection); 115 // return collect_init(collection); 116 return true; 111 117 } 112 118 … … 134 140 // contains content then reponse_data contains the content-type. 135 141 // Note that images can now be produced by the receptionist. 136 void receptionist::get_cgihead_info (c onst cgiargsclass &args, response_t &response,142 void receptionist::get_cgihead_info (cgiargsclass &args, response_t &response, 137 143 text_t &response_data, ostream &logout) { 138 144 } … … 140 146 141 147 // produce the page content 142 void receptionist::produce_content (c onst cgiargsclass &args, ostream &contentout,148 void receptionist::produce_content (cgiargsclass &args, ostream &contentout, 143 149 ostream &logout) { 144 150 } -
trunk/gsdl/src/recpt/receptionist.h
r145 r146 47 47 void set_gwcgi (const text_t &thegwcgi); 48 48 49 // init should be called after setgsdhome has been called.49 // digest should be called after setgsdhome has been called. 50 50 // It returns true on success and false on failure. If false is 51 51 // returned getpage should not be called (without producing 52 52 // meaningless output), instead an error page should be 53 53 // produced by the calling code. 54 bool init (ostream &logout);54 bool digest (ostream &logout); 55 55 56 56 // There are two ways to produce a page. You can either call parse_cgi_args, … … 73 73 // response_t is used to inform the calling code what type of 74 74 // cgi header it should produce 75 // eventually this should reside in cgiutils.h 75 76 enum response_t {location, content}; 76 77 … … 80 81 // contains content then reponse_data contains the content-type. 81 82 // Note that images can now be produced by the receptionist. 82 void get_cgihead_info (c onst cgiargsclass &args, response_t &response,83 void get_cgihead_info (cgiargsclass &args, response_t &response, 83 84 text_t &response_data, ostream &logout); 84 85 85 86 // produce the page content 86 void produce_content (c onst cgiargsclass &args, ostream &contentout,87 void produce_content (cgiargsclass &args, ostream &contentout, 87 88 ostream &logout); 88 89
Note:
See TracChangeset
for help on using the changeset viewer.