EHS Embedded HTTP Server
1.5.0.132
|
00001 /* $Id: ehsconnection.h 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 _EHSCONNECTION_H_ 00027 #define _EHSCONNECTION_H_ 00028 00029 #include <ehstypes.h> 00030 00031 class EHSServer; 00032 class NetworkAbstraction; 00033 00039 class EHSConnection { 00040 00041 private: 00042 00043 EHSConnection ( const EHSConnection & ); 00044 00045 EHSConnection & operator = ( const EHSConnection & ); 00046 00047 private: 00048 00049 bool m_bRawMode; 00050 00051 bool m_bDoneReading; 00052 00053 bool m_bDisconnected; 00054 00055 bool m_bIdleHandling; 00056 00057 HttpRequest * m_poCurrentHttpRequest; 00058 00059 EHSServer * m_poEHSServer; 00060 00061 time_t m_nLastActivity; 00062 00063 int m_nRequests; 00064 00065 int m_nResponses; 00066 00067 int m_nActiveRequests; 00068 00070 NetworkAbstraction * m_poNetworkAbstraction; 00071 00073 std::string m_sBuffer; 00074 00076 ResponseQueue m_oResponseQueue; 00077 00079 HttpRequestList m_oHttpRequestList; 00080 00082 std::string m_sRemoteAddress; 00083 00085 std::string m_sLocalAddress; 00086 00088 int m_nRemotePort; 00089 00091 int m_nLocalPort; 00092 00093 size_t m_nMaxRequestSize; 00094 00095 pthread_mutex_t m_oMutex; 00096 00097 public: 00098 00100 std::string GetRemoteAddress() const { return m_sRemoteAddress; } 00101 00103 int GetRemotePort() const { return m_nRemotePort; } 00104 00106 std::string GetLocalAddress() const { return m_sLocalAddress; } 00107 00109 int GetLocalPort() const { return m_nLocalPort; } 00110 00111 DEPRECATED("Use GetRemoteAddress()") 00116 std::string GetAddress() const { return GetRemoteAddress(); } 00117 00118 DEPRECATED("Use GetRemotePort()") 00123 int GetPort() const { return GetRemotePort(); } 00124 00126 bool Disconnected() const { return m_bDisconnected; } 00127 00129 bool IsRaw() const { return m_bRawMode; } 00130 00132 void AddResponse(ehs_autoptr<GenericResponse> ehs_rvref response); 00133 00140 void EnableIdleTimeout(bool enable = true) { m_bIdleHandling = enable; } 00141 00149 void EnableKeepAlive(bool enable = true); 00150 00151 private: 00152 00154 EHSConnection(NetworkAbstraction * ipoNetworkAbstraction, 00155 EHSServer * ipoEHSServer); 00156 00158 ~EHSConnection(); 00159 00161 void UpdateLastActivity() { m_nLastActivity = time(NULL); } 00162 00164 time_t LastActivity() { return m_bIdleHandling ? m_nLastActivity : time(NULL); } 00165 00167 bool StillReading() { return !m_bDoneReading; } 00168 00171 void DoneReading ( bool ibDisconnected ); 00172 00174 HttpRequest *GetNextRequest(); 00175 00177 int CheckDone(); 00178 00180 enum AddBufferResult { 00181 ADDBUFFER_INVALID = 0, 00182 ADDBUFFER_OK, 00183 ADDBUFFER_INVALIDREQUEST, 00184 ADDBUFFER_TOOBIG, 00185 ADDBUFFER_NORESOURCE 00186 }; 00187 00189 AddBufferResult AddBuffer(char * ipsData, int inSize); 00190 00197 void SendResponse(GenericResponse *response); 00198 00200 int RequestsPending() { return (0 != m_nActiveRequests) || !m_oHttpRequestList.empty(); } 00201 00203 NetworkAbstraction * GetNetworkAbstraction(); 00204 00206 void SetMaxRequestSize(size_t n) { m_nMaxRequestSize = n; } 00207 00208 friend class EHSServer; 00209 }; 00210 00211 #endif // _EHSCONNECTION_H_