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

Last change on this file since 357 was 154, checked in by rjmcnab, 25 years ago

Got the receptionist producing something using the statusaction.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 6.2 KB
Line 
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 154 1999-02-08 01:28:01Z 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
38enum response_t {location, content};
39
40
41typedef map<text_t, text_t, lttext_t> textmap;
42
43// cgiargsclass is used to store a particular set
44// of cgi arguments.
45class cgiargsclass
46{
47protected:
48 textmap args;
49
50public:
51 //type support for textmap
52 typedef textmap::iterator iterator;
53 typedef textmap::const_iterator const_iterator;
54 typedef textmap::reference reference;
55 typedef textmap::const_reference const_reference;
56 typedef textmap::size_type size_type;
57 typedef textmap::difference_type difference_type;
58 typedef textmap::const_reverse_iterator const_reverse_iterator;
59 typedef textmap::reverse_iterator reverse_iterator;
60
61 // constructors
62 cgiargsclass ();
63
64 // basic container support
65 iterator begin () {return args.begin();}
66 const_iterator begin () const {return args.begin();}
67 iterator end () {return args.end();}
68 const_iterator end () const {return args.end();}
69
70 void erase(iterator pos) {args.erase(pos);}
71 void erase(iterator first, iterator last) {args.erase(first, last);}
72 cgiargsclass &operator=(const cgiargsclass &x) {args=x.args;return *this;}
73
74 bool empty () const {return args.empty();}
75 size_type size() const {return args.size();}
76
77
78 // added functionality
79 void clear () {args.erase(args.begin(),args.end());}
80
81 // setdefaultarg, setdefaultintarg, and setdefaultcarg will
82 // only set the argument if it is not already set
83 // getargs returns NULL if there isn't an entry with
84 // 'key' already defined, getintarg returns 0 if there wasn't an
85 // entry with 'key' defined and operator[] returns "" if
86 // 'key' wasn't already defined (and sets 'key'="").
87 void setarg (const text_t &key, const text_t &value);
88 void setdefaultarg (const text_t &key, const text_t &value);
89 void setintarg (const text_t &key, int value);
90 void setdefaultintarg (const text_t &key, int value);
91 void setcarg (const text_t &key, unsigned short c);
92 void setdefaultcarg (const text_t &key, unsigned short c);
93 text_t *getarg (const text_t &key);
94 int getintarg (const text_t &key);
95 text_t &operator[] (const text_t &key) {return args[key];}
96};
97
98// stream operators to print cgi arguments for debugging purposes
99ostream &operator<<(ostream &outs, const cgiargsclass &args);
100
101
102
103// cgiarginfo holds information relating to a cgi argument
104class cgiarginfo {
105public:
106 cgiarginfo ();
107
108 // shortname is the name used in cgi arguments
109 text_t shortname;
110
111 // longname is the name used when giving information
112 // about the argument and to spot name duplication
113 text_t longname;
114
115 // multiplechar should be set to true if the value can be
116 // more than one character long
117 bool multiplechar;
118
119 // defaultstatus_t indicates how good the default is when different
120 // defaults are given for one argument. "none" means there is no default
121 // (a default might be given elsewhere). "weak" is a basic guess that
122 // doesn't hold much weight, "good" is a better guess, "config" was a default
123 // given in a configuration file, and "imperative" means it must not
124 // be overriden at any costs (unless there is another "imperative"...)
125 // Note: I assume that the comparison none < weak < good < config < imperative
126 // holds :-/
127 enum defaultstatus_t {none, weak, good, config, imperative};
128
129 defaultstatus_t defaultstatus;
130 text_t argdefault; // a default value
131
132 // savedarginfo_t indicates whether the argument should be saved
133 // between pages (e.g. using the compressed argument) or not. The
134 // value of an argument can change from "can" to "mustnot" and
135 // "can" to "must" but not "mustnot" to "must" or "must" to "mustnot".
136 enum savedarginfo_t {mustnot, can, must};
137
138 savedarginfo_t savedarginfo;
139};
140
141
142typedef map<text_t, cgiarginfo, lttext_t> argsinfomap;
143
144// contains a list of cgi argument information
145class cgiargsinfoclass {
146protected:
147 argsinfomap argsinfo;
148
149public:
150 // type support for arginfomap
151 typedef argsinfomap::iterator iterator;
152 typedef argsinfomap::const_iterator const_iterator;
153 typedef argsinfomap::reference reference;
154 typedef argsinfomap::const_reference const_reference;
155 typedef argsinfomap::size_type size_type;
156 typedef argsinfomap::difference_type difference_type;
157 typedef argsinfomap::const_reverse_iterator const_reverse_iterator;
158 typedef argsinfomap::reverse_iterator reverse_iterator;
159
160 // constructors
161 cgiargsinfoclass ();
162
163 // basic container support
164 iterator begin () {return argsinfo.begin();}
165 const_iterator begin () const {return argsinfo.begin();}
166 iterator end () {return argsinfo.end();}
167 const_iterator end () const {return argsinfo.end();}
168
169 void erase(iterator pos) {argsinfo.erase(pos);}
170 void erase(iterator first, iterator last) {argsinfo.erase(first, last);}
171 cgiargsinfoclass &operator=(const cgiargsinfoclass &x) {argsinfo=x.argsinfo;return *this;}
172
173 bool empty () const {return argsinfo.empty();}
174 size_type size() const {return argsinfo.size();}
175
176
177 // added functionality
178 void clear () {argsinfo.erase(argsinfo.begin(),argsinfo.end());}
179
180 // addarginfo will combine the information with the present
181 // information. If name clashes were detected then the information
182 // will be written to logout and addarginfo will return false. No
183 // processing with the arguments should be done if this happens
184 // as the results will be meaningless.
185 bool addarginfo (ostream *logout, const cgiarginfo &info);
186 bool addarginfo (ostream *logout, const cgiargsinfoclass &info);
187
188 cgiarginfo *getarginfo (const text_t &key);
189 const cgiarginfo *getarginfo (const text_t &key) const;
190 cgiarginfo &operator[] (const text_t &key) {return argsinfo[key];}
191};
192
193
194#endif
Note: See TracBrowser for help on using the repository browser.