aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2023-07-04 14:00:32 +0200
committerEgor Tensin <Egor.Tensin@gmail.com>2023-07-04 14:00:32 +0200
commit258a0e9f84a54b41bb59b90f570f759cffd9abf3 (patch)
tree979c3639254a8cb1f0825c45c113825e5afca231 /src
parentsqlite: add run status field (diff)
downloadcimple-258a0e9f84a54b41bb59b90f570f759cffd9abf3.tar.gz
cimple-258a0e9f84a54b41bb59b90f570f759cffd9abf3.zip
storage_sqlite: refactoring
Diffstat (limited to 'src')
-rw-r--r--src/server.c2
-rw-r--r--src/storage.c6
-rw-r--r--src/storage.h2
-rw-r--r--src/storage_sqlite.c28
-rw-r--r--src/storage_sqlite.h10
5 files changed, 24 insertions, 24 deletions
diff --git a/src/server.c b/src/server.c
index 3d41047..18e8391 100644
--- a/src/server.c
+++ b/src/server.c
@@ -326,7 +326,7 @@ int server_create(struct server **_server, const struct settings *settings)
worker_queue_create(&server->worker_queue);
run_queue_create(&server->run_queue);
- ret = storage_settings_create_sqlite(&storage_settings, settings->sqlite_path);
+ ret = storage_sqlite_settings_create(&storage_settings, settings->sqlite_path);
if (ret < 0)
goto destroy_run_queue;
diff --git a/src/storage.c b/src/storage.c
index b7f74e5..a273030 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -23,9 +23,9 @@ struct storage_api {
static const struct storage_api apis[] = {
{
- storage_settings_destroy_sqlite,
- storage_create_sqlite,
- storage_destroy_sqlite,
+ storage_sqlite_settings_destroy,
+ storage_sqlite_create,
+ storage_sqlite_destroy,
},
};
diff --git a/src/storage.h b/src/storage.h
index e10ee87..139dcdd 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -17,7 +17,7 @@ enum storage_type {
struct storage_settings {
enum storage_type type;
union {
- struct storage_settings_sqlite *sqlite;
+ struct storage_sqlite_settings *sqlite;
};
};
diff --git a/src/storage_sqlite.c b/src/storage_sqlite.c
index 507f5b1..3483bae 100644
--- a/src/storage_sqlite.c
+++ b/src/storage_sqlite.c
@@ -17,13 +17,13 @@
#include <stdlib.h>
#include <string.h>
-struct storage_settings_sqlite {
+struct storage_sqlite_settings {
char *path;
};
-int storage_settings_create_sqlite(struct storage_settings *settings, const char *path)
+int storage_sqlite_settings_create(struct storage_settings *settings, const char *path)
{
- struct storage_settings_sqlite *sqlite = malloc(sizeof(struct storage_settings_sqlite));
+ struct storage_sqlite_settings *sqlite = malloc(sizeof(struct storage_sqlite_settings));
if (!sqlite) {
log_errno("malloc");
return -1;
@@ -45,7 +45,7 @@ free:
return -1;
}
-void storage_settings_destroy_sqlite(const struct storage_settings *settings)
+void storage_sqlite_settings_destroy(const struct storage_settings *settings)
{
free(settings->sqlite->path);
free(settings->sqlite);
@@ -55,7 +55,7 @@ struct storage_sqlite {
sqlite3 *db;
};
-static int storage_upgrade_sqlite_to(struct storage_sqlite *storage, size_t version)
+static int storage_sqlite_upgrade_to(struct storage_sqlite *storage, size_t version)
{
static const char *const fmt = "%s PRAGMA user_version = %zu;";
@@ -82,13 +82,13 @@ free:
return ret;
}
-static int storage_upgrade_sqlite_from_to(struct storage_sqlite *storage, size_t from, size_t to)
+static int storage_sqlite_upgrade_from_to(struct storage_sqlite *storage, size_t from, size_t to)
{
int ret = 0;
for (size_t i = from; i < to; ++i) {
log("Upgrading SQLite database from version %zu to version %zu\n", i, i + 1);
- ret = storage_upgrade_sqlite_to(storage, i);
+ ret = storage_sqlite_upgrade_to(storage, i);
if (ret < 0) {
log_err("Failed to upgrade to version %zu\n", i + 1);
return ret;
@@ -98,7 +98,7 @@ static int storage_upgrade_sqlite_from_to(struct storage_sqlite *storage, size_t
return ret;
}
-static int storage_upgrade_sqlite(struct storage_sqlite *storage)
+static int storage_sqlite_upgrade(struct storage_sqlite *storage)
{
unsigned int current_version = 0;
int ret = 0;
@@ -121,10 +121,10 @@ static int storage_upgrade_sqlite(struct storage_sqlite *storage)
return 0;
}
- return storage_upgrade_sqlite_from_to(storage, current_version, newest_version);
+ return storage_sqlite_upgrade_from_to(storage, current_version, newest_version);
}
-static int storage_prepare_sqlite(struct storage_sqlite *storage)
+static int storage_sqlite_prepare(struct storage_sqlite *storage)
{
int ret = 0;
@@ -132,14 +132,14 @@ static int storage_prepare_sqlite(struct storage_sqlite *storage)
if (ret < 0)
return ret;
- ret = storage_upgrade_sqlite(storage);
+ ret = storage_sqlite_upgrade(storage);
if (ret < 0)
return ret;
return ret;
}
-int storage_create_sqlite(struct storage *storage, const struct storage_settings *settings)
+int storage_sqlite_create(struct storage *storage, const struct storage_settings *settings)
{
int ret = 0;
@@ -157,7 +157,7 @@ int storage_create_sqlite(struct storage *storage, const struct storage_settings
ret = sqlite_open_rw(settings->sqlite->path, &sqlite->db);
if (ret < 0)
goto destroy;
- ret = storage_prepare_sqlite(sqlite);
+ ret = storage_sqlite_prepare(sqlite);
if (ret < 0)
goto close;
@@ -174,7 +174,7 @@ free:
return ret;
}
-void storage_destroy_sqlite(struct storage *storage)
+void storage_sqlite_destroy(struct storage *storage)
{
sqlite_close(storage->sqlite->db);
sqlite_destroy();
diff --git a/src/storage_sqlite.h b/src/storage_sqlite.h
index 30a5dd4..e9e0581 100644
--- a/src/storage_sqlite.h
+++ b/src/storage_sqlite.h
@@ -9,15 +9,15 @@
#define __STORAGE_SQLITE_H__
struct storage_settings;
-struct storage_settings_sqlite;
+struct storage_sqlite_setttings;
struct storage;
struct storage_sqlite;
-int storage_settings_create_sqlite(struct storage_settings *, const char *path);
-void storage_settings_destroy_sqlite(const struct storage_settings *);
+int storage_sqlite_settings_create(struct storage_settings *, const char *path);
+void storage_sqlite_settings_destroy(const struct storage_settings *);
-int storage_create_sqlite(struct storage *, const struct storage_settings *);
-void storage_destroy_sqlite(struct storage *);
+int storage_sqlite_create(struct storage *, const struct storage_settings *);
+void storage_sqlite_destroy(struct storage *);
#endif