summaryrefslogtreecommitdiff
path: root/src/database/database-sqlite3.h
diff options
context:
space:
mode:
authorBen Deutsch <ben@bendeutsch.de>2018-08-05 13:13:38 +0200
committerLoïc Blot <nerzhul@users.noreply.github.com>2018-08-05 13:13:38 +0200
commit153fb211ac2342907eb766a79c1f41824f981ab5 (patch)
tree58a927bbf9a7d3d3811df6a703de02362b6474fb /src/database/database-sqlite3.h
parent18368824958139f1428d534082852d778982b4c9 (diff)
downloadminetest-153fb211ac2342907eb766a79c1f41824f981ab5.tar.gz
minetest-153fb211ac2342907eb766a79c1f41824f981ab5.tar.bz2
minetest-153fb211ac2342907eb766a79c1f41824f981ab5.zip
Replace auth.txt with SQLite auth database (#7279)
* Replace auth.txt with SQLite auth database
Diffstat (limited to 'src/database/database-sqlite3.h')
-rw-r--r--src/database/database-sqlite3.h41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/database/database-sqlite3.h b/src/database/database-sqlite3.h
index 8d9f91f21..d7202a918 100644
--- a/src/database/database-sqlite3.h
+++ b/src/database/database-sqlite3.h
@@ -85,6 +85,16 @@ protected:
return (u32) sqlite3_column_int(s, iCol);
}
+ inline s64 sqlite_to_int64(sqlite3_stmt *s, int iCol)
+ {
+ return (s64) sqlite3_column_int64(s, iCol);
+ }
+
+ inline u64 sqlite_to_uint64(sqlite3_stmt *s, int iCol)
+ {
+ return (u64) sqlite3_column_int64(s, iCol);
+ }
+
inline float sqlite_to_float(sqlite3_stmt *s, int iCol)
{
return (float) sqlite3_column_double(s, iCol);
@@ -191,3 +201,34 @@ private:
sqlite3_stmt *m_stmt_player_metadata_remove = nullptr;
sqlite3_stmt *m_stmt_player_metadata_add = nullptr;
};
+
+class AuthDatabaseSQLite3 : private Database_SQLite3, public AuthDatabase
+{
+public:
+ AuthDatabaseSQLite3(const std::string &savedir);
+ virtual ~AuthDatabaseSQLite3();
+
+ virtual bool getAuth(const std::string &name, AuthEntry &res);
+ virtual bool saveAuth(const AuthEntry &authEntry);
+ virtual bool createAuth(AuthEntry &authEntry);
+ virtual bool deleteAuth(const std::string &name);
+ virtual void listNames(std::vector<std::string> &res);
+ virtual void reload();
+
+protected:
+ virtual void createDatabase();
+ virtual void initStatements();
+
+private:
+ virtual void writePrivileges(const AuthEntry &authEntry);
+
+ sqlite3_stmt *m_stmt_read = nullptr;
+ sqlite3_stmt *m_stmt_write = nullptr;
+ sqlite3_stmt *m_stmt_create = nullptr;
+ sqlite3_stmt *m_stmt_delete = nullptr;
+ sqlite3_stmt *m_stmt_list_names = nullptr;
+ sqlite3_stmt *m_stmt_read_privs = nullptr;
+ sqlite3_stmt *m_stmt_write_privs = nullptr;
+ sqlite3_stmt *m_stmt_delete_privs = nullptr;
+ sqlite3_stmt *m_stmt_last_insert_rowid = nullptr;
+};