Cgicc.h
Go to the documentation of this file.
1 /* -*-mode:c++; c-file-style: "gnu";-*- */
2 /*
3  * $Id: Cgicc.h,v 1.19 2009/01/03 17:12:07 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 "cgicc/CgiDefs.h"
47 #include "cgicc/FormEntry.h"
48 #include "cgicc/FormFile.h"
49 #include "cgicc/CgiInput.h"
50 #include "cgicc/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&
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_ */
Class representing a single HTML form entry.
std::vector< FormEntry >::const_iterator const_form_iterator
A vector of const FormEntry objects.
Definition: Cgicc.h:68
Class that abstracts a data source.
Definition: CgiInput.h:58
std::vector< FormEntry >::iterator form_iterator
A vector of FormEntry objects.
Definition: Cgicc.h:59
Cgicc(const Cgicc &cgi)
Copy constructor.
Definition: Cgicc.h:129
std::vector< FormFile >::iterator file_iterator
A vector of FormFile objects.
Definition: Cgicc.h:71
Platform and operating system specific macro definitions.
const CgiEnvironment & getEnvironment() const
Definition: Cgicc.h:394
const std::vector< FormFile > & getFiles() const
Definition: Cgicc.h:380
Class that abstracts a data source.
Class encapsulating the CGI runtime environment.
The main class of the GNU cgicc library.
Definition: Cgicc.h:103
const std::vector< FormEntry > & getElements() const
Get all the submitted form elements, excluding files.
Definition: Cgicc.h:348
The namespace containing the cgicc library.
Definition: Cgicc.h:52
Class representing a file submitted via an HTML form.
Class encapsulating the CGI runtime environment.
std::vector< FormFile >::const_iterator const_file_iterator
A vector of const FormFile objects.
Definition: Cgicc.h:73

GNU cgicc - A C++ class library for writing CGI applications
Copyright © 1996 - 2004 Stephen F. Booth
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front Cover Texts, and with no Back-Cover Texts.
Documentation generated Fri Jul 3 2015 00:51:38 for cgicc by doxygen 1.8.8