1 /** \file HttpdSocket.h
4 Copyright (C) 2001-2007 Anders Hedstrom (grymse@alhem.net)
6 This library is made available under the terms of the GNU GPL.
8 If you would like to use this library in a closed-source application,
9 a separate license agreement is available. For information about
10 the closed-source license agreement for the C++ sockets library,
11 please visit http://www.alhem.net/Sockets/license.html and/or
12 email license@alhem.net.
14 This program is free software; you can redistribute it and/or
15 modify it under the terms of the GNU General Public License
16 as published by the Free Software Foundation; either version 2
17 of the License, or (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 #ifndef _SOCKETS_HttpdSocket_H
29 #define _SOCKETS_HttpdSocket_H
31 #include "sockets-config.h"
32 #include "HTTPSocket.h"
33 #include "ISocketHandler.h"
35 #ifdef SOCKETS_NAMESPACE
36 namespace SOCKETS_NAMESPACE
{
44 /** \defgroup webserver Webserver framework */
45 /** Web server socket framework.
47 class HttpdSocket
: public HTTPSocket
50 HttpdSocket(ISocketHandler
& );
54 void OnHeader(const std::string
& key
,const std::string
& value
);
55 void OnHeaderComplete();
56 void OnData(const char *,size_t);
58 /** This method needs to be implemented with logic to produce
59 a response to an incoming request. */
60 virtual void Exec() = 0;
61 /** Get current date in http rfc format. */
62 const std::string
& GetHttpDate() const;
63 /** Get pointer to cookie class. */
64 HttpdCookies
*GetCookies();
65 /** Get pointer to query string/form data class. */
66 const HttpdForm
*GetForm() const;
68 size_t ContentLength() const { return m_content_length
; }
69 const IFile
*Body() const { return m_file
; }
70 int RequestId() const { return m_request_id
; }
73 HttpdSocket(const HttpdSocket
& s
) : HTTPSocket(s
) {}
74 /** Decode and send a base64-encoded string.
75 \param str64 Base64-encoded string
76 \param type Mime type of content (content-type header) */
77 void Send64(const std::string
& str64
, const std::string
& type
);
78 std::string
datetime2httpdate(const std::string
& dt
);
79 std::string
GetDate();
82 std::string m_http_cookie
;
83 std::string m_content_type
;
84 std::string m_content_length_str
;
85 std::string m_if_modified_since
;
88 HttpdSocket
& operator=(const HttpdSocket
& s
) { return *this; }
89 static int m_request_count
;
90 static std::string m_start
;
91 size_t m_content_length
;
95 std::string m_http_date
;
96 HttpdCookies
*m_cookies
;
101 #ifdef SOCKETS_NAMESPACE
105 #endif // _SOCKETS_HttpdSocket_H