2016-05-22 21:34:27 +02:00
|
|
|
#ifndef _SQMYSQL_ACCOUNT_HPP_
|
|
|
|
#define _SQMYSQL_ACCOUNT_HPP_
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
#include "Common.hpp"
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
namespace SqMod {
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* Helper class containing shared connection information to avoid repetition.
|
|
|
|
*/
|
|
|
|
class Account
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
|
|
|
typedef std::unordered_map< String, String > Options;
|
|
|
|
|
2016-06-03 20:33:21 +02:00
|
|
|
private:
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
|
|
|
Uint16 m_Port; // Server port.
|
|
|
|
String m_Host; // Host address.
|
|
|
|
String m_User; // User name.
|
|
|
|
String m_Pass; // User password.
|
|
|
|
String m_Name; // Database name.
|
|
|
|
String m_Socket; // Unix socket.
|
|
|
|
Ulong m_Flags; // Client connection flags.
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
|
|
|
String m_SSL_Key; // SSL key.
|
|
|
|
String m_SSL_Cert; // SSL certificate.
|
|
|
|
String m_SSL_CA; // SSL certificate authority.
|
|
|
|
String m_SSL_CA_Path; // SSL certificate authority path.
|
|
|
|
String m_SSL_Cipher; // SSL Cipher.
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
|
|
|
Options m_Options; // Option container.
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
|
|
|
bool m_AutoCommit; // Toggle autocommit.
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
|
|
|
static const String s_String; // Dummy used to return a reference to a null string.
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2016-05-22 21:34:27 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Base Constructor.
|
|
|
|
*/
|
|
|
|
Account(CSStr host, CSStr user)
|
|
|
|
: Account(host, user, _SC(""), _SC(""), 3306, _SC(""))
|
|
|
|
{
|
|
|
|
/* ... */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Base Constructor.
|
|
|
|
*/
|
|
|
|
Account(CSStr host, CSStr user, CSStr pass)
|
|
|
|
: Account(host, user, pass, _SC(""), 3306, _SC(""))
|
|
|
|
{
|
|
|
|
/* ... */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Base Constructor.
|
|
|
|
*/
|
2016-06-03 20:33:21 +02:00
|
|
|
Account(CSStr host, CSStr user, CSStr pass, CSStr name)
|
|
|
|
: Account(host, user, pass, name, 3306, _SC(""))
|
2016-05-22 21:34:27 +02:00
|
|
|
{
|
|
|
|
/* ... */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Base Constructor.
|
|
|
|
*/
|
2016-06-03 20:33:21 +02:00
|
|
|
Account(CSStr host, CSStr user, CSStr pass, CSStr name, SQInteger port)
|
|
|
|
: Account(host, user, pass, name, port, _SC(""))
|
2016-05-22 21:34:27 +02:00
|
|
|
{
|
|
|
|
/* ... */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Base Constructor.
|
|
|
|
*/
|
2016-06-03 20:33:21 +02:00
|
|
|
Account(CSStr host, CSStr user, CSStr pass, CSStr name, SQInteger port, CSStr socket);
|
2016-05-22 21:34:27 +02:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-06-03 20:33:21 +02:00
|
|
|
* Copy constructor.
|
2016-05-22 21:34:27 +02:00
|
|
|
*/
|
|
|
|
Account(const Account & o) = default;
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-06-03 20:33:21 +02:00
|
|
|
* Move constructor.
|
2016-05-22 21:34:27 +02:00
|
|
|
*/
|
|
|
|
Account(Account && o) = default;
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Destructor.
|
|
|
|
*/
|
|
|
|
~Account() = default;
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-06-03 20:33:21 +02:00
|
|
|
* Copy assignment operator.
|
2016-05-22 21:34:27 +02:00
|
|
|
*/
|
|
|
|
Account & operator = (const Account & o) = default;
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-06-03 20:33:21 +02:00
|
|
|
* Move assignment operator.
|
2016-05-22 21:34:27 +02:00
|
|
|
*/
|
|
|
|
Account & operator = (Account && o) = default;
|
|
|
|
|
2016-06-03 20:33:21 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Used by the script engine to compare two instances of this type.
|
|
|
|
*/
|
|
|
|
Int32 Cmp(const Account & o) const;
|
2016-05-22 21:34:27 +02:00
|
|
|
|
2016-06-03 20:33:21 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Used by the script engine to convert an instance of this type to a string.
|
|
|
|
*/
|
|
|
|
CSStr ToString() const;
|
2016-05-22 21:34:27 +02:00
|
|
|
|
2016-06-03 20:33:21 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Used by the script engine to retrieve the name from instances of this type.
|
|
|
|
*/
|
|
|
|
static SQInteger Typename(HSQUIRRELVM vm);
|
2016-05-22 21:34:27 +02:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-06-03 20:33:21 +02:00
|
|
|
* Retrieve the host address specified during creation.
|
2016-05-22 21:34:27 +02:00
|
|
|
*/
|
|
|
|
const String & GetHost() const
|
|
|
|
{
|
|
|
|
return m_Host;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-06-03 20:33:21 +02:00
|
|
|
* Modify the host address specified during creation.
|
|
|
|
*/
|
|
|
|
void SetHost(CSStr addr);
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve the user name specified during creation.
|
2016-05-22 21:34:27 +02:00
|
|
|
*/
|
|
|
|
const String & GetUser() const
|
|
|
|
{
|
|
|
|
return m_User;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-06-03 20:33:21 +02:00
|
|
|
* Modify the user name specified during creation.
|
|
|
|
*/
|
|
|
|
void SetUser(CSStr user)
|
|
|
|
{
|
|
|
|
m_User.assign(user != nullptr ? user : _SC(""));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve the password specified during creation.
|
2016-05-22 21:34:27 +02:00
|
|
|
*/
|
|
|
|
const String & GetPass() const
|
|
|
|
{
|
|
|
|
return m_Pass;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-06-03 20:33:21 +02:00
|
|
|
* Modify the password specified during creation.
|
2016-05-22 21:34:27 +02:00
|
|
|
*/
|
2016-06-03 20:33:21 +02:00
|
|
|
void SetPass(CSStr pass)
|
2016-05-22 21:34:27 +02:00
|
|
|
{
|
2016-06-03 20:33:21 +02:00
|
|
|
m_Pass.assign(pass != nullptr ? pass : _SC(""));
|
2016-05-22 21:34:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-06-03 20:33:21 +02:00
|
|
|
* Retrieve the database name specified during creation.
|
2016-05-22 21:34:27 +02:00
|
|
|
*/
|
2016-06-03 20:33:21 +02:00
|
|
|
const String & GetName() const
|
2016-05-22 21:34:27 +02:00
|
|
|
{
|
2016-06-03 20:33:21 +02:00
|
|
|
return m_Name;
|
2016-05-22 21:34:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-06-03 20:33:21 +02:00
|
|
|
* Modify the database name specified during creation.
|
|
|
|
*/
|
|
|
|
void SetName(CSStr name)
|
|
|
|
{
|
|
|
|
m_Name.assign(name != nullptr ? name : _SC(""));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve the server port specified during creation.
|
|
|
|
*/
|
|
|
|
Uint16 GetPortNum() const
|
|
|
|
{
|
|
|
|
return m_Port;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Modify the server port specified during creation.
|
|
|
|
*/
|
|
|
|
void SetPortNum(SQInteger port);
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve the server socket.
|
2016-05-22 21:34:27 +02:00
|
|
|
*/
|
|
|
|
const String & GetSocket() const
|
|
|
|
{
|
|
|
|
return m_Socket;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-06-03 20:33:21 +02:00
|
|
|
* Modify the server socket.
|
|
|
|
*/
|
|
|
|
void SetSocket(CSStr socket)
|
|
|
|
{
|
|
|
|
m_Socket.assign(socket != nullptr ? socket : _SC(""));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve the current client connection flags.
|
|
|
|
*/
|
|
|
|
SQInteger GetFlags() const
|
|
|
|
{
|
|
|
|
return m_Flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Modify the current client connection flags.
|
|
|
|
*/
|
|
|
|
void SetFlags(SQInteger flags)
|
|
|
|
{
|
|
|
|
m_Flags = flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Modify the current client connection flags.
|
|
|
|
*/
|
|
|
|
void EnableFlags(SQInteger flags)
|
|
|
|
{
|
|
|
|
m_Flags |= flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Modify the current client connection flags.
|
|
|
|
*/
|
|
|
|
void DisableFlags(SQInteger flags)
|
|
|
|
{
|
|
|
|
m_Flags |= flags;
|
|
|
|
m_Flags ^= flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve the SSL key.
|
2016-05-22 21:34:27 +02:00
|
|
|
*/
|
|
|
|
const String & GetSSL_Key() const
|
|
|
|
{
|
|
|
|
return m_SSL_Key;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-06-03 20:33:21 +02:00
|
|
|
* Modify the SSL key.
|
|
|
|
*/
|
|
|
|
void SetSSL_Key(CSStr key)
|
|
|
|
{
|
|
|
|
m_SSL_Key.assign(key != nullptr ? key : _SC(""));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve the SSL certificate.
|
2016-05-22 21:34:27 +02:00
|
|
|
*/
|
|
|
|
const String & GetSSL_Cert() const
|
|
|
|
{
|
2016-06-03 20:33:21 +02:00
|
|
|
return m_SSL_Cert;
|
2016-05-22 21:34:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-06-03 20:33:21 +02:00
|
|
|
* Modify the SSL certificate.
|
|
|
|
*/
|
|
|
|
void SetSSL_Cert(CSStr cert)
|
|
|
|
{
|
|
|
|
m_SSL_Cert.assign(cert != nullptr ? cert : _SC(""));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve the SSL certificate authority.
|
2016-05-22 21:34:27 +02:00
|
|
|
*/
|
|
|
|
const String & GetSSL_CA() const
|
|
|
|
{
|
|
|
|
return m_SSL_CA;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-06-03 20:33:21 +02:00
|
|
|
* Modify the SSL certificate authority.
|
|
|
|
*/
|
|
|
|
void SetSSL_CA(CSStr ca)
|
|
|
|
{
|
|
|
|
m_SSL_CA.assign(ca != nullptr ? ca : _SC(""));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve the SSL certificate authority path.
|
2016-05-22 21:34:27 +02:00
|
|
|
*/
|
|
|
|
const String & GetSSL_CA_Path() const
|
|
|
|
{
|
|
|
|
return m_SSL_CA_Path;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-06-03 20:33:21 +02:00
|
|
|
* Modify the SSL certificate authority path.
|
|
|
|
*/
|
|
|
|
void SetSSL_CA_Path(CSStr capath)
|
|
|
|
{
|
|
|
|
m_SSL_CA_Path.assign(capath != nullptr ? capath : _SC(""));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve the SSL cipher.
|
2016-05-22 21:34:27 +02:00
|
|
|
*/
|
|
|
|
const String & GetSSL_Cipher() const
|
|
|
|
{
|
|
|
|
return m_SSL_Cipher;
|
|
|
|
}
|
|
|
|
|
2016-06-03 20:33:21 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Modify the SSL cipher.
|
|
|
|
*/
|
|
|
|
void SetSSL_Cipher(CSStr cipher)
|
|
|
|
{
|
|
|
|
m_SSL_Cipher.assign(cipher != nullptr ? cipher : _SC(""));
|
|
|
|
}
|
|
|
|
|
2016-05-22 21:34:27 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Set the SSL information.
|
|
|
|
*/
|
|
|
|
void SetSSL(CSStr key, CSStr cert, CSStr ca, CSStr ca_path, CSStr cipher);
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* See whether autocommit is enabled or not.
|
|
|
|
*/
|
2016-06-03 20:33:21 +02:00
|
|
|
bool GetAutoCommit() const
|
2016-05-22 21:34:27 +02:00
|
|
|
{
|
2016-06-03 20:33:21 +02:00
|
|
|
return m_AutoCommit;
|
2016-05-22 21:34:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Set whether autocommit should be enabled or not.
|
|
|
|
*/
|
2016-06-03 20:33:21 +02:00
|
|
|
void SetAutoCommit(bool toggle)
|
2016-05-22 21:34:27 +02:00
|
|
|
{
|
2016-06-03 20:33:21 +02:00
|
|
|
m_AutoCommit = toggle;
|
2016-05-22 21:34:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-06-03 20:33:21 +02:00
|
|
|
* Retrieve the entire options container as a table.
|
2016-05-22 21:34:27 +02:00
|
|
|
*/
|
2016-06-03 20:33:21 +02:00
|
|
|
const Options & GetOptions() const
|
|
|
|
{
|
|
|
|
return m_Options;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve the entire options container as a table.
|
|
|
|
*/
|
|
|
|
Table GetOptionsTable() const;
|
2016-05-22 21:34:27 +02:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-06-03 20:33:21 +02:00
|
|
|
* Retrieve a value from the options container.
|
2016-05-22 21:34:27 +02:00
|
|
|
*/
|
|
|
|
const String & GetOption(CSStr name) const;
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Set a value in the options container.
|
|
|
|
*/
|
|
|
|
void SetOption(CSStr name, CSStr value);
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Remove a value from the options container.
|
|
|
|
*/
|
2016-06-03 20:33:21 +02:00
|
|
|
void RemoveOption(CSStr name);
|
2016-05-22 21:34:27 +02:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-06-03 20:33:21 +02:00
|
|
|
* Retrieve the number of values in the options container.
|
2016-05-22 21:34:27 +02:00
|
|
|
*/
|
|
|
|
Uint32 OptionsCount() const
|
|
|
|
{
|
|
|
|
return static_cast< Uint32 >(m_Options.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* See whether the options container is empty or not.
|
|
|
|
*/
|
|
|
|
bool OptionsEmpty() const
|
|
|
|
{
|
|
|
|
return m_Options.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Remove all the options from the options container.
|
|
|
|
*/
|
|
|
|
void OptionsClear()
|
|
|
|
{
|
|
|
|
m_Options.clear();
|
|
|
|
}
|
2016-06-03 20:33:21 +02:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Create a connection with the current account information.
|
|
|
|
*/
|
|
|
|
Connection Connect() const;
|
2016-05-22 21:34:27 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // Namespace:: SqMod
|
|
|
|
|
|
|
|
#endif // _SQMYSQL_ACCOUNT_HPP_
|