From 5686bc864d6158f23d138d5576d5ad5cf637c7ce Mon Sep 17 00:00:00 2001 From: simon987 Date: Wed, 13 May 2020 17:37:40 -0400 Subject: [PATCH] wip --- .gitmodules | 3 +++ CMakeLists.txt | 10 +++++----- src/index/web.c | 17 +++++++++++++---- src/index/web.h | 2 +- third-party/mongoose | 1 + 5 files changed, 23 insertions(+), 10 deletions(-) create mode 160000 third-party/mongoose diff --git a/.gitmodules b/.gitmodules index 1b29252..efa1f71 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "third-party/argparse"] path = third-party/argparse url = https://github.com/cofyc/argparse +[submodule "third-party/mongoose"] + path = third-party/mongoose + url = https://github.com/cesanta/mongoose/ diff --git a/CMakeLists.txt b/CMakeLists.txt index ae2d9f2..5cce9c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,20 +28,22 @@ add_executable( # argparse third-party/argparse/argparse.h third-party/argparse/argparse.c + third-party/mongoose/mongoose.h third-party/mongoose/mongoose.c src/cli.c src/cli.h ) +target_compile_definitions(sist2 PUBLIC MG_ENABLE_SSL=1) + target_link_directories(sist2 PRIVATE BEFORE ${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/) set(CMAKE_FIND_LIBRARY_SUFFIXES .a .lib) find_package(lmdb CONFIG REQUIRED) find_package(cJSON CONFIG REQUIRED) find_package(unofficial-glib CONFIG REQUIRED) -find_package(unofficial-mongoose CONFIG REQUIRED) find_library(UUID_LIB NAMES uuid) -#find_package(OpenSSL REQUIRED) +find_package(OpenSSL REQUIRED) target_include_directories( @@ -72,7 +74,6 @@ if (SIST_DEBUG) sist2 PRIVATE -fsanitize=address -# -static ) set_target_properties( sist2 @@ -103,8 +104,7 @@ target_link_libraries( cjson argparse unofficial::glib::glib - unofficial::mongoose::mongoose -# OpenSSL::SSL OpenSSL::Crypto + OpenSSL::SSL OpenSSL::Crypto ${UUID_LIB} pthread diff --git a/src/index/web.c b/src/index/web.c index 8eaa16a..a776586 100644 --- a/src/index/web.c +++ b/src/index/web.c @@ -2,9 +2,6 @@ #include "src/sist.h" #include "src/ctx.h" -#include -#include - void free_response(response_t *resp) { if (resp->body != NULL) { @@ -77,7 +74,19 @@ subreq_ctx_t *http_req(const char *url, const char *extra_headers, const char *p char address[8196]; snprintf(address, sizeof(address), "tcp://%.*s:%u", (int) host.len, host.p, port); - struct mg_connection *nc = mg_connect(&ctx->mgr, address, http_req_ev); + struct mg_connect_opts opts; + memset(&opts, 0, sizeof(opts)); + opts.ssl_key = "./a.key"; + opts.ssl_cert = "./cert.crt"; + opts.ssl_ca_cert = "*"; + opts.ssl_server_name = "dev2.simon987.net:443"; + const char* tmp[256]; + opts.error_string = tmp; + + struct mg_connection *nc = mg_connect_opt(&ctx->mgr, address, http_req_ev, opts); + printf("%d\n", nc->err); + + nc->user_data = &ctx->ev_data; mg_set_protocol_http_websocket(nc); diff --git a/src/index/web.h b/src/index/web.h index be525ac..4045090 100644 --- a/src/index/web.h +++ b/src/index/web.h @@ -2,7 +2,7 @@ #define SIST2_WEB_H #include "src/sist.h" -#include +#include "third-party/mongoose/mongoose.h" typedef struct response { char *body; diff --git a/third-party/mongoose b/third-party/mongoose new file mode 160000 index 0000000..359060a --- /dev/null +++ b/third-party/mongoose @@ -0,0 +1 @@ +Subproject commit 359060a151998c5ab08e54af1420b7406005dc6b