-
-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
427 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
DEFINES =ENABLE_CONTENT | ||
DEFINES =ENABLE_CONTENT ENABLE_FIRMWARE_UPLOAD | ||
|
||
#DEFINES+=NDEBUG | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
/** | ||
* @file httpd.h | ||
* @brief HTTP daemon class for managing HTTP server tasks. | ||
* | ||
* This class handles HTTP requests and integrates with the network and mDNS subsystems. | ||
* It uses placement new to construct and destruct request handlers explicitly. | ||
*/ | ||
/* Copyright (C) 2021-2024 by Arjan van Vught mailto:[email protected] | ||
/* Copyright (C) 2021-2025 by Arjan van Vught mailto:[email protected] | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
|
@@ -35,11 +39,38 @@ | |
|
||
#include "../../lib-network/config/net_config.h" | ||
|
||
#include "debug.h" | ||
|
||
/** | ||
* @class HttpDaemon | ||
* @brief A class that manages an HTTP server with support for multiple connections. | ||
* | ||
* The HttpDaemon class sets up an HTTP server, handles incoming requests, and integrates with mDNS. | ||
*/ | ||
class HttpDaemon { | ||
public: | ||
/** | ||
* @brief Constructor for HttpDaemon. | ||
* | ||
* Initializes the HTTP daemon, sets up the TCP listener on port 80, | ||
* creates request handlers, and registers the service with mDNS. | ||
*/ | ||
HttpDaemon(); | ||
|
||
/** | ||
* @brief Destructor for HttpDaemon. | ||
* | ||
* Cleans up resources, unregisters the mDNS service, | ||
* destroys request handlers, and stops the TCP listener. | ||
*/ | ||
~HttpDaemon(); | ||
|
||
/** | ||
* @brief Main loop function to handle HTTP requests. | ||
* | ||
* Reads incoming TCP data, determines the connection handle, | ||
* and dispatches the request to the appropriate handler. | ||
*/ | ||
void Run() { | ||
uint32_t nConnectionHandle; | ||
const auto nBytesReceived = Network::Get()->TcpRead(m_nHandle, const_cast<const uint8_t **>(reinterpret_cast<uint8_t **>(&m_pReceiveBuffer)), nConnectionHandle); | ||
|
@@ -50,11 +81,23 @@ class HttpDaemon { | |
|
||
DEBUG_PRINTF("nConnectionHandle=%u", nConnectionHandle); | ||
|
||
pHandleRequest[nConnectionHandle]->HandleRequest(nBytesReceived, m_pReceiveBuffer); | ||
handleRequest[nConnectionHandle].HandleRequest(nBytesReceived, m_pReceiveBuffer); | ||
} | ||
|
||
private: | ||
HttpDeamonHandleRequest *pHandleRequest[TCP_MAX_TCBS_ALLOWED]; | ||
/** | ||
* https://www.gd32-dmx.org/memory.html | ||
*/ | ||
#if defined (GD32F207RG) || defined (GD32F450VE) || defined (GD32F470ZK) | ||
# define SECTION_HTTPD __attribute__ ((section (".httpd"))) | ||
#else | ||
# define SECTION_HTTPD | ||
#endif | ||
/* | ||
* Each handler corresponds to a connection handle. Objects are constructed | ||
* using placement new and must be explicitly destructed. | ||
*/ | ||
static inline HttpDeamonHandleRequest handleRequest[TCP_MAX_TCBS_ALLOWED] __attribute__ ((aligned (4))) SECTION_HTTPD; | ||
int32_t m_nHandle { -1 }; | ||
char *m_pReceiveBuffer { nullptr }; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
* @file tftpfileserver.h | ||
* | ||
*/ | ||
/* Copyright (C) 2019-2024 by Arjan van Vught mailto:[email protected] | ||
/* Copyright (C) 2019-2025 by Arjan van Vught mailto:[email protected] | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
|
@@ -37,28 +37,6 @@ | |
|
||
namespace tftpfileserver { | ||
bool is_valid(const void *pBuffer); | ||
#if defined(__linux__) || defined (__APPLE__) | ||
#else | ||
# if defined (H3) | ||
# if defined(ORANGE_PI) | ||
static constexpr char FILE_NAME[] = "orangepi_zero.uImage"; | ||
# else | ||
static constexpr char FILE_NAME[] = "orangepi_one.uImage"; | ||
# endif | ||
# elif defined (GD32) | ||
# if defined (GD32F10X) | ||
static constexpr char FILE_NAME[] = "gd32f107.bin"; | ||
# elif defined (GD32F20X) | ||
static constexpr char FILE_NAME[] = "gd32f207.bin"; | ||
# elif defined (GD32F4XX) | ||
static constexpr char FILE_NAME[] = "gd32f4xx.bin"; | ||
# elif defined (GD32H7XX) | ||
static constexpr char FILE_NAME[] = "gd32h7xx.bin"; | ||
# else | ||
# error FAMILY is not defined | ||
# endif | ||
# endif | ||
#endif | ||
} // namespace tftpfileserver | ||
|
||
class TFTPFileServer final: public TFTPDaemon { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
* | ||
*/ | ||
/* Copyright (C) 2020 by hippy mailto:[email protected] | ||
* Copyright (C) 2020-2024 by Arjan van Vught mailto:[email protected] | ||
* Copyright (C) 2020-2025 by Arjan van Vught mailto:[email protected] | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
|
@@ -31,15 +31,15 @@ | |
|
||
#include "debug.h" | ||
|
||
void h3_board_dump(); | ||
|
||
extern "C" { | ||
void h3_board_dump(void); | ||
void h3_dump_memory_mapping(void); | ||
void h3_ccu_pll_dump(void); | ||
void arm_dump_memmap(void); | ||
void arm_dump_page_table(void); | ||
} | ||
|
||
|
||
namespace shell::dump { | ||
namespace arg { | ||
static constexpr char BOARD[] = "board"; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* @file http_status_messages.h | ||
* | ||
*/ | ||
/* Copyright (C) 2025 by Arjan van Vught mailto:[email protected] | ||
* | ||
* 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. | ||
*/ | ||
|
||
|
||
#ifndef HTTP_STATUS_MESSAGES_H_ | ||
#define HTTP_STATUS_MESSAGES_H_ | ||
|
||
namespace httpd { | ||
static constexpr const char STATUS_400[] = "{\"code\":400,\"status\":\"Bad Request\",\"message\":\"%s\"}\n"; | ||
static constexpr auto STATUS_400_LENGTH = sizeof(STATUS_400) - 1; | ||
static constexpr const char STATUS_404[] = "{\"code\":404,\"status\":\"Not found\",\"message\":\"%s\"}\n"; | ||
static constexpr auto STATUS_404_LENGTH = sizeof(STATUS_404) - 1; | ||
} // namespace httpd | ||
|
||
#endif /* HTTP_STATUS_MESSAGES_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
* @file httpd.cpp | ||
* | ||
*/ | ||
/* Copyright (C) 2021-2024 by Arjan van Vught mailto:[email protected] | ||
/* Copyright (C) 2021-2025 by Arjan van Vught mailto:[email protected] | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
|
@@ -47,8 +47,7 @@ HttpDaemon::HttpDaemon() { | |
assert(m_nHandle != -1); | ||
|
||
for (uint32_t nIndex = 0; nIndex < TCP_MAX_TCBS_ALLOWED; nIndex++) { | ||
pHandleRequest[nIndex] = new HttpDeamonHandleRequest(nIndex, m_nHandle); | ||
assert(pHandleRequest[nIndex] != nullptr); | ||
new (&handleRequest[nIndex]) HttpDeamonHandleRequest(nIndex, m_nHandle); | ||
} | ||
|
||
mdns_service_record_add(nullptr, mdns::Services::HTTP); | ||
|
@@ -62,9 +61,8 @@ HttpDaemon::~HttpDaemon() { | |
mdns_service_record_delete(mdns::Services::HTTP); | ||
|
||
for (uint32_t nIndex = 0; nIndex < TCP_MAX_TCBS_ALLOWED; nIndex++) { | ||
if (pHandleRequest[nIndex] != nullptr) { | ||
delete pHandleRequest[nIndex]; | ||
} | ||
// Explicitly calling the destructor because objects were constructed with placement new. | ||
handleRequest[nIndex].~HttpDeamonHandleRequest(); | ||
} | ||
|
||
Network::Get()->TcpEnd(m_nHandle); | ||
|
Oops, something went wrong.