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