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

Last change on this file since 793 was 776, checked in by sjboddie, 25 years ago

added multiplevalue option to cgiarginfo

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