source: branches/z3950-branch/gsdl/src/recpt/cgiargs.h@ 1342

Last change on this file since 1342 was 1342, checked in by johnmcp, 24 years ago

Relatively stable z39.50 implementation now, merged with the mgpp source.
(Still needs a decent interface and query language though...)

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 8.0 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
52enum response_t {location, content};
53
54
55struct cgiarg_t {
56 void clear ();
57 cgiarg_t () {clear();}
58 cgiarg_t &operator=(const cgiarg_t &x);
59
60 enum source_t {default_arg, compressed_arg, cgi_arg, program_arg};
61
62 text_t value;
63 source_t source;
64};
65
66bool operator==(const cgiarg_t &x, const cgiarg_t &y);
67bool operator<(const cgiarg_t &x, const cgiarg_t &y);
68
69typedef map<text_t, cgiarg_t, lttext_t> cgiarg_tmap;
70
71// cgiargsclass is used to store a particular set
72// of cgi arguments.
73class cgiargsclass {
74protected:
75 cgiarg_tmap args;
76
77public:
78 //type support for cgiarg_tmap
79 typedef cgiarg_tmap::iterator iterator;
80 typedef cgiarg_tmap::const_iterator const_iterator;
81 typedef cgiarg_tmap::reference reference;
82 typedef cgiarg_tmap::const_reference const_reference;
83 typedef cgiarg_tmap::size_type size_type;
84 typedef cgiarg_tmap::difference_type difference_type;
85 typedef cgiarg_tmap::const_reverse_iterator const_reverse_iterator;
86 typedef cgiarg_tmap::reverse_iterator reverse_iterator;
87
88 // constructors
89 cgiargsclass ();
90
91 // basic container support
92 iterator begin () {return args.begin();}
93 const_iterator begin () const {return args.begin();}
94 iterator end () {return args.end();}
95 const_iterator end () const {return args.end();}
96
97 void erase(iterator pos) {args.erase(pos);}
98 void erase(iterator first, iterator last) {args.erase(first, last);}
99 cgiargsclass &operator=(const cgiargsclass &x) {args=x.args;return *this;}
100
101 bool empty () const {return args.empty();}
102 size_type size() const {return args.size();}
103
104
105 // added functionality
106 void clear () {args.erase(args.begin(),args.end());}
107
108 // setdefaultarg, setdefaultintarg, and setdefaultcarg will
109 // only set the argument if it is not already set
110 // getargs returns NULL if there isn't an entry with
111 // 'key' already defined, getintarg returns 0 if there wasn't an
112 // entry with 'key' defined and operator[] returns "" if
113 // 'key' wasn't already defined (and sets 'key'="").
114 void setarg (const text_t &key, const text_t &value,
115 cgiarg_t::source_t source=cgiarg_t::program_arg);
116 void setdefaultarg (const text_t &key, const text_t &value,
117 cgiarg_t::source_t source=cgiarg_t::default_arg);
118 void setintarg (const text_t &key, int value,
119 cgiarg_t::source_t source=cgiarg_t::program_arg);
120 void setdefaultintarg (const text_t &key, int value,
121 cgiarg_t::source_t source=cgiarg_t::default_arg);
122 void setcarg (const text_t &key, unsigned short c,
123 cgiarg_t::source_t source=cgiarg_t::program_arg);
124 void setdefaultcarg (const text_t &key, unsigned short c,
125 cgiarg_t::source_t source=cgiarg_t::default_arg);
126 text_t *getarg (const text_t &key);
127 int getintarg (const text_t &key);
128 text_t &operator[] (const text_t &key) {return args[key].value;}
129 cgiarg_t &lookupcgiarg (const text_t &key) {return args[key];}
130};
131
132// stream operators to print cgi arguments for debugging purposes
133ostream &operator<<(ostream &outs, const cgiargsclass &args);
134
135
136
137// cgiarginfo holds information relating to a cgi argument
138class cgiarginfo {
139public:
140 cgiarginfo ();
141
142 // shortname is the name used in cgi arguments
143 text_t shortname;
144
145 // longname is the name used when giving information
146 // about the argument and to spot name duplication
147 text_t longname;
148
149 // multiplechar should be set to true if the value can be
150 // more than one character long
151 bool multiplechar;
152
153 // multiplevalue should be set to true the argument may have
154 // multiple values (as is the case when multiple checkboxes
155 // use the same name)
156 bool multiplevalue;
157
158 // defaultstatus_t indicates how good the default is when different
159 // defaults are given for one argument. "none" means there is no default
160 // (a default might be given elsewhere). "weak" is a basic guess that
161 // doesn't hold much weight, "good" is a better guess, "config" was a default
162 // given in a configuration file, and "imperative" means it must not
163 // be overriden at any costs (unless there is another "imperative"...)
164 enum defaultstatus_t {none=0, weak=1, good=2, config=3, imperative=4};
165
166 defaultstatus_t defaultstatus;
167 text_t argdefault; // a default value
168
169 // savedarginfo_t indicates whether the argument should be saved
170 // between pages (e.g. using the compressed argument) or not. The
171 // value of an argument can change from "can" to "mustnot" and
172 // "can" to "must" but not "mustnot" to "must" or "must" to "mustnot".
173 enum savedarginfo_t {mustnot, can, must};
174
175 savedarginfo_t savedarginfo;
176};
177
178bool operator==(const cgiarginfo &x, const cgiarginfo &y);
179bool operator<(const cgiarginfo &x, const cgiarginfo &y);
180
181typedef map<text_t, cgiarginfo, lttext_t> argsinfomap;
182
183// contains a list of cgi argument information
184class cgiargsinfoclass {
185protected:
186 argsinfomap argsinfo;
187
188public:
189 // type support for arginfomap
190 typedef argsinfomap::iterator iterator;
191 typedef argsinfomap::const_iterator const_iterator;
192 typedef argsinfomap::reference reference;
193 typedef argsinfomap::const_reference const_reference;
194 typedef argsinfomap::size_type size_type;
195 typedef argsinfomap::difference_type difference_type;
196 typedef argsinfomap::const_reverse_iterator const_reverse_iterator;
197 typedef argsinfomap::reverse_iterator reverse_iterator;
198
199 // constructors
200 cgiargsinfoclass ();
201
202 // basic container support
203 iterator begin () {return argsinfo.begin();}
204 const_iterator begin () const {return argsinfo.begin();}
205 iterator end () {return argsinfo.end();}
206 const_iterator end () const {return argsinfo.end();}
207
208 void erase(iterator pos) {argsinfo.erase(pos);}
209 void erase(iterator first, iterator last) {argsinfo.erase(first, last);}
210 cgiargsinfoclass &operator=(const cgiargsinfoclass &x) {argsinfo=x.argsinfo;return *this;}
211
212 bool empty () const {return argsinfo.empty();}
213 size_type size() const {return argsinfo.size();}
214
215
216 // added functionality
217 void clear () {argsinfo.erase(argsinfo.begin(),argsinfo.end());}
218
219 // addarginfo will combine the information with the present
220 // information. If name clashes were detected then the information
221 // will be written to logout and addarginfo will return false. No
222 // processing with the arguments should be done if this happens
223 // as the results will be meaningless.
224 bool addarginfo (ostream *logout, const cgiarginfo &info);
225 bool addarginfo (ostream *logout, const cgiargsinfoclass &info);
226
227 cgiarginfo *getarginfo (const text_t &key);
228 const cgiarginfo *getarginfo (const text_t &key) const;
229 cgiarginfo &operator[] (const text_t &key) {return argsinfo[key];}
230};
231
232
233#endif
Note: See TracBrowser for help on using the repository browser.