EHS Embedded HTTP Server  1.5.1.173
ehsconnection.h
00001 /* $Id: ehsconnection.h 166 2018-09-11 13:29:27Z 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 _EHSCONNECTION_H_
00027 #define _EHSCONNECTION_H_
00028 
00029 #include <ehstypes.h>
00030 #include <ctime>
00031 
00032 class EHSServer;
00033 class NetworkAbstraction;
00034 
00040 class EHSConnection {
00041 
00042     private:
00043 
00044         EHSConnection ( const EHSConnection & );
00045 
00046         EHSConnection & operator = ( const EHSConnection & );
00047 
00048     private:
00049 
00050         bool m_bRawMode; 
00051 
00052         bool m_bDoneReading; 
00053 
00054         bool m_bDisconnected; 
00055 
00056         bool m_bIdleHandling; 
00057 
00058         HttpRequest * m_poCurrentHttpRequest; 
00059 
00060         EHSServer * m_poEHSServer; 
00061 
00062         time_t m_nLastActivity; 
00063 
00064         int m_nRequests; 
00065 
00066         int m_nResponses; 
00067 
00068         int m_nActiveRequests; 
00069 
00071         NetworkAbstraction * m_poNetworkAbstraction;    
00072 
00074         std::string m_sBuffer;
00075 
00077         ResponseQueue m_oResponseQueue;
00078 
00080         HttpRequestList m_oHttpRequestList;
00081 
00083         std::string m_sRemoteAddress;
00084 
00086         std::string m_sLocalAddress;
00087 
00089         int m_nRemotePort;
00090 
00092         int m_nLocalPort;
00093 
00094         size_t m_nMaxRequestSize;
00095 
00097         std::string m_sParseContentType;
00098 
00099         pthread_mutex_t m_oMutex; 
00100 
00101     public:
00102 
00104         std::string GetRemoteAddress() const { return m_sRemoteAddress; }
00105 
00107         int GetRemotePort() const { return m_nRemotePort; }
00108 
00110         std::string GetLocalAddress() const { return m_sLocalAddress; }
00111 
00113         int GetLocalPort() const { return m_nLocalPort; }
00114 
00115         DEPRECATED("Use GetRemoteAddress()")
00120             std::string GetAddress() const { return GetRemoteAddress(); }
00121 
00122         DEPRECATED("Use GetRemotePort()")
00127             int GetPort() const { return GetRemotePort(); }
00128 
00130         bool Disconnected() const { return m_bDisconnected; }
00131 
00133         bool IsRaw() const { return m_bRawMode; }
00134 
00136         void AddResponse(ehs_autoptr<GenericResponse> ehs_rvref response);
00137 
00144         void EnableIdleTimeout(bool enable = true) { m_bIdleHandling = enable; }
00145 
00153         void EnableKeepAlive(bool enable = true);
00154 
00155     private:
00156 
00158         EHSConnection(NetworkAbstraction * ipoNetworkAbstraction,
00159                 EHSServer * ipoEHSServer);
00160 
00162         ~EHSConnection();
00163 
00165         void UpdateLastActivity() { m_nLastActivity = time(NULL); }
00166 
00168         time_t LastActivity() { return m_bIdleHandling ? m_nLastActivity : time(NULL); }
00169 
00171         bool StillReading() { return !m_bDoneReading; }
00172 
00175         void DoneReading ( bool ibDisconnected );
00176 
00178         HttpRequest *GetNextRequest();
00179 
00181         int CheckDone();
00182 
00184         enum AddBufferResult {
00185             ADDBUFFER_INVALID = 0,
00186             ADDBUFFER_OK,
00187             ADDBUFFER_INVALIDREQUEST,
00188             ADDBUFFER_TOOBIG,
00189             ADDBUFFER_NORESOURCE
00190         };
00191 
00193         AddBufferResult AddBuffer(char * ipsData, int inSize);
00194 
00201         void SendResponse(GenericResponse *response);
00202 
00204         int RequestsPending() { return (0 != m_nActiveRequests) || !m_oHttpRequestList.empty(); }
00205 
00207         NetworkAbstraction * GetNetworkAbstraction();
00208 
00210         void SetMaxRequestSize(size_t n) { m_nMaxRequestSize = n; }
00211 
00213         void SetParseContentType(const std::string & s) { m_sParseContentType = s; }
00214 
00215         friend class EHSServer;
00216 };
00217 
00218 #endif // _EHSCONNECTION_H_
 All Classes Functions Variables Enumerations