Fix local variable initialization and handle a invalid parameter
[platform/core/connectivity/stc-manager.git] / src / stc-restriction.c
old mode 100755 (executable)
new mode 100644 (file)
index 05d7544..2f44459
@@ -46,14 +46,16 @@ void __initialize_rstn_rule(table_restrictions_info *rule)
        rule->ifname = NULL;
        rule->iftype = STC_IFACE_ALL;
        rule->rstn_type = STC_RSTN_TYPE_UNKNOWN;
-       rule->data_limit = 0;
-       rule->data_warn_limit = 0;
+       rule->data_limit = -1;
+       rule->data_warn_limit = -1;
+       rule->monthly_limit = -1;
+       rule->weekly_limit = -1;
+       rule->daily_limit = -1;
        rule->roaming = STC_ROAMING_DISABLE;
        rule->subscriber_id = NULL;
 }
 
-gboolean __validate_rstn_rule(table_restrictions_info *rule,
-                             enum traffic_restriction_type rstn_type)
+gboolean __validate_rstn_rule(table_restrictions_info *rule)
 {
        __STC_LOG_FUNC_ENTER__;
 
@@ -62,11 +64,6 @@ gboolean __validate_rstn_rule(table_restrictions_info *rule,
                return FALSE; //LCOV_EXCL_LINE
        }
 
-       if (rstn_type <= RST_UNDEFINDED || rstn_type >= RST_MAX_VALUE) {
-               __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
-               return FALSE; //LCOV_EXCL_LINE
-       }
-
        if (rule->iftype <= STC_IFACE_UNKNOWN ||
            rule->iftype >= STC_IFACE_LAST_ELEM) {
                __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
@@ -120,6 +117,18 @@ void __stc_restriction_app_info_builder_add(GVariantBuilder *builder,
        g_variant_builder_add(builder, "{sv}", "data_warn_limit",
                              g_variant_new_int64(info->data_warn_limit));
 
+       g_variant_builder_add(builder, "{sv}", "month_start_date",
+                             g_variant_new_int32(info->month_start_date));
+
+       g_variant_builder_add(builder, "{sv}", "monthly_limit",
+                             g_variant_new_int64(info->monthly_limit));
+
+       g_variant_builder_add(builder, "{sv}", "weekly_limit",
+                             g_variant_new_int64(info->weekly_limit));
+
+       g_variant_builder_add(builder, "{sv}", "daily_limit",
+                             g_variant_new_int64(info->daily_limit));
+
        g_variant_builder_add(builder, "{sv}", "roaming",
                              g_variant_new_uint16(info->roaming));
 
@@ -171,8 +180,6 @@ stc_cb_ret_e __table_restrictions_per_app_cb(const table_restrictions_info *info
 static void __stc_extract_restriction_rule(const char *key, GVariant *value,
                                           void *user_data)
 {
-       __STC_LOG_FUNC_ENTER__;
-
        table_restrictions_info *rule =
                (table_restrictions_info *) user_data;
        if (rule == NULL) {
@@ -184,7 +191,7 @@ static void __stc_extract_restriction_rule(const char *key, GVariant *value,
                guint str_length;
                const gchar *str = g_variant_get_string(value, &str_length);
                rule->app_id = g_strdup(str);
-               STC_LOGD("app_id: [%s]", (unsigned int) rule->app_id);
+               STC_LOGD("app_id: [%s]", rule->app_id);
 
        } else if (!g_strcmp0(key, "ifname")) {
                guint str_length;
@@ -204,6 +211,22 @@ static void __stc_extract_restriction_rule(const char *key, GVariant *value,
                rule->data_warn_limit = g_variant_get_int64(value);
                STC_LOGD("data_warn_limit: [%lld]", rule->data_warn_limit);
 
+       } else if (!g_strcmp0(key, "month_start_date")) {
+               rule->month_start_date = g_variant_get_int32(value);
+               STC_LOGD("month_start_date: [%d]", rule->month_start_date);
+
+       } else if (!g_strcmp0(key, "monthly_limit")) {
+               rule->monthly_limit = g_variant_get_int64(value);
+               STC_LOGD("monthly_limit: [%lld]", rule->monthly_limit);
+
+       } else if (!g_strcmp0(key, "weekly_limit")) {
+               rule->weekly_limit = g_variant_get_int64(value);
+               STC_LOGD("weekly_limit: [%lld]", rule->weekly_limit);
+
+       } else if (!g_strcmp0(key, "daily_limit")) {
+               rule->daily_limit = g_variant_get_int64(value);
+               STC_LOGD("daily_limit: [%lld]", rule->daily_limit);
+
        } else if (!g_strcmp0(key, "roaming")) {
                rule->roaming = g_variant_get_uint16(value);
                STC_LOGD("roaming: [%u]", rule->roaming);
@@ -214,11 +237,13 @@ static void __stc_extract_restriction_rule(const char *key, GVariant *value,
                rule->subscriber_id = g_strdup(str);
                STC_LOGD("subscriber_id: [%s]", rule->subscriber_id);
 
+       } else if (!g_strcmp0(key, "rstn_type")) {
+               rule->rstn_type = g_variant_get_uint16(value);
+               STC_LOGD("type: [%u]", (unsigned int) rule->rstn_type);
+
        } else {
                STC_LOGD("Unknown select rule"); //LCOV_EXCL_LINE
        }
-
-       __STC_LOG_FUNC_EXIT__;
 }
 
 gboolean handle_restriction_set(StcRestriction *object,
@@ -241,47 +266,7 @@ gboolean handle_restriction_set(StcRestriction *object,
                g_variant_iter_free(iter);
        }
 
-       rule.rstn_type = STC_RSTN_TYPE_DROP;
-
-       if (__validate_rstn_rule(&rule, RST_SET) == FALSE) {
-               STC_RESTRICTION_DBUS_REPLY_ERROR(invocation, //LCOV_EXCL_LINE
-                                                STC_ERROR_INVALID_PARAMETER);
-               __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
-               return TRUE;
-       }
-
-       table_restrictions_update(&rule);
-       /* update restriction rule in runtime structure */
-       stc_monitor_rstns_tree_add(&rule);
-
-       STC_DBUS_REPLY_ERROR_NONE(invocation);
-       __STC_LOG_FUNC_EXIT__;
-       return TRUE;
-}
-
-gboolean handle_restriction_exclude(StcRestriction *object,
-                                   GDBusMethodInvocation *invocation,
-                                   GVariant *parameters,
-                                   void *user_data)
-{
-       __STC_LOG_FUNC_ENTER__;
-       GVariantIter *iter = NULL;
-       table_restrictions_info rule;
-
-       memset(&rule, 0, sizeof(table_restrictions_info));
-       __initialize_rstn_rule(&rule);
-
-       g_variant_get(parameters, "a{sv}", &iter);
-       if (iter != NULL) {
-               stc_manager_gdbus_dict_foreach(iter,
-                                              __stc_extract_restriction_rule,
-                                              &rule);
-               g_variant_iter_free(iter);
-       }
-
-       rule.rstn_type = STC_RSTN_TYPE_ACCEPT;
-
-       if (__validate_rstn_rule(&rule, RST_EXCLUDE) == FALSE) {
+       if (__validate_rstn_rule(&rule) == FALSE) {
                STC_RESTRICTION_DBUS_REPLY_ERROR(invocation, //LCOV_EXCL_LINE
                                                 STC_ERROR_INVALID_PARAMETER);
                __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
@@ -317,7 +302,7 @@ gboolean handle_restriction_unset(StcRestriction *object,
                g_variant_iter_free(iter);
        }
 
-       if (__validate_rstn_rule(&rule, RST_UNSET) == FALSE) {
+       if (__validate_rstn_rule(&rule) == FALSE) {
                STC_RESTRICTION_DBUS_REPLY_ERROR(invocation, //LCOV_EXCL_LINE
                                                 STC_ERROR_INVALID_PARAMETER);
                __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE