#define EXEC(error_code, command) do { \
if (error_code != command) { \
__STC_LOG_FUNC_EXIT__; \
- goto handle_error; \
+ return false; \
} \
} while (0)
#define ret_msg_if(expr, fmt, arg...) do { \
if (expr) { \
- STC_LOGE(fmt, ##arg); \
+ if (STC_DEBUG_LOG) \
+ STC_LOGD(fmt, ##arg); \
return; \
} \
} while (0)
#define ret_value_msg_if(expr, val, fmt, arg...) do { \
if (expr) { \
if (STC_DEBUG_LOG) \
- STC_LOGE(fmt, ##arg); \
+ STC_LOGD(fmt, ##arg); \
return val; \
} \
} while (0)
-#define ret_value_errno_msg_if(expr, val, fmt, arg...) do { \
- if (expr) { \
- if (STC_DEBUG_LOG) \
- STC_LOGE(fmt, ##arg); \
- return val; \
- } \
-} while (0)
-
-
/*
* @brief Copy from source to destination
* destination should not be on heap.
Name: stc-manager
Summary: STC(Smart Traffic Control) manager
-Version: 0.0.97
+Version: 0.0.98
Release: 0
Group: Network & Connectivity/Other
License: Apache-2.0
%define enable_database YES
%define enable_statistics YES
%define enable_restriction YES
-%define database_full_path /opt/usr/dbspace/.stc-manager-datausage.db
+%define database_full_path %{TZ_SYS_GLOBALUSER_DB}/.stc-manager-datausage.db
+%define database_backup_path %{TZ_SYS_RO_SHARE}/stc/.stc-manager-datausage.db
%define upgrade_script_filename 500.stc-manager_upgrade.sh
-%define upgrade_script_path /usr/share/upgrade/scripts
+%define upgrade_script_path %{TZ_SYS_RO_SHARE}/upgrade/scripts
BuildRequires: cmake
BuildRequires: pkgconfig(glib-2.0)
-DLIB_PATH=%{_lib} \
-DENABLE_DATABASE=%{enable_database} \
-DDATABASE_FULL_PATH=%{database_full_path} \
+ -DDATABASE_BACKUP_PATH=%{database_backup_path} \
-DENABLE_STATISTICS=%{enable_statistics} \
-DENABLE_RESTRICTION=%{enable_restriction} \
-DBUILD_GTESTS=%{?gtests:1}%{!?gtests:0} \
#database initialization
%if %{?enable_database} == YES
- mkdir -p %{buildroot}/opt/usr/dbspace
+ mkdir -p %{buildroot}%{TZ_SYS_GLOBALUSER_DB}
sqlite3 %{buildroot}%{database_full_path} < %{buildroot}/usr/share/traffic_db.sql
sqlite3 %{buildroot}%{database_full_path} < %{buildroot}/usr/share/firewall_db.sql
+ mkdir -p %{buildroot}%{TZ_SYS_RO_SHARE}/stc
+ cp %{buildroot}%{database_full_path} %{buildroot}%{database_backup_path}
rm %{buildroot}/usr/share/traffic_db.sql
rm %{buildroot}/usr/share/firewall_db.sql
%endif
%if %{?enable_database} == YES
%config(noreplace) %attr(660, root, root) %{database_full_path}
%config(noreplace) %attr(660, root, root) %{database_full_path}-journal
+%config(noreplace) %attr(660, root, root) %{database_backup_path}
%endif
%if 0%{?gtests:1}
ADD_DEFINITIONS("-DUSE_DLOG")
ADD_DEFINITIONS("-DDATABASE_FULL_PATH=\"${DATABASE_FULL_PATH}\"")
+ADD_DEFINITIONS("-DDATABASE_BACKUP_PATH=\"${DATABASE_BACKUP_PATH}\"")
IF(BUILD_GTESTS)
ADD_DEFINITIONS(-DTIZEN_GTESTS)
ENDIF(BUILD_GTESTS)
* limitations under the License.
*/
+#include <errno.h>
+#include <sys/stat.h>
+
#include "stc-db.h"
#include "db-internal.h"
#include "table-statistics.h"
#include "table-counters.h"
#include "table-firewall.h"
-#ifndef DATABASE_FULL_PATH
-#define DATABASE_FULL_PATH "/opt/usr/dbspace/.stc-manager-datausage.db"
-#endif
-
#define SQLITE_BUSY_TIMEOUT 500000
static sqlite3 *database;
__STC_LOG_FUNC_EXIT__;
return 1;
}
-//LCOV_EXCL_STOP
-stc_error_e stc_db_initialize_once(void)
+static gboolean __stc_db_restore(const char *src, const char *dst)
+{
+ gchar *buf = NULL;
+ gsize length = 0;
+ GError *error = NULL;
+ gboolean result;
+
+ result = g_file_get_contents(src, &buf, &length, &error);
+ if (result != TRUE) {
+ STC_LOGE("Failed to read [%s]", error->message);
+ g_error_free(error);
+ return result;
+ }
+
+ result = g_file_set_contents(dst, buf, length, &error);
+ if (result != TRUE) {
+ STC_LOGE("Failed to write [%s]", error->message);
+ g_error_free(error);
+ g_free(buf);
+ return result;
+ }
+
+ STC_LOGD("Successfully restored database");
+ g_free(buf);
+
+ return result;
+}
+
+static gboolean __stc_db_table_init()
+{
+ EXEC(STC_ERROR_NONE, table_statistics_prepare(database));
+ EXEC(STC_ERROR_NONE, table_restrictions_prepare(database));
+ EXEC(STC_ERROR_NONE, table_counters_prepare(database));
+ EXEC(STC_ERROR_NONE, table_firewall_prepare(database));
+ EXEC(STC_ERROR_NONE, stc_init_db_guard());
+
+ return true;
+}
+
+static int __stc_db_open(void)
+{
+ int ret = 0;
+
+ ret = sqlite3_open(DATABASE_FULL_PATH, &database);
+ if (ret != SQLITE_OK) {
+ STC_LOGD("Failed to open database [%s]", sqlite3_errmsg(database));
+ return STC_ERROR_DB_FAILED;
+ }
+
+ STC_LOGD("Successfully opened database");
+ return ret;
+}
+
+static int __stc_db_exec(char *sql, void *cb)
+{
+ int ret;
+ char *error = NULL;
+
+ if (database == NULL)
+ return STC_ERROR_DB_FAILED;
+
+ ret = sqlite3_exec(database, sql, cb, 0, &error);
+ if (ret != SQLITE_OK) {
+ STC_LOGE("Failed to execute sql [%d:%s]", ret, error);
+ sqlite3_free(error);
+ sqlite3_close(database);
+ database = NULL;
+ __STC_LOG_FUNC_EXIT__;
+ return STC_ERROR_DB_FAILED;
+ }
+
+ return STC_ERROR_NONE;
+}
+
+static int __stc_db_integrity_cb(void *err, int count, char **data, char **columns)
+{
+ STC_LOGD("%s [%s]", columns[0], data[0] ? data[0] : "null");
+
+ if (!g_strcmp0(columns[0], "integrity_check") && !g_strcmp0(data[0], "ok"))
+ return SQLITE_OK;
+
+ return SQLITE_ERROR;
+}
+
+static int __stc_db_check_integrity(void)
+{
+ int ret;
+ char *sql = NULL;
+
+ sql = sqlite3_mprintf("PRAGMA integrity_check");
+ ret = __stc_db_exec(sql, __stc_db_integrity_cb);
+ if (ret == STC_ERROR_NONE)
+ STC_LOGD("Successfully checked integrity");
+
+ sqlite3_free(sql);
+
+ return ret;
+}
+
+static int __stc_db_set_locking_mode(void)
+{
+ int ret;
+ char *sql = NULL;
+
+ sql = sqlite3_mprintf("PRAGMA locking_mode = NORMAL");
+ ret = __stc_db_exec(sql, NULL);
+ if (ret == STC_ERROR_NONE)
+ STC_LOGD("Successfully set locking mode");
+
+ sqlite3_free(sql);
+
+ return ret;
+}
+
+static int __stc_db_stat(void)
+{
+ struct stat db_stat = { 0 };
+
+ if (stat(DATABASE_FULL_PATH, &db_stat)) {
+ STC_LOGD("Db restoration is required [no file]");
+ return STC_ERROR_DB_FAILED;
+ } else if (db_stat.st_size == 0) {
+ STC_LOGD("Db restoration is required [size is zero]");
+ return STC_ERROR_DB_FAILED;
+ }
+
+ return STC_ERROR_NONE;
+}
+
+static int __stc_db_verify(void)
+{
+ ret_value_msg_if(__stc_db_check_integrity() != STC_ERROR_NONE,
+ STC_ERROR_DB_FAILED, "Failed to check integrity");
+
+ ret_value_msg_if(__stc_db_set_locking_mode() != STC_ERROR_NONE,
+ STC_ERROR_DB_FAILED, "Failed to set locking mode");
+
+ return STC_ERROR_NONE;
+}
+
+//LCOV_EXCL_STOP
+stc_error_e stc_db_initialize_once()
{
__STC_LOG_FUNC_ENTER__;
- int res = 0;
- int retry_count = 0;
+ int retry_count = MAX_DB_RETRY_COUNT;
+
if (database != NULL) {
- __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
- return STC_ERROR_NONE; //LCOV_EXCL_LINE
+ __STC_LOG_FUNC_EXIT__;
+ return STC_ERROR_NONE;
}
- do {
- res = sqlite3_open(DATABASE_FULL_PATH, &database);
- if (res != SQLITE_OK) {
- STC_LOGD("Retry[%d] opening database %s: %s\n", //LCOV_EXCL_LINE
- ++retry_count, DATABASE_FULL_PATH,
- sqlite3_errmsg(database)); //LCOV_EXCL_LINE
- } else {
- break;
+ if (__stc_db_stat() != STC_ERROR_NONE) {
+ if (!__stc_db_restore(DATABASE_BACKUP_PATH, DATABASE_FULL_PATH)) {
+ __STC_LOG_FUNC_EXIT__;
+ return STC_ERROR_DB_FAILED;
}
- usleep(MAX_USLEEP_TIMEOUT);
- } while (retry_count <= MAX_DB_RETRY_COUNT);
-
- if (res != SQLITE_OK) {
- STC_LOGE("Can't open database %s: %s\n", DATABASE_FULL_PATH, //LCOV_EXCL_LINE
- sqlite3_errmsg(database));
- __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
- return STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
}
- STC_LOGD("Successfully opened database");
+ do {
+ if (__stc_db_open() == SQLITE_OK) {
+ if (__stc_db_verify() == STC_ERROR_NONE) {
+ STC_LOGD("Successfully verified database");
+ break;
+ } else {
+ __stc_db_restore(DATABASE_BACKUP_PATH, DATABASE_FULL_PATH);
+ }
+ }
+ usleep(MAX_USLEEP_TIMEOUT);
+ STC_LOGD("Retry opening database [%d]", MAX_DB_RETRY_COUNT - retry_count + 1);
+ } while (retry_count--);
- res = sqlite3_exec(database, "PRAGMA locking_mode = NORMAL", 0, 0, 0);
- if (res != SQLITE_OK) {
- STC_LOGE("Can't set locking mode %s, skip set busy handler.", //LCOV_EXCL_LINE
- sqlite3_errmsg(database));
- sqlite3_close(database); //LCOV_EXCL_LINE
- database = NULL; //LCOV_EXCL_LINE
- __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
- return STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
+ if (retry_count == 0) {
+ STC_LOGE("Failed to initialize database");
+ sqlite3_close(database);
+ database = NULL;
+ __STC_LOG_FUNC_EXIT__;
+ return STC_ERROR_DB_FAILED;
}
/* Set how many times we'll repeat our attempts for sqlite_step */
- if (sqlite3_busy_handler(database, __stc_db_busy, NULL)
- != SQLITE_OK)
- STC_LOGE("Couldn't set busy handler!"); //LCOV_EXCL_LINE
+ if (sqlite3_busy_handler(database, __stc_db_busy, NULL) != SQLITE_OK)
+ STC_LOGE("Couldn't set busy handler!");
+ STC_LOGD("Successfully initialize database");
__STC_LOG_FUNC_EXIT__;
return STC_ERROR_NONE;
}
stc_error_e stc_db_initialize(void)
{
__STC_LOG_FUNC_ENTER__;
+ int ret;
+ int retry_count = MAX_DB_RETRY_COUNT;
database = NULL;
- stc_db_initialize_once();
-
- EXEC(STC_ERROR_NONE, table_statistics_prepare(database));
- EXEC(STC_ERROR_NONE, table_restrictions_prepare(database));
- EXEC(STC_ERROR_NONE, table_counters_prepare(database));
- EXEC(STC_ERROR_NONE, table_firewall_prepare(database));
- EXEC(STC_ERROR_NONE, stc_init_db_guard());
+ do {
+ stc_db_initialize_once();
+ ret = __stc_db_table_init();
+ if (ret) {
+ STC_LOGD("Successfully initialize database");
+ break;
+ } else {
+ __stc_db_restore(DATABASE_BACKUP_PATH, DATABASE_FULL_PATH);
+ sqlite3_close(database);
+ database = NULL;
+ }
+ STC_LOGD("Retry init database [%d]", MAX_DB_RETRY_COUNT - retry_count + 1);
+ } while (retry_count--);
__STC_LOG_FUNC_EXIT__;
return STC_ERROR_NONE;
-
-handle_error:
- stc_db_deinitialize(); //LCOV_EXCL_LINE
- __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
- return STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
}
gboolean stc_db_deinitialize(void)
{
__STC_LOG_FUNC_ENTER__;
if (database == NULL) {
- __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
- return TRUE; //LCOV_EXCL_LINE
+ __STC_LOG_FUNC_EXIT__;
+ return TRUE;
}
table_statistics_finalize();
#define DB_ACTION(command) do { \
if ((command) != SQLITE_OK) { \
error_code = STC_ERROR_DB_FAILED; \
- __STC_LOG_FUNC_EXIT__; \
goto handle_error; \
} \
} while (0)
#include "stc-manager.h"
-#define MAX_DB_RETRY_COUNT 20
+#define MAX_DB_RETRY_COUNT 5
#define MAX_USLEEP_TIMEOUT 500000
#define SQLITE_BUSY_TIMEOUT 500000
#define MAX_IFACE_LENGTH 32
static int __prepare_delete(sqlite3 *db)
{
- __STC_LOG_FUNC_ENTER__;
int rc;
static int initialized;
- if (initialized) {
- __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
- return SQLITE_OK; //LCOV_EXCL_LINE
- }
+ if (initialized)
+ return SQLITE_OK;
PREPARE_DELETE(delete_counter, DELETE_COUNTER);
initialized = 1;
- __STC_LOG_FUNC_EXIT__;
return rc;
}
static void __finalize_delete(void)
{
- __STC_LOG_FUNC_ENTER__;
-
FINALIZE(delete_counter);
-
- __STC_LOG_FUNC_EXIT__;
}
static int __prepare_select(sqlite3 *db)
{
- __STC_LOG_FUNC_ENTER__;
int rc;
static int initialized;
- if (initialized) {
- __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
- return SQLITE_OK; //LCOV_EXCL_LINE
- }
+ if (initialized)
+ return SQLITE_OK;
PREPARE_SELECT(select_counter, SELECT_COUNTER);
PREPARE_SELECT(select_timestamp, SELECT_TIMESTAMP);
PREPARE_SELECT(select_restriction_id, SELECT_RESTRICTION_ID);
initialized = 1;
- __STC_LOG_FUNC_EXIT__;
return rc;
}
static void __finalize_select(void)
{
- __STC_LOG_FUNC_ENTER__;
-
FINALIZE(select_counter);
FINALIZE(select_timestamp);
FINALIZE(select_restriction_id);
-
- __STC_LOG_FUNC_EXIT__;
}
static int __prepare_update(sqlite3 *db)
{
- __STC_LOG_FUNC_ENTER__;
int rc;
static int initialized;
- if (initialized) {
- __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
- return SQLITE_OK; //LCOV_EXCL_LINE
- }
+ if (initialized)
+ return SQLITE_OK;
PREPARE_UPDATE(update_counter, UPDATE_COUNTER);
PREPARE_UPDATE(update_timestamp, UPDATE_TIMESTAMP);
initialized = 1;
- __STC_LOG_FUNC_EXIT__;
return rc;
}
static void __finalize_update(void)
{
- __STC_LOG_FUNC_ENTER__;
-
FINALIZE(update_counter);
FINALIZE(update_timestamp);
-
- __STC_LOG_FUNC_EXIT__;
}
static int __prepare_insert(sqlite3 *db)
{
- __STC_LOG_FUNC_ENTER__;
int rc;
static int initialized;
- if (initialized) {
- __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
- return SQLITE_OK; //LCOV_EXCL_LINE
- }
+ if (initialized)
+ return SQLITE_OK;
PREPARE_INSERT(insert_counter, INSERT_COUNTER);
PREPARE_INSERT(insert_timestamp, INSERT_TIMESTAMP);
initialized = 1;
- __STC_LOG_FUNC_EXIT__;
return rc;
}
static void __finalize_insert(void)
{
- __STC_LOG_FUNC_ENTER__;
-
FINALIZE(insert_counter);
FINALIZE(insert_timestamp);
-
- __STC_LOG_FUNC_EXIT__;
}
static bool __table_counters_is_entry_present(long long int restriction_id)
static int __prepare_delete(sqlite3 *db)
{
- __STC_LOG_FUNC_ENTER__;
int rc;
static int initialized;
- if (initialized) {
- __STC_LOG_FUNC_EXIT__;
+ if (initialized)
return SQLITE_OK;
- }
PREPARE_DELETE(delete_fw_chain, DELETE_FIREWALL_CHAIN);
PREPARE_DELETE(delete_fw_rule, DELETE_FIREWALL_RULE);
PREPARE_DELETE(delete_fw_rule_per_chain, DELETE_FIREWALL_RULE_PER_CHAIN);
initialized = 1;
- __STC_LOG_FUNC_EXIT__;
return rc;
}
static void __finalize_delete(void)
{
- __STC_LOG_FUNC_ENTER__;
-
FINALIZE(delete_fw_chain);
FINALIZE(delete_fw_rule);
FINALIZE(delete_fw_rule_per_chain);
-
- __STC_LOG_FUNC_EXIT__;
}
static int __prepare_select(sqlite3 *db)
{
- __STC_LOG_FUNC_ENTER__;
int rc;
static int initialized;
- if (initialized) {
- __STC_LOG_FUNC_EXIT__;
+ if (initialized)
return SQLITE_OK;
- }
PREPARE_SELECT(select_fw_lock, SELECT_FIREWALL_LOCK);
PREPARE_SELECT(select_fw_chain, SELECT_FIREWALL_CHAIN);
PREPARE_SELECT(select_fw_rule_per_chain, SELECT_FIREWALL_RULE_PER_CHAIN);
initialized = 1;
- __STC_LOG_FUNC_EXIT__;
return rc;
}
static void __finalize_select(void)
{
- __STC_LOG_FUNC_ENTER__;
-
FINALIZE(select_fw_lock);
FINALIZE(select_fw_chain);
FINALIZE(select_fw_rule);
FINALIZE(select_fw_rule_per_chain);
-
- __STC_LOG_FUNC_EXIT__;
}
static int __prepare_update(sqlite3 *db)
{
- __STC_LOG_FUNC_ENTER__;
int rc;
static int initialized;
- if (initialized) {
- __STC_LOG_FUNC_EXIT__;
+ if (initialized)
return SQLITE_OK;
- }
PREPARE_UPDATE(update_fw_lock, UPDATE_FIREWALL_LOCK);
PREPARE_UPDATE(update_fw_chain, UPDATE_FIREWALL_CHAIN);
PREPARE_UPDATE(update_fw_rule, UPDATE_FIREWALL_RULE);
initialized = 1;
- __STC_LOG_FUNC_EXIT__;
return rc;
}
static void __finalize_update(void)
{
- __STC_LOG_FUNC_ENTER__;
-
FINALIZE(update_fw_lock);
FINALIZE(update_fw_chain);
FINALIZE(update_fw_rule);
-
- __STC_LOG_FUNC_EXIT__;
}
static int __prepare_insert(sqlite3 *db)
{
- __STC_LOG_FUNC_ENTER__;
int rc;
static int initialized;
- if (initialized) {
- __STC_LOG_FUNC_EXIT__;
+ if (initialized)
return SQLITE_OK;
- }
PREPARE_INSERT(insert_fw_lock, INSERT_FIREWALL_LOCK);
PREPARE_INSERT(insert_fw_chain, INSERT_FIREWALL_CHAIN);
PREPARE_INSERT(insert_fw_rule, INSERT_FIREWALL_RULE);
initialized = 1;
- __STC_LOG_FUNC_EXIT__;
return rc;
}
static void __finalize_insert(void)
{
- __STC_LOG_FUNC_ENTER__;
-
FINALIZE(insert_fw_lock);
FINALIZE(insert_fw_chain);
FINALIZE(insert_fw_rule);
-
- __STC_LOG_FUNC_EXIT__;
}
API stc_error_e table_firewall_insert_lock(char *name, int state)
static int __prepare_delete(sqlite3 *db)
{
- __STC_LOG_FUNC_ENTER__;
int rc;
static int initialized;
- if (initialized) {
- __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
- return SQLITE_OK; //LCOV_EXCL_LINE
- }
+ if (initialized)
+ return SQLITE_OK;
PREPARE_DELETE(delete_restrictions, DELETE_RESTRICTIONS);
initialized = 1;
- __STC_LOG_FUNC_EXIT__;
return rc;
}
static void __finalize_delete(void)
{
- __STC_LOG_FUNC_ENTER__;
-
FINALIZE(delete_restrictions);
-
- __STC_LOG_FUNC_EXIT__;
}
static int __prepare_select(sqlite3 *db)
{
- __STC_LOG_FUNC_ENTER__;
int rc;
static int initialized;
- if (initialized) {
- __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
- return SQLITE_OK; //LCOV_EXCL_LINE
- }
+ if (initialized)
+ return SQLITE_OK;
PREPARE_SELECT(select_restriction, SELECT_RESTRICTIONS);
PREPARE_SELECT(select_restriction_per_app, SELECT_RESTRICTIONS_PER_APP);
PREPARE_SELECT(select_restriction_id, SELECT_RESTRICTION_ID);
initialized = 1;
- __STC_LOG_FUNC_EXIT__;
return rc;
}
static void __finalize_select(void)
{
- __STC_LOG_FUNC_ENTER__;
-
FINALIZE(select_restriction);
FINALIZE(select_restriction_per_app);
FINALIZE(select_restriction_type);
FINALIZE(select_restriction_type_subscriber_id);
FINALIZE(select_restriction_id);
-
- __STC_LOG_FUNC_EXIT__;
}
static int __prepare_replace(sqlite3 *db)
{
- __STC_LOG_FUNC_ENTER__;
int rc;
static int initialized;
- if (initialized) {
- __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
- return SQLITE_OK; //LCOV_EXCL_LINE
- }
+ if (initialized)
+ return SQLITE_OK;
PREPARE_UPDATE(update_net_restrictions, UPDATE_NET_RESTRICTIONS);
initialized = 1;
- __STC_LOG_FUNC_EXIT__;
return rc;
}
static void __finalize_update(void)
{
- __STC_LOG_FUNC_ENTER__;
-
FINALIZE(update_net_restrictions);
-
- __STC_LOG_FUNC_EXIT__;
}
static int __prepare_insert(sqlite3 *db)
{
- __STC_LOG_FUNC_ENTER__;
int rc;
static int initialized;
- if (initialized) {
- __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
- return SQLITE_OK; //LCOV_EXCL_LINE
- }
+ if (initialized)
+ return SQLITE_OK;
PREPARE_UPDATE(insert_net_restrictions, INSERT_NET_RESTRICTIONS);
initialized = 1;
- __STC_LOG_FUNC_EXIT__;
return rc;
}
static void __finalize_insert(void)
{
- __STC_LOG_FUNC_ENTER__;
-
FINALIZE(insert_net_restrictions);
-
- __STC_LOG_FUNC_EXIT__;
}
stc_error_e table_restrictions_per_app(const gchar* app_id,
static int __prepare_delete(sqlite3 *db)
{
- __STC_LOG_FUNC_ENTER__;
int rc;
static int initialized;
- if (initialized) {
- __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
- return SQLITE_OK; //LCOV_EXCL_LINE
- }
+ if (initialized)
+ return SQLITE_OK;
PREPARE_DELETE(delete_query[0], DELETE_ALL);
PREPARE_DELETE(delete_query[1], DELETE_APP);
PREPARE_DELETE(delete_query[4], DELETE_FIRST_BY_NUMBER);
initialized = 1;
- __STC_LOG_FUNC_EXIT__;
return rc;
}
static void __finalize_delete(void)
{
- __STC_LOG_FUNC_ENTER__;
-
unsigned int i;
for (i = 0; i < sizeof(delete_query) / sizeof(*delete_query); i++)
FINALIZE(delete_query[i]);
-
- __STC_LOG_FUNC_EXIT__;
}
static int __prepare_select(sqlite3 *db)
{
- __STC_LOG_FUNC_ENTER__;
int rc;
static int initialized;
- if (initialized) {
- __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
- return SQLITE_OK; //LCOV_EXCL_LINE
- }
+ if (initialized)
+ return SQLITE_OK;
PREPARE_SELECT(select_for_period, SELECT_FOR_PERIOD);
PREPARE_SELECT(select_for_period_iface, SELECT_FOR_PERIOD_IFACE);
PREPARE_SELECT(select_chunks_total_iface, SELECT_CHUNKS_TOTAL_IFACE);
initialized = 1;
- __STC_LOG_FUNC_EXIT__;
return rc;
}
static void __finalize_select(void)
{
- __STC_LOG_FUNC_ENTER__;
-
FINALIZE(select_for_period);
FINALIZE(select_for_period_iface);
FINALIZE(select_chunks);
FINALIZE(select_total_iface);
FINALIZE(select_chunks_total);
FINALIZE(select_chunks_total_iface);
-
- __STC_LOG_FUNC_EXIT__;
}
static int __prepare_insert(sqlite3 *db)
{
- __STC_LOG_FUNC_ENTER__;
int rc;
static int initialized;
- if (initialized) {
- __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
- return SQLITE_OK; //LCOV_EXCL_LINE
- }
+ if (initialized)
+ return SQLITE_OK;
PREPARE_INSERT(update_statistics_query, INSERT_VALUES);
initialized = 1;
- __STC_LOG_FUNC_EXIT__;
return rc;
}
static void __finalize_insert(void)
{
- __STC_LOG_FUNC_ENTER__;
-
FINALIZE(update_statistics_query);
-
- __STC_LOG_FUNC_EXIT__;
}
static int __is_iftype_defined(const stc_iface_type_e iftype)