Cgicc.h

Go to the documentation of this file.
00001 /* -*-mode:c++; c-file-style: "gnu";-*- */
00002 /*
00003  *  $Id: Cgicc_8h-source.html,v 1.3 2008/01/19 21:53:40 sebdiaz Exp $
00004  *
00005  *  Copyright (C) 1996 - 2004 Stephen F. Booth <sbooth@gnu.org>
00006  *                       2007 Sebastien DIAZ <sebastien.diaz@gmail.com>
00007  *  Part of the GNU cgicc library, http://www.gnu.org/software/cgicc
00008  *
00009  *  This library is free software; you can redistribute it and/or
00010  *  modify it under the terms of the GNU Lesser General Public
00011  *  License as published by the Free Software Foundation; either
00012  *  version 3 of the License, or (at your option) any later version.
00013  *
00014  *  This library is distributed in the hope that it will be useful,
00015  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017  *  Lesser General Public License for more details.
00018  *
00019  *  You should have received a copy of the GNU Lesser General Public
00020  *  License along with this library; if not, write to the Free Software
00021  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
00022  */
00023 
00024 #ifndef _CGICC_H_
00025 #define _CGICC_H_ 1
00026 
00027 #ifdef __GNUG__
00028 #  pragma interface
00029 #endif
00030 
00035 /*
00036  * The GNU cgicc library, by Stephen F. Booth <sbooth@gnu.org>
00037  * http://www.cgicc.org
00038  *
00039  * The latest version can be found on your closest GNU mirror site.
00040  * Please mail bug reports to <bug-cgicc@gnu.org>
00041  */
00042 
00043 #include <vector>
00044 #include <string>
00045 
00046 #include "cgicc/CgiDefs.h"
00047 #include "cgicc/FormEntry.h"
00048 #include "cgicc/FormFile.h"
00049 #include "cgicc/CgiInput.h"
00050 #include "cgicc/CgiEnvironment.h"
00051 
00052 namespace cgicc {
00053   
00054 #ifdef WIN32
00055   template class CGICC_API std::vector<FormEntry>;
00056   template class CGICC_API std::vector<FormFile>;
00057 #endif
00058   
00059   class MultipartHeader;
00060   
00061   // ============================================================
00062   // Iterator typedefs
00063   // ============================================================
00064   
00066   typedef std::vector<FormEntry>::iterator      form_iterator;
00068   typedef std::vector<FormEntry>::const_iterator const_form_iterator;
00069   
00071   typedef std::vector<FormFile>::iterator       file_iterator;
00073   typedef std::vector<FormFile>::const_iterator const_file_iterator;
00074   
00075   // ============================================================
00076   // Class Cgicc
00077   // ============================================================
00078   
00103   class CGICC_API Cgicc {
00104   public:
00105     
00106     // ============================================================
00107     
00110     
00120     Cgicc(CgiInput *input = 0);
00121     
00128     inline
00129     Cgicc(const Cgicc& cgi)
00130       : fEnvironment(cgi.fEnvironment)
00131     { operator=(cgi); }
00132 
00138     ~Cgicc();
00140     
00141     // ============================================================
00142     
00145     
00153     inline bool 
00154     operator== (const Cgicc& cgi)               const
00155     { return this->fEnvironment == cgi.fEnvironment; }
00156     
00164     inline bool
00165     operator!= (const Cgicc& cgi)               const
00166     { return ! operator==(cgi); }
00167     
00168 #ifdef WIN32
00169     /* Dummy operator for MSVC++ */
00170     inline bool
00171     operator< (const Cgicc& cgi)                const
00172     { return false; }
00173 #endif
00174     
00182     Cgicc& 
00183     operator= (const Cgicc& cgi);
00185 
00186     // ============================================================
00187     
00192     
00199     const char*
00200     getCompileDate()                                    const;
00201     
00208     const char*
00209     getCompileTime()                                    const;
00210     
00217     const char*
00218     getVersion()                                        const;
00219     
00226     const char*
00227     getHost()                                           const;
00229     
00230     // ============================================================
00231     
00236     
00243     bool 
00244     queryCheckbox(const std::string& elementName)       const;
00245     
00252     inline form_iterator 
00253     operator[] (const std::string& name)
00254     { return getElement(name); }
00255 
00262     std::string
00263     operator() (const std::string& name)                const;
00264     
00271     inline const_form_iterator 
00272     operator[] (const std::string& name)                const
00273     { return getElement(name); }
00274     
00281     form_iterator 
00282     getElement(const std::string& name);
00283     
00290     const_form_iterator 
00291     getElement(const std::string& name)                 const;
00292     
00300     bool 
00301     getElement(const std::string& name,
00302                std::vector<FormEntry>& result)          const;
00303     
00310     form_iterator 
00311     getElementByValue(const std::string& value);
00312     
00319     const_form_iterator 
00320     getElementByValue(const std::string& value)         const;
00321     
00329     bool 
00330     getElementByValue(const std::string& value,
00331                       std::vector<FormEntry>& result)   const;
00332     
00338     inline const std::vector<FormEntry>& 
00339     operator* ()                                        const
00340     { return fFormData; }
00341     
00347     inline const std::vector<FormEntry>&
00348     getElements()                                       const
00349     { return fFormData; }
00351     
00352     // ============================================================
00353     
00356     
00363     file_iterator 
00364     getFile(const std::string& name);
00365     
00372     const_file_iterator 
00373     getFile(const std::string& name)                    const;
00374     
00379     inline const std::vector<FormFile>&
00380     getFiles()                                          const
00381     { return fFormFiles; }
00383     
00384     // ============================================================
00385     
00388     
00393     inline const CgiEnvironment&
00394     getEnvironment()                                    const
00395     { return fEnvironment;}
00397     
00398     // ============================================================
00399     
00402     
00409     void 
00410     save(const std::string& filename)                   const;
00411     
00418     void 
00419     restore(const std::string& filename);
00421     
00422   private:
00423     CgiEnvironment              fEnvironment;
00424     std::vector<FormEntry>      fFormData;
00425     std::vector<FormFile>       fFormFiles;
00426 
00427     // Convert query string into a list of FormEntries
00428     void 
00429     parseFormInput(const std::string& data);
00430     
00431     // Parse a multipart/form-data header
00432     MultipartHeader
00433     parseHeader(const std::string& data);
00434     
00435     // Parse a (name=value) form entry
00436     void 
00437     parsePair(const std::string& data);
00438     
00439     // Parse a MIME entry for ENCTYPE=""
00440     void
00441     parseMIME(const std::string& data);
00442     
00443     // Find elements in the list of entries
00444     bool 
00445     findEntries(const std::string& param, 
00446                 bool byName,
00447                 std::vector<FormEntry>& result)         const;
00448   };
00449   
00450 } // namespace cgicc
00451 
00452 #endif /* ! _CGICC_H_ */

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 Sat Jan 19 21:15:58 2008 for cgicc by doxygen 1.5.1