/********************************************************************** * * cgiargs.h -- * Copyright (C) 1999 The New Zealand Digital Library Project * * PUT COPYRIGHT NOTICE HERE * * $Id: cgiargs.h 154 1999-02-08 01:28:01Z rjmcnab $ * *********************************************************************/ #ifndef CGIARGS_H #define CGIARGS_H #include "gsdlconf.h" #include "text_t.h" #if defined(GSDL_USE_OBJECTSPACE) # include #elif defined(GSDL_USE_IOS_H) # include #else # include #endif #if defined(GSDL_USE_OBJECTSPACE) # include #elif defined(GSDL_USE_STL_H) # include #else # include #endif // response_t is used to define what type of cgi header // should be produced enum response_t {location, content}; typedef map textmap; // cgiargsclass is used to store a particular set // of cgi arguments. class cgiargsclass { protected: textmap args; public: //type support for textmap typedef textmap::iterator iterator; typedef textmap::const_iterator const_iterator; typedef textmap::reference reference; typedef textmap::const_reference const_reference; typedef textmap::size_type size_type; typedef textmap::difference_type difference_type; typedef textmap::const_reverse_iterator const_reverse_iterator; typedef textmap::reverse_iterator reverse_iterator; // constructors cgiargsclass (); // basic container support iterator begin () {return args.begin();} const_iterator begin () const {return args.begin();} iterator end () {return args.end();} const_iterator end () const {return args.end();} void erase(iterator pos) {args.erase(pos);} void erase(iterator first, iterator last) {args.erase(first, last);} cgiargsclass &operator=(const cgiargsclass &x) {args=x.args;return *this;} bool empty () const {return args.empty();} size_type size() const {return args.size();} // added functionality void clear () {args.erase(args.begin(),args.end());} // setdefaultarg, setdefaultintarg, and setdefaultcarg will // only set the argument if it is not already set // getargs returns NULL if there isn't an entry with // 'key' already defined, getintarg returns 0 if there wasn't an // entry with 'key' defined and operator[] returns "" if // 'key' wasn't already defined (and sets 'key'=""). void setarg (const text_t &key, const text_t &value); void setdefaultarg (const text_t &key, const text_t &value); void setintarg (const text_t &key, int value); void setdefaultintarg (const text_t &key, int value); void setcarg (const text_t &key, unsigned short c); void setdefaultcarg (const text_t &key, unsigned short c); text_t *getarg (const text_t &key); int getintarg (const text_t &key); text_t &operator[] (const text_t &key) {return args[key];} }; // stream operators to print cgi arguments for debugging purposes ostream &operator<<(ostream &outs, const cgiargsclass &args); // cgiarginfo holds information relating to a cgi argument class cgiarginfo { public: cgiarginfo (); // shortname is the name used in cgi arguments text_t shortname; // longname is the name used when giving information // about the argument and to spot name duplication text_t longname; // multiplechar should be set to true if the value can be // more than one character long bool multiplechar; // defaultstatus_t indicates how good the default is when different // defaults are given for one argument. "none" means there is no default // (a default might be given elsewhere). "weak" is a basic guess that // doesn't hold much weight, "good" is a better guess, "config" was a default // given in a configuration file, and "imperative" means it must not // be overriden at any costs (unless there is another "imperative"...) // Note: I assume that the comparison none < weak < good < config < imperative // holds :-/ enum defaultstatus_t {none, weak, good, config, imperative}; defaultstatus_t defaultstatus; text_t argdefault; // a default value // savedarginfo_t indicates whether the argument should be saved // between pages (e.g. using the compressed argument) or not. The // value of an argument can change from "can" to "mustnot" and // "can" to "must" but not "mustnot" to "must" or "must" to "mustnot". enum savedarginfo_t {mustnot, can, must}; savedarginfo_t savedarginfo; }; typedef map argsinfomap; // contains a list of cgi argument information class cgiargsinfoclass { protected: argsinfomap argsinfo; public: // type support for arginfomap typedef argsinfomap::iterator iterator; typedef argsinfomap::const_iterator const_iterator; typedef argsinfomap::reference reference; typedef argsinfomap::const_reference const_reference; typedef argsinfomap::size_type size_type; typedef argsinfomap::difference_type difference_type; typedef argsinfomap::const_reverse_iterator const_reverse_iterator; typedef argsinfomap::reverse_iterator reverse_iterator; // constructors cgiargsinfoclass (); // basic container support iterator begin () {return argsinfo.begin();} const_iterator begin () const {return argsinfo.begin();} iterator end () {return argsinfo.end();} const_iterator end () const {return argsinfo.end();} void erase(iterator pos) {argsinfo.erase(pos);} void erase(iterator first, iterator last) {argsinfo.erase(first, last);} cgiargsinfoclass &operator=(const cgiargsinfoclass &x) {argsinfo=x.argsinfo;return *this;} bool empty () const {return argsinfo.empty();} size_type size() const {return argsinfo.size();} // added functionality void clear () {argsinfo.erase(argsinfo.begin(),argsinfo.end());} // addarginfo will combine the information with the present // information. If name clashes were detected then the information // will be written to logout and addarginfo will return false. No // processing with the arguments should be done if this happens // as the results will be meaningless. bool addarginfo (ostream *logout, const cgiarginfo &info); bool addarginfo (ostream *logout, const cgiargsinfoclass &info); cgiarginfo *getarginfo (const text_t &key); const cgiarginfo *getarginfo (const text_t &key) const; cgiarginfo &operator[] (const text_t &key) {return argsinfo[key];} }; #endif