#include <sys/types.h>
+#include <string>
+
#include "sqlite3.h"
#include "glib.h"
}
return PMINFO_R_OK;
+}
+
+extern "C" EXPORT_API int _appinfo_get_appcontrol_privileges(
+ const char *appid, const char *operation, uid_t uid, GList **privileges) {
+ char *query = nullptr;
+ query = sqlite3_mprintf(
+ "SELECT app_control, privilege FROM package_app_app_control_privilege "
+ "WHERE app_id=%Q", appid);
+ if (query == NULL) {
+ LOG(ERROR) << "Out of memory";
+ return PMINFO_R_ERROR;
+ }
+
+ std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
+ new pkgmgr_common::parcel::QueryParcelable(uid, std::string(query)));
+
+ pkgmgr_client::PkgInfoClient client(parcelable, uid);
+ if (!client.SendRequest())
+ return PMINFO_R_ERROR;
+ // TODO: deliver rawdata to reqhandler directly if server is not working
+
+ std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
+ std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
+ client.GetResultParcel()));
+ tizen_base::Parcel parcel;
+ parcel.ReadParcelable(return_parcel.get());
+ sqlite3_free(query);
+ // result_list is vector of string vector
+ auto result_list = return_parcel->GetResult();
+ if (result_list.size() == 0)
+ return PMINFO_R_ENOENT;
+
+ for (auto result : result_list) {
+ if (result.size() != 2)
+ return PMINFO_R_ERROR;
+ if (result.front().empty() || result.front().size() == 0 ||
+ result.back().empty() || result.back().size() == 0)
+ return PMINFO_R_ERROR;
+ std::string app_control = result.front();
+ std::stringstream ss(app_control);
+ std::string token;
+ while (std::getline(ss, token, '|')) {
+ if (token.compare(std::string(operation))) {
+ char *privilege = strdup(result.back().c_str());
+ if (privilege == nullptr) {
+ LOG(ERROR) << "Out of memory";
+ return PMINFO_R_ERROR;
+ }
+ *privileges = g_list_append(*privileges, privilege);
+ }
+ }
+ }
+ return PMINFO_R_OK;
}
\ No newline at end of file
for (tmp = list; tmp != NULL; tmp = g_list_next(tmp)) {
count++;
ret = privilege_func((char *)tmp->data, user_data);
- if (ret < 0);
+ if (ret < 0)
break;
}
return PMINFO_R_OK;
}
-static int _appinfo_foreach_appcontrol_privileges(
- const char *appid, const char *operation,
- pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
-{
- char *query = NULL;
-
- query = sqlite3_mprintf(
- "SELECT app_control, privilege FROM package_app_app_control_privilege "
- "WHERE app_id=%Q", appid);
- if (query == NULL) {
- LOGE("Out of memory");
- return PMINFO_R_ERROR;
- }
-
- // TODO: need to remove this codes and change to use pkginfo-client APIs
- sqlite3_free(query);
- return 0;
-}
-
-static int _pkgmgrinfo_appinfo_foreach_appcontrol_privileges(uid_t uid,
- const char *appid, const char *operation,
- pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
-{
- int ret;
-
- ret = _appinfo_foreach_appcontrol_privileges(appid, operation,
- callback, user_data);
-
- return ret;
-}
-
API int pkgmgrinfo_appinfo_usr_foreach_appcontrol_privileges(const char *appid,
const char *operation,
pkgmgrinfo_pkg_privilege_list_cb privilege_func,
void *user_data, uid_t uid)
{
int ret;
+ GList *privilege_list = NULL;
+ GList *tmp_list;
if (appid == NULL || operation == NULL || privilege_func == NULL) {
LOGE("invalid parameter");
return PMINFO_R_EINVAL;
}
- ret = _pkgmgrinfo_appinfo_foreach_appcontrol_privileges(GLOBAL_USER,
- appid, operation, privilege_func, user_data);
- if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
- ret = _pkgmgrinfo_appinfo_foreach_appcontrol_privileges(uid,
- appid, operation, privilege_func, user_data);
+ ret = _appinfo_get_appcontrol_privileges(appid, operation, uid,
+ &privilege_list);
+ if (ret == PMINFO_R_ENOENT) {
+ return PMINFO_R_OK;
+ } else if (ret != PMINFO_R_OK) {
+ g_list_free_full(privilege_list, free);
+ return ret;
+ }
- if (ret == PMINFO_R_ENOENT)
- ret = PMINFO_R_OK;
+ for (tmp_list = privilege_list; tmp_list != NULL;
+ tmp_list = g_list_next(tmp_list)) {
+ ret = privilege_func((char *)tmp_list->data, user_data);
+ if (ret != 0)
+ break;
+ }
- return ret;
+ g_list_free_full(privilege_list, free);
+ return PMINFO_R_OK;
}
API int pkgmgrinfo_appinfo_foreach_appcontrol_privileges(const char *appid,