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

Last change on this file since 1074 was 928, checked in by kjm18, 24 years ago

search history stuff added.

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