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