mirror of
https://github.com/Expand-sys/CCash
synced 2026-03-22 12:37:08 +11:00
🔨 made str_intrusion.h into a wrapper
This commit is contained in:
parent
1d6bbb35bf
commit
dc6c3d70a0
3 changed files with 38 additions and 43 deletions
|
|
@ -1,5 +1,9 @@
|
|||
#pragma once
|
||||
#include <string>
|
||||
|
||||
void string_view_to_string(std::string &str, std::string_view sv);
|
||||
void destroy_string(std::string &str);
|
||||
struct StrFromSV_Wrapper
|
||||
{
|
||||
std::string str;
|
||||
StrFromSV_Wrapper(std::string_view sv);
|
||||
~StrFromSV_Wrapper();
|
||||
};
|
||||
|
|
@ -16,12 +16,12 @@ static thread_local ondemand::parser parser;
|
|||
static thread_local ondemand::document doc = parser.iterate(input)
|
||||
|
||||
#define RESPONSE_PARSE(R) \
|
||||
static thread_local const auto resp = HttpResponse::newCustomHttpResponse(R); \
|
||||
static thread_local const auto &resp = HttpResponse::newCustomHttpResponse(R); \
|
||||
CORS; \
|
||||
callback(resp)
|
||||
|
||||
#define RESPOND_TRUE \
|
||||
static thread_local const auto resp = HttpResponse::newCustomHttpResponse(BankResponse(k200OK, "true")); \
|
||||
static thread_local const auto &resp = HttpResponse::newCustomHttpResponse(BankResponse(k200OK, "true")); \
|
||||
CORS; \
|
||||
CACHE_FOREVER; \
|
||||
callback(resp)
|
||||
|
|
@ -47,7 +47,7 @@ void api::GetLogs(req_args)
|
|||
}
|
||||
else
|
||||
{
|
||||
static thread_local const auto resp = HttpResponse::newCustomHttpResponse(BankResponse(k404NotFound, "\"Logs are Disabled\""));
|
||||
static thread_local const auto &resp = HttpResponse::newCustomHttpResponse(BankResponse(k404NotFound, "\"Logs are Disabled\""));
|
||||
CORS;
|
||||
CACHE_FOREVER;
|
||||
callback(resp);
|
||||
|
|
@ -65,9 +65,8 @@ void api::SendFunds(req_args) const
|
|||
}
|
||||
else
|
||||
{
|
||||
static thread_local std::string name_val;
|
||||
string_view_to_string(name_val, name.value());
|
||||
res = bank.SendFunds(NAME_PARAM, name_val, amount.value());
|
||||
static thread_local StrFromSV_Wrapper name_val(name.value());
|
||||
res = bank.SendFunds(NAME_PARAM, name_val.str, amount.value());
|
||||
}
|
||||
RESPONSE_PARSE(std::move(res));
|
||||
}
|
||||
|
|
@ -78,17 +77,15 @@ void api::ChangePassword(req_args) const
|
|||
{
|
||||
SIMD_JSON_GEN;
|
||||
static thread_local auto pass = doc.find_field("pass").get_string();
|
||||
static thread_local auto amount = doc.find_field("amount").get_uint64();
|
||||
BankResponse res;
|
||||
if (pass.error() || amount.error())
|
||||
if (pass.error())
|
||||
{
|
||||
res = BankResponse(k400BadRequest, "Invalid JSON");
|
||||
}
|
||||
else
|
||||
{
|
||||
static thread_local std::string pass_val;
|
||||
string_view_to_string(pass_val, pass.value());
|
||||
bank.ChangePassword(NAME_PARAM, std::move(pass_val));
|
||||
static thread_local StrFromSV_Wrapper pass_val(pass.value());
|
||||
bank.ChangePassword(NAME_PARAM, std::move(pass_val.str));
|
||||
}
|
||||
RESPOND_TRUE;
|
||||
}
|
||||
|
|
@ -104,10 +101,9 @@ void api::AdminChangePassword(req_args) const
|
|||
}
|
||||
else
|
||||
{
|
||||
static thread_local std::string name_val, pass_val;
|
||||
string_view_to_string(name_val, name.value());
|
||||
string_view_to_string(pass_val, pass.value());
|
||||
bank.ChangePassword(name_val, std::move(pass_val));
|
||||
static thread_local StrFromSV_Wrapper name_val(name.value());
|
||||
static thread_local StrFromSV_Wrapper pass_val(pass.value());
|
||||
bank.ChangePassword(name_val.str, std::move(pass_val.str));
|
||||
}
|
||||
RESPOND_TRUE;
|
||||
}
|
||||
|
|
@ -123,9 +119,8 @@ void api::SetBal(req_args) const
|
|||
}
|
||||
else
|
||||
{
|
||||
static thread_local std::string name_val;
|
||||
string_view_to_string(name_val, name.value());
|
||||
res = bank.SetBal(name_val, amount.value());
|
||||
static thread_local StrFromSV_Wrapper name_val(name.value());
|
||||
res = bank.SetBal(name_val.str, amount.value());
|
||||
}
|
||||
RESPONSE_PARSE(std::move(res));
|
||||
}
|
||||
|
|
@ -141,9 +136,8 @@ void api::ImpactBal(req_args) const
|
|||
}
|
||||
else
|
||||
{
|
||||
static thread_local std::string name_val;
|
||||
string_view_to_string(name_val, name.value());
|
||||
res = bank.ImpactBal(name_val, amount.value());
|
||||
static thread_local StrFromSV_Wrapper name_val(name.value());
|
||||
res = bank.ImpactBal(name_val.str, amount.value());
|
||||
}
|
||||
RESPONSE_PARSE(std::move(res));
|
||||
}
|
||||
|
|
@ -151,7 +145,7 @@ void api::ImpactBal(req_args) const
|
|||
//System Usage
|
||||
void api::Help(req_args) const
|
||||
{
|
||||
static thread_local const auto resp = HttpResponse::newRedirectionResponse("https://github.com/EntireTwix/CCash/blob/Refractor/README.md");
|
||||
static thread_local const auto &resp = HttpResponse::newRedirectionResponse("https://github.com/EntireTwix/CCash/blob/Refractor/README.md");
|
||||
CACHE_FOREVER;
|
||||
callback(resp);
|
||||
}
|
||||
|
|
@ -200,10 +194,9 @@ void api::AddUser(req_args) const
|
|||
}
|
||||
else
|
||||
{
|
||||
static thread_local std::string name_val, pass_val;
|
||||
string_view_to_string(name_val, name.value());
|
||||
string_view_to_string(pass_val, pass.value());
|
||||
res = bank.AddUser(std::move(name_val), 0, std::move(pass_val));
|
||||
StrFromSV_Wrapper name_val(name.value());
|
||||
StrFromSV_Wrapper pass_val(pass.value());
|
||||
res = bank.AddUser(std::move(name_val.str), 0, std::move(pass_val.str));
|
||||
}
|
||||
RESPONSE_PARSE(std::move(res));
|
||||
}
|
||||
|
|
@ -220,10 +213,9 @@ void api::AdminAddUser(req_args) const
|
|||
}
|
||||
else
|
||||
{
|
||||
static thread_local std::string name_val, pass_val;
|
||||
string_view_to_string(name_val, name.value());
|
||||
string_view_to_string(pass_val, pass.value());
|
||||
res = bank.AddUser(std::move(name_val), amount.value(), std::move(pass_val));
|
||||
static thread_local StrFromSV_Wrapper name_val(name.value());
|
||||
static thread_local StrFromSV_Wrapper pass_val(pass.value());
|
||||
res = bank.AddUser(std::move(name_val.str), amount.value(), std::move(pass_val.str));
|
||||
}
|
||||
RESPONSE_PARSE(std::move(res));
|
||||
}
|
||||
|
|
@ -242,9 +234,8 @@ void api::AdminDelUser(req_args) const
|
|||
}
|
||||
else
|
||||
{
|
||||
static thread_local std::string name_val;
|
||||
string_view_to_string(name_val, name.value());
|
||||
res = bank.DelUser(name_val);
|
||||
static thread_local StrFromSV_Wrapper name_val(name.value());
|
||||
res = bank.DelUser(name_val.str);
|
||||
}
|
||||
RESPONSE_PARSE(std::move(res));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,13 +31,13 @@ struct string_data
|
|||
typedef void (std::string::*type)(char *);
|
||||
};
|
||||
template class rob<string_data, &std::string::_M_data>;
|
||||
void string_view_to_string(std::string &str, std::string_view sv)
|
||||
|
||||
StrFromSV_Wrapper::StrFromSV_Wrapper(std::string_view sv)
|
||||
{
|
||||
(str.*result<string_data>::ptr)((char *)sv.data());
|
||||
(str.*result<string_length>::ptr)(sv.size());
|
||||
}
|
||||
//may be used later
|
||||
void destroy_string(std::string &str)
|
||||
StrFromSV_Wrapper::~StrFromSV_Wrapper()
|
||||
{
|
||||
(str.*result<string_data>::ptr)(nullptr);
|
||||
(str.*result<string_length>::ptr)(0);
|
||||
|
|
|
|||
Loading…
Reference in a new issue