1 /** \file HttpdForm.h - read stdin, parse cgi input
3 ** Written: 1999-Feb-10 grymse@alhem.net
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"
39 #ifdef SOCKETS_NAMESPACE
40 namespace SOCKETS_NAMESPACE
{
46 /** Parse/store a http query_string/form-data body.
51 * Store the name/value pairs from a GET/POST operation.
52 * "name" does not have to be unique.
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
) {}
63 /** list of key/value pairs. */
64 typedef std::list
<CGI
*> cgi_v
;
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
);
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
);
84 /** Encode characters '<' '>' '&' as < > & */
85 void strcpyval(std::string
&,const char *) const;
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;
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;
101 const std::string
& GetBoundary() const;
104 HttpdForm(const HttpdForm
& ) {}
105 HttpdForm
& operator=(const HttpdForm
& ) { return *this; }
107 mutable cgi_v::const_iterator m_current
;
108 std::string m_strBoundary
;
113 #ifdef SOCKETS_NAMESPACE
117 #endif // _SOCKETS_HttpdForm_H