TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
TCSoap.cpp File Reference
#include "TCSoap.h"
#include "soapH.h"
#include "soapStub.h"
#include "World.h"
#include "AccountMgr.h"
#include "Log.h"
+ Include dependency graph for TCSoap.cpp:

Functions

void TCSoapThread (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

int ns1__executeCommand ( soap soap,
char *  command,
char **  result 
)
73 {
74  // security check
75  if (!soap->userid || !soap->passwd)
76  {
77  TC_LOG_INFO("network.soap", "Client didn't provide login information");
78  return 401;
79  }
80 
81  uint32 accountId = AccountMgr::GetId(soap->userid);
82  if (!accountId)
83  {
84  TC_LOG_INFO("network.soap", "Client used invalid username '%s'", soap->userid);
85  return 401;
86  }
87 
88  if (!AccountMgr::CheckPassword(accountId, soap->passwd))
89  {
90  TC_LOG_INFO("network.soap", "Invalid password for account '%s'", soap->userid);
91  return 401;
92  }
93 
95  {
96  TC_LOG_INFO("network.soap", "%s's gmlevel is too low", soap->userid);
97  return 403;
98  }
99 
100  if (!command || !*command)
101  return soap_sender_fault(soap, "Command can not be empty", "The supplied command was an empty string");
102 
103  TC_LOG_INFO("network.soap", "Received command '%s'", command);
104  SOAPCommand connection;
105 
106  // commands are executed in the world thread. We have to wait for them to be completed
107  {
108  // CliCommandHolder will be deleted from world, accessing after queueing is NOT safe
110  sWorld->QueueCliCommand(cmd);
111  }
112 
113  // Wait until the command has finished executing
114  connection.finishedPromise.get_future().wait();
115 
116  // The command has finished executing already
117  char* printBuffer = soap_strdup(soap, connection.m_printBuffer.c_str());
118  if (connection.hasCommandSucceeded())
119  {
120  *result = printBuffer;
121  return SOAP_OK;
122  }
123  else
124  return soap_sender_fault(soap, printBuffer, printBuffer);
125 }
SOAP_FMAC1 char *SOAP_FMAC2 soap_strdup(struct soap *soap, const char *s)
Definition: stdsoap2.cpp:2122
static bool CheckPassword(uint32 accountId, std::string password)
Definition: AccountMgr.cpp:333
const char * userid
Definition: stdsoap2.h:1974
Definition: Common.h:111
static void print(void *callbackArg, const char *msg)
Definition: TCSoap.h:57
#define sWorld
Definition: World.h:887
Storage class for commands issued for delayed execution.
Definition: World.h:507
const char * passwd
Definition: stdsoap2.h:1975
static uint32 GetSecurity(uint32 accountId)
Definition: AccountMgr.cpp:284
bool hasCommandSucceeded() const
Definition: TCSoap.h:52
SOAP_FMAC1 int SOAP_FMAC2 soap_sender_fault(struct soap *soap, const char *faultstring, const char *faultdetailXML)
Definition: stdsoap2.cpp:16739
static uint32 GetId(std::string const &username)
Definition: AccountMgr.cpp:275
uint32_t uint32
Definition: Define.h:150
static void commandFinished(void *callbackArg, bool success)
Definition: TCSoap.cpp:127
#define SOAP_OK
Definition: stdsoap2.h:1245
Definition: TCSoap.h:29
#define TC_LOG_INFO(filterType__,...)
Definition: Log.h:201
std::string m_printBuffer
Definition: TCSoap.h:65
std::promise< void > finishedPromise
Definition: TCSoap.h:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void process_message ( struct soap soap_message)
58 {
59  TC_LOG_TRACE("network.soap", "SOAPWorkingThread::process_message");
60 
61  soap_serve(soap_message);
62  soap_destroy(soap_message); // dealloc C++ data
63  soap_end(soap_message); // dealloc data and clean up
64  soap_done(soap_message); // detach soap struct
65  free(soap_message);
66 }
#define soap_destroy(soap)
Definition: stdsoap2.h:2295
SOAP_FMAC1 void SOAP_FMAC2 soap_done(struct soap *soap)
Definition: stdsoap2.cpp:5181
#define TC_LOG_TRACE(filterType__,...)
Definition: Log.h:195
SOAP_FMAC1 void SOAP_FMAC2 soap_end(struct soap *soap)
Definition: stdsoap2.cpp:9279
SOAP_FMAC5 int SOAP_FMAC6 soap_serve(struct soap *soap)
Definition: soapServer.cpp:20

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void TCSoapThread ( const std::string &  host,
uint16  port 
)
26 {
27  struct soap soap;
28  soap_init(&soap);
31 
32  // check every 3 seconds if world ended
33  soap.accept_timeout = 3;
34  soap.recv_timeout = 5;
35  soap.send_timeout = 5;
36  if (!soap_valid_socket(soap_bind(&soap, host.c_str(), port, 100)))
37  {
38  TC_LOG_ERROR("network.soap", "Couldn't bind to %s:%d", host.c_str(), port);
39  exit(-1);
40  }
41 
42  TC_LOG_INFO("network.soap", "Bound to http://%s:%d", host.c_str(), port);
43 
44  while (!World::IsStopped())
45  {
47  continue; // ran into an accept timeout
48 
49  TC_LOG_DEBUG("network.soap", "Accepted connection from IP=%d.%d.%d.%d", (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  process_message(thread_soap);
52  }
53 
54  soap_done(&soap);
55 }
unsigned long ip
Definition: stdsoap2.h:2097
#define SOAP_C_UTFSTRING
Definition: stdsoap2.h:1375
#define soap_valid_socket(n)
Definition: stdsoap2.h:859
Definition: stdsoap2.h:1933
SOAP_FMAC1 SOAP_SOCKET SOAP_FMAC2 soap_accept(struct soap *soap)
Definition: stdsoap2.cpp:4971
int accept_timeout
Definition: stdsoap2.h:1950
SOAP_FMAC1 SOAP_SOCKET SOAP_FMAC2 soap_bind(struct soap *soap, const char *host, int port, int backlog)
Definition: stdsoap2.cpp:4743
static bool IsStopped()
Definition: World.h:663
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
#define soap_set_omode(soap, n)
Definition: stdsoap2.h:2291
#define soap_set_imode(soap, n)
Definition: stdsoap2.h:2289
SOAP_FMAC1 void SOAP_FMAC2 soap_done(struct soap *soap)
Definition: stdsoap2.cpp:5181
char host[SOAP_TAGLEN]
Definition: stdsoap2.h:2094
SOAP_FMAC1 struct soap *SOAP_FMAC2 soap_copy(const struct soap *soap)
Definition: stdsoap2.cpp:8660
int send_timeout
Definition: stdsoap2.h:1948
void process_message(struct soap *soap_message)
Definition: TCSoap.cpp:57
#define soap_init(soap)
Definition: stdsoap2.h:2275
int recv_timeout
Definition: stdsoap2.h:1947
int port
Definition: stdsoap2.h:2098
#define TC_LOG_INFO(filterType__,...)
Definition: Log.h:201
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

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