Skip to content

Commit 5573871

Browse files
committed
Updated Remote module
1 parent 306948b commit 5573871

File tree

3 files changed

+50
-17
lines changed

3 files changed

+50
-17
lines changed

VCMP-LUA/Core.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,6 @@ extern "C" EXPORT unsigned int VcmpPluginInit(PluginFuncs * pluginFuncs, PluginC
6262
Lua.open_libraries();
6363
Lua.set_exception_handler(&my_exception_handler);
6464

65-
RegisterClasses(&Lua);
66-
RegisterVCMPCallbacks();
67-
6865
bool experimental_mode = false;
6966

7067
// Load Configuration
@@ -91,7 +88,16 @@ extern "C" EXPORT unsigned int VcmpPluginInit(PluginFuncs * pluginFuncs, PluginC
9188
}
9289
else spdlog::warn("No configuration settings supplied, using defaults");
9390
}
94-
91+
92+
if (experimental_mode) {
93+
Lua["__experimental__"] = true;
94+
spdlog::warn("Experimental features may be really unstable, be very careful when using them.");
95+
Lua["__reload_scripts"] = &reload_scripts;
96+
}
97+
98+
RegisterClasses(&Lua);
99+
RegisterVCMPCallbacks();
100+
95101
// Load Scripts
96102
{
97103
std::list<CSimpleIniA::Entry> scripts;
@@ -108,12 +114,6 @@ extern "C" EXPORT unsigned int VcmpPluginInit(PluginFuncs * pluginFuncs, PluginC
108114
else spdlog::error("No Lua scripts specified to load");
109115
}
110116

111-
if (experimental_mode) {
112-
Lua["__experimental__"] = true;
113-
spdlog::warn("Experimental features may be really unstable, be very careful when using them.");
114-
Lua["__reload_scripts"] = &reload_scripts;
115-
}
116-
117117
return 1;
118118
}
119119

VCMP-LUA/vcmpWrap/Modules/CPR/Remote.cpp

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,29 @@
33
extern sol::state Lua;
44

55
std::vector<RemoteRequest> Remote::s_Container = {};
6+
std::string Remote::certificates = "";
7+
8+
bool Remote::setSSLCerts(const std::string& bundle)
9+
{
10+
certificates.assign(bundle);
11+
return true;
12+
}
613

714
/*** Lua ***/
815
sol::table Remote::fetchHTTP(const std::string& url, sol::table params, sol::table auth)
916
{
1017
cpr::Parameters cprParams = GetParameters(params);
1118
cpr::Authentication cprAuth = GetAuthentication(auth);
1219

20+
cpr::ssl::CaInfo Certs(certificates.c_str());
21+
cpr::SslOptions opts;
22+
opts.SetOption(Certs);
23+
1324
cpr::Response r = cpr::Get(
1425
cpr::Url(url),
1526
cprParams,
16-
cprAuth
27+
cprAuth,
28+
opts
1729
);
1830

1931
sol::table resultTable = Lua.create_table();
@@ -27,9 +39,13 @@ sol::table Remote::fetchHTTP(const std::string& url, sol::table params, sol::tab
2739

2840
void Remote::fetchHTTPAsync(sol::function handler, const std::string& url, sol::table params, sol::table auth)
2941
{
42+
cpr::ssl::CaInfo Certs(certificates.c_str());
43+
cpr::SslOptions opts;
44+
opts.SetOption(Certs);
45+
3046
cpr::Parameters cprParams = GetParameters(params);
3147
cpr::Authentication cprAuth = GetAuthentication(auth);
32-
s_Container.emplace_back(handler, RemoteRequestType::GET, url, cprParams, cpr::Header{}, cpr::Body(""), cpr::Payload{}, cprAuth);
48+
s_Container.emplace_back(handler, RemoteRequestType::GET, url, cprParams, cpr::Header{}, cpr::Body(""), cpr::Payload{}, cprAuth, opts);
3349
}
3450

3551
sol::table Remote::postHTTP(const std::string& url, sol::table data)
@@ -65,12 +81,17 @@ sol::table Remote::postHTTP(const std::string& url, sol::table data)
6581
}
6682
}
6783

84+
cpr::ssl::CaInfo Certs(certificates.c_str());
85+
cpr::SslOptions opts;
86+
opts.SetOption(Certs);
87+
6888
cpr::Response r = cpr::Post(
6989
cpr::Url(url),
7090
cprHeader,
7191
cprBody,
7292
cprParams,
73-
cprPayload
93+
cprPayload,
94+
opts
7495
);
7596

7697
sol::table resultTable = Lua.create_table();
@@ -115,7 +136,11 @@ void Remote::postHTTPAsync(sol::function handler, const std::string& url, sol::t
115136
}
116137
}
117138

118-
s_Container.emplace_back(handler, RemoteRequestType::POST, url, cprParams, cprHeader, cprBody, cprPayload, cpr::Authentication("", ""));
139+
cpr::ssl::CaInfo Certs(certificates.c_str());
140+
cpr::SslOptions opts;
141+
opts.SetOption(Certs);
142+
143+
s_Container.emplace_back(handler, RemoteRequestType::POST, url, cprParams, cprHeader, cprBody, cprPayload, cpr::Authentication("", ""), opts);
119144
}
120145

121146
/*** Internal ***/
@@ -125,6 +150,7 @@ void Remote::Init(sol::state* Lua)
125150

126151
sol::usertype<Remote> userdata = Lua->new_usertype<Remote>("Remote");
127152

153+
userdata["setSSLCerts"] = &Remote::setSSLCerts;
128154
userdata["fetch"] = sol::overload(&Remote::fetchHTTP, &Remote::fetchHTTPAsync);
129155
userdata["post"] = sol::overload(&Remote::postHTTP, &Remote::postHTTPAsync);
130156
}

VCMP-LUA/vcmpWrap/Modules/CPR/Remote.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,25 @@ struct RemoteRequest
1818
cpr::Header cprHeader,
1919
cpr::Body cprBody,
2020
cpr::Payload cprPayload,
21-
cpr::Authentication cprAuth
21+
cpr::Authentication cprAuth,
22+
cpr::SslOptions opts
2223
)
2324
: handler(luaHandler)
2425
{
2526
if (requestType == RemoteRequestType::GET)
2627
future = cpr::GetAsync(cpr::Url(url),
2728
cprParams,
28-
cprAuth
29+
cprAuth,
30+
opts
2931
);
3032
else if (requestType == RemoteRequestType::POST)
3133
future = cpr::PostAsync(cpr::Url(url),
3234
cprParams,
3335
cprHeader,
3436
cprBody,
3537
cprPayload,
36-
cprAuth
38+
cprAuth,
39+
opts
3740
);
3841
}
3942

@@ -54,6 +57,10 @@ class Remote
5457
static cpr::Authentication GetAuthentication(sol::table& auth);
5558

5659
/*** Lua ***/
60+
static std::string certificates;
61+
62+
static bool setSSLCerts(const std::string& bundle);
63+
5764
static sol::table fetchHTTP(const std::string& url, sol::table params, sol::table auth);
5865
static void fetchHTTPAsync(sol::function handler, const std::string& url, sol::table params, sol::table auth);
5966

0 commit comments

Comments
 (0)