source: trunk/gsdl/src/recpt/cgiargs.cpp@ 1148

Last change on this file since 1148 was 802, checked in by sjboddie, 25 years ago

can't remember why I did this - must have been a reason ;-)

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 9.1 KB
RevLine 
[108]1/**********************************************************************
2 *
3 * cgiargs.cpp --
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.cpp 802 1999-12-05 21:25:20Z sjboddie $
25 *
26 *********************************************************************/
27
28/*
29 $Log$
[802]30 Revision 1.11 1999/12/05 21:25:20 sjboddie
31 can't remember why I did this - must have been a reason ;-)
32
[776]33 Revision 1.10 1999/11/08 20:26:38 sjboddie
34 added multiplevalue option to cgiarginfo
35
[533]36 Revision 1.9 1999/09/07 04:56:53 sjboddie
37 added GPL notice
38
[528]39 Revision 1.8 1999/09/03 09:52:45 rjmcnab
40 Fixed a couple of small things
41
[509]42 Revision 1.7 1999/09/02 00:23:55 rjmcnab
43 changes to get compiling on AIX
44
[364]45 Revision 1.6 1999/07/11 01:02:13 rjmcnab
46 Stored information relating to the cgi argument's origin with the cgi argument.
47
[154]48 Revision 1.5 1999/02/08 01:28:00 rjmcnab
[364]49
[154]50 Got the receptionist producing something using the statusaction.
51
[150]52 Revision 1.4 1999/02/05 10:42:41 rjmcnab
53
54 Continued working on receptionist
55
[146]56 Revision 1.3 1999/02/04 10:00:54 rjmcnab
57
58 Developed the idea of an "action" and having them define the cgi arguments
59 which they need and how those cgi arguments function.
60
[112]61 Revision 1.2 1999/01/12 01:51:06 rjmcnab
62
63 Standard header.
64
[108]65 Revision 1.1 1999/01/08 08:40:54 rjmcnab
66
67 Moved from lib directory.
68
69 Revision 1.1 1999/01/08 07:50:30 rjmcnab
70
71 Moved from src/library directory to lib directory.
72
73 */
74
75
76#include "cgiargs.h"
77#include "gsdlunicode.h"
78
[364]79
80
81void cgiarg_t::clear () {
82 value.clear();
83 source = program_arg;
84}
85
86cgiarg_t &cgiarg_t::operator=(const cgiarg_t &x) {
87 value=x.value;
88 source=x.source;
89 return *this;
90}
91
92
[509]93bool operator==(const cgiarg_t &x, const cgiarg_t &y) {
94 return ((x.value == y.value) && (x.source == y.source));
95}
[364]96
[509]97bool operator<(const cgiarg_t &x, const cgiarg_t &y) {
98 return ((x.value < y.value) ||
99 ((x.value == y.value) && (x.source == y.source)));
100}
[364]101
[509]102
103
104
[108]105// constructors
[146]106cgiargsclass::cgiargsclass () {
[108]107}
108
109
110// this returns NULL if there isn't an entry with a value of
111// 'key' already defined
112
[364]113void cgiargsclass::setarg (const text_t &key, const text_t &value,
114 cgiarg_t::source_t source) {
115 cgiarg_t temparg;
116 temparg.value = value;
117 temparg.source = source;
118 args[key] = temparg;
[108]119}
120
[364]121void cgiargsclass::setdefaultarg (const text_t &key, const text_t &value,
122 cgiarg_t::source_t source) {
123 if (getarg(key) == NULL) setarg (key, value, source);
[108]124}
125
[364]126void cgiargsclass::setintarg (const text_t &key, int value,
127 cgiarg_t::source_t source) {
128 setarg (key, value, source);
[108]129}
130
[364]131void cgiargsclass::setdefaultintarg (const text_t &key, int value,
132 cgiarg_t::source_t source) {
133 if (getarg(key) == NULL) setintarg (key, value, source);
[108]134}
135
[364]136void cgiargsclass::setcarg (const text_t &key, unsigned short c,
137 cgiarg_t::source_t source) {
[108]138 text_t t;
139 t.push_back(c);
[364]140 setarg(key,t, source);
[108]141}
142
[364]143void cgiargsclass::setdefaultcarg (const text_t &key, unsigned short c,
144 cgiarg_t::source_t source) {
145 if (getarg(key) == NULL) setcarg (key, c, source);
[108]146}
147
[364]148text_t *cgiargsclass::getarg (const text_t &key) {
[108]149 iterator here = args.find (key);
150 if (here == args.end()) return NULL;
151
[364]152 return &((*here).second.value);
[108]153}
154
[364]155int cgiargsclass::getintarg (const text_t &key) {
[108]156 text_t *text = getarg (key);
157 if (text == NULL) return 0;
158 return text->getint();
159}
160
161
162
163// stream operators to print cgi arguments for debugging purposes
[364]164ostream &operator<<(ostream &outs, const cgiargsclass &args) {
[108]165 utf8outconvertclass text_t2utf8;
166 cgiargsclass::const_iterator here = args.begin ();
167 cgiargsclass::const_iterator end = args.end ();
168
169 outs << "*** cgiargsclass\n";
170
[364]171 while (here != end) {
172 outs << text_t2utf8 << " \"" << (*here).first << "\"=\"" <<
173 (*here).second.value << "\"\n";
174 here++;
175 }
[108]176 outs << "\n";
177
178 return outs;
179}
180
181
[146]182
183cgiarginfo::cgiarginfo () {
184 multiplechar = false;
[776]185 multiplevalue = false;
[146]186 defaultstatus = weak;
[802]187 argdefault.clear();
[528]188 savedarginfo = can;
[146]189}
190
[509]191
192bool operator==(const cgiarginfo &x, const cgiarginfo &y) {
193 return ((x.shortname == y.shortname) &&
194 (x.longname == y.longname) &&
195 (x.multiplechar == y.multiplechar) &&
[776]196 (x.multiplevalue == y.multiplevalue) &&
[509]197 (x.defaultstatus == y.defaultstatus) &&
198 (x.argdefault == y.argdefault) &&
199 (x.savedarginfo == y.savedarginfo));
200}
201
202bool operator<(const cgiarginfo &x, const cgiarginfo &y) {
203 return ((x.shortname < y.shortname) ||
204 ((x.shortname == y.shortname) &&
205 ((x.longname < y.longname) ||
206 ((x.longname == y.longname) &&
[776]207 ((x.multiplevalue < y.multiplevalue) ||
208 ((x.multiplevalue == y.multiplevalue) &&
209 ((x.multiplechar < y.multiplechar) ||
210 ((x.multiplechar == y.multiplechar) &&
211 ((x.defaultstatus < y.defaultstatus) ||
212 ((x.defaultstatus == y.defaultstatus) &&
213 ((x.argdefault < y.argdefault) ||
214 ((x.argdefault == y.argdefault) &&
215 ((x.savedarginfo < y.savedarginfo))))))))))))));
[509]216}
217
218
[146]219// constructor
220cgiargsinfoclass::cgiargsinfoclass () {
221}
222
223// addarginfo will combine the information with the present
224// information. If name clashes were detected then the information
225// will be written to logout and addarginfo will return false. No
226// processing with the arguments should be done if this happens
227// as the results will be meaningless.
[154]228bool cgiargsinfoclass::addarginfo (ostream *logout, const cgiarginfo &info) {
[146]229 outconvertclass text_t2ascii;
230
231 cgiarginfo *orginfo = getarginfo (info.shortname);
232 if (orginfo == NULL) {
233 argsinfo[info.shortname] = info;
234 return true; // no clashes
235 }
236
237 if (orginfo->longname != info.longname) {
[154]238 if (logout != NULL) {
239 (*logout) << text_t2ascii << "Error: cgi argument name clash for argument \""
240 << info.shortname << "\".\nOne long name was\n \"" << orginfo->longname
241 << "\"\nand the other was\n \"" << info.longname << "\".\n\n";
242 }
[146]243 return false; // found a clash
244 }
245
[776]246 if (orginfo->multiplevalue != info.multiplevalue) {
247 if (logout != NULL) {
248 (*logout) << text_t2ascii << "Error: cgi argument \"" << info.shortname
249 << "\" was given as being a single value option\n"
250 << "and a multiple value option.\n\n";
251 }
252 return false; // found a clash
253 }
254
[146]255 if (orginfo->multiplechar != info.multiplechar) {
[154]256 if (logout != NULL) {
257 (*logout) << text_t2ascii << "Error: cgi argument \"" << info.shortname
258 << "\" was given as being a single character option\n"
259 << "and a multiple character option.\n\n";
260 }
[146]261 return false; // found a clash
262 }
[154]263
[146]264 if (!info.multiplechar && info.argdefault.size() > 1) {
[154]265 if (logout != NULL) {
266 (*logout) << text_t2ascii << "Error: cgi argument \"" << info.shortname
267 << "\" was defined as being a single character option\n"
268 << "but a multiple character default was given.\n\n";
269 }
[150]270 return false; // found a problem
[146]271 }
272
[150]273 // make sure there is no clashes in the savedarginfo
274 if ((orginfo->savedarginfo==cgiarginfo::mustnot &&
275 info.savedarginfo==cgiarginfo::must) ||
276 (orginfo->savedarginfo==cgiarginfo::must &&
277 info.savedarginfo==cgiarginfo::mustnot)) {
[154]278 if (logout != NULL) {
279 (*logout) << text_t2ascii << "Error: it was specified that cgi argument \""
280 << info.shortname << "\" should be saved in the state\n"
281 << "information and that it should not be save in the state information.\n\n";
282 }
[150]283 return false; // found a clash
284 }
285 // the only time orginfo->savedarginfo can change is when it is set
286 // to "can"
287 if (orginfo->savedarginfo == cgiarginfo::can)
288 orginfo->savedarginfo = info.savedarginfo;
289
290
[146]291 if (orginfo->defaultstatus > info.defaultstatus) {
292 return true;
293 }
294 orginfo->defaultstatus = info.defaultstatus;
295 orginfo->argdefault = info.argdefault;
[150]296
[146]297 return true;
298}
299
[154]300bool cgiargsinfoclass::addarginfo (ostream *logout, const cgiargsinfoclass &info) {
[146]301 const_iterator here = info.begin ();
302 const_iterator end = info.end ();
303
304 while (here != end) {
305 if (!addarginfo (logout, (*here).second)) return false;
306 here++;
307 }
308
309 return true; // made it, no clashes
310}
311
312cgiarginfo *cgiargsinfoclass::getarginfo (const text_t &key) {
313 iterator here = argsinfo.find (key);
314 if (here == argsinfo.end()) return NULL;
315
316 return &((*here).second);
317}
318
[150]319const cgiarginfo *cgiargsinfoclass::getarginfo (const text_t &key) const {
320 const_iterator here = argsinfo.find (key);
321 if (here == argsinfo.end()) return NULL;
322
323 return &((*here).second);
324}
325
326
327
Note: See TracBrowser for help on using the repository browser.