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

#include "APIServiceDB.h"

Public Member Functions

 APIServiceDB ()
 
bool GetAccountIdFromUsername (std::string username, std::string *accountID)
 ? More...
 
bool GetAccountIdFromUserID (std::string userID, uint32 *accountID)
 ? More...
 
bool GetApiAccountInfoUsingAccountID (std::string accountID, uint32 *userID, std::string *apiFullKey, std::string *apiLimitedKey, uint32 *apiRole)
 ? More...
 
bool GetApiAccountInfoUsingUserID (std::string userID, std::string *apiFullKey, std::string *apiLimitedKey, uint32 *apiRole)
 ? More...
 
bool UpdateUserIdApiKeyDatabaseRow (uint32 userID, std::string apiFullKey, std::string apiLimitedKey)
 ? More...
 
bool InsertNewUserIdApiKeyInfoToDatabase (uint32 accountID, std::string apiFullKey, std::string apiLimitedKey, uint32 apiRole)
 ? More...
 
bool UpdateUserIdApiRole (uint32 userID, uint32 apiRole)
 ? More...
 

Detailed Description

Definition at line 29 of file APIServiceDB.h.

Constructor & Destructor Documentation

APIServiceDB::APIServiceDB ( )

Definition at line 30 of file APIServiceDB.cpp.

31 {
32 }

Member Function Documentation

bool APIServiceDB::GetAccountIdFromUserID ( std::string  userID,
uint32 accountID 
)

?

?

Parameters
[in]?
[in]?
Return values
?

Definition at line 60 of file APIServiceDB.cpp.

References DBQueryResult::GetRow(), DBResultRow::GetUInt(), sDatabase, and sLog.

Referenced by APIAccountManager::_AccountStatus(), and APIAccountManager::_Characters().

61 {
62  DBQueryResult res;
63 
64  // Find accountID in 'accountapi' table using userID:
65  if( !sDatabase.RunQuery(res,
66  "SELECT"
67  " accountID "
68  " FROM accountApi "
69  " WHERE userID='%s'" , userID.c_str() ))
70  {
71  sLog.Error( "APIServiceDB::GetAccountIdFromUserID()", "Cannot find accountID for userID %s", userID.c_str() );
72  return false;
73  }
74 
75  DBResultRow row;
76  if( !res.GetRow(row) )
77  {
78  sLog.Error( "APIServiceDB::GetAccountIdFromUserID()", "res.GetRow(row) failed for unknown reason." );
79  return false;
80  }
81 
82  *accountID = row.GetUInt(0); // Grab accountID from the retrieved row from the 'accountapi' table
83  return true;
84 }
#define sDatabase
Definition: dbcore.h:199
uint32 GetUInt(uint32 index) const
Definition: dbcore.cpp:658
bool GetRow(DBResultRow &into)
Definition: dbcore.cpp:552
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250

Here is the call graph for this function:

Here is the caller graph for this function:

bool APIServiceDB::GetAccountIdFromUsername ( std::string  username,
std::string *  accountID 
)

?

?

Parameters
[in]?
[in]?
Return values
?

Definition at line 34 of file APIServiceDB.cpp.

References DBQueryResult::GetRow(), DBResultRow::GetText(), sDatabase, and sLog.

Referenced by APIAccountManager::_APIKeyRequest().

35 {
36  DBQueryResult res;
37 
38  // Find accountID in 'account' table using accountName:
39  if( !sDatabase.RunQuery(res,
40  "SELECT"
41  " accountID "
42  " FROM account "
43  " WHERE accountName='%s'" , username.c_str() ))
44  {
45  sLog.Error( "APIServiceDB::GetAccountIdFromUsername()", "Cannot find accountID for username %s", username.c_str() );
46  return false;
47  }
48 
49  DBResultRow row;
50  if( !res.GetRow(row) )
51  {
52  sLog.Error( "APIServiceDB::GetAccountIdFromUsername()", "res.GetRow(row) failed for unknown reason." );
53  return false;
54  }
55 
56  *accountID = row.GetText(0); // Grab accountID from the retrieved row from the 'account' table
57  return true;
58 }
#define sDatabase
Definition: dbcore.h:199
const char * GetText(uint32 index) const
Definition: dbcore.h:104
bool GetRow(DBResultRow &into)
Definition: dbcore.cpp:552
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250

Here is the call graph for this function:

Here is the caller graph for this function:

bool APIServiceDB::GetApiAccountInfoUsingAccountID ( std::string  accountID,
uint32 userID,
std::string *  apiFullKey,
std::string *  apiLimitedKey,
uint32 apiRole 
)

?

?

Parameters
[in]?
[in]?
Return values
?

Definition at line 86 of file APIServiceDB.cpp.

References DBQueryResult::GetRow(), DBResultRow::GetText(), DBResultRow::GetUInt(), sDatabase, and sLog.

Referenced by APIAccountManager::_APIKeyRequest().

88 {
89  DBQueryResult res;
90 
91  // Find userID, fullKey, limitedKey, and apiRole from 'accountApi' table using accountID obtained from 'account' table:
92  if( !sDatabase.RunQuery(res,
93  "SELECT"
94  " userID, fullKey, limitedKey, apiRole "
95  " FROM accountApi "
96  " WHERE accountID='%s'" , accountID.c_str() ))
97  {
98  sLog.Error( "APIServiceDB::GetApiAccountInfoUsingAccountID()", "Cannot find accountID '%s' in 'accountApi' table", accountID.c_str() );
99  return false;
100  }
101 
102  DBResultRow row;
103  if( !res.GetRow(row) )
104  {
105  sLog.Error( "APIServiceDB::GetApiAccountInfoUsingAccountID()", "res.GetRow(row) failed for unknown reason." );
106  return false;
107  }
108 
109  *userID = row.GetUInt(0); // Grab userID from retrieved row from the 'accountApi' table
110  *apiFullKey = row.GetText(1); // Grab Full API Key from retrieved row from the 'accountApi' table
111  *apiLimitedKey = row.GetText(2); // Grab Limited API Key from retrieved row from the 'accountApi' table
112  *apiRole = row.GetUInt(3); // Grab API Role from retrieved row from the 'accountApi' table
113  return true;
114 }
#define sDatabase
Definition: dbcore.h:199
const char * GetText(uint32 index) const
Definition: dbcore.h:104
uint32 GetUInt(uint32 index) const
Definition: dbcore.cpp:658
bool GetRow(DBResultRow &into)
Definition: dbcore.cpp:552
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250

Here is the call graph for this function:

Here is the caller graph for this function:

bool APIServiceDB::GetApiAccountInfoUsingUserID ( std::string  userID,
std::string *  apiFullKey,
std::string *  apiLimitedKey,
uint32 apiRole 
)

?

?

Parameters
[in]?
[in]?
Return values
?

Definition at line 116 of file APIServiceDB.cpp.

References DBQueryResult::GetRow(), DBResultRow::GetText(), DBResultRow::GetUInt(), sDatabase, and sLog.

Referenced by APIServiceManager::_AuthenticateFullAPIQuery(), and APIServiceManager::_AuthenticateLimitedAPIQuery().

117 {
118  DBQueryResult res;
119 
120  // Find fullKey, limitedKey, and apiRole from 'accountApi' table using userID supplied from an API query string:
121  if( !sDatabase.RunQuery(res,
122  "SELECT"
123  " fullKey, limitedKey, apiRole "
124  " FROM accountApi "
125  " WHERE userID='%s'" , userID.c_str() ))
126  {
127  sLog.Error( "APIServiceDB::GetApiAccountInfoUsingUserID()", "Cannot find userID '%s' in 'accountApi' table", userID.c_str() );
128  return false;
129  }
130 
131  DBResultRow row;
132  if( !res.GetRow(row) )
133  {
134  sLog.Error( "APIServiceDB::GetApiAccountInfoUsingUserID()", "res.GetRow(row) failed for unknown reason." );
135  return false;
136  }
137 
138  *apiFullKey = row.GetText(0); // Grab Full API Key from retrieved row from the 'accountApi' table
139  *apiLimitedKey = row.GetText(1); // Grab Limited API Key from retrieved row from the 'accountApi' table
140  *apiRole = row.GetUInt(2); // Grab API Role from retrieved row from the 'accountApi' table
141  return true;
142 }
#define sDatabase
Definition: dbcore.h:199
const char * GetText(uint32 index) const
Definition: dbcore.h:104
uint32 GetUInt(uint32 index) const
Definition: dbcore.cpp:658
bool GetRow(DBResultRow &into)
Definition: dbcore.cpp:552
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250

Here is the call graph for this function:

Here is the caller graph for this function:

bool APIServiceDB::InsertNewUserIdApiKeyInfoToDatabase ( uint32  accountID,
std::string  apiFullKey,
std::string  apiLimitedKey,
uint32  apiRole 
)

?

?

Parameters
[in]?
[in]?
Return values
?

Definition at line 176 of file APIServiceDB.cpp.

References DBerror::c_str(), sDatabase, and sLog.

Referenced by APIAccountManager::_APIKeyRequest().

177 {
178  // Check key lengths and report error and return if either are incorrect:
179  if( apiLimitedKey.length() != 64 )
180  {
181  sLog.Error( "APIServiceDB::UpdateUserIdApiKeyDatabaseRow()", "limitedApiKey length != 64, but rather %u", apiLimitedKey.length() );
182  return false;
183  }
184 
185  if( apiFullKey.length() != 64 )
186  {
187  sLog.Error( "APIServiceDB::UpdateUserIdApiKeyDatabaseRow()", "fullApiKey length != 64, but rather %u", apiFullKey.length() );
188  return false;
189  }
190 
191  DBerror err;
192 
193  if( !sDatabase.RunQuery(err,
194  "INSERT INTO"
195  " accountApi ("
196  " accountID, fullKey, limitedKey, apiRole"
197  " ) VALUES ("
198  " %u, '%s', '%s', %u"
199  " )",
200  accountID, apiFullKey.c_str(), apiLimitedKey.c_str(), apiRole
201  ))
202  {
203  sLog.Error( "", "Error in query: %s.", err.c_str());
204  return false;
205  }
206  else
207  return true;
208 }
#define sDatabase
Definition: dbcore.h:199
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250
const char * c_str() const
Definition: dbcore.h:48
Definition: dbcore.h:39

Here is the call graph for this function:

Here is the caller graph for this function:

bool APIServiceDB::UpdateUserIdApiKeyDatabaseRow ( uint32  userID,
std::string  apiFullKey,
std::string  apiLimitedKey 
)

?

?

Parameters
[in]?
[in]?
Return values
?

Definition at line 144 of file APIServiceDB.cpp.

References DBerror::c_str(), sDatabase, and sLog.

Referenced by APIAccountManager::_APIKeyRequest().

145 {
146  // Check key lengths and report error and return if either are incorrect:
147  if( apiLimitedKey.length() != 64 )
148  {
149  sLog.Error( "APIServiceDB::UpdateUserIdApiKeyDatabaseRow()", "limitedApiKey length != 64, but rather %u", apiLimitedKey.length() );
150  return false;
151  }
152 
153  if( apiFullKey.length() != 64 )
154  {
155  sLog.Error( "APIServiceDB::UpdateUserIdApiKeyDatabaseRow()", "fullApiKey length != 64, but rather %u", apiFullKey.length() );
156  return false;
157  }
158 
159  // Update fullKey and limitedKey in the 'accountApi' table using userID:
160  DBerror err;
161 
162  if( !sDatabase.RunQuery(err,
163  "UPDATE"
164  " accountApi"
165  " SET fullKey = '%s', limitedKey = '%s'"
166  " WHERE userID = %u",
167  apiFullKey.c_str(), apiLimitedKey.c_str(), userID ))
168  {
169  sLog.Error( "", "Error in query: %s.", err.c_str());
170  return false;
171  }
172  else
173  return true;
174 }
#define sDatabase
Definition: dbcore.h:199
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250
const char * c_str() const
Definition: dbcore.h:48
Definition: dbcore.h:39

Here is the call graph for this function:

Here is the caller graph for this function:

bool APIServiceDB::UpdateUserIdApiRole ( uint32  userID,
uint32  apiRole 
)

?

?

Parameters
[in]?
[in]?
Return values
?

Definition at line 210 of file APIServiceDB.cpp.

References DBerror::c_str(), sDatabase, and sLog.

211 {
212  // Update fullKey and limitedKey in the 'accountApi' table using userID:
213  DBerror err;
214 
215  if( !sDatabase.RunQuery(err,
216  "UPDATE"
217  " accountApi"
218  " SET apiRole = %u"
219  " WHERE userID = %u",
220  apiRole, userID ))
221  {
222  sLog.Error( "", "Error in query: %s.", err.c_str());
223  return false;
224  }
225  else
226  return true;
227 }
#define sDatabase
Definition: dbcore.h:199
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250
const char * c_str() const
Definition: dbcore.h:48
Definition: dbcore.h:39

Here is the call graph for this function:


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