#include <sys/types.h>
+#include <map>
#include <string>
#include "sqlite3.h"
return PMINFO_R_OK;
}
+extern "C" EXPORT_API int _certinfo_compare_certinfo(const char *l_pkgid,
+ const char *r_pkgid, pkgmgrinfo_cert_compare_result_type_e *result) {
+ char *query = sqlite3_mprintf("SELECT package, "
+ "COALESCE(author_signer_cert, -1) FROM package_cert_info WHERE "
+ "package IN (%Q, %Q)");
+ if (query == nullptr) {
+ LOG(ERROR) << "Out of memory";
+ return PMINFO_R_ERROR;
+ }
+ std::vector<std::string> queries;
+ queries.emplace_back(query);
+ sqlite3_free(query);
+
+ std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
+ new pkgmgr_common::parcel::QueryParcelable(0, queries,
+ pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_CERTDB,
+ pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
+ pkgmgr_client::PkgInfoClient client(parcelable, 0,
+ pkgmgr_common::ReqType::QUERY);
+ if (!client.SendRequest()) {
+ return PMINFO_R_ERROR;
+ }
+
+ std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
+ std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
+ client.GetResultParcel()));
+
+ auto certinfo_list = return_parcel->GetResult();
+ if (certinfo_list.size() != 2)
+ return PMINFO_R_ERROR;
+
+ std::map<std::string, std::string> result_map;
+ for (auto& certinfo : certinfo_list)
+ result_map.insert(make_pair(certinfo.front(), certinfo.back()));
+
+ if (result_map.find(std::string(l_pkgid))->second == "-1" &&
+ result_map.find(std::string(r_pkgid))->second == "-1")
+ *result = PMINFO_CERT_COMPARE_BOTH_NO_CERT;
+ else if (result_map.find(std::string(l_pkgid))->second == "-1")
+ *result = PMINFO_CERT_COMPARE_LHS_NO_CERT;
+ else if (result_map.find(std::string(r_pkgid))->second == "-1")
+ *result = PMINFO_CERT_COMPARE_RHS_NO_CERT;
+ else if (result_map.find(std::string(l_pkgid))->second ==
+ result_map.find(std::string(r_pkgid))->second)
+ *result = PMINFO_CERT_COMPARE_MATCH;
+ else
+ *result = PMINFO_CERT_COMPARE_MISMATCH;
+
+/*
+ auto cert_list = return_parcel->GetResult();
+ for (auto& cert : cert_list) {
+
+ }
+*/
+ return PMINFO_R_OK;
+}
+
extern "C" EXPORT_API int _parser_execute_write_query(const char *query, uid_t uid)
{
std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(