OCT 1. 增加内置HTTP Service配置以及编译开关

This commit is contained in:
huangxin 2023-02-16 18:44:01 +08:00
parent 14daf5f945
commit b7b886bd4a
11 changed files with 44 additions and 9 deletions

View File

@ -1,5 +1,7 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.10 FATAL_ERROR) CMAKE_MINIMUM_REQUIRED(VERSION 3.10 FATAL_ERROR)
INCLUDE(CMakeDependentOption)
LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/depend) LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/depend)
IF (BUILD_TESTING) IF (BUILD_TESTING)
INCLUDE(doctest_framework) 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_OPENDHCPDDNS "DHCP And DNS server for vCPE" OFF)
OPTION(USED_USER_VNI "Support pass user vni id from console command line" OFF) OPTION(USED_USER_VNI "Support pass user vni id from console command line" OFF)
OPTION(BUILD_TESTING "Enable tests" 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) OPTION(USED_REDIS "Add redis database support for vCPE" OFF)
@ -84,6 +87,11 @@ IF (USED_USER_VNI)
MESSAGE("Select Option USED_USER_VNI") MESSAGE("Select Option USED_USER_VNI")
ENDIF () ENDIF ()
IF (USED_HTTP_SVR)
LIST(APPEND COMMON_DEFINE "-DHTTPSERVER_ON")
MESSAGE("Select Option USED_HTTP_SVR")
ENDIF ()
IF (USED_LWIP) IF (USED_LWIP)
LIST(APPEND COMMON_DEFINE "-DLWIP_ON") LIST(APPEND COMMON_DEFINE "-DLWIP_ON")
MESSAGE("Select Option USED_LWIP") MESSAGE("Select Option USED_LWIP")
@ -113,9 +121,12 @@ IF (USED_LWIP OR VCPE_AGENT)
ADD_SUBDIRECTORY(srcs/lwip) ADD_SUBDIRECTORY(srcs/lwip)
ENDIF () ENDIF ()
IF (USED_HTTP_SVR)
ADD_SUBDIRECTORY(srcs/httpserver)
ENDIF ()
ADD_SUBDIRECTORY(srcs) ADD_SUBDIRECTORY(srcs)
ADD_SUBDIRECTORY(srcs/libs) ADD_SUBDIRECTORY(srcs/libs)
ADD_SUBDIRECTORY(srcs/httpserver)
IF (BUILD_TESTING) IF (BUILD_TESTING)
ADD_SUBDIRECTORY(unit_test) ADD_SUBDIRECTORY(unit_test)

View File

@ -56,7 +56,11 @@ ADD_DEFINITIONS(${COMMON_DEFINE})
ADD_LIBRARY(${LIB_PROJECT_TARGET} ${C_SRC} ${C_HEADS}) 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) IF (USED_OPENDHCPD)
TARGET_LINK_LIBRARIES(${LIB_PROJECT_TARGET} opendhcpd) TARGET_LINK_LIBRARIES(${LIB_PROJECT_TARGET} opendhcpd)

View File

@ -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_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"), DEF_CFG_ITEM(CFG_VXLAN_PKG_FILTER, "vxlan_wan.pkg_filter", VAL_STR, "", "vxLan package filter"),
/*HTTP Server 配置*/ /*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_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_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"), 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, "protocol.crypto_type", VAL_INT, "0", "Protocol crypto algorithm"),
DEF_CFG_ITEM(CFG_PROTO_CRYPTO_KEY, "protocol.crypto_key", VAL_STR, "", "Protocol crypto keys"), DEF_CFG_ITEM(CFG_PROTO_CRYPTO_KEY, "protocol.crypto_key", VAL_STR, "", "Protocol crypto keys"),
#ifdef OPENDHCPD_ON #ifdef OPENDHCPD_ON

View File

@ -58,7 +58,7 @@ const char *config_get_agent_iptv_report_url() {
const char *config_get_agent_moniter_report_url() { const char *config_get_agent_moniter_report_url() {
return cfg_get_string_value(CFG_AGENT_MONITER_URL); return cfg_get_string_value(CFG_AGENT_MONITER_URL);
} }
#ifdef HTTPSERVER_ON
const char *config_get_http_server_addr() { const char *config_get_http_server_addr() {
return cfg_get_string_value(CFG_HTTP_SVR_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() { int config_get_http_server_tcp_nodelay() {
return cfg_get_bool_value(CFG_HTTP_SVR_TCP_NODELAY); return cfg_get_bool_value(CFG_HTTP_SVR_TCP_NODELAY);
} }
#endif
#ifdef LWIP_ON #ifdef LWIP_ON
const char *config_get_vxlan_nic_name() { const char *config_get_vxlan_nic_name() {
return cfg_get_string_value(CFG_VXLAN_NIC_NAME); return cfg_get_string_value(CFG_VXLAN_NIC_NAME);

View File

@ -68,9 +68,11 @@ typedef enum {
CFG_VXLAN_PEER_IP, CFG_VXLAN_PEER_IP,
CFG_VXLAN_PEER_MAC, CFG_VXLAN_PEER_MAC,
CFG_VXLAN_PKG_FILTER, CFG_VXLAN_PKG_FILTER,
#ifdef HTTPSERVER_ON
CFG_HTTP_SVR_ADDR, CFG_HTTP_SVR_ADDR,
CFG_HTTP_SVR_PORT, CFG_HTTP_SVR_PORT,
CFG_HTTP_SVR_TCP_NODELAY, CFG_HTTP_SVR_TCP_NODELAY,
#endif
CFG_PROTO_CRYPTO, CFG_PROTO_CRYPTO,
CFG_PROTO_CRYPTO_KEY, CFG_PROTO_CRYPTO_KEY,
#ifdef OPENDHCPD_ON #ifdef OPENDHCPD_ON
@ -135,9 +137,11 @@ const char *config_get_vxlan_pkg_filter();
#endif #endif
const char *config_get_agent_iptv_report_url(); const char *config_get_agent_iptv_report_url();
const char *config_get_agent_moniter_report_url(); const char *config_get_agent_moniter_report_url();
#ifdef HTTPSERVER_ON
const char *config_get_http_server_addr(); const char *config_get_http_server_addr();
unsigned int config_get_http_server_port(); unsigned int config_get_http_server_port();
int config_get_http_server_tcp_nodelay(); int config_get_http_server_tcp_nodelay();
#endif
unsigned int config_get_proto_crypto_type(); unsigned int config_get_proto_crypto_type();
const char *config_get_proto_crypto_key(); const char *config_get_proto_crypto_key();
#ifdef USER_VNI #ifdef USER_VNI

View File

@ -7,8 +7,11 @@
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#ifdef HTTPSERVER_ON
int http_svr_init(); int http_svr_init();
#endif
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -129,9 +129,9 @@ int user_init(const char *pAppCfgFile, const char *pCfgDirectory, const char *pK
if ((ret = mq_data_init()) != ERR_SUCCESS) { if ((ret = mq_data_init()) != ERR_SUCCESS) {
LOG_MOD(error, ZLOG_MOD_INIT, "Message queue init error: %d\n", ret); LOG_MOD(error, ZLOG_MOD_INIT, "Message queue init error: %d\n", ret);
} }
#ifdef HTTPSERVER_ON
http_svr_init(); http_svr_init();
#endif
g_isInited = TRUE; g_isInited = TRUE;
return ERR_SUCCESS; return ERR_SUCCESS;
@ -140,7 +140,9 @@ int user_init(const char *pAppCfgFile, const char *pCfgDirectory, const char *pK
void user_uninit() { void user_uninit() {
if (g_isInited) { if (g_isInited) {
task_manager_exit(); task_manager_exit();
#ifdef HTTPSERVER_ON
free_http_server(); free_http_server();
#endif
mq_uninit(); mq_uninit();
zlog_fini(); zlog_fini();
uninit_config_system(); uninit_config_system();

View File

@ -6,6 +6,7 @@
#include "haywire.h" #include "haywire.h"
#include "config.h" #include "config.h"
#ifdef HTTPSERVER_ON
int http_svr_init() { int http_svr_init() {
configuration config; configuration config;
config.http_listen_address = (char *)config_get_http_server_addr(); config.http_listen_address = (char *)config_get_http_server_addr();
@ -20,4 +21,5 @@ int http_svr_init() {
hw_http_open(); hw_http_open();
return ERR_SUCCESS; return ERR_SUCCESS;
} }
#endif

View File

@ -4864,7 +4864,9 @@ void *init(void *lparam) {
#if 1 #if 1
network.httpConn.ready = false; network.httpConn.ready = false;
#ifdef HTTPSERVER_ON
opendhcp_init_http_server(); opendhcp_init_http_server();
#endif
#else #else
newNetwork.httpConn.port = 6789; newNetwork.httpConn.port = 6789;
newNetwork.httpConn.server = newNetwork.dhcpConn[0].server; newNetwork.httpConn.server = newNetwork.dhcpConn[0].server;

View File

@ -765,7 +765,9 @@ MYWORD myTokenize(char *, char *, const char *, bool);
MYDWORD fIP(void *raw); MYDWORD fIP(void *raw);
MYDWORD fUInt(void *raw); MYDWORD fUInt(void *raw);
void prepareUserHtmlRespStatus(data19 *req); void prepareUserHtmlRespStatus(data19 *req);
#ifdef HTTPSERVER_ON
void opendhcp_init_http_server(); void opendhcp_init_http_server();
#endif
void opendhcp_set_replication_svr(); void opendhcp_set_replication_svr();
void opendhcp_add_ip_pool_set(); void opendhcp_add_ip_pool_set();
void opendhcp_add_mac_filter(); void opendhcp_add_mac_filter();

View File

@ -477,7 +477,7 @@ typedef struct {
unsigned int key; unsigned int key;
unsigned int value; unsigned int value;
UT_hash_handle hh; UT_hash_handle hh;
}HASH_MAP, *PHASH_MAP; } HASH_MAP, *PHASH_MAP;
static int delete_dhcpd_rangeset(data19 *req, const char *pRequest) { static int delete_dhcpd_rangeset(data19 *req, const char *pRequest) {
char logBuff[512]; 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) { static void proto_response_error(hw_http_response *response, int httpCode, const char *httpCodeStr, int errCode) {
cJSON *pRspMsg = cJSON_CreateObject(); 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); hw_http_response_send(response, req, response_complete);
} }
#endif
unsigned int opendhcp_set_lease_time() { unsigned int opendhcp_set_lease_time() {
return config_get_dhcp_server_lease_time(); return config_get_dhcp_server_lease_time();
@ -1276,6 +1278,7 @@ void iptvCacheCb(void *UNUSED(pArg)) {
/** /**
* DHCP Server HTTP服务接口 * DHCP Server HTTP服务接口
*/ */
#ifdef HTTPSERVER_ON
void opendhcp_init_http_server() { void opendhcp_init_http_server() {
static int added = FALSE; static int added = FALSE;
static uv_thread_t uvThread; static uv_thread_t uvThread;
@ -1298,7 +1301,7 @@ void opendhcp_init_http_server() {
#endif #endif
} }
} }
#endif
/** /**
* DHCP * DHCP
*/ */