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