forked from cloudbase/EHS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ehstypes.h.in
196 lines (163 loc) · 5.91 KB
/
ehstypes.h.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/* $Id$
*
* EHS is a library for embedding HTTP(S) support into a C++ application
*
* Copyright (C) 2004 Zachary J. Hansen
*
* Code cleanup, new features and bugfixes: Copyright (C) 2010 Fritz Elfert
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation;
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* This can be found in the 'COPYING' file.
*
*/
#ifndef EHSTYPES_H
#define EHSTYPES_H
#include <string>
#include <cstring>
#include <memory>
#include <map>
#include <deque>
#include <list>
class EHSServer;
class EHSConnection;
class EHS;
class Datum;
class FormValue;
class HttpResponse;
class HttpRequest;
/**
* Caseless Compare class for case insensitive map
*/
struct __caseless
{
/**
* case-insensitive comparator
*/
bool operator() ( const std::string & s1, const std::string & s2 ) const
{
return strcasecmp( s1.c_str(), s2.c_str() ) < 0;
}
};
#if @USE_UNIQUE_PTR@
# define ehs_autoptr std::unique_ptr
# define ehs_move(x) std::move(x)
# define ehs_rvref &&
#else
# include <boost/shared_ptr.hpp>
# define ehs_autoptr boost::shared_ptr
# define ehs_move(x) (x)
# define ehs_rvref
#endif
@DEFINE_DEPRECATED@
#ifdef _WIN32
#include <pthread.h>
typedef unsigned long ehs_threadid_t;
extern ehs_threadid_t THREADID(pthread_t t);
#else
typedef pthread_t ehs_threadid_t;
#define THREADID
#endif
/**
* This class represents what is sent back to the client.
* It contains the actual body only.
* Any HTTP specific additions like headers or the response
* code are handled in the drived class HttpResponse.
*/
class GenericResponse {
private:
GenericResponse( const GenericResponse & );
GenericResponse &operator = (const GenericResponse &);
public:
/**
* Constructs a new instance.
* @param inResponseId A unique Id (normally derived from the corresponding request Id).
* @param ipoEHSConnection The connection, on which this response should be sent.
*/
GenericResponse(int inResponseId, EHSConnection * ipoEHSConnection)
: m_nResponseId(inResponseId)
, m_sBody("")
, m_poEHSConnection(ipoEHSConnection)
{ }
/**
* Sets the body of this instance.
* @param ipsBody The content to set.
* @param inBodyLength The length of the body.
*/
void SetBody(const char *ipsBody, size_t inBodyLength) {
m_sBody = std::string(ipsBody, inBodyLength);
}
/**
* retrieves the body of this response.
* @return The current content of the body.
*/
std::string & GetBody() { return m_sBody; };
/**
* retrieves the EHSConnection, on which this response
* is supposed to be send.
* @return The EHSConnection of this instance.
*/
EHSConnection * GetConnection() { return m_poEHSConnection; }
/// Destructor
virtual ~GenericResponse() { }
/**
* Enable/Disable idle-timeout handling for the current connection.
* @param enable If true, idle-timeout handling is enabled,
* otherwise the socket may stay open forever.
* When creating an EHSConnection, this is initially enabled.
*/
void EnableIdleTimeout(bool enable = true);
/**
* Enable/Disable TCP keepalive on the underlying socket of the current connection.
* This enables detection of "dead" sockets, even when
* idle-timeout handling is disabled.
* @param enable If true, enable TCP keepalive.
* When creating an EHSConnection, this is initially disabled.
*/
void EnableKeepAlive(bool enable = true);
protected:
/// response id for making sure we send responses in the right order
int m_nResponseId;
/// the actual body to be sent back
std::string m_sBody;
/// ehs connection object this response goes back on
EHSConnection * m_poEHSConnection;
friend class EHSConnection;
friend class EHSServer;
};
/// generic std::string => std::string map used by many things
typedef std::map < std::string, std::string > StringMap;
/// std::string => std::string map with case-insensitive search
typedef std::map < std::string, std::string, __caseless > StringCaseMap;
/// generic list of std::strings
typedef std::list < std::string > StringList;
/// list of EHSConnection objects to handle all current connections
typedef std::list < EHSConnection * > EHSConnectionList;
/// map for registered EHS objects on a path
typedef std::map < std::string, EHS * > EHSMap;
/// map type for storing EHSServer parameters
typedef std::map < std::string, Datum > EHSServerParameters;
/// cookies that come in from the client, mapped by name
typedef std::map < std::string, std::string > CookieMap;
/// describes a form value that came in from a client
typedef std::map < std::string, FormValue > FormValueMap;
/// describes a cookie to be sent back to the client
typedef std::map < std::string, Datum > CookieParameters;
/// holds respose objects not yet ready to send
typedef std::deque <ehs_autoptr<GenericResponse> > ResponseQueue;
/// holds the currently handled request for each thread
typedef std::map < ehs_threadid_t, HttpRequest * > CurrentRequestMap;
/// holds a list of pending requests
typedef std::list < HttpRequest * > HttpRequestList;
#endif