Moved exception list to plugin
[platform/core/connectivity/stc-manager.git] / src / monitor / stc-exception.c
index 87c3eeb..30579fc 100755 (executable)
  * @file        stc-exception.c
  */
 
+#include <pkgmgr-info.h>
+
 #include "stc-manager.h"
 #include "stc-exception.h"
 
 #define EXCEPTION_BUF_MAX   64
 #define EXCEPTION_STORAGE   "/var/lib/stc/exceptions"
 
-stc_error_e table_exceptions_foreach(const table_exceptions_info_cb exception_cb,
+#define INTERNET_PRIVILEGE  "http://tizen.org/privilege/internet"
+
+static GHashTable *g_pkginfo_filter_hash;
+
+stc_error_e table_exceptions_foreach(const stc_exceptions_info_cb exception_cb,
                                       void *user_data)
 {
        __STC_LOG_FUNC_ENTER__;
 
        stc_error_e error_code = STC_ERROR_NONE;
-       table_exceptions_info data;
+       stc_exceptions_info data;
 
        FILE *fp = NULL;
        char buf[EXCEPTION_BUF_MAX] = {0, };
@@ -64,3 +70,95 @@ stc_error_e table_exceptions_foreach(const table_exceptions_info_cb exception_cb
        __STC_LOG_FUNC_EXIT__;
        return error_code;
 }
+
+static int __pkginfo_filter_list_cb(pkgmgrinfo_pkginfo_h handle, void *user_data)
+{
+       int ret = 0;
+       char *pkgname = NULL;
+
+       ret = pkgmgrinfo_pkginfo_get_pkgname(handle, &pkgname);
+       if (ret == PMINFO_R_OK) {
+               if (g_hash_table_insert(g_pkginfo_filter_hash,
+                               g_strdup(pkgname), g_strdup(EXE_TYPE_APPLICATION)) != TRUE)
+                       STC_LOGE("Failed to insert hash table");
+       }
+
+       return STC_CONTINUE;
+}
+
+static int __pkginfo_pkg_list_cb(pkgmgrinfo_pkginfo_h handle, void *user_data)
+{
+       int ret = 0;
+       char *pkgname = NULL;
+       char *exe_type = NULL;
+       stc_exceptions_info data;
+       const stc_exceptions_info_cb excn_cb = user_data;
+
+       ret = pkgmgrinfo_pkginfo_get_pkgname(handle, &pkgname);
+       if (ret == PMINFO_R_OK) {
+               exe_type = g_hash_table_lookup(g_pkginfo_filter_hash, pkgname);
+               if (exe_type)
+                       return STC_CONTINUE;
+
+               data.process_name = pkgname;
+               data.exe_type = EXE_TYPE_APPLICATION;
+
+               if (excn_cb(&data, NULL) == STC_CANCEL)
+                       STC_LOGE("Failed to insert hash table");
+       }
+
+       return STC_CONTINUE;
+}
+
+stc_error_e pkginfo_exceptions_foreach(const stc_exceptions_info_cb exception_cb,
+                                      void *user_data)
+{
+       __STC_LOG_FUNC_ENTER__;
+
+       int ret = 0;
+       int err = STC_ERROR_NONE;
+       pkgmgrinfo_pkginfo_filter_h handle;
+
+       g_pkginfo_filter_hash = g_hash_table_new_full(g_str_hash,
+                                               g_str_equal, g_free, g_free);
+
+       ret = pkgmgrinfo_pkginfo_filter_create(&handle);
+       ret_value_msg_if(ret != PMINFO_R_OK, STC_ERROR_FAIL,
+                       "Failed to create pkginfo filter");
+
+       ret = pkgmgrinfo_pkginfo_filter_add_string(handle,
+                       PMINFO_PKGINFO_PROP_PACKAGE_PRIVILEGE,
+                       INTERNET_PRIVILEGE);
+       if (ret != PMINFO_R_OK) {
+               STC_LOGE("Failed to add pkginfo filter string");
+               err = STC_ERROR_FAIL;
+               goto out;
+       }
+
+       ret = pkgmgrinfo_pkginfo_filter_foreach_pkginfo(handle,
+                       __pkginfo_filter_list_cb, NULL);
+       if (ret != PMINFO_R_OK) {
+               STC_LOGE("Failed to foreach pkginfo filter");
+               err = STC_ERROR_FAIL;
+               goto out;
+       }
+
+       ret = pkgmgrinfo_pkginfo_get_list(__pkginfo_pkg_list_cb, exception_cb);
+       if (ret != PMINFO_R_OK) {
+               STC_LOGE("Failed to get pkginfo list");
+               err = STC_ERROR_FAIL;
+               goto out;
+       }
+
+out:
+       if (g_pkginfo_filter_hash) {
+               g_hash_table_destroy(g_pkginfo_filter_hash);
+               g_pkginfo_filter_hash = NULL;
+       }
+
+       if (handle)
+               pkgmgrinfo_pkginfo_filter_destroy(handle);
+
+       __STC_LOG_FUNC_EXIT__;
+       return err;
+}