summaryrefslogtreecommitdiffstats
path: root/admin
diff options
context:
space:
mode:
authorOpenGnSys Support Team <soporte-og@soleta.eu>2019-05-17 12:26:26 +0200
committerOpenGnSys Support Team <soporte-og@soleta.eu>2020-03-04 14:53:01 +0100
commit5c30724ccb174bd382df5eb0611f085984094e2c (patch)
tree0d8551db3c027d1265328caf8abaf7f4c780d37b /admin
parent3dd397f6e6f54658b0d834abdab0c7d18ef04a33 (diff)
#941 add basic database-independent abstraction (dbi)
Add basic infrastructure to support for the independent database layer.
Diffstat (limited to 'admin')
-rw-r--r--admin/Sources/Services/ogAdmServer/Makefile4
-rw-r--r--admin/Sources/Services/ogAdmServer/sources/dbi.cpp37
-rw-r--r--admin/Sources/Services/ogAdmServer/sources/dbi.h21
3 files changed, 60 insertions, 2 deletions
diff --git a/admin/Sources/Services/ogAdmServer/Makefile b/admin/Sources/Services/ogAdmServer/Makefile
index bffa4dca..9087eaad 100644
--- a/admin/Sources/Services/ogAdmServer/Makefile
+++ b/admin/Sources/Services/ogAdmServer/Makefile
@@ -12,10 +12,10 @@ CFLAGS += -g -Wall -I../../Includes
CPPFLAGS := $(CFLAGS)
# Opciones de linkado
-LDFLAGS := -Wl,--no-as-needed $(shell mysql_config --libs) -lev -ljansson
+LDFLAGS := -Wl,--no-as-needed $(shell mysql_config --libs) -lev -ljansson -ldbi
# Ficheros objetos
-OBJS := ../../Includes/Database.o sources/ogAdmServer.o
+OBJS := ../../Includes/Database.o sources/ogAdmServer.o sources/dbi.o
all: $(PROYECTO)
diff --git a/admin/Sources/Services/ogAdmServer/sources/dbi.cpp b/admin/Sources/Services/ogAdmServer/sources/dbi.cpp
new file mode 100644
index 00000000..cc5c5b59
--- /dev/null
+++ b/admin/Sources/Services/ogAdmServer/sources/dbi.cpp
@@ -0,0 +1,37 @@
+#include "dbi.h"
+
+struct og_dbi *og_dbi_open(struct og_dbi_config *config)
+{
+ struct og_dbi *dbi;
+
+ dbi = (struct og_dbi *)malloc(sizeof(struct og_dbi));
+ if (!dbi)
+ return NULL;
+
+ dbi_initialize_r(NULL, &dbi->inst);
+ dbi->conn = dbi_conn_new_r("mysql", dbi->inst);
+ if (!dbi->conn) {
+ free(dbi);
+ return NULL;
+ }
+
+ dbi_conn_set_option(dbi->conn, "host", config->host);
+ dbi_conn_set_option(dbi->conn, "username", config->user);
+ dbi_conn_set_option(dbi->conn, "password", config->passwd);
+ dbi_conn_set_option(dbi->conn, "dbname", config->database);
+ dbi_conn_set_option(dbi->conn, "encoding", "UTF-8");
+
+ if (dbi_conn_connect(dbi->conn) < 0) {
+ free(dbi);
+ return NULL;
+ }
+
+ return dbi;
+}
+
+void og_dbi_close(struct og_dbi *dbi)
+{
+ dbi_conn_close(dbi->conn);
+ dbi_shutdown_r(dbi->inst);
+ free(dbi);
+}
diff --git a/admin/Sources/Services/ogAdmServer/sources/dbi.h b/admin/Sources/Services/ogAdmServer/sources/dbi.h
new file mode 100644
index 00000000..882550f1
--- /dev/null
+++ b/admin/Sources/Services/ogAdmServer/sources/dbi.h
@@ -0,0 +1,21 @@
+#ifndef __OG_DBI
+#define __OG_DBI
+
+#include <dbi/dbi.h>
+
+struct og_dbi_config {
+ const char *user;
+ const char *passwd;
+ const char *host;
+ const char *database;
+};
+
+struct og_dbi {
+ dbi_conn conn;
+ dbi_inst inst;
+};
+
+struct og_dbi *og_dbi_open(struct og_dbi_config *config);
+void og_dbi_close(struct og_dbi *db);
+
+#endif