Committing updates.
This commit is contained in:
@@ -343,12 +343,12 @@ namespace Apostol {
|
||||
auto OnDone = [this, &Context, &Provider](CTCPConnection *Sender) {
|
||||
|
||||
auto pConnection = dynamic_cast<CHTTPClientConnection *> (Sender);
|
||||
auto pReply = pConnection->Reply();
|
||||
const auto &Reply = pConnection->Reply();
|
||||
|
||||
DebugReply(pReply);
|
||||
DebugReply(Reply);
|
||||
|
||||
if (pReply->Status == CHTTPReply::ok) {
|
||||
const CJSON Json(pReply->Content);
|
||||
if (Reply.Status == CHTTPReply::ok) {
|
||||
const CJSON Json(Reply.Content);
|
||||
|
||||
Context.Session() = Json["session"].AsString();
|
||||
Context.Secret() = Json["secret"].AsString();
|
||||
@@ -405,12 +405,12 @@ namespace Apostol {
|
||||
auto OnDone = [this, &Context, &Provider](CTCPConnection *Sender) {
|
||||
|
||||
auto pConnection = dynamic_cast<CHTTPClientConnection *> (Sender);
|
||||
auto pReply = pConnection->Reply();
|
||||
const auto &Reply = pConnection->Reply();
|
||||
|
||||
DebugReply(pReply);
|
||||
DebugReply(Reply);
|
||||
|
||||
if (pReply->Status == CHTTPReply::ok) {
|
||||
const CJSON Json(pReply->Content);
|
||||
if (Reply.Status == CHTTPReply::ok) {
|
||||
const CJSON Json(Reply.Content);
|
||||
|
||||
Context.Session() = Json["session"].AsString();
|
||||
Context.Secret() = Json["secret"].AsString();
|
||||
@@ -546,22 +546,22 @@ namespace Apostol {
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------------------
|
||||
|
||||
CString CCustomModule::GetAddress(CHTTPRequest *ARequest) {
|
||||
CString CCustomModule::GetAddress(const CHTTPRequest &Request) {
|
||||
CString Result;
|
||||
|
||||
Result = ARequest->Params["address"];
|
||||
Result = Request.Params["address"];
|
||||
|
||||
if (Result.IsEmpty() && !ARequest->Content.IsEmpty()) {
|
||||
const auto &contentType = ARequest->Headers.Values(_T("content-type"));
|
||||
if (Result.IsEmpty() && !Request.Content.IsEmpty()) {
|
||||
const auto &contentType = Request.Headers.Values(_T("content-type"));
|
||||
if (contentType.Find("application/x-www-form-urlencoded") == 0) {
|
||||
const CStringList &FormData = ARequest->FormData;
|
||||
const CStringList &FormData = Request.FormData;
|
||||
Result = FormData["address"];
|
||||
} else if (contentType.Find("multipart/form-data") == 0) {
|
||||
CFormData FormData;
|
||||
CHTTPRequestParser::ParseFormData(ARequest, FormData);
|
||||
CHTTPRequestParser::ParseFormData(Request, FormData);
|
||||
Result = FormData.Data("address");
|
||||
} else if (contentType.Find("application/json") == 0) {
|
||||
const CJSON contextJson(ARequest->Content);
|
||||
const CJSON contextJson(Request.Content);
|
||||
Result = contextJson["address"].AsString();
|
||||
}
|
||||
}
|
||||
@@ -572,9 +572,9 @@ namespace Apostol {
|
||||
|
||||
void CCustomModule::DoGet(CHTTPServerConnection *AConnection) {
|
||||
|
||||
auto pRequest = AConnection->Request();
|
||||
const auto &caRequest = AConnection->Request();
|
||||
|
||||
CString sPath(pRequest->Location.pathname);
|
||||
CString sPath(caRequest.Location.pathname);
|
||||
|
||||
// Request sPath must be absolute and not contain "..".
|
||||
if (sPath.empty() || sPath.front() != '/' || sPath.find(_T("..")) != CString::npos) {
|
||||
@@ -597,13 +597,13 @@ namespace Apostol {
|
||||
|
||||
void CCustomModule::DoPost(CHTTPServerConnection *AConnection) {
|
||||
|
||||
auto pRequest = AConnection->Request();
|
||||
auto pReply = AConnection->Reply();
|
||||
const auto &caRequest = AConnection->Request();
|
||||
auto &Reply = AConnection->Reply();
|
||||
|
||||
pReply->ContentType = CHTTPReply::json;
|
||||
Reply.ContentType = CHTTPReply::json;
|
||||
|
||||
CStringList slRouts;
|
||||
SplitColumns(pRequest->Location.pathname, slRouts, '/');
|
||||
SplitColumns(caRequest.Location.pathname, slRouts, '/');
|
||||
|
||||
if (slRouts.Count() < 3) {
|
||||
AConnection->SendStockReply(CHTTPReply::not_found);
|
||||
@@ -649,13 +649,13 @@ namespace Apostol {
|
||||
|
||||
void CCustomModule::DoAPI(CHTTPServerConnection *AConnection) {
|
||||
|
||||
auto pRequest = AConnection->Request();
|
||||
auto pReply = AConnection->Reply();
|
||||
auto &Request = AConnection->Request();
|
||||
auto &Reply = AConnection->Reply();
|
||||
|
||||
pReply->ContentType = CHTTPReply::json;
|
||||
Reply.ContentType = CHTTPReply::json;
|
||||
|
||||
CStringList slRouts;
|
||||
SplitColumns(pRequest->Location.pathname, slRouts, '/');
|
||||
SplitColumns(Request.Location.pathname, slRouts, '/');
|
||||
|
||||
if (slRouts.Count() < 3) {
|
||||
AConnection->SendStockReply(CHTTPReply::not_found);
|
||||
@@ -690,31 +690,31 @@ namespace Apostol {
|
||||
|
||||
} else if (caCommand == "time") {
|
||||
|
||||
pReply->Content << "{\"serverTime\": " << ToString(MsEpoch()) << "}";
|
||||
Reply.Content << "{\"serverTime\": " << ToString(MsEpoch()) << "}";
|
||||
|
||||
AConnection->SendReply(CHTTPReply::ok);
|
||||
|
||||
} else if (caCommand == "help") {
|
||||
|
||||
pRequest->Content.Clear();
|
||||
Request.Content.Clear();
|
||||
|
||||
DoAccount(AConnection, "GET", sRoute);
|
||||
|
||||
} else if (caCommand == "account" && caAction == "status") {
|
||||
|
||||
pRequest->Content.Clear();
|
||||
Request.Content.Clear();
|
||||
|
||||
DoAccount(AConnection, "GET", sRoute);
|
||||
|
||||
} else if (caCommand == "deal" && caAction == "status") {
|
||||
|
||||
pRequest->Content.Clear();
|
||||
Request.Content.Clear();
|
||||
|
||||
DoDeal(AConnection, "GET", sRoute, caAction);
|
||||
|
||||
} else if (caCommand == "bc" && caAction == "history") {
|
||||
|
||||
const auto &caAccount = pRequest->Params["account"];
|
||||
const auto &caAccount = Request.Params["account"];
|
||||
|
||||
if (caAccount.IsEmpty()) {
|
||||
AConnection->SendStockReply(CHTTPReply::bad_request);
|
||||
@@ -727,9 +727,9 @@ namespace Apostol {
|
||||
CJSON history;
|
||||
fetch_history(address, history);
|
||||
|
||||
pReply->Content = history.ToString();
|
||||
Reply.Content = history.ToString();
|
||||
} catch (Delphi::Exception::Exception &E) {
|
||||
ExceptionToJson(CHTTPReply::bad_request, E, pReply->Content);
|
||||
ExceptionToJson(CHTTPReply::bad_request, E, Reply.Content);
|
||||
Log()->Error(APP_LOG_EMERG, 0, E.what());
|
||||
}
|
||||
|
||||
@@ -737,8 +737,8 @@ namespace Apostol {
|
||||
|
||||
} else if (caCommand == "bc" && caAction == "header") {
|
||||
|
||||
const auto &caHeight = pRequest->Params["height"];
|
||||
const auto &caHash = pRequest->Params["hash"];
|
||||
const auto &caHeight = Request.Params["height"];
|
||||
const auto &caHash = Request.Params["hash"];
|
||||
|
||||
if (caHeight.IsEmpty() && caHash.IsEmpty()) {
|
||||
AConnection->SendStockReply(CHTTPReply::bad_request);
|
||||
@@ -755,9 +755,9 @@ namespace Apostol {
|
||||
fetch_header(height, header);
|
||||
}
|
||||
|
||||
pReply->Content = header.ToString();
|
||||
Reply.Content = header.ToString();
|
||||
} catch (Delphi::Exception::Exception &E) {
|
||||
ExceptionToJson(CHTTPReply::bad_request, E, pReply->Content);
|
||||
ExceptionToJson(CHTTPReply::bad_request, E, Reply.Content);
|
||||
Log()->Error(APP_LOG_EMERG, 0, E.what());
|
||||
}
|
||||
|
||||
@@ -779,26 +779,26 @@ namespace Apostol {
|
||||
|
||||
Log()->Notice("[%s] [%s] Trying to fetch a OAuth2 configuration file.", Context.Name().c_str(), Context.URL().Origin().c_str());
|
||||
|
||||
auto OnRequest = [this, &Context](CHTTPClient *Sender, CHTTPRequest *ARequest) {
|
||||
auto OnRequest = [this, &Context](CHTTPClient *Sender, CHTTPRequest &Request) {
|
||||
|
||||
Context.SetStatus(Context::csPreparing);
|
||||
|
||||
ARequest->ContentType = CHTTPRequest::text;
|
||||
Request.ContentType = CHTTPRequest::text;
|
||||
|
||||
Apostol::PGP::CleartextSignature(
|
||||
m_pgpModuleKey,
|
||||
m_pgpPassphrase,
|
||||
BPS_PGP_HASH,
|
||||
Context.Name(),
|
||||
ARequest->Content);
|
||||
Request.Content);
|
||||
|
||||
CHTTPRequest::Prepare(ARequest, "POST", "/api/v1/dm/service");
|
||||
CHTTPRequest::Prepare(Request, "POST", "/api/v1/dm/service");
|
||||
|
||||
const auto &caModuleAddress = m_Module["address"];
|
||||
if (!caModuleAddress.IsEmpty())
|
||||
ARequest->AddHeader("Module-Address", caModuleAddress);
|
||||
Request.AddHeader("Module-Address", caModuleAddress);
|
||||
|
||||
DebugRequest(ARequest);
|
||||
DebugRequest(Request);
|
||||
};
|
||||
|
||||
auto OnExecute = [&Context](CTCPConnection *AConnection) {
|
||||
@@ -808,12 +808,12 @@ namespace Apostol {
|
||||
auto pConnection = dynamic_cast<CHTTPClientConnection *> (AConnection);
|
||||
|
||||
if (pConnection != nullptr) {
|
||||
auto pReply = pConnection->Reply();
|
||||
auto &Reply = pConnection->Reply();
|
||||
|
||||
DebugReply(pReply);
|
||||
DebugReply(Reply);
|
||||
|
||||
if (pReply->Status == CHTTPReply::ok) {
|
||||
const CJSON OAuth2(pReply->Content);
|
||||
if (Reply.Status == CHTTPReply::ok) {
|
||||
const CJSON OAuth2(Reply.Content);
|
||||
UpdateOAuth2(Context, OAuth2.Object());
|
||||
}
|
||||
|
||||
@@ -851,24 +851,24 @@ namespace Apostol {
|
||||
|
||||
Log()->Notice("[%s] [%s] Trying get module status.", Context.Name().c_str(), Context.URL().Origin().c_str());
|
||||
|
||||
auto OnRequest = [this, &Context](CHTTPClient *Sender, CHTTPRequest *ARequest) {
|
||||
auto OnRequest = [this, &Context](CHTTPClient *Sender, CHTTPRequest &Request) {
|
||||
|
||||
Context.SetStatus(Context::csInProgress);
|
||||
|
||||
const auto &caModuleAddress = m_Module["address"];
|
||||
|
||||
ARequest->ContentType = CHTTPRequest::text;
|
||||
Request.ContentType = CHTTPRequest::text;
|
||||
|
||||
ARequest->Content.Format(R"({"address": "%s"})", caModuleAddress.c_str());
|
||||
Request.Content.Format(R"({"address": "%s"})", caModuleAddress.c_str());
|
||||
|
||||
CHTTPRequest::Prepare(ARequest, "POST", "/api/v1/dm/status");
|
||||
CHTTPRequest::Prepare(Request, "POST", "/api/v1/dm/status");
|
||||
|
||||
ARequest->AddHeader("Authorization", "Bearer " + Context.Tokens()["module_token"]);
|
||||
Request.AddHeader("Authorization", "Bearer " + Context.Tokens()["module_token"]);
|
||||
|
||||
if (!caModuleAddress.IsEmpty())
|
||||
ARequest->AddHeader("Module-Address", caModuleAddress);
|
||||
Request.AddHeader("Module-Address", caModuleAddress);
|
||||
|
||||
DebugRequest(ARequest);
|
||||
DebugRequest(Request);
|
||||
};
|
||||
|
||||
auto OnExecute = [this, &Context](CTCPConnection *AConnection) {
|
||||
@@ -876,11 +876,11 @@ namespace Apostol {
|
||||
auto pConnection = dynamic_cast<CHTTPClientConnection *> (AConnection);
|
||||
|
||||
if (pConnection != nullptr) {
|
||||
auto pReply = pConnection->Reply();
|
||||
auto &Reply = pConnection->Reply();
|
||||
|
||||
DebugReply(pReply);
|
||||
DebugReply(Reply);
|
||||
|
||||
if (pReply->Status == CHTTPReply::ok) {
|
||||
if (Reply.Status == CHTTPReply::ok) {
|
||||
ModuleAuthorize(Context);
|
||||
} else {
|
||||
ModuleNew(Context);
|
||||
@@ -920,11 +920,11 @@ namespace Apostol {
|
||||
|
||||
Log()->Notice("[%s] [%s] Trying create new module.", Context.Name().c_str(), Context.URL().Origin().c_str());
|
||||
|
||||
auto OnRequest = [this, &Context](CHTTPClient *Sender, CHTTPRequest *ARequest) {
|
||||
auto OnRequest = [this, &Context](CHTTPClient *Sender, CHTTPRequest &Request) {
|
||||
|
||||
Context.SetStatus(Context::csInProgress);
|
||||
|
||||
ARequest->ContentType = CHTTPRequest::json;
|
||||
Request.ContentType = CHTTPRequest::json;
|
||||
|
||||
const auto &caModuleAddress = m_Module["address"];
|
||||
|
||||
@@ -938,16 +938,16 @@ namespace Apostol {
|
||||
|
||||
Json.Object().AddPair("pgp", public_key.write(OpenPGP::PGP::Armored::YES));
|
||||
|
||||
ARequest->Content = Json.ToString();
|
||||
Request.Content = Json.ToString();
|
||||
|
||||
CHTTPRequest::Prepare(ARequest, "POST", "/api/v1/client/new");
|
||||
CHTTPRequest::Prepare(Request, "POST", "/api/v1/client/new");
|
||||
|
||||
ARequest->AddHeader("Authorization", "Bearer " + Context.Tokens()["module_token"]);
|
||||
Request.AddHeader("Authorization", "Bearer " + Context.Tokens()["module_token"]);
|
||||
|
||||
if (!caModuleAddress.IsEmpty())
|
||||
ARequest->AddHeader("Module-Address", caModuleAddress);
|
||||
Request.AddHeader("Module-Address", caModuleAddress);
|
||||
|
||||
DebugRequest(ARequest);
|
||||
DebugRequest(Request);
|
||||
};
|
||||
|
||||
auto OnExecute = [this, &Context](CTCPConnection *AConnection) {
|
||||
@@ -957,12 +957,12 @@ namespace Apostol {
|
||||
auto pConnection = dynamic_cast<CHTTPClientConnection *> (AConnection);
|
||||
|
||||
if (pConnection != nullptr) {
|
||||
auto pReply = pConnection->Reply();
|
||||
auto &Reply = pConnection->Reply();
|
||||
|
||||
DebugReply(pReply);
|
||||
DebugReply(Reply);
|
||||
|
||||
if (pReply->Status == CHTTPReply::ok) {
|
||||
const CJSON Json(pReply->Content);
|
||||
if (Reply.Status == CHTTPReply::ok) {
|
||||
const CJSON Json(Reply.Content);
|
||||
|
||||
if (Json.HasOwnProperty("result")) {
|
||||
const auto &caResult = Json["result"];
|
||||
@@ -1013,32 +1013,32 @@ namespace Apostol {
|
||||
|
||||
Log()->Notice("[%s] [%s] Trying authorize module.", Context.Name().c_str(), Context.URL().Origin().c_str());
|
||||
|
||||
auto OnRequest = [this, &Context](CHTTPClient *Sender, CHTTPRequest *ARequest) {
|
||||
auto OnRequest = [this, &Context](CHTTPClient *Sender, CHTTPRequest &Request) {
|
||||
|
||||
Context.SetStatus(Context::csAuthorization);
|
||||
|
||||
ARequest->ContentType = CHTTPRequest::text;
|
||||
Request.ContentType = CHTTPRequest::text;
|
||||
|
||||
Apostol::PGP::CleartextSignature(
|
||||
m_pgpModuleKey,
|
||||
m_pgpPassphrase,
|
||||
BPS_PGP_HASH,
|
||||
Context.Name(),
|
||||
ARequest->Content);
|
||||
Request.Content);
|
||||
|
||||
CHTTPRequest::Prepare(ARequest, "POST", "/api/v1/dm/authorize");
|
||||
CHTTPRequest::Prepare(Request, "POST", "/api/v1/dm/authorize");
|
||||
|
||||
ARequest->AddHeader("Authorization", "Bearer " + Context.Tokens()["module_token"]);
|
||||
Request.AddHeader("Authorization", "Bearer " + Context.Tokens()["module_token"]);
|
||||
|
||||
const auto &access_token = Context.Tokens()["access_token"];
|
||||
if (!access_token.IsEmpty())
|
||||
ARequest->AddHeader("Subject-Token", access_token);
|
||||
Request.AddHeader("Subject-Token", access_token);
|
||||
|
||||
const auto &caModuleAddress = m_Module["address"];
|
||||
if (!caModuleAddress.IsEmpty())
|
||||
ARequest->AddHeader("Module-Address", caModuleAddress);
|
||||
Request.AddHeader("Module-Address", caModuleAddress);
|
||||
|
||||
DebugRequest(ARequest);
|
||||
DebugRequest(Request);
|
||||
};
|
||||
|
||||
auto OnExecute = [&Context](CTCPConnection *AConnection) {
|
||||
@@ -1048,13 +1048,13 @@ namespace Apostol {
|
||||
auto pConnection = dynamic_cast<CHTTPClientConnection *> (AConnection);
|
||||
|
||||
if (pConnection != nullptr) {
|
||||
auto pReply = pConnection->Reply();
|
||||
auto &Reply = pConnection->Reply();
|
||||
|
||||
DebugReply(pReply);
|
||||
DebugReply(Reply);
|
||||
|
||||
const CJSON Json(pReply->Content);
|
||||
const CJSON Json(Reply.Content);
|
||||
|
||||
if (pReply->Status == CHTTPReply::ok) {
|
||||
if (Reply.Status == CHTTPReply::ok) {
|
||||
Context.Session() = Json["session"].AsString();
|
||||
Context.Secret() = Json["secret"].AsString();
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ namespace Apostol {
|
||||
void ModuleNew(CContext &Context);
|
||||
void ModuleAuthorize(CContext &Context);
|
||||
|
||||
static CString GetAddress(CHTTPRequest *ARequest);
|
||||
static CString GetAddress(const CHTTPRequest &Request);
|
||||
|
||||
void DoGet(CHTTPServerConnection *AConnection) override;
|
||||
|
||||
|
||||
@@ -104,31 +104,31 @@ namespace Apostol {
|
||||
|
||||
if (Assigned(pProxy) && (pProxy->Connection() != nullptr)) {
|
||||
auto pProxyConnection = pProxy->Connection();
|
||||
auto pServerRequest = pProxyConnection->Request();
|
||||
auto pServerReply = pProxyConnection->Reply();
|
||||
auto pProxyReply = pConnection->Reply();
|
||||
const auto &caServerRequest = pProxyConnection->Request();
|
||||
auto &ServerReply = pProxyConnection->Reply();
|
||||
auto &ProxyReply = pConnection->Reply();
|
||||
|
||||
const auto &caFormat = pServerRequest->Params["payload"];
|
||||
const auto &caFormat = caServerRequest.Params["payload"];
|
||||
if (!caFormat.IsEmpty()) {
|
||||
if (caFormat == "html") {
|
||||
pServerReply->ContentType = CHTTPReply::html;
|
||||
ServerReply.ContentType = CHTTPReply::html;
|
||||
} else if (caFormat == "json") {
|
||||
pServerReply->ContentType = CHTTPReply::json;
|
||||
ServerReply.ContentType = CHTTPReply::json;
|
||||
} else if (caFormat == "xml") {
|
||||
pServerReply->ContentType = CHTTPReply::xml;
|
||||
ServerReply.ContentType = CHTTPReply::xml;
|
||||
} else {
|
||||
pServerReply->ContentType = CHTTPReply::text;
|
||||
ServerReply.ContentType = CHTTPReply::text;
|
||||
}
|
||||
|
||||
if (pProxyReply->Status == CHTTPReply::ok) {
|
||||
if (!pProxyReply->Content.IsEmpty()) {
|
||||
const CJSON json(pProxyReply->Content);
|
||||
pServerReply->Content = base64_decode(json["payload"].AsString());
|
||||
if (ProxyReply.Status == CHTTPReply::ok) {
|
||||
if (!ProxyReply.Content.IsEmpty()) {
|
||||
const CJSON json(ProxyReply.Content);
|
||||
ServerReply.Content = base64_decode(json["payload"].AsString());
|
||||
}
|
||||
pProxyConnection->SendReply(pProxyReply->Status, nullptr, true);
|
||||
pProxyConnection->SendReply(ProxyReply.Status, nullptr, true);
|
||||
} else {
|
||||
if (pProxyReply->Status == CHTTPReply::forbidden) {
|
||||
const auto &caServerParam = pServerRequest->Params["server"];
|
||||
if (ProxyReply.Status == CHTTPReply::forbidden) {
|
||||
const auto &caServerParam = caServerRequest.Params["server"];
|
||||
const auto index = CurrentContextIndex(caServerParam);
|
||||
|
||||
auto &Context = index == -1 ? m_CurrentServer : m_Servers[index].Value();
|
||||
@@ -137,15 +137,15 @@ namespace Apostol {
|
||||
Context.SetStatus(Context::csInitialized);
|
||||
}
|
||||
|
||||
pServerReply->Content = pProxyReply->Content;
|
||||
pProxyConnection->SendStockReply(pProxyReply->Status, true);
|
||||
ServerReply.Content = ProxyReply.Content;
|
||||
pProxyConnection->SendStockReply(ProxyReply.Status, true);
|
||||
}
|
||||
} else {
|
||||
pServerReply->Content = pProxyReply->Content;
|
||||
if (pProxyReply->Status == CHTTPReply::ok) {
|
||||
pProxyConnection->SendReply(pProxyReply->Status, nullptr, true);
|
||||
ServerReply.Content = ProxyReply.Content;
|
||||
if (ProxyReply.Status == CHTTPReply::ok) {
|
||||
pProxyConnection->SendReply(ProxyReply.Status, nullptr, true);
|
||||
} else {
|
||||
pProxyConnection->SendStockReply(pProxyReply->Status, true);
|
||||
pProxyConnection->SendStockReply(ProxyReply.Status, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -162,12 +162,12 @@ namespace Apostol {
|
||||
|
||||
if (Assigned(pProxy) && (pProxy->Connection() != nullptr)) {
|
||||
auto pProxyConnection = pProxy->Connection();
|
||||
auto pServerRequest = pProxyConnection->Request();
|
||||
auto pServerReply = pProxyConnection->Reply();
|
||||
const auto &caServerRequest = pProxyConnection->Request();
|
||||
auto &ServerReply = pProxyConnection->Reply();
|
||||
|
||||
const auto &Format = pServerRequest->Params["format"];
|
||||
const auto &Format = caServerRequest.Params["format"];
|
||||
if (Format == "html") {
|
||||
pServerReply->ContentType = CHTTPReply::html;
|
||||
ServerReply.ContentType = CHTTPReply::html;
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -187,8 +187,8 @@ namespace Apostol {
|
||||
|
||||
if (Assigned(pProxy) && (pProxy->Connection() != nullptr)) {
|
||||
auto pProxyConnection = pProxy->Connection();
|
||||
auto pReply = pProxyConnection->Reply();
|
||||
ExceptionToJson(0, E, pReply->Content);
|
||||
auto &Reply = pProxyConnection->Reply();
|
||||
ExceptionToJson(0, E, Reply.Content);
|
||||
pProxyConnection->SendReply(CHTTPReply::internal_server_error, nullptr, true);
|
||||
}
|
||||
|
||||
@@ -244,16 +244,16 @@ namespace Apostol {
|
||||
void CWebService::DoAccount(CHTTPServerConnection *AConnection, const CString &Method, const CString &URI) {
|
||||
|
||||
auto pProxy = GetProxy(AConnection);
|
||||
auto pServerRequest = AConnection->Request();
|
||||
auto pProxyRequest = pProxy->Request();
|
||||
const auto &caServerRequest = AConnection->Request();
|
||||
auto &ProxyRequest = pProxy->Request();
|
||||
|
||||
const auto &caModuleAddress = m_Module["address"];
|
||||
const auto &caHost = pServerRequest->Headers["host"];
|
||||
const auto &caOrigin = pServerRequest->Headers["origin"];
|
||||
const auto &caUserAddress = GetAddress(pServerRequest);
|
||||
const auto &caHost = caServerRequest.Headers["host"];
|
||||
const auto &caOrigin = caServerRequest.Headers["origin"];
|
||||
const auto &caUserAddress = GetAddress(caServerRequest);
|
||||
|
||||
const auto &pgpValue = pServerRequest->Params["pgp"];
|
||||
const auto &caServerParam = pServerRequest->Params["server"];
|
||||
const auto &pgpValue = caServerRequest.Params["pgp"];
|
||||
const auto &caServerParam = caServerRequest.Params["server"];
|
||||
|
||||
const auto index = CurrentContextIndex(caServerParam);
|
||||
|
||||
@@ -268,13 +268,13 @@ namespace Apostol {
|
||||
CStringList caClearText;
|
||||
CString sPayload;
|
||||
|
||||
if (!pServerRequest->Content.IsEmpty()) {
|
||||
if (!caServerRequest.Content.IsEmpty()) {
|
||||
|
||||
const auto &ContentType = pServerRequest->Headers.Values(_T("content-type"));
|
||||
const auto &ContentType = caServerRequest.Headers.Values(_T("content-type"));
|
||||
|
||||
if (ContentType.Find("application/x-www-form-urlencoded") == 0) {
|
||||
|
||||
const CStringList &FormData = pServerRequest->FormData;
|
||||
const CStringList &FormData = caServerRequest.FormData;
|
||||
|
||||
const auto &formDate = FormData["date"];
|
||||
const auto &formAddress = FormData["address"];
|
||||
@@ -320,7 +320,7 @@ namespace Apostol {
|
||||
} else if (ContentType.Find("multipart/form-data") == 0) {
|
||||
|
||||
CFormData FormData;
|
||||
CHTTPRequestParser::ParseFormData(pServerRequest, FormData);
|
||||
CHTTPRequestParser::ParseFormData(caServerRequest, FormData);
|
||||
|
||||
const auto &formDate = FormData.Data("date");
|
||||
const auto &formAddress = FormData.Data("address");
|
||||
@@ -365,7 +365,7 @@ namespace Apostol {
|
||||
|
||||
} else if (ContentType.Find("application/json") == 0) {
|
||||
|
||||
const CJSON contextJson(pServerRequest->Content);
|
||||
const CJSON contextJson(caServerRequest.Content);
|
||||
|
||||
const auto &jsonDate = contextJson["date"].AsString();
|
||||
const auto &jsonAddress = contextJson["address"].AsString();
|
||||
@@ -412,7 +412,7 @@ namespace Apostol {
|
||||
}
|
||||
|
||||
} else {
|
||||
caClearText = pServerRequest->Content;
|
||||
caClearText = caServerRequest.Content;
|
||||
}
|
||||
|
||||
if (pgpValue == "off" || pgpValue == "false") {
|
||||
@@ -445,22 +445,22 @@ namespace Apostol {
|
||||
if (!sPayload.IsEmpty())
|
||||
Json.Object().AddPair("payload", base64_encode(sPayload));
|
||||
|
||||
pProxyRequest->Clear();
|
||||
ProxyRequest.Clear();
|
||||
|
||||
pProxyRequest->Location = pServerRequest->Location;
|
||||
pProxyRequest->CloseConnection = false;
|
||||
pProxyRequest->ContentType = CHTTPRequest::json;
|
||||
pProxyRequest->Content << Json;
|
||||
ProxyRequest.Location = caServerRequest.Location;
|
||||
ProxyRequest.CloseConnection = false;
|
||||
ProxyRequest.ContentType = CHTTPRequest::json;
|
||||
ProxyRequest.Content << Json;
|
||||
|
||||
CHTTPRequest::Prepare(pProxyRequest, "POST", URI.c_str());
|
||||
CHTTPRequest::Prepare(ProxyRequest, "POST", URI.c_str());
|
||||
|
||||
pProxyRequest->AddHeader("Authorization", "Bearer " + caContext.Tokens()["access_token"]);
|
||||
ProxyRequest.AddHeader("Authorization", "Bearer " + caContext.Tokens()["access_token"]);
|
||||
|
||||
if (!caModuleAddress.IsEmpty())
|
||||
pProxyRequest->AddHeader("Module-Address", caModuleAddress);
|
||||
ProxyRequest.AddHeader("Module-Address", caModuleAddress);
|
||||
|
||||
if (!caOrigin.IsEmpty())
|
||||
pProxyRequest->AddHeader("Origin", caOrigin);
|
||||
ProxyRequest.AddHeader("Origin", caOrigin);
|
||||
|
||||
AConnection->CloseConnection(false);
|
||||
|
||||
@@ -472,8 +472,8 @@ namespace Apostol {
|
||||
void CWebService::DoDeal(CHTTPServerConnection *AConnection, const CString &Method, const CString &URI, const CString &Action) {
|
||||
|
||||
auto pProxy = GetProxy(AConnection);
|
||||
auto pServerRequest = AConnection->Request();
|
||||
auto pProxyRequest = pProxy->Request();
|
||||
const auto &caServerRequest = AConnection->Request();
|
||||
auto &ProxyRequest = pProxy->Request();
|
||||
|
||||
const auto &caModuleAddress = m_Module["address"];
|
||||
const auto &caModuleFee = m_Module["fee"];
|
||||
@@ -482,17 +482,17 @@ namespace Apostol {
|
||||
if (checkFee == -1)
|
||||
throw ExceptionFrm("Invalid module fee value: %s", caModuleFee.c_str());
|
||||
|
||||
const auto &caHost = pServerRequest->Headers["host"];
|
||||
const auto &caOrigin = pServerRequest->Headers["origin"];
|
||||
const auto &caHost = caServerRequest.Headers["host"];
|
||||
const auto &caOrigin = caServerRequest.Headers["origin"];
|
||||
|
||||
const auto &address = GetAddress(pServerRequest);
|
||||
const auto &code = pServerRequest->Params["code"];
|
||||
const auto &address = GetAddress(caServerRequest);
|
||||
const auto &code = caServerRequest.Params["code"];
|
||||
|
||||
const auto &caUserAddress = address.length() == 40 ? CString() : address;
|
||||
const auto &caDealCode = !code.empty() ? code : address.length() == 40 ? address : CString();
|
||||
|
||||
const auto &pgpValue = pServerRequest->Params["pgp"];
|
||||
const auto &caServerParam = pServerRequest->Params["server"];
|
||||
const auto &pgpValue = caServerRequest.Params["pgp"];
|
||||
const auto &caServerParam = caServerRequest.Params["server"];
|
||||
|
||||
const auto index = CurrentContextIndex(caServerParam);
|
||||
|
||||
@@ -508,13 +508,13 @@ namespace Apostol {
|
||||
|
||||
CString sPayload;
|
||||
|
||||
if (!pServerRequest->Content.IsEmpty() && Action != "status") {
|
||||
if (!caServerRequest.Content.IsEmpty() && Action != "status") {
|
||||
|
||||
const auto &ContentType = pServerRequest->Headers.Values(_T("content-type"));
|
||||
const auto &ContentType = caServerRequest.Headers.Values(_T("content-type"));
|
||||
|
||||
if (ContentType.Find("application/x-www-form-urlencoded") == 0) {
|
||||
|
||||
const CStringList &FormData = pServerRequest->FormData;
|
||||
const CStringList &FormData = caServerRequest.FormData;
|
||||
|
||||
const auto &formType = FormData["type"];
|
||||
const auto &formAt = FormData["at"];
|
||||
@@ -605,7 +605,7 @@ namespace Apostol {
|
||||
} else if (ContentType.Find("multipart/form-data") == 0) {
|
||||
|
||||
CFormData FormData;
|
||||
CHTTPRequestParser::ParseFormData(pServerRequest, FormData);
|
||||
CHTTPRequestParser::ParseFormData(caServerRequest, FormData);
|
||||
|
||||
const auto &formType = FormData.Data("type");
|
||||
const auto &formAt = FormData.Data("at");
|
||||
@@ -695,7 +695,7 @@ namespace Apostol {
|
||||
|
||||
} else if (ContentType.Find("application/json") == 0) {
|
||||
|
||||
const CJSON jsonData(pServerRequest->Content);
|
||||
const CJSON jsonData(caServerRequest.Content);
|
||||
|
||||
const auto &formOrder = jsonData["order"].AsString().Lower();
|
||||
const auto &formType = jsonData["type"].AsString();
|
||||
@@ -794,7 +794,7 @@ namespace Apostol {
|
||||
}
|
||||
|
||||
} else {
|
||||
Node = YAML::Load(pServerRequest->Content.c_str());
|
||||
Node = YAML::Load(caServerRequest.Content.c_str());
|
||||
}
|
||||
|
||||
const auto &BTCKeys = caContext.BTCKeys();
|
||||
@@ -871,25 +871,25 @@ namespace Apostol {
|
||||
if (!sPayload.IsEmpty())
|
||||
Json.Object().AddPair("payload", base64_encode(sPayload));
|
||||
|
||||
pProxyRequest->Clear();
|
||||
ProxyRequest.Clear();
|
||||
|
||||
pProxyRequest->Location = pServerRequest->Location;
|
||||
pProxyRequest->CloseConnection = true;
|
||||
pProxyRequest->ContentType = CHTTPRequest::json;
|
||||
pProxyRequest->Content << Json;
|
||||
ProxyRequest.Location = caServerRequest.Location;
|
||||
ProxyRequest.CloseConnection = true;
|
||||
ProxyRequest.ContentType = CHTTPRequest::json;
|
||||
ProxyRequest.Content << Json;
|
||||
|
||||
CHTTPRequest::Prepare(pProxyRequest, "POST", URI.c_str());
|
||||
CHTTPRequest::Prepare(ProxyRequest, "POST", URI.c_str());
|
||||
|
||||
pProxyRequest->AddHeader("Authorization", "Bearer " + caContext.Tokens()["access_token"]);
|
||||
ProxyRequest.AddHeader("Authorization", "Bearer " + caContext.Tokens()["access_token"]);
|
||||
|
||||
if (!caModuleAddress.IsEmpty())
|
||||
pProxyRequest->AddHeader("Module-Address", caModuleAddress);
|
||||
ProxyRequest.AddHeader("Module-Address", caModuleAddress);
|
||||
|
||||
if (!caModuleFee.IsEmpty())
|
||||
pProxyRequest->AddHeader("Module-Fee", caModuleFee);
|
||||
ProxyRequest.AddHeader("Module-Fee", caModuleFee);
|
||||
|
||||
if (!caOrigin.IsEmpty())
|
||||
pProxyRequest->AddHeader("Origin", caOrigin);
|
||||
ProxyRequest.AddHeader("Origin", caOrigin);
|
||||
|
||||
AConnection->TimeOutInterval(30 * 1000);
|
||||
AConnection->UpdateTimeOut(Now());
|
||||
@@ -904,8 +904,8 @@ namespace Apostol {
|
||||
void CWebService::DoProxy(CHTTPServerConnection *AConnection, const CString &Method, const CString &URI) {
|
||||
|
||||
auto pProxy = GetProxy(AConnection);
|
||||
auto pServerRequest = AConnection->Request();
|
||||
auto pProxyRequest = pProxy->Request();
|
||||
const auto &caServerRequest = AConnection->Request();
|
||||
auto &ProxyRequest = pProxy->Request();
|
||||
|
||||
const auto &caModuleAddress = m_Module["address"];
|
||||
const auto &caModuleFee = m_Module["fee"];
|
||||
@@ -914,18 +914,18 @@ namespace Apostol {
|
||||
if (checkFee == -1)
|
||||
throw ExceptionFrm("Invalid module fee value: %s", caModuleFee.c_str());
|
||||
|
||||
const auto &caHost = pServerRequest->Headers["host"];
|
||||
const auto &caOrigin = pServerRequest->Headers["origin"];
|
||||
const auto &caContentType = pServerRequest->Headers["content-type"].Lower();
|
||||
const auto &caHost = caServerRequest.Headers["host"];
|
||||
const auto &caOrigin = caServerRequest.Headers["origin"];
|
||||
const auto &caContentType = caServerRequest.Headers["content-type"].Lower();
|
||||
|
||||
const auto &address = GetAddress(pServerRequest);
|
||||
const auto &code = pServerRequest->Params["code"];
|
||||
const auto &address = GetAddress(caServerRequest);
|
||||
const auto &code = caServerRequest.Params["code"];
|
||||
|
||||
const auto &caUserAddress = address.length() == 40 ? CString() : address;
|
||||
const auto &caDealCode = !code.empty() ? code : address.length() == 40 ? address : CString();
|
||||
|
||||
const auto &pgpValue = pServerRequest->Params["pgp"];
|
||||
const auto &caServerParam = pServerRequest->Params["server"];
|
||||
const auto &pgpValue = caServerRequest.Params["pgp"];
|
||||
const auto &caServerParam = caServerRequest.Params["server"];
|
||||
|
||||
const auto index = CurrentContextIndex(caServerParam);
|
||||
|
||||
@@ -937,29 +937,29 @@ namespace Apostol {
|
||||
pProxy->Host() = Location.hostname;
|
||||
pProxy->Port(Location.port == 0 ? BPS_SERVER_PORT : Location.port);
|
||||
|
||||
pProxyRequest->Clear();
|
||||
ProxyRequest.Clear();
|
||||
|
||||
pProxyRequest->Location = pServerRequest->Location;
|
||||
ProxyRequest.Location = caServerRequest.Location;
|
||||
|
||||
if (Method == "POST") {
|
||||
pProxyRequest->ContentType = StringToContentType(caContentType);
|
||||
pProxyRequest->Content = pServerRequest->Content;
|
||||
ProxyRequest.ContentType = StringToContentType(caContentType);
|
||||
ProxyRequest.Content = caServerRequest.Content;
|
||||
}
|
||||
|
||||
pProxyRequest->CloseConnection = true;
|
||||
ProxyRequest.CloseConnection = true;
|
||||
|
||||
CHTTPRequest::Prepare(pProxyRequest, Method.c_str(), URI.c_str(), caContentType.c_str());
|
||||
CHTTPRequest::Prepare(ProxyRequest, Method.c_str(), URI.c_str(), caContentType.c_str());
|
||||
|
||||
pProxyRequest->AddHeader("Authorization", "Bearer " + caContext.Tokens()["access_token"]);
|
||||
ProxyRequest.AddHeader("Authorization", "Bearer " + caContext.Tokens()["access_token"]);
|
||||
|
||||
if (!caModuleAddress.IsEmpty())
|
||||
pProxyRequest->AddHeader("Module-Address", caModuleAddress);
|
||||
ProxyRequest.AddHeader("Module-Address", caModuleAddress);
|
||||
|
||||
if (!caModuleFee.IsEmpty())
|
||||
pProxyRequest->AddHeader("Module-Fee", caModuleFee);
|
||||
ProxyRequest.AddHeader("Module-Fee", caModuleFee);
|
||||
|
||||
if (!caOrigin.IsEmpty())
|
||||
pProxyRequest->AddHeader("Origin", caOrigin);
|
||||
ProxyRequest.AddHeader("Origin", caOrigin);
|
||||
|
||||
AConnection->TimeOutInterval(15 * 1000);
|
||||
AConnection->UpdateTimeOut(Now());
|
||||
@@ -972,15 +972,15 @@ namespace Apostol {
|
||||
//--------------------------------------------------------------------------------------------------------------
|
||||
|
||||
void CWebService::DoSignature(CHTTPServerConnection *AConnection) {
|
||||
auto pRequest = AConnection->Request();
|
||||
auto pReply = AConnection->Reply();
|
||||
const auto &caRequest = AConnection->Request();
|
||||
auto &Reply = AConnection->Reply();
|
||||
|
||||
if (pRequest->Content.IsEmpty()) {
|
||||
if (caRequest.Content.IsEmpty()) {
|
||||
AConnection->SendStockReply(CHTTPReply::no_content);
|
||||
return;
|
||||
}
|
||||
|
||||
const auto &caServerParam = pRequest->Params["server"];
|
||||
const auto &caServerParam = caRequest.Params["server"];
|
||||
int index = CurrentContextIndex(caServerParam);
|
||||
const auto &caContext = index == -1 ? m_CurrentServer : m_Servers[index].Value();
|
||||
|
||||
@@ -1002,10 +1002,10 @@ namespace Apostol {
|
||||
CString message;
|
||||
CJSON Json(jvtObject);
|
||||
|
||||
const auto &caContentType = pRequest->Headers["content-type"];
|
||||
const auto &caContentType = caRequest.Headers["content-type"];
|
||||
|
||||
if (caContentType.Find("application/x-www-form-urlencoded") == 0) {
|
||||
const CStringList &FormData = pRequest->FormData;
|
||||
const auto &FormData = caRequest.FormData;
|
||||
|
||||
const auto &caClearText = FormData["message"];
|
||||
CheckKeyForNull("message", caClearText.c_str());
|
||||
@@ -1014,7 +1014,7 @@ namespace Apostol {
|
||||
Json.Object().AddPair("verified", bVerified);
|
||||
} else if (caContentType.Find("multipart/form-data") == 0) {
|
||||
CFormData FormData;
|
||||
CHTTPRequestParser::ParseFormData(pRequest, FormData);
|
||||
CHTTPRequestParser::ParseFormData(caRequest, FormData);
|
||||
|
||||
const auto &caClearText = FormData.Data("message");
|
||||
CheckKeyForNull("message", caClearText.c_str());
|
||||
@@ -1022,7 +1022,7 @@ namespace Apostol {
|
||||
const auto bVerified = CheckVerifyPGPSignature(VerifyPGPSignature(caClearText, caServerKey, message), message);
|
||||
Json.Object().AddPair("verified", bVerified);
|
||||
} else if (caContentType.Find("application/json") == 0) {
|
||||
const CJSON jsonData(pRequest->Content);
|
||||
const CJSON jsonData(caRequest.Content);
|
||||
|
||||
const auto &caClearText = jsonData["message"].AsString();
|
||||
CheckKeyForNull("message", caClearText.c_str());
|
||||
@@ -1030,7 +1030,7 @@ namespace Apostol {
|
||||
const auto bVerified = CheckVerifyPGPSignature(VerifyPGPSignature(caClearText, caServerKey, message), message);
|
||||
Json.Object().AddPair("verified", bVerified);
|
||||
} else {
|
||||
const auto &caClearText = pRequest->Content;
|
||||
const auto &caClearText = caRequest.Content;
|
||||
const auto bVerified = CheckVerifyPGPSignature(VerifyPGPSignature(caClearText, caServerKey, message), message);
|
||||
Json.Object().AddPair("verified", bVerified);
|
||||
}
|
||||
@@ -1038,7 +1038,7 @@ namespace Apostol {
|
||||
Json.Object().AddPair("message", message);
|
||||
|
||||
AConnection->CloseConnection(true);
|
||||
pReply->Content << Json;
|
||||
Reply.Content << Json;
|
||||
|
||||
AConnection->SendReply(CHTTPReply::ok);
|
||||
}
|
||||
@@ -1048,7 +1048,7 @@ namespace Apostol {
|
||||
|
||||
Log()->Notice("[%s] [%s] Trying to fetch a PGP key.", Context.Name().c_str(), Context.URL().Origin().c_str());
|
||||
|
||||
auto OnRequest = [&Context](CHTTPClient *Sender, CHTTPRequest *ARequest) {
|
||||
auto OnRequest = [&Context](CHTTPClient *Sender, CHTTPRequest &Request) {
|
||||
|
||||
const auto &name = Sender->Data()["name"];
|
||||
auto &Keys = Context.PGP();
|
||||
@@ -1058,7 +1058,7 @@ namespace Apostol {
|
||||
index++;
|
||||
}
|
||||
|
||||
ARequest->ContentType = CHTTPRequest::json;
|
||||
Request.ContentType = CHTTPRequest::json;
|
||||
|
||||
if (index < Keys.Count()) {
|
||||
auto &Key = Keys[index];
|
||||
@@ -1066,17 +1066,17 @@ namespace Apostol {
|
||||
Key.StatusTime = Now();
|
||||
}
|
||||
|
||||
ARequest->Content = CString().Format(R"({"type": "pgp", "account": "%s", "code": "%s", "fields": ["code", "data"]})", Context.Name().c_str(), name.c_str());
|
||||
Request.Content = CString().Format(R"({"type": "pgp", "account": "%s", "code": "%s", "fields": ["code", "data"]})", Context.Name().c_str(), name.c_str());
|
||||
|
||||
CHTTPRequest::Prepare(ARequest, "POST", "/api/v1/key/public");
|
||||
CHTTPRequest::Prepare(Request, "POST", "/api/v1/key/public");
|
||||
|
||||
const auto &access_token = Context.Tokens()["access_token"];
|
||||
|
||||
if (!access_token.empty()) {
|
||||
ARequest->AddHeader("Authorization", "Bearer " + access_token);
|
||||
Request.AddHeader("Authorization", "Bearer " + access_token);
|
||||
}
|
||||
|
||||
DebugRequest(ARequest);
|
||||
DebugRequest(Request);
|
||||
};
|
||||
|
||||
auto OnExecute = [this, &Context](CTCPConnection *AConnection) {
|
||||
@@ -1085,15 +1085,15 @@ namespace Apostol {
|
||||
|
||||
if (pConnection != nullptr) {
|
||||
auto pClient = dynamic_cast<CHTTPClient *> (pConnection->Client());
|
||||
auto pReply = pConnection->Reply();
|
||||
const auto &Reply = pConnection->Reply();
|
||||
|
||||
DebugReply(pReply);
|
||||
DebugReply(Reply);
|
||||
|
||||
CString Code;
|
||||
CString Key;
|
||||
|
||||
try {
|
||||
JsonStringToKey(pReply->Content, Code, Key);
|
||||
JsonStringToKey(Reply.Content, Code, Key);
|
||||
|
||||
if (Key.IsEmpty())
|
||||
throw Delphi::Exception::Exception("Not found.");
|
||||
|
||||
@@ -316,10 +316,10 @@ namespace Apostol {
|
||||
chASSERT(pClient);
|
||||
auto pContext = pClient->Context();
|
||||
chASSERT(pContext);
|
||||
auto pReply = pConnection->Reply();
|
||||
const auto &Reply = pConnection->Reply();
|
||||
|
||||
if (pReply->Status == CHTTPReply::moved_permanently || pReply->Status == CHTTPReply::moved_temporarily) {
|
||||
const auto &caLocation = pReply->Headers["Location"];
|
||||
if (Reply.Status == CHTTPReply::moved_permanently || Reply.Status == CHTTPReply::moved_temporarily) {
|
||||
const auto &caLocation = Reply.Headers["Location"];
|
||||
if (!caLocation.IsEmpty()) {
|
||||
pClient->SetURI(CLocation(caLocation));
|
||||
Log()->Notice(_T("[%s] Redirect to %s."), pClient->Session().c_str(), pClient->URI().href().c_str());
|
||||
@@ -346,37 +346,37 @@ namespace Apostol {
|
||||
void CWebSocketModule::DoAccount(CHTTPServerConnection *AConnection, const CString &Method, const CString &URI) {
|
||||
|
||||
auto OnRequest = [AConnection](CWebSocketMessageHandler *AHandler, CWebSocketConnection *AWSConnection) {
|
||||
auto pReply = AConnection->Reply();
|
||||
auto &Reply = AConnection->Reply();
|
||||
const auto &wsMessage = CCustomWebSocketClient::RequestToMessage(AWSConnection);
|
||||
pReply->ContentType = CHTTPReply::json;
|
||||
Reply.ContentType = CHTTPReply::json;
|
||||
if (wsMessage.MessageTypeId == mtCallResult) {
|
||||
pReply->Content = wsMessage.Payload.ToString();
|
||||
Reply.Content = wsMessage.Payload.ToString();
|
||||
AConnection->SendReply(CHTTPReply::ok, nullptr, true);
|
||||
} else {
|
||||
ReplyError(AConnection, CHTTPReply::bad_request, wsMessage.ErrorMessage);
|
||||
}
|
||||
};
|
||||
|
||||
auto pServerRequest = AConnection->Request();
|
||||
const auto &ServerRequest = AConnection->Request();
|
||||
|
||||
const auto &caModuleAddress = m_Module["address"];
|
||||
const auto &caHost = pServerRequest->Headers["host"];
|
||||
const auto &caOrigin = pServerRequest->Headers["origin"];
|
||||
const auto &caUserAddress = GetAddress(pServerRequest);
|
||||
const auto &caHost = ServerRequest.Headers["host"];
|
||||
const auto &caOrigin = ServerRequest.Headers["origin"];
|
||||
const auto &caUserAddress = GetAddress(ServerRequest);
|
||||
|
||||
const auto &pgpValue = pServerRequest->Params["pgp"];
|
||||
const auto &caServerParam = pServerRequest->Params["server"];
|
||||
const auto &pgpValue = ServerRequest.Params["pgp"];
|
||||
const auto &caServerParam = ServerRequest.Params["server"];
|
||||
|
||||
CStringList caClearText;
|
||||
CString sPayload;
|
||||
|
||||
if (!pServerRequest->Content.IsEmpty()) {
|
||||
if (!ServerRequest.Content.IsEmpty()) {
|
||||
|
||||
const auto &ContentType = pServerRequest->Headers.Values(_T("content-type"));
|
||||
const auto &ContentType = ServerRequest.Headers.Values(_T("content-type"));
|
||||
|
||||
if (ContentType.Find("application/x-www-form-urlencoded") == 0) {
|
||||
|
||||
const CStringList &FormData = pServerRequest->FormData;
|
||||
const CStringList &FormData = ServerRequest.FormData;
|
||||
|
||||
const auto &formDate = FormData["date"];
|
||||
const auto &formAddress = FormData["address"];
|
||||
@@ -422,7 +422,7 @@ namespace Apostol {
|
||||
} else if (ContentType.Find("multipart/form-data") == 0) {
|
||||
|
||||
CFormData FormData;
|
||||
CHTTPRequestParser::ParseFormData(pServerRequest, FormData);
|
||||
CHTTPRequestParser::ParseFormData(ServerRequest, FormData);
|
||||
|
||||
const auto &formDate = FormData.Data("date");
|
||||
const auto &formAddress = FormData.Data("address");
|
||||
@@ -467,7 +467,7 @@ namespace Apostol {
|
||||
|
||||
} else if (ContentType.Find("application/json") == 0) {
|
||||
|
||||
const CJSON contextJson(pServerRequest->Content);
|
||||
const CJSON contextJson(ServerRequest.Content);
|
||||
|
||||
const auto &jsonDate = contextJson["date"].AsString();
|
||||
const auto &jsonAddress = contextJson["address"].AsString();
|
||||
@@ -514,7 +514,7 @@ namespace Apostol {
|
||||
}
|
||||
|
||||
} else {
|
||||
caClearText = pServerRequest->Content;
|
||||
caClearText = ServerRequest.Content;
|
||||
}
|
||||
|
||||
if (pgpValue == "off" || pgpValue == "false") {
|
||||
@@ -560,18 +560,18 @@ namespace Apostol {
|
||||
void CWebSocketModule::DoDeal(CHTTPServerConnection *AConnection, const CString &Method, const CString &URI, const CString &Action) {
|
||||
|
||||
auto OnRequest = [AConnection](CWebSocketMessageHandler *AHandler, CWebSocketConnection *AWSConnection) {
|
||||
auto pReply = AConnection->Reply();
|
||||
auto &Reply = AConnection->Reply();
|
||||
const auto &wsMessage = CCustomWebSocketClient::RequestToMessage(AWSConnection);
|
||||
pReply->ContentType = CHTTPReply::json;
|
||||
Reply.ContentType = CHTTPReply::json;
|
||||
if (wsMessage.MessageTypeId == mtCallResult) {
|
||||
pReply->Content = wsMessage.Payload.ToString();
|
||||
Reply.Content = wsMessage.Payload.ToString();
|
||||
AConnection->SendReply(CHTTPReply::ok, nullptr, true);
|
||||
} else {
|
||||
ReplyError(AConnection, CHTTPReply::bad_request, wsMessage.ErrorMessage);
|
||||
}
|
||||
};
|
||||
|
||||
auto pServerRequest = AConnection->Request();
|
||||
const auto &ServerRequest = AConnection->Request();
|
||||
|
||||
const auto &caModuleAddress = m_Module["address"];
|
||||
const auto &caModuleFee = m_Module["fee"];
|
||||
@@ -580,17 +580,17 @@ namespace Apostol {
|
||||
if (checkFee == -1)
|
||||
throw ExceptionFrm("Invalid module fee value: %s", caModuleFee.c_str());
|
||||
|
||||
const auto &caHost = pServerRequest->Headers["host"];
|
||||
const auto &caOrigin = pServerRequest->Headers["origin"];
|
||||
const auto &caHost = ServerRequest.Headers["host"];
|
||||
const auto &caOrigin = ServerRequest.Headers["origin"];
|
||||
|
||||
const auto &address = GetAddress(pServerRequest);
|
||||
const auto &code = pServerRequest->Params["code"];
|
||||
const auto &address = GetAddress(ServerRequest);
|
||||
const auto &code = ServerRequest.Params["code"];
|
||||
|
||||
const auto &caUserAddress = address.length() == 40 ? CString() : address;
|
||||
const auto &caDealCode = !code.empty() ? code : address.length() == 40 ? address : CString();
|
||||
|
||||
const auto &pgpValue = pServerRequest->Params["pgp"];
|
||||
const auto &caServerParam = pServerRequest->Params["server"];
|
||||
const auto &pgpValue = ServerRequest.Params["pgp"];
|
||||
const auto &caServerParam = ServerRequest.Params["server"];
|
||||
|
||||
const auto index = CurrentContextIndex(caServerParam);
|
||||
if (index == -1) {
|
||||
@@ -603,14 +603,14 @@ namespace Apostol {
|
||||
|
||||
CString sPayload;
|
||||
|
||||
if (!pServerRequest->Content.IsEmpty() && Action != "status") {
|
||||
if (!ServerRequest.Content.IsEmpty() && Action != "status") {
|
||||
|
||||
const auto utc = UTC();
|
||||
const auto &ContentType = pServerRequest->Headers.Values(_T("content-type"));
|
||||
const auto &ContentType = ServerRequest.Headers.Values(_T("content-type"));
|
||||
|
||||
if (ContentType.Find("application/x-www-form-urlencoded") == 0) {
|
||||
|
||||
const CStringList &FormData = pServerRequest->FormData;
|
||||
const CStringList &FormData = ServerRequest.FormData;
|
||||
|
||||
const auto &formType = FormData["type"];
|
||||
const auto &formAt = FormData["at"];
|
||||
@@ -697,7 +697,7 @@ namespace Apostol {
|
||||
} else if (ContentType.Find("multipart/form-data") == 0) {
|
||||
|
||||
CFormData FormData;
|
||||
CHTTPRequestParser::ParseFormData(pServerRequest, FormData);
|
||||
CHTTPRequestParser::ParseFormData(ServerRequest, FormData);
|
||||
|
||||
const auto &formType = FormData.Data("type");
|
||||
const auto &formAt = FormData.Data("at");
|
||||
@@ -783,7 +783,7 @@ namespace Apostol {
|
||||
|
||||
} else if (ContentType.Find("application/json") == 0) {
|
||||
|
||||
const CJSON jsonData(pServerRequest->Content);
|
||||
const CJSON jsonData(ServerRequest.Content);
|
||||
|
||||
const auto &formOrder = jsonData["order"].AsString().Lower();
|
||||
const auto &formType = jsonData["type"].AsString();
|
||||
@@ -878,7 +878,7 @@ namespace Apostol {
|
||||
}
|
||||
|
||||
} else {
|
||||
Node = YAML::Load(pServerRequest->Content.c_str());
|
||||
Node = YAML::Load(ServerRequest.Content.c_str());
|
||||
}
|
||||
|
||||
const auto &BTCKeys = caContext.BTCKeys();
|
||||
@@ -968,18 +968,18 @@ namespace Apostol {
|
||||
void CWebSocketModule::DoProxy(CHTTPServerConnection *AConnection, const CString &Method, const CString &URI) {
|
||||
|
||||
auto OnRequest = [AConnection](CWebSocketMessageHandler *AHandler, CWebSocketConnection *AWSConnection) {
|
||||
auto pReply = AConnection->Reply();
|
||||
auto &Reply = AConnection->Reply();
|
||||
const auto &wsMessage = CCustomWebSocketClient::RequestToMessage(AWSConnection);
|
||||
pReply->ContentType = CHTTPReply::json;
|
||||
Reply.ContentType = CHTTPReply::json;
|
||||
if (wsMessage.MessageTypeId == mtCallResult) {
|
||||
pReply->Content = wsMessage.Payload.ToString();
|
||||
Reply.Content = wsMessage.Payload.ToString();
|
||||
AConnection->SendReply(CHTTPReply::ok, nullptr, true);
|
||||
} else {
|
||||
ReplyError(AConnection, CHTTPReply::bad_request, wsMessage.ErrorMessage);
|
||||
}
|
||||
};
|
||||
|
||||
auto pServerRequest = AConnection->Request();
|
||||
const auto &ServerRequest = AConnection->Request();
|
||||
|
||||
const auto &caModuleAddress = m_Module["address"];
|
||||
const auto &caModuleFee = m_Module["fee"];
|
||||
@@ -988,17 +988,17 @@ namespace Apostol {
|
||||
if (checkFee == -1)
|
||||
throw ExceptionFrm("Invalid module fee value: %s", caModuleFee.c_str());
|
||||
|
||||
const auto &caHost = pServerRequest->Headers["host"];
|
||||
const auto &caOrigin = pServerRequest->Headers["origin"];
|
||||
const auto &caHost = ServerRequest.Headers["host"];
|
||||
const auto &caOrigin = ServerRequest.Headers["origin"];
|
||||
|
||||
const auto &address = pServerRequest->Params["address"];
|
||||
const auto &code = pServerRequest->Params["code"];
|
||||
const auto &address = ServerRequest.Params["address"];
|
||||
const auto &code = ServerRequest.Params["code"];
|
||||
|
||||
const auto &caUserAddress = address.length() == 40 ? CString() : address;
|
||||
const auto &caDealCode = !code.empty() ? code : address.length() == 40 ? address : CString();
|
||||
|
||||
const auto &pgpValue = pServerRequest->Params["pgp"];
|
||||
const auto &caServerParam = pServerRequest->Params["server"];
|
||||
const auto &pgpValue = ServerRequest.Params["pgp"];
|
||||
const auto &caServerParam = ServerRequest.Params["server"];
|
||||
|
||||
const auto index = CurrentContextIndex(caServerParam);
|
||||
if (index == -1) {
|
||||
@@ -1013,22 +1013,22 @@ namespace Apostol {
|
||||
throw Delphi::Exception::Exception(NOT_FOUND_ACTIVE_CONNECTION);
|
||||
}
|
||||
|
||||
const CJSON Json(pServerRequest->Content);
|
||||
const CJSON Json(ServerRequest.Content);
|
||||
|
||||
pClient->Send(URI, Json, OnRequest);
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------------------
|
||||
|
||||
void CWebSocketModule::DoSignature(CHTTPServerConnection *AConnection) {
|
||||
auto pRequest = AConnection->Request();
|
||||
auto pReply = AConnection->Reply();
|
||||
const auto &caRequest = AConnection->Request();
|
||||
auto &Reply = AConnection->Reply();
|
||||
|
||||
if (pRequest->Content.IsEmpty()) {
|
||||
if (caRequest.Content.IsEmpty()) {
|
||||
AConnection->SendStockReply(CHTTPReply::no_content);
|
||||
return;
|
||||
}
|
||||
|
||||
const auto &caServerParam = pRequest->Params["server"];
|
||||
const auto &caServerParam = caRequest.Params["server"];
|
||||
|
||||
int index = CurrentContextIndex(caServerParam);
|
||||
if (index == -1) {
|
||||
@@ -1054,10 +1054,10 @@ namespace Apostol {
|
||||
CString message;
|
||||
CJSON Json(jvtObject);
|
||||
|
||||
const auto& caContentType = pRequest->Headers["content-type"];
|
||||
const auto& caContentType = caRequest.Headers["content-type"];
|
||||
|
||||
if (caContentType.Find("application/x-www-form-urlencoded") == 0) {
|
||||
const CStringList &FormData = pRequest->FormData;
|
||||
const CStringList &FormData = caRequest.FormData;
|
||||
|
||||
const auto& caClearText = FormData["message"];
|
||||
CheckKeyForNull("message", caClearText.c_str());
|
||||
@@ -1066,7 +1066,7 @@ namespace Apostol {
|
||||
Json.Object().AddPair("verified", bVerified);
|
||||
} else if (caContentType.Find("multipart/form-data") == 0) {
|
||||
CFormData FormData;
|
||||
CHTTPRequestParser::ParseFormData(pRequest, FormData);
|
||||
CHTTPRequestParser::ParseFormData(caRequest, FormData);
|
||||
|
||||
const auto& caClearText = FormData.Data("message");
|
||||
CheckKeyForNull("message", caClearText.c_str());
|
||||
@@ -1074,7 +1074,7 @@ namespace Apostol {
|
||||
const auto bVerified = CheckVerifyPGPSignature(VerifyPGPSignature(caClearText, caServerKey, message), message);
|
||||
Json.Object().AddPair("verified", bVerified);
|
||||
} else if (caContentType.Find("application/json") == 0) {
|
||||
const CJSON jsonData(pRequest->Content);
|
||||
const CJSON jsonData(caRequest.Content);
|
||||
|
||||
const auto& caClearText = jsonData["message"].AsString();
|
||||
CheckKeyForNull("message", caClearText.c_str());
|
||||
@@ -1082,7 +1082,7 @@ namespace Apostol {
|
||||
const auto bVerified = CheckVerifyPGPSignature(VerifyPGPSignature(caClearText, caServerKey, message), message);
|
||||
Json.Object().AddPair("verified", bVerified);
|
||||
} else {
|
||||
const auto& caClearText = pRequest->Content;
|
||||
const auto& caClearText = caRequest.Content;
|
||||
const auto bVerified = CheckVerifyPGPSignature(VerifyPGPSignature(caClearText, caServerKey, message), message);
|
||||
Json.Object().AddPair("verified", bVerified);
|
||||
}
|
||||
@@ -1090,7 +1090,7 @@ namespace Apostol {
|
||||
Json.Object().AddPair("message", message);
|
||||
|
||||
AConnection->CloseConnection(true);
|
||||
pReply->Content << Json;
|
||||
Reply.Content << Json;
|
||||
|
||||
AConnection->SendReply(CHTTPReply::ok);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user