-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathHttpStack.h
More file actions
130 lines (110 loc) · 3.61 KB
/
Copy pathHttpStack.h
File metadata and controls
130 lines (110 loc) · 3.61 KB
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
/*
* Copyright (C) 2012 Yee Young Han <websearch@naver.com> (http://blog.naver.com/websearch)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _HTTP_STACK_H_
#define _HTTP_STACK_H_
#include "TcpStack.h"
#include "HttpPacket.h"
#include "Http2Packet.h"
#include "Http2Conversion.h"
#include "WebSocketPacket.h"
#include "HttpStackCallBack.h"
/**
* @ingroup HttpStack
* @brief HTTP 세션 타입
*/
enum EHttpSessionType
{
E_HST_NULL = 0,
E_HST_WEB_SOCKET,
E_HST_HTTP_2
};
/**
* @defgroup HttpStack HttpStack
* HTTP 통신 라이브러리
*/
class CHttpMessageSendRecv
{
public:
CHttpMessage m_clsSend;
CHttpMessage m_clsRecv;
};
// key = HTTP/2 frame id
typedef std::map< int, CHttpMessageSendRecv > HTTP_MESSAGE_MAP;
/**
* @ingroup HttpStack
* @brief HTTP 서버의 각 세션 정보를 저장하는 클래스
*/
class CHttpStackSession : public ITcpSessionApp
{
public:
CHttpStackSession() : m_eType(E_HST_NULL){};
virtual ~CHttpStackSession(){};
CHttpMessageSendRecv * GetMessage( int iId )
{
HTTP_MESSAGE_MAP::iterator itMap = m_clsMessageMap.find( iId );
if( itMap == m_clsMessageMap.end() )
{
CHttpMessageSendRecv clsData;
m_clsMessageMap.insert( HTTP_MESSAGE_MAP::value_type( iId, clsData ) );
itMap = m_clsMessageMap.find( iId );
if( itMap == m_clsMessageMap.end() )
{
return NULL;
}
}
return &itMap->second;
}
CHttpPacket m_clsHttpPacket;
CHttp2Packet m_clsHttp2Packet;
CHttp2Conversion m_clsSendConversion;
CHttp2Conversion m_clsRecvConversion;
CHttp2FrameList m_clsFrameList;
CWebSocketPacket m_clsWsPacket;
EHttpSessionType m_eType;
HTTP_MESSAGE_MAP m_clsMessageMap;
};
/**
* @ingroup HttpStack
* @brief HTTP 서버 클래스
*/
class CHttpStack : public ITcpStackCallBack
{
public:
CHttpStack();
virtual ~CHttpStack();
bool Start( CTcpStackSetup * pclsSetup, IHttpStackCallBack * pclsCallBack );
bool Stop( );
static void Release();
// HttpStackWebSocket.hpp
bool SendWebSocketPacket( const char * pszClientIp, int iClientPort, const char * pszData, int iDataLen );
// ITcpStackCallBack
virtual bool InComingConnected( CTcpSessionInfo * pclsSessionInfo );
virtual void SessionClosed( CTcpSessionInfo * pclsSessionInfo );
virtual bool RecvPacket( char * pszPacket, int iPacketLen, CTcpSessionInfo * pclsSessionInfo );
private:
// HttpStackHttp2.hpp
bool RecvPacketHttp2Pri( CTcpSessionInfo * pclsSessionInfo, CHttpStackSession * pclsApp );
bool RecvPacketHttp2( char * pszPacket, int iPacketLen, CTcpSessionInfo * pclsSessionInfo, CHttpStackSession * pclsApp );
// HttpStackWebSocket.hpp
bool RecvPacketWebSocket( char * pszPacket, int iPacketLen, CTcpSessionInfo * pclsSessionInfo, CHttpStackSession * pclsApp );
bool MakeWebSocketResponse( CHttpMessage * pclsRecv, CHttpMessage * pclsSend );
CTcpStack m_clsTcpStack;
IHttpStackCallBack * m_pclsCallBack;
static const EVP_MD * m_psttMd;
};
#endif