Separately identify restrictions by rst_type 39/170639/1
authorNishant Chaprana <n.chaprana@samsung.com>
Wed, 21 Feb 2018 06:25:51 +0000 (11:55 +0530)
committerNishant Chaprana <n.chaprana@samsung.com>
Wed, 21 Feb 2018 06:25:51 +0000 (11:55 +0530)
Description: This patch adds logic to separately identify restriction
on basis of restriction type (Blocked/Excluded).
Also it stores rst_type inplace of rst_state in restriction table because
rst_state is only to check whether restriction is active or not and
we are not required to store that information to database.

Change-Id: I5f540c5b791634072d58c87e7eceda8e6f653e76
Signed-off-by: Nishant Chaprana <n.chaprana@samsung.com>
data/traffic_db.sql
include/stc-manager.h
packaging/stc-manager.spec
src/database/include/table-restrictions.h
src/database/tables/table-restrictions.c
src/monitor/include/stc-monitor.h
src/monitor/stc-monitor.c
src/stc-restriction.c

index dd83d65..c305dbd 100644 (file)
@@ -20,7 +20,7 @@ CREATE TABLE IF NOT EXISTS restrictions (
   binpath TEXT,
   iftype INT,
   ifname TEXT,
-  rst_state INT,
+  rst_type INT,
   roaming INT,
   subscriber_id TEXT NOT NULL,
   data_limit BIGINT,
index f2b9c97..bb23514 100755 (executable)
@@ -84,6 +84,16 @@ typedef enum {
 } stc_restriction_state_e;
 
 /**
+ * @brief Network restriction types
+ */
+typedef enum {
+       STC_RSTN_TYPE_UNKNOWN,
+       STC_RSTN_TYPE_EXCLUDED,  /**< exclusion */
+       STC_RSTN_TYPE_BLOCKED,    /**< block */
+       STC_RSTN_TYPE_LAST_ELEM
+} stc_rstn_type_e;
+
+/**
  * @brief Network interface types
  */
 typedef enum {
index d896960..7762b06 100644 (file)
@@ -1,6 +1,6 @@
 Name:       stc-manager
 Summary:    STC(Smart Traffic Control) manager
-Version:    0.0.52
+Version:    0.0.53
 Release:    0
 Group:      Network & Connectivity/Other
 License:    Apache-2.0
index d972b87..e006bdc 100755 (executable)
@@ -22,7 +22,7 @@ typedef struct {
        char *ifname;
        char *subscriber_id;
        stc_iface_type_e iftype;
-       stc_restriction_state_e rst_state;
+       stc_rstn_type_e rst_type;
        stc_roaming_type_e roaming;
        int64_t data_limit;
        int64_t data_warn_limit;
index 1c717e4..2d64f9c 100755 (executable)
 
 /* SELECT statements */
 #define SELECT_RESTRICTIONS "SELECT binpath, data_limit, " \
-       " iftype, rst_state, roaming, ifname, subscriber_id, " \
+       " iftype, rst_type, roaming, ifname, subscriber_id, " \
        " data_warn_limit, restriction_id FROM restrictions"
 
 #define SELECT_RESTRICTIONS_PER_APP "SELECT binpath, data_limit, " \
-       " iftype, rst_state, roaming, ifname, subscriber_id, " \
+       " iftype, rst_type, roaming, ifname, subscriber_id, " \
        " data_warn_limit, restriction_id " \
        " FROM restrictions INDEXED BY restrictions_index " \
        " WHERE binpath = ?"
 
-#define SELECT_RESTRICTION_STATE "SELECT rst_state " \
+#define SELECT_RESTRICTION_STATE "SELECT rst_type " \
        " FROM restrictions INDEXED BY restrictions_index " \
        " WHERE binpath = ? AND iftype = ?"
 
-#define SELECT_RESTRICTION_STATE_SUBSCRIBER_ID "SELECT rst_state " \
+#define SELECT_RESTRICTION_STATE_SUBSCRIBER_ID "SELECT rst_type " \
        " FROM restrictions INDEXED BY restrictions_index " \
        " WHERE binpath = ? AND iftype = ? AND subscriber_id = ?"
 
 #define SELECT_RESTRICTION_ID "SELECT restriction_id FROM restrictions " \
        " WHERE binpath = ? AND iftype = ? AND subscriber_id = ? AND " \
-       " rst_state = ? AND roaming = ? AND ifname = ?"
+       " rst_type = ? AND roaming = ? AND ifname = ?"
 
 /* UPDATE statement */
 #define UPDATE_NET_RESTRICTIONS "UPDATE restrictions " \
-       " SET binpath = ?, data_limit = ?, iftype = ?, rst_state = ?, " \
+       " SET binpath = ?, data_limit = ?, iftype = ?, rst_type = ?, " \
        " roaming = ?, ifname = ?, subscriber_id = ?, data_warn_limit = ? " \
        " WHERE restriction_id = ?"
 
 /* INSERT statement */
 #define INSERT_NET_RESTRICTIONS "INSERT INTO restrictions " \
-       " (binpath, data_limit, iftype, rst_state, " \
+       " (binpath, data_limit, iftype, rst_type, " \
        " roaming, ifname, subscriber_id, data_warn_limit) " \
        " VALUES (?, ?, ?, ?, ?, ?, ?, ?)"
 
@@ -285,8 +285,8 @@ stc_error_e table_restrictions_per_app(const gchar* app_id,
                        data.app_id = (char *)sqlite3_column_text(stmt, 0);
                        data.data_limit = sqlite3_column_int64(stmt, 1);
                        data.iftype = (stc_iface_type_e)sqlite3_column_int(stmt, 2);
-                       data.rst_state =
-                               (stc_restriction_state_e)sqlite3_column_int(stmt, 3);
+                       data.rst_type =
+                               (stc_rstn_type_e)sqlite3_column_int(stmt, 3);
                        data.roaming = sqlite3_column_int(stmt, 4);
                        data.ifname = (char *)sqlite3_column_text(stmt, 5);
                        data.subscriber_id = (char *)sqlite3_column_text(stmt, 6);
@@ -333,8 +333,8 @@ stc_error_e table_restrictions_foreach(const table_restrictions_info_cb restrict
                        data.app_id = (char *)sqlite3_column_text(stmt, 0);
                        data.data_limit = sqlite3_column_int64(stmt, 1);
                        data.iftype = (stc_iface_type_e)sqlite3_column_int(stmt, 2);
-                       data.rst_state =
-                               (stc_restriction_state_e)sqlite3_column_int(stmt, 3);
+                       data.rst_type =
+                               (stc_rstn_type_e)sqlite3_column_int(stmt, 3);
                        data.roaming = sqlite3_column_int(stmt, 4);
                        data.ifname = (char *)sqlite3_column_text(stmt, 5);
                        data.subscriber_id = (char *)sqlite3_column_text(stmt, 6);
@@ -475,7 +475,7 @@ stc_error_e __get_restriction_id(table_restrictions_info *info)
        DB_ACTION(sqlite3_bind_int(stmt, 2, info->iftype));
        DB_ACTION(sqlite3_bind_text(stmt, 3, info->subscriber_id ? info->subscriber_id : "",
                                    -1, SQLITE_TRANSIENT));
-       DB_ACTION(sqlite3_bind_int(stmt, 4, info->rst_state));
+       DB_ACTION(sqlite3_bind_int(stmt, 4, info->rst_type));
        DB_ACTION(sqlite3_bind_int(stmt, 5, info->roaming));
        DB_ACTION(sqlite3_bind_text(stmt, 6, info->ifname ? info->ifname : "",
                                    -1, SQLITE_TRANSIENT));
@@ -519,7 +519,7 @@ stc_error_e table_restrictions_update(table_restrictions_info *info)
                                    -1, SQLITE_TRANSIENT));
        DB_ACTION(sqlite3_bind_int64(stmt, 2, info->data_limit));
        DB_ACTION(sqlite3_bind_int(stmt, 3, info->iftype));
-       DB_ACTION(sqlite3_bind_int(stmt, 4, info->rst_state));
+       DB_ACTION(sqlite3_bind_int(stmt, 4, info->rst_type));
        DB_ACTION(sqlite3_bind_int(stmt, 5, info->roaming));
        DB_ACTION(sqlite3_bind_text(stmt, 6, info->ifname ? info->ifname : "",
                                    -1, SQLITE_TRANSIENT));
index b8a7357..3437637 100755 (executable)
@@ -79,6 +79,7 @@ typedef struct {
        uint64_t restriction_id;
        uint32_t classid;
        stc_restriction_state_e rst_state;
+       stc_rstn_type_e rst_type;
        int64_t data_limit;
        int64_t data_warn_limit;
        int64_t data_counter;
index b27c97f..50a917f 100755 (executable)
@@ -257,6 +257,10 @@ static int __rstns_tree_key_compare(gconstpointer a, gconstpointer b,
        if (ret != 0)
                return ret;
 
+       ret = key_a->roaming - key_b->roaming;
+       if (ret != 0)
+               return ret;
+
        return 0;
 }
 
@@ -1346,6 +1350,7 @@ static stc_error_e __rstn_tree_add(stc_rstn_key_s *key,
 
        rstn_value->restriction_id = value->restriction_id;
        rstn_value->rst_state = value->rst_state;
+       rstn_value->rst_type = value->rst_type;
        rstn_value->classid = value->classid;
        rstn_value->data_limit = value->data_limit;
        rstn_value->data_warn_limit = value->data_warn_limit;
@@ -1379,10 +1384,11 @@ static stc_cb_ret_e __insert_restriction_cb(const table_restrictions_info *info,
        key.iftype = info->iftype;
        key.roaming = info->roaming;
 
-       value.rst_state = info->rst_state;
+       value.rst_type = info->rst_type;
+       value.rst_state = STC_RESTRICTION_UNKNOWN;
        value.restriction_id = info->restriction_id;
 
-       if (value.rst_state != STC_RESTRICTION_EXCLUDED && info->app_id)
+       if (info->app_id)
                value.classid = get_classid_by_app_id(info->app_id, TRUE);
        else
                value.classid = STC_UNKNOWN_CLASSID;
@@ -1868,12 +1874,11 @@ stc_error_e stc_monitor_rstns_tree_add(const table_restrictions_info *info)
        key.iftype = info->iftype;
        key.roaming = info->roaming;
 
-       value.rst_state = info->rst_state;
+       value.rst_type = info->rst_type;
+       value.rst_state = STC_RESTRICTION_UNKNOWN;
        value.restriction_id = info->restriction_id;
 
-       if (value.rst_state > STC_RESTRICTION_UNKNOWN &&
-               value.rst_state < STC_RESTRICTION_LAST_ELEM &&
-               info->app_id)
+       if (info->app_id)
                value.classid = get_classid_by_app_id(info->app_id, TRUE);
        else
                value.classid = STC_UNKNOWN_CLASSID;
index e8a8a7d..cb3a382 100755 (executable)
@@ -43,7 +43,7 @@ void __initialize_rstn_rule(table_restrictions_info *rule)
        rule->app_id = NULL;
        rule->ifname = NULL;
        rule->iftype = STC_IFACE_ALL;
-       rule->rst_state = STC_RESTRICTION_REMOVED;
+       rule->rst_type = STC_RSTN_TYPE_UNKNOWN;
        rule->data_limit = 0;
        rule->data_warn_limit = 0;
        rule->roaming = STC_ROAMING_DISABLE;
@@ -109,8 +109,8 @@ void __stc_restriction_app_info_builder_add(GVariantBuilder *builder,
        g_variant_builder_add(builder, "{sv}", "iftype",
                              g_variant_new_uint16(info->iftype));
 
-       g_variant_builder_add(builder, "{sv}", "rst_state",
-                             g_variant_new_uint16(info->rst_state));
+       g_variant_builder_add(builder, "{sv}", "rst_type",
+                             g_variant_new_uint16(info->rst_type));
 
        g_variant_builder_add(builder, "{sv}", "data_limit",
                              g_variant_new_int64(info->data_limit));
@@ -239,7 +239,7 @@ gboolean handle_restriction_set(StcRestriction *object,
                g_variant_iter_free(iter);
        }
 
-       rule.rst_state = STC_RESTRICTION_REMOVED;
+       rule.rst_type = STC_RSTN_TYPE_BLOCKED;
 
        if (__validate_rstn_rule(&rule, RST_SET) == FALSE) {
                STC_RESTRICTION_DBUS_REPLY_ERROR(invocation, //LCOV_EXCL_LINE
@@ -277,7 +277,7 @@ gboolean handle_restriction_exclude(StcRestriction *object,
                g_variant_iter_free(iter);
        }
 
-       rule.rst_state = STC_RESTRICTION_EXCLUDED;
+       rule.rst_type = STC_RSTN_TYPE_EXCLUDED;
 
        if (__validate_rstn_rule(&rule, RST_EXCLUDE) == FALSE) {
                STC_RESTRICTION_DBUS_REPLY_ERROR(invocation, //LCOV_EXCL_LINE