Fix pkgmgrinfo_appinfo_foreach_appcontrol_privileges API 52/167852/5
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 23 Jan 2018 00:47:59 +0000 (09:47 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Tue, 23 Jan 2018 04:22:23 +0000 (13:22 +0900)
- Removes uri and mime parameters

Change-Id: I2fe782cc9831dc3e8cff2f88ec2e6963b71a6f72
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
include/pkgmgr-info.h
src/pkgmgrinfo_appinfo.c

index 98f8ad1..a8f3971 100644 (file)
@@ -4288,7 +4288,7 @@ int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
 
 /**
  * @fn int pkgmgrinfo_appinfo_foreach_appcontrol_privileges(const char *appid,
- *                     const char *operation, const char *uri, const char *mime,
+ *                     const char *operation,
  *                     pkgmgrinfo_pkg_privilege_list_cb privilege_func,
  *                     void *user_data);
  * @brief      This API gets the list of privileges for a particular
@@ -4298,8 +4298,6 @@ int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
  * @par Sync (or) Async : Synchronous API
  * @param[in]  appid           application id
  * @param[in]  operation       operation of appcontrol
- * @param[in]  uri             uri of appcontrol
- * @param[in]  mime            mime of appcontrol
  * @param[in]  privilege_func  callback function for list
  * @param[in]  user_data       user data to be passed to callback function
  * @return     0 if success, error code(<0) if fail
@@ -4308,11 +4306,11 @@ int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
  * @retval     PMINFO_R_ERROR  internal error
  */
 int pkgmgrinfo_appinfo_usr_foreach_appcontrol_privileges(const char *appid,
-               const char *operation, const char *uri, const char *mime,
+               const char *operation,
                pkgmgrinfo_pkg_privilege_list_cb privilege_func,
                void *user_data, uid_t uid);
 int pkgmgrinfo_appinfo_foreach_appcontrol_privileges(const char *appid,
-               const char *operation, const char *uri, const char *mime,
+               const char *operation,
                pkgmgrinfo_pkg_privilege_list_cb privilege_func,
                void *user_data);
 
index 0864028..a3833c1 100644 (file)
@@ -2696,14 +2696,19 @@ API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
 }
 
 static int _appinfo_foreach_appcontrol_privileges(sqlite3 *db,
-               const char *appid, const char *app_control,
+               const char *appid, const char *operation,
                pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
 {
        static const char query[] =
-               "SELECT privilege FROM package_app_app_control_privilege "
-               "WHERE app_id=? AND app_control=?";
+               "SELECT app_control, privilege FROM package_app_app_control_privilege "
+               "WHERE app_id=?";
        int ret;
        sqlite3_stmt *stmt;
+       const char *app_control;
+       char *dup_app_control;
+       char *token;
+       char *saveptr = NULL;
+       const char *privilege;
        int count = 0;
 
        ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
@@ -2719,19 +2724,26 @@ static int _appinfo_foreach_appcontrol_privileges(sqlite3 *db,
                return PMINFO_R_ERROR;
        }
 
-       ret = sqlite3_bind_text(stmt, 2, app_control, -1, SQLITE_STATIC);
-       if (ret != SQLITE_OK) {
-               LOGE("bind failed: %s", sqlite3_errmsg(db));
-               sqlite3_finalize(stmt);
-               return PMINFO_R_ERROR;
-       }
-
        while (sqlite3_step(stmt) == SQLITE_ROW) {
-               count++;
-               ret = callback((const char *)sqlite3_column_text(stmt, 0),
-                               user_data);
-               if (ret < 0)
-                       break;
+               app_control = (const char *)sqlite3_column_text(stmt, 0);
+               if (!app_control)
+                       continue;
+
+               dup_app_control = strdup(app_control);
+               if (!dup_app_control)
+                       continue;
+
+               token = strtok_r(dup_app_control, "|", &saveptr);
+               if (token && !strcmp(token, operation)) {
+                       count++;
+                       privilege = (const char *)sqlite3_column_text(stmt, 1);
+                       ret = callback(privilege, user_data);
+                       if (ret < 0) {
+                               free(dup_app_control);
+                               break;
+                       }
+               }
+               free(dup_app_control);
        }
 
        sqlite3_finalize(stmt);
@@ -2740,7 +2752,7 @@ static int _appinfo_foreach_appcontrol_privileges(sqlite3 *db,
 }
 
 static int _pkgmgrinfo_appinfo_foreach_appcontrol_privileges(uid_t uid,
-               const char *appid, const char *app_control,
+               const char *appid, const char *operation,
                pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
 {
        int ret;
@@ -2758,7 +2770,7 @@ static int _pkgmgrinfo_appinfo_foreach_appcontrol_privileges(uid_t uid,
                return PMINFO_R_ERROR;
        }
 
-       ret = _appinfo_foreach_appcontrol_privileges(db, appid, app_control,
+       ret = _appinfo_foreach_appcontrol_privileges(db, appid, operation,
                        callback, user_data);
        sqlite3_close_v2(db);
 
@@ -2766,26 +2778,22 @@ static int _pkgmgrinfo_appinfo_foreach_appcontrol_privileges(uid_t uid,
 }
 
 API int pkgmgrinfo_appinfo_usr_foreach_appcontrol_privileges(const char *appid,
-               const char *operation, const char *uri, const char *mime,
+               const char *operation,
                pkgmgrinfo_pkg_privilege_list_cb privilege_func,
                void *user_data, uid_t uid)
 {
        int ret;
-       char app_control[BUFSIZE];
 
        if (appid == NULL || operation == NULL || privilege_func == NULL) {
                LOGE("invalid parameter");
                return PMINFO_R_EINVAL;
        }
 
-       snprintf(app_control, sizeof(app_control), "%s|%s|%s", operation,
-                       uri ? uri : "NULL", mime ? mime : "NULL");
-
        ret = _pkgmgrinfo_appinfo_foreach_appcontrol_privileges(GLOBAL_USER,
-                       appid, app_control, privilege_func, user_data);
+                       appid, operation, privilege_func, user_data);
        if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
                ret = _pkgmgrinfo_appinfo_foreach_appcontrol_privileges(uid,
-                               appid, app_control, privilege_func, user_data);
+                               appid, operation, privilege_func, user_data);
 
        if (ret == PMINFO_R_ENOENT)
                ret = PMINFO_R_OK;
@@ -2794,13 +2802,12 @@ API int pkgmgrinfo_appinfo_usr_foreach_appcontrol_privileges(const char *appid,
 }
 
 API int pkgmgrinfo_appinfo_foreach_appcontrol_privileges(const char *appid,
-               const char *operation, const char *uri, const char *mime,
+               const char *operation,
                pkgmgrinfo_pkg_privilege_list_cb privilege_func,
                void *user_data)
 {
        return pkgmgrinfo_appinfo_usr_foreach_appcontrol_privileges(appid,
-                       operation, uri, mime, privilege_func, user_data,
-                       _getuid());
+                       operation, privilege_func, user_data, _getuid());
 }
 
 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,