Change column name defined in query
[platform/core/appfw/pkgmgr-info.git] / src / pkgmgrinfo_pkginfo.c
index 203dbd2..2b22e92 100644 (file)
@@ -53,8 +53,8 @@ static bool _get_bool_value(const char *str)
 
 static gint __compare_func(gconstpointer data1, gconstpointer data2)
 {
-       pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1;
-       pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x*)data2;
+       pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x *)data1;
+       pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x *)data2;
        if (node1->prop == node2->prop)
                return 0;
        else if (node1->prop > node2->prop)
@@ -66,7 +66,7 @@ static gint __compare_func(gconstpointer data1, gconstpointer data2)
 static void __destroy_each_node(gpointer data, gpointer user_data)
 {
        ret_if(data == NULL);
-       pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
+       pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)data;
        if (node->value) {
                free(node->value);
                node->value = NULL;
@@ -170,11 +170,12 @@ static int _pkginfo_get_privilege(sqlite3 *db, const char *pkgid,
                GList **privileges)
 {
        static const char query_raw[] =
-               "SELECT privilege FROM package_privilege_info WHERE package=%Q";
+               "SELECT DISTINCT privilege FROM package_privilege_info "
+               "WHERE package=%Q";
        int ret;
        char *query;
        sqlite3_stmt *stmt;
-       char *privilege;
+       privilege_x *privilege;
 
        query = sqlite3_mprintf(query_raw, pkgid);
        if (query == NULL) {
@@ -191,11 +192,11 @@ static int _pkginfo_get_privilege(sqlite3 *db, const char *pkgid,
        }
 
        while (sqlite3_step(stmt) == SQLITE_ROW) {
-               privilege = NULL;
-               _save_column_str(stmt, 0, &privilege);
-               if (privilege)
-                       *privileges = g_list_append(*privileges,
-                                       (gpointer)privilege);
+               privilege = calloc(1, sizeof(privilege_x));
+               _save_column_str(stmt, 0, &privilege->value);
+               _save_column_str(stmt, 1, &privilege->type);
+               *privileges = g_list_append(*privileges,
+                               (gpointer)privilege);
        }
 
        sqlite3_finalize(stmt);
@@ -296,7 +297,8 @@ static int _pkginfo_get_packages(uid_t uid, const char *locale,
                "pi.storeclient_id, pi.mainapp_id, pi.package_url, "
                "pi.root_path, pi.csc_path, pi.package_nodisplay, "
                "pi.package_api_version, pi.package_support_disable, "
-               "pi.package_tep_name, pi.package_zip_mount_file";
+               "pi.package_tep_name, pi.package_zip_mount_file, pi.external_path, "
+               "pi.package_support_mode";
        static const char query_author[] =
                ", pi.author_name, pi.author_email, pi.author_href";
        static const char query_label[] =
@@ -436,6 +438,8 @@ static int _pkginfo_get_packages(uid_t uid, const char *locale,
                _save_column_str(stmt, idx++, &info->support_disable);
                _save_column_str(stmt, idx++, &info->tep_name);
                _save_column_str(stmt, idx++, &info->zip_mount_file);
+               _save_column_str(stmt, idx++, &info->external_path);
+               _save_column_str(stmt, idx++, &info->support_mode);
                info->for_all_users =
                        strdup((uid != GLOBAL_USER) ? "false" : "true");
 
@@ -499,6 +503,13 @@ static int _pkginfo_get_packages(uid_t uid, const char *locale,
                        }
                }
 
+               if (__pkginfo_check_installed_storage(info) != PMINFO_R_OK) {
+                       ret = PMINFO_R_ERROR;
+                       pkgmgrinfo_basic_free_package(info);
+                       info = NULL;
+                       continue;
+               }
+
                g_hash_table_insert(packages, (gpointer)info->package,
                                (gpointer)info);
        }
@@ -735,10 +746,11 @@ API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
 
        if (info->pkg_info == NULL)
                return PMINFO_R_ERROR;
-       if (info->pkg_info->type == NULL)
-               info->pkg_info->type = strdup("");
 
-       *type = (char *)info->pkg_info->type;
+       if (info->pkg_info->type == NULL)
+               *type = "";
+       else
+               *type = (char *)info->pkg_info->type;
 
        return PMINFO_R_OK;
 }
@@ -752,10 +764,11 @@ API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **versi
 
        if (info->pkg_info == NULL)
                return PMINFO_R_ERROR;
-       if (info->pkg_info->version == NULL)
-               info->pkg_info->version = strdup("");
 
-       *version = (char *)info->pkg_info->version;
+       if (info->pkg_info->version == NULL)
+               *version = "";
+       else
+               *version = (char *)info->pkg_info->version;
 
        return PMINFO_R_OK;
 }
@@ -769,10 +782,11 @@ API int pkgmgrinfo_pkginfo_get_api_version(pkgmgrinfo_pkginfo_h handle, char **a
 
        if (info->pkg_info == NULL)
                return PMINFO_R_ERROR;
-       if (info->pkg_info->api_version == NULL)
-               info->pkg_info->api_version = strdup("");
 
-       *api_version = (char *)info->pkg_info->api_version;
+       if (info->pkg_info->api_version == NULL)
+               *api_version = "";
+       else
+               *api_version = (char *)info->pkg_info->api_version;
 
        return PMINFO_R_OK;
 }
@@ -801,10 +815,11 @@ API int pkgmgrinfo_pkginfo_get_zip_mount_file(pkgmgrinfo_pkginfo_h handle, char
 
        if (info->pkg_info == NULL)
                return PMINFO_R_ERROR;
-       if (info->pkg_info->zip_mount_file == NULL)
-               info->pkg_info->zip_mount_file = strdup("");
 
-       *zip_mount_file = (char *)info->pkg_info->zip_mount_file;
+       if (info->pkg_info->zip_mount_file == NULL)
+               *zip_mount_file = "";
+       else
+               *zip_mount_file = (char *)info->pkg_info->zip_mount_file;
 
        return PMINFO_R_OK;
 }
@@ -917,10 +932,13 @@ API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **d
                return PMINFO_R_ERROR;
 
        ptr = (description_x *)info->pkg_info->description->data;
-       if (ptr == NULL || ptr->text == NULL)
-               *description = "";
+       if (ptr == NULL)
+               return PMINFO_R_ERROR;
 
-       *description = (char *)ptr->text;
+       if (ptr->text == NULL)
+               *description = "";
+       else
+               *description = (char *)ptr->text;
 
        return PMINFO_R_OK;
 }
@@ -939,10 +957,11 @@ API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **a
        author = (author_x *)info->pkg_info->author->data;
        if (author == NULL)
                return PMINFO_R_ERROR;
-       if (author->text == NULL)
-               author->text = strdup("");
 
-       *author_name = (char *)author->text;
+       if (author->text == NULL)
+               *author_name = "";
+       else
+               *author_name = (char *)author->text;
 
        return PMINFO_R_OK;
 }
@@ -961,10 +980,11 @@ API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **
        author = (author_x *)info->pkg_info->author->data;
        if (author == NULL)
                return PMINFO_R_ERROR;
-       if (author->email == NULL)
-               author->email = strdup("");
 
-       *author_email = (char *)author->email;
+       if (author->email == NULL)
+               *author_email = "";
+       else
+               *author_email = (char *)author->email;
 
        return PMINFO_R_OK;
 }
@@ -983,10 +1003,11 @@ API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **a
        author = (author_x *)info->pkg_info->author->data;
        if (author == NULL)
                return PMINFO_R_ERROR;
-       if (author->href == NULL)
-               author->href = strdup("");
 
-       *author_href = (char *)author->href;
+       if (author->href == NULL)
+               *author_href = "";
+       else
+               *author_href = (char *)author->href;
 
        return PMINFO_R_OK;
 }
@@ -1035,10 +1056,11 @@ API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char *
 
        if (info->pkg_info == NULL)
                return PMINFO_R_ERROR;
-       if (info->pkg_info->storeclient_id == NULL)
-               info->pkg_info->storeclient_id = strdup("");
 
-       *storeclientid = (char *)info->pkg_info->storeclient_id;
+       if (info->pkg_info->storeclient_id == NULL)
+               *storeclientid = "";
+       else
+               *storeclientid = (char *)info->pkg_info->storeclient_id;
 
        return PMINFO_R_OK;
 }
@@ -1067,10 +1089,11 @@ API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
 
        if (info->pkg_info == NULL)
                return PMINFO_R_ERROR;
-       if (info->pkg_info->package_url == NULL)
-               info->pkg_info->package_url = strdup("");
 
-       *url = (char *)info->pkg_info->package_url;
+       if (info->pkg_info->package_url == NULL)
+               *url = "";
+       else
+               *url = (char *)info->pkg_info->package_url;
 
        return PMINFO_R_OK;
 }
@@ -1099,14 +1122,28 @@ API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path
 
        if (info->pkg_info == NULL)
                return PMINFO_R_ERROR;
-       if (info->pkg_info->csc_path == NULL)
-               info->pkg_info->csc_path = strdup("");
 
-       *path = (char *)info->pkg_info->csc_path;
+       if (info->pkg_info->csc_path == NULL)
+               *path = "";
+       else
+               *path = (char *)info->pkg_info->csc_path;
 
        return PMINFO_R_OK;
 }
 
+API int pkgmgrinfo_pkginfo_get_support_mode(pkgmgrinfo_pkginfo_h handle, int *support_mode)
+{
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
+       retvm_if(support_mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
+
+       pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
+       if (info->pkg_info->support_mode)
+               *support_mode = atoi(info->pkg_info->support_mode);
+       else
+               *support_mode = 0;
+
+       return PMINFO_R_OK;
+}
 
 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
 {
@@ -1558,7 +1595,7 @@ API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
        retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
        retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
        int ret;
-       const char *privilege;
+       privilege_x *privilege;
        GList *tmp;
        pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
 
@@ -1566,10 +1603,10 @@ API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
                return PMINFO_R_ERROR;
 
        for (tmp = info->pkg_info->privileges; tmp; tmp = tmp->next) {
-               privilege = (const char *)tmp->data;
+               privilege = (privilege_x *)tmp->data;
                if (privilege == NULL)
                        continue;
-               ret = privilege_func(privilege, user_data);
+               ret = privilege_func(privilege->value, user_data);
                if (ret < 0)
                        break;
        }