AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
ACSoap.cpp File Reference
#include "ACSoap.h"
#include "AccountMgr.h"
#include "Log.h"
#include "World.h"
#include "soapStub.h"

Go to the source code of this file.

Functions

void ACSoapThread (const std::string &host, uint16 port)
 
void process_message (struct soap *soap_message)
 
int ns1__executeCommand (soap *soap, char *command, char **result)
 

Variables

struct Namespace namespaces []
 

Function Documentation

◆ ACSoapThread()

void ACSoapThread ( const std::string &  host,
uint16  port 
)
25{
26 struct soap soap;
27 soap_init(&soap);
28 soap_set_imode(&soap, SOAP_C_UTFSTRING);
29 soap_set_omode(&soap, SOAP_C_UTFSTRING);
30
31 // check every 3 seconds if world ended
32 soap.accept_timeout = 3;
33 soap.recv_timeout = 5;
34 soap.send_timeout = 5;
35
36 if (!soap_valid_socket(soap_bind(&soap, host.c_str(), port, 100)))
37 {
38 LOG_ERROR("network.soap", "ACSoap: couldn't bind to {}:{}", host, port);
39 exit(-1);
40 }
41
42 LOG_INFO("network.soap", "ACSoap: bound to http://{}:{}", host, port);
43
44 while (!World::IsStopped())
45 {
46 if (!soap_valid_socket(soap_accept(&soap)))
47 continue; // ran into an accept timeout
48
49 LOG_DEBUG("network.soap", "ACSoap: accepted connection from IP={}.{}.{}.{}", (int)(soap.ip >> 24) & 0xFF, (int)(soap.ip >> 16) & 0xFF, (int)(soap.ip >> 8) & 0xFF, (int)soap.ip & 0xFF);
50 struct soap* thread_soap = soap_copy(&soap);// make a safe copy
51
52 process_message(thread_soap);
53 }
54
55 soap_destroy(&soap);
56 soap_end(&soap);
57 soap_done(&soap);
58}
#define LOG_INFO(filterType__,...)
Definition: Log.h:165
#define LOG_ERROR(filterType__,...)
Definition: Log.h:157
#define LOG_DEBUG(filterType__,...)
Definition: Log.h:169
void process_message(struct soap *soap_message)
Definition: ACSoap.cpp:60
static bool IsStopped()
Definition: World.h:254

References World::IsStopped(), LOG_DEBUG, LOG_ERROR, LOG_INFO, and process_message().

Referenced by main().

◆ ns1__executeCommand()

int ns1__executeCommand ( soap *  soap,
char *  command,
char **  result 
)
75{
76 // security check
77 if (!soap->userid || !soap->passwd)
78 {
79 LOG_DEBUG("network.soap", "ACSoap: Client didn't provide login information");
80 return 401;
81 }
82
83 uint32 accountId = AccountMgr::GetId(soap->userid);
84 if (!accountId)
85 {
86 LOG_DEBUG("network", "ACSoap: Client used invalid username '{}'", soap->userid);
87 return 401;
88 }
89
90 if (!AccountMgr::CheckPassword(accountId, soap->passwd))
91 {
92 LOG_DEBUG("network.soap", "ACSoap: invalid password for account '{}'", soap->userid);
93 return 401;
94 }
95
97 {
98 LOG_DEBUG("network.soap", "ACSoap: {}'s gmlevel is too low", soap->userid);
99 return 403;
100 }
101
102 if (!command || !*command)
103 return soap_sender_fault(soap, "Command can not be empty", "The supplied command was an empty string");
104
105 LOG_DEBUG("network.soap", "ACSoap: got command '{}'", command);
106 SOAPCommand connection;
107
108 // commands are executed in the world thread. We have to wait for them to be completed
109 {
110 // CliCommandHolder will be deleted from world, accessing after queueing is NOT save
112 sWorld->QueueCliCommand(cmd);
113 }
114
115 // Wait until the command has finished executing
116 connection.finishedPromise.get_future().wait();
117
118 // The command has finished executing already
119 char* printBuffer = soap_strdup(soap, connection.m_printBuffer.c_str());
120 if (connection.hasCommandSucceeded())
121 {
122 *result = printBuffer;
123 return SOAP_OK;
124 }
125 else
126 return soap_sender_fault(soap, printBuffer, printBuffer);
127}
@ SEC_ADMINISTRATOR
Definition: Common.h:60
std::uint32_t uint32
Definition: Define.h:107
#define sWorld
Definition: World.h:443
bool CheckPassword(uint32 accountId, std::string password)
Definition: AccountMgr.cpp:272
uint32 GetSecurity(uint32 accountId)
Definition: AccountMgr.cpp:238
uint32 GetId(std::string const &username)
Definition: AccountMgr.cpp:229
Definition: ACSoap.h:28
static void commandFinished(void *callbackArg, bool success)
Definition: ACSoap.cpp:129
bool hasCommandSucceeded() const
Definition: ACSoap.h:46
static void print(void *callbackArg, std::string_view msg)
Definition: ACSoap.h:51
std::string m_printBuffer
Definition: ACSoap.h:59
std::promise< void > finishedPromise
Definition: ACSoap.h:60
Storage class for commands issued for delayed execution.
Definition: IWorld.h:34

References AccountMgr::CheckPassword(), SOAPCommand::commandFinished(), SOAPCommand::finishedPromise, AccountMgr::GetId(), AccountMgr::GetSecurity(), SOAPCommand::hasCommandSucceeded(), LOG_DEBUG, SOAPCommand::m_printBuffer, SOAPCommand::print(), SEC_ADMINISTRATOR, and sWorld.

◆ process_message()

void process_message ( struct soap *  soap_message)
61{
62 LOG_TRACE("network.soap", "SOAPWorkingThread::process_message");
63
64 soap_serve(soap_message);
65 soap_destroy(soap_message); // dealloc C++ data
66 soap_end(soap_message); // dealloc data and clean up
67 soap_free(soap_message); // detach soap struct and fre up the memory
68}
#define LOG_TRACE(filterType__,...)
Definition: Log.h:173

References LOG_TRACE.

Referenced by ACSoapThread().

Variable Documentation

◆ namespaces

struct Namespace namespaces[]
Initial value:
=
{
{ "SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/", nullptr, nullptr },
{ "SOAP-ENC", "http://schemas.xmlsoap.org/soap/encoding/", nullptr, nullptr },
{ "xsi", "http://www.w3.org/1999/XMLSchema-instance", "http://www.w3.org/*/XMLSchema-instance", nullptr },
{ "xsd", "http://www.w3.org/1999/XMLSchema", "http://www.w3.org/*/XMLSchema", nullptr },
{ "ns1", "urn:AC", nullptr, nullptr },
{ nullptr, nullptr, nullptr, nullptr }
}