Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Toggle main menu visibility
Loading...
Searching...
No Matches
SFSoap.cpp
Go to the documentation of this file.
1
/*
2
* This file is part of Project SkyFire https://www.projectskyfire.org.
3
* See LICENSE.md file for Copyright information
4
*/
5
6
#include "
AccountMgr.h
"
7
#include "
Log.h
"
8
#include "
SFSoap.h
"
9
#include "soapH.h"
10
#include "soapStub.h"
11
#include "
World.h
"
12
13
void
SFSoapRunnable::Run
()
14
{
15
struct
soap soap;
16
soap_init(&soap);
17
soap_set_imode(&soap, SOAP_C_UTFSTRING);
18
soap_set_omode(&soap, SOAP_C_UTFSTRING);
19
20
// check every 3 seconds if world ended
21
soap.accept_timeout = 3;
22
soap.recv_timeout = 5;
23
soap.send_timeout = 5;
24
if
(!soap_valid_socket(soap_bind(&soap,
_host
.c_str(),
_port
, 100)))
25
{
26
SF_LOG_ERROR
(
"network.soap"
,
"Couldn't bind to %s:%d"
,
_host
.c_str(),
_port
);
27
exit(-1);
28
}
29
30
SF_LOG_INFO
(
"network.soap"
,
"Bound to http://%s:%d"
,
_host
.c_str(),
_port
);
31
32
while
(!
World::IsStopped
())
33
{
34
if
(!soap_valid_socket(soap_accept(&soap)))
35
continue
;
// ran into an accept timeout
36
37
SF_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);
38
struct
soap* thread_soap = soap_copy(&soap);
// make a safe copy
39
40
process_message
(thread_soap);
41
}
42
43
soap_done(&soap);
44
}
45
46
void
SFSoapRunnable::process_message
(
struct
soap* soap)
47
{
48
soap_serve(soap);
49
soap_destroy(soap);
// dealloc C++ data
50
soap_end(soap);
// dealloc data and clean up
51
soap_done(soap);
// detach soap struct
52
free(soap);
53
}
54
/*
55
Code used for generating stubs:
56
57
int ns1__executeCommand(char* command, char** result);
58
*/
59
int
ns1__executeCommand
(soap* soap,
char
* command,
char
** result)
60
{
61
// security check
62
if
(!soap->userid || !soap->passwd)
63
{
64
SF_LOG_INFO
(
"network.soap"
,
"Client didn't provide login information"
);
65
return
401;
66
}
67
68
uint32
accountId =
AccountMgr::GetId
(soap->userid);
69
if
(!accountId)
70
{
71
SF_LOG_INFO
(
"network.soap"
,
"Client used invalid username '%s'"
, soap->userid);
72
return
401;
73
}
74
75
if
(!
AccountMgr::CheckPassword
(accountId, soap->passwd))
76
{
77
SF_LOG_INFO
(
"network.soap"
,
"Invalid password for account '%s'"
, soap->userid);
78
return
401;
79
}
80
81
if
(
AccountMgr::GetSecurity
(accountId) <
AccountTypes::SEC_ADMINISTRATOR
)
82
{
83
SF_LOG_INFO
(
"network.soap"
,
"%s's gmlevel is too low"
, soap->userid);
84
return
403;
85
}
86
87
if
(!command || !*command)
88
return
soap_sender_fault(soap,
"Command can not be empty"
,
"The supplied command was an empty string"
);
89
90
SF_LOG_INFO
(
"network.soap"
,
"Received command '%s'"
, command);
91
SOAPCommand
connection;
92
93
// commands are executed in the world thread. We have to wait for them to be completed
94
{
95
// CliCommandHolder will be deleted from world, accessing after queueing is NOT save
96
CliCommandHolder
* cmd =
new
CliCommandHolder
(&connection, command, &
SOAPCommand::print
, &
SOAPCommand::commandFinished
);
97
sWorld
->QueueCliCommand(cmd);
98
}
99
100
// wait for callback to complete command
101
102
connection.
wait
();
103
104
// alright, command finished
105
106
char
* printBuffer = soap_strdup(soap, connection.
m_printBuffer
.c_str());
107
if
(connection.
hasCommandSucceeded
())
108
{
109
*result = printBuffer;
110
return
SOAP_OK;
111
}
112
else
113
return
soap_sender_fault(soap, printBuffer, printBuffer);
114
}
115
116
void
SOAPCommand::commandFinished
(
void
* soapconnection,
bool
success)
117
{
118
SOAPCommand
* con = (
SOAPCommand
*)soapconnection;
119
con->
complete
(success);
120
}
121
123
//
124
// Namespace Definition Table
125
//
127
128
struct
Namespace
namespaces
[] =
129
{ {
"SOAP-ENV"
,
"http://schemas.xmlsoap.org/soap/envelope/"
, NULL, NULL },
// must be first
130
{
"SOAP-ENC"
,
"http://schemas.xmlsoap.org/soap/encoding/"
, NULL, NULL },
// must be second
131
{
"xsi"
,
"http://www.w3.org/1999/XMLSchema-instance"
,
"http://www.w3.org/*/XMLSchema-instance"
, NULL },
132
{
"xsd"
,
"http://www.w3.org/1999/XMLSchema"
,
"http://www.w3.org/*/XMLSchema"
, NULL },
133
{
"ns1"
,
"urn:SF"
, NULL, NULL },
// "ns1" namespace prefix
134
{ NULL, NULL, NULL, NULL }
135
};
AccountMgr.h
AccountTypes::SEC_ADMINISTRATOR
@ SEC_ADMINISTRATOR
Definition
Common.h:133
uint32
std::uint32_t uint32
Definition
Define.h:77
Log.h
SF_LOG_DEBUG
#define SF_LOG_DEBUG(filterType__,...)
Definition
Log.h:134
SF_LOG_ERROR
#define SF_LOG_ERROR(filterType__,...)
Definition
Log.h:143
SF_LOG_INFO
#define SF_LOG_INFO(filterType__,...)
Definition
Log.h:137
namespaces
struct Namespace namespaces[]
Definition
SFSoap.cpp:128
ns1__executeCommand
int ns1__executeCommand(soap *soap, char *command, char **result)
Definition
SFSoap.cpp:59
SFSoap.h
World.h
AccountMgr::CheckPassword
static bool CheckPassword(uint32 accountId, std::string password)
Definition
AccountMgr.cpp:298
AccountMgr::GetSecurity
static AccountTypes GetSecurity(uint32 accountId)
Definition
AccountMgr.cpp:249
AccountMgr::GetId
static uint32 GetId(std::string const &username)
Definition
AccountMgr.cpp:240
SFSoapRunnable::process_message
void process_message(struct soap *soap)
Definition
SFSoap.cpp:46
SFSoapRunnable::_host
std::string _host
Definition
SFSoap.h:34
SFSoapRunnable::_port
uint16 _port
Definition
SFSoap.h:35
SFSoapRunnable::Run
void Run()
Definition
SFSoap.cpp:13
SOAPCommand
Definition
SFSoap.h:84
SOAPCommand::wait
void wait()
Definition
SFSoap.h:100
SOAPCommand::commandFinished
static void commandFinished(void *callbackArg, bool success)
Definition
SFSoap.cpp:116
SOAPCommand::hasCommandSucceeded
bool hasCommandSucceeded() const
Definition
SFSoap.h:122
SOAPCommand::SOAPCommand
SOAPCommand()
Definition
SFSoap.h:86
SOAPCommand::print
static void print(void *callbackArg, const char *msg)
Definition
SFSoap.h:127
SOAPCommand::m_printBuffer
std::string m_printBuffer
Definition
SFSoap.h:135
SOAPCommand::complete
void complete(bool success)
Definition
SFSoap.h:106
World::IsStopped
static bool IsStopped()
Definition
World.h:675
sWorld
#define sWorld
Definition
World.h:910
CliCommandHolder
Storage class for commands issued for delayed execution.
Definition
World.h:524
src
server
worldserver
SFSoap
SFSoap.cpp
Generated on
for Project SkyFire Core by
1.17.0