/**
* @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
* @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
* @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);
}
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);
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);
}
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;
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);
}
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;
}
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,