mirror of
https://gitee.com/jiuyilian/embedded-framework.git
synced 2025-01-06 10:16:51 -05:00
Modify:Goahead open source code.
This commit is contained in:
parent
480d5ee9c7
commit
08031ed4fa
3546
external/goahead-5.2.0/modify/http.c
vendored
Normal file
3546
external/goahead-5.2.0/modify/http.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
|
@ -9,6 +9,7 @@ include_directories(
|
|||
${UTILS_SOURCE_PATH}/StatusCode/include
|
||||
${UTILS_SOURCE_PATH}/Log/include
|
||||
${UTILS_SOURCE_PATH}/FxHttpServer/include
|
||||
${UTILS_SOURCE_PATH}/WebServer/include
|
||||
${HAL_SOURCE_PATH}/include
|
||||
)
|
||||
#do not rely on any other library
|
||||
|
@ -21,7 +22,7 @@ aux_source_directory(./src/Protocol/SixFrame SRC_FILES)
|
|||
set(TARGET_NAME AppManager)
|
||||
add_library(${TARGET_NAME} STATIC ${SRC_FILES})
|
||||
|
||||
target_link_libraries(${TARGET_NAME} FxHttpServer StatusCode Log)
|
||||
target_link_libraries(${TARGET_NAME} WebServer StatusCode Log)
|
||||
|
||||
if ("${CLANG_TIDY_SUPPORT}" MATCHES "true")
|
||||
add_custom_target(
|
||||
|
|
|
@ -14,8 +14,9 @@
|
|||
*/
|
||||
#include "AppManager.h"
|
||||
#include "AppManagerMakePtr.h"
|
||||
#include "FxHttpServer.h"
|
||||
// #include "FxHttpServer.h"
|
||||
#include "ILog.h"
|
||||
#include "WebServer.h"
|
||||
AppManager::AppManager()
|
||||
{
|
||||
//
|
||||
|
@ -49,7 +50,8 @@ void AppManager::HttpServerStart(void)
|
|||
}
|
||||
void AppManager::HttpServerStop(void)
|
||||
{
|
||||
FxHttpServerExit();
|
||||
// FxHttpServerExit();
|
||||
WebServerExit();
|
||||
if (mHttpSever.joinable()) {
|
||||
mHttpSever.join();
|
||||
}
|
||||
|
@ -66,6 +68,9 @@ void AppManager::HttpServerThread(void)
|
|||
appImpl->AppRequestHandle(url, urlLength, responseHandle, context);
|
||||
}
|
||||
};
|
||||
FxHttpServerInit(httpHandle, 8080);
|
||||
FxHttpServerUnInit();
|
||||
}
|
||||
// FxHttpServerInit(httpHandle, 8080);
|
||||
// FxHttpServerUnInit();
|
||||
WebServerParam web = {.mIp = "192.168.1.29", .mPort = 8888, .mHttpRequestHandle = httpHandle};
|
||||
WebServerInit(web);
|
||||
WebServerUnInit();
|
||||
}
|
|
@ -31,7 +31,6 @@ bool CreateAppManagerModule(void)
|
|||
bool DestroyAppManagerModule(void)
|
||||
{
|
||||
auto instance = std::make_shared<IAppManager>();
|
||||
IAppManager::GetInstance()->UnInit();
|
||||
IAppManager::GetInstance(&instance);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ include_directories(
|
|||
./tool/include
|
||||
${UTILS_SOURCE_PATH}/Log/include
|
||||
${UTILS_SOURCE_PATH}/StatusCode/include
|
||||
# ${UTILS_SOURCE_PATH}/UartDevice/include
|
||||
# ${UTILS_SOURCE_PATH}/WebServer/include
|
||||
# ${UTILS_SOURCE_PATH}/McuProtocol/include
|
||||
${UTILS_SOURCE_PATH}/KeyControl/include
|
||||
${UTILS_SOURCE_PATH}/LedControl/include
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
*/
|
||||
#include "IAppManager.h"
|
||||
#include "ILog.h"
|
||||
// #include "WebServer.h"
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <thread>
|
||||
|
|
|
@ -24,7 +24,8 @@ TEST(WebServerTest, Demo)
|
|||
{
|
||||
CreateLogModule();
|
||||
ILogInit(LOG_INSTANCE_TYPE_END);
|
||||
WebServerInit();
|
||||
WebServerParam web = {.mIp = "192.168.1.29", .mPort = 8080};
|
||||
WebServerInit(web);
|
||||
// std::this_thread::sleep_for(std::chrono::milliseconds(1000 * 10));
|
||||
ILogUnInit();
|
||||
}
|
||||
|
|
|
@ -15,8 +15,6 @@ include_directories(
|
|||
# ${EXTERNAL_SOURCE_PATH}/libconfig/libconfig-1.7.3/lib/.libs
|
||||
# )
|
||||
|
||||
|
||||
|
||||
if (NOT DEFINED GOAHEAD_DOCUMENTS_PATH)
|
||||
set(GOAHEAD_DOCUMENTS_PATH "web")
|
||||
endif()
|
||||
|
@ -68,6 +66,7 @@ add_custom_command(
|
|||
OUTPUT ${EXTERNAL_SOURCE_PATH}/goahead-5.2.0/GoAhead/Makefile
|
||||
COMMAND echo "tar zxvf goahead-5.2.0.tar.gz"
|
||||
COMMAND tar zxvf goahead-5.2.0.tar.gz
|
||||
COMMAND cp ${EXTERNAL_SOURCE_PATH}/goahead-5.2.0/modify/http.c ${EXTERNAL_SOURCE_PATH}/goahead-5.2.0/GoAhead/src
|
||||
WORKING_DIRECTORY ${EXTERNAL_SOURCE_PATH}/goahead-5.2.0/
|
||||
)
|
||||
add_custom_command(
|
||||
|
|
|
@ -36,4 +36,38 @@ add_custom_target(
|
|||
## 1.3. 环境配置
|
||||
|
||||
1. 拷贝self.crt,self.key两个到运行目录;
|
||||
2. 配置文件两个:route.txt,auth.txt;
|
||||
2. 配置文件两个:route.txt,auth.txt;
|
||||
|
||||
## 1.4. 代码整改
|
||||
|
||||
   由于官方源码是不超时阻塞,为了方便自动化测试,把官方源码的不超时阻塞改成超时阻塞。
|
||||
```
|
||||
PUBLIC void websServiceEvents(int *finished)
|
||||
{
|
||||
int delay, nextEvent;
|
||||
|
||||
if (finished) {
|
||||
*finished = 0;
|
||||
}
|
||||
// ===================== added by xiao ===================== //
|
||||
// delay = 0; // open source code
|
||||
#define TIME_OUT_MS 1000
|
||||
delay = TIME_OUT_MS; // modifed by xiao, time out 1000 ms
|
||||
// ===================== added by xiao end ===================== //
|
||||
while (!finished || !*finished) {
|
||||
if (socketSelect(-1, delay)) {
|
||||
socketProcess();
|
||||
}
|
||||
#if ME_GOAHEAD_CGI
|
||||
delay = websCgiPoll();
|
||||
#else
|
||||
delay = MAXINT;
|
||||
#endif
|
||||
nextEvent = websRunEvents();
|
||||
delay = min(delay, nextEvent);
|
||||
// ===================== added by xiao ===================== //
|
||||
delay = (delay <= 0 || delay >= TIME_OUT_MS) ? TIME_OUT_MS : delay;
|
||||
// ===================== added by xiao end ===================== //
|
||||
}
|
||||
}
|
||||
```
|
|
@ -18,7 +18,16 @@
|
|||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
StatusCode WebServerInit(void);
|
||||
typedef void (*ResponseHandle)(const char *, void *);
|
||||
typedef void (*HttpHandleCallback)(const char *, const unsigned int, ResponseHandle, void *);
|
||||
typedef struct web_server_param
|
||||
{
|
||||
const char *mIp;
|
||||
int mPort;
|
||||
HttpHandleCallback mHttpRequestHandle;
|
||||
} WebServerParam;
|
||||
StatusCode WebServerInit(const WebServerParam webParam);
|
||||
StatusCode WebServerExit(void);
|
||||
StatusCode WebServerUnInit(void);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -27,7 +27,10 @@ static void logHeader(void)
|
|||
{
|
||||
char home[ME_GOAHEAD_LIMIT_STRING];
|
||||
|
||||
getcwd(home, sizeof(home));
|
||||
char *result = getcwd(home, sizeof(home));
|
||||
if (nullptr == result) {
|
||||
LogWarning("Can't get path.\n");
|
||||
}
|
||||
logmsg(2, "Configuration for %s", ME_TITLE);
|
||||
logmsg(2, "---------------------------------------------");
|
||||
logmsg(2, "Version: %s", ME_VERSION);
|
||||
|
@ -47,7 +50,30 @@ void initPlatform(void)
|
|||
signal(SIGKILL, sigHandler);
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
}
|
||||
StatusCode WebServerInit(void)
|
||||
static bool testHandler(Webs *wp)
|
||||
{
|
||||
if (smatch(wp->path, "/")) {
|
||||
// websRewriteRequest(wp, "/home.html");
|
||||
/* Fall through */
|
||||
}
|
||||
LogInfo("sssssssssssssssssssssssssssss url = %s\n", wp->url);
|
||||
// websSetStatus(wp, HTTP_CODE_OK);
|
||||
// websWriteHeaders(wp, 0, 0);
|
||||
// websWriteEndHeaders(wp);
|
||||
// websWrite(wp, "<html><body><h2>");
|
||||
// websWrite(wp, "sssssssssssssssssssssss");
|
||||
// websWrite(wp, "</h2></body></html>\n");
|
||||
// websDone(wp);
|
||||
websSetStatus(wp, 200);
|
||||
websWriteHeaders(wp, -1, 0);
|
||||
websWriteHeader(wp, "Content-Type", "text/plain");
|
||||
websWriteEndHeaders(wp);
|
||||
websWrite(wp, "Hello Legacy World\n");
|
||||
websDone(wp);
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
StatusCode WebServerInit(const WebServerParam webParam)
|
||||
{
|
||||
websSetDebug(1);
|
||||
logSetPath("stdout:2");
|
||||
|
@ -55,8 +81,10 @@ StatusCode WebServerInit(void)
|
|||
constexpr int BUF_LENGTH = 128;
|
||||
char routePath[BUF_LENGTH] = {0};
|
||||
char authPath[BUF_LENGTH] = {0};
|
||||
char listen[BUF_LENGTH] = {0};
|
||||
snprintf(routePath, BUF_LENGTH, "%s/route.txt", GOAHEAD_CONFIG_FILE_PATH);
|
||||
snprintf(authPath, BUF_LENGTH, "%s/auth.txt", GOAHEAD_CONFIG_FILE_PATH);
|
||||
snprintf(listen, BUF_LENGTH, "%s:%d", webParam.mIp, webParam.mPort);
|
||||
initPlatform();
|
||||
if (websOpen(documents, routePath) < 0) {
|
||||
LogError("Cannot initialize server. Exiting.\n");
|
||||
|
@ -67,12 +95,24 @@ StatusCode WebServerInit(void)
|
|||
LogError("Cannot load %s", authPath);
|
||||
return CreateStatusCode(STATUS_CODE_NOT_OK);
|
||||
}
|
||||
if (websListen("192.168.1.189:8080") < 0) {
|
||||
if (websListen(listen) < 0) {
|
||||
return CreateStatusCode(STATUS_CODE_NOT_OK);
|
||||
}
|
||||
websDefineHandler("test", 0, testHandler, 0, 0);
|
||||
websAddRoute("/test", "test", 0);
|
||||
websServiceEvents(&finished);
|
||||
logmsg(1, "Instructed to exit\n");
|
||||
websClose();
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode WebServerUnInit(void) { return CreateStatusCode(STATUS_CODE_OK); }
|
||||
StatusCode WebServerExit(void)
|
||||
{
|
||||
LogInfo("Stop goahead web server.\n");
|
||||
finished = 1;
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode WebServerUnInit(void)
|
||||
{
|
||||
LogInfo("WebServerUnInit.\n");
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
Loading…
Reference in New Issue
Block a user