#include "manager/pkginfo_manager.h"
#include <sys/types.h>
+#include <glib.h>
-#include <string>
+#include <parcel.hh>
-#include "sqlite3.h"
-#include "glib.h"
+#include <map>
+#include <memory>
+#include <string>
+#include <utility>
+#include <vector>
#include "pkgmgrinfo_private.h"
+#include "pkgmgr_query_index.h"
-#include "logging.hh"
+#include "client/pkginfo_client.hh"
#include "common/parcel/appinfo_parcelable.hh"
+#include "common/parcel/certinfo_parcelable.hh"
+#include "common/parcel/command_parcelable.hh"
+#include "common/parcel/create_db_parcelable.hh"
+#include "common/parcel/depinfo_parcelable.hh"
#include "common/parcel/filter_parcelable.hh"
+#include "common/parcel/parcelable_factory.hh"
#include "common/parcel/pkginfo_parcelable.hh"
#include "common/parcel/query_parcelable.hh"
#include "common/parcel/result_parcelable.hh"
+#include "utils/logging.hh"
-#include "client/pkginfo_client.hh"
-
-#include <parcel.hh>
+#include "pkg_write_type.hh"
+#include "db_type.hh"
#ifdef LOG_TAG
#undef LOG_TAG
#endif
#define EXPORT_API __attribute__((visibility("default")))
-extern "C" EXPORT_API int _pkginfo_get_packages(uid_t uid,
- pkgmgrinfo_filter_x *filter, int flag, GHashTable *packages) {
- std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
- new pkgmgr_common::parcel::FilterParcelable(uid,
- static_cast<pkgmgrinfo_filter_x*>(filter), flag));
+namespace pcp = pkgmgr_common::parcel;
- pkgmgr_client::PkgInfoClient client(parcelable, uid);
- if (!client.SendRequest())
- return PMINFO_R_ERROR;
+namespace {
- std::shared_ptr<pkgmgr_common::parcel::PkgInfoParcelable> return_parcel(
- std::static_pointer_cast<pkgmgr_common::parcel::PkgInfoParcelable>(
- client.GetResultParcel()));
+int ValidateParcelable(
+ std::shared_ptr<pcp::AbstractParcelable> parcel,
+ pcp::ParcelableType parcel_type) {
+ if (parcel == nullptr) {
+ LOG(ERROR) << "Failed to get return parcelable";
+ return PMINFO_R_ERROR;
+ }
- tizen_base::Parcel parcel;
- parcel.ReadParcelable(return_parcel.get());
+ if (parcel->GetType() != parcel_type) {
+ LOG(ERROR) << "Invalid parcelable Type " << parcel->GetType() << ' ' << parcel_type;
+ return PMINFO_R_ERROR;
+ }
- auto result_list = return_parcel->GetPkgInfo();
- // TODO: check noentry error has returned if size of result_list is 0
- for (auto& pkginfo : result_list) {
- g_hash_table_insert(packages, (gpointer)pkginfo->package, (gpointer)pkginfo);
- // TODO: remove element from list. is this work?
- pkginfo = nullptr;
- }
+ if (parcel->GetRequestResult() != PMINFO_R_OK) {
+ LOG(ERROR) << "Request fail";
+ return parcel->GetRequestResult();
+ }
- return PMINFO_R_OK;
+ return PMINFO_R_OK;
}
-// TODO: Need to add target db uid to identify which database to be searched
-extern "C" EXPORT_API int _appinfo_get_applications(uid_t db_uid, uid_t uid,
- pkgmgrinfo_filter_x *filter, int flag, GHashTable *packages) {
- std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
- new pkgmgr_common::parcel::FilterParcelable(uid,
- static_cast<pkgmgrinfo_filter_x*>(filter), flag));
+} // namespace
- pkgmgr_client::PkgInfoClient client(parcelable, uid);
- if (!client.SendRequest())
- return PMINFO_R_ERROR;
+extern "C" EXPORT_API int _pkginfo_get_packages(uid_t uid,
+ pkgmgrinfo_filter_x* filter, int flag, GHashTable* packages) {
+ std::shared_ptr<pcp::AbstractParcelable> parcelable(
+ new pcp::FilterParcelable(uid,
+ static_cast<pkgmgrinfo_filter_x*>(filter), flag, false));
+
+ pkgmgr_client::PkgInfoClient client(parcelable, uid,
+ pkgmgr_common::ReqType::GET_PKG_INFO);
+ if (!client.SendRequest())
+ return PMINFO_R_ERROR;
+
+ auto ptr = client.GetResultParcel();
+ if (ptr == nullptr) {
+ LOG(ERROR) << "Fail to get return parcelable";
+ return PMINFO_R_ERROR;
+ }
+
+ if (ptr->GetRequestResult() != PMINFO_R_OK) {
+ if (ptr->GetRequestResult() == PMINFO_R_ERROR)
+ LOG(ERROR) << "Request fail";
+ return ptr->GetRequestResult();
+ }
+
+ if (ptr->GetType() != pcp::ParcelableType::PkgInfo) {
+ LOG(ERROR) << "Invalid parcelable type";
+ return PMINFO_R_ERROR;
+ }
+
+ std::shared_ptr<pcp::PkgInfoParcelable> return_parcel(
+ std::static_pointer_cast<pcp::PkgInfoParcelable>(
+ ptr));
+
+ auto result_list = return_parcel->ExtractPkgInfo();
+ if (result_list.size() == 0) {
+ LOG(DEBUG) << "No packages meets given condition for user " << uid;
+ return PMINFO_R_ENOENT;
+ }
+ for (auto& pkginfo : result_list)
+ g_hash_table_insert(packages, reinterpret_cast<gpointer>(pkginfo->package),
+ reinterpret_cast<gpointer>(pkginfo.get()));
+
+ return PMINFO_R_OK;
+}
+
+extern "C" EXPORT_API int _pkginfo_get_depends_on(uid_t uid,
+ const char* pkgid, GList** dependencies) {
+ std::shared_ptr<pcp::AbstractParcelable> parcelable(
+ new pcp::DepInfoParcelable(std::string(pkgid)));
- std::shared_ptr<pkgmgr_common::parcel::AppInfoParcelable> return_parcel(
- std::static_pointer_cast<pkgmgr_common::parcel::AppInfoParcelable>(
- client.GetResultParcel()));
+ pkgmgr_client::PkgInfoClient client(parcelable, uid,
+ pkgmgr_common::ReqType::GET_PKG_DEP_INFO);
+ if (!client.SendRequest())
+ return PMINFO_R_ERROR;
- tizen_base::Parcel parcel;
- parcel.ReadParcelable(return_parcel.get());
- auto result_list = return_parcel->GetAppInfo();
- for (auto& appinfo : result_list) {
- g_hash_table_insert(packages, (gpointer)appinfo->appid, (gpointer)appinfo);
- // TODO: remove element from list. is this work?
- appinfo = nullptr;
- }
+ auto ptr = client.GetResultParcel();
+ int ret = ValidateParcelable(ptr, pcp::ParcelableType::DepInfo);
+ if (ret != PMINFO_R_OK)
+ return ret;
- return PMINFO_R_OK;
+ std::shared_ptr<pcp::DepInfoParcelable> return_parcel(
+ std::static_pointer_cast<pcp::DepInfoParcelable>(ptr));
+
+ auto dependency_list = return_parcel->ExtractDependencyInfo();
+ for (auto dependency : dependency_list)
+ *dependencies = g_list_prepend(*dependencies, dependency);
+ return PMINFO_R_OK;
+}
+
+extern "C" EXPORT_API int _appinfo_get_applications(uid_t uid,
+ pkgmgrinfo_filter_x* filter, int flag, GHashTable* packages) {
+ std::shared_ptr<pcp::AbstractParcelable> parcelable(
+ new pcp::FilterParcelable(uid,
+ static_cast<pkgmgrinfo_filter_x*>(filter), flag, false));
+
+ pkgmgr_client::PkgInfoClient client(
+ parcelable, uid, pkgmgr_common::ReqType::GET_APP_INFO);
+ if (!client.SendRequest())
+ return PMINFO_R_ERROR;
+
+ auto ptr = client.GetResultParcel();
+ if (ptr == nullptr) {
+ LOG(ERROR) << "Fail to get return parcelable";
+ return PMINFO_R_ERROR;
+ }
+
+ int ret = ptr->GetRequestResult();
+ if (ret != PMINFO_R_OK) {
+ if (ret == PMINFO_R_ENOENT)
+ LOG(DEBUG) << "No such application";
+ else
+ LOG(ERROR) << "Request fail";
+ return ret;
+ }
+
+ if (ptr->GetType() != pcp::ParcelableType::AppInfo) {
+ LOG(ERROR) << "Invalid parcelable type";
+ return PMINFO_R_ERROR;
+ }
+
+ std::shared_ptr<pcp::AppInfoParcelable> return_parcel(
+ std::static_pointer_cast<pcp::AppInfoParcelable>(ptr));
+
+ std::vector<std::shared_ptr<application_x>> result_list = return_parcel->ExtractAppInfo();
+ for (auto& app : result_list)
+ g_hash_table_insert(packages, reinterpret_cast<gpointer>(app->appid),
+ reinterpret_cast<gpointer>(app.get()));
+
+ return PMINFO_R_OK;
}
-extern "C" EXPORT_API char *_appinfo_get_localed_label(
- const char *appid, const char *locale, uid_t uid) {
- char *query = nullptr;
- query = sqlite3_mprintf(
- "SELECT COALESCE((SELECT app_label FROM package_app_localized_info "
- "WHERE app_id=%Q AND app_locale=%Q),"
- "(SELECT app_label FROM package_app_localized_info WHERE "
- "app_id=%Q AND app_locale='No Locale'))", appid, locale, appid);
- if (query == nullptr) {
- LOG(ERROR) << "Out of memory";
- return nullptr;
- }
-
- 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 nullptr;
- sqlite3_free(query);
- 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());
-
- // result_list is vector of string vector
- char *label;
- auto result_list = return_parcel->GetResult();
- for (auto result : result_list) {
- // result is string vector
- // it only has one string or not.
- if (result.front().empty() || result.front().length() == 0)
- return nullptr;
- label = strdup(result.front().c_str());
- if (label == nullptr) {
- LOG(ERROR) << "Out of memory";
- return nullptr;
- }
- }
-
- return label;
+extern "C" EXPORT_API char* _appinfo_get_localed_label(
+ const char* appid, const char* locale, uid_t uid) {
+ std::shared_ptr<pcp::AbstractParcelable> parcelable(
+ new pcp::QueryParcelable(uid,
+ { QUERY_INDEX_APPINFO_GET_LOCALED_LABEL, { appid, locale, appid } },
+ pkgmgr_common::DBType::DB_TYPE_FILE_PKGDB,
+ pkgmgr_common::DBOperationType::OPERATION_TYPE_READ));
+
+ pkgmgr_client::PkgInfoClient client(parcelable, uid,
+ pkgmgr_common::ReqType::READ_QUERY);
+ if (!client.SendRequest())
+ return nullptr;
+
+ auto ptr = client.GetResultParcel();
+ if (ValidateParcelable(ptr, pcp::ParcelableType::Result) != PMINFO_R_OK)
+ return nullptr;
+
+ std::shared_ptr<pcp::ResultParcelable> return_parcel(
+ std::static_pointer_cast<pcp::ResultParcelable>(ptr));
+ char* label = nullptr;
+ auto& result_list = return_parcel->GetResult();
+
+ for (auto& result : result_list) {
+ if (!result.front() || (*result.front()).empty())
+ continue;
+
+ label = strdup((*result.front()).c_str());
+ if (label == nullptr) {
+ LOG(ERROR) << "Out of memory";
+ return nullptr;
+ }
+
+ break;
+ }
+
+ return label;
}
extern "C" EXPORT_API int _appinfo_get_datacontrol_info(
- const char *providerid, const char *type, uid_t uid,
- char **appid, char **access) {
- char *query = nullptr;
- query = sqlite3_mprintf("SELECT app_id, access FROM "
- "package_app_data_control WHERE "
- "providerid=%Q AND type=%Q", providerid, type);
- if (query == nullptr) {
- 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;
- *appid = strdup(result.front().c_str());
- *access = strdup(result.back().c_str());
- if (*appid == nullptr || *access == nullptr) {
- LOG(ERROR) << "Out of memory";
- return PMINFO_R_ERROR;
- }
- }
-
- return PMINFO_R_OK;
+ const char* providerid, const char* type, uid_t uid,
+ char** appid, char** access) {
+ std::shared_ptr<pcp::AbstractParcelable> parcelable(
+ new pcp::QueryParcelable(uid,
+ { QUERY_INDEX_APPINFO_GET_DATACONTROL_INFO, { providerid, type } },
+ pkgmgr_common::DBType::DB_TYPE_FILE_PKGDB,
+ pkgmgr_common::DBOperationType::OPERATION_TYPE_READ));
+
+ pkgmgr_client::PkgInfoClient client(parcelable, uid,
+ pkgmgr_common::ReqType::READ_QUERY);
+ if (!client.SendRequest())
+ return PMINFO_R_ERROR;
+
+ auto ptr = client.GetResultParcel();
+ int ret = ValidateParcelable(ptr, pcp::ParcelableType::Result);
+ if (ret != PMINFO_R_OK)
+ return ret;
+
+ std::shared_ptr<pcp::ResultParcelable> return_parcel(
+ std::static_pointer_cast<pcp::ResultParcelable>(ptr));
+
+ auto& result_list = return_parcel->GetResult();
+ if (result_list.size() == 0)
+ return PMINFO_R_ENOENT;
+
+ for (auto it = result_list.rbegin(); it != result_list.rend(); it++) {
+ const auto& result = *it;
+ if (result.size() != 2 || !result.front() || !result.back() ||
+ (*result.front()).empty() || (*result.back()).empty())
+ continue;
+
+ char* tmp_appid = strdup((*result.front()).c_str());
+ if (tmp_appid == nullptr) {
+ LOG(ERROR) << "Out of memory";
+ return PMINFO_R_ERROR;
+ }
+
+ char* tmp_access = strdup((*result.back()).c_str());
+ if (tmp_access == nullptr) {
+ LOG(ERROR) << "Out of memory";
+ free(tmp_appid);
+ return PMINFO_R_ERROR;
+ }
+
+ *appid = tmp_appid;
+ *access = tmp_access;
+
+ return PMINFO_R_OK;
+ }
+
+ return PMINFO_R_ENOENT;
}
extern "C" EXPORT_API int _appinfo_get_datacontrol_appid(
- const char *providerid, uid_t uid, char **appid) {
- char *query = nullptr;
-
- query = sqlite3_mprintf("SELECT app_id FROM package_app_data_control "
- "WHERE providerid=%Q", providerid);
- if (query == NULL) {
- LOGE("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() != 1)
- return PMINFO_R_ERROR;
- if (result.front().empty() || result.front().size() == 0)
- return PMINFO_R_ERROR;
- *appid = strdup(result.front().c_str());
- if (*appid == nullptr) {
- LOG(ERROR) << "Out of memory";
- return PMINFO_R_ERROR;
- }
- }
-
- return PMINFO_R_OK;
+ const char* providerid, uid_t uid, char** appid) {
+ std::shared_ptr<pcp::AbstractParcelable> parcelable(
+ new pcp::QueryParcelable(uid,
+ { QUERY_INDEX_APPINFO_GET_DATACONTROL_APPID, { providerid } },
+ pkgmgr_common::DBType::DB_TYPE_FILE_PKGDB,
+ pkgmgr_common::DBOperationType::OPERATION_TYPE_READ));
+
+ pkgmgr_client::PkgInfoClient client(parcelable, uid,
+ pkgmgr_common::ReqType::READ_QUERY);
+ if (!client.SendRequest())
+ return PMINFO_R_ERROR;
+
+ auto ptr = client.GetResultParcel();
+ int ret = ValidateParcelable(ptr, pcp::ParcelableType::Result);
+ if (ret != PMINFO_R_OK)
+ return ret;
+
+ std::shared_ptr<pcp::ResultParcelable> return_parcel(
+ std::static_pointer_cast<pcp::ResultParcelable>(ptr));
+
+ auto& result_list = return_parcel->GetResult();
+ if (result_list.size() == 0)
+ return PMINFO_R_ENOENT;
+
+ for (auto it = result_list.rbegin(); it != result_list.rend(); it++) {
+ const auto& result = *it;
+ if (result.size() != 1 || !result.front() || (*result.front()).empty())
+ continue;
+
+ *appid = strdup((*result.front()).c_str());
+ if (*appid == nullptr) {
+ LOG(ERROR) << "Out of memory";
+ return PMINFO_R_ERROR;
+ }
+
+ return PMINFO_R_OK;
+ }
+
+ return PMINFO_R_ENOENT;
}
extern "C" EXPORT_API int _appinfo_get_datacontrol_trusted_info(
- const char *providerid, const char *type, uid_t uid,
- char **appid, char **trusted) {
- char *query = nullptr;
- query = sqlite3_mprintf(
- "SELECT app_id, trusted FROM package_app_data_control "
- "WHERE providerid=%Q AND type=%Q", providerid, type);
- if (query == NULL) {
- LOGE("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;
- *appid = strdup(result.front().c_str());
- *trusted = strdup(result.back().c_str());
- if (*appid == nullptr || *trusted == nullptr) {
- LOG(ERROR) << "Out of memory";
- return PMINFO_R_ERROR;
- }
- }
-
- return PMINFO_R_OK;
+ const char* providerid, const char* type, uid_t uid,
+ char** appid, char** trusted) {
+ std::shared_ptr<pcp::AbstractParcelable> parcelable(
+ new pcp::QueryParcelable(uid,
+ { QUERY_INDEX_APPINFO_GET_DATACONTROL_TRUSTED_INFO,
+ { providerid, type } },
+ pkgmgr_common::DBType::DB_TYPE_FILE_PKGDB,
+ pkgmgr_common::DBOperationType::OPERATION_TYPE_READ));
+
+ pkgmgr_client::PkgInfoClient client(parcelable, uid,
+ pkgmgr_common::ReqType::READ_QUERY);
+ if (!client.SendRequest())
+ return PMINFO_R_ERROR;
+
+ auto ptr = client.GetResultParcel();
+ int ret = ValidateParcelable(ptr, pcp::ParcelableType::Result);
+ if (ret != PMINFO_R_OK)
+ return ret;
+
+ std::shared_ptr<pcp::ResultParcelable> return_parcel(
+ std::static_pointer_cast<pcp::ResultParcelable>(ptr));
+
+ auto& result_list = return_parcel->GetResult();
+ if (result_list.size() == 0)
+ return PMINFO_R_ENOENT;
+
+ for (auto it = result_list.rbegin(); it != result_list.rend(); it++) {
+ const auto& result = *it;
+ if (result.size() != 2 || !result.front() || !result.back() ||
+ (*result.front()).empty() || (*result.back()).empty())
+ continue;
+
+ char* tmp_appid = strdup((*result.front()).c_str());
+ if (tmp_appid == nullptr) {
+ LOG(ERROR) << "Out of memory";
+ return PMINFO_R_ERROR;
+ }
+
+ char* tmp_trusted = strdup((*result.back()).c_str());
+ if (tmp_trusted == nullptr) {
+ LOG(ERROR) << "Out of memory";
+ free(tmp_appid);
+ return PMINFO_R_ERROR;
+ }
+
+ *appid = tmp_appid;
+ *trusted = tmp_trusted;
+
+ return PMINFO_R_OK;
+ }
+
+ return PMINFO_R_ENOENT;
}
extern "C" EXPORT_API int _appinfo_get_datacontrol_privileges(
- const char *providerid, const char *type, uid_t uid,
- GList **privileges) {
- char *query = nullptr;
- query = sqlite3_mprintf(
- "SELECT privilege FROM package_app_data_control_privilege "
- "WHERE providerid=%Q AND type=%Q", providerid, type);
- if (query == NULL) {
- LOGE("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() != 1)
- return PMINFO_R_ERROR;
- if (result.front().empty() || result.front().size() == 0)
- return PMINFO_R_ERROR;
- char *privilege = strdup(result.front().c_str());
- if (privilege == nullptr) {
- LOG(ERROR) << "Out of memory";
- return PMINFO_R_ERROR;
- }
- *privileges = g_list_append(*privileges, privilege);
- }
-
- return PMINFO_R_OK;
+ const char* providerid, const char* type, uid_t uid, GList** privileges) {
+ std::shared_ptr<pcp::AbstractParcelable> parcelable(
+ new pcp::QueryParcelable(uid,
+ { QUERY_INDEX_APPINFO_GET_DATACONTROL_PRIVILEGES,
+ { providerid, type } },
+ pkgmgr_common::DBType::DB_TYPE_FILE_PKGDB,
+ pkgmgr_common::DBOperationType::OPERATION_TYPE_READ));
+
+ pkgmgr_client::PkgInfoClient client(parcelable, uid,
+ pkgmgr_common::ReqType::READ_QUERY);
+ if (!client.SendRequest())
+ return PMINFO_R_ERROR;
+
+ auto ptr = client.GetResultParcel();
+ int ret = ValidateParcelable(ptr, pcp::ParcelableType::Result);
+ if (ret != PMINFO_R_OK)
+ return ret;
+
+ std::shared_ptr<pcp::ResultParcelable> return_parcel(
+ std::static_pointer_cast<pcp::ResultParcelable>(ptr));
+
+ auto& result_list = return_parcel->GetResult();
+ if (result_list.size() == 0)
+ return PMINFO_R_ENOENT;
+
+ for (auto& result : result_list) {
+ if (result.size() != 1 || !result.front() || (*result.front()).empty())
+ return PMINFO_R_ERROR;
+
+ char* privilege = strdup((*result.front()).c_str());
+ if (privilege == nullptr) {
+ LOG(ERROR) << "Out of memory";
+ return PMINFO_R_ERROR;
+ }
+ *privileges = g_list_append(*privileges, privilege);
+ }
+
+ 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
+ const char* appid, const char* operation, uid_t uid, GList** privileges) {
+ std::shared_ptr<pcp::AbstractParcelable> parcelable(
+ new pcp::QueryParcelable(uid,
+ { QUERY_INDEX_APPINFO_GET_APPCONTROL_PRIVILEGES, { appid } },
+ pkgmgr_common::DBType::DB_TYPE_FILE_PKGDB,
+ pkgmgr_common::DBOperationType::OPERATION_TYPE_READ));
+
+ pkgmgr_client::PkgInfoClient client(parcelable, uid,
+ pkgmgr_common::ReqType::READ_QUERY);
+ if (!client.SendRequest())
+ return PMINFO_R_ERROR;
+
+ auto ptr = client.GetResultParcel();
+ int ret = ValidateParcelable(ptr, pcp::ParcelableType::Result);
+ if (ret != PMINFO_R_OK)
+ return ret;
+
+ std::shared_ptr<pcp::ResultParcelable> return_parcel(
+ std::static_pointer_cast<pcp::ResultParcelable>(ptr));
+
+ // 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 || !result.front() || !result.back() ||
+ (*result.front()).empty() || (*result.back()).empty())
+ return PMINFO_R_ERROR;
+
+ std::stringstream ss((*result.front()));
+ 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;
+}
+
+extern "C" EXPORT_API int _plugininfo_get_appids(
+ const char* pkgid, const char* plugin_type,
+ const char* plugin_name, GList** list) {
+ if (!pkgid || !plugin_type || !plugin_name || !list) {
+ LOG(ERROR) << "Invalid parameter";
+ return PMINFO_R_EINVAL;
+ }
+
+ std::shared_ptr<pcp::AbstractParcelable> parcelable(
+ new pcp::QueryParcelable(_getuid(),
+ { QUERY_INDEX_PLUGININFO_GET_APPIDS,
+ { pkgid, plugin_type, plugin_name } },
+ pkgmgr_common::DBType::DB_TYPE_FILE_PKGDB,
+ pkgmgr_common::DBOperationType::OPERATION_TYPE_READ));
+
+ pkgmgr_client::PkgInfoClient client(parcelable, _getuid(),
+ pkgmgr_common::ReqType::READ_QUERY);
+ if (!client.SendRequest())
+ return PMINFO_R_ERROR;
+
+ auto ptr = client.GetResultParcel();
+ int ret = ValidateParcelable(ptr, pcp::ParcelableType::Result);
+ if (ret != PMINFO_R_OK)
+ return ret;
+
+ std::shared_ptr<pcp::ResultParcelable> return_parcel(
+ std::static_pointer_cast<pcp::ResultParcelable>(ptr));
+
+ if (return_parcel->GetCol() != 1) {
+ LOG(ERROR) << "Invalid result";
+ return PMINFO_R_ERROR;
+ }
+
+ auto& result_list = return_parcel->GetResult();
+ if (result_list.size() == 0)
+ return PMINFO_R_ENOENT;
+
+ for (auto& result : result_list) {
+ if (result.size() != 1) {
+ LOG(ERROR) << "Invalid result";
+ g_list_free_full(*list, free);
+ return PMINFO_R_ERROR;
+ }
+
+ *list = g_list_append(*list, strdup((*result[0]).c_str()));
+ }
+
+ return PMINFO_R_OK;
+}
+
+static int __convert_update_type(const char* type,
+ pkgmgrinfo_updateinfo_update_type* convert_type) {
+ if (strncasecmp(type, PMINFO_UPDATEINFO_TYPE_NONE,
+ strlen(PMINFO_UPDATEINFO_TYPE_NONE)) == 0)
+ *convert_type = PMINFO_UPDATEINFO_NONE;
+ else if (strncasecmp(type, PMINFO_UPDATEINFO_TYPE_FORCE,
+ strlen(PMINFO_UPDATEINFO_TYPE_FORCE)) == 0)
+ *convert_type = PMINFO_UPDATEINFO_FORCE;
+ else if (strncasecmp(type, PMINFO_UPDATEINFO_TYPE_OPTIONAL,
+ strlen(PMINFO_UPDATEINFO_TYPE_OPTIONAL)) == 0)
+ *convert_type = PMINFO_UPDATEINFO_OPTIONAL;
+ else
+ return -1;
+
+ return 0;
+}
+
+static void __free_update_info(gpointer data) {
+ updateinfo_x* update_info = reinterpret_cast<updateinfo_x*>(data);
+ if (update_info == nullptr)
+ return;
+
+ if (update_info->pkgid)
+ free(reinterpret_cast<void*>(update_info->pkgid));
+
+ if (update_info->version)
+ free(reinterpret_cast<void*>(update_info->version));
+
+ free(reinterpret_cast<void*>(update_info));
+}
+
+extern "C" EXPORT_API int _get_pkg_updateinfo(const char* pkgid,
+ GSList** update_info_list, uid_t uid) {
+ int ret;
+
+ std::pair<int, std::vector<const char*>> info;
+
+ if (pkgid == nullptr) {
+ info = std::pair<int, std::vector<const char*>>(
+ QUERY_INDEX_GET_PKG_UPDATEINFO_1, {});
+ } else {
+ info = std::pair<int, std::vector<const char*>>(
+ QUERY_INDEX_GET_PKG_UPDATEINFO_2, { pkgid });
+ }
+
+ std::shared_ptr<pcp::AbstractParcelable> parcelable(
+ new pcp::QueryParcelable(uid, info,
+ pkgmgr_common::DBType::DB_TYPE_FILE_PKGDB,
+ pkgmgr_common::DBOperationType::OPERATION_TYPE_READ));
+
+ pkgmgr_client::PkgInfoClient client(parcelable, uid,
+ pkgmgr_common::ReqType::READ_QUERY);
+ if (!client.SendRequest())
+ return PMINFO_R_ERROR;
+
+ auto ptr = client.GetResultParcel();
+ ret = ValidateParcelable(ptr, pcp::ParcelableType::Result);
+ if (ret != PMINFO_R_OK)
+ return ret;
+
+ std::shared_ptr<pcp::ResultParcelable> return_parcel(
+ std::static_pointer_cast<pcp::ResultParcelable>(ptr));
+
+ if (return_parcel->GetCol() != 3) {
+ LOG(ERROR) << "Invalid result";
+ return PMINFO_R_ERROR;
+ }
+
+ auto& result_list = return_parcel->GetResult();
+ if (result_list.size() == 0)
+ return PMINFO_R_ENOENT;
+
+ GSList* tmp_list = nullptr;
+ for (auto& result : result_list) {
+ if (result.size() != 3) {
+ LOG(ERROR) << "Invalid result";
+ g_slist_free_full(tmp_list, __free_update_info);
+ return PMINFO_R_ERROR;
+ }
+
+ updateinfo_x* update_info = reinterpret_cast<updateinfo_x*>(
+ calloc(1, sizeof(updateinfo_x)));
+ if (update_info == nullptr) {
+ LOG(ERROR) << "Out of memory";
+ g_slist_free_full(tmp_list, __free_update_info);
+ return PMINFO_R_ERROR;
+ }
+
+ update_info->pkgid = strdup((*result[0]).c_str());
+ update_info->version = strdup((*result[1]).c_str());
+ pkgmgrinfo_updateinfo_update_type convert_type;
+
+ ret = __convert_update_type((*result[2]).c_str(), &convert_type);
+ if (ret != 0) {
+ __free_update_info(update_info);
+ g_slist_free_full(tmp_list, __free_update_info);
+ return PMINFO_R_ERROR;
+ }
+
+ update_info->type = static_cast<int>(convert_type);
+ tmp_list = g_slist_append(tmp_list, update_info);
+ }
+
+ *update_info_list = tmp_list;
+ return PMINFO_R_OK;
+}
+
+extern "C" EXPORT_API int _pkginfo_set_usr_installed_storage(const char* pkgid,
+ INSTALL_LOCATION location, const char* external_pkg_path, uid_t uid) {
+ const char* location_str;
+
+ if (location == INSTALL_INTERNAL)
+ location_str = "installed_internal";
+ else if (location == INSTALL_EXTERNAL)
+ location_str = "installed_external";
+ else
+ location_str = "installed_extended";
+
+ std::shared_ptr<pcp::AbstractParcelable> parcelable(
+ new pcp::QueryParcelable(uid, { {
+ QUERY_INDEX_PKGINFO_SET_USR_INSTALLED_STORAGE_1, {
+ location_str,
+ external_pkg_path,
+ pkgid
+ }
+ }, {
+ QUERY_INDEX_PKGINFO_SET_USR_INSTALLED_STORAGE_2, {
+ location_str,
+ external_pkg_path,
+ pkgid
+ }
+ },
+ },
+ pkgmgr_common::DBType::DB_TYPE_FILE_PKGDB,
+ pkgmgr_common::DBOperationType::OPERATION_TYPE_WRITE));
+
+ pkgmgr_client::PkgInfoClient client(parcelable, uid,
+ pkgmgr_common::ReqType::WRITE_QUERY);
+ if (!client.SendRequest())
+ return PMINFO_R_ERROR;
+
+ return ValidateParcelable(
+ client.GetResultParcel(), pcp::ParcelableType::Result);
+}
+
+extern "C" EXPORT_API int _certinfo_compare_pkg_certinfo(const char* l_pkgid,
+ const char* r_pkgid, pkgmgrinfo_cert_compare_result_type_e* result) {
+ std::shared_ptr<pcp::AbstractParcelable> parcelable(
+ new pcp::QueryParcelable(0,
+ { QUERY_INDEX_CERTINFO_COMPARE_PKG_CERTINFO, { l_pkgid, r_pkgid } },
+ pkgmgr_common::DBType::DB_TYPE_FILE_CERTDB,
+ pkgmgr_common::DBOperationType::OPERATION_TYPE_READ));
+ pkgmgr_client::PkgInfoClient client(parcelable, 0,
+ pkgmgr_common::ReqType::READ_QUERY);
+ if (!client.SendRequest())
+ return PMINFO_R_ERROR;
+
+ auto ptr = client.GetResultParcel();
+ int ret = ValidateParcelable(ptr, pcp::ParcelableType::Result);
+ if (ret != PMINFO_R_OK)
+ return ret;
+
+ std::shared_ptr<pcp::ResultParcelable> return_parcel(
+ std::static_pointer_cast<pcp::ResultParcelable>(
+ ptr));
+
+ auto& certinfo_list = return_parcel->GetResult();
+
+ std::map<std::string, std::string> result_map;
+ result_map.insert(make_pair(std::string(l_pkgid), "-1"));
+ result_map.insert(make_pair(std::string(r_pkgid), "-1"));
+
+ for (auto& certinfo : certinfo_list)
+ result_map[*certinfo.front()] = *certinfo.back();
+
+ auto l_iter = result_map.find(l_pkgid);
+ auto r_iter = result_map.find(r_pkgid);
+ if (l_iter->second == "-1" && r_iter->second == "-1")
+ *result = PMINFO_CERT_COMPARE_BOTH_NO_CERT;
+ else if (l_iter->second == "-1")
+ *result = PMINFO_CERT_COMPARE_LHS_NO_CERT;
+ else if (r_iter->second == "-1")
+ *result = PMINFO_CERT_COMPARE_RHS_NO_CERT;
+ else if (l_iter->second == r_iter->second)
+ *result = PMINFO_CERT_COMPARE_MATCH;
+ else
+ *result = PMINFO_CERT_COMPARE_MISMATCH;
+
+ return PMINFO_R_OK;
+}
+
+extern "C" EXPORT_API int _certinfo_compare_app_certinfo(uid_t uid,
+ const char* l_appid, const char* r_appid,
+ pkgmgrinfo_cert_compare_result_type_e* result) {
+ std::shared_ptr<pcp::AbstractParcelable> parcelable(
+ new pcp::QueryParcelable(uid,
+ { QUERY_INDEX_CERTINFO_COMPARE_APP_CERTINFO, { l_appid, r_appid } },
+ pkgmgr_common::DBType::DB_TYPE_FILE_PKGDB,
+ pkgmgr_common::DBOperationType::OPERATION_TYPE_READ));
+ pkgmgr_client::PkgInfoClient client(parcelable, uid,
+ pkgmgr_common::ReqType::READ_QUERY);
+ if (!client.SendRequest())
+ return PMINFO_R_ERROR;
+
+ auto ptr = client.GetResultParcel();
+ int ret = ValidateParcelable(ptr, pcp::ParcelableType::Result);
+ if (ret != PMINFO_R_OK)
+ return ret;
+
+ std::shared_ptr<pcp::ResultParcelable> return_parcel(
+ std::static_pointer_cast<pcp::ResultParcelable>(ptr));
+
+ auto& pkgid_list = return_parcel->GetResult();
+ std::map<std::string, std::string> result_map;
+ for (auto& pkgid : pkgid_list)
+ result_map.insert(make_pair(*pkgid.front(), *pkgid.back()));
+
+ auto l_iter = result_map.find(l_appid);
+ if (l_iter == result_map.end()) {
+ LOG(ERROR) << "Cannot find pkgid of app " << l_appid
+ << " for uid " << uid;
+ return PMINFO_R_ENOENT;
+ }
+ auto r_iter = result_map.find(r_appid);
+ if (r_iter == result_map.end()) {
+ LOG(ERROR) << "Cannot find pkgid of app " << r_appid
+ << " for uid " << uid;
+ return PMINFO_R_ENOENT;
+ }
+
+ const char* l_pkgid = l_iter->second.c_str();
+ const char* r_pkgid = r_iter->second.c_str();
+
+ return _certinfo_compare_pkg_certinfo(l_pkgid, r_pkgid, result);
+}
+
+extern "C" EXPORT_API int _parser_execute_write_query(
+ int query_index, const char** query_args, unsigned int arg_cnt, uid_t uid) {
+ std::vector<const char*> args;
+
+ for (unsigned int i = 0; i < arg_cnt; i++)
+ args.push_back(query_args[i]);
+
+ std::shared_ptr<pcp::AbstractParcelable> parcelable(
+ new pcp::QueryParcelable(uid, { query_index, std::move(args) },
+ pkgmgr_common::DBType::DB_TYPE_FILE_PKGDB,
+ pkgmgr_common::DBOperationType::OPERATION_TYPE_WRITE));
+
+ pkgmgr_client::PkgInfoClient client(parcelable, uid,
+ pkgmgr_common::ReqType::WRITE_QUERY);
+ if (!client.SendRequest())
+ return PMINFO_R_ERROR;
+
+ return ValidateParcelable(
+ client.GetResultParcel(), pcp::ParcelableType::Result);
+}
+
+extern "C" EXPORT_API int _parser_execute_write_queries(
+ int query_index, const char*** query_args, unsigned int arg_cnt,
+ unsigned int query_cnt, uid_t uid) {
+ std::vector<std::pair<int, std::vector<const char*>>> queries;
+
+ for (unsigned int i = 0; i < query_cnt; i++) {
+ std::vector<const char*> args;
+ for (unsigned int j = 0; j < arg_cnt; j++)
+ args.push_back(query_args[i][j]);
+ queries.push_back({ query_index, std::move(args) });
+ }
+
+ std::shared_ptr<pcp::AbstractParcelable> parcelable(
+ new pcp::QueryParcelable(uid, queries,
+ pkgmgr_common::DBType::DB_TYPE_FILE_PKGDB,
+ pkgmgr_common::DBOperationType::OPERATION_TYPE_WRITE));
+
+ pkgmgr_client::PkgInfoClient client(parcelable, uid,
+ pkgmgr_common::ReqType::WRITE_QUERY);
+ if (!client.SendRequest())
+ return PMINFO_R_ERROR;
+
+ return ValidateParcelable(
+ client.GetResultParcel(), pcp::ParcelableType::Result);
+}
+
+extern "C" EXPORT_API int _parser_insert_manifest_info(
+ manifest_x* mfx, uid_t uid) {
+ auto parcelable =
+ std::make_shared<pcp::PkgInfoParcelable>(uid,
+ std::vector<std::shared_ptr<package_x>>(1,
+ std::shared_ptr<package_x>(mfx, [] (package_x*) -> void {})),
+ pkgmgr_common::PkgWriteType::Insert, false);
+
+ pkgmgr_client::PkgInfoClient client(parcelable, uid,
+ pkgmgr_common::ReqType::SET_PKG_INFO);
+ if (!client.SendRequest())
+ return PMINFO_R_ERROR;
+
+ return ValidateParcelable(
+ client.GetResultParcel(), pcp::ParcelableType::Result);
+}
+
+extern "C" EXPORT_API int _parser_update_manifest_info(
+ manifest_x* mfx, uid_t uid) {
+ auto parcelable =
+ std::make_shared<pcp::PkgInfoParcelable>(uid,
+ std::vector<std::shared_ptr<package_x>>(1,
+ std::shared_ptr<package_x>(mfx, [] (package_x*) -> void {})),
+ pkgmgr_common::PkgWriteType::Update, false);
+
+ pkgmgr_client::PkgInfoClient client(parcelable, uid,
+ pkgmgr_common::ReqType::SET_PKG_INFO);
+ if (!client.SendRequest())
+ return PMINFO_R_ERROR;
+
+ return ValidateParcelable(
+ client.GetResultParcel(), pcp::ParcelableType::Result);
+}
+
+extern "C" EXPORT_API int _parser_delete_manifest_info(
+ manifest_x* mfx, uid_t uid) {
+ auto parcelable =
+ std::make_shared<pcp::PkgInfoParcelable>(uid,
+ std::vector<std::shared_ptr<package_x>>(1,
+ std::shared_ptr<package_x>(mfx, [] (package_x*) -> void {})),
+ pkgmgr_common::PkgWriteType::Delete, false);
+
+ pkgmgr_client::PkgInfoClient client(parcelable, uid,
+ pkgmgr_common::ReqType::SET_PKG_INFO);
+ if (!client.SendRequest())
+ return PMINFO_R_ERROR;
+
+ return ValidateParcelable(
+ client.GetResultParcel(), pcp::ParcelableType::Result);
+}
+
+extern "C" EXPORT_API int _pkginfo_insert_certinfo(const char* pkgid,
+ pkgmgr_certinfo_x* cert, uid_t uid) {
+ std::shared_ptr<pcp::AbstractParcelable> parcelable(
+ new pcp::CertInfoParcelable(uid, cert, false));
+ pkgmgr_client::PkgInfoClient client(parcelable, uid,
+ pkgmgr_common::ReqType::SET_CERT_INFO);
+
+ if (!client.SendRequest())
+ return PMINFO_R_ERROR;
+
+ return ValidateParcelable(
+ client.GetResultParcel(), pcp::ParcelableType::Result);
+}
+
+extern "C" EXPORT_API int _pkginfo_get_certinfo(const char* pkgid,
+ pkgmgr_certinfo_x* cert, uid_t uid) {
+ std::shared_ptr<pcp::AbstractParcelable> parcelable(
+ new pcp::CertInfoParcelable(uid,
+ std::string(pkgid)));
+
+ pkgmgr_client::PkgInfoClient client(parcelable, uid,
+ pkgmgr_common::ReqType::GET_CERT_INFO);
+ if (!client.SendRequest())
+ return PMINFO_R_ERROR;
+
+ auto ptr = client.GetResultParcel();
+ int ret = ValidateParcelable(ptr, pcp::ParcelableType::CertInfo);
+ if (ret != PMINFO_R_OK)
+ return ret;
+
+ std::shared_ptr<pcp::CertInfoParcelable> return_parcel(
+ std::static_pointer_cast<pcp::CertInfoParcelable>(ptr));
+
+ pkgmgr_certinfo_x* certinfo = return_parcel->ExtractCertInfo();
+ if (certinfo == nullptr)
+ return PMINFO_R_ERROR;
+
+ cert->for_all_users = certinfo->for_all_users;
+ cert->pkgid = certinfo->pkgid;
+ certinfo->pkgid = nullptr;
+ cert->cert_value = certinfo->cert_value;
+ certinfo->cert_value = nullptr;
+ for (int i = 0; i < MAX_CERT_TYPE; i++) {
+ cert->cert_info[i] = certinfo->cert_info[i];
+ certinfo->cert_info[i] = nullptr;
+ }
+
+ for (int i = 0; i < MAX_CERT_TYPE; i++)
+ cert->cert_id[i] = certinfo->cert_id[i];
+
+ free(certinfo);
+
+ return PMINFO_R_OK;
+}
+
+extern "C" EXPORT_API int _pkginfo_delete_certinfo(const char* pkgid) {
+ std::shared_ptr<pcp::AbstractParcelable> parcelable(
+ new pcp::QueryParcelable(0,
+ { QUERY_INDEX_PKGINFO_DELETE_CERTINFO, { pkgid } },
+ pkgmgr_common::DBType::DB_TYPE_FILE_CERTDB,
+ pkgmgr_common::DBOperationType::OPERATION_TYPE_WRITE));
+
+ pkgmgr_client::PkgInfoClient client(parcelable, 0,
+ pkgmgr_common::ReqType::WRITE_QUERY);
+ if (!client.SendRequest())
+ return PMINFO_R_ERROR;
+
+ return ValidateParcelable(
+ client.GetResultParcel(), pcp::ParcelableType::Result);
+}
+
+extern "C" EXPORT_API int _parser_update_pending_cache(const char* pkgid) {
+ std::shared_ptr<pcp::AbstractParcelable> parcelable(
+ new pcp::CommandParcelable(_getuid(),
+ CommandType::UpdatePendingCache, { pkgid }));
+
+ pkgmgr_client::PkgInfoClient client(parcelable, _getuid(),
+ pkgmgr_common::ReqType::COMMAND);
+
+ if (!client.SendRequest())
+ return PMINFO_R_ERROR;
+
+ return ValidateParcelable(
+ client.GetResultParcel(), pcp::ParcelableType::Result);
+}
+
+static int __create_and_initialize_db(uid_t uid) {
+ std::shared_ptr<pcp::AbstractParcelable> parcelable(
+ new pcp::CreateDBParcelable(uid));
+
+ pkgmgr_client::PkgInfoClient client(parcelable, _getuid(),
+ pkgmgr_common::ReqType::CREATE_DB);
+
+ if (!client.SendRequest())
+ return PMINFO_R_ERROR;
+
+ return ValidateParcelable(
+ client.GetResultParcel(), pcp::ParcelableType::Result);
+}
+
+extern "C" EXPORT_API int _parser_create_and_initialize_db(uid_t uid) {
+ if (__create_and_initialize_db(uid) < 0) {
+ LOG(ERROR) << "Fail to initialize db";
+ return PMINFO_R_ERROR;
+ }
+
+ return PMINFO_R_OK;
+}