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