EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
APIServiceManager Class Reference

Generic Base Class used to derive classes for specific service handlers (character, corporation, etc) More...

#include "APIServiceManager.h"

Inheritance diagram for APIServiceManager:
Collaboration diagram for APIServiceManager:

Public Member Functions

 APIServiceManager (const PyServiceMgr &services)
 
PyServiceMgrservices ()
 
virtual std::tr1::shared_ptr
< std::string > 
ProcessCall (const APICommandCall *pAPICommandCall)
 
std::tr1::shared_ptr< std::string > BuildErrorXMLResponse (std::string errorCode, std::string errorMessage)
 

Protected Member Functions

bool _AuthenticateUserNamePassword (std::string userName, std::string password)
 
bool _AuthenticateFullAPIQuery (std::string userID, std::string apiKey)
 
bool _AuthenticateLimitedAPIQuery (std::string userID, std::string apiKey)
 
void _BuildXMLHeader ()
 
void _CloseXMLHeader (uint32 cacheStyle)
 
void _BuildXMLRowSet (std::string name, std::string key, const std::vector< std::string > *columns)
 
void _CloseXMLRowSet ()
 
void _BuildXMLRow (const std::vector< std::string > *columns)
 
void _BuildXMLTag (std::string name)
 
void _BuildXMLTag (std::string name, const std::vector< std::pair< std::string, std::string > > *params)
 
void _BuildXMLTag (std::string name, const std::vector< std::pair< std::string, std::string > > *params, std::string value)
 
void _CloseXMLTag ()
 
void _BuildSingleXMLTag (std::string name, std::string param)
 
void _BuildErrorXMLTag (std::string code, std::string param)
 
std::tr1::shared_ptr< std::string > _GetXMLDocumentString ()
 

Protected Attributes

APIServiceDB m_db
 
PyServiceMgr m_services
 
TiXmlDocument _XmlDoc
 
TiXmlElement * _pXmlDocOuterTag
 
std::string _CurrentRowSetColumnString
 
std::stack< TiXmlElement * > * _pXmlElementStack
 

Detailed Description

Generic Base Class used to derive classes for specific service handlers (character, corporation, etc)

This class implements basic functions to build the xml documents needed to be returned from the specific service handlers for the API Server. It is used as the base class for polymorphism container in APIServer::GetXML() call to route the API Command Call package to the appropriate service handler using the service category.

Author
Aknor Jaden
Date
July 2011

Definition at line 73 of file APIServiceManager.h.

Constructor & Destructor Documentation

APIServiceManager::APIServiceManager ( const PyServiceMgr services)

Definition at line 30 of file APIServiceManager.cpp.

References _CurrentRowSetColumnString, _pXmlDocOuterTag, and _pXmlElementStack.

31 : m_services(services)
32 {
33  _pXmlDocOuterTag = NULL;
34  _pXmlElementStack = NULL;
36 }
std::stack< TiXmlElement * > * _pXmlElementStack
PyServiceMgr m_services
std::string _CurrentRowSetColumnString
TiXmlElement * _pXmlDocOuterTag

Member Function Documentation

bool APIServiceManager::_AuthenticateFullAPIQuery ( std::string  userID,
std::string  apiKey 
)
protected

Definition at line 162 of file APIServiceManager.cpp.

References APIServiceDB::GetApiAccountInfoUsingUserID(), and m_db.

163 {
164  std::string apiFullKey;
165  std::string apiLimitedKey;
166  uint32 apiRole;
167 
168  bool status = m_db.GetApiAccountInfoUsingUserID(userID, &apiFullKey, &apiLimitedKey, &apiRole);
169 
170  if( (apiKey.compare( apiFullKey )) && (status) )
171  return true;
172  else
173  return false;
174 }
bool GetApiAccountInfoUsingUserID(std::string userID, std::string *apiFullKey, std::string *apiLimitedKey, uint32 *apiRole)
?
unsigned __int32 uint32
Definition: eve-compat.h:50

Here is the call graph for this function:

bool APIServiceManager::_AuthenticateLimitedAPIQuery ( std::string  userID,
std::string  apiKey 
)
protected

Definition at line 176 of file APIServiceManager.cpp.

References APIServiceDB::GetApiAccountInfoUsingUserID(), and m_db.

177 {
178  std::string apiFullKey;
179  std::string apiLimitedKey;
180  uint32 apiRole;
181 
182  bool status = m_db.GetApiAccountInfoUsingUserID(userID, &apiFullKey, &apiLimitedKey, &apiRole);
183 
184  if( (apiKey.compare( apiLimitedKey )) && (status) )
185  return true;
186  else
187  return false;
188 }
bool GetApiAccountInfoUsingUserID(std::string userID, std::string *apiFullKey, std::string *apiLimitedKey, uint32 *apiRole)
?
unsigned __int32 uint32
Definition: eve-compat.h:50

Here is the call graph for this function:

bool APIServiceManager::_AuthenticateUserNamePassword ( std::string  userName,
std::string  password 
)
protected

Definition at line 142 of file APIServiceManager.cpp.

References PasswordModule::GeneratePassHash(), and services().

Referenced by APIAccountManager::_APIKeyRequest().

143 {
144  // Query account info
145  AccountInfo account_info;
146  if( !services().serviceDB().GetAccountInformation(
147  username.c_str(),
148  password.c_str(),
149  account_info ) )
150  return false;
151 
152  // Compute pass hash
153  std::string passHash;
155  username, password, passHash ) )
156  return false;
157 
158  // Compare the hashes
159  return passHash == account_info.hash;
160 }
static bool GeneratePassHash(const std::string &user, const std::string &pass, std::string &hash)
Generates a SHA-1 hash from a username and a password.
PyServiceMgr & services()

Here is the call graph for this function:

Here is the caller graph for this function:

void APIServiceManager::_BuildErrorXMLTag ( std::string  code,
std::string  param 
)
protected

Definition at line 316 of file APIServiceManager.cpp.

References _pXmlDocOuterTag, and _pXmlElementStack.

Referenced by BuildErrorXMLResponse(), and ProcessCall().

317 {
318  TiXmlElement * error = new TiXmlElement( "error" );
319  error->SetAttribute( "code", code.c_str() );
320  error->LinkEndChild( new TiXmlText( param.c_str() ));
321 
322  if( _pXmlElementStack->empty() )
323  _pXmlDocOuterTag->LinkEndChild( error );
324  else
325  _pXmlElementStack->top()->LinkEndChild( error );
326 }
std::stack< TiXmlElement * > * _pXmlElementStack
TiXmlElement * _pXmlDocOuterTag

Here is the caller graph for this function:

void APIServiceManager::_BuildSingleXMLTag ( std::string  name,
std::string  param 
)
protected

Definition at line 305 of file APIServiceManager.cpp.

References _pXmlDocOuterTag, and _pXmlElementStack.

Referenced by APIAccountManager::_AccountStatus(), APIAccountManager::_APIKeyRequest(), APICharacterManager::_CharacterSheet(), _CloseXMLHeader(), APIServerManager::_ServerStatus(), and APICharacterManager::_SkillInTraining().

306 {
307  TiXmlElement * tag = new TiXmlElement( name.c_str() );
308  tag->LinkEndChild( new TiXmlText( value.c_str() ));
309 
310  if( _pXmlElementStack->empty() )
311  _pXmlDocOuterTag->LinkEndChild( tag );
312  else
313  _pXmlElementStack->top()->LinkEndChild( tag );
314 }
std::stack< TiXmlElement * > * _pXmlElementStack
TiXmlElement * _pXmlDocOuterTag

Here is the caller graph for this function:

void APIServiceManager::_BuildXMLHeader ( )
protected

Definition at line 190 of file APIServiceManager.cpp.

References _pXmlDocOuterTag, _pXmlElementStack, _XmlDoc, currentTime, Win32TimeNow(), and Win32TimeToString().

Referenced by APIAccountManager::_AccountStatus(), APIAccountManager::_APIKeyRequest(), APIAccountManager::_Characters(), APICharacterManager::_CharacterSheet(), APIServerManager::_ServerStatus(), APICharacterManager::_SkillInTraining(), APICharacterManager::_SkillQueue(), BuildErrorXMLResponse(), and ProcessCall().

191 {
192  // Build header at beginning of XML document, so clear existing xml document
193  _XmlDoc.Clear();
194  // object pointed to by '_pXmlDocOuterTag' is automatically deleted by the TinyXML system with the above call
195  if( _pXmlElementStack != NULL )
196  {
197  delete _pXmlElementStack;
198  _pXmlElementStack = NULL;
199  }
200  _pXmlElementStack = new std::stack<TiXmlElement *>();
201 
202  TiXmlDeclaration * decl = new TiXmlDeclaration( "1.0", "UTF-8", "" );
203  _XmlDoc.LinkEndChild( decl );
204 
205  _pXmlDocOuterTag = new TiXmlElement( "eveapi" );
206  _XmlDoc.LinkEndChild( _pXmlDocOuterTag );
207  _pXmlDocOuterTag->SetAttribute( "version", "2" );
208 
209  TiXmlElement * currentTime = new TiXmlElement( "currentTime" );
210  currentTime->LinkEndChild( new TiXmlText( Win32TimeToString(Win32TimeNow()).c_str() ));
211  _pXmlDocOuterTag->LinkEndChild( currentTime );
212 }
TiXmlDocument _XmlDoc
std::stack< TiXmlElement * > * _pXmlElementStack
int64 Win32TimeNow()
Definition: utils_time.cpp:70
TiXmlElement * _pXmlDocOuterTag
std::string Win32TimeToString(int64 win32t)
Definition: utils_time.cpp:59
static uint32 currentTime
Definition: timer.cpp:33

Here is the call graph for this function:

Here is the caller graph for this function:

void APIServiceManager::_BuildXMLRow ( const std::vector< std::string > *  columns)
protected

Definition at line 259 of file APIServiceManager.cpp.

References _CurrentRowSetColumnString, and _pXmlElementStack.

Referenced by APIAccountManager::_Characters(), APICharacterManager::_CharacterSheet(), and APICharacterManager::_SkillQueue().

260 {
261  TiXmlElement * row = new TiXmlElement( "row" );
262 
263  std::vector<std::string>::const_iterator current, end;
264  std::string column_string = _CurrentRowSetColumnString;
265  std::string column_name;
266  int pos=0;
267  int pos2=0;
268  current = columns->begin();
269  end = columns->end();
270  for(; current != end; ++current)
271  {
272  pos = column_string.find_first_of(",");
273  column_name = column_string.substr(0,pos);
274  column_string = column_string.substr(pos+1);
275  row->SetAttribute( column_name.c_str(), current->c_str() );
276  }
277  _pXmlElementStack->top()->LinkEndChild( row );
278 }
std::stack< TiXmlElement * > * _pXmlElementStack
std::string _CurrentRowSetColumnString

Here is the caller graph for this function:

void APIServiceManager::_BuildXMLRowSet ( std::string  name,
std::string  key,
const std::vector< std::string > *  columns 
)
protected

Definition at line 233 of file APIServiceManager.cpp.

References _CurrentRowSetColumnString, and _pXmlElementStack.

Referenced by APIAccountManager::_Characters(), APICharacterManager::_CharacterSheet(), and APICharacterManager::_SkillQueue().

234 {
235  TiXmlElement * rowset = new TiXmlElement( "rowset" );
236 
237  std::vector<std::string>::const_iterator current, end;
238  rowset->SetAttribute( "name", name.c_str() );
239  rowset->SetAttribute( "key", key.c_str() );
240  current = columns->begin();
241  end = columns->end();
242  _CurrentRowSetColumnString = *current;
243  ++current;
244  for(; current != end; ++current)
245  {
247  _CurrentRowSetColumnString += *current;
248  }
249  rowset->SetAttribute( "columns", _CurrentRowSetColumnString.c_str() );
250 
251  _pXmlElementStack->push( rowset );
252 }
std::stack< TiXmlElement * > * _pXmlElementStack
std::string _CurrentRowSetColumnString
typeID Spawn an NPC with the specified type text Search for items matching the specified query() type() key(value)-Send an OnRemoteMessage" ) COMMAND( setbpattr

Here is the caller graph for this function:

void APIServiceManager::_BuildXMLTag ( std::string  name)
protected

Definition at line 280 of file APIServiceManager.cpp.

References _pXmlElementStack.

Referenced by APIAccountManager::_AccountStatus(), _BuildXMLTag(), APIAccountManager::_Characters(), APICharacterManager::_CharacterSheet(), APIServerManager::_ServerStatus(), APICharacterManager::_SkillInTraining(), and APICharacterManager::_SkillQueue().

281 {
282  TiXmlElement * tag = new TiXmlElement( name.c_str() );
283  _pXmlElementStack->push( tag );
284 }
std::stack< TiXmlElement * > * _pXmlElementStack

Here is the caller graph for this function:

void APIServiceManager::_BuildXMLTag ( std::string  name,
const std::vector< std::pair< std::string, std::string > > *  params 
)
protected

Definition at line 286 of file APIServiceManager.cpp.

References _pXmlElementStack.

287 {
288  TiXmlElement * tag = new TiXmlElement( name.c_str() );
289 
290  std::vector<std::pair<std::string, std::string> >::const_iterator current, end;
291  current = params->begin();
292  end = params->end();
293  for(; current != end; ++current)
294  tag->SetAttribute( current->first.c_str(), current->second.c_str() );
295 
296  _pXmlElementStack->push( tag );
297 }
std::stack< TiXmlElement * > * _pXmlElementStack
void APIServiceManager::_BuildXMLTag ( std::string  name,
const std::vector< std::pair< std::string, std::string > > *  params,
std::string  value 
)
protected

Definition at line 299 of file APIServiceManager.cpp.

References _BuildXMLTag(), and _pXmlElementStack.

300 {
301  _BuildXMLTag( name, params );
302  _pXmlElementStack->top()->LinkEndChild( new TiXmlText( value.c_str() ));
303 }
std::stack< TiXmlElement * > * _pXmlElementStack
void _BuildXMLTag(std::string name)

Here is the call graph for this function:

void APIServiceManager::_CloseXMLHeader ( uint32  cacheStyle)
protected

Definition at line 214 of file APIServiceManager.cpp.

References _BuildSingleXMLTag(), EVEAPI::CacheStyles::Long, EVEAPI::CacheStyles::Modified, EVEAPI::CacheStyles::Short, Win32Time_Minute, Win32TimeNow(), and Win32TimeToString().

Referenced by APIAccountManager::_AccountStatus(), APIAccountManager::_APIKeyRequest(), APIAccountManager::_Characters(), APICharacterManager::_CharacterSheet(), APIServerManager::_ServerStatus(), APICharacterManager::_SkillInTraining(), APICharacterManager::_SkillQueue(), BuildErrorXMLResponse(), and ProcessCall().

215 {
216  switch( cacheStyle )
217  {
219  // 2 hour cache timer
220  _BuildSingleXMLTag( "cachedUntil", Win32TimeToString(Win32TimeNow() + 120*Win32Time_Minute).c_str() );
221  break;
223  // 5 minute cache timer
224  _BuildSingleXMLTag( "cachedUntil", Win32TimeToString(Win32TimeNow() + 5*Win32Time_Minute).c_str() );
225  break;
227  // 15 minute cache timer
228  _BuildSingleXMLTag( "cachedUntil", Win32TimeToString(Win32TimeNow() + 15*Win32Time_Minute).c_str() );
229  break;
230  }
231 }
void _BuildSingleXMLTag(std::string name, std::string param)
int64 Win32TimeNow()
Definition: utils_time.cpp:70
const int64 Win32Time_Minute
Definition: utils_time.cpp:39
std::string Win32TimeToString(int64 win32t)
Definition: utils_time.cpp:59

Here is the call graph for this function:

Here is the caller graph for this function:

void APIServiceManager::_CloseXMLRowSet ( )
protected

Definition at line 254 of file APIServiceManager.cpp.

References _CloseXMLTag().

Referenced by APIAccountManager::_Characters(), APICharacterManager::_CharacterSheet(), and APICharacterManager::_SkillQueue().

255 {
256  _CloseXMLTag();
257 }

Here is the call graph for this function:

Here is the caller graph for this function:

void APIServiceManager::_CloseXMLTag ( )
protected

Definition at line 328 of file APIServiceManager.cpp.

References _pXmlDocOuterTag, and _pXmlElementStack.

Referenced by APIAccountManager::_AccountStatus(), APIAccountManager::_Characters(), APICharacterManager::_CharacterSheet(), _CloseXMLRowSet(), APIServerManager::_ServerStatus(), APICharacterManager::_SkillInTraining(), and APICharacterManager::_SkillQueue().

329 {
330  if( _pXmlElementStack->empty() )
331  return;
332 
333  TiXmlElement * _pTopElement = _pXmlElementStack->top();
334  _pXmlElementStack->pop();
335 
336  if( _pXmlElementStack->empty() )
337  _pXmlDocOuterTag->LinkEndChild( _pTopElement );
338  else
339  {
340  TiXmlElement * _pNextTopElement = _pXmlElementStack->top();
341  _pNextTopElement->LinkEndChild( _pTopElement );
342  }
343 }
std::stack< TiXmlElement * > * _pXmlElementStack
TiXmlElement * _pXmlDocOuterTag

Here is the caller graph for this function:

std::tr1::shared_ptr< std::string > APIServiceManager::_GetXMLDocumentString ( )
protected

Definition at line 345 of file APIServiceManager.cpp.

References _XmlDoc.

Referenced by APIAccountManager::_AccountStatus(), APIAccountManager::_APIKeyRequest(), APIAccountManager::_Characters(), APICharacterManager::_CharacterSheet(), APIServerManager::_ServerStatus(), APICharacterManager::_SkillInTraining(), APICharacterManager::_SkillQueue(), BuildErrorXMLResponse(), and ProcessCall().

346 {
347  TiXmlPrinter xmlPrinter;
348  _XmlDoc.Accept( &xmlPrinter );
349 
350  return std::tr1::shared_ptr<std::string>(new std::string(xmlPrinter.CStr()));
351 }
TiXmlDocument _XmlDoc

Here is the caller graph for this function:

std::tr1::shared_ptr< std::string > APIServiceManager::BuildErrorXMLResponse ( std::string  errorCode,
std::string  errorMessage 
)
std::tr1::shared_ptr< std::string > APIServiceManager::ProcessCall ( const APICommandCall pAPICommandCall)
virtual

Reimplemented in APIAccountManager, APICharacterManager, APIActiveObjectManager, APIAdminManager, APICorporationManager, APIEveSystemManager, APIMapManager, and APIServerManager.

Definition at line 38 of file APIServiceManager.cpp.

References _BuildErrorXMLTag(), _BuildXMLHeader(), _CloseXMLHeader(), _GetXMLDocumentString(), EVEAPI::CacheStyles::Modified, and sLog.

39 {
40  sLog.Debug("APIServiceManager::ProcessCall()", "EVEmu API - Default Service Manager");
41 
42  // EXAMPLE OF USING ALL FEATURES OF THE INHERITED APISERVICEMANAGER XML BUILDING HELPER FUNCTIONS:
43  /*
44  std::vector<std::string> rowset;
45  _BuildXMLHeader();
46  {
47  _BuildErrorXMLTag( "500", "EVEmu: Invalid Service Manager Specified." );
48 
49  _BuildXMLTag( "attributes" );
50  {
51  _BuildXMLTag( "Aknor_Jaden" );
52  {
53  _BuildSingleXMLTag( "intelligence", "6" );
54  _BuildSingleXMLTag( "memory", "4" );
55  _BuildSingleXMLTag( "charisma", "7" );
56  _BuildSingleXMLTag( "perception", "12" );
57  _BuildSingleXMLTag( "willpower", "10" );
58  }
59  _CloseXMLTag(); // close "Aknor_Jaden" tag
60  }
61  _CloseXMLTag(); // close "attributes" tag
62 
63  rowset.push_back("typeID");
64  rowset.push_back("skillpoints");
65  rowset.push_back("level");
66  rowset.push_back("published");
67  _BuildXMLRowSet( "skills", "typeID", &rowset );
68  {
69  rowset.clear();
70  rowset.push_back("3431");
71  rowset.push_back("8000");
72  rowset.push_back("3");
73  rowset.push_back("1");
74  _BuildXMLRow( &rowset );
75  rowset.clear();
76  rowset.push_back("3413");
77  rowset.push_back("8000");
78  rowset.push_back("3");
79  rowset.push_back("1");
80  _BuildXMLRow( &rowset );
81  rowset.clear();
82  rowset.push_back("21059");
83  rowset.push_back("500");
84  rowset.push_back("1");
85  rowset.push_back("1");
86  _BuildXMLRow( &rowset );
87  rowset.clear();
88  rowset.push_back("3416");
89  rowset.push_back("8000");
90  rowset.push_back("3");
91  rowset.push_back("1");
92  _BuildXMLRow( &rowset );
93  rowset.clear();
94  rowset.push_back("3445");
95  rowset.push_back("512000");
96  rowset.push_back("5");
97  rowset.push_back("0");
98  _BuildXMLRow( &rowset );
99  }
100  _CloseXMLRowSet(); // close rowset "skils"
101 
102  _BuildXMLTag( "attributeEnhancers" );
103  {
104  _BuildXMLTag( "memoryBonus" );
105  {
106  _BuildSingleXMLTag( "augmentatorName", "Memory Augmentation - Basic" );
107  _BuildSingleXMLTag( "augmentatorValue", "3" );
108  }
109  _CloseXMLTag(); // close tag "memoryBonus"
110  _BuildXMLTag( "perceptionBonus" );
111  {
112  _BuildSingleXMLTag( "augmentatorName", "Ocular Filter - Basic" );
113  _BuildSingleXMLTag( "augmentatorValue", "5" );
114  }
115  _CloseXMLTag(); // close tag "perceptionBonus"
116  }
117  _CloseXMLTag(); // close tag "attributeEnhancers"
118  }
119  _CloseXMLHeader( API_CACHE_STYLE_MODIFIED );
120  */
121 
122  _BuildXMLHeader();
123  {
124  _BuildErrorXMLTag( "500", "EVEmu: Invalid Service Manager Specified." );
125  }
127 
128  return _GetXMLDocumentString();
129 }
std::tr1::shared_ptr< std::string > _GetXMLDocumentString()
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250
void _BuildErrorXMLTag(std::string code, std::string param)
void _CloseXMLHeader(uint32 cacheStyle)

Here is the call graph for this function:

PyServiceMgr& APIServiceManager::services ( )
inline

Definition at line 77 of file APIServiceManager.h.

References m_services.

Referenced by _AuthenticateUserNamePassword(), and APIServerManager::_ServerStatus().

77 { return m_services; }
PyServiceMgr m_services

Here is the caller graph for this function:

Member Data Documentation

std::string APIServiceManager::_CurrentRowSetColumnString
protected

Definition at line 107 of file APIServiceManager.h.

Referenced by _BuildXMLRow(), _BuildXMLRowSet(), and APIServiceManager().

TiXmlElement* APIServiceManager::_pXmlDocOuterTag
protected
std::stack<TiXmlElement *>* APIServiceManager::_pXmlElementStack
protected
TiXmlDocument APIServiceManager::_XmlDoc
protected

Definition at line 105 of file APIServiceManager.h.

Referenced by _BuildXMLHeader(), and _GetXMLDocumentString().

PyServiceMgr APIServiceManager::m_services
protected

Definition at line 103 of file APIServiceManager.h.

Referenced by services().


The documentation for this class was generated from the following files: