source: trunk/gsdl/src/recpt/action.h@ 361

Last change on this file since 361 was 361, checked in by rjmcnab, 25 years ago

Added function check_external_cgiargs so that actions that
are not being called can override cgi arguments.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 5.2 KB
Line 
1/**********************************************************************
2 *
3 * action.h --
4 * Copyright (C) 1999 The New Zealand Digital Library Project
5 *
6 * PUT COPYRIGHT NOTICE HERE
7 *
8 * $Id: action.h 361 1999-07-10 22:15:30Z rjmcnab $
9 *
10 *********************************************************************/
11
12
13#ifndef ACTION_H
14#define ACTION_H
15
16#include "gsdlconf.h"
17#include "text_t.h"
18#include "cgiargs.h"
19#include "display.h"
20#include "recptproto.h"
21
22#if defined(GSDL_USE_OBJECTSPACE)
23# include <ospace\std\iostream>
24#elif defined(GSDL_USE_IOS_H)
25# include <iostream.h>
26#else
27# include <iostream>
28#endif
29
30
31class action {
32protected:
33 cgiargsinfoclass argsinfo;
34
35
36public:
37 action ();
38 virtual ~action ();
39
40 // configure should be called once for each configuration line
41 virtual void configure (const text_t &key, const text_tarray &cfgline);
42
43 // init should be called after all the configuration is done but
44 // before any other methods are called
45 virtual bool init (ostream &logout);
46
47 // returns the "a" argument value that will specify this action
48 // this name should be short but does not have to be one character
49 // long
50 virtual text_t get_action_name ();
51
52 // check_cgiargs should be called before get_cgihead_info,
53 // define_external_macros, and do_action. If an error is found
54 // a message will be written to logout, if the error is severe
55 // then the function will return false and no page content
56 // should be produced based on the arguments.
57 virtual bool check_cgiargs (cgiargsinfoclass &argsinfo, cgiargsclass &args,
58 ostream &logout);
59
60 // check_external_cgiargs should be called after check_cgiargs
61 // for all actions. It should only be used to override some other
62 // normal behaviour, for example, producing a login page when
63 // the requested page needs authentication.
64 virtual bool check_external_cgiargs (cgiargsinfoclass &argsinfo,
65 cgiargsclass &args,
66 outconvertclass &outconvert,
67 const text_t &saveconf,
68 ostream &logout);
69
70 // get_cgihead_info determines the cgi header information for
71 // a set of cgi arguments. If response contains location then
72 // response_data contains the redirect address. If reponse
73 // contains content then reponse_data contains the content-type.
74 // Note that images can now be produced by the receptionist.
75 virtual void get_cgihead_info (cgiargsclass &args, response_t &response,
76 text_t &response_data, ostream &logout);
77
78 // uses_display should return true if the receptionist should return
79 // true if the display class is needed to output the page content.
80 // The default is to return true.
81 virtual bool uses_display (cgiargsclass &args);
82
83 // define all the macros which are related to pages generated
84 // by this action
85 virtual void define_internal_macros (displayclass &disp, cgiargsclass &args,
86 recptproto *collectproto, ostream &logout);
87
88 // define all the macros which might be used by other actions
89 // to produce pages. These macros should be well documented.
90 virtual void define_external_macros (displayclass &disp, cgiargsclass &args,
91 recptproto *collectproto, ostream &logout);
92
93 // returns false if there was an error which prevented the action
94 // from outputing anything.
95 virtual bool do_action (cgiargsclass &args, recptproto *collectproto,
96 displayclass &disp, outconvertclass &outconvert,
97 ostream &textout, ostream &logout);
98
99 // getargsinfo should be called after all configuration files
100 // have been read
101 cgiargsinfoclass getargsinfo () {return argsinfo;};
102};
103
104
105// The actionptr function does not 'own' the action. The
106// action should be deleted by the code which created it.
107class actionptr {
108public:
109 action *a;
110
111 actionptr () {a=NULL;}
112};
113
114typedef map<text_t, actionptr, lttext_t> actionptrmap;
115
116// contains a list of actions indexed by their name
117class actionmapclass {
118protected:
119 actionptrmap actionptrs;
120
121public:
122 // type support for actionptrmap
123 typedef actionptrmap::iterator iterator;
124 typedef actionptrmap::const_iterator const_iterator;
125 typedef actionptrmap::reference reference;
126 typedef actionptrmap::const_reference const_reference;
127 typedef actionptrmap::size_type size_type;
128
129 typedef actionptrmap::difference_type difference_type;
130 typedef actionptrmap::const_reverse_iterator const_reverse_iterator;
131 typedef actionptrmap::reverse_iterator reverse_iterator;
132
133 // basic container support
134 iterator begin () {return actionptrs.begin();}
135 const_iterator begin () const {return actionptrs.begin();}
136 iterator end () {return actionptrs.end();}
137 const_iterator end () const {return actionptrs.end();}
138
139 void erase(iterator pos) {actionptrs.erase(pos);}
140 void erase(iterator first, iterator last) {actionptrs.erase(first, last);}
141 actionmapclass &operator=(const actionmapclass &x) {actionptrs=x.actionptrs;return *this;}
142
143 bool empty () const {return actionptrs.empty();}
144 size_type size() const {return actionptrs.size();}
145
146
147 // added functionality
148 void clear () {actionptrs.erase(actionptrs.begin(),actionptrs.end());}
149
150 // theaction remains the property of the calling code but
151 // should not be deleted until it is removed from this list.
152 void addaction (action *theaction);
153
154 // getaction will return NULL if the action could not be found
155 action *getaction (const text_t &key);
156};
157
158
159#endif
Note: See TracBrowser for help on using the repository browser.