-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPuushDatabase.h
68 lines (54 loc) · 1.46 KB
/
PuushDatabase.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
class PuushDatabase;
#ifndef _PUUSHDATABASE_H
#define _PUUSHDATABASE_H
#include <list>
#include <vector>
#include <random>
#ifndef WIN32
namespace std { typedef minstd_rand0 default_random_engine; }
#endif
class PuushDatabase
{
public:
PuushDatabase();
~PuushDatabase();
bool load(const char *filename);
void close();
std::string addUser(const char *username, const char *password);
std::string authenticateUser(const char *username, const char *passwordOrApiKey);
std::string addFile(const char *apiKey, const char *filename, const char *path, const char *md5hash);
std::string lookupFile(const char *shortName, int &httpStatus);
int getUserCount();
struct User
{
int id;
std::string username;
std::string apiKey;
};
std::list<User> getUsers();
bool deleteUser(int id);
private:
struct QueryField
{
bool isNull;
std::string value;
};
struct QueryResult
{
std::list<std::vector<QueryField> > rows;
std::vector<std::string> columns;
};
std::string execute(const char *query, QueryResult *destResult);
static int queryCallback(void *userdata, int argc, char **argv, char **columns);
std::string generateApiKey();
std::string generateShortName();
sqlite3 *m_database;
std::random_device m_randomDevice;
std::default_random_engine m_randomGenerator;
#if defined(WIN32) || (defined(GCC_VERSION) && GCC_VERSION >= 40500)
std::uniform_int_distribution<int> m_randomDistribution;
#else
std::uniform_int<int> m_randomDistribution;
#endif
};
#endif