Check validity of database 53/227853/2 accepted/tizen/unified/20200321.043820 submit/tizen/20200320.041119
authorhyunuk.tak <hyunuk.tak@samsung.com>
Tue, 17 Mar 2020 01:17:36 +0000 (10:17 +0900)
committerhyunuk.tak <hyunuk.tak@samsung.com>
Thu, 19 Mar 2020 04:28:13 +0000 (13:28 +0900)
Change-Id: Ib412f13d82b5e29b373480ad15cc5310f2be949a
Signed-off-by: hyunuk.tak <hyunuk.tak@samsung.com>
include/stc-manager-util.h
packaging/stc-manager.spec
src/CMakeLists.txt
src/database/db-common.c
src/database/include/db-internal.h
src/database/include/stc-db.h
src/database/tables/table-counters.c
src/database/tables/table-firewall.c
src/database/tables/table-restrictions.c
src/database/tables/table-statistics.c

index 7440534..3dd9b38 100755 (executable)
@@ -85,7 +85,7 @@
 #define EXEC(error_code, command) do { \
        if (error_code != command) { \
                __STC_LOG_FUNC_EXIT__; \
-               goto handle_error; \
+               return false; \
        } \
 } while (0)
 
@@ -253,7 +253,8 @@ static inline bool strstart_with(const char *str, const char *with)
 
 #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)
@@ -267,20 +268,11 @@ static inline bool strstart_with(const char *str, const char *with)
 #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.
index bc30e18..7e5f221 100644 (file)
@@ -1,6 +1,6 @@
 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
@@ -9,9 +9,10 @@ Source0:    %{name}-%{version}.tar.gz
 %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)
@@ -106,6 +107,7 @@ export CXXFLAGS="$CXXFLAGS -D_GNU_SOURCE"
        -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} \
@@ -120,9 +122,11 @@ rm -rf %{buildroot}
 
 #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
@@ -168,6 +172,7 @@ cp -f scripts/%{upgrade_script_filename} %{buildroot}%{upgrade_script_path}
 %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}
index 35aaafd..9883098 100644 (file)
@@ -87,6 +87,7 @@ SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
 
 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)
index a4c2a3d..3519710 100755 (executable)
@@ -14,6 +14,9 @@
  * 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;
@@ -40,54 +39,191 @@ static int __stc_db_busy(void *user, int attempts)
        __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;
 }
@@ -105,31 +241,34 @@ sqlite3 *stc_db_get_database(void)
 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();
index 2d8922d..2b2daae 100755 (executable)
@@ -35,7 +35,6 @@ extern "C" {
 #define DB_ACTION(command) do { \
        if ((command) != SQLITE_OK) { \
                error_code = STC_ERROR_DB_FAILED; \
-               __STC_LOG_FUNC_EXIT__; \
                goto handle_error; \
        } \
 } while (0)
index c15d3fa..e648d21 100755 (executable)
@@ -19,7 +19,7 @@
 
 #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
index fa22cc5..c4c0db1 100755 (executable)
@@ -123,118 +123,86 @@ static sqlite3_stmt *insert_timestamp;
 
 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)
index 5e179e3..995e8cd 100755 (executable)
@@ -180,45 +180,34 @@ static sqlite3_stmt *insert_fw_rule;
 
 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);
@@ -226,82 +215,61 @@ static int __prepare_select(sqlite3 *db)
        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)
index 71167ee..1466a65 100755 (executable)
@@ -145,41 +145,30 @@ static sqlite3_stmt *insert_net_restrictions;
 
 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);
@@ -188,75 +177,54 @@ static int __prepare_select(sqlite3 *db)
        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,
index 7d13a3f..b631d47 100755 (executable)
@@ -218,14 +218,11 @@ static sqlite3_stmt *update_statistics_query;
 
 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);
@@ -234,31 +231,23 @@ static int __prepare_delete(sqlite3 *db)
        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);
@@ -274,14 +263,11 @@ static int __prepare_select(sqlite3 *db)
        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);
@@ -294,35 +280,25 @@ static void __finalize_select(void)
        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)