Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
master
Branches (2)
Tags (46)
master
dev
v5.7.1
v5.6.4
v5.6.3
v5.6.2
v5.6.1
v5.5.3
v5.5.2
v5.5.1
v5.4.4
v5.4.3
v5.4.2
v5.4.1
v5.3.2
v5.3.1
v5.2.1
v1.0.0-for-linux
v5.1.1-for-windows
v5.0.2
v5.0.1
v4.3.1
master
Branches (2)
Tags (46)
master
dev
v5.7.1
v5.6.4
v5.6.3
v5.6.2
v5.6.1
v5.5.3
v5.5.2
v5.5.1
v5.4.4
v5.4.3
v5.4.2
v5.4.1
v5.3.2
v5.3.1
v5.2.1
v1.0.0-for-linux
v5.1.1-for-windows
v5.0.2
v5.0.1
v4.3.1
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
master
Branches (2)
Tags (46)
master
dev
v5.7.1
v5.6.4
v5.6.3
v5.6.2
v5.6.1
v5.5.3
v5.5.2
v5.5.1
v5.4.4
v5.4.3
v5.4.2
v5.4.1
v5.3.2
v5.3.1
v5.2.1
v1.0.0-for-linux
v5.1.1-for-windows
v5.0.2
v5.0.1
v4.3.1
HP-Socket
/
Linux
/
src
/
HttpAgent.cpp
HP-Socket
/
Linux
/
src
/
HttpAgent.cpp
HttpAgent.cpp 12.41 KB
Copy Edit Raw Blame History
伤神小怪兽 authored 2019年12月18日 21:58 +08:00 . 20191218
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 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461
/*
* Copyright: JessMA Open Source (ldcsaa@gmail.com)
*
* Author : Bruce Liang
* Website : https://github.com/ldcsaa
* Project : https://github.com/ldcsaa/HP-Socket
* Blog : http://www.cnblogs.com/ldcsaa
* Wiki : http://www.oschina.net/p/hp-socket
* QQ Group : 44636872, 75375912
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "HttpAgent.h"
#ifdef _HTTP_SUPPORT
template<class T, USHORT default_port> BOOL CHttpAgentT<T, default_port>::CheckParams()
{
if(m_enLocalVersion != HV_1_1 && m_enLocalVersion != HV_1_0)
{
SetLastError(SE_INVALID_PARAM, __FUNCTION__, ERROR_INVALID_PARAMETER);
return FALSE;
}
return __super::CheckParams();
}
template<class T, USHORT default_port> void CHttpAgentT<T, default_port>::PrepareStart()
{
__super::PrepareStart();
m_objPool.SetHttpObjLockTime(GetFreeSocketObjLockTime());
m_objPool.SetHttpObjPoolSize(GetFreeSocketObjPool());
m_objPool.SetHttpObjPoolHold(GetFreeSocketObjHold());
m_objPool.Prepare();
}
template<class T, USHORT default_port> BOOL CHttpAgentT<T, default_port>::SendRequest(CONNID dwConnID, LPCSTR lpszMethod, LPCSTR lpszPath, const THeader lpHeaders[], int iHeaderCount, const BYTE* pBody, int iLength)
{
THttpObj* pHttpObj = FindHttpObj(dwConnID);
if(pHttpObj == nullptr)
{
::SetLastError(ERROR_OBJECT_NOT_FOUND);
return FALSE;
}
WSABUF szBuffer[2];
CStringA strHeader;
LPCSTR lpszHost = nullptr;
USHORT usPort = 0;
BOOL bConnect = (stricmp(lpszMethod, HTTP_METHOD_CONNECT) == 0);
if(!bConnect)
{
GetRemoteHost(dwConnID, &lpszHost, &usPort);
if(usPort == default_port) usPort = 0;
}
CStringA strPath;
::AdjustRequestPath(bConnect, lpszPath, strPath);
pHttpObj->SetRequestPath(lpszMethod, strPath);
pHttpObj->ReloadCookies();
::MakeRequestLine(lpszMethod, strPath, m_enLocalVersion, strHeader);
::MakeHeaderLines(lpHeaders, iHeaderCount, &pHttpObj->GetCookieMap(), iLength, TRUE, -1, lpszHost, usPort, strHeader);
::MakeHttpPacket(strHeader, pBody, iLength, szBuffer);
return SendPackets(dwConnID, szBuffer, 2);
}
template<class T, USHORT default_port> BOOL CHttpAgentT<T, default_port>::SendLocalFile(CONNID dwConnID, LPCSTR lpszFileName, LPCSTR lpszMethod, LPCSTR lpszPath, const THeader lpHeaders[], int iHeaderCount)
{
CFile file;
CFileMapping fmap;
HRESULT hr = ::ReadSmallFile(CA2T(lpszFileName), file, fmap);
if(FAILED(hr))
{
::SetLastError(hr);
return FALSE;
}
return SendRequest(dwConnID, lpszMethod, lpszPath, lpHeaders, iHeaderCount, (BYTE*)fmap, (int)fmap.Size());
}
template<class T, USHORT default_port> BOOL CHttpAgentT<T, default_port>::SendChunkData(CONNID dwConnID, const BYTE* pData, int iLength, LPCSTR lpszExtensions)
{
char szLen[12];
WSABUF bufs[5];
int iCount = MakeChunkPackage(pData, iLength, lpszExtensions, szLen, bufs);
return SendPackets(dwConnID, bufs, iCount);
}
template<class T, USHORT default_port> BOOL CHttpAgentT<T, default_port>::SendWSMessage(CONNID dwConnID, BOOL bFinal, BYTE iReserved, BYTE iOperationCode, const BYTE lpszMask[4], const BYTE* pData, int iLength, ULONGLONG ullBodyLen)
{
ASSERT(lpszMask);
WSABUF szBuffer[2];
BYTE szHeader[HTTP_MAX_WS_HEADER_LEN];
unique_ptr<BYTE[]> szData = make_unique<BYTE[]>(iLength);
memcpy(szData.get(), pData, iLength);
if(!::MakeWSPacket(bFinal, iReserved, iOperationCode, lpszMask, szData.get(), iLength, ullBodyLen, szHeader, szBuffer))
return FALSE;
return SendPackets(dwConnID, szBuffer, 2);
}
template<class T, USHORT default_port> EnHandleResult CHttpAgentT<T, default_port>::FireConnect(TAgentSocketObj* pSocketObj)
{
return m_bHttpAutoStart ? __super::FireConnect(pSocketObj) : __super::DoFireConnect(pSocketObj);
}
template<class T, USHORT default_port> EnHandleResult CHttpAgentT<T, default_port>::DoFireConnect(TAgentSocketObj* pSocketObj)
{
EnHandleResult result = __super::DoFireConnect(pSocketObj);
if(result != HR_ERROR)
DoStartHttp(pSocketObj);
return result;
}
template<class T, USHORT default_port> EnHandleResult CHttpAgentT<T, default_port>::DoFireHandShake(TAgentSocketObj* pSocketObj)
{
EnHandleResult result = __super::DoFireHandShake(pSocketObj);
if(result == HR_ERROR)
{
THttpObj* pHttpObj = FindHttpObj(pSocketObj);
VERIFY(pHttpObj);
m_objPool.PutFreeHttpObj(pHttpObj);
SetConnectionReserved(pSocketObj, nullptr);
}
return result;
}
template<class T, USHORT default_port> EnHandleResult CHttpAgentT<T, default_port>::DoFireReceive(TAgentSocketObj* pSocketObj, const BYTE* pData, int iLength)
{
THttpObj* pHttpObj = FindHttpObj(pSocketObj);
if(pHttpObj != nullptr)
return pHttpObj->Execute(pData, iLength);
else
return DoFireSuperReceive(pSocketObj, pData, iLength);
}
template<class T, USHORT default_port> EnHandleResult CHttpAgentT<T, default_port>::DoFireClose(TAgentSocketObj* pSocketObj, EnSocketOperation enOperation, int iErrorCode)
{
THttpObj* pHttpObj = FindHttpObj(pSocketObj);
if(pHttpObj != nullptr)
pHttpObj->CheckBodyIdentityEof();
EnHandleResult result = __super::DoFireClose(pSocketObj, enOperation, iErrorCode);
if(pHttpObj != nullptr)
m_objPool.PutFreeHttpObj(pHttpObj);
return result;
}
template<class T, USHORT default_port> EnHandleResult CHttpAgentT<T, default_port>::DoFireShutdown()
{
EnHandleResult result = __super::DoFireShutdown();
m_objPool.Clear();
return result;
}
template<class T, USHORT default_port> BOOL CHttpAgentT<T, default_port>::IsUpgrade(CONNID dwConnID)
{
THttpObj* pHttpObj = FindHttpObj(dwConnID);
if(pHttpObj == nullptr)
return FALSE;
return pHttpObj->IsUpgrade();
}
template<class T, USHORT default_port> BOOL CHttpAgentT<T, default_port>::IsKeepAlive(CONNID dwConnID)
{
THttpObj* pHttpObj = FindHttpObj(dwConnID);
if(pHttpObj == nullptr)
return FALSE;
return pHttpObj->IsKeepAlive();
}
template<class T, USHORT default_port> USHORT CHttpAgentT<T, default_port>::GetVersion(CONNID dwConnID)
{
THttpObj* pHttpObj = FindHttpObj(dwConnID);
if(pHttpObj == nullptr)
return 0;
return pHttpObj->GetVersion();
}
template<class T, USHORT default_port> ULONGLONG CHttpAgentT<T, default_port>::GetContentLength(CONNID dwConnID)
{
THttpObj* pHttpObj = FindHttpObj(dwConnID);
if(pHttpObj == nullptr)
return 0;
return pHttpObj->GetContentLength();
}
template<class T, USHORT default_port> LPCSTR CHttpAgentT<T, default_port>::GetContentType(CONNID dwConnID)
{
THttpObj* pHttpObj = FindHttpObj(dwConnID);
if(pHttpObj == nullptr)
return nullptr;
return pHttpObj->GetContentType();
}
template<class T, USHORT default_port> LPCSTR CHttpAgentT<T, default_port>::GetContentEncoding(CONNID dwConnID)
{
THttpObj* pHttpObj = FindHttpObj(dwConnID);
if(pHttpObj == nullptr)
return nullptr;
return pHttpObj->GetContentEncoding();
}
template<class T, USHORT default_port> LPCSTR CHttpAgentT<T, default_port>::GetTransferEncoding(CONNID dwConnID)
{
THttpObj* pHttpObj = FindHttpObj(dwConnID);
if(pHttpObj == nullptr)
return nullptr;
return pHttpObj->GetTransferEncoding();
}
template<class T, USHORT default_port> EnHttpUpgradeType CHttpAgentT<T, default_port>::GetUpgradeType(CONNID dwConnID)
{
THttpObj* pHttpObj = FindHttpObj(dwConnID);
if(pHttpObj == nullptr)
return HUT_NONE;
return pHttpObj->GetUpgradeType();
}
template<class T, USHORT default_port> USHORT CHttpAgentT<T, default_port>::GetParseErrorCode(CONNID dwConnID, LPCSTR* lpszErrorDesc)
{
THttpObj* pHttpObj = FindHttpObj(dwConnID);
if(pHttpObj == nullptr)
return 0;
return pHttpObj->GetParseErrorCode(lpszErrorDesc);
}
template<class T, USHORT default_port> BOOL CHttpAgentT<T, default_port>::GetHeader(CONNID dwConnID, LPCSTR lpszName, LPCSTR* lpszValue)
{
THttpObj* pHttpObj = FindHttpObj(dwConnID);
if(pHttpObj == nullptr)
return FALSE;
return pHttpObj->GetHeader(lpszName, lpszValue);
}
template<class T, USHORT default_port> BOOL CHttpAgentT<T, default_port>::GetHeaders(CONNID dwConnID, LPCSTR lpszName, LPCSTR lpszValue[], DWORD& dwCount)
{
THttpObj* pHttpObj = FindHttpObj(dwConnID);
if(pHttpObj == nullptr)
return FALSE;
return pHttpObj->GetHeaders(lpszName, lpszValue, dwCount);
}
template<class T, USHORT default_port> BOOL CHttpAgentT<T, default_port>::GetAllHeaders(CONNID dwConnID, THeader lpHeaders[], DWORD& dwCount)
{
THttpObj* pHttpObj = FindHttpObj(dwConnID);
if(pHttpObj == nullptr)
return FALSE;
return pHttpObj->GetAllHeaders(lpHeaders, dwCount);
}
template<class T, USHORT default_port> BOOL CHttpAgentT<T, default_port>::GetAllHeaderNames(CONNID dwConnID, LPCSTR lpszName[], DWORD& dwCount)
{
THttpObj* pHttpObj = FindHttpObj(dwConnID);
if(pHttpObj == nullptr)
return FALSE;
return pHttpObj->GetAllHeaderNames(lpszName, dwCount);
}
template<class T, USHORT default_port> BOOL CHttpAgentT<T, default_port>::GetCookie(CONNID dwConnID, LPCSTR lpszName, LPCSTR* lpszValue)
{
THttpObj* pHttpObj = FindHttpObj(dwConnID);
if(pHttpObj == nullptr)
return FALSE;
return pHttpObj->GetCookie(lpszName, lpszValue);
}
template<class T, USHORT default_port> BOOL CHttpAgentT<T, default_port>::GetAllCookies(CONNID dwConnID, TCookie lpCookies[], DWORD& dwCount)
{
THttpObj* pHttpObj = FindHttpObj(dwConnID);
if(pHttpObj == nullptr)
return FALSE;
return pHttpObj->GetAllCookies(lpCookies, dwCount);
}
template<class T, USHORT default_port> USHORT CHttpAgentT<T, default_port>::GetStatusCode(CONNID dwConnID)
{
THttpObj* pHttpObj = FindHttpObj(dwConnID);
if(pHttpObj == nullptr)
return 0;
return pHttpObj->GetStatusCode();
}
template<class T, USHORT default_port> BOOL CHttpAgentT<T, default_port>::GetWSMessageState(CONNID dwConnID, BOOL* lpbFinal, BYTE* lpiReserved, BYTE* lpiOperationCode, LPCBYTE* lpszMask, ULONGLONG* lpullBodyLen, ULONGLONG* lpullBodyRemain)
{
THttpObj* pHttpObj = FindHttpObj(dwConnID);
if(pHttpObj == nullptr)
return FALSE;
return pHttpObj->GetWSMessageState(lpbFinal, lpiReserved, lpiOperationCode, lpszMask, lpullBodyLen, lpullBodyRemain);
}
template<class T, USHORT default_port> inline typename CHttpAgentT<T, default_port>::THttpObj* CHttpAgentT<T, default_port>::FindHttpObj(CONNID dwConnID)
{
THttpObj* pHttpObj = nullptr;
GetConnectionReserved(dwConnID, (PVOID*)&pHttpObj);
return pHttpObj;
}
template<class T, USHORT default_port> inline typename CHttpAgentT<T, default_port>::THttpObj* CHttpAgentT<T, default_port>::FindHttpObj(TAgentSocketObj* pSocketObj)
{
THttpObj* pHttpObj = nullptr;
GetConnectionReserved(pSocketObj, (PVOID*)&pHttpObj);
return pHttpObj;
}
template<class T, USHORT default_port> BOOL CHttpAgentT<T, default_port>::StartHttp(CONNID dwConnID)
{
if(IsHttpAutoStart())
{
::SetLastError(ERROR_INVALID_OPERATION);
return FALSE;
}
TAgentSocketObj* pSocketObj = FindSocketObj(dwConnID);
if(!TAgentSocketObj::IsValid(pSocketObj))
{
::SetLastError(ERROR_OBJECT_NOT_FOUND);
return FALSE;
}
return StartHttp(pSocketObj);
}
template<class T, USHORT default_port> BOOL CHttpAgentT<T, default_port>::StartHttp(TAgentSocketObj* pSocketObj)
{
if(!pSocketObj->HasConnected())
{
::SetLastError(ERROR_INVALID_STATE);
return FALSE;
}
CReentrantCriSecLock locallock(pSocketObj->csSend);
if(!TAgentSocketObj::IsValid(pSocketObj))
{
::SetLastError(ERROR_OBJECT_NOT_FOUND);
return FALSE;
}
if(!pSocketObj->HasConnected())
{
::SetLastError(ERROR_INVALID_STATE);
return FALSE;
}
THttpObj* pHttpObj = FindHttpObj(pSocketObj);
if(pHttpObj != nullptr)
{
::SetLastError(ERROR_ALREADY_INITIALIZED);
return FALSE;
}
DoStartHttp(pSocketObj);
if(!IsSecure())
FireHandShake(pSocketObj);
else
{
#ifdef _SSL_SUPPORT
if(IsSSLAutoHandShake())
StartSSLHandShake(pSocketObj);
#endif
}
return TRUE;
}
template<class T, USHORT default_port> void CHttpAgentT<T, default_port>::DoStartHttp(TAgentSocketObj* pSocketObj)
{
THttpObj* pHttpObj = m_objPool.PickFreeHttpObj(this, pSocketObj);
VERIFY(SetConnectionReserved(pSocketObj, pHttpObj));
}
// ------------------------------------------------------------------------------------------------------------- //
template class CHttpAgentT<CTcpAgent, HTTP_DEFAULT_PORT>;
#ifdef _SSL_SUPPORT
#include "SSLAgent.h"
template class CHttpAgentT<CSSLAgent, HTTPS_DEFAULT_PORT>;
#endif
#endif
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

About

HP-Socket 是一套通用的高性能 TCP/UDP/HTTP 通信框架,包含服务端组件、客户端组件和Agent组件,广泛适用于各种不同应用场景的 TCP/UDP/HTTP 通信系统,提供 C/C++、C#、Delphi、E(易语言)、Java、Python 等编程语言接口
Cancel

Releases

No release

Contributors

All

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/AbstractFactory/HP-Socket.git
git@gitee.com:AbstractFactory/HP-Socket.git
AbstractFactory
HP-Socket
HP-Socket
master
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

AltStyle によって変換されたページ (->オリジナル) /