Add some chains to separate monitoring and restriction
[platform/core/connectivity/stc-manager.git] / src / stc-restriction.c
index 2f44459..6b207a5 100644 (file)
@@ -43,16 +43,23 @@ static const gchar *stc_err_strs[] = {
 void __initialize_rstn_rule(table_restrictions_info *rule)
 {
        rule->app_id = NULL;
-       rule->ifname = NULL;
+
        rule->iftype = STC_IFACE_ALL;
+       rule->ifname = NULL;
+
+       rule->subscriber_id = NULL;
+       rule->roaming = STC_ROAMING_DISABLE;
+
        rule->rstn_type = STC_RSTN_TYPE_UNKNOWN;
        rule->data_limit = -1;
        rule->data_warn_limit = -1;
+
+       rule->month_start_date = 1;
        rule->monthly_limit = -1;
        rule->weekly_limit = -1;
        rule->daily_limit = -1;
-       rule->roaming = STC_ROAMING_DISABLE;
-       rule->subscriber_id = NULL;
+
+       rule->mac = NULL;
 }
 
 gboolean __validate_rstn_rule(table_restrictions_info *rule)
@@ -70,7 +77,7 @@ gboolean __validate_rstn_rule(table_restrictions_info *rule)
                return FALSE; //LCOV_EXCL_LINE
        }
 
-       if (rule->roaming >= STC_ROAMING_LAST_ELEM) {
+       if (rule->roaming > STC_ROAMING_ENABLE) {
                __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
                return FALSE; //LCOV_EXCL_LINE
        }
@@ -241,6 +248,12 @@ static void __stc_extract_restriction_rule(const char *key, GVariant *value,
                rule->rstn_type = g_variant_get_uint16(value);
                STC_LOGD("type: [%u]", (unsigned int) rule->rstn_type);
 
+       } else if (!g_strcmp0(key, "mac")) {
+               guint str_length;
+               const gchar *str = g_variant_get_string(value, &str_length);
+               rule->mac = g_strdup(str);
+               STC_LOGD("mac: [%s]", rule->mac);
+
        } else {
                STC_LOGD("Unknown select rule"); //LCOV_EXCL_LINE
        }
@@ -254,6 +267,7 @@ gboolean handle_restriction_set(StcRestriction *object,
        __STC_LOG_FUNC_ENTER__;
        GVariantIter *iter = NULL;
        table_restrictions_info rule;
+       stc_error_e ret = STC_ERROR_NONE;
 
        memset(&rule, 0, sizeof(table_restrictions_info));
        __initialize_rstn_rule(&rule);
@@ -273,10 +287,15 @@ gboolean handle_restriction_set(StcRestriction *object,
                return TRUE;
        }
 
-       table_restrictions_update(&rule);
-       /* update restriction rule in runtime structure */
-       stc_monitor_rstns_tree_add(&rule);
+       ret = table_restrictions_update(&rule);
+       if (ret != STC_ERROR_NONE) {
+               STC_RESTRICTION_DBUS_REPLY_ERROR(invocation, //LCOV_EXCL_LINE
+                                                STC_ERROR_DB_FAILED);
+               __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return TRUE;
+       }
 
+       stc_monitor_rstn_add(&rule);
        STC_DBUS_REPLY_ERROR_NONE(invocation);
        __STC_LOG_FUNC_EXIT__;
        return TRUE;
@@ -290,6 +309,7 @@ gboolean handle_restriction_unset(StcRestriction *object,
        __STC_LOG_FUNC_ENTER__;
        GVariantIter *iter = NULL;
        table_restrictions_info rule;
+       stc_error_e ret = STC_ERROR_NONE;
 
        memset(&rule, 0, sizeof(table_restrictions_info));
        __initialize_rstn_rule(&rule);
@@ -309,10 +329,16 @@ gboolean handle_restriction_unset(StcRestriction *object,
                return TRUE;
        }
 
-       table_restrictions_delete(rule.app_id, rule.iftype, rule.subscriber_id);
-       /* remove restriction rule from runtime structure */
-       stc_monitor_rstns_tree_remove(&rule);
+       ret = table_restrictions_delete(rule.app_id, rule.iftype, rule.ifname,
+                                       rule.subscriber_id, rule.roaming);
+       if (ret != STC_ERROR_NONE) {
+               STC_RESTRICTION_DBUS_REPLY_ERROR(invocation, //LCOV_EXCL_LINE
+                                                STC_ERROR_DB_FAILED);
+               __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return TRUE;
+       }
 
+       stc_monitor_rstn_remove(&rule);
        STC_DBUS_REPLY_ERROR_NONE(invocation);
        __STC_LOG_FUNC_EXIT__;
        return TRUE;