/* Copyright Joyent, Inc. and other Node contributors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#include "http_parser.h"
#include <assert.h>
#include <stddef.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
static uint32_t max_header_size = HTTP_MAX_HEADER_SIZE;
#ifndef ULLONG_MAX
# define ULLONG_MAX ((uint64_t) -1) /* 2^64-1 */
#endif
#ifndef MIN
# define MIN(a,b) ((a) < (b) ? (a) : (b))
#endif
#ifndef ARRAY_SIZE
# define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
#endif
#ifndef BIT_AT
# define BIT_AT(a, i) \
(!!((unsigned int) (a)[(unsigned int) (i) >> 3] & \
(1 << ((unsigned int) (i) & 7))))
#endif
#ifndef ELEM_AT
# define ELEM_AT(a, i, v) ((unsigned int) (i) < ARRAY_SIZE(a) ? (a)[(i)] : (v))
#endif
#define SET_ERRNO(e) \
do { \
parser->nread = nread; \
parser->http_errno = (e); \
} while(0)
#define CURRENT_STATE() p_state
#define UPDATE_STATE(V) p_state = (enum state) (V);
#define RETURN(V) \
do { \
parser->nread = nread; \
parser->state = CURRENT_STATE(); \
return (V); \
} while (0);
#define REEXECUTE() \
goto reexecute; \
#ifdef __GNUC__
# define LIKELY(X) __builtin_expect(!!(X), 1)
# define UNLIKELY(X) __builtin_expect(!!(X), 0)
#else
# define LIKELY(X) (X)
# define UNLIKELY(X) (X)
#endif
/* Run the notify callback FOR, returning ER if it fails */
#define CALLBACK_NOTIFY_(FOR, ER) \
do { \
assert(HTTP_PARSER_ERRNO(parser) == HPE_OK); \
\
if (LIKELY(settings->on_##FOR)) { \
parser->state = CURRENT_STATE(); \
if (UNLIKELY(0 != settings->on_##FOR(parser))) { \
SET_ERRNO(HPE_CB_##FOR); \
} \
UPDATE_STATE(parser->state); \
\
/* We either errored above or got paused; get out */ \
if (UNLIKELY(HTTP_PARSER_ERRNO(parser) != HPE_OK)) { \
return (ER); \
} \
} \
} while (0)
/* Run the notify callback FOR and consume the current byte */
#define CALLBACK_NOTIFY(FOR) CALLBACK_NOTIFY_(FOR, p - data + 1)
/* Run the notify callback FOR and don't consume the current byte */
#define CALLBACK_NOTIFY_NOADVANCE(FOR) CALLBACK_NOTIFY_(FOR, p - data)
/* Run data callback FOR with LEN bytes, returning ER if it fails */
#define CALLBACK_DATA_(FOR, LEN, ER) \
do { \
assert(HTTP_PARSER_ERRNO(parser) == HPE_OK); \
\
if (FOR##_mark) { \
if (LIKELY(settings->on_##FOR)) { \
parser->state = CURRENT_STATE(); \
if (UNLIKELY(0 != \
settings->on_##FOR(parser, FOR##_mark, (LEN)))) { \
SET_ERRNO(HPE_CB_##FOR); \
} \
UPDATE_STATE(parser->state); \
\
/* We either errored above or got paused; get out */ \
if (UNLIKELY(HTTP_PARSER_ERRNO(parser) != HPE_OK)) { \
return (ER); \
} \
} \
FOR##_mark = NULL; \
} \
} while (0)
/* Run the data callback FOR and consume the current byte */
#define CALLBACK_DATA(FOR) \
CALLBACK_DATA_(FOR, p - FOR##_mark, p - data + 1)
/* Run the data callback FOR and don't consume the current byte */
#define CALLBACK_DATA_NOADVANCE(FOR) \
CALLBACK_DATA_(FOR, p - FOR##_mark, p - data)
/* Set the mark FOR; non-destructive if mark is already set */
#define MARK(FOR) \
do { \
if (!FOR##_mark) { \
FOR##_mark = p; \
} \
} while (0)
/* Don't allow the total size of the HTTP headers (including the status
* line) to exceed max_header_size. This check is here to protect
* embedders against denial-of-service attacks where the attacker feeds
* us a never-ending header that the embedder keeps buffering.
*
* This check is arguably the responsibility of embedders but we're doing
* it on the embedder's behalf because most won't bother and this way we
* make the web a little safer. max_header_size is still far bigger
* than any reasonable request or response so this should never affect
* day-to-day operation.
*/
#define COUNT_HEADER_SIZE(V) \
do { \
nread += (uint32_t)(V); \
if (UNLIKELY(nread > max_header_size)) { \
SET_ERRNO(HPE_HEADER_OVERFLOW); \
goto error; \
} \
} while (0)
#define PROXY_CONNECTION "proxy-connection"
#define CONNECTION "connection"
#define CONTENT_LENGTH "content-length"
#define TRANSFER_ENCODING "transfer-encoding"
#define UPGRADE "upgrade"
#defi
没有合适的资源?快使用搜索试试~ 我知道了~
基于ASIO的插件式服务器,支持TCP, UDP, 串口.rar
共924个文件
hpp:511个
h:237个
ipp:68个
需积分: 5 1 下载量 42 浏览量
2023-05-31
19:28:07
上传
评论
收藏 2.88MB RAR 举报
温馨提示
有以下几点是需要注意的地方: 1、通过io_service.run()驱动异步事件 2、tcp::v4() = 0.0.0.0,程序本身不要做客户端连接限制,最好由运维在linux系统下进行设置 3、server类下通过自定义start()方法可以控制服务器启动时机 4、newSession表示对客户端socket的构造出了作用域会析构,session的内部调用了shared_from_this()引用计数会加1,所以newsession析构没有关系 5、asio中的socket支持move,move本身资源相当于恢复初始化,还保存了数据结构 6、使用move应该有构造函数的良好行为
资源推荐
资源详情
资源评论
收起资源包目录
基于ASIO的插件式服务器,支持TCP, UDP, 串口.rar (924个子文件)
http_parser.c 74KB
applink.c 3KB
FindGTEST.cmake 304B
ModuleLogic.cpp 32KB
read_logic_json_info.cpp 24KB
TcpSSLClientSession.cpp 11KB
BaseCommand.cpp 10KB
TcpClientSession.cpp 10KB
UdpServer.cpp 10KB
PacketParse_Http.cpp 9KB
LoadModule.cpp 9KB
TtyServer.cpp 9KB
HttpFormat.cpp 8KB
UdpClientSession.cpp 7KB
TcpSSLSession.cpp 7KB
TcpSession.cpp 7KB
ServerService.cpp 7KB
Test_Logic.cpp 7KB
IotoIo.cpp 7KB
PSS_ASIO_CLIENT.cpp 7KB
test_buffpacket.cpp 6KB
SessionService.cpp 6KB
CommunicationService.cpp 6KB
LoadPacketParse.cpp 6KB
PacketParse_Inferface.cpp 5KB
serverconfig.cpp 5KB
UdpSession.cpp 4KB
TcpSession.cpp 4KB
TcpSSLServer.cpp 3KB
template_logic.cpp 3KB
SessionInterface.cpp 3KB
Queueservice.cpp 3KB
TcpServer.cpp 2KB
test_Iotoio.cpp 1KB
test_pss_asio.cpp 1002B
ModuleInterfalce.cpp 897B
PSS_PLUGIN_LOGIC_MAKER.cpp 862B
src.cpp 719B
PSS_ASIO.cpp 495B
template_Command.cpp 246B
ConnectCounter.cpp 100B
libcrypto.dll 2.73MB
libssl.dll 670KB
PSS_ASIO.vcxproj.filters 8KB
PSS_ASIO_CLIENT.vcxproj.filters 2KB
test_pss_asio.vcxproj.filters 2KB
PSS_PLUGIN_LOGIC_MAKER.vcxproj.filters 1KB
PacketParse_Http.vcxproj.filters 1KB
Test_Logic.vcxproj.filters 1KB
PacketParse_Inferface.vcxproj.filters 962B
obj_mac.h 212KB
format.h 130KB
ssl.h 109KB
format-inl.h 107KB
evp.h 75KB
tls1.h 71KB
core.h 70KB
ec.h 62KB
sslerr.h 46KB
x509.h 42KB
pattern_formatter-inl.h 40KB
chrono.h 35KB
bio.h 34KB
engine.h 34KB
asn1.h 33KB
x509v3.h 33KB
asn1t.h 32KB
x509_vfy.h 32KB
compile.h 24KB
color.h 23KB
printf.h 23KB
ts.h 22KB
rsa.h 22KB
bn.h 22KB
http_parser.h 19KB
crypto.h 17KB
cms.h 16KB
ui.h 16KB
ct.h 16KB
ecerr.h 15KB
os-inl.h 15KB
pem.h 15KB
ocsp.h 15KB
ssl3.h 14KB
asn1err.h 14KB
os.h 13KB
dh.h 13KB
ranges.h 12KB
logger.h 12KB
pkcs7.h 11KB
evperr.h 11KB
err.h 11KB
store.h 11KB
cmserr.h 11KB
modes.h 10KB
dsa.h 10KB
pkcs12.h 10KB
spdlog.h 9KB
lhash.h 9KB
rsaerr.h 9KB
共 924 条
- 1
- 2
- 3
- 4
- 5
- 6
- 10
资源评论
野生的狒狒
- 粉丝: 1680
- 资源: 1668
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于python实现的多线程爬虫爬取电影天堂资源
- 基于MFC的教职工信息管理系统c++源码含代码注释.zip
- 毕业设计-基于Vue + Node的外卖系统设计与实现
- python烟花代码示例
- 中国各地级市工业三废数据(2006-2021年).xlsx
- 基于MFC的校园导航程序(使用最短路径dijkstra算法).rar
- Android Studio android APP 视频作为视图背景需要源代码或想了解其实现原理的可以私心我
- com.ZeroneGames.GreenProject.apk
- Python自动化开发入门教程
- 4399GameSem_116_13955_207551_6.apk
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功