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

??? More...

#include "APIAccountManager.h"

Inheritance diagram for APIAccountManager:
Collaboration diagram for APIAccountManager:

Public Member Functions

 APIAccountManager (const PyServiceMgr &services)
 
std::tr1::shared_ptr< std::string > ProcessCall (const APICommandCall *pAPICommandCall)
 
- Public Member Functions inherited from APIServiceManager
 APIServiceManager (const PyServiceMgr &services)
 
PyServiceMgrservices ()
 
std::tr1::shared_ptr< std::string > BuildErrorXMLResponse (std::string errorCode, std::string errorMessage)
 

Protected Member Functions

std::tr1::shared_ptr< std::string > _APIKeyRequest (const APICommandCall *pAPICommandCall)
 
std::tr1::shared_ptr< std::string > _Characters (const APICommandCall *pAPICommandCall)
 
std::tr1::shared_ptr< std::string > _AccountStatus (const APICommandCall *pAPICommandCall)
 
std::string _GenerateAPIKey ()
 
- Protected Member Functions inherited from APIServiceManager
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

APIAccountDB m_accountDB
 
- Protected Attributes inherited from APIServiceManager
APIServiceDB m_db
 
PyServiceMgr m_services
 
TiXmlDocument _XmlDoc
 
TiXmlElement * _pXmlDocOuterTag
 
std::string _CurrentRowSetColumnString
 
std::stack< TiXmlElement * > * _pXmlElementStack
 

Static Protected Attributes

static std::string m_hexCharMap
 

Detailed Description

???

??? ??? ???

Author
Aknor Jaden
Date
July 2011

Definition at line 44 of file APIAccountManager.h.

Constructor & Destructor Documentation

APIAccountManager::APIAccountManager ( const PyServiceMgr services)

Definition at line 32 of file APIAccountManager.cpp.

33 : APIServiceManager(services)
34 {
35 }
APIServiceManager(const PyServiceMgr &services)

Member Function Documentation

std::tr1::shared_ptr< std::string > APIAccountManager::_AccountStatus ( const APICommandCall pAPICommandCall)
protected

Definition at line 268 of file APIAccountManager.cpp.

References APIServiceManager::_BuildSingleXMLTag(), APIServiceManager::_BuildXMLHeader(), APIServiceManager::_BuildXMLTag(), APIServiceManager::_CloseXMLHeader(), APIServiceManager::_CloseXMLTag(), APIServiceManager::_GetXMLDocumentString(), APIServiceManager::BuildErrorXMLResponse(), APIServiceDB::GetAccountIdFromUserID(), APIAccountDB::GetAccountInfo(), m_accountDB, APIServiceManager::m_db, EVEAPI::CacheStyles::Short, and sLog.

Referenced by ProcessCall().

269 {
270  sLog.Error( "APIAccountManager::_AccountStatus()", "TODO: Insert code to validate userID and apiKey" );
271 
272  if( pAPICommandCall->find( "userid" ) == pAPICommandCall->end() )
273  {
274  sLog.Error( "APIAccountManager::_AccountStatus()", "ERROR: No 'userID' parameter found in call argument list - exiting with error" );
275  return BuildErrorXMLResponse( "106", "Must provide userID parameter for authentication." );
276  }
277 
278  uint32 accountID = 0;
279  std::vector<std::string> accountInfoList;
280 
281  if( !(m_db.GetAccountIdFromUserID( pAPICommandCall->find( "userid" )->second, &accountID )) )
282  {
283  sLog.Error( "APIAccountManager::_AccountStatus()", "ERROR: Could not find 'accountID' in 'accountApi' table - exiting with error" );
284  return BuildErrorXMLResponse( "106", "Must provide userID parameter for authentication." );
285  }
286 
287  if( !(m_accountDB.GetAccountInfo( accountID, accountInfoList )) )
288  {
289  sLog.Error( "APIAccountManager::_AccountStatus()", "ERROR: Could not find 'accountID' in 'account' table; there is an invalid 'accountID' referenced by api account 'userID' = %s - exiting with error", pAPICommandCall->find( "userid" )->second.c_str() );
290  return BuildErrorXMLResponse( "106", "Must provide userID parameter for authentication." );
291  }
292 
293  _BuildXMLHeader();
294  {
295  _BuildXMLTag( "result" );
296  {
297  _BuildSingleXMLTag( "paidUntil", "2100-12-31 12:00:00" );
298  _BuildSingleXMLTag( "createDate", "2000-01-01 12:00:00" );
299  _BuildSingleXMLTag( "logonCount", accountInfoList.at(2) );
300  _BuildSingleXMLTag( "logonMinutes", "1000" );
301  }
302  _CloseXMLTag(); // close tag "result"
303  }
305 
306  return _GetXMLDocumentString();
307 }
std::tr1::shared_ptr< std::string > BuildErrorXMLResponse(std::string errorCode, std::string errorMessage)
std::tr1::shared_ptr< std::string > _GetXMLDocumentString()
void _BuildSingleXMLTag(std::string name, std::string param)
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250
bool GetAccountIdFromUserID(std::string userID, uint32 *accountID)
?
bool GetAccountInfo(uint32 accountID, std::vector< std::string > &accountInfoList)
?
APIAccountDB m_accountDB
unsigned __int32 uint32
Definition: eve-compat.h:50
void _BuildXMLTag(std::string name)
void _CloseXMLHeader(uint32 cacheStyle)

Here is the call graph for this function:

Here is the caller graph for this function:

std::tr1::shared_ptr< std::string > APIAccountManager::_APIKeyRequest ( const APICommandCall pAPICommandCall)
protected

Definition at line 65 of file APIAccountManager.cpp.

References APIServiceManager::_AuthenticateUserNamePassword(), APIServiceManager::_BuildSingleXMLTag(), APIServiceManager::_BuildXMLHeader(), APIServiceManager::_CloseXMLHeader(), _GenerateAPIKey(), APIServiceManager::_GetXMLDocumentString(), APIServiceManager::BuildErrorXMLResponse(), APIServiceDB::GetAccountIdFromUsername(), APIServiceDB::GetApiAccountInfoUsingAccountID(), APIServiceDB::InsertNewUserIdApiKeyInfoToDatabase(), itoa(), EVEAPI::CacheStyles::Long, APIServiceManager::m_db, EVEAPI::Roles::Player, sLog, APIServiceDB::UpdateUserIdApiKeyDatabaseRow(), Win32Time_Day, Win32TimeNow(), and Win32TimeToString().

Referenced by ProcessCall().

66 {
67  bool status = false;
68  uint32 userID, apiRole;
69  std::string username;
70  std::string password;
71  std::string keyType;
72  std::string action;
73  std::string apiLimitedKey;
74  std::string apiFullKey;
75  std::string accountID;
76  std::string keyTag;
77 
78  sLog.Debug("APIAccountManager::_APIKeyRequest()", "EVEmu API - Account Service Manager - CALL: APIKeyRequest.xml.aspx");
79 
80  // 1: Decode arguments:
81  if( pAPICommandCall->find( "username" ) != pAPICommandCall->end() )
82  username = pAPICommandCall->find( "username" )->second;
83  else
84  {
85  sLog.Error( "APIAccountManager::_APIKeyRequest()", "ERROR: No 'username' parameter found in call argument list - exiting with error" );
86  return BuildErrorXMLResponse( "203", "Authentication failure." );
87  }
88 
89  if( pAPICommandCall->find( "password" ) != pAPICommandCall->end() )
90  password = pAPICommandCall->find( "password" )->second;
91  else
92  {
93  sLog.Error( "APIAccountManager::_APIKeyRequest()", "ERROR: No 'password' parameter found in call argument list - exiting with error" );
94  return BuildErrorXMLResponse( "203", "Authentication failure." );
95  }
96 
97  if( pAPICommandCall->find( "keytype" ) != pAPICommandCall->end() )
98  keyType = pAPICommandCall->find( "keytype" )->second;
99  else
100  {
101  sLog.Error( "APIAccountManager::_APIKeyRequest()", "ERROR: No 'keytype' parameter found in call argument list - exiting with error" );
102  return BuildErrorXMLResponse( "203", "Authentication failure." );
103  }
104 
105  if( keyType != "full" )
106  if( keyType != "limited" )
107  {
108  sLog.Error( "APIAccountManager::_APIKeyRequest()", "ERROR: 'keytype' parameter has invalid value '%s' - exiting with error", keyType.c_str() );
109  return BuildErrorXMLResponse( "203", "Authentication failure." );
110  }
111 
112  if( pAPICommandCall->find( "action" ) != pAPICommandCall->end() )
113  action = pAPICommandCall->find( "action" )->second;
114  else
115  {
116  sLog.Error( "APIAccountManager::_APIKeyRequest()", "ERROR: No 'action' parameter found in call argument list - exiting with error" );
117  return BuildErrorXMLResponse( "203", "Authentication failure." );
118  }
119 
120  if( action != "new" )
121  if( action != "get" )
122  {
123  sLog.Error( "APIAccountManager::_APIKeyRequest()", "ERROR: 'action' parameter has invalid value '%s' - exiting with error", action.c_str() );
124  return BuildErrorXMLResponse( "203", "Authentication failure." );
125  }
126 
127  // 2: Authenticate the username and password against the account table:
128  status = _AuthenticateUserNamePassword( username, password );
129  if( !status )
130  {
131  sLog.Error( "APIAccountManager::_APIKeyRequest()", "ERROR: username='%s' password='%s' does not authenticate.", username.c_str(), password.c_str() );
132  return BuildErrorXMLResponse( "203", "Authentication failure." );
133  }
134  // 2a: Get accountID using username, now that it's been validated:
135  status = m_db.GetAccountIdFromUsername( username, &accountID );
136  if( !status )
137  {
138  sLog.Error( "APIAccountManager::_APIKeyRequest()", "ERROR: username='%s' cannot be found in 'account' table.", username.c_str() );
139  return BuildErrorXMLResponse( "203", "Authentication failure." );
140  }
141 
142  // 3: Determine if this account's userID exists:
143  status = m_db.GetApiAccountInfoUsingAccountID( accountID, &userID, &apiFullKey, &apiLimitedKey, &apiRole );
144 
145  // 4: Generate new random 64-character hexadecimal API Keys:
146  // Write new API Key to database if key request 'action' is 'new':
147  if( !status )
148  {
149  // 4a: If userID does not exist for this accountID, then insert a new row into the 'accountApi' table regardless of 'get' or 'new':
150  apiLimitedKey = _GenerateAPIKey();
151  apiFullKey = _GenerateAPIKey();
152  status = m_db.InsertNewUserIdApiKeyInfoToDatabase( atol(accountID.c_str()), apiFullKey, apiLimitedKey, EVEAPI::Roles::Player );
153  }
154 
155  if( action == "new" )
156  if( keyType == "limited" )
157  apiLimitedKey = _GenerateAPIKey();
158  else //if( keyType == "full" )
159  apiFullKey = _GenerateAPIKey();
160 
161  if( action == "new" )
162  {
163  if( status )
164  // 4b: If userID already exists, generate new API keys and write them back to the database under that userID:
165  status = m_db.UpdateUserIdApiKeyDatabaseRow( userID, apiFullKey, apiLimitedKey );
166  }
167 
168  // 5: Build XML document to return to API client:
169  userID = 0;
170  apiFullKey = "";
171  apiLimitedKey = "";
172  apiRole = 0;
173  //status = m_db.GetAccountIdFromUsername( username, &accountID );
174 
175  status = m_db.GetApiAccountInfoUsingAccountID( accountID, &userID, &apiFullKey, &apiLimitedKey, &apiRole );
176  if( !status )
177  {
178  sLog.Error( "APIAccountManager::_APIKeyRequest()", "ERROR: username='%s' cannot be found in 'account' table.", username.c_str() );
179  return BuildErrorXMLResponse( "203", "Authentication failure." );
180  }
181 
182  // 6: Return the userID and the API key requested in the xml structure:
183  _BuildXMLHeader();
184  {
185  _BuildSingleXMLTag( "userID", std::string(itoa(userID)) );
186  if( keyType == "full" )
187  {
188  keyTag = "apiFullKey";
189  _BuildSingleXMLTag( keyTag, apiFullKey );
190  }
191  else
192  {
193  keyTag = "apiLimitedKey";
194  _BuildSingleXMLTag( keyTag, apiLimitedKey );
195  }
197  }
199 
200  return _GetXMLDocumentString();
201 }
std::tr1::shared_ptr< std::string > BuildErrorXMLResponse(std::string errorCode, std::string errorMessage)
bool GetAccountIdFromUsername(std::string username, std::string *accountID)
?
std::tr1::shared_ptr< std::string > _GetXMLDocumentString()
void _BuildSingleXMLTag(std::string name, std::string param)
bool InsertNewUserIdApiKeyInfoToDatabase(uint32 accountID, std::string apiFullKey, std::string apiLimitedKey, uint32 apiRole)
?
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250
const int64 Win32Time_Day
Definition: utils_time.cpp:41
std::string _GenerateAPIKey()
int64 Win32TimeNow()
Definition: utils_time.cpp:70
unsigned __int32 uint32
Definition: eve-compat.h:50
bool _AuthenticateUserNamePassword(std::string userName, std::string password)
std::string Win32TimeToString(int64 win32t)
Definition: utils_time.cpp:59
bool GetApiAccountInfoUsingAccountID(std::string accountID, uint32 *userID, std::string *apiFullKey, std::string *apiLimitedKey, uint32 *apiRole)
?
void _CloseXMLHeader(uint32 cacheStyle)
const char * itoa(int64 num)
Convers num to string.
bool UpdateUserIdApiKeyDatabaseRow(uint32 userID, std::string apiFullKey, std::string apiLimitedKey)
?

Here is the call graph for this function:

Here is the caller graph for this function:

std::tr1::shared_ptr< std::string > APIAccountManager::_Characters ( const APICommandCall pAPICommandCall)
protected

Definition at line 203 of file APIAccountManager.cpp.

References APIServiceManager::_BuildXMLHeader(), APIServiceManager::_BuildXMLRow(), APIServiceManager::_BuildXMLRowSet(), APIServiceManager::_BuildXMLTag(), APIServiceManager::_CloseXMLHeader(), APIServiceManager::_CloseXMLRowSet(), APIServiceManager::_CloseXMLTag(), APIServiceManager::_GetXMLDocumentString(), APIServiceManager::BuildErrorXMLResponse(), APIServiceDB::GetAccountIdFromUserID(), APIAccountDB::GetCharactersList(), EVEAPI::CacheStyles::Long, m_accountDB, APIServiceManager::m_db, and sLog.

Referenced by ProcessCall().

204 {
205 
206  sLog.Error( "APIAccountManager::_Characters()", "TODO: Insert code to validate userID and apiKey" );
207 
208  sLog.Debug("APIAccountManager::_Characters()", "EVEmu API - Account Service Manager - CALL: Characters.xml.aspx");
209 
210  if( pAPICommandCall->find( "userid" ) == pAPICommandCall->end() )
211  {
212  sLog.Error( "APIAccountManager::_Characters()", "ERROR: No 'userID' parameter found in call argument list - exiting with error" );
213  return BuildErrorXMLResponse( "106", "Must provide userID parameter for authentication." );
214  }
215 
216  uint32 status = 0;
217  uint32 accountID = 0;
218  std::vector<std::string> charIDList;
219  std::vector<std::string> charNameList;
220  std::vector<std::string> charCorpIDList;
221  std::vector<std::string> charCorpNameList;
222 
223  std::string userID = pAPICommandCall->find( "userid" )->second;
224 
225  status = m_db.GetAccountIdFromUserID( userID, &accountID );
226  if( !status )
227  {
228  sLog.Error( "APIAccountManager::_Characters()", "ERROR: userID='%s' cannot be found in 'accountApi' table.", userID.c_str() );
229  return BuildErrorXMLResponse( "203", "Authentication failure." );
230  }
231 
232  if( !( m_accountDB.GetCharactersList(accountID, charIDList, charNameList, charCorpIDList, charCorpNameList) ) )
233  {
234  sLog.Error( "APIAccountManager::_Characters()", "ERROR: m_accountDB.GetCharactersList() call failed for unknown reason - exiting with error" );
235  BuildErrorXMLResponse( "9999", "EVEmu API Server: Account Manager - Characters.xml.aspx STUB" );
236  }
237 
238  std::vector<std::string> rowset;
239  _BuildXMLHeader();
240  {
241  _BuildXMLTag( "result" );
242  {
243  rowset.push_back("name");
244  rowset.push_back("characterID");
245  rowset.push_back("corporationName");
246  rowset.push_back("corporationID");
247  _BuildXMLRowSet( "characters", "characterID", &rowset );
248  {
249  for(uint32 i=0; i<charIDList.size(); i++)
250  {
251  rowset.clear();
252  rowset.push_back(charNameList.at(i));
253  rowset.push_back(charIDList.at(i));
254  rowset.push_back(charCorpNameList.at(i));
255  rowset.push_back(charCorpIDList.at(i));
256  _BuildXMLRow( &rowset );
257  }
258  }
259  _CloseXMLRowSet(); // close rowset "characters"
260  }
261  _CloseXMLTag(); // close tag "result"
262  }
264 
265  return _GetXMLDocumentString();
266 }
std::tr1::shared_ptr< std::string > BuildErrorXMLResponse(std::string errorCode, std::string errorMessage)
std::tr1::shared_ptr< std::string > _GetXMLDocumentString()
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250
bool GetAccountIdFromUserID(std::string userID, uint32 *accountID)
?
APIAccountDB m_accountDB
bool GetCharactersList(uint32 accountID, std::vector< std::string > &charIDList, std::vector< std::string > &charNameList, std::vector< std::string > &charCorpIDList, std::vector< std::string > &charCorpNameList)
?
unsigned __int32 uint32
Definition: eve-compat.h:50
void _BuildXMLTag(std::string name)
void _BuildXMLRow(const std::vector< std::string > *columns)
void _CloseXMLHeader(uint32 cacheStyle)
void _BuildXMLRowSet(std::string name, std::string key, const std::vector< std::string > *columns)

Here is the call graph for this function:

Here is the caller graph for this function:

std::string APIAccountManager::_GenerateAPIKey ( )
protected

Definition at line 309 of file APIAccountManager.cpp.

References key(), m_hexCharMap, and MakeRandomInt().

Referenced by _APIKeyRequest().

310 {
311  std::string key = "";
312 
313  for( int i=0; i<64; i++ )
314  key += m_hexCharMap.substr(static_cast<uint16>(MakeRandomInt(0, 15)), 1);
315 
316  return key;
317 }
static std::string m_hexCharMap
int64 MakeRandomInt(int64 low, int64 high)
Generates random integer from interval [low; high].
Definition: misc.cpp:109
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 call graph for this function:

Here is the caller graph for this function:

std::tr1::shared_ptr< std::string > APIAccountManager::ProcessCall ( const APICommandCall pAPICommandCall)
virtual

Reimplemented from APIServiceManager.

Definition at line 37 of file APIAccountManager.cpp.

References _AccountStatus(), _APIKeyRequest(), _Characters(), APIServiceManager::BuildErrorXMLResponse(), and sLog.

38 {
39  sLog.Debug("APIAccountManager::ProcessCall()", "EVEmu API - Account Service Manager");
40 
41  if( pAPICommandCall->find( "servicehandler" ) == pAPICommandCall->end() )
42  {
43  sLog.Error( "APIAccountManager::ProcessCall()", "Cannot find 'servicehandler' specifier in pAPICommandCall packet" );
44  return std::tr1::shared_ptr<std::string>(new std::string(""));
45  }
46 
47  if( pAPICommandCall->find( "servicehandler" )->second == "APIKeyRequest.xml.aspx" )
48  return _APIKeyRequest(pAPICommandCall);
49  else if( pAPICommandCall->find( "servicehandler" )->second == "Characters.xml.aspx" )
50  return _Characters(pAPICommandCall);
51  else if( pAPICommandCall->find( "servicehandler" )->second == "AccountStatus.xml.aspx" )
52  return _AccountStatus(pAPICommandCall);
53  //else if( pAPICommandCall->find( "servicehandler" )->second == "TODO.xml.aspx" )
54  // return _TODO(pAPICommandCall);
55  else
56  {
57  sLog.Error("APIAccountManager::ProcessCall()", "EVEmu API - Account Service Manager - ERROR: Cannot resolve '%s' as a valid service query for Admin Service Manager",
58  pAPICommandCall->find("servicehandler")->second.c_str() );
59  return std::tr1::shared_ptr<std::string>(new std::string(""));
60  }
61 
62  return BuildErrorXMLResponse( "9999", "EVEmu API Server: Account Manager - Unknown call." );
63 }
std::tr1::shared_ptr< std::string > BuildErrorXMLResponse(std::string errorCode, std::string errorMessage)
std::tr1::shared_ptr< std::string > _APIKeyRequest(const APICommandCall *pAPICommandCall)
std::tr1::shared_ptr< std::string > _AccountStatus(const APICommandCall *pAPICommandCall)
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250
std::tr1::shared_ptr< std::string > _Characters(const APICommandCall *pAPICommandCall)

Here is the call graph for this function:

Member Data Documentation

APIAccountDB APIAccountManager::m_accountDB
protected

Definition at line 61 of file APIAccountManager.h.

Referenced by _AccountStatus(), and _Characters().

std::string APIAccountManager::m_hexCharMap
staticprotected

Definition at line 62 of file APIAccountManager.h.

Referenced by _GenerateAPIKey().


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