Fix some svace issues for unchecking return value
[platform/core/connectivity/stc-manager.git] / src / database / tables / table-restrictions.c
old mode 100644 (file)
new mode 100755 (executable)
index bbbede0..71167ee
@@ -26,7 +26,8 @@
 
 /* DELETE statements */
 #define DELETE_RESTRICTIONS "DELETE FROM restrictions " \
-       " WHERE binpath = ? AND iftype = ? AND subscriber_id = ?"
+       " WHERE binpath = ? AND iftype = ? AND ifname = ? " \
+       " AND subscriber_id = ? AND roaming = ?"
 
 /* SELECT statements */
 #define SELECT_RESTRICTIONS "SELECT binpath, data_limit, " \
@@ -314,12 +315,15 @@ stc_error_e table_restrictions_per_app(const gchar* app_id,
        } while (rc == SQLITE_ROW);
 
 handle_error:
-       sqlite3_reset(stmt);
+       rc = sqlite3_reset(stmt);
+       if (rc != SQLITE_OK)
+               error_code = STC_ERROR_DB_FAILED;
+
        __STC_LOG_FUNC_EXIT__;
        return error_code;
 }
 
-stc_error_e table_restrictions_foreach(const table_restrictions_info_cb restriction_cb,
+API stc_error_e table_restrictions_foreach(const table_restrictions_info_cb restriction_cb,
                                       void *user_data)
 {
        __STC_LOG_FUNC_ENTER__;
@@ -365,7 +369,10 @@ stc_error_e table_restrictions_foreach(const table_restrictions_info_cb restrict
                }
        } while (rc == SQLITE_ROW);
 
-       sqlite3_reset(stmt);
+       rc = sqlite3_reset(stmt);
+       if (rc != SQLITE_OK)
+               error_code = STC_ERROR_DB_FAILED;
+
        __STC_LOG_FUNC_EXIT__;
        return error_code;
 }
@@ -387,8 +394,17 @@ stc_error_e table_restrictions_get_restriction_type_subscriber_id(const char *ap
        }
 
        *type = STC_RSTN_TYPE_UNKNOWN;
-       sqlite3_reset(select_restriction_type_subscriber_id);
-       sqlite3_reset(select_restriction_type);
+       ret = sqlite3_reset(select_restriction_type_subscriber_id);
+       if (ret != SQLITE_OK) {
+               __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
+       }
+
+       ret = sqlite3_reset(select_restriction_type);
+       if (ret != SQLITE_OK) {
+               __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
+       }
 
        if (subscriber_id == NULL) {
                state_subscriber_id = 0;
@@ -427,8 +443,14 @@ stc_error_e table_restrictions_get_restriction_type_subscriber_id(const char *ap
        }
 
 handle_error:
-       sqlite3_reset(select_restriction_type);
-       sqlite3_reset(select_restriction_type_subscriber_id);
+       ret = sqlite3_reset(select_restriction_type);
+       if (ret != SQLITE_OK)
+               error_code = STC_ERROR_DB_FAILED;
+
+       ret = sqlite3_reset(select_restriction_type_subscriber_id);
+       if (ret != SQLITE_OK)
+               error_code = STC_ERROR_DB_FAILED;
+
        return error_code;
 }
 
@@ -444,19 +466,24 @@ stc_error_e table_restrictions_get_restriction_type(const char *app_id,
 
 stc_error_e table_restrictions_delete(const char *app_id,
                                      const stc_iface_type_e iftype,
-                                     const char *subscriber_id)
+                                     const char *ifname,
+                                     const char *subscriber_id,
+                                     const stc_roaming_type_e roaming)
 {
        stc_error_e error_code = STC_ERROR_NONE;
        sqlite3_stmt *stmt = delete_restrictions;
 
-       STC_LOGD("app_id [%s], iftype [%d], subscriber_id [%s]",
-                app_id, iftype, subscriber_id);
+       STC_LOGD("app_id[%s] iftype[%d] ifname[%s] subscriber_id[%s] roaming[%d]",
+                app_id, iftype, ifname, subscriber_id, roaming);
 
        DB_ACTION(sqlite3_bind_text(stmt, 1, app_id ? app_id : "",
                                    -1, SQLITE_TRANSIENT));
        DB_ACTION(sqlite3_bind_int(stmt, 2, iftype));
-       DB_ACTION(sqlite3_bind_text(stmt, 3, subscriber_id ? subscriber_id : "", -1,
-                                   SQLITE_TRANSIENT));
+       DB_ACTION(sqlite3_bind_text(stmt, 3, ifname ? ifname : "",
+                                   -1, SQLITE_TRANSIENT));
+       DB_ACTION(sqlite3_bind_text(stmt, 4, subscriber_id ? subscriber_id : "",
+                                       -1, SQLITE_TRANSIENT));
+       DB_ACTION(sqlite3_bind_int(stmt, 5, roaming));
 
        if (sqlite3_step(stmt) != SQLITE_DONE) {
                STC_LOGE("Failed to remove restrictions by network interface %s\n", //LCOV_EXCL_LINE
@@ -469,7 +496,9 @@ stc_error_e table_restrictions_delete(const char *app_id,
 
 handle_error:
 
-       sqlite3_reset(stmt);
+       if (sqlite3_reset(stmt) != SQLITE_OK)
+               error_code = STC_ERROR_DB_FAILED;
+
        return error_code;
 }
 
@@ -502,10 +531,14 @@ stc_error_e __get_restriction_id(table_restrictions_info *info)
        default:
                STC_LOGE("Failed to get restriction id: %s\n", //LCOV_EXCL_LINE
                         sqlite3_errmsg(stc_db_get_database()));
+               error_code = STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
        }
 
 handle_error:
-       sqlite3_reset(stmt);
+       rc = sqlite3_reset(stmt);
+       if (rc != SQLITE_OK)
+               error_code = STC_ERROR_DB_FAILED;
+
        __STC_LOG_FUNC_EXIT__;
        return error_code;
 }
@@ -520,7 +553,11 @@ stc_error_e table_restrictions_update(table_restrictions_info *info)
                goto handle_error; //LCOV_EXCL_LINE
        }
 
-       __get_restriction_id(info);
+       if (__get_restriction_id(info) != STC_ERROR_NONE) {
+               error_code = STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
+               goto handle_error; //LCOV_EXCL_LINE
+       }
+
        if (info->restriction_id)
                stmt = update_net_restrictions;
 
@@ -555,11 +592,14 @@ stc_error_e table_restrictions_update(table_restrictions_info *info)
                STC_LOGD("Restriction updated app_id [%s]", info->app_id);
        } else {
                STC_LOGD("Restriction inserted app_id [%s]", info->app_id);
-               __get_restriction_id(info);
+               if (__get_restriction_id(info) != STC_ERROR_NONE)
+                       error_code = STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
        }
 
 handle_error:
-       sqlite3_reset(stmt);
+       if (sqlite3_reset(stmt) != SQLITE_OK)
+               error_code = STC_ERROR_DB_FAILED;
+
        return error_code;
 }