Separate monitoring function plugin
[platform/core/connectivity/stc-manager.git] / src / stc-firewall.c
old mode 100644 (file)
new mode 100755 (executable)
index 2a1799c..64e7abb
@@ -207,8 +207,10 @@ static void __fw_rule_make_key(firewall_rule_s *rule,
        info->identifier = g_strdup(rule->identifier);
        info->key = rule->key;
 
-       STC_LOGD("Identifier [%s]", rule->identifier);
-       STC_LOGD("Key [%u]", rule->key);
+       if (STC_DEBUG_LOG && STC_FW_LOG) {
+               STC_LOGD("Identifier [%s]", rule->identifier);
+               STC_LOGD("Key [%u]", rule->key);
+       }
 }
 
 static void __fw_rule_free(void *data)
@@ -257,13 +259,15 @@ static stc_error_e __fw_chain_add(const char *chain)
 
        lookup = g_hash_table_lookup(g_firewalls, chain);
        if (lookup) {
-               STC_LOGD("chain already present");
+               if (STC_DEBUG_LOG && STC_FW_LOG)
+                       STC_LOGD("chain already present");
                return STC_ERROR_ALREADY_DATA;
        }
 
        data = MALLOC0(stc_fw_data_s, 1);
        if (!data) {
-               STC_LOGE("data allocation failed");
+               if (STC_DEBUG_LOG && STC_FW_LOG)
+                       STC_LOGE("data allocation failed");
                return STC_ERROR_OUT_OF_MEMORY;
        }
 
@@ -286,12 +290,14 @@ static stc_error_e __fw_chain_remove(const char *chain)
 
        lookup = g_hash_table_lookup(g_firewalls, chain);
        if (!lookup) {
-               STC_LOGE("chain not found");
+               if (STC_DEBUG_LOG && STC_FW_LOG)
+                       STC_LOGE("chain not found");
                return STC_ERROR_NO_DATA;
        }
 
        if (lookup->target != STC_FW_CHAIN_TARGET_NONE) {
-               STC_LOGE("can't be applied bcz chain is set");
+               if (STC_DEBUG_LOG && STC_FW_LOG)
+                       STC_LOGE("can't be applied bcz chain is set");
                return STC_ERROR_INVALID_PARAMETER;
        }
 
@@ -313,12 +319,14 @@ static stc_error_e __fw_chain_flush(const char *chain)
 
        lookup = g_hash_table_lookup(g_firewalls, chain);
        if (!lookup) {
-               STC_LOGE("chain not found");
+               if (STC_DEBUG_LOG && STC_FW_LOG)
+                       STC_LOGE("chain not found");
                return STC_ERROR_NO_DATA;
        }
 
        if (lookup->target != STC_FW_CHAIN_TARGET_NONE) {
-               STC_LOGE("can't be applied bcz chain is set");
+               if (STC_DEBUG_LOG && STC_FW_LOG)
+                       STC_LOGE("can't be applied bcz chain is set");
                return STC_ERROR_INVALID_PARAMETER;
        }
 
@@ -338,7 +346,8 @@ static stc_error_e __fw_chain_set(const char *chain, stc_fw_data_s value)
 
        lookup = g_hash_table_lookup(g_firewalls, chain);
        if (!lookup) {
-               STC_LOGE("chain not found");
+               if (STC_DEBUG_LOG && STC_FW_LOG)
+                       STC_LOGE("chain not found");
                return STC_ERROR_NO_DATA;
        }
 
@@ -357,7 +366,8 @@ static stc_fw_data_s *__fw_chain_get(const char *chain)
 
        lookup = g_hash_table_lookup(g_firewalls, chain);
        if (!lookup) {
-               STC_LOGE("chain not found");
+               if (STC_DEBUG_LOG && STC_FW_LOG)
+                       STC_LOGE("chain not found");
                return NULL;
        }
 
@@ -375,7 +385,8 @@ static stc_error_e __fw_chain_unset(const char *chain)
 
        lookup = g_hash_table_lookup(g_firewalls, chain);
        if (!lookup) {
-               STC_LOGE("chain not found");
+               if (STC_DEBUG_LOG && STC_FW_LOG)
+                       STC_LOGE("chain not found");
                return STC_ERROR_NO_DATA;
        }
 
@@ -747,7 +758,8 @@ stc_cb_ret_e __fw_table_chain_info_cb(const firewall_chain_s *info,
 
        data = MALLOC0(stc_fw_data_s, 1);
        if (!data) {
-               STC_LOGE("data allocation failed");
+               if (STC_DEBUG_LOG && STC_FW_LOG)
+                       STC_LOGE("data allocation failed");
                return STC_CONTINUE;
        }
 
@@ -768,13 +780,15 @@ stc_cb_ret_e __fw_table_rule_info_cb(const firewall_rule_s *info,
 
        lookup = g_hash_table_lookup(g_firewalls, info->chain);
        if (!lookup) {
-               STC_LOGE("chain not found");
+               if (STC_DEBUG_LOG && STC_FW_LOG)
+                       STC_LOGE("chain not found");
                return STC_CONTINUE;
        }
 
        rule = MALLOC0(firewall_rule_s, 1);
        if (!rule) {
-               STC_LOGE("rule allocation failed");
+               if (STC_DEBUG_LOG && STC_FW_LOG)
+                       STC_LOGE("rule allocation failed");
                return STC_CONTINUE;
        }
 
@@ -798,18 +812,21 @@ static stc_error_e __fw_rule_add(firewall_rule_s *info)
 
        lookup = g_hash_table_lookup(g_firewalls, info->chain);
        if (!lookup) {
-               STC_LOGE("chain not found");
+               if (STC_DEBUG_LOG && STC_FW_LOG)
+                       STC_LOGE("chain not found");
                return STC_ERROR_NO_DATA;
        }
 
        if (lookup->target != STC_FW_CHAIN_TARGET_NONE) {
-               STC_LOGE("can't be applied bcz chain is set");
+               if (STC_DEBUG_LOG && STC_FW_LOG)
+                       STC_LOGE("can't be applied bcz chain is set");
                return STC_ERROR_INVALID_PARAMETER;
        }
 
        rule = MALLOC0(firewall_rule_s, 1);
        if (!rule) {
-               STC_LOGE("rule allocation failed");
+               if (STC_DEBUG_LOG && STC_FW_LOG)
+                       STC_LOGE("rule allocation failed");
                return STC_ERROR_OUT_OF_MEMORY;
        }
 
@@ -819,7 +836,8 @@ static stc_error_e __fw_rule_add(firewall_rule_s *info)
 
        comp = g_slist_find_custom(lookup->rules, rule, __fw_rule_comp);
        if (comp) {
-               STC_LOGD("rule already present");
+               if (STC_DEBUG_LOG && STC_FW_LOG)
+                       STC_LOGD("rule already present");
                __fw_rule_free(rule);
                return STC_ERROR_ALREADY_DATA;
        }
@@ -842,19 +860,22 @@ static stc_error_e __fw_rule_remove(const firewall_rule_s *info)
 
        lookup = g_hash_table_lookup(g_firewalls, info->chain);
        if (!lookup) {
-               STC_LOGE("chain not found");
+               if (STC_DEBUG_LOG && STC_FW_LOG)
+                       STC_LOGE("chain not found");
                return STC_ERROR_NO_DATA;
        }
 
        if (lookup->target != STC_FW_CHAIN_TARGET_NONE) {
-               STC_LOGE("can't be applied bcz chain is set");
+               if (STC_DEBUG_LOG && STC_FW_LOG)
+                       STC_LOGE("can't be applied bcz chain is set");
                return STC_ERROR_INVALID_PARAMETER;
        }
 
        rule_list = lookup->rules;
        comp = g_slist_find_custom(rule_list, info, __fw_rule_comp);
        if (!comp) {
-               STC_LOGD("rule not found");
+               if (STC_DEBUG_LOG && STC_FW_LOG)
+                       STC_LOGD("rule not found");
                return STC_ERROR_NO_DATA;
        }
 
@@ -879,19 +900,22 @@ static stc_error_e __fw_rule_update(firewall_rule_s *info)
 
        lookup = g_hash_table_lookup(g_firewalls, info->chain);
        if (!lookup) {
-               STC_LOGE("chain not found");
+               if (STC_DEBUG_LOG && STC_FW_LOG)
+                       STC_LOGE("chain not found");
                return STC_ERROR_NO_DATA;
        }
 
        if (lookup->target != STC_FW_CHAIN_TARGET_NONE) {
-               STC_LOGE("can't be applied bcz chain is set");
+               if (STC_DEBUG_LOG && STC_FW_LOG)
+                       STC_LOGE("can't be applied bcz chain is set");
                return STC_ERROR_INVALID_PARAMETER;
        }
 
        rule_list = lookup->rules;
        comp = g_slist_find_custom(rule_list, info, __fw_rule_comp);
        if (!comp) {
-               STC_LOGD("rule not found");
+               if (STC_DEBUG_LOG && STC_FW_LOG)
+                       STC_LOGD("rule not found");
                return STC_ERROR_NO_DATA;
        }
 
@@ -899,7 +923,8 @@ static stc_error_e __fw_rule_update(firewall_rule_s *info)
 
        update_rule = MALLOC0(firewall_rule_s, 1);
        if (!update_rule) {
-               STC_LOGE("rule allocation failed");
+               if (STC_DEBUG_LOG && STC_FW_LOG)
+                       STC_LOGE("rule allocation failed");
                return STC_ERROR_OUT_OF_MEMORY;
        }
 
@@ -909,7 +934,8 @@ static stc_error_e __fw_rule_update(firewall_rule_s *info)
 
        comp = g_slist_find_custom(lookup->rules, update_rule, __fw_rule_comp);
        if (comp) {
-               STC_LOGD("rule already present");
+               if (STC_DEBUG_LOG && STC_FW_LOG)
+                       STC_LOGD("rule already present");
                __fw_rule_free(update_rule);
                return STC_ERROR_ALREADY_DATA;
        }
@@ -1190,6 +1216,8 @@ gboolean __validate_fw_rule(firewall_rule_s *rule)
 
 void stc_firewall_init(void)
 {
+       __STC_LOG_FUNC_ENTER__;
+
        int ret = STC_ERROR_NONE;
 
        g_firewalls = g_hash_table_new_full(g_str_hash,
@@ -1204,21 +1232,31 @@ void stc_firewall_init(void)
 
        table_firewall_foreach_chain(__fw_table_chain_info_cb, NULL);
        table_firewall_foreach_rule(__fw_table_rule_info_cb, NULL);
+
+       __STC_LOG_FUNC_EXIT__;
 }
 
-void stc_firewall_update(void)
+API void stc_firewall_update(void)
 {
+       __STC_LOG_FUNC_ENTER__;
+
        __fw_chain_foreach(__fw_foreach_to_add_chain, NULL);
        __fw_chain_foreach(__fw_foreach_to_set_rule_to_chain, NULL);
        __fw_chain_foreach(__fw_foreach_to_set_chain, NULL);
+
+       __STC_LOG_FUNC_EXIT__;
 }
 
 void stc_firewall_deinit(void)
 {
+       __STC_LOG_FUNC_ENTER__;
+
        if (g_firewalls) {
                g_hash_table_destroy(g_firewalls);
                g_firewalls = NULL;
        }
+
+       __STC_LOG_FUNC_EXIT__;
 }
 
 gboolean handle_firewall_lock(StcFirewall *object,
@@ -1518,7 +1556,8 @@ gboolean handle_firewall_unset_chain(StcFirewall *object,
        }
 
        if (lookup->target == STC_FW_CHAIN_TARGET_NONE) {
-               STC_LOGE("chain is not set");
+               if (STC_DEBUG_LOG && STC_FW_LOG)
+                       STC_LOGE("chain is not set");
                STC_FIREWALL_DBUS_REPLY_ERROR(invocation,
                                                STC_ERROR_INVALID_PARAMETER);
                __STC_LOG_FUNC_EXIT__;
@@ -1575,7 +1614,8 @@ gboolean handle_firewall_add_rule(StcFirewall *object,
 
        rule = MALLOC0(firewall_rule_s, 1);
        if (!rule) {
-               STC_LOGE("rule allocation failed");
+               if (STC_DEBUG_LOG && STC_FW_LOG)
+                       STC_LOGE("rule allocation failed");
                return STC_ERROR_OUT_OF_MEMORY;
        }
 
@@ -1627,7 +1667,8 @@ gboolean handle_firewall_remove_rule(StcFirewall *object,
 
        rule = MALLOC0(firewall_rule_s, 1);
        if (!rule) {
-               STC_LOGE("rule allocation failed");
+               if (STC_DEBUG_LOG && STC_FW_LOG)
+                       STC_LOGE("rule allocation failed");
                return STC_ERROR_OUT_OF_MEMORY;
        }
 
@@ -1680,7 +1721,8 @@ gboolean handle_firewall_update_rule(StcFirewall *object,
 
        rule = MALLOC0(firewall_rule_s, 1);
        if (!rule) {
-               STC_LOGE("rule allocation failed");
+               if (STC_DEBUG_LOG && STC_FW_LOG)
+                       STC_LOGE("rule allocation failed");
                return STC_ERROR_OUT_OF_MEMORY;
        }