EHS Embedded HTTP Server  1.5.1.173
ehstypes.h
1 /* $Id: ehstypes.h.in 166 2018-09-11 13:29:27Z felfert $
2  *
3  * EHS is a library for embedding HTTP(S) support into a C++ application
4  *
5  * Copyright (C) 2004 Zachary J. Hansen
6  *
7  * Code cleanup, new features and bugfixes: Copyright (C) 2010 Fritz Elfert
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License version 2.1 as published by the Free Software Foundation;
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21  *
22  * This can be found in the 'COPYING' file.
23  *
24  */
25 
26 #ifndef EHSTYPES_H
27 #define EHSTYPES_H
28 
29 #include <string>
30 #include <cstring>
31 #include <memory>
32 #include <map>
33 #include <deque>
34 #include <list>
35 
36 class EHSServer;
37 class EHSConnection;
38 class EHS;
39 class Datum;
40 class FormValue;
41 class HttpResponse;
42 class HttpRequest;
43 
47 struct __caseless
48 {
52  bool operator() ( const std::string & s1, const std::string & s2 ) const
53  {
54  return strcasecmp( s1.c_str(), s2.c_str() ) < 0;
55  }
56 };
57 
58 #if 1
59 # define ehs_autoptr std::unique_ptr
60 # define ehs_move(x) std::move(x)
61 # define ehs_rvref &&
62 #else
63 # include <boost/shared_ptr.hpp>
64 # define ehs_autoptr boost::shared_ptr
65 # define ehs_move(x) (x)
66 # define ehs_rvref
67 #endif
68 
69 #define DEPRECATED(x) __attribute__((deprecated (x)))
70 
71 #ifdef _WIN32
72 #include <pthread.h>
73 typedef uint64_t ehs_threadid_t;
74 extern ehs_threadid_t THREADID(pthread_t t);
75 #else
76 typedef pthread_t ehs_threadid_t;
77 #define THREADID
78 #endif
79 
87  private:
89  GenericResponse &operator = (const GenericResponse &);
90 
91  public:
97  GenericResponse(int inResponseId, EHSConnection * ipoEHSConnection)
98  : m_nResponseId(inResponseId)
99  , m_sBody("")
100  , m_poEHSConnection(ipoEHSConnection)
101  { }
102 
108  void SetBody(const char *ipsBody, size_t inBodyLength) {
109  m_sBody = std::string(ipsBody, inBodyLength);
110  }
111 
116  std::string & GetBody() { return m_sBody; };
117 
124 
126  virtual ~GenericResponse() { }
127 
134  void EnableIdleTimeout(bool enable = true);
135 
143  void EnableKeepAlive(bool enable = true);
144 
145 
146  protected:
149 
151  std::string m_sBody;
152 
155 
156  friend class EHSConnection;
157  friend class EHSServer;
158 };
159 
161 typedef std::map < std::string, std::string > StringMap;
162 
164 typedef std::map < std::string, std::string, __caseless > StringCaseMap;
165 
167 typedef std::list < std::string > StringList;
168 
170 typedef std::list < EHSConnection * > EHSConnectionList;
171 
173 typedef std::map < std::string, EHS * > EHSMap;
174 
176 typedef std::map < std::string, Datum > EHSServerParameters;
177 
179 typedef std::map < std::string, std::string > CookieMap;
180 
182 typedef std::map < std::string, FormValue > FormValueMap;
183 
185 typedef std::map < std::string, Datum > CookieParameters;
186 
188 typedef std::deque <ehs_autoptr<GenericResponse> > ResponseQueue;
189 
191 typedef std::map < ehs_threadid_t, HttpRequest * > CurrentRequestMap;
192 
194 typedef std::list < HttpRequest * > HttpRequestList;
195 
196 #endif
EHSServer contains all the network related services for EHS.
Definition: ehsserver.h:34
void EnableIdleTimeout(bool enable=true)
Enable/Disable idle-timeout handling for the current connection.
EHS provides HTTP server functionality to a child class.
Definition: ehs.h:147
std::string m_sBody
the actual body to be sent back
Definition: ehstypes.h:151
EHSConnection abstracts the concept of a connection to an EHS application.
Definition: ehsconnection.h:40
GenericResponse(int inResponseId, EHSConnection *ipoEHSConnection)
Constructs a new instance.
Definition: ehstypes.h:97
int m_nResponseId
response id for making sure we send responses in the right order
Definition: ehstypes.h:148
void EnableKeepAlive(bool enable=true)
Enable/Disable TCP keepalive on the underlying socket of the current connection.
Caseless Compare class for case insensitive map.
Definition: ehstypes.h:47
void SetBody(const char *ipsBody, size_t inBodyLength)
Sets the body of this instance.
Definition: ehstypes.h:108
virtual ~GenericResponse()
Destructor.
Definition: ehstypes.h:126
bool operator()(const std::string &s1, const std::string &s2) const
case-insensitive comparator
Definition: ehstypes.h:52
EHSConnection * m_poEHSConnection
ehs connection object this response goes back on
Definition: ehstypes.h:154
std::string & GetBody()
retrieves the body of this response.
Definition: ehstypes.h:116
This class stores form data sent from the client in GET and POST requests.
Definition: formvalue.h:39
EHSConnection * GetConnection()
retrieves the EHSConnection, on which this response is supposed to be send.
Definition: ehstypes.h:123
This class represents what is sent back to the client.
Definition: ehstypes.h:86
This class represents a clients HTTP request.
Definition: httprequest.h:51
class that makes it easy to go between numbers and strings
Definition: datum.h:36
This class represents what is sent back to the client.
Definition: httpresponse.h:54