Cgicc.h
Go to the documentation of this file.
1/* -*-mode:c++; c-file-style: "gnu";-*- */
2/*
3 * $Id: Cgicc.h,v 1.20 2014/04/23 20:55:04 sebdiaz Exp $
4 *
5 * Copyright (C) 1996 - 2004 Stephen F. Booth <sbooth@gnu.org>
6 * 2007 Sebastien DIAZ <sebastien.diaz@gmail.com>
7 * Part of the GNU cgicc library, http://www.gnu.org/software/cgicc
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 3 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
22 */
23
24#ifndef _CGICC_H_
25#define _CGICC_H_ 1
26
27#ifdef __GNUG__
28# pragma interface
29#endif
30
35/*
36 * The GNU cgicc library, by Stephen F. Booth <sbooth@gnu.org>
37 * http://www.cgicc.org
38 *
39 * The latest version can be found on your closest GNU mirror site.
40 * Please mail bug reports to <bug-cgicc@gnu.org>
41 */
42
43#include <vector>
44#include <string>
45
46#include "CgiDefs.h"
47#include "FormEntry.h"
48#include "FormFile.h"
49#include "CgiInput.h"
50#include "CgiEnvironment.h"
51
52 namespace cgicc {
53
54#ifdef WIN32
55 template class CGICC_API std::vector<FormEntry>;
56 template class CGICC_API std::vector<FormFile>;
57#endif
58
59 class MultipartHeader;
60
61 // ============================================================
62 // Iterator typedefs
63 // ============================================================
64
66 typedef std::vector<FormEntry>::iterator form_iterator;
68 typedef std::vector<FormEntry>::const_iterator const_form_iterator;
69
71 typedef std::vector<FormFile>::iterator file_iterator;
73 typedef std::vector<FormFile>::const_iterator const_file_iterator;
74
75 // ============================================================
76 // Class Cgicc
77 // ============================================================
78
103 class CGICC_API Cgicc {
104 public:
105
106 // ============================================================
107
110
120 Cgicc(CgiInput *input = 0);
121
128 inline
129 Cgicc(const Cgicc& cgi)
130 : fEnvironment(cgi.fEnvironment)
131 { operator=(cgi); }
132
138 ~Cgicc();
140
141 // ============================================================
142
145
153 inline bool
154 operator== (const Cgicc& cgi) const
155 { return this->fEnvironment == cgi.fEnvironment; }
156
164 inline bool
165 operator!= (const Cgicc& cgi) const
166 { return ! operator==(cgi); }
167
168#ifdef WIN32
169 /* Dummy operator for MSVC++ */
170 inline bool
171 operator< (const Cgicc& cgi) const
172 { return false; }
173#endif
174
182 Cgicc&
183 operator= (const Cgicc& cgi);
185
186 // ============================================================
187
192
199 const char*
200 getCompileDate() const;
201
208 const char*
209 getCompileTime() const;
210
217 const char*
218 getVersion() const;
219
226 const char*
227 getHost() const;
229
230 // ============================================================
231
236
243 bool
244 queryCheckbox(const std::string& elementName) const;
245
252 inline form_iterator
253 operator[] (const std::string& name)
254 { return getElement(name); }
255
262 std::string
263 operator() (const std::string& name) const;
264
271 inline const_form_iterator
272 operator[] (const std::string& name) const
273 { return getElement(name); }
274
281 form_iterator
282 getElement(const std::string& name);
283
290 const_form_iterator
291 getElement(const std::string& name) const;
292
300 bool
301 getElement(const std::string& name,
302 std::vector<FormEntry>& result) const;
303
310 form_iterator
311 getElementByValue(const std::string& value);
312
319 const_form_iterator
320 getElementByValue(const std::string& value) const;
321
329 bool
330 getElementByValue(const std::string& value,
331 std::vector<FormEntry>& result) const;
332
338 inline const std::vector<FormEntry>&
339 operator* () const
340 { return fFormData; }
341
347 inline const std::vector<FormEntry>&
348 getElements() const
349 { return fFormData; }
351
352 // ============================================================
353
356
363 file_iterator
364 getFile(const std::string& name);
365
372 const_file_iterator
373 getFile(const std::string& name) const;
374
379 inline const std::vector<FormFile>&
380 getFiles() const
381 { return fFormFiles; }
383
384 // ============================================================
385
388
393 inline const CgiEnvironment&
394 getEnvironment() const
395 { return fEnvironment;}
397
398 // ============================================================
399
402
409 void
410 save(const std::string& filename) const;
411
418 void
419 restore(const std::string& filename);
421
422 private:
423 CgiEnvironment fEnvironment;
424 std::vector<FormEntry> fFormData;
425 std::vector<FormFile> fFormFiles;
426
427 // Convert query string into a list of FormEntries
428 void
429 parseFormInput(const std::string& data, const std::string& content_type = "application/x-www-form-urlencoded");
430
431 // Parse a multipart/form-data header
432 MultipartHeader
433 parseHeader(const std::string& data);
434
435 // Parse a (name=value) form entry
436 void
437 parsePair(const std::string& data);
438
439 // Parse a MIME entry for ENCTYPE=""
440 void
441 parseMIME(const std::string& data);
442
443 // Find elements in the list of entries
444 bool
445 findEntries(const std::string& param,
446 bool byName,
447 std::vector<FormEntry>& result) const;
448 };
449
450} // namespace cgicc
451
452#endif /* ! _CGICC_H_ */
CgiDefs.h
Platform and operating system specific macro definitions.
CgiEnvironment.h
Class encapsulating the CGI runtime environment.
CgiInput.h
Class that abstracts a data source.
FormEntry.h
Class representing a single HTML form entry.
FormFile.h
Class representing a file submitted via an HTML form.
cgicc::CgiEnvironment
Class encapsulating the CGI runtime environment.
Definition: CgiEnvironment.h:77
cgicc::CgiInput
Class that abstracts a data source.
Definition: CgiInput.h:59
cgicc::Cgicc
The main class of the GNU cgicc library.
Definition: Cgicc.h:103
cgicc::Cgicc::restore
void restore(const std::string &filename)
Restore from a previously-saved CGI environment.
cgicc::Cgicc::getCompileDate
const char * getCompileDate() const
Get the date on which this library was compiled.
cgicc::Cgicc::getEnvironment
const CgiEnvironment & getEnvironment() const
Definition: Cgicc.h:394
cgicc::Cgicc::Cgicc
Cgicc(const Cgicc &cgi)
Copy constructor.
Definition: Cgicc.h:129
cgicc::Cgicc::getElementByValue
const_form_iterator getElementByValue(const std::string &value) const
Find a radio button in a radio group, or a selected list item.
cgicc::Cgicc::queryCheckbox
bool queryCheckbox(const std::string &elementName) const
Query whether a checkbox is checked.
cgicc::Cgicc::getVersion
const char * getVersion() const
Get the version number of cgicc.
cgicc::Cgicc::getFile
file_iterator getFile(const std::string &name)
Find an uploaded file.
cgicc::Cgicc::getElement
bool getElement(const std::string &name, std::vector< FormEntry > &result) const
Find multiple checkboxes in a group or selected items in a list.
cgicc::Cgicc::getElementByValue
bool getElementByValue(const std::string &value, std::vector< FormEntry > &result) const
Find multiple checkboxes in a group or selected items in a list.
cgicc::Cgicc::Cgicc
Cgicc(CgiInput *input=0)
Constructor.
cgicc::Cgicc::getElement
const_form_iterator getElement(const std::string &name) const
Find a radio button in a radio group, or a selected list item.
cgicc::Cgicc::~Cgicc
~Cgicc()
Destructor.
cgicc::Cgicc::getCompileTime
const char * getCompileTime() const
Get the time at which this library was compiled.
cgicc::Cgicc::getHost
const char * getHost() const
Get the platform for which Cgicc was configured.
cgicc::Cgicc::save
void save(const std::string &filename) const
Save the current CGI environment to a file.
cgicc::Cgicc::getFile
const_file_iterator getFile(const std::string &name) const
Find an uploaded file.
cgicc::Cgicc::getFiles
const std::vector< FormFile > & getFiles() const
Definition: Cgicc.h:380
cgicc::Cgicc::getElementByValue
form_iterator getElementByValue(const std::string &value)
Find a radio button in a radio group, or a selected list item.
cgicc::Cgicc::getElements
const std::vector< FormEntry > & getElements() const
Get all the submitted form elements, excluding files.
Definition: Cgicc.h:348
cgicc::Cgicc::getElement
form_iterator getElement(const std::string &name)
Find a radio button in a radio group, or a selected list item.
cgicc
The namespace containing the cgicc library.
Definition: Cgicc.h:52
cgicc::form_iterator
std::vector< FormEntry >::iterator form_iterator
A vector of FormEntry objects.
Definition: Cgicc.h:59
cgicc::const_file_iterator
std::vector< FormFile >::const_iterator const_file_iterator
A vector of const FormFile objects.
Definition: Cgicc.h:73
cgicc::const_form_iterator
std::vector< FormEntry >::const_iterator const_form_iterator
A vector of const FormEntry objects.
Definition: Cgicc.h:68
cgicc::file_iterator
std::vector< FormFile >::iterator file_iterator
A vector of FormFile objects.
Definition: Cgicc.h:71