[108] | 1 | /**********************************************************************
|
---|
| 2 | *
|
---|
| 3 | * action.cpp --
|
---|
| 4 | * Copyright (C) 1999 The New Zealand Digital Library Project
|
---|
| 5 | *
|
---|
| 6 | * PUT COPYRIGHT NOTICE HERE
|
---|
| 7 | *
|
---|
| 8 | * $Id: action.cpp 172 1999-02-25 21:59:02Z rjmcnab $
|
---|
| 9 | *
|
---|
| 10 | *********************************************************************/
|
---|
| 11 |
|
---|
| 12 | /*
|
---|
| 13 | $Log$
|
---|
[172] | 14 | Revision 1.7 1999/02/25 21:58:58 rjmcnab
|
---|
| 15 |
|
---|
| 16 | Merged sources.
|
---|
| 17 |
|
---|
[165] | 18 | Revision 1.6 1999/02/21 22:33:52 rjmcnab
|
---|
| 19 |
|
---|
| 20 | Lots of stuff :-)
|
---|
| 21 |
|
---|
[158] | 22 | Revision 1.5 1999/02/11 01:24:04 rjmcnab
|
---|
| 23 |
|
---|
| 24 | Fixed a few compiler warnings.
|
---|
| 25 |
|
---|
[155] | 26 | Revision 1.4 1999/02/08 01:27:59 rjmcnab
|
---|
| 27 |
|
---|
| 28 | Got the receptionist producing something using the statusaction.
|
---|
| 29 |
|
---|
[150] | 30 | Revision 1.3 1999/02/05 10:42:41 rjmcnab
|
---|
| 31 |
|
---|
| 32 | Continued working on receptionist
|
---|
| 33 |
|
---|
[146] | 34 | Revision 1.2 1999/02/04 10:00:53 rjmcnab
|
---|
| 35 |
|
---|
| 36 | Developed the idea of an "action" and having them define the cgi arguments
|
---|
| 37 | which they need and how those cgi arguments function.
|
---|
| 38 |
|
---|
[108] | 39 | Revision 1.1 1999/01/08 08:40:52 rjmcnab
|
---|
| 40 |
|
---|
| 41 | Moved from lib directory.
|
---|
| 42 |
|
---|
| 43 | Revision 1.1 1999/01/08 03:57:44 rjmcnab
|
---|
| 44 |
|
---|
| 45 | Initial revision
|
---|
| 46 |
|
---|
| 47 | */
|
---|
| 48 |
|
---|
| 49 |
|
---|
| 50 | #include "action.h"
|
---|
[146] | 51 | #include <assert.h>
|
---|
[108] | 52 |
|
---|
| 53 |
|
---|
[155] | 54 | // define all the macros which are related to pages generated
|
---|
| 55 | // by this action
|
---|
| 56 | void action::define_internal_macros (displayclass &/*disp*/, cgiargsclass &/*args*/,
|
---|
| 57 | ostream &/*logout*/) {
|
---|
| 58 | }
|
---|
| 59 |
|
---|
[146] | 60 | action::action () {
|
---|
| 61 | }
|
---|
[108] | 62 |
|
---|
[146] | 63 | action::~action () {
|
---|
| 64 | }
|
---|
[108] | 65 |
|
---|
[165] | 66 | // configure should be called once for each configuration line
|
---|
| 67 | // the default version configures the default for any arguments
|
---|
| 68 | // which this action uses
|
---|
| 69 | void action::configure (const text_t &key, const text_tarray &cfgline) {
|
---|
| 70 | cgiarginfo *info = NULL;
|
---|
| 71 | if ((key == "argdefault") && (cfgline.size() == 2) &&
|
---|
| 72 | ((info = argsinfo.getarginfo(cfgline[0])) != NULL)) {
|
---|
| 73 | if (info->defaultstatus <= cgiarginfo::config) {
|
---|
| 74 | info->defaultstatus = cgiarginfo::config;
|
---|
| 75 | info->argdefault = cfgline[1];
|
---|
| 76 | }
|
---|
| 77 | }
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | // init should be called after all the configuration is done but
|
---|
| 81 | // before any other methods are called
|
---|
| 82 | bool action::init (ostream &/*logout*/) {
|
---|
| 83 | return true;
|
---|
| 84 | }
|
---|
| 85 |
|
---|
[146] | 86 | // returns the "a" argument value that will specify this action
|
---|
| 87 | // this name should be short but does not have to be one character
|
---|
| 88 | // long
|
---|
| 89 | text_t action::get_action_name () {
|
---|
| 90 | return "nzdl";
|
---|
| 91 | }
|
---|
| 92 |
|
---|
[155] | 93 | // check_cgiargs should be called before get_cgihead_info,
|
---|
| 94 | // define_external_macros, and do_action. If an error is found
|
---|
| 95 | // a message will be written to logout, if the error is severe
|
---|
| 96 | // then the function will return false and no page content
|
---|
| 97 | // should be produced based on the arguments.
|
---|
[158] | 98 | bool action::check_cgiargs (cgiargsclass &/*args*/, ostream &/*logout*/) {
|
---|
[155] | 99 | return true;
|
---|
| 100 | }
|
---|
| 101 |
|
---|
[146] | 102 | // get_cgihead_info determines the cgi header information for
|
---|
| 103 | // a set of cgi arguments. If response contains location then
|
---|
| 104 | // response_data contains the redirect address. If reponse
|
---|
| 105 | // contains content then reponse_data contains the content-type.
|
---|
| 106 | // Note that images can now be produced by the receptionist.
|
---|
[155] | 107 | void action::get_cgihead_info (cgiargsclass &/*args*/, response_t &response,
|
---|
| 108 | text_t &response_data, ostream &/*logout*/) {
|
---|
[146] | 109 | response = location;
|
---|
| 110 | response_data = "http://www.nzdl.org";
|
---|
| 111 | }
|
---|
| 112 |
|
---|
[155] | 113 | // define all the macros which might be used by other actions
|
---|
| 114 | // to produce pages. These macros should be well documented.
|
---|
| 115 | void action::define_external_macros (displayclass &/*disp*/, cgiargsclass &/*args*/,
|
---|
| 116 | ostream &/*logout*/) {
|
---|
| 117 | }
|
---|
| 118 |
|
---|
[146] | 119 | // returns false if there was an error which prevented the action
|
---|
| 120 | // from outputing anything.
|
---|
[172] | 121 | bool action::do_action (cgiargsclass &/*args*/, recptproto */*collectproto*/,
|
---|
| 122 | displayclass &/*disp*/, outconvertclass &/*outconvert*/,
|
---|
| 123 | ostream &/*textout*/, ostream &/*logout*/) {
|
---|
[146] | 124 | return true;
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 |
|
---|
| 128 |
|
---|
[172] | 129 |
|
---|
[165] | 130 | // theaction remains the property of the calling code but
|
---|
| 131 | // should not be deleted until it is removed from this list.
|
---|
[146] | 132 | void actionmapclass::addaction (action *theaction) {
|
---|
| 133 | // can't add a null action
|
---|
| 134 | assert (theaction != NULL);
|
---|
| 135 | if (theaction == NULL) return;
|
---|
| 136 |
|
---|
| 137 | // can't add an action with no name
|
---|
| 138 | assert (!(theaction->get_action_name()).empty());
|
---|
| 139 | if ((theaction->get_action_name()).empty()) return;
|
---|
| 140 |
|
---|
| 141 | actionptr aptr;
|
---|
| 142 | aptr.a = theaction;
|
---|
| 143 | actionptrs[theaction->get_action_name()] = aptr;
|
---|
| 144 | }
|
---|
| 145 |
|
---|
| 146 | // getaction will return NULL if the action could not be found
|
---|
| 147 | action *actionmapclass::getaction (const text_t &key) {
|
---|
[165] | 148 | // can't find an action with no name
|
---|
| 149 | assert (!key.empty());
|
---|
| 150 | if (key.empty()) return NULL;
|
---|
| 151 |
|
---|
[146] | 152 | iterator here = actionptrs.find (key);
|
---|
| 153 | if (here == actionptrs.end()) return NULL;
|
---|
| 154 |
|
---|
| 155 | return (*here).second.a;
|
---|
| 156 | }
|
---|
[155] | 157 |
|
---|