Добавлено: возможность указать путь к файлу БД

This commit is contained in:
Alexander Zhirov 2022-07-18 15:01:15 +03:00
parent f53fc681ab
commit 5e743f843f
6 changed files with 31 additions and 13 deletions

View File

@ -14,8 +14,10 @@
#include "db.h"
#include "monitor.h"
void settingsLoad()
void settingsLoad(char *pathDB)
{
getPathDB(pathDB);
dbLoadData();
Monitors *monitors = dbGetMonitorsList();

View File

@ -17,7 +17,7 @@ typedef struct
void buildArguments(Arguments *args);
void freeArguments(Arguments *args);
void settingsLoad();
void settingsLoad(char *pathDB);
void settingsFree();
#endif /* ARGUMENTS_H_ */

31
db.c
View File

@ -12,6 +12,17 @@
#include "db.h"
#include "node_settings.h"
char *getPathDB(char *path)
{
static char *current = NULL;
if (path)
{
current = path;
}
return current;
}
static sqlite3 *dbGetBase(char *path)
{
sqlite3 *db = NULL;
@ -68,7 +79,7 @@ static int dbLoad(void *NotUsed, int argc, char **argv, char **azColName)
bool dbLoadData()
{
sqlite3 *db = dbGetBase("freerdp.db");
sqlite3 *db = dbGetBase(getPathDB(NULL));
if (!db)
{
return false;
@ -126,7 +137,7 @@ static int dbCreateHostsList(void *answer, int argc, char **argv, char **azColNa
Hosts *dbGetHostsList()
{
sqlite3 *db = dbGetBase("freerdp.db");
sqlite3 *db = dbGetBase(getPathDB(NULL));
if (!db)
{
return false;
@ -167,7 +178,7 @@ void dbFreeHosts(Hosts *hosts)
bool dbWriteParameter(Parameter name, bool set)
{
sqlite3 *db = dbGetBase("freerdp.db");
sqlite3 *db = dbGetBase(getPathDB(NULL));
if (!db)
{
return false;
@ -204,7 +215,7 @@ bool dbWriteParameter(Parameter name, bool set)
bool dbWriteValue(Value name, bool set)
{
sqlite3 *db = dbGetBase("freerdp.db");
sqlite3 *db = dbGetBase(getPathDB(NULL));
if (!db)
{
return false;
@ -245,7 +256,7 @@ int dbAddServer(char *ip, char *dns)
if (!(ip && strlen(ip) && dns && strlen(dns)))
return -1;
sqlite3 *db = dbGetBase("freerdp.db");
sqlite3 *db = dbGetBase(getPathDB(NULL));
if (!db)
{
return -2;
@ -349,7 +360,7 @@ int dbAddServer(char *ip, char *dns)
bool dbSetUserNameCurrent(char *current)
{
sqlite3 *db = dbGetBase("freerdp.db");
sqlite3 *db = dbGetBase(getPathDB(NULL));
if (!db)
{
return false;
@ -415,7 +426,7 @@ static int dbCreateMonitorsList(void *answer, int argc, char **argv, char **azCo
Monitors *dbGetMonitorsList()
{
sqlite3 *db = dbGetBase("freerdp.db");
sqlite3 *db = dbGetBase(getPathDB(NULL));
if (!db)
{
return false;
@ -457,7 +468,7 @@ void dbFreeMonitors(Monitors *monitors)
bool deleteAllMonitors()
{
sqlite3 *db = dbGetBase("freerdp.db");
sqlite3 *db = dbGetBase(getPathDB(NULL));
if (!db)
{
return false;
@ -481,7 +492,7 @@ int dbAddMonitor(char *monitor, bool set)
if (!(monitor && strlen(monitor)))
return -1;
sqlite3 *db = dbGetBase("freerdp.db");
sqlite3 *db = dbGetBase(getPathDB(NULL));
if (!db)
{
return -2;
@ -522,7 +533,7 @@ int dbSaveMonitors(char *name)
if (!(name && strlen(name)))
return -1;
sqlite3 *db = dbGetBase("freerdp.db");
sqlite3 *db = dbGetBase(getPathDB(NULL));
if (!db)
{
return -2;

2
db.h
View File

@ -38,6 +38,8 @@ typedef struct Monitors
size_t size;
} Monitors;
char *getPathDB(char *path);
bool dbLoadData();
Hosts *dbGetHostsList();
void dbFreeHosts(Hosts *hosts);

Binary file not shown.

View File

@ -6,7 +6,10 @@
int main(int argc, char **argv)
{
settingsLoad();
if (argc > 1)
settingsLoad(argv[1]);
else
settingsLoad("/etc/freerdp/freerdp.db");
IupOpen(&argc, &argv);