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

Last change on this file since 7594 was 7594, checked in by mdewsnip, 20 years ago

"I'm feeling lucky" functionality (a la Google). An extra argument ("ifl") can be specified to a query -- in this case, the user will be taken directly to the first matching document.

You can add a checkbox to the query form to get this functionality:

<input type=checkbox name="ifl">I'm feeling lucky!

This functionality is also very useful to go directly from some key value (eg. a unique file name) to a document, from within format statements. This removes the need to know the HASH ID of the target document.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 8.4 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
55
56struct cgiarg_t {
57 void clear ();
58 cgiarg_t () {clear();}
59 cgiarg_t &operator=(const cgiarg_t &x);
60
61 enum source_t {default_arg, compressed_arg, cgi_arg, program_arg};
62
63 text_t value;
64 source_t source;
65};
66
67bool operator==(const cgiarg_t &x, const cgiarg_t &y);
68bool operator<(const cgiarg_t &x, const cgiarg_t &y);
69
70typedef map<text_t, cgiarg_t, lttext_t> cgiarg_tmap;
71typedef map<text_t, text_tmap, lttext_t> confcgiarg_tmap;
72
73// cgiargsclass is used to store a particular set
74// of cgi arguments.
75class cgiargsclass {
76protected:
77 cgiarg_tmap args;
78
79public:
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;
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
112 // getargs returns NULL if there isn't an entry with
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'="").
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);
128 text_t *getarg (const text_t &key);
129 int getintarg (const text_t &key);
130 text_t &operator[] (const text_t &key) {return args[key].value;}
131 cgiarg_t &lookupcgiarg (const text_t &key) {return args[key];}
132};
133
134// stream operators to print cgi arguments for debugging purposes
135ostream &operator<<(ostream &outs, const cgiargsclass &args);
136
137
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
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
160 // defaultstatus_t indicates how good the default is when different
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
164 // given in a configuration file, and "imperative" means it must not
165 // be overriden at any costs (unless there is another "imperative"...)
166 enum defaultstatus_t {none=0, weak=1, good=2, config=3, imperative=4};
167
168 defaultstatus_t defaultstatus;
169 text_t argdefault; // a default value
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;
178};
179
180bool operator==(const cgiarginfo &x, const cgiarginfo &y);
181bool operator<(const cgiarginfo &x, const cgiarginfo &y);
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.
226 bool addarginfo (ostream *logout, const cgiarginfo &info);
227 bool addarginfo (ostream *logout, const cgiargsinfoclass &info);
228
229 // addarginfo will override args info with info loaded from config files
230 // if the args do not exists will be created
231 bool addarginfo (ostream *logout, const text_t& argshortname, const text_tmap& mapinfo);
232 bool addarginfo (ostream *logout, const confcgiarg_tmap& info);
233
234 cgiarginfo *getarginfo (const text_t &key);
235 const cgiarginfo *getarginfo (const text_t &key) const;
236 cgiarginfo &operator[] (const text_t &key) {return argsinfo[key];}
237};
238
239
240#endif
Note: See TracBrowser for help on using the repository browser.