source: gsdl/trunk/src/recpt/cgiargs.h@ 15597

Last change on this file since 15597 was 12512, checked in by kjdon, 18 years ago

Added Stefan's fileupload code to replace use of cgicc by depositor. Changed the signature of some methods; added fileupload_t; cgiargsclass now has fileupload_t variable; cgiargsinfoclass now has 'bool fileupload' variable; added some more debug print methods; in addarginfo, if logout is null I write the error message to stderr

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 8.9 KB
Line 
1/**********************************************************************
2 *
3 * cgiargs.h --
4 * Copyright (C) 1999 The New Zealand Digital Library Project
5 *
6 * A component of the Greenstone digital library software
7 * from the New Zealand Digital Library Project at the
8 * University of Waikato, New Zealand.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 *********************************************************************/
25
26
27#ifndef CGIARGS_H
28#define CGIARGS_H
29
30#include "gsdlconf.h"
31#include "text_t.h"
32
33#if defined(GSDL_USE_OBJECTSPACE)
34# include <ospace\std\iostream>
35#elif defined(GSDL_USE_IOS_H)
36# include <iostream.h>
37#else
38# include <iostream>
39#endif
40
41#if defined(GSDL_USE_OBJECTSPACE)
42# include <ospace\std\map>
43#elif defined(GSDL_USE_STL_H)
44# include <map.h>
45#else
46# include <map>
47#endif
48
49
50// response_t is used to define what type of cgi header
51// should be produced
52// fullcontent same as content but the action should put content-type as last header.
53enum response_t {location, content, fullcontent, undecided_location};
54
55struct fileupload_t {
56 void clear();
57 fileupload_t() {clear();}
58
59 text_t name;
60 text_t type;
61 int size;
62 text_t tmp_name;
63};
64
65typedef map<text_t, fileupload_t, lttext_t> fileupload_tmap;
66
67struct cgiarg_t {
68 void clear ();
69 cgiarg_t () {clear();}
70 cgiarg_t &operator=(const cgiarg_t &x);
71
72 enum source_t {default_arg, compressed_arg, cgi_arg, program_arg};
73
74 text_t value;
75 source_t source;
76 fileupload_t fileupload;
77};
78
79ostream &operator<<(ostream &outs, const fileupload_t &fu);
80
81bool operator==(const cgiarg_t &x, const cgiarg_t &y);
82bool operator<(const cgiarg_t &x, const cgiarg_t &y);
83
84typedef map<text_t, cgiarg_t, lttext_t> cgiarg_tmap;
85typedef map<text_t, text_tmap, lttext_t> confcgiarg_tmap;
86
87// cgiargsclass is used to store a particular set
88// of cgi arguments.
89class cgiargsclass {
90protected:
91 cgiarg_tmap args;
92
93public:
94 //type support for cgiarg_tmap
95 typedef cgiarg_tmap::iterator iterator;
96 typedef cgiarg_tmap::const_iterator const_iterator;
97 typedef cgiarg_tmap::reference reference;
98 typedef cgiarg_tmap::const_reference const_reference;
99 typedef cgiarg_tmap::size_type size_type;
100 typedef cgiarg_tmap::difference_type difference_type;
101 typedef cgiarg_tmap::const_reverse_iterator const_reverse_iterator;
102 typedef cgiarg_tmap::reverse_iterator reverse_iterator;
103
104 // constructors
105 cgiargsclass ();
106
107 // basic container support
108 iterator begin () {return args.begin();}
109 const_iterator begin () const {return args.begin();}
110 iterator end () {return args.end();}
111 const_iterator end () const {return args.end();}
112
113 void erase(iterator pos) {args.erase(pos);}
114 void erase(iterator first, iterator last) {args.erase(first, last);}
115 cgiargsclass &operator=(const cgiargsclass &x) {args=x.args;return *this;}
116
117 bool empty () const {return args.empty();}
118 size_type size() const {return args.size();}
119
120
121 // added functionality
122 void clear () {args.erase(args.begin(),args.end());}
123
124 // setdefaultarg, setdefaultintarg, and setdefaultcarg will
125 // only set the argument if it is not already set
126 // getargs returns NULL if there isn't an entry with
127 // 'key' already defined, getintarg returns 0 if there wasn't an
128 // entry with 'key' defined and operator[] returns "" if
129 // 'key' wasn't already defined (and sets 'key'="").
130 void setarg (const text_t &key, const text_t &value,
131 cgiarg_t::source_t source=cgiarg_t::program_arg);
132 void setdefaultarg (const text_t &key, const text_t &value,
133 cgiarg_t::source_t source=cgiarg_t::default_arg);
134 void setintarg (const text_t &key, int value,
135 cgiarg_t::source_t source=cgiarg_t::program_arg);
136 void setdefaultintarg (const text_t &key, int value,
137 cgiarg_t::source_t source=cgiarg_t::default_arg);
138 void setcarg (const text_t &key, unsigned short c,
139 cgiarg_t::source_t source=cgiarg_t::program_arg);
140 void setdefaultcarg (const text_t &key, unsigned short c,
141 cgiarg_t::source_t source=cgiarg_t::default_arg);
142 void setargfile (const text_t &key, const fileupload_t &fileupload);
143 text_t *getarg (const text_t &key);
144 int getintarg (const text_t &key);
145 fileupload_t *getargfile (const text_t &key);
146 text_t &operator[] (const text_t &key) {return args[key].value;}
147 cgiarg_t &lookupcgiarg (const text_t &key) {return args[key];}
148};
149
150// stream operators to print cgi arguments for debugging purposes
151ostream &operator<<(ostream &outs, const cgiargsclass &args);
152
153
154
155// cgiarginfo holds information relating to a cgi argument
156class cgiarginfo {
157public:
158 cgiarginfo ();
159
160 // shortname is the name used in cgi arguments
161 text_t shortname;
162
163 // longname is the name used when giving information
164 // about the argument and to spot name duplication
165 text_t longname;
166
167 // multiplechar should be set to true if the value can be
168 // more than one character long
169 bool multiplechar;
170
171 // multiplevalue should be set to true the argument may have
172 // multiple values (as is the case when multiple checkboxes
173 // use the same name)
174 bool multiplevalue;
175
176 // fileupload should be set if the argument is to be used to upload files
177 bool fileupload;
178
179 // defaultstatus_t indicates how good the default is when different
180 // defaults are given for one argument. "none" means there is no default
181 // (a default might be given elsewhere). "weak" is a basic guess that
182 // doesn't hold much weight, "good" is a better guess, "config" was a default
183 // given in a configuration file, and "imperative" means it must not
184 // be overriden at any costs (unless there is another "imperative"...)
185 enum defaultstatus_t {none=0, weak=1, good=2, config=3, imperative=4};
186
187 defaultstatus_t defaultstatus;
188 text_t argdefault; // a default value
189
190 // savedarginfo_t indicates whether the argument should be saved
191 // between pages (e.g. using the compressed argument) or not. The
192 // value of an argument can change from "can" to "mustnot" and
193 // "can" to "must" but not "mustnot" to "must" or "must" to "mustnot".
194 enum savedarginfo_t {mustnot, can, must};
195
196 savedarginfo_t savedarginfo;
197};
198
199bool operator==(const cgiarginfo &x, const cgiarginfo &y);
200bool operator<(const cgiarginfo &x, const cgiarginfo &y);
201
202typedef map<text_t, cgiarginfo, lttext_t> argsinfomap;
203
204// contains a list of cgi argument information
205class cgiargsinfoclass {
206protected:
207 argsinfomap argsinfo;
208
209public:
210 // type support for arginfomap
211 typedef argsinfomap::iterator iterator;
212 typedef argsinfomap::const_iterator const_iterator;
213 typedef argsinfomap::reference reference;
214 typedef argsinfomap::const_reference const_reference;
215 typedef argsinfomap::size_type size_type;
216 typedef argsinfomap::difference_type difference_type;
217 typedef argsinfomap::const_reverse_iterator const_reverse_iterator;
218 typedef argsinfomap::reverse_iterator reverse_iterator;
219
220 // constructors
221 cgiargsinfoclass ();
222
223 // basic container support
224 iterator begin () {return argsinfo.begin();}
225 const_iterator begin () const {return argsinfo.begin();}
226 iterator end () {return argsinfo.end();}
227 const_iterator end () const {return argsinfo.end();}
228
229 void erase(iterator pos) {argsinfo.erase(pos);}
230 void erase(iterator first, iterator last) {argsinfo.erase(first, last);}
231 cgiargsinfoclass &operator=(const cgiargsinfoclass &x) {argsinfo=x.argsinfo;return *this;}
232
233 bool empty () const {return argsinfo.empty();}
234 size_type size() const {return argsinfo.size();}
235
236
237 // added functionality
238 void clear () {argsinfo.erase(argsinfo.begin(),argsinfo.end());}
239
240 // addarginfo will combine the information with the present
241 // information. If name clashes were detected then the information
242 // will be written to logout and addarginfo will return false. No
243 // processing with the arguments should be done if this happens
244 // as the results will be meaningless.
245 bool addarginfo (ostream *logout, cgiarginfo &info);
246 bool addarginfo (ostream *logout, cgiargsinfoclass &info);
247
248 // addarginfo will override args info with info loaded from config files
249 // if the args do not exists will be created
250 bool addarginfo (ostream *logout, const text_t& argshortname, const text_tmap& mapinfo);
251 bool addarginfo (ostream *logout, confcgiarg_tmap& info);
252
253 cgiarginfo *getarginfo (const text_t &key);
254 const cgiarginfo *getarginfo (const text_t &key) const;
255 cgiarginfo &operator[] (const text_t &key) {return argsinfo[key];}
256};
257
258ostream &operator<<(ostream &outs, const cgiargsinfoclass &argsinfo);
259
260#endif
Note: See TracBrowser for help on using the repository browser.