svn cleanup
[anytun.git] / Sockets / HttpdForm.h
blob962a753e1673257534912b7f1f8e2da7a01b5516
1 /** \file HttpdForm.h - read stdin, parse cgi input
2 **
3 ** Written: 1999-Feb-10 grymse@alhem.net
4 **/
6 /*
7 Copyright (C) 1999-2007 Anders Hedstrom
9 This library is made available under the terms of the GNU GPL.
11 If you would like to use this library in a closed-source application,
12 a separate license agreement is available. For information about
13 the closed-source license agreement for the C++ sockets library,
14 please visit http://www.alhem.net/Sockets/license.html and/or
15 email license@alhem.net.
17 This program is free software; you can redistribute it and/or
18 modify it under the terms of the GNU General Public License
19 as published by the Free Software Foundation; either version 2
20 of the License, or (at your option) any later version.
22 This program is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 GNU General Public License for more details.
27 You should have received a copy of the GNU General Public License
28 along with this program; if not, write to the Free Software
29 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 #ifndef _SOCKETS_HttpdForm_H
33 #define _SOCKETS_HttpdForm_H
35 #include "sockets-config.h"
36 #include <string>
37 #include <list>
39 #ifdef SOCKETS_NAMESPACE
40 namespace SOCKETS_NAMESPACE {
41 #endif
44 class IFile;
46 /** Parse/store a http query_string/form-data body.
47 \ingroup webserver */
48 class HttpdForm
50 /**
51 * Store the name/value pairs from a GET/POST operation.
52 * "name" does not have to be unique.
53 \ingroup webserver
55 struct CGI
57 CGI(const std::string& n,const std::string& v) : name(n),value(v) {}
58 CGI(const std::string& n,const std::string& v,const std::string& p) : name(n),value(v),path(p) {}
59 std::string name;
60 std::string value;
61 std::string path;
63 /** list of key/value pairs. */
64 typedef std::list<CGI *> cgi_v;
66 public:
67 /**
68 * Default constructor (used in POST operations).
69 * Input is read from stdin. Number of characters to read
70 * can be found in the environment variable CONTENT_LENGTH.
72 HttpdForm(IFile *, const std::string& content_type, size_t content_length);
73 /**
74 * Another constructor (used in GET operations).
75 * Input is read from the environment variable QUERY_STRING.
76 * @param query_string The httpd server provided QUERY_STRING
77 * @param length Query string length.
79 HttpdForm(const std::string& query_string,size_t length);
80 ~HttpdForm();
82 void EnableRaw(bool);
84 /** Encode characters '<' '>' '&' as &lt; &gt; &amp; */
85 void strcpyval(std::string&,const char *) const;
87 /* get names */
88 bool getfirst(std::string& n) const;
89 bool getnext(std::string& n) const;
91 /* get names and values */
92 bool getfirst(std::string& n,std::string& v) const;
93 bool getnext(std::string& n,std::string& v) const;
95 /* get value */
96 int getvalue(const std::string& ,std::string& ) const;
97 std::string getvalue(const std::string& ) const;
98 size_t getlength(const std::string& ) const;
99 cgi_v& getbase();
101 const std::string& GetBoundary() const;
103 private:
104 HttpdForm(const HttpdForm& ) {}
105 HttpdForm& operator=(const HttpdForm& ) { return *this; }
106 cgi_v m_cgi;
107 mutable cgi_v::const_iterator m_current;
108 std::string m_strBoundary;
109 bool raw;
113 #ifdef SOCKETS_NAMESPACE
115 #endif
117 #endif // _SOCKETS_HttpdForm_H