Merge "Return errors to caller" into tizen_5.5
[platform/core/connectivity/stc-manager.git] / src / stc-restriction.c
index d47aaf0..7e0e847 100755 (executable)
@@ -259,6 +259,14 @@ static void __stc_extract_restriction_rule(const char *key, GVariant *value,
        }
 }
 
+static void __stc_free_restriction_rule_members(table_restrictions_info *rule)
+{
+       FREE(rule->app_id);
+       FREE(rule->ifname);
+       FREE(rule->subscriber_id);
+       FREE(rule->mac);
+}
+
 gboolean handle_restriction_set(StcRestriction *object,
                                GDBusMethodInvocation *invocation,
                                GVariant *parameters,
@@ -285,6 +293,7 @@ gboolean handle_restriction_set(StcRestriction *object,
        if (__validate_rstn_rule(&rule) == FALSE) {
                STC_RESTRICTION_DBUS_REPLY_ERROR(invocation, //LCOV_EXCL_LINE
                                                 STC_ERROR_INVALID_PARAMETER);
+               __stc_free_restriction_rule_members(&rule);
                __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
                return TRUE;
        }
@@ -293,12 +302,29 @@ gboolean handle_restriction_set(StcRestriction *object,
        if (ret != STC_ERROR_NONE) {
                STC_RESTRICTION_DBUS_REPLY_ERROR(invocation, //LCOV_EXCL_LINE
                                                 STC_ERROR_DB_FAILED);
+               __stc_free_restriction_rule_members(&rule);
                __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
                return TRUE;
        }
 
-       stc_plugin_monitor_add_rstn(&rule);
+       ret = stc_plugin_monitor_add_rstn(&rule);
+       if (ret == STC_ERROR_UNINITIALIZED) {
+               STC_RESTRICTION_DBUS_REPLY_ERROR(invocation, //LCOV_EXCL_LINE
+                                                STC_ERROR_UNINITIALIZED);
+               table_restrictions_delete(rule.app_id, rule.iftype, rule.ifname,
+                                       rule.subscriber_id, rule.roaming);
+               __stc_free_restriction_rule_members(&rule);
+               __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return TRUE;
+       } else if (ret == STC_ERROR_NO_DATA || ret == STC_ERROR_OUT_OF_MEMORY) {
+               STC_RESTRICTION_DBUS_REPLY_ERROR(invocation, //LCOV_EXCL_LINE
+                                                ret);
+               __stc_free_restriction_rule_members(&rule);
+               __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return TRUE;
+       }
        STC_DBUS_REPLY_ERROR_NONE(invocation);
+       __stc_free_restriction_rule_members(&rule);
        __STC_LOG_FUNC_EXIT__;
        return TRUE;
 }
@@ -329,6 +355,7 @@ gboolean handle_restriction_unset(StcRestriction *object,
        if (__validate_rstn_rule(&rule) == FALSE) {
                STC_RESTRICTION_DBUS_REPLY_ERROR(invocation, //LCOV_EXCL_LINE
                                                 STC_ERROR_INVALID_PARAMETER);
+               __stc_free_restriction_rule_members(&rule);
                __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
                return TRUE;
        }
@@ -338,12 +365,29 @@ gboolean handle_restriction_unset(StcRestriction *object,
        if (ret != STC_ERROR_NONE) {
                STC_RESTRICTION_DBUS_REPLY_ERROR(invocation, //LCOV_EXCL_LINE
                                                 STC_ERROR_DB_FAILED);
+               __stc_free_restriction_rule_members(&rule);
+               __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return TRUE;
+       }
+
+       ret = stc_plugin_monitor_remove_rstn(&rule);
+       if (ret == STC_ERROR_UNINITIALIZED) {
+               STC_RESTRICTION_DBUS_REPLY_ERROR(invocation, //LCOV_EXCL_LINE
+                                                STC_ERROR_UNINITIALIZED);
+               __stc_free_restriction_rule_members(&rule);
+               __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return TRUE;
+       } else if (ret == STC_ERROR_NO_DATA) {
+               table_restrictions_update(&rule);
+               STC_RESTRICTION_DBUS_REPLY_ERROR(invocation, //LCOV_EXCL_LINE
+                                               STC_ERROR_NO_DATA);
+               __stc_free_restriction_rule_members(&rule);
                __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
                return TRUE;
        }
 
-       stc_plugin_monitor_remove_rstn(&rule);
        STC_DBUS_REPLY_ERROR_NONE(invocation);
+       __stc_free_restriction_rule_members(&rule);
        __STC_LOG_FUNC_EXIT__;
        return TRUE;
 }
@@ -376,6 +420,7 @@ gboolean handle_restriction_set_list(StcRestriction *object,
                                STC_RESTRICTION_DBUS_REPLY_ERROR(invocation, ret); //LCOV_EXCL_LINE
                                g_variant_iter_free(iter_row);
                                g_variant_iter_free(iter);
+                               __stc_free_restriction_rule_members(&rule);
                                __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
                                return TRUE;
                        }
@@ -385,11 +430,13 @@ gboolean handle_restriction_set_list(StcRestriction *object,
                                STC_RESTRICTION_DBUS_REPLY_ERROR(invocation, ret); //LCOV_EXCL_LINE
                                g_variant_iter_free(iter_row);
                                g_variant_iter_free(iter);
+                               __stc_free_restriction_rule_members(&rule);
                                __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
                                return TRUE;
                        }
                }
 
+               __stc_free_restriction_rule_members(&rule);
                g_variant_iter_free(iter_row);
        }
        g_variant_iter_free(iter);
@@ -428,6 +475,7 @@ gboolean handle_restriction_unset_list(StcRestriction *object,
                                STC_RESTRICTION_DBUS_REPLY_ERROR(invocation, ret); //LCOV_EXCL_LINE
                                g_variant_iter_free(iter_row);
                                g_variant_iter_free(iter);
+                               __stc_free_restriction_rule_members(&rule);
                                __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
                                return TRUE;
                        }
@@ -437,11 +485,13 @@ gboolean handle_restriction_unset_list(StcRestriction *object,
                                STC_RESTRICTION_DBUS_REPLY_ERROR(invocation, ret); //LCOV_EXCL_LINE
                                g_variant_iter_free(iter_row);
                                g_variant_iter_free(iter);
+                               __stc_free_restriction_rule_members(&rule);
                                __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
                                return TRUE;
                        }
                }
 
+               __stc_free_restriction_rule_members(&rule);
                g_variant_iter_free(iter_row);
        }
        g_variant_iter_free(iter);