EHS Embedded HTTP Server  1.5.0.132
ehstypes.h
00001 /* $Id: ehstypes.h.in 132 2012-04-15 18:25:58Z felfert $
00002  *
00003  * EHS is a library for embedding HTTP(S) support into a C++ application
00004  *
00005  * Copyright (C) 2004 Zachary J. Hansen
00006  *
00007  * Code cleanup, new features and bugfixes: Copyright (C) 2010 Fritz Elfert
00008  *
00009  *    This library is free software; you can redistribute it and/or
00010  *    modify it under the terms of the GNU Lesser General Public
00011  *    License version 2.1 as published by the Free Software Foundation;
00012  *
00013  *    This library is distributed in the hope that it will be useful,
00014  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  *    Lesser General Public License for more details.
00017  *
00018  *    You should have received a copy of the GNU Lesser General Public
00019  *    License along with this library; if not, write to the Free Software
00020  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  *
00022  *    This can be found in the 'COPYING' file.
00023  *
00024  */
00025 
00026 #ifndef EHSTYPES_H
00027 #define EHSTYPES_H
00028 
00029 #include <string>
00030 #include <cstring>
00031 #include <memory>
00032 #include <map>
00033 #include <deque>
00034 #include <list>
00035 
00036 class EHSServer;
00037 class EHSConnection;
00038 class EHS;
00039 class Datum;
00040 class FormValue;
00041 class HttpResponse;
00042 class HttpRequest;
00043 
00047 struct __caseless
00048 {
00052     bool operator() ( const std::string & s1, const std::string & s2 ) const
00053     {
00054         return strcasecmp( s1.c_str(), s2.c_str() ) < 0;
00055     }
00056 };
00057 
00058 #if 1
00059 # define ehs_autoptr std::unique_ptr
00060 # define ehs_move(x) std::move(x)
00061 # define ehs_rvref &&
00062 #else
00063 # include <boost/shared_ptr.hpp>
00064 # define ehs_autoptr boost::shared_ptr
00065 # define ehs_move(x) (x)
00066 # define ehs_rvref
00067 #endif
00068 
00069 #define DEPRECATED(x) __attribute__((deprecated (x)))
00070 
00071 #ifdef _WIN32
00072 #include <pthread.h>
00073 typedef unsigned long ehs_threadid_t;
00074 extern ehs_threadid_t THREADID(pthread_t t);
00075 #else
00076 typedef pthread_t ehs_threadid_t;
00077 #define THREADID
00078 #endif
00079 
00086 class GenericResponse {
00087     private:
00088         GenericResponse( const GenericResponse & );
00089         GenericResponse &operator = (const GenericResponse &);
00090 
00091     public:
00097         GenericResponse(int inResponseId, EHSConnection * ipoEHSConnection)
00098             : m_nResponseId(inResponseId)
00099             , m_sBody("")
00100             , m_poEHSConnection(ipoEHSConnection)
00101     { }
00102 
00108         void SetBody(const char *ipsBody, size_t inBodyLength) {
00109             m_sBody = std::string(ipsBody, inBodyLength);
00110         }
00111 
00116         std::string & GetBody() { return m_sBody; };
00117 
00123         EHSConnection * GetConnection() { return m_poEHSConnection; }
00124 
00126         virtual ~GenericResponse() { }
00127 
00134         void EnableIdleTimeout(bool enable = true);
00135 
00143         void EnableKeepAlive(bool enable = true);
00144 
00145 
00146     protected:
00148         int m_nResponseId;
00149 
00151         std::string m_sBody;
00152 
00154         EHSConnection * m_poEHSConnection;
00155 
00156         friend class EHSConnection;
00157         friend class EHSServer;
00158 };
00159 
00161 typedef std::map < std::string, std::string > StringMap;
00162 
00164 typedef std::map < std::string, std::string, __caseless > StringCaseMap;
00165 
00167 typedef std::list < std::string > StringList;
00168 
00170 typedef std::list < EHSConnection * > EHSConnectionList;
00171 
00173 typedef std::map < std::string, EHS * > EHSMap;
00174 
00176 typedef std::map < std::string, Datum > EHSServerParameters;
00177 
00179 typedef std::map < std::string, std::string > CookieMap;
00180 
00182 typedef std::map < std::string, FormValue > FormValueMap;
00183 
00185 typedef std::map < std::string, Datum > CookieParameters;
00186 
00188 typedef std::deque <ehs_autoptr<GenericResponse> > ResponseQueue;
00189 
00191 typedef std::map < ehs_threadid_t, HttpRequest * > CurrentRequestMap;
00192 
00194 typedef std::list < HttpRequest * > HttpRequestList;
00195 
00196 #endif