Refactors Lumenite to use a new server

Moves Lumenite to a new, modern C++ server implementation,
removing the old implementation and integrating it.

The new server implementation provides a more robust and
efficient foundation for handling HTTP requests, improving
performance and scalability.

Additionally, the old CURL dependency is removed and replaced
with simpler and more efficient methods using the built-in
http_get from LumenitePackageManager for package management.

The yaml-cpp library is added for extended parsing abilities.
This commit is contained in:
2025-08-07 08:42:49 -05:00
parent d638981262
commit b678e2353f
7 changed files with 553 additions and 641 deletions

1
.idea/vcs.xml generated
View File

@@ -4,5 +4,6 @@
<mapping directory="" vcs="Git" />
<mapping directory="$PROJECT_DIR$/cmake-build-debug/_deps/curl-src" vcs="Git" />
<mapping directory="$PROJECT_DIR$/cmake-build-debug/_deps/jsoncpp-src" vcs="Git" />
<mapping directory="$PROJECT_DIR$/cmake-build-debug/_deps/yamlcpp-src" vcs="Git" />
</component>
</project>

View File

@@ -4,66 +4,43 @@ project(Lumenite LANGUAGES C CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
include(FetchContent)
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build static libraries" FORCE)
# jsoncpp
FetchContent_Declare(
jsoncpp
GIT_REPOSITORY https://github.com/open-source-parsers/jsoncpp.git
GIT_TAG 1.9.5
)
set(JSONCPP_WITH_TESTS OFF CACHE BOOL "Disable jsoncpp tests" FORCE)
FetchContent_MakeAvailable(jsoncpp)
set(BUILD_CURL_EXE OFF CACHE BOOL "Don't build curl executable" FORCE)
set(BUILD_TESTING OFF CACHE BOOL "Don't build curl tests" FORCE)
set(HTTP_ONLY OFF CACHE BOOL "Enable HTTPS support" FORCE)
set(ENABLE_IPV6 ON CACHE BOOL "Enable IPv6" FORCE)
set(CURL_USE_LIBIDN2 OFF CACHE BOOL "Disable libidn2" FORCE)
set(CURL_USE_LIBIDN OFF CACHE BOOL "Disable libidn" FORCE)
set(CURL_USE_WIN32_IDN ON CACHE BOOL "Enable Win32 IDN (skip libidn2)" FORCE)
# yaml-cpp
FetchContent_Declare(
yamlcpp
GIT_REPOSITORY https://github.com/jbeder/yaml-cpp.git
GIT_TAG 0.8.0
)
set(YAML_CPP_BUILD_TESTS OFF CACHE BOOL "Disable yaml-cpp tests" FORCE)
FetchContent_MakeAvailable(yamlcpp)
FetchContent_Declare(
curl
GIT_REPOSITORY https://github.com/curl/curl.git
GIT_TAG curl-8_7_1
)
FetchContent_MakeAvailable(curl)
# sqlite3
FetchContent_Declare(
sqlite3
URL https://www.sqlite.org/2024/sqlite-amalgamation-3450100.zip
)
FetchContent_MakeAvailable(sqlite3)
add_library(sqlite3 STATIC ${sqlite3_SOURCE_DIR}/sqlite3.c)
target_include_directories(sqlite3 PUBLIC ${sqlite3_SOURCE_DIR})
# Lua
file(GLOB LUA_SRC CONFIGURE_DEPENDS vendor/lua/*.c)
add_library(lua_static STATIC ${LUA_SRC})
target_include_directories(lua_static PUBLIC vendor/lua)
# OpenSSL
if (MINGW)
set(OPENSSL_ROOT_DIR "C:/msys64/mingw64")
set(OPENSSL_USE_STATIC_LIBS TRUE)
@@ -83,12 +60,9 @@ add_executable(lumenite
src/modules/LumeniteSafe.cpp src/modules/LumeniteSafe.h
src/utils/ProjectScaffolder.cpp src/utils/ProjectScaffolder.h
src/utils/Version.h
src/utils/MimeDetector.cpp
src/utils/MimeDetector.h
src/modules/ModuleBase.cpp
src/modules/ModuleBase.h
src/utils/LumenitePackageManager.cpp
src/utils/LumenitePackageManager.h
src/utils/MimeDetector.cpp src/utils/MimeDetector.h
src/modules/ModuleBase.cpp src/modules/ModuleBase.h
src/utils/LumenitePackageManager.cpp src/utils/LumenitePackageManager.h
)
target_include_directories(lumenite PRIVATE
@@ -100,7 +74,6 @@ target_include_directories(lumenite PRIVATE
target_link_libraries(lumenite PRIVATE
lua_static
jsoncpp_static
CURL::libcurl
sqlite3
OpenSSL::SSL
OpenSSL::Crypto
@@ -114,4 +87,3 @@ endif ()
if (WIN32)
target_link_libraries(lumenite PRIVATE ws2_32 iphlpapi wininet)
endif ()

View File

@@ -6,7 +6,6 @@
#include <sstream>
#include <json/json.h>
#include <curl/curl.h>
#include "ErrorHandler.h"
#include "LumeniteApp.h"
@@ -17,6 +16,7 @@
#include "modules/LumeniteDb.h"
#include "modules/LumeniteSafe.h"
#include "modules/ModuleBase.h"
#include "utils/LumenitePackageManager.h"
#include "utils/MimeDetector.h"
@@ -237,64 +237,16 @@ static int lua_http_get(lua_State *L)
{
const char *url = luaL_checkstring(L, 1);
CURL *curl = curl_easy_init();
std::string response;
long http_status = 0;
CURLcode res;
auto [status, body] = LumenitePackageManager::http_get(url);
lua_newtable(L); // prepare return table
if (!curl) {
lua_pushstring(L, "status");
lua_pushinteger(L, 0);
lua_settable(L, -3);
lua_pushstring(L, "body");
lua_pushstring(L, "");
lua_settable(L, -3);
lua_pushstring(L, "error");
lua_pushstring(L, "CURL initialization failed");
lua_settable(L, -3);
return 1;
}
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10L);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
res = curl_easy_perform(curl);
if (res != CURLE_OK) {
curl_easy_cleanup(curl);
lua_pushstring(L, "status");
lua_pushinteger(L, 0);
lua_settable(L, -3);
lua_pushstring(L, "body");
lua_pushstring(L, "");
lua_settable(L, -3);
lua_pushstring(L, "error");
lua_pushstring(L, curl_easy_strerror(res));
lua_settable(L, -3);
return 1;
}
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_status);
curl_easy_cleanup(curl);
lua_newtable(L);
lua_pushstring(L, "status");
lua_pushinteger(L, http_status);
lua_pushinteger(L, status);
lua_settable(L, -3);
lua_pushstring(L, "body");
lua_pushlstring(L, response.data(), response.size());
lua_pushlstring(L, body.data(), body.size());
lua_settable(L, -3);
return 1;

File diff suppressed because it is too large Load Diff

View File

@@ -64,3 +64,5 @@ private:
static void sendResponse(int clientSocket, const std::string &out);
};

View File

@@ -215,7 +215,7 @@ void LumenitePackageManager::saveYAML()
std::vector<LumenitePackageManager::AvailablePlugin> LumenitePackageManager::fetchRegistry()
{
std::vector<AvailablePlugin> list;
std::string rawJson = http_get(registryURL);
std::string rawJson = http_get(registryURL).second;
if (rawJson.empty()) {
log_error("Registry fetch failed.");
return list;
@@ -276,47 +276,74 @@ void LumenitePackageManager::markPluginInstalled(const std::string &name, const
}
std::string LumenitePackageManager::http_get(const std::string &url)
std::pair<long, std::string> LumenitePackageManager::http_get(const std::string &url)
{
#ifdef _WIN32
HINTERNET hInternet = InternetOpenA("LumenitePM", INTERNET_OPEN_TYPE_DIRECT, nullptr, nullptr, 0);
if (!hInternet) return "";
// Open the Internet session
HINTERNET hInternet = InternetOpenA(
"LumenitePM",
INTERNET_OPEN_TYPE_DIRECT,
nullptr,
nullptr,
0
);
if (!hInternet) return {0, ""};
DWORD flags = INTERNET_FLAG_NO_UI | INTERNET_FLAG_NO_COOKIES;
if (!use_cache) {
flags |= INTERNET_FLAG_RELOAD |
INTERNET_FLAG_NO_CACHE_WRITE | // never write to cache
INTERNET_FLAG_PRAGMA_NOCACHE | // no client or proxy cache
INTERNET_FLAG_NO_AUTH | // skip auth
INTERNET_FLAG_NO_AUTO_REDIRECT | // stop auto redirects
INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP |
INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS;
flags |= INTERNET_FLAG_RELOAD
| INTERNET_FLAG_NO_CACHE_WRITE
| INTERNET_FLAG_PRAGMA_NOCACHE
| INTERNET_FLAG_NO_AUTH
| INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP
| INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS;
}
HINTERNET hFile = InternetOpenUrlA(hInternet, url.c_str(), nullptr, 0, flags, 0);
// Open the URL
HINTERNET hFile = InternetOpenUrlA(
hInternet,
url.c_str(),
nullptr, 0,
flags,
0
);
if (!hFile) {
InternetCloseHandle(hInternet);
return "";
return {0, ""};
}
// Get the HTTP status code
DWORD status = 0, statusLen = sizeof(status);
HttpQueryInfoA(
hFile,
HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER,
&status,
&statusLen,
nullptr
);
// Read the body
std::ostringstream ss;
char buffer[4096];
DWORD bytesRead;
while (InternetReadFile(hFile, buffer, sizeof(buffer), &bytesRead) && bytesRead > 0) {
DWORD bytesRead = 0;
while (InternetReadFile(hFile, buffer, sizeof(buffer), &bytesRead)
&& bytesRead > 0) {
ss.write(buffer, bytesRead);
}
}
InternetCloseHandle(hFile);
InternetCloseHandle(hInternet);
return ss.str();
return { static_cast<long>(status), ss.str() };
#else
log_error("http_get not implemented on this platform.");
return "";
return {0, ""};
#endif
}
bool LumenitePackageManager::downloadFile(const std::string &url, const std::string &outPath)
{
#ifdef _WIN32

View File

@@ -7,6 +7,9 @@ class LumenitePackageManager
public:
static void run(const std::vector<std::string> &args);
static std::pair<long, std::string> http_get(const std::string &url);
private:
struct AvailablePlugin
{
@@ -42,7 +45,7 @@ private:
static void cmd_list();
static std::string http_get(const std::string &url);
static bool downloadFile(const std::string &url, const std::string &outPath);