diff options
author | Shauren <shauren.trinity@gmail.com> | 2018-01-06 01:21:59 +0100 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2018-01-06 01:21:59 +0100 |
commit | dfd2660a85e4f0891c63009ee8425b2796586409 (patch) | |
tree | 26704dff3840402765ada5e6e4549a48b95ed82b /src/server/bnetserver/REST/LoginRESTService.cpp | |
parent | 76577ddc3ca4edd5943777443d9cf5a4c5314e10 (diff) |
Core/Misc: Added compatibility layer for boost 1.66 and future std:: networking stuff
* Based on work done by @dimiandre in PR #21173
Closes #21171
Closes #21173
Diffstat (limited to 'src/server/bnetserver/REST/LoginRESTService.cpp')
-rw-r--r-- | src/server/bnetserver/REST/LoginRESTService.cpp | 39 |
1 files changed, 19 insertions, 20 deletions
diff --git a/src/server/bnetserver/REST/LoginRESTService.cpp b/src/server/bnetserver/REST/LoginRESTService.cpp index 20ca3f1431d..e256c9f10a5 100644 --- a/src/server/bnetserver/REST/LoginRESTService.cpp +++ b/src/server/bnetserver/REST/LoginRESTService.cpp @@ -19,8 +19,10 @@ #include "Configuration/Config.h" #include "DatabaseEnv.h" #include "Errors.h" +#include "IpNetwork.h" #include "ProtobufJSON.h" #include "Realm.h" +#include "Resolver.h" #include "SessionManager.h" #include "SHA1.h" #include "SHA256.h" @@ -69,9 +71,9 @@ int32 handle_post_plugin(soap* soapClient) return sLoginService.HandleHttpRequest(soapClient, "POST", sLoginService._postHandlers); } -bool LoginRESTService::Start(boost::asio::io_service* ioService) +bool LoginRESTService::Start(Trinity::Asio::IoContext* ioContext) { - _ioService = ioService; + _ioContext = ioContext; _bindIP = sConfigMgr->GetStringDefault("BindIP", "0.0.0.0"); _port = sConfigMgr->GetIntDefault("LoginREST.Port", 8081); if (_port < 0 || _port > 0xFFFF) @@ -81,30 +83,28 @@ bool LoginRESTService::Start(boost::asio::io_service* ioService) } boost::system::error_code ec; - boost::asio::ip::tcp::resolver resolver(*ioService); - boost::asio::ip::tcp::resolver::iterator end; + boost::asio::ip::tcp::resolver resolver(*ioContext); std::string configuredAddress = sConfigMgr->GetStringDefault("LoginREST.ExternalAddress", "127.0.0.1"); - boost::asio::ip::tcp::resolver::query externalAddressQuery(boost::asio::ip::tcp::v4(), configuredAddress, std::to_string(_port)); - boost::asio::ip::tcp::resolver::iterator endPoint = resolver.resolve(externalAddressQuery, ec); - if (endPoint == end || ec) + Optional<boost::asio::ip::tcp::endpoint> externalAddress = Trinity::Net::Resolve(resolver, boost::asio::ip::tcp::v4(), configuredAddress, std::to_string(_port)); + if (!externalAddress) { TC_LOG_ERROR("server.rest", "Could not resolve LoginREST.ExternalAddress %s", configuredAddress.c_str()); return false; } - _externalAddress = endPoint->endpoint(); + _externalAddress = *externalAddress; configuredAddress = sConfigMgr->GetStringDefault("LoginREST.LocalAddress", "127.0.0.1"); - boost::asio::ip::tcp::resolver::query localAddressQuery(boost::asio::ip::tcp::v4(), configuredAddress, std::to_string(_port)); - endPoint = resolver.resolve(localAddressQuery, ec); - if (endPoint == end || ec) + Optional<boost::asio::ip::tcp::endpoint> localAddress = Trinity::Net::Resolve(resolver, boost::asio::ip::tcp::v4(), configuredAddress, std::to_string(_port)); + if (!localAddress) { - TC_LOG_ERROR("server.rest", "Could not resolve LoginREST.ExternalAddress %s", configuredAddress.c_str()); + TC_LOG_ERROR("server.rest", "Could not resolve LoginREST.LocalAddress %s", configuredAddress.c_str()); return false; } - _localAddress = endPoint->endpoint(); + _localAddress = *localAddress; + _localNetmask = Trinity::Net::GetDefaultNetmaskV4(_localAddress.address().to_v4()); // set up form inputs Battlenet::JSON::Login::FormInput* input; @@ -145,8 +145,7 @@ boost::asio::ip::tcp::endpoint const& LoginRESTService::GetAddressForClient(boos else if (_localAddress.address().is_loopback()) return _externalAddress; - boost::asio::ip::address_v4 netmask = boost::asio::ip::address_v4::netmask(_localAddress.address().to_v4()); - if ((netmask.to_ulong() & address.to_v4().to_ulong()) == (netmask.to_ulong() & _localAddress.address().to_v4().to_ulong())) + if (Trinity::Net::IsInNetwork(_localAddress.address().to_v4(), _localNetmask, address.to_v4())) return _localAddress; return _externalAddress; @@ -205,7 +204,7 @@ void LoginRESTService::Run() TC_LOG_DEBUG("server.rest", "Accepted connection from IP=%s", boost::asio::ip::address_v4(soapClient->GetClient()->ip).to_string().c_str()); - _ioService->post([soapClient]() + Trinity::Asio::post(*_ioContext, [soapClient]() { soapClient->GetClient()->user = (void*)&soapClient; // this allows us to make a copy of pointer inside GET/POST handlers to increment reference count soap_begin(soapClient->GetClient()); @@ -295,7 +294,7 @@ int32 LoginRESTService::HandleGetGameAccounts(std::shared_ptr<AsyncRequest> requ SendResponse(request->GetClient(), response); }))); - _ioService->post([this, request]() { HandleAsyncRequest(request); }); + Trinity::Asio::post(*_ioContext, [this, request]() { HandleAsyncRequest(request); }); return SOAP_OK; } @@ -436,7 +435,7 @@ int32 LoginRESTService::HandlePostLogin(std::shared_ptr<AsyncRequest> request) sLoginService.SendResponse(request->GetClient(), loginResult); }))); - _ioService->post([this, request]() { HandleAsyncRequest(request); }); + Trinity::Asio::post(*_ioContext, [this, request]() { HandleAsyncRequest(request); }); return SOAP_OK; } @@ -476,7 +475,7 @@ int32 LoginRESTService::HandlePostRefreshLoginTicket(std::shared_ptr<AsyncReques SendResponse(request->GetClient(), loginRefreshResult); }))); - _ioService->post([this, request]() { HandleAsyncRequest(request); }); + Trinity::Asio::post(*_ioContext, [this, request]() { HandleAsyncRequest(request); }); return SOAP_OK; } @@ -494,7 +493,7 @@ void LoginRESTService::HandleAsyncRequest(std::shared_ptr<AsyncRequest> request) { if (!request->InvokeIfReady()) { - _ioService->post([this, request]() { HandleAsyncRequest(request); }); + Trinity::Asio::post(*_ioContext, [this, request]() { HandleAsyncRequest(request); }); } else if (request->GetResponseStatus()) { |