139
tests/ipdemo/CMakeLists.txt
Normal file
139
tests/ipdemo/CMakeLists.txt
Normal file
@ -0,0 +1,139 @@
|
||||
# Get the current date in yyyy.mmdd.hhmm format
|
||||
execute_process(
|
||||
COMMAND date "+%Y.%m%d.%H%M"
|
||||
OUTPUT_VARIABLE PROJECT_VERSION
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
|
||||
cmake_minimum_required(VERSION 3.14)
|
||||
if(NOT DEFINED PROJECT_NAME)
|
||||
message(FATAL_ERROR "PROJECT_NAME is not defined. Pass it via -DPROJECT_NAME=<name>")
|
||||
endif()
|
||||
|
||||
# Include required modules
|
||||
include(FetchContent)
|
||||
|
||||
project(${PROJECT_NAME} VERSION ${PROJECT_VERSION} LANGUAGES CXX)
|
||||
set(PROJECT_EXE_NAME ${PROJECT_NAME})
|
||||
|
||||
# Force static linking globally
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
|
||||
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
|
||||
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libraries" FORCE)
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE OFF)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static -rdynamic")
|
||||
set(ZLIB_USE_STATIC_LIBS "ON")
|
||||
|
||||
set(CMAKE_CXX_STANDARD 23)
|
||||
set(CMAKE_C_STANDARD 23)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
# Set default build type to Debug if not specified
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build (Debug or Release)" FORCE)
|
||||
endif()
|
||||
|
||||
# Configure build-specific compiler flags
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -gdwarf-4 -fno-omit-frame-pointer")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -DNDEBUG -g -gdwarf-4 -fno-omit-frame-pointer")
|
||||
|
||||
# Configure version.hpp file
|
||||
configure_file(
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/src/version.hpp.in"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/src/autogen/version.hpp"
|
||||
@ONLY
|
||||
)
|
||||
|
||||
# Set CMAKE_MODULE_PATH to include our custom find modules
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
|
||||
|
||||
# Add custom target to run cmake_prebuild.sh at the start of the build process
|
||||
add_custom_target(run_prebuild_script ALL
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "Running cmake_prebuild.sh..."
|
||||
COMMAND ${CMAKE_COMMAND} -E env bash ${CMAKE_CURRENT_SOURCE_DIR}/cmake_prebuild.sh
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
file(GLOB_RECURSE SOURCES "src/*.cpp")
|
||||
|
||||
# Mark sources as GENERATED to defer existence check until build time
|
||||
set_source_files_properties(${SOURCES} PROPERTIES GENERATED TRUE)
|
||||
|
||||
# Add executable
|
||||
add_executable(${PROJECT_EXE_NAME} ${SOURCES})
|
||||
add_dependencies(${PROJECT_EXE_NAME} run_prebuild_script)
|
||||
|
||||
# Set include directories
|
||||
# build dir goes first so that we can use the generated version.hpp
|
||||
target_include_directories(${PROJECT_EXE_NAME} PRIVATE
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/src/autogen>
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/autogen
|
||||
)
|
||||
|
||||
|
||||
|
||||
# Add nlohmann/json
|
||||
FetchContent_Declare(
|
||||
nlohmann_json
|
||||
GIT_REPOSITORY https://github.com/nlohmann/json.git
|
||||
GIT_TAG v3.12.0
|
||||
)
|
||||
FetchContent_MakeAvailable(nlohmann_json)
|
||||
|
||||
# Find required libraries using pkg-config
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_check_modules(LIBUNWIND REQUIRED IMPORTED_TARGET libunwind)
|
||||
|
||||
# Required libraries for basic stack tracing
|
||||
set(EXTRA_LIBS
|
||||
${LIBUNWIND_LIBRARIES}
|
||||
-lunwind
|
||||
-lunwind-x86_64
|
||||
-llzma # Required by libunwind for debug info
|
||||
-ldl # For dladdr
|
||||
)
|
||||
|
||||
|
||||
# Set paths for libraries before finding Drogon
|
||||
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH}
|
||||
/usr/local/jsoncpp
|
||||
/usr/local/openssl-musl
|
||||
/usr/local/pgsql
|
||||
/usr/local/mariadb-connector-c
|
||||
/usr/local/sqlite3
|
||||
/usr/local/mysql
|
||||
/usr/local/cares
|
||||
/usr/local/curl
|
||||
)
|
||||
|
||||
# Explicitly set jsoncpp paths for Drogon's FindJsoncpp.cmake
|
||||
set(JSONCPP_INCLUDE_DIRS /usr/local/jsoncpp/include)
|
||||
set(JSONCPP_LIBRARIES /usr/local/jsoncpp/lib/libjsoncpp.a)
|
||||
|
||||
find_package(Drogon CONFIG REQUIRED)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE Drogon::Drogon)
|
||||
|
||||
# Additional PostgreSQL libraries needed for static linking
|
||||
set(POSTGRESQL_EXTRA_LIBS
|
||||
/usr/local/pgsql/lib/libpgcommon.a
|
||||
/usr/local/pgsql/lib/libpgport.a
|
||||
)
|
||||
|
||||
# Link libraries
|
||||
target_link_libraries(${PROJECT_EXE_NAME} PRIVATE
|
||||
nlohmann_json::nlohmann_json
|
||||
Drogon::Drogon
|
||||
${POSTGRESQL_EXTRA_LIBS}
|
||||
${EXTRA_LIBS}
|
||||
)
|
||||
|
||||
# Set static linking flags
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
|
||||
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
|
||||
set(BUILD_SHARED_LIBS OFF)
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE OFF)
|
||||
|
||||
# Add musl's backtrace headers
|
||||
include_directories(/usr/include/musl)
|
3
tests/ipdemo/cmake_prebuild.sh
Executable file
3
tests/ipdemo/cmake_prebuild.sh
Executable file
@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "cmake_prebuild.sh complete."
|
186
tests/ipdemo/src/assert.hpp
Normal file
186
tests/ipdemo/src/assert.hpp
Normal file
@ -0,0 +1,186 @@
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <string_view>
|
||||
#include <source_location>
|
||||
#include <cxxabi.h>
|
||||
#include <libunwind.h>
|
||||
#include <dlfcn.h>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <unistd.h>
|
||||
|
||||
// ANSI color codes
|
||||
namespace colors {
|
||||
constexpr const char* reset = "\033[0m";
|
||||
constexpr const char* red = "\033[31m";
|
||||
constexpr const char* green = "\033[32m";
|
||||
constexpr const char* yellow = "\033[33m";
|
||||
constexpr const char* blue = "\033[34m";
|
||||
constexpr const char* magenta = "\033[35m";
|
||||
constexpr const char* cyan = "\033[36m";
|
||||
}
|
||||
|
||||
// Simple RAII wrapper for file descriptor
|
||||
class FileDescriptor {
|
||||
int fd_ = -1;
|
||||
public:
|
||||
explicit FileDescriptor(int fd) : fd_(fd) {}
|
||||
~FileDescriptor() { if (fd_ != -1) close(fd_); }
|
||||
operator int() const { return fd_; }
|
||||
FileDescriptor(const FileDescriptor&) = delete;
|
||||
FileDescriptor& operator=(const FileDescriptor&) = delete;
|
||||
};
|
||||
|
||||
struct SourceInfo {
|
||||
std::string function;
|
||||
std::string file;
|
||||
int line = 0;
|
||||
};
|
||||
|
||||
std::vector<SourceInfo> get_source_info_batch(const char* executable, const std::vector<void*>& addresses) {
|
||||
if (addresses.empty()) return {};
|
||||
|
||||
// Build command with all addresses
|
||||
std::string cmd = std::string("addr2line -f -e ") + executable;
|
||||
for (void* addr : addresses) {
|
||||
char addr_buf[32];
|
||||
snprintf(addr_buf, sizeof(addr_buf), " %p", addr);
|
||||
cmd += addr_buf;
|
||||
}
|
||||
cmd += " 2>/dev/null";
|
||||
|
||||
FILE* pipe = popen(cmd.c_str(), "r");
|
||||
if (!pipe) return std::vector<SourceInfo>(addresses.size());
|
||||
|
||||
std::vector<SourceInfo> results(addresses.size());
|
||||
char buffer[1024] = {0};
|
||||
size_t current_frame = 0;
|
||||
|
||||
// Read function names and file/line info for each address
|
||||
while (current_frame < addresses.size() && fgets(buffer, sizeof(buffer), pipe)) {
|
||||
// Remove trailing newline
|
||||
size_t len = strlen(buffer);
|
||||
if (len > 0 && buffer[len-1] == '\n') {
|
||||
buffer[len-1] = '\0';
|
||||
}
|
||||
|
||||
// Demangle function name
|
||||
int status = 0;
|
||||
char* demangled = abi::__cxa_demangle(buffer, nullptr, nullptr, &status);
|
||||
if (demangled) {
|
||||
results[current_frame].function = demangled;
|
||||
free(demangled);
|
||||
} else {
|
||||
results[current_frame].function = buffer;
|
||||
}
|
||||
|
||||
// Read file and line number
|
||||
if (fgets(buffer, sizeof(buffer), pipe)) {
|
||||
char* colon = strchr(buffer, ':');
|
||||
if (colon) {
|
||||
*colon = '\0';
|
||||
results[current_frame].line = atoi(colon + 1);
|
||||
|
||||
// Extract just the filename
|
||||
const char* slash = strrchr(buffer, '/');
|
||||
results[current_frame].file = (slash ? slash + 1 : buffer);
|
||||
}
|
||||
}
|
||||
|
||||
current_frame++;
|
||||
}
|
||||
|
||||
pclose(pipe);
|
||||
return results;
|
||||
}
|
||||
|
||||
void print_stacktrace() {
|
||||
unw_cursor_t cursor;
|
||||
unw_context_t context;
|
||||
unw_word_t pc;
|
||||
char exe_path[1024] = {0};
|
||||
bool found_main = false;
|
||||
std::vector<SourceInfo> frames;
|
||||
|
||||
// Get the path to the current executable
|
||||
ssize_t count = readlink("/proc/self/exe", exe_path, sizeof(exe_path) - 1);
|
||||
if (count == -1) {
|
||||
strcpy(exe_path, "[unknown]");
|
||||
} else {
|
||||
exe_path[count] = '\0';
|
||||
}
|
||||
|
||||
// Initialize cursor to current frame
|
||||
unw_getcontext(&context);
|
||||
unw_init_local(&cursor, &context);
|
||||
|
||||
// First pass: collect frames until we find main
|
||||
std::vector<void*> addresses;
|
||||
while (unw_step(&cursor) > 0) {
|
||||
if (unw_get_reg(&cursor, UNW_REG_IP, &pc) != 0 || pc == 0) {
|
||||
break;
|
||||
}
|
||||
addresses.push_back(reinterpret_cast<void*>(pc));
|
||||
}
|
||||
|
||||
// Get source info for all addresses in batch
|
||||
std::vector<SourceInfo> results = get_source_info_batch(exe_path, addresses);
|
||||
|
||||
// Process results and check for main
|
||||
for (auto& info : results) {
|
||||
// Stop collecting after main()
|
||||
if (!info.function.empty() &&
|
||||
(info.function.find("main") != std::string::npos ||
|
||||
info.function.find("__libc_start_main") != std::string::npos)) {
|
||||
found_main = true;
|
||||
frames.push_back(info);
|
||||
break;
|
||||
}
|
||||
frames.push_back(info);
|
||||
}
|
||||
|
||||
// Print the collected frames in reverse order (most recent last)
|
||||
std::cerr << colors::yellow << "Stack trace (most recent call last):" << colors::reset << "\n";
|
||||
|
||||
for (size_t i = frames.size(); i-- > 0; ) {
|
||||
const auto& frame = frames[i];
|
||||
std::cerr << " "; // Indent each line
|
||||
|
||||
if (frame.function.empty()) {
|
||||
std::cerr << colors::red << "[unknown function]" << colors::reset;
|
||||
} else {
|
||||
std::cerr << colors::green << frame.function << colors::reset;
|
||||
}
|
||||
|
||||
if (!frame.file.empty() && frame.line > 0) {
|
||||
std::cerr << " at " << colors::blue << frame.file << colors::reset
|
||||
<< ":" << colors::magenta << frame.line << colors::reset;
|
||||
}
|
||||
|
||||
std::cerr << "\n";
|
||||
}
|
||||
|
||||
if (!found_main) {
|
||||
std::cerr << " " << colors::yellow << "[truncated - main() not found]" << colors::reset << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
void assert_failed(
|
||||
bool condition,
|
||||
std::string_view message,
|
||||
std::source_location location = std::source_location::current()
|
||||
) {
|
||||
if (!condition) {
|
||||
std::cerr << "Assertion failed at " << location.file_name() << ":" << location.line() << ": "
|
||||
<< location.function_name() << ": " << message << "\n";
|
||||
print_stacktrace();
|
||||
std::abort();
|
||||
}
|
||||
}
|
||||
|
||||
#define ASSERT(condition, message) assert_failed(condition, message, std::source_location::current())
|
21
tests/ipdemo/src/autogen/version.hpp
Normal file
21
tests/ipdemo/src/autogen/version.hpp
Normal file
@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
|
||||
version.hpp is automatically generated by the build system, from version.hpp.in.
|
||||
|
||||
DO NOT EDIT VERSION.HPP!
|
||||
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace ipdemo {
|
||||
|
||||
// Version information
|
||||
const std::string VERSION = "@PROJECT_VERSION@";
|
||||
const std::string RELEASE_DATE = "@RELEASE_DATE@";
|
||||
const std::string AUTHOR = "j842";
|
||||
const std::string LICENSE = "MIT";
|
||||
|
||||
} // namespace dropshell
|
175
tests/ipdemo/src/http_utils.cpp
Normal file
175
tests/ipdemo/src/http_utils.cpp
Normal file
@ -0,0 +1,175 @@
|
||||
#include "http_utils.hpp"
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
static std::string find_ca_certificates() {
|
||||
// Common CA certificate locations across different Linux distributions
|
||||
const std::vector<std::string> ca_paths = {
|
||||
"/etc/ssl/certs/ca-certificates.crt", // Debian/Ubuntu/Raspbian
|
||||
"/etc/pki/tls/certs/ca-bundle.crt", // Fedora/RHEL/CentOS
|
||||
"/etc/ssl/ca-bundle.pem", // OpenSUSE
|
||||
"/etc/pki/tls/cert.pem", // Fedora/RHEL alternative
|
||||
"/etc/ssl/certs/ca-bundle.crt", // Some distros
|
||||
"/etc/ssl/cert.pem", // Alpine Linux
|
||||
"/usr/local/share/certs/ca-root-nss.crt", // FreeBSD
|
||||
"/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem", // CentOS/RHEL 7+
|
||||
"/etc/ca-certificates/extracted/tls-ca-bundle.pem" // Arch Linux
|
||||
};
|
||||
|
||||
for (const auto& path : ca_paths) {
|
||||
std::ifstream file(path);
|
||||
if (file.good()) {
|
||||
file.close();
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
HttpResponse http_get(const std::string& url, const std::string& path, bool use_https, double timeout_seconds) {
|
||||
HttpResponse result{0, "", false};
|
||||
bool done = false;
|
||||
std::mutex mtx;
|
||||
std::condition_variable cv;
|
||||
|
||||
std::thread worker([&]() {
|
||||
trantor::EventLoop loop;
|
||||
|
||||
auto client = drogon::HttpClient::newHttpClient(
|
||||
(use_https ? "https://" : "http://") + url,
|
||||
&loop
|
||||
);
|
||||
|
||||
// Configure SSL certificates for HTTPS
|
||||
if (use_https) {
|
||||
std::string ca_path = find_ca_certificates();
|
||||
if (!ca_path.empty()) {
|
||||
std::cerr << "Debug: Found CA certificates at: " << ca_path << std::endl;
|
||||
// Use addSSLConfigs with proper parameter names for OpenSSL
|
||||
std::vector<std::pair<std::string, std::string>> sslConfigs;
|
||||
sslConfigs.push_back({"VerifyCAFile", ca_path});
|
||||
client->addSSLConfigs(sslConfigs);
|
||||
} else {
|
||||
// If no CA certificates found, print warning but continue
|
||||
std::cerr << "Warning: No system CA certificates found. SSL verification may fail." << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
auto req = drogon::HttpRequest::newHttpRequest();
|
||||
req->setMethod(drogon::Get);
|
||||
req->setPath(path);
|
||||
|
||||
client->sendRequest(req, [&](drogon::ReqResult res, const drogon::HttpResponsePtr &resp) {
|
||||
std::lock_guard<std::mutex> lock(mtx);
|
||||
if (res == drogon::ReqResult::Ok && resp) {
|
||||
result.status_code = resp->statusCode();
|
||||
result.body = resp->body();
|
||||
result.success = true;
|
||||
} else {
|
||||
result.status_code = 0;
|
||||
result.body = "";
|
||||
result.success = false;
|
||||
}
|
||||
done = true;
|
||||
cv.notify_one();
|
||||
loop.quit();
|
||||
}, timeout_seconds);
|
||||
|
||||
loop.loop();
|
||||
});
|
||||
|
||||
// Wait for completion
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mtx);
|
||||
cv.wait(lock, [&] { return done; });
|
||||
}
|
||||
|
||||
worker.join();
|
||||
return result;
|
||||
}
|
||||
|
||||
HttpResponse http_get_with_ssl(const std::string& url, const std::string& path, const HttpClientSSLConfig& ssl_config, double timeout_seconds) {
|
||||
HttpResponse result{0, "", false};
|
||||
bool done = false;
|
||||
std::mutex mtx;
|
||||
std::condition_variable cv;
|
||||
|
||||
std::thread worker([&]() {
|
||||
trantor::EventLoop loop;
|
||||
|
||||
// Create HTTPS client with SSL configuration options
|
||||
auto client = drogon::HttpClient::newHttpClient(
|
||||
"https://" + url,
|
||||
&loop,
|
||||
ssl_config.use_old_tls,
|
||||
ssl_config.validate_cert
|
||||
);
|
||||
|
||||
// Configure client certificate if provided
|
||||
if (!ssl_config.cert_path.empty() && !ssl_config.key_path.empty()) {
|
||||
client->setCertPath(ssl_config.cert_path, ssl_config.key_path);
|
||||
}
|
||||
|
||||
// Configure SSL settings
|
||||
std::vector<std::pair<std::string, std::string>> finalSslConfigs = ssl_config.ssl_configs;
|
||||
|
||||
// Set CA certificates path if not explicitly disabled
|
||||
if (ssl_config.validate_cert) {
|
||||
// Check if cafile is provided in ssl_configs
|
||||
bool ca_path_set = false;
|
||||
for (const auto& config : ssl_config.ssl_configs) {
|
||||
if (config.first == "cafile" || config.first == "CAfile" ||
|
||||
config.first == "VerifyCAFile") {
|
||||
ca_path_set = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// If no cafile provided, use system certificates
|
||||
if (!ca_path_set) {
|
||||
std::string ca_path = find_ca_certificates();
|
||||
if (!ca_path.empty()) {
|
||||
finalSslConfigs.push_back({"VerifyCAFile", ca_path});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add all SSL configurations at once
|
||||
if (!finalSslConfigs.empty()) {
|
||||
client->addSSLConfigs(finalSslConfigs);
|
||||
}
|
||||
|
||||
auto req = drogon::HttpRequest::newHttpRequest();
|
||||
req->setMethod(drogon::Get);
|
||||
req->setPath(path);
|
||||
|
||||
client->sendRequest(req, [&](drogon::ReqResult res, const drogon::HttpResponsePtr &resp) {
|
||||
std::lock_guard<std::mutex> lock(mtx);
|
||||
if (res == drogon::ReqResult::Ok && resp) {
|
||||
result.status_code = resp->statusCode();
|
||||
result.body = resp->body();
|
||||
result.success = true;
|
||||
} else {
|
||||
result.status_code = 0;
|
||||
result.body = "";
|
||||
result.success = false;
|
||||
}
|
||||
done = true;
|
||||
cv.notify_one();
|
||||
loop.quit();
|
||||
}, timeout_seconds);
|
||||
|
||||
loop.loop();
|
||||
});
|
||||
|
||||
// Wait for completion
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mtx);
|
||||
cv.wait(lock, [&] { return done; });
|
||||
}
|
||||
|
||||
worker.join();
|
||||
return result;
|
||||
}
|
29
tests/ipdemo/src/http_utils.hpp
Normal file
29
tests/ipdemo/src/http_utils.hpp
Normal file
@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include <drogon/HttpClient.h>
|
||||
#include <trantor/net/EventLoop.h>
|
||||
|
||||
struct HttpResponse {
|
||||
int status_code;
|
||||
std::string body;
|
||||
bool success;
|
||||
};
|
||||
|
||||
// SSL configuration options for HTTP client
|
||||
struct HttpClientSSLConfig {
|
||||
std::string cert_path; // Client certificate path
|
||||
std::string key_path; // Client key path
|
||||
bool validate_cert = true; // Whether to validate server certificate
|
||||
bool use_old_tls = false; // Enable TLS 1.0/1.1
|
||||
std::vector<std::pair<std::string, std::string>> ssl_configs; // Additional SSL_CONF_cmd options
|
||||
};
|
||||
|
||||
// Utility function for blocking HTTP GET requests
|
||||
HttpResponse http_get(const std::string& url, const std::string& path, bool use_https = false, double timeout_seconds = 10.0);
|
||||
|
||||
// Utility function for blocking HTTP GET requests with SSL configuration
|
||||
HttpResponse http_get_with_ssl(const std::string& url, const std::string& path, const HttpClientSSLConfig& ssl_config, double timeout_seconds = 10.0);
|
10509
tests/ipdemo/src/httplib.hpp
Normal file
10509
tests/ipdemo/src/httplib.hpp
Normal file
File diff suppressed because it is too large
Load Diff
33
tests/ipdemo/src/main.cpp
Normal file
33
tests/ipdemo/src/main.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include "version.hpp"
|
||||
#include "assert.hpp"
|
||||
#include "http_utils.hpp"
|
||||
|
||||
void crashy() {
|
||||
ASSERT(false, "SUCCESS!");
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::cout << "ipdemo version: " << ipdemo::VERSION << std::endl;
|
||||
std::cout << std::endl;
|
||||
std::cout << "Retrieving IP address..." << std::endl;
|
||||
|
||||
// Use the utility function for HTTP GET
|
||||
auto response = http_get("ipinfo.io", "/ip", true, 10.0);
|
||||
|
||||
ASSERT(response.success && response.status_code == 200, "Failed to get IP");
|
||||
|
||||
nlohmann::json j;
|
||||
j["ip"] = response.body;
|
||||
j["status"] = response.status_code;
|
||||
|
||||
std::cout << j.dump(4) << std::endl;
|
||||
|
||||
std::cout << "Done" << std::endl;
|
||||
|
||||
crashy();
|
||||
|
||||
return 0;
|
||||
}
|
21
tests/ipdemo/src/version.hpp.in
Normal file
21
tests/ipdemo/src/version.hpp.in
Normal file
@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
|
||||
version.hpp is automatically generated by the build system, from version.hpp.in.
|
||||
|
||||
DO NOT EDIT VERSION.HPP!
|
||||
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace ipdemo {
|
||||
|
||||
// Version information
|
||||
const std::string VERSION = "@PROJECT_VERSION@";
|
||||
const std::string RELEASE_DATE = "@RELEASE_DATE@";
|
||||
const std::string AUTHOR = "j842";
|
||||
const std::string LICENSE = "MIT";
|
||||
|
||||
} // namespace dropshell
|
Reference in New Issue
Block a user