Fixed windows project files - added SOAP
Added project file for SOAP Applied Trinity coding standards to TCSoap files --HG-- branch : trunk
This commit is contained in:
@@ -24,66 +24,64 @@
|
||||
|
||||
void TCSoapRunnable::run()
|
||||
{
|
||||
// create pool
|
||||
SOAPWorkingThread pool;
|
||||
pool.activate (THR_NEW_LWP | THR_JOINABLE, POOL_SIZE);
|
||||
// create pool
|
||||
SOAPWorkingThread pool;
|
||||
pool.activate (THR_NEW_LWP | THR_JOINABLE, POOL_SIZE);
|
||||
|
||||
struct soap soap;
|
||||
int m, s;
|
||||
soap_init(&soap);
|
||||
soap_set_imode(&soap, SOAP_C_UTFSTRING);
|
||||
soap_set_omode(&soap, SOAP_C_UTFSTRING);
|
||||
m = soap_bind(&soap, m_host.c_str(), m_port, 100);
|
||||
struct soap soap;
|
||||
int m, s;
|
||||
soap_init(&soap);
|
||||
soap_set_imode(&soap, SOAP_C_UTFSTRING);
|
||||
soap_set_omode(&soap, SOAP_C_UTFSTRING);
|
||||
m = soap_bind(&soap, m_host.c_str(), m_port, 100);
|
||||
|
||||
// check every 3 seconds if world ended
|
||||
soap.accept_timeout = 3;
|
||||
// check every 3 seconds if world ended
|
||||
soap.accept_timeout = 3;
|
||||
|
||||
soap.recv_timeout = 5;
|
||||
soap.send_timeout = 5;
|
||||
if (m < 0)
|
||||
soap.recv_timeout = 5;
|
||||
soap.send_timeout = 5;
|
||||
if (m < 0)
|
||||
{
|
||||
sLog.outError("TCSoap: couldn't bind to %s:%d", m_host.c_str(), m_port);
|
||||
exit(-1);
|
||||
sLog.outError("TCSoap: couldn't bind to %s:%d", m_host.c_str(), m_port);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
sLog.outString("TCSoap: bound to http://%s:%d", m_host.c_str(), m_port);
|
||||
sLog.outString("TCSoap: bound to http://%s:%d", m_host.c_str(), m_port);
|
||||
|
||||
while(!World::IsStopped())
|
||||
while(!World::IsStopped())
|
||||
{
|
||||
s = soap_accept(&soap);
|
||||
s = soap_accept(&soap);
|
||||
|
||||
if (s < 0)
|
||||
{
|
||||
// ran into an accept timeout
|
||||
continue;
|
||||
}
|
||||
if (s < 0)
|
||||
continue; // ran into an accept timeout
|
||||
|
||||
sLog.outDebug("TCSoap: 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);
|
||||
struct soap* thread_soap = soap_copy(&soap);// make a safe copy
|
||||
sLog.outDebug("TCSoap: 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);
|
||||
struct soap* thread_soap = soap_copy(&soap);// make a safe copy
|
||||
|
||||
ACE_Message_Block *mb = new ACE_Message_Block(sizeof(struct soap*));
|
||||
ACE_OS::memcpy (mb->wr_ptr (), &thread_soap, sizeof(struct soap*));
|
||||
pool.putq(mb);
|
||||
ACE_Message_Block *mb = new ACE_Message_Block(sizeof(struct soap*));
|
||||
ACE_OS::memcpy (mb->wr_ptr(), &thread_soap, sizeof(struct soap*));
|
||||
pool.putq(mb);
|
||||
}
|
||||
pool.msg_queue ()->deactivate ();
|
||||
pool.wait ();
|
||||
|
||||
soap_done(&soap);
|
||||
pool.msg_queue()->deactivate();
|
||||
pool.wait();
|
||||
|
||||
soap_done(&soap);
|
||||
}
|
||||
|
||||
void SOAPWorkingThread::process_message (ACE_Message_Block *mb)
|
||||
{
|
||||
ACE_TRACE (ACE_TEXT ("SOAPWorkingThread::process_message"));
|
||||
ACE_TRACE (ACE_TEXT ("SOAPWorkingThread::process_message"));
|
||||
|
||||
struct soap* soap;
|
||||
ACE_OS::memcpy (&soap, mb->rd_ptr (), sizeof(struct soap*));
|
||||
mb->release ();
|
||||
struct soap* soap;
|
||||
ACE_OS::memcpy (&soap, mb->rd_ptr (), sizeof(struct soap*));
|
||||
mb->release();
|
||||
|
||||
soap_serve(soap);
|
||||
soap_destroy(soap); // dealloc C++ data
|
||||
soap_end(soap); // dealloc data and clean up
|
||||
soap_done(soap); // detach soap struct
|
||||
free(soap);
|
||||
soap_serve(soap);
|
||||
soap_destroy(soap); // dealloc C++ data
|
||||
soap_end(soap); // dealloc data and clean up
|
||||
soap_done(soap); // detach soap struct
|
||||
free(soap);
|
||||
}
|
||||
/*
|
||||
Code used for generating stubs:
|
||||
@@ -92,71 +90,71 @@ int ns1__executeCommand(char* command, char** result);
|
||||
*/
|
||||
int ns1__executeCommand(soap* soap, char* command, char** result)
|
||||
{
|
||||
// security check
|
||||
if (!soap->userid || !soap->passwd)
|
||||
// security check
|
||||
if (!soap->userid || !soap->passwd)
|
||||
{
|
||||
sLog.outDebug("TCSoap: Client didn't provide login information");
|
||||
return 401;
|
||||
sLog.outDebug("TCSoap: Client didn't provide login information");
|
||||
return 401;
|
||||
}
|
||||
|
||||
uint32 accountId = accmgr.GetId(soap->userid);
|
||||
if(!accountId)
|
||||
uint32 accountId = accmgr.GetId(soap->userid);
|
||||
if(!accountId)
|
||||
{
|
||||
sLog.outDebug("TCSoap: Client used invalid username '%s'", soap->userid);
|
||||
return 401;
|
||||
sLog.outDebug("TCSoap: Client used invalid username '%s'", soap->userid);
|
||||
return 401;
|
||||
}
|
||||
|
||||
if(!accmgr.CheckPassword(accountId, soap->passwd))
|
||||
if(!accmgr.CheckPassword(accountId, soap->passwd))
|
||||
{
|
||||
sLog.outDebug("TCSoap: invalid password for account '%s'", soap->userid);
|
||||
return 401;
|
||||
sLog.outDebug("TCSoap: invalid password for account '%s'", soap->userid);
|
||||
return 401;
|
||||
}
|
||||
|
||||
if(accmgr.GetSecurity(accountId) < SEC_ADMINISTRATOR)
|
||||
if(accmgr.GetSecurity(accountId) < SEC_ADMINISTRATOR)
|
||||
{
|
||||
sLog.outDebug("TCSoap: %s's gmlevel is too low", soap->userid);
|
||||
return 403;
|
||||
sLog.outDebug("TCSoap: %s's gmlevel is too low", soap->userid);
|
||||
return 403;
|
||||
}
|
||||
|
||||
if(!command || !*command)
|
||||
return soap_sender_fault(soap, "Command mustn't be empty", "The supplied command was an empty string");
|
||||
if(!command || !*command)
|
||||
return soap_sender_fault(soap, "Command mustn't be empty", "The supplied command was an empty string");
|
||||
|
||||
sLog.outDebug("TCSoap: got command '%s'", command);
|
||||
SOAPCommand connection;
|
||||
sLog.outDebug("TCSoap: got command '%s'", command);
|
||||
SOAPCommand connection;
|
||||
|
||||
// commands are executed in the world thread. We have to wait for them to be completed
|
||||
{
|
||||
// CliCommandHolder will be deleted from world, accessing after queueing is NOT save
|
||||
CliCommandHolder* cmd = new CliCommandHolder(&connection, command, &SOAPCommand::print, &SOAPCommand::commandFinished);
|
||||
sWorld.QueueCliCommand(cmd);
|
||||
}
|
||||
|
||||
// wait for callback to complete command
|
||||
|
||||
int acc = connection.pendingCommands.acquire();
|
||||
if(acc)
|
||||
// commands are executed in the world thread. We have to wait for them to be completed
|
||||
{
|
||||
sLog.outError("TCSoap: Error while acquiring lock, acc = %i, errno = %u", acc, errno);
|
||||
// CliCommandHolder will be deleted from world, accessing after queueing is NOT save
|
||||
CliCommandHolder* cmd = new CliCommandHolder(&connection, command, &SOAPCommand::print, &SOAPCommand::commandFinished);
|
||||
sWorld.QueueCliCommand(cmd);
|
||||
}
|
||||
|
||||
// alright, command finished
|
||||
// wait for callback to complete command
|
||||
|
||||
char* printBuffer = soap_strdup(soap, connection.m_printBuffer.c_str());
|
||||
if(connection.hasCommandSucceeded())
|
||||
int acc = connection.pendingCommands.acquire();
|
||||
if(acc)
|
||||
{
|
||||
*result = printBuffer;
|
||||
return SOAP_OK;
|
||||
sLog.outError("TCSoap: Error while acquiring lock, acc = %i, errno = %u", acc, errno);
|
||||
}
|
||||
else
|
||||
return soap_sender_fault(soap, printBuffer, printBuffer);
|
||||
|
||||
// alright, command finished
|
||||
|
||||
char* printBuffer = soap_strdup(soap, connection.m_printBuffer.c_str());
|
||||
if(connection.hasCommandSucceeded())
|
||||
{
|
||||
*result = printBuffer;
|
||||
return SOAP_OK;
|
||||
}
|
||||
else
|
||||
return soap_sender_fault(soap, printBuffer, printBuffer);
|
||||
}
|
||||
|
||||
|
||||
void SOAPCommand::commandFinished(void* soapconnection, bool success)
|
||||
{
|
||||
SOAPCommand* con = (SOAPCommand*)soapconnection;
|
||||
con->setCommandSuccess(success);
|
||||
con->pendingCommands.release();
|
||||
SOAPCommand* con = (SOAPCommand*)soapconnection;
|
||||
con->setCommandSuccess(success);
|
||||
con->pendingCommands.release();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -166,10 +164,10 @@ void SOAPCommand::commandFinished(void* soapconnection, bool success)
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Namespace namespaces[] =
|
||||
{ { "SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/" }, // must be first
|
||||
{ { "SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/" }, // must be first
|
||||
{ "SOAP-ENC", "http://schemas.xmlsoap.org/soap/encoding/" }, // must be second
|
||||
{ "xsi", "http://www.w3.org/1999/XMLSchema-instance", "http://www.w3.org/*/XMLSchema-instance" },
|
||||
{ "xsd", "http://www.w3.org/1999/XMLSchema", "http://www.w3.org/*/XMLSchema" },
|
||||
{ "ns1", "urn:TC" }, // "ns1" namespace prefix
|
||||
{ NULL, NULL }
|
||||
};
|
||||
};
|
||||
|
||||
@@ -34,87 +34,87 @@
|
||||
|
||||
class TCSoapRunnable: public ACE_Based::Runnable
|
||||
{
|
||||
public:
|
||||
TCSoapRunnable() { }
|
||||
void run();
|
||||
void setListenArguments(std::string host, uint16 port)
|
||||
{
|
||||
m_host = host;
|
||||
m_port = port;
|
||||
}
|
||||
private:
|
||||
std::string m_host;
|
||||
uint16 m_port;
|
||||
public:
|
||||
TCSoapRunnable() { }
|
||||
void run();
|
||||
void setListenArguments(std::string host, uint16 port)
|
||||
{
|
||||
m_host = host;
|
||||
m_port = port;
|
||||
}
|
||||
private:
|
||||
std::string m_host;
|
||||
uint16 m_port;
|
||||
};
|
||||
|
||||
class SOAPWorkingThread : public ACE_Task<ACE_MT_SYNCH>
|
||||
{
|
||||
public:
|
||||
SOAPWorkingThread ()
|
||||
{ }
|
||||
public:
|
||||
SOAPWorkingThread() { }
|
||||
|
||||
virtual int svc (void)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
ACE_Message_Block *mb = 0;
|
||||
if (this->getq (mb) == -1)
|
||||
{
|
||||
ACE_DEBUG ((LM_INFO,
|
||||
ACE_TEXT ("(%t) Shutting down\n")));
|
||||
break;
|
||||
}
|
||||
virtual int svc(void)
|
||||
{
|
||||
while(1)
|
||||
{
|
||||
ACE_Message_Block *mb = 0;
|
||||
if (this->getq(mb) == -1)
|
||||
{
|
||||
ACE_DEBUG((LM_INFO,
|
||||
ACE_TEXT("(%t) Shutting down\n")));
|
||||
break;
|
||||
}
|
||||
|
||||
// Process the message.
|
||||
process_message (mb);
|
||||
}
|
||||
// Process the message.
|
||||
process_message(mb);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
private:
|
||||
void process_message (ACE_Message_Block *mb);
|
||||
return 0;
|
||||
}
|
||||
private:
|
||||
void process_message(ACE_Message_Block *mb);
|
||||
};
|
||||
|
||||
|
||||
class SOAPCommand
|
||||
{
|
||||
public:
|
||||
SOAPCommand()
|
||||
{
|
||||
ACE_ASSERT (pendingCommands.open("pendingCommands",
|
||||
ACE_SV_Semaphore_Simple::ACE_CREATE,
|
||||
0) != -1);
|
||||
public:
|
||||
SOAPCommand()
|
||||
{
|
||||
ACE_ASSERT(pendingCommands.open("pendingCommands",
|
||||
ACE_SV_Semaphore_Simple::ACE_CREATE,
|
||||
0) != -1);
|
||||
}
|
||||
|
||||
}
|
||||
~SOAPCommand()
|
||||
{
|
||||
}
|
||||
~SOAPCommand()
|
||||
{
|
||||
}
|
||||
|
||||
void appendToPrintBuffer(const char* msg)
|
||||
{
|
||||
m_printBuffer += msg;
|
||||
}
|
||||
void appendToPrintBuffer(const char* msg)
|
||||
{
|
||||
m_printBuffer += msg;
|
||||
}
|
||||
|
||||
ACE_SV_Semaphore_Simple pendingCommands;
|
||||
ACE_SV_Semaphore_Simple pendingCommands;
|
||||
|
||||
void setCommandSuccess(bool val)
|
||||
{
|
||||
m_success = val;
|
||||
}
|
||||
bool hasCommandSucceeded()
|
||||
{
|
||||
return m_success;
|
||||
}
|
||||
void setCommandSuccess(bool val)
|
||||
{
|
||||
m_success = val;
|
||||
}
|
||||
|
||||
static void print(void* callbackArg, const char* msg)
|
||||
{
|
||||
((SOAPCommand*)callbackArg)->appendToPrintBuffer(msg);
|
||||
}
|
||||
bool hasCommandSucceeded()
|
||||
{
|
||||
return m_success;
|
||||
}
|
||||
|
||||
static void commandFinished(void* callbackArg, bool success);
|
||||
static void print(void* callbackArg, const char* msg)
|
||||
{
|
||||
((SOAPCommand*)callbackArg)->appendToPrintBuffer(msg);
|
||||
}
|
||||
|
||||
bool m_success;
|
||||
std::string m_printBuffer;
|
||||
static void commandFinished(void* callbackArg, bool success);
|
||||
|
||||
bool m_success;
|
||||
std::string m_printBuffer;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user