Skip to content

Commit 8815bca

Browse files
committed
fix(http): Event Call
1 parent 65007b1 commit 8815bca

File tree

3 files changed

+78
-15
lines changed

3 files changed

+78
-15
lines changed

.editorconfig

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
[*]
2+
cpp_indent_braces=false
3+
cpp_indent_multi_line_relative_to=innermost_parenthesis
4+
cpp_indent_within_parentheses=indent
5+
cpp_indent_preserve_within_parentheses=false
6+
cpp_indent_case_labels=false
7+
cpp_indent_case_contents=true
8+
cpp_indent_case_contents_when_block=false
9+
cpp_indent_lambda_braces_when_parameter=true
10+
cpp_indent_goto_labels=one_left
11+
cpp_indent_preprocessor=leftmost_column
12+
cpp_indent_access_specifiers=false
13+
cpp_indent_namespace_contents=true
14+
cpp_indent_preserve_comments=false
15+
cpp_new_line_before_open_brace_namespace=ignore
16+
cpp_new_line_before_open_brace_type=ignore
17+
cpp_new_line_before_open_brace_function=ignore
18+
cpp_new_line_before_open_brace_block=ignore
19+
cpp_new_line_before_open_brace_lambda=ignore
20+
cpp_new_line_scope_braces_on_separate_lines=false
21+
cpp_new_line_close_brace_same_line_empty_type=false
22+
cpp_new_line_close_brace_same_line_empty_function=false
23+
cpp_new_line_before_catch=true
24+
cpp_new_line_before_else=true
25+
cpp_new_line_before_while_in_do_while=false
26+
cpp_space_before_function_open_parenthesis=remove
27+
cpp_space_within_parameter_list_parentheses=false
28+
cpp_space_between_empty_parameter_list_parentheses=false
29+
cpp_space_after_keywords_in_control_flow_statements=true
30+
cpp_space_within_control_flow_statement_parentheses=false
31+
cpp_space_before_lambda_open_parenthesis=false
32+
cpp_space_within_cast_parentheses=false
33+
cpp_space_after_cast_close_parenthesis=false
34+
cpp_space_within_expression_parentheses=false
35+
cpp_space_before_block_open_brace=true
36+
cpp_space_between_empty_braces=false
37+
cpp_space_before_initializer_list_open_brace=false
38+
cpp_space_within_initializer_list_braces=true
39+
cpp_space_preserve_in_initializer_list=true
40+
cpp_space_before_open_square_bracket=false
41+
cpp_space_within_square_brackets=false
42+
cpp_space_before_empty_square_brackets=false
43+
cpp_space_between_empty_square_brackets=false
44+
cpp_space_group_square_brackets=true
45+
cpp_space_within_lambda_brackets=false
46+
cpp_space_between_empty_lambda_brackets=false
47+
cpp_space_before_comma=false
48+
cpp_space_after_comma=true
49+
cpp_space_remove_around_member_operators=true
50+
cpp_space_before_inheritance_colon=true
51+
cpp_space_before_constructor_colon=true
52+
cpp_space_remove_before_semicolon=true
53+
cpp_space_after_semicolon=false
54+
cpp_space_remove_around_unary_operator=true
55+
cpp_space_around_binary_operator=insert
56+
cpp_space_around_assignment_operator=insert
57+
cpp_space_pointer_reference_alignment=left
58+
cpp_space_around_ternary_operator=insert
59+
cpp_wrap_preserve_blocks=one_liners

.vscode/c_cpp_properties.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
],
7070
"cStandard": "c17",
7171
"cppStandard": "c++17",
72-
"intelliSenseMode": "linux-gcc-x64"
72+
"intelliSenseMode": "linux-gcc-x64",
7373
}
7474
],
7575
"version": 4

src/plugins/core/scripting/http.cpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ extern "C"
2020
#undef GetObject
2121
#endif
2222

23-
static size_t WriteCallback(void *contents, size_t size, size_t nmemb, std::vector<std::string> *userp)
23+
static size_t WriteCallback(void* contents, size_t size, size_t nmemb, std::vector<std::string>* userp)
2424
{
2525
size_t totalSize = size * nmemb;
26-
userp->emplace_back((char *)contents, totalSize);
26+
userp->emplace_back((char*)contents, totalSize);
2727
return totalSize;
2828
}
2929

30-
static size_t HeaderCallback(char *buffer, size_t size, size_t nitems, std::vector<std::string> *headers)
30+
static size_t HeaderCallback(char* buffer, size_t size, size_t nitems, std::vector<std::string>* headers)
3131
{
3232
size_t totalSize = size * nitems;
3333
headers->emplace_back(buffer, totalSize);
@@ -50,8 +50,8 @@ void RunCurlRequest(std::string url, std::string data, std::map<std::string, std
5050
{
5151
std::vector<std::string> responseBody;
5252
std::vector<std::string> responseHeaders;
53-
curl_mime *mime = nullptr;
54-
CURL *curlRequest = curl_easy_init();
53+
curl_mime* mime = nullptr;
54+
CURL* curlRequest = curl_easy_init();
5555
if (!curlRequest)
5656
return;
5757

@@ -64,17 +64,17 @@ void RunCurlRequest(std::string url, std::string data, std::map<std::string, std
6464
if (headers.find("User-Agent") != headers.end())
6565
curl_easy_setopt(curlRequest, CURLOPT_USERAGENT, headers.at("User-Agent").c_str());
6666

67-
struct curl_slist *headersList = nullptr;
67+
struct curl_slist* headersList = nullptr;
6868
for (auto it = headers.begin(); it != headers.end(); ++it)
6969
headersList = curl_slist_append(headersList, (string_format("%s: %s", it->first.c_str(), it->second.c_str()) + "\0").c_str());
7070

7171
if (files.size() > 0)
7272
{
7373
mime = curl_mime_init(curlRequest);
7474

75-
for (auto &file : files)
75+
for (auto& file : files)
7676
{
77-
curl_mimepart *part = curl_mime_addpart(mime);
77+
curl_mimepart* part = curl_mime_addpart(mime);
7878
curl_mime_name(part, file.first.c_str());
7979
curl_mime_filedata(part, file.second.c_str());
8080
}
@@ -132,10 +132,14 @@ void RunCurlRequest(std::string url, std::string data, std::map<std::string, std
132132

133133
msgpack::pack(ss, eventData);
134134

135-
PluginEvent *event = new PluginEvent("core", nullptr, nullptr);
136-
g_pluginManager->ExecuteEvent("core", "OnHTTPActionPerformed", ss.str(), event);
135+
std::string eventPayload = ss.str();
136+
137+
g_Plugin.NextFrame([&]() -> void {
138+
PluginEvent* event = new PluginEvent("core", nullptr, nullptr);
139+
g_pluginManager->ExecuteEvent("core", "OnHTTPActionPerformed", eventPayload, event);
140+
delete event;
141+
});
137142

138-
delete event;
139143

140144
if (headersList)
141145
curl_slist_free_all(headersList);
@@ -195,7 +199,7 @@ std::string PluginHTTP::PerformHTTP(std::string receivedData)
195199

196200
std::string headerValue = headerIt->value.GetString();
197201

198-
headers.insert({headerName, headerValue});
202+
headers.insert({ headerName, headerValue });
199203
}
200204
}
201205
}
@@ -214,14 +218,14 @@ std::string PluginHTTP::PerformHTTP(std::string receivedData)
214218
if (!Files::ExistsPath(fileValue))
215219
continue;
216220

217-
files.insert({fileName, fileValue});
221+
files.insert({ fileName, fileValue });
218222
}
219223
}
220224
}
221225

222226
std::string requestUUID = get_uuid();
223227

224-
Request req = {url, data, headers, files, method, requestUUID};
228+
Request req = { url, data, headers, files, method, requestUUID };
225229
requestsQueue.push_back(req);
226230

227231
if (!httpThread)

0 commit comments

Comments
 (0)