From b7b886bd4a74c7ee4746145f80af91232519fca7 Mon Sep 17 00:00:00 2001 From: huangxin Date: Thu, 16 Feb 2023 18:44:01 +0800 Subject: [PATCH] =?UTF-8?q?OCT=201.=20=E5=A2=9E=E5=8A=A0=E5=86=85=E7=BD=AE?= =?UTF-8?q?HTTP=20Service=E9=85=8D=E7=BD=AE=E4=BB=A5=E5=8F=8A=E7=BC=96?= =?UTF-8?q?=E8=AF=91=E5=BC=80=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 13 ++++++++++++- srcs/libs/CMakeLists.txt | 6 +++++- srcs/libs/configure/config.c | 2 ++ srcs/libs/configure/config_help.c | 4 ++-- srcs/libs/include/config.h | 4 ++++ srcs/libs/include/http_svr.h | 3 +++ srcs/libs/init/init_runtime.c | 6 ++++-- srcs/libs/network/http_svr.c | 4 +++- srcs/opendhcp183/opendhcpd.cpp | 2 ++ srcs/opendhcp183/opendhcpd.h | 2 ++ srcs/opendhcp183/query.cpp | 7 +++++-- 11 files changed, 44 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ce8eb09..f6fb6aa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.10 FATAL_ERROR) +INCLUDE(CMakeDependentOption) + LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/depend) IF (BUILD_TESTING) INCLUDE(doctest_framework) @@ -15,6 +17,7 @@ OPTION(USED_OPENDHCPD "DHCP server for vCPE" OFF) OPTION(USED_OPENDHCPDDNS "DHCP And DNS server for vCPE" OFF) OPTION(USED_USER_VNI "Support pass user vni id from console command line" OFF) OPTION(BUILD_TESTING "Enable tests" OFF) +CMAKE_DEPENDENT_OPTION(USED_HTTP_SVR "Build-in http(s) server support" ON "USED_OPENDHCPD OR USED_OPENDHCPDDNS" OFF) # 数据库开关 OPTION(USED_REDIS "Add redis database support for vCPE" OFF) @@ -84,6 +87,11 @@ IF (USED_USER_VNI) MESSAGE("Select Option USED_USER_VNI") ENDIF () +IF (USED_HTTP_SVR) + LIST(APPEND COMMON_DEFINE "-DHTTPSERVER_ON") + MESSAGE("Select Option USED_HTTP_SVR") +ENDIF () + IF (USED_LWIP) LIST(APPEND COMMON_DEFINE "-DLWIP_ON") MESSAGE("Select Option USED_LWIP") @@ -113,9 +121,12 @@ IF (USED_LWIP OR VCPE_AGENT) ADD_SUBDIRECTORY(srcs/lwip) ENDIF () +IF (USED_HTTP_SVR) + ADD_SUBDIRECTORY(srcs/httpserver) +ENDIF () + ADD_SUBDIRECTORY(srcs) ADD_SUBDIRECTORY(srcs/libs) -ADD_SUBDIRECTORY(srcs/httpserver) IF (BUILD_TESTING) ADD_SUBDIRECTORY(unit_test) diff --git a/srcs/libs/CMakeLists.txt b/srcs/libs/CMakeLists.txt index 9cd29fe..ee6c29a 100644 --- a/srcs/libs/CMakeLists.txt +++ b/srcs/libs/CMakeLists.txt @@ -56,7 +56,11 @@ ADD_DEFINITIONS(${COMMON_DEFINE}) ADD_LIBRARY(${LIB_PROJECT_TARGET} ${C_SRC} ${C_HEADS}) -TARGET_LINK_LIBRARIES(${LIB_PROJECT_TARGET} ${COMMON_LIBS} haywire) +TARGET_LINK_LIBRARIES(${LIB_PROJECT_TARGET} ${COMMON_LIBS}) + +IF (USED_HTTP_SVR) + TARGET_LINK_LIBRARIES(${LIB_PROJECT_TARGET} haywire) +ENDIF () IF (USED_OPENDHCPD) TARGET_LINK_LIBRARIES(${LIB_PROJECT_TARGET} opendhcpd) diff --git a/srcs/libs/configure/config.c b/srcs/libs/configure/config.c index 6fc1a6f..d0e3af2 100644 --- a/srcs/libs/configure/config.c +++ b/srcs/libs/configure/config.c @@ -109,9 +109,11 @@ static CFG_ITEM g_cfgItem[] = { DEF_CFG_ITEM(CFG_VXLAN_PEER_MAC, "vxlan_wan.peer_mac", VAL_STR, "", "vxLan peer mac address"), DEF_CFG_ITEM(CFG_VXLAN_PKG_FILTER, "vxlan_wan.pkg_filter", VAL_STR, "", "vxLan package filter"), /*HTTP Server 配置*/ +#ifdef HTTPSERVER_ON DEF_CFG_ITEM(CFG_HTTP_SVR_ADDR, "http_svr.listen_addr", VAL_STR, "0.0.0.0", "Network address to listen on"), DEF_CFG_ITEM(CFG_HTTP_SVR_PORT, "http_svr.listen_port", VAL_INT, "6789", "Network port to listen on"), DEF_CFG_ITEM(CFG_HTTP_SVR_TCP_NODELAY, "http_svr.tcp_nodelay", VAL_BOOL, "1", "TCP delay switch"), +#endif DEF_CFG_ITEM(CFG_PROTO_CRYPTO, "protocol.crypto_type", VAL_INT, "0", "Protocol crypto algorithm"), DEF_CFG_ITEM(CFG_PROTO_CRYPTO_KEY, "protocol.crypto_key", VAL_STR, "", "Protocol crypto keys"), #ifdef OPENDHCPD_ON diff --git a/srcs/libs/configure/config_help.c b/srcs/libs/configure/config_help.c index 812e5ad..689ee22 100644 --- a/srcs/libs/configure/config_help.c +++ b/srcs/libs/configure/config_help.c @@ -58,7 +58,7 @@ const char *config_get_agent_iptv_report_url() { const char *config_get_agent_moniter_report_url() { return cfg_get_string_value(CFG_AGENT_MONITER_URL); } - +#ifdef HTTPSERVER_ON const char *config_get_http_server_addr() { return cfg_get_string_value(CFG_HTTP_SVR_ADDR); } @@ -70,7 +70,7 @@ unsigned int config_get_http_server_port() { int config_get_http_server_tcp_nodelay() { return cfg_get_bool_value(CFG_HTTP_SVR_TCP_NODELAY); } - +#endif #ifdef LWIP_ON const char *config_get_vxlan_nic_name() { return cfg_get_string_value(CFG_VXLAN_NIC_NAME); diff --git a/srcs/libs/include/config.h b/srcs/libs/include/config.h index 7d31ca9..64eac8d 100644 --- a/srcs/libs/include/config.h +++ b/srcs/libs/include/config.h @@ -68,9 +68,11 @@ typedef enum { CFG_VXLAN_PEER_IP, CFG_VXLAN_PEER_MAC, CFG_VXLAN_PKG_FILTER, +#ifdef HTTPSERVER_ON CFG_HTTP_SVR_ADDR, CFG_HTTP_SVR_PORT, CFG_HTTP_SVR_TCP_NODELAY, +#endif CFG_PROTO_CRYPTO, CFG_PROTO_CRYPTO_KEY, #ifdef OPENDHCPD_ON @@ -135,9 +137,11 @@ const char *config_get_vxlan_pkg_filter(); #endif const char *config_get_agent_iptv_report_url(); const char *config_get_agent_moniter_report_url(); +#ifdef HTTPSERVER_ON const char *config_get_http_server_addr(); unsigned int config_get_http_server_port(); int config_get_http_server_tcp_nodelay(); +#endif unsigned int config_get_proto_crypto_type(); const char *config_get_proto_crypto_key(); #ifdef USER_VNI diff --git a/srcs/libs/include/http_svr.h b/srcs/libs/include/http_svr.h index e0fbbf7..52a6044 100644 --- a/srcs/libs/include/http_svr.h +++ b/srcs/libs/include/http_svr.h @@ -7,8 +7,11 @@ #ifdef __cplusplus extern "C" { #endif +#ifdef HTTPSERVER_ON + int http_svr_init(); +#endif #ifdef __cplusplus } #endif diff --git a/srcs/libs/init/init_runtime.c b/srcs/libs/init/init_runtime.c index f2421f0..fc32229 100644 --- a/srcs/libs/init/init_runtime.c +++ b/srcs/libs/init/init_runtime.c @@ -129,9 +129,9 @@ int user_init(const char *pAppCfgFile, const char *pCfgDirectory, const char *pK if ((ret = mq_data_init()) != ERR_SUCCESS) { LOG_MOD(error, ZLOG_MOD_INIT, "Message queue init error: %d\n", ret); } - +#ifdef HTTPSERVER_ON http_svr_init(); - +#endif g_isInited = TRUE; return ERR_SUCCESS; @@ -140,7 +140,9 @@ int user_init(const char *pAppCfgFile, const char *pCfgDirectory, const char *pK void user_uninit() { if (g_isInited) { task_manager_exit(); +#ifdef HTTPSERVER_ON free_http_server(); +#endif mq_uninit(); zlog_fini(); uninit_config_system(); diff --git a/srcs/libs/network/http_svr.c b/srcs/libs/network/http_svr.c index 531e032..855e45d 100644 --- a/srcs/libs/network/http_svr.c +++ b/srcs/libs/network/http_svr.c @@ -6,6 +6,7 @@ #include "haywire.h" #include "config.h" +#ifdef HTTPSERVER_ON int http_svr_init() { configuration config; config.http_listen_address = (char *)config_get_http_server_addr(); @@ -20,4 +21,5 @@ int http_svr_init() { hw_http_open(); return ERR_SUCCESS; -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/srcs/opendhcp183/opendhcpd.cpp b/srcs/opendhcp183/opendhcpd.cpp index b534a83..e203178 100644 --- a/srcs/opendhcp183/opendhcpd.cpp +++ b/srcs/opendhcp183/opendhcpd.cpp @@ -4864,7 +4864,9 @@ void *init(void *lparam) { #if 1 network.httpConn.ready = false; +#ifdef HTTPSERVER_ON opendhcp_init_http_server(); +#endif #else newNetwork.httpConn.port = 6789; newNetwork.httpConn.server = newNetwork.dhcpConn[0].server; diff --git a/srcs/opendhcp183/opendhcpd.h b/srcs/opendhcp183/opendhcpd.h index 7b33094..2cbe9f3 100644 --- a/srcs/opendhcp183/opendhcpd.h +++ b/srcs/opendhcp183/opendhcpd.h @@ -765,7 +765,9 @@ MYWORD myTokenize(char *, char *, const char *, bool); MYDWORD fIP(void *raw); MYDWORD fUInt(void *raw); void prepareUserHtmlRespStatus(data19 *req); +#ifdef HTTPSERVER_ON void opendhcp_init_http_server(); +#endif void opendhcp_set_replication_svr(); void opendhcp_add_ip_pool_set(); void opendhcp_add_mac_filter(); diff --git a/srcs/opendhcp183/query.cpp b/srcs/opendhcp183/query.cpp index bbc5b57..a95e53e 100644 --- a/srcs/opendhcp183/query.cpp +++ b/srcs/opendhcp183/query.cpp @@ -477,7 +477,7 @@ typedef struct { unsigned int key; unsigned int value; UT_hash_handle hh; -}HASH_MAP, *PHASH_MAP; +} HASH_MAP, *PHASH_MAP; static int delete_dhcpd_rangeset(data19 *req, const char *pRequest) { char logBuff[512]; @@ -825,6 +825,7 @@ static void response_complete(void *user_data) { } } +#ifdef HTTPSERVER_ON static void proto_response_error(hw_http_response *response, int httpCode, const char *httpCodeStr, int errCode) { cJSON *pRspMsg = cJSON_CreateObject(); @@ -1175,6 +1176,7 @@ static void opendhcp_http_query_rangeset(http_request *request, hw_http_response hw_http_response_send(response, req, response_complete); } +#endif unsigned int opendhcp_set_lease_time() { return config_get_dhcp_server_lease_time(); @@ -1276,6 +1278,7 @@ void iptvCacheCb(void *UNUSED(pArg)) { /** * 增加 DHCP Server HTTP服务接口 */ +#ifdef HTTPSERVER_ON void opendhcp_init_http_server() { static int added = FALSE; static uv_thread_t uvThread; @@ -1298,7 +1301,7 @@ void opendhcp_init_http_server() { #endif } } - +#endif /** * 增加 DHCP 主、从服务器配置 */