-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathHttpStackHttp2.hpp
More file actions
137 lines (115 loc) · 5.06 KB
/
Copy pathHttpStackHttp2.hpp
File metadata and controls
137 lines (115 loc) · 5.06 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
131
132
133
134
135
136
137
/*
* 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
*/
bool CHttpStack::RecvPacketHttp2Pri( CTcpSessionInfo * pclsSessionInfo, CHttpStackSession * pclsApp )
{
pclsApp->m_eType = E_HST_HTTP_2;
pclsApp->m_clsHttp2Packet.AddPacket( &pclsApp->m_clsHttpPacket );
CHttp2Settings clsSettings;
CHttp2Frame clsFrame;
clsSettings.Add( HTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, 10 );
clsFrame.Set( HTTP2_FRAME_TYPE_SETTINGS, 0, 0, clsSettings.m_pszPacket, clsSettings.m_iPacketLen );
if( pclsSessionInfo->Send( (char *)clsFrame.m_pszPacket, clsFrame.m_iPacketLen ) == false )
{
CLog::Print( LOG_ERROR, "Send(%s:%d) error", pclsSessionInfo->m_strIp.c_str(), pclsSessionInfo->m_iPort );
return false;
}
clsFrame.PrintLog( LOG_HTTP2, pclsSessionInfo->m_strIp.c_str(), pclsSessionInfo->m_iPort, true );
return RecvPacketHttp2( NULL, 0, pclsSessionInfo, pclsApp );
}
bool CHttpStack::RecvPacketHttp2( char * pszPacket, int iPacketLen, CTcpSessionInfo * pclsSessionInfo, CHttpStackSession * pclsApp )
{
pclsApp->m_clsHttp2Packet.AddPacket( (uint8_t *)pszPacket, iPacketLen );
CHttp2Frame clsFrame;
CHttpMessageSendRecv * pclsData;
while( pclsApp->m_clsHttp2Packet.GetFrame( &clsFrame ) )
{
clsFrame.PrintLog( LOG_HTTP2, pclsSessionInfo->m_strIp.c_str(), pclsSessionInfo->m_iPort, false );
pclsData = pclsApp->GetMessage( clsFrame.GetStreamIdentifier() );
switch( clsFrame.GetType() )
{
case HTTP2_FRAME_TYPE_HEADERS:
case HTTP2_FRAME_TYPE_DATA:
pclsApp->m_clsRecvConversion.MakeMessage( clsFrame, pclsData->m_clsRecv );
if( clsFrame.GetFlags() & HTTP2_FLAG_END_STREAM )
{
if( m_clsTcpStack.m_clsSetup.m_bUseHttp2HeaderLog )
{
std::string strLog;
pclsData->m_clsRecv.ToString( strLog, true );
CLog::Print( LOG_HTTP2, "Recv(%s:%d) [%s]", pclsSessionInfo->m_strIp.c_str(), pclsSessionInfo->m_iPort, strLog.c_str() );
}
if( m_pclsCallBack->RecvHttpRequest( &pclsData->m_clsRecv, &pclsData->m_clsSend ) == false )
{
CLog::Print( LOG_ERROR, "%s RecvHttpRequest error", __FUNCTION__ );
return false;
}
if( m_clsTcpStack.m_clsSetup.m_bUseHttp2HeaderLog )
{
std::string strLog;
pclsData->m_clsSend.ToString( strLog, true );
CLog::Print( LOG_HTTP2, "Send(%s:%d) [%s]", pclsSessionInfo->m_strIp.c_str(), pclsSessionInfo->m_iPort, strLog.c_str() );
}
pclsData->m_clsSend.m_iStreamIdentifier = clsFrame.GetStreamIdentifier();
if( pclsApp->m_clsSendConversion.MakeFrameList( pclsData->m_clsSend, pclsApp->m_clsFrameList ) == false )
{
CLog::Print( LOG_ERROR, "%s MakeFrameList error", __FUNCTION__ );
return false;
}
HTTP2_FRAME_LIST::iterator itFL;
for( itFL = pclsApp->m_clsFrameList.m_clsList.begin(); itFL != pclsApp->m_clsFrameList.m_clsList.end(); ++itFL )
{
if( pclsSessionInfo->Send( (char *)((*itFL)->m_pszPacket), (*itFL)->m_iPacketLen ) == false )
{
CLog::Print( LOG_ERROR, "Send(%s:%d) error", pclsSessionInfo->m_strIp.c_str(), pclsSessionInfo->m_iPort );
return false;
}
(*itFL)->PrintLog( LOG_HTTP2, pclsSessionInfo->m_strIp.c_str(), pclsSessionInfo->m_iPort, true );
}
}
break;
case HTTP2_FRAME_TYPE_SETTINGS:
if( clsFrame.GetFlags() == 0 )
{
clsFrame.Set( HTTP2_FRAME_TYPE_SETTINGS, HTTP2_FLAG_ACK, 0, NULL, 0 );
if( pclsSessionInfo->Send( (char *)clsFrame.m_pszPacket, clsFrame.m_iPacketLen ) == false )
{
CLog::Print( LOG_ERROR, "%s Send(%s:%d) error", __FUNCTION__, pclsSessionInfo->m_strIp.c_str(), pclsSessionInfo->m_iPort );
return false;
}
clsFrame.PrintLog( LOG_HTTP2, pclsSessionInfo->m_strIp.c_str(), pclsSessionInfo->m_iPort, true );
}
break;
case HTTP2_FRAME_TYPE_RST_STREAM:
case HTTP2_FRAME_TYPE_GOAWAY:
break;
case HTTP2_FRAME_TYPE_PING:
if( clsFrame.GetFlags() == 0 )
{
clsFrame.SetFlags( HTTP2_FLAG_ACK );
if( pclsSessionInfo->Send( (char *)clsFrame.m_pszPacket, clsFrame.m_iPacketLen ) == false )
{
CLog::Print( LOG_ERROR, "%s Send(%s:%d) error", __FUNCTION__, pclsSessionInfo->m_strIp.c_str(), pclsSessionInfo->m_iPort );
return false;
}
clsFrame.PrintLog( LOG_HTTP2, pclsSessionInfo->m_strIp.c_str(), pclsSessionInfo->m_iPort, true );
}
break;
}
}
return true;
}