hunting/utils/FxHttpServer/README.md
2024-06-15 08:36:44 +08:00

62 lines
2.4 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 1. httpserver组件库
&emsp;&emsp; 使用<sdk>/external/httpserver.h-master/src/CMakeLists.txt文件编译的开源库二次封装接口给到应用层使用。
## 1.1. 注意事项
1. 编译libhttpsrv时可能会提示 ragel 工具未安装,需要安装 ragel 工具:
```
$ sudo apt install ragel
```
2. 对开源库的CMakeLists.txt文件增加拷贝命令
```
message("${PLATFORM_PATH}/cmake-shell/external${SUBMODULE_PATH_OF_IPC_SDK}/httpserver.h-master/src/libhttpsrv.a")
add_custom_command(
TARGET httpsrv
POST_BUILD
COMMAND cp ${PLATFORM_PATH}/cmake-shell${SUBMODULE_PATH_OF_IPC_SDK}/external/httpserver.h-master/src/libhttpsrv.a ${EXTERNAL_LIBS_OUTPUT_PATH}
WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/
)
```
3. 取消开源库的CMakeLists.txt文件debug配置未知会产生什么不良后果
```
PUBLIC $<$<CONFIG:DEBUG>:-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all>
```
4. 由于开源代码不支持安全退出,所以修改了开源代码;
```
int gHttpServerRuning = 1; // 增加一个运行标识
int hs_server_run_event_loop(http_server_t *serv, const char *ipaddr) {
hs_server_listen_on_addr(serv, ipaddr);
struct epoll_event ev_list[1];
while (gHttpServerRuning) { // 运行标识赋值为0时httpserver退出
int nev = epoll_wait(serv->loop, ev_list, 1, -1);
for (int i = 0; i < nev; i++) {
ev_cb_t *ev_cb = (ev_cb_t *)ev_list[i].data.ptr;
ev_cb->handler(&ev_list[i]);
}
}
return 0;
}
```
5. 修复一个内存安全漏洞;
```
void _hs_accept_and_begin_request_cycle(http_server_t *server,
hs_io_cb_t on_client_connection_cb,
hs_io_cb_t on_timer_event_cb) {
http_request_t *request = NULL;
while ((request = hs_server_accept_connection(server, on_client_connection_cb,
on_timer_event_cb))) {
if (server->memused > HTTP_MAX_TOTAL_EST_MEM_USAGE) {
hs_request_respond_error(request, 503, "Service Unavailable",
hs_request_begin_write);
} else {
hs_request_begin_read(request);
}
// ================ added by xiao ================ //
if (request) {
hs_request_terminate_connection(request); // 此处应该释放内存
}
// ================ added by xiao end ================ //
}
}
```
6.