Add Error handling in RequestHandler (#117)
[platform/core/appfw/pkgmgr-info.git] / src / manager / pkginfo_manager.cc
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "manager/pkginfo_manager.h"
18
19 #include <sys/types.h>
20
21 #include <map>
22 #include <string>
23
24 #include "sqlite3.h"
25 #include "glib.h"
26
27 #include "pkgmgr_parser.h"
28 #include "pkgmgrinfo_private.h"
29
30 #include "logging.hh"
31 #include "common/database/abstract_db_handler.hh"
32 #include "common/database/pkg_set_db_handler.hh"
33 #include "common/parcel/appinfo_parcelable.hh"
34 #include "common/parcel/certinfo_parcelable.hh"
35 #include "common/parcel/depinfo_parcelable.hh"
36 #include "common/parcel/filter_parcelable.hh"
37 #include "common/parcel/pkginfo_parcelable.hh"
38 #include "common/parcel/query_parcelable.hh"
39 #include "common/parcel/result_parcelable.hh"
40
41 #include "client/pkginfo_client.hh"
42
43 #include <parcel.hh>
44
45 #ifdef LOG_TAG
46 #undef LOG_TAG
47 #endif
48 #define LOG_TAG "PKGMGR_INFO"
49
50 #ifdef EXPORT_API
51 #undef EXPORT_API
52 #endif
53 #define EXPORT_API __attribute__((visibility("default")))
54
55 extern "C" EXPORT_API int _pkginfo_get_packages(uid_t uid,
56             pkgmgrinfo_filter_x *filter, int flag, GHashTable *packages) {
57         std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
58                         new pkgmgr_common::parcel::FilterParcelable(uid,
59                                         static_cast<pkgmgrinfo_filter_x*>(filter), flag));
60
61         pkgmgr_client::PkgInfoClient client(parcelable, uid,
62                         pkgmgr_common::ReqType::GET_PKG_INFO);
63         if (!client.SendRequest())
64       return PMINFO_R_ERROR;
65
66         std::shared_ptr<pkgmgr_common::parcel::PkgInfoParcelable> return_parcel(
67                         std::static_pointer_cast<pkgmgr_common::parcel::PkgInfoParcelable>(
68                                         client.GetResultParcel()));
69
70         if (return_parcel == nullptr) {
71                 LOG(ERROR) << "Fail to get return parcelable";
72                 return PMINFO_R_ERROR;
73         }
74
75         if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
76                 LOG(ERROR) << "Request fail";
77                 return return_parcel->GetRequestResult();
78         }
79
80         tizen_base::Parcel parcel;
81         parcel.ReadParcelable(return_parcel.get());
82
83         auto result_list = return_parcel->GetPkgInfo();
84         // TODO: check noentry error has returned if size of result_list is 0
85         for (auto& pkginfo : result_list)
86                 g_hash_table_insert(packages, (gpointer)pkginfo->package,
87                                 (gpointer)pkginfo);
88
89         return PMINFO_R_OK;
90 }
91
92 extern "C" EXPORT_API int _pkginfo_get_depends_on(uid_t uid,
93                 const char *pkgid, GList **dependencies) {
94         std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
95                         new pkgmgr_common::parcel::DepInfoParcelable(std::string(pkgid)));
96
97         pkgmgr_client::PkgInfoClient client(parcelable, uid,
98                         pkgmgr_common::ReqType::GET_PKG_DEP_INFO);
99         if (!client.SendRequest())
100       return PMINFO_R_ERROR;
101
102         std::shared_ptr<pkgmgr_common::parcel::DepInfoParcelable> return_parcel(
103                         std::static_pointer_cast<pkgmgr_common::parcel::DepInfoParcelable>(
104                                         client.GetResultParcel()));
105
106         if (return_parcel == nullptr) {
107                 LOG(ERROR) << "Fail to get return parcelable";
108                 return PMINFO_R_ERROR;
109         }
110
111         if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
112                 LOG(ERROR) << "Request fail";
113                 return return_parcel->GetRequestResult();
114         }
115
116         tizen_base::Parcel parcel;
117         parcel.ReadParcelable(return_parcel.get());
118
119         auto dependency_list = return_parcel->GetDependencyInfo();
120         for (auto& dependency : dependency_list)
121                 *dependencies = g_list_prepend(*dependencies, dependency);
122         return PMINFO_R_OK;
123 }
124
125 // TODO: Need to add target db uid to identify which database to be searched
126 extern "C" EXPORT_API int _appinfo_get_applications(uid_t db_uid, uid_t uid,
127                 pkgmgrinfo_filter_x *filter, int flag, GHashTable *packages) {
128         std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
129                         new pkgmgr_common::parcel::FilterParcelable(uid,
130                                         static_cast<pkgmgrinfo_filter_x*>(filter), flag));
131
132         pkgmgr_client::PkgInfoClient client(parcelable, uid, pkgmgr_common::ReqType::GET_APP_INFO);
133         if (!client.SendRequest())
134       return PMINFO_R_ERROR;
135
136         std::shared_ptr<pkgmgr_common::parcel::AppInfoParcelable> return_parcel(
137                         std::static_pointer_cast<pkgmgr_common::parcel::AppInfoParcelable>(
138                                         client.GetResultParcel()));
139
140         if (return_parcel == nullptr) {
141                 LOG(ERROR) << "Fail to get return parcelable";
142                 return PMINFO_R_ERROR;
143         }
144
145         if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
146                 LOG(ERROR) << "Request fail";
147                 return return_parcel->GetRequestResult();
148         }
149
150         tizen_base::Parcel parcel;
151         parcel.ReadParcelable(return_parcel.get());
152         auto result_list = return_parcel->GetAppInfo();
153         for (auto& appinfo : result_list)
154                 g_hash_table_insert(packages, (gpointer)appinfo->appid,
155                                 (gpointer)appinfo);
156
157         return PMINFO_R_OK;
158 }
159
160 extern "C" EXPORT_API char *_appinfo_get_localed_label(
161                 const char *appid, const char *locale, uid_t uid) {
162         char *query = nullptr;
163     query = sqlite3_mprintf(
164                         "SELECT COALESCE((SELECT app_label FROM package_app_localized_info "
165                         "WHERE app_id=%Q AND app_locale=%Q),"
166                         "(SELECT app_label FROM package_app_localized_info WHERE "
167                         "app_id=%Q AND app_locale='No Locale'))", appid, locale, appid);
168         if (query == nullptr) {
169                 LOG(ERROR) << "Out of memory";
170                 return nullptr;
171         }
172
173         std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
174                         new pkgmgr_common::parcel::QueryParcelable(uid, std::string(query),
175           pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
176           pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
177
178         pkgmgr_client::PkgInfoClient client(parcelable, uid,
179                         pkgmgr_common::ReqType::QUERY);
180         if (!client.SendRequest()) {
181                 sqlite3_free(query);
182                 return nullptr;
183         }
184
185         std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
186                                 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
187                                                 client.GetResultParcel()));
188
189         if (return_parcel == nullptr) {
190                 LOG(ERROR) << "Fail to get return parcelable";
191                 return nullptr;
192         }
193
194         if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
195                 LOG(ERROR) << "Request fail";
196                 return nullptr;
197         }
198
199         tizen_base::Parcel parcel;
200         parcel.ReadParcelable(return_parcel.get());
201         sqlite3_free(query);
202         // result_list is vector of string vector
203         char *label = nullptr;
204         auto result_list = return_parcel->GetResult();
205         for (auto result : result_list) {
206                 // result is string vector
207                 // it only has one string or not.
208                 if (result.front().empty() || result.front().length() == 0)
209                         return nullptr;
210                 label = strdup(result.front().c_str());
211                 if (label == nullptr) {
212                         LOG(ERROR) << "Out of memory";
213                         return nullptr;
214                 }
215                 return label;
216         }
217
218         return label;
219 }
220
221 extern "C" EXPORT_API int _appinfo_get_datacontrol_info(
222                 const char *providerid, const char *type, uid_t uid,
223                 char **appid, char **access) {
224         char *query = nullptr;
225         query = sqlite3_mprintf("SELECT app_id, access FROM "
226                         "package_app_data_control WHERE "
227                         "providerid=%Q AND type=%Q", providerid, type);
228         if (query == nullptr) {
229                 LOG(ERROR) << "Out of memory";
230                 return PMINFO_R_ERROR;
231         }
232
233         std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
234                         new pkgmgr_common::parcel::QueryParcelable(uid, std::string(query),
235           pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
236           pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
237
238         pkgmgr_client::PkgInfoClient client(parcelable, uid,
239                         pkgmgr_common::ReqType::QUERY);
240         if (!client.SendRequest()) {
241                 sqlite3_free(query);
242                 return PMINFO_R_ERROR;
243         }
244
245         std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
246                         std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
247                                         client.GetResultParcel()));
248
249         if (return_parcel == nullptr) {
250                 LOG(ERROR) << "Fail to get return parcelable";
251                 return PMINFO_R_ERROR;
252         }
253
254         if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
255                 LOG(ERROR) << "Request fail";
256                 return return_parcel->GetRequestResult();
257         }
258
259         tizen_base::Parcel parcel;
260         parcel.ReadParcelable(return_parcel.get());
261         sqlite3_free(query);
262         // result_list is vector of string vector
263         auto result_list = return_parcel->GetResult();
264         if (result_list.size() == 0)
265                 return PMINFO_R_ENOENT;
266         for (auto result : result_list) {
267                 if (result.size() != 2)
268                         return PMINFO_R_ERROR;
269                 if (result.front().empty() || result.front().size() == 0 ||
270                                 result.back().empty() || result.back().size() == 0)
271                         return PMINFO_R_ERROR;
272                 *appid = strdup(result.front().c_str());
273                 *access = strdup(result.back().c_str());
274                 if (*appid == nullptr || *access == nullptr) {
275                         LOG(ERROR) << "Out of memory";
276                         return PMINFO_R_ERROR;
277                 }
278         }
279
280         return PMINFO_R_OK;
281 }
282
283 extern "C" EXPORT_API int _appinfo_get_datacontrol_appid(
284                 const char *providerid, uid_t uid, char **appid) {
285         char *query = nullptr;
286
287         query = sqlite3_mprintf("SELECT app_id FROM package_app_data_control "
288                 "WHERE providerid=%Q", providerid);
289         if (query == nullptr) {
290                 LOGE("Out of memory");
291                 return PMINFO_R_ERROR;
292         }
293         std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
294                         new pkgmgr_common::parcel::QueryParcelable(uid, std::string(query),
295           pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
296           pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
297
298         pkgmgr_client::PkgInfoClient client(parcelable, uid,
299                         pkgmgr_common::ReqType::QUERY);
300         if (!client.SendRequest()) {
301                 sqlite3_free(query);
302                 return PMINFO_R_ERROR;
303         }
304         // TODO: deliver rawdata to reqhandler directly if server is not working
305
306         std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
307                         std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
308                                         client.GetResultParcel()));
309
310         if (return_parcel == nullptr) {
311                 LOG(ERROR) << "Fail to get return parcelable";
312                 return PMINFO_R_ERROR;
313         }
314
315         if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
316                 LOG(ERROR) << "Request fail";
317                 return return_parcel->GetRequestResult();
318         }
319
320         tizen_base::Parcel parcel;
321         parcel.ReadParcelable(return_parcel.get());
322         sqlite3_free(query);
323
324         // result_list is vector of string vector
325         auto result_list = return_parcel->GetResult();
326         if (result_list.size() == 0)
327                 return PMINFO_R_ENOENT;
328         for (auto result : result_list) {
329                 if (result.size() != 1)
330                         return PMINFO_R_ERROR;
331                 if (result.front().empty() || result.front().size() == 0)
332                         return PMINFO_R_ERROR;
333                 *appid = strdup(result.front().c_str());
334                 if (*appid == nullptr) {
335                         LOG(ERROR) << "Out of memory";
336                         return PMINFO_R_ERROR;
337                 }
338         }
339
340         return PMINFO_R_OK;
341 }
342
343 extern "C" EXPORT_API int _appinfo_get_datacontrol_trusted_info(
344                 const char *providerid, const char *type, uid_t uid,
345                 char **appid, char **trusted) {
346         char *query = nullptr;
347         query = sqlite3_mprintf(
348                         "SELECT app_id, trusted FROM package_app_data_control "
349                         "WHERE providerid=%Q AND type=%Q", providerid, type);
350         if (query == nullptr) {
351                 LOGE("Out of memory");
352                 return PMINFO_R_ERROR;
353         }
354
355         std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
356                         new pkgmgr_common::parcel::QueryParcelable(uid, std::string(query),
357           pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
358           pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
359
360         pkgmgr_client::PkgInfoClient client(parcelable, uid,
361                         pkgmgr_common::ReqType::QUERY);
362         if (!client.SendRequest()) {
363                 sqlite3_free(query);
364                 return PMINFO_R_ERROR;
365         }
366         // TODO: deliver rawdata to reqhandler directly if server is not working
367
368         std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
369                         std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
370                                         client.GetResultParcel()));
371
372         if (return_parcel == nullptr) {
373                 LOG(ERROR) << "Fail to get return parcelable";
374                 return PMINFO_R_ERROR;
375         }
376
377         if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
378                 LOG(ERROR) << "Request fail";
379                 return return_parcel->GetRequestResult();
380         }
381
382         tizen_base::Parcel parcel;
383         parcel.ReadParcelable(return_parcel.get());
384         sqlite3_free(query);
385         // result_list is vector of string vector
386         auto result_list = return_parcel->GetResult();
387         if (result_list.size() == 0)
388                 return PMINFO_R_ENOENT;
389         for (auto result : result_list) {
390                 if (result.size() != 2)
391                         return PMINFO_R_ERROR;
392                 if (result.front().empty() || result.front().size() == 0 ||
393                                 result.back().empty() || result.back().size() == 0)
394                         return PMINFO_R_ERROR;
395                 *appid = strdup(result.front().c_str());
396                 *trusted = strdup(result.back().c_str());
397                 if (*appid == nullptr || *trusted == nullptr) {
398                         LOG(ERROR) << "Out of memory";
399                         return PMINFO_R_ERROR;
400                 }
401         }
402
403         return PMINFO_R_OK;
404 }
405
406 extern "C" EXPORT_API int _appinfo_get_datacontrol_privileges(
407                 const char *providerid, const char *type, uid_t uid,
408                 GList **privileges) {
409         char *query = nullptr;
410         query = sqlite3_mprintf(
411                         "SELECT privilege FROM package_app_data_control_privilege "
412                         "WHERE providerid=%Q AND type=%Q", providerid, type);
413         if (query == nullptr) {
414                 LOGE("Out of memory");
415                 return PMINFO_R_ERROR;
416         }
417
418         std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
419                         new pkgmgr_common::parcel::QueryParcelable(uid, std::string(query),
420           pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
421           pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
422
423         pkgmgr_client::PkgInfoClient client(parcelable, uid,
424                         pkgmgr_common::ReqType::QUERY);
425         if (!client.SendRequest()) {
426                 sqlite3_free(query);
427                 return PMINFO_R_ERROR;
428         }
429         // TODO: deliver rawdata to reqhandler directly if server is not working
430
431         std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
432                         std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
433                                         client.GetResultParcel()));
434
435         if (return_parcel == nullptr) {
436                 LOG(ERROR) << "Fail to get return parcelable";
437                 return PMINFO_R_ERROR;
438         }
439
440         if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
441                 LOG(ERROR) << "Request fail";
442                 return return_parcel->GetRequestResult();
443         }
444
445         tizen_base::Parcel parcel;
446         parcel.ReadParcelable(return_parcel.get());
447         sqlite3_free(query);
448         // result_list is vector of string vector
449         auto result_list = return_parcel->GetResult();
450         if (result_list.size() == 0)
451                 return PMINFO_R_ENOENT;
452
453         for (auto result : result_list) {
454                 if (result.size() != 1)
455                         return PMINFO_R_ERROR;
456                 if (result.front().empty() || result.front().size() == 0)
457                         return PMINFO_R_ERROR;
458                 char *privilege = strdup(result.front().c_str());
459                 if (privilege == nullptr) {
460                         LOG(ERROR) << "Out of memory";
461                         return PMINFO_R_ERROR;
462                 }
463                 *privileges = g_list_append(*privileges, privilege);
464         }
465
466         return PMINFO_R_OK;
467 }
468
469 extern "C" EXPORT_API int _appinfo_get_appcontrol_privileges(
470                 const char *appid, const char *operation, uid_t uid, GList **privileges) {
471         char *query = nullptr;
472         query = sqlite3_mprintf(
473                 "SELECT app_control, privilege FROM package_app_app_control_privilege "
474                 "WHERE app_id=%Q", appid);
475         if (query == nullptr) {
476                 LOG(ERROR) << "Out of memory";
477                 return PMINFO_R_ERROR;
478         }
479
480         std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
481                         new pkgmgr_common::parcel::QueryParcelable(uid, std::string(query),
482           pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
483           pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
484
485         pkgmgr_client::PkgInfoClient client(parcelable, uid,
486                         pkgmgr_common::ReqType::QUERY);
487         if (!client.SendRequest()) {
488                 sqlite3_free(query);
489                 return PMINFO_R_ERROR;
490         }
491         // TODO: deliver rawdata to reqhandler directly if server is not working
492
493         std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
494                         std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
495                                         client.GetResultParcel()));
496
497         if (return_parcel == nullptr) {
498                 LOG(ERROR) << "Fail to get return parcelable";
499                 return PMINFO_R_ERROR;
500         }
501
502         if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
503                 LOG(ERROR) << "Request fail";
504                 return return_parcel->GetRequestResult();
505         }
506
507         tizen_base::Parcel parcel;
508         parcel.ReadParcelable(return_parcel.get());
509         sqlite3_free(query);
510         // result_list is vector of string vector
511         auto result_list = return_parcel->GetResult();
512         if (result_list.size() == 0)
513                 return PMINFO_R_ENOENT;
514
515         for (auto result : result_list) {
516                 if (result.size() != 2)
517                         return PMINFO_R_ERROR;
518                 if (result.front().empty() || result.front().size() == 0 ||
519                                 result.back().empty() || result.back().size() == 0)
520                         return PMINFO_R_ERROR;
521                 std::string app_control = result.front();
522                 std::stringstream ss(app_control);
523                 std::string token;
524                 while (std::getline(ss, token, '|')) {
525                         if (token.compare(std::string(operation))) {
526                                 char *privilege = strdup(result.back().c_str());
527                                 if (privilege == nullptr) {
528                                         LOG(ERROR) << "Out of memory";
529                                         return PMINFO_R_ERROR;
530                                 }
531                                 *privileges = g_list_append(*privileges, privilege);
532                         }
533                 }
534         }
535         return PMINFO_R_OK;
536 }
537
538 extern "C" EXPORT_API int _plugininfo_get_appids(
539                 const char *pkgid, const char *plugin_type,
540                 const char *plugin_name, GList **list) {
541         if (!pkgid || !plugin_type || !plugin_name || !list) {
542                 LOG(ERROR) << "Invalid parameter";
543                 return PMINFO_R_EINVAL;
544         }
545
546         char *query = nullptr;
547         query = sqlite3_mprintf(
548                         "SELECT appid FROM "
549                         "package_plugin_info WHERE pkgid=%Q AND "
550                         "plugin_type=%Q AND plugin_name=%Q",
551       pkgid, plugin_type, plugin_name);
552         if (query == nullptr) {
553                 LOG(ERROR) << "Out of memory";
554                 return PMINFO_R_ERROR;
555         }
556
557         std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
558                         new pkgmgr_common::parcel::QueryParcelable(_getuid(), std::string(query),
559           pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
560           pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
561         sqlite3_free(query);
562
563         pkgmgr_client::PkgInfoClient client(parcelable, _getuid(),
564                         pkgmgr_common::ReqType::QUERY);
565         if (!client.SendRequest()) {
566                 return PMINFO_R_ERROR;
567         }
568
569         std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
570                         std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
571                                         client.GetResultParcel()));
572
573         if (return_parcel == nullptr) {
574                 LOG(ERROR) << "Fail to get return parcelable";
575                 return PMINFO_R_ERROR;
576         }
577
578         if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
579                 LOG(ERROR) << "Request fail";
580                 return return_parcel->GetRequestResult();
581         }
582
583   if (return_parcel->GetCol() != 1) {
584     LOG(ERROR) << "Invalid result";
585     return PMINFO_R_ERROR;
586   }
587         // result_list is vector of string vector
588         auto& result_list = return_parcel->GetResult();
589         if (result_list.size() == 0)
590                 return PMINFO_R_ENOENT;
591
592         for (auto result : result_list) {
593     if (result.size() != 1) {
594       LOG(ERROR) << "Invalid result";
595       g_list_free_full(*list, free);
596       return PMINFO_R_ERROR;
597     }
598     *list = g_list_append(*list, strdup(result[0].c_str()));
599   }
600
601   return PMINFO_R_OK;
602 }
603
604 static int __convert_update_type(const char *type, pkgmgrinfo_updateinfo_update_type *convert_type)
605 {
606         if (strncasecmp(type, PMINFO_UPDATEINFO_TYPE_NONE,
607                         strlen(PMINFO_UPDATEINFO_TYPE_NONE)) == 0)
608                 *convert_type = PMINFO_UPDATEINFO_NONE;
609         else if (strncasecmp(type, PMINFO_UPDATEINFO_TYPE_FORCE,
610                         strlen(PMINFO_UPDATEINFO_TYPE_FORCE)) == 0)
611                 *convert_type = PMINFO_UPDATEINFO_FORCE;
612         else if (strncasecmp(type, PMINFO_UPDATEINFO_TYPE_OPTIONAL,
613                         strlen(PMINFO_UPDATEINFO_TYPE_OPTIONAL)) == 0)
614                 *convert_type = PMINFO_UPDATEINFO_OPTIONAL;
615         else
616                 return -1;
617         return 0;
618 }
619
620 static void __free_update_info(gpointer data)
621 {
622         updateinfo_x *update_info = (updateinfo_x *)data;
623         if (update_info == nullptr)
624                 return;
625
626         if (update_info->pkgid)
627                 free((void *)update_info->pkgid);
628         if (update_info->version)
629                 free((void *)update_info->version);
630         free((void *)update_info);
631
632 }
633
634 extern "C" EXPORT_API int _get_pkg_updateinfo(const char *pkgid,
635                 GSList **update_info_list, uid_t uid)
636 {
637         char *query = nullptr;
638         int ret;
639
640         if (pkgid == nullptr)
641                 query = sqlite3_mprintf(
642                                                 "SELECT package, update_version, update_type "
643                                                 "FROM package_update_info");
644         else
645                 query = sqlite3_mprintf(
646                                                 "SELECT package, update_version, update_type "
647                                                 "FROM package_update_info WHERE package=%Q",
648                                                 pkgid);
649         if (query == nullptr) {
650                 LOG(ERROR) << "Out of memory";
651                 return PMINFO_R_ERROR;
652         }
653
654         std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
655                         new pkgmgr_common::parcel::QueryParcelable(uid, std::string(query),
656           pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
657           pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
658         sqlite3_free(query);
659
660         pkgmgr_client::PkgInfoClient client(parcelable, uid,
661                         pkgmgr_common::ReqType::QUERY);
662         if (!client.SendRequest()) {
663                 return PMINFO_R_ERROR;
664         }
665
666         std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
667                         std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
668                                         client.GetResultParcel()));
669
670         if (return_parcel == nullptr) {
671                 LOG(ERROR) << "Fail to get return parcelable";
672                 return PMINFO_R_ERROR;
673         }
674
675         if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
676                 LOG(ERROR) << "Request fail";
677                 return return_parcel->GetRequestResult();
678         }
679
680   if (return_parcel->GetCol() != 3) {
681     LOG(ERROR) << "Invalid result";
682     return PMINFO_R_ERROR;
683   }
684
685         auto result_list = return_parcel->GetResult();
686         if (result_list.size() == 0)
687                 return PMINFO_R_ENOENT;
688
689         for (auto result : result_list) {
690     if (result.size() != 3) {
691       LOG(ERROR) << "Invalid result";
692       g_slist_free_full(*update_info_list, __free_update_info);
693       return PMINFO_R_ERROR;
694     }
695     updateinfo_x *update_info = reinterpret_cast<updateinfo_x *>(calloc(1, sizeof(updateinfo_x)));
696                 if (update_info == nullptr) {
697                         LOG(ERROR) << "Out of memory";
698                         return PMINFO_R_ERROR;
699                 }
700     update_info->pkgid = strdup(result[0].c_str());
701     update_info->version = strdup(result[1].c_str());
702           pkgmgrinfo_updateinfo_update_type convert_type;
703                 ret = __convert_update_type(result[2].c_str(), &convert_type);
704                 if (ret != 0) {
705                         __free_update_info(update_info);
706       g_slist_free_full(*update_info_list, __free_update_info);
707                         return PMINFO_R_ERROR;
708                 }
709                 update_info->type = static_cast<int>(convert_type);
710                 *update_info_list = g_slist_prepend(*update_info_list,
711                                 update_info);
712   }
713
714         return PMINFO_R_OK;
715 }
716
717 extern "C" EXPORT_API int _pkginfo_set_usr_installed_storage(const char *pkgid,
718                 INSTALL_LOCATION location, const char *external_pkg_path,
719                 uid_t uid)
720 {
721         char *query = nullptr;
722         const char *location_str;
723         std::vector<std::string> queries;
724
725         if (location == INSTALL_INTERNAL)
726                 location_str = "installed_internal";
727         else if (location == INSTALL_EXTERNAL)
728                 location_str = "installed_external";
729         else
730                 location_str = "installed_extended";
731         /* pkgcakge_info table */
732         query = sqlite3_mprintf(
733                         "update package_info set installed_storage=%Q, external_path=%Q where package=%Q",
734                         location_str, external_pkg_path, pkgid);
735         queries.emplace_back(query);
736         sqlite3_free(query);
737
738         /* package_app_info table */
739         query = sqlite3_mprintf(
740                         "update package_app_info set app_installed_storage=%Q, app_external_path=%Q where package=%Q",
741                         location_str, external_pkg_path, pkgid);
742         queries.emplace_back(query);
743         sqlite3_free(query);
744
745         std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
746                         new pkgmgr_common::parcel::QueryParcelable(uid, queries,
747                                         pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
748                                         pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_WRITE));
749
750         pkgmgr_client::PkgInfoClient client(parcelable, uid,
751                         pkgmgr_common::ReqType::QUERY);
752         if (!client.SendRequest()) {
753                 return PMINFO_R_ERROR;
754         }
755
756         std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
757                         std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
758                                         client.GetResultParcel()));
759
760         if (return_parcel == nullptr) {
761                 LOG(ERROR) << "Fail to get return parcelable";
762                 return PMINFO_R_ERROR;
763         }
764
765         if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
766                 LOG(ERROR) << "Request fail";
767                 return return_parcel->GetRequestResult();
768         }
769
770         auto result_list = return_parcel->GetResult();
771         if (result_list.size() != 1) {
772                 LOG(ERROR) << "Invalid result";
773                 return PMINFO_R_ERROR;
774         }
775
776         if (result_list[0].size() != 1) {
777                 LOG(ERROR) << "Invalid result";
778                 return PMINFO_R_ERROR;
779         }
780
781         LOG(ERROR) << "result : " << result_list[0][0];
782         if (result_list[0][0] != "SUCCESS")
783                 return PMINFO_R_ERROR;
784
785         return PMINFO_R_OK;
786 }
787
788 extern "C" EXPORT_API int _certinfo_compare_pkg_certinfo(const char *l_pkgid,
789                 const char *r_pkgid, pkgmgrinfo_cert_compare_result_type_e *result) {
790         char *query = sqlite3_mprintf("SELECT package, "
791                         "COALESCE(author_signer_cert, -1) FROM package_cert_info WHERE "
792                         "package IN (%Q, %Q)", l_pkgid, r_pkgid);
793         if (query == nullptr) {
794                 LOG(ERROR) << "Out of memory";
795                 return PMINFO_R_ERROR;
796         }
797         std::vector<std::string> queries;
798         queries.emplace_back(query);
799         sqlite3_free(query);
800
801         std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
802                 new pkgmgr_common::parcel::QueryParcelable(0, queries,
803                                 pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_CERTDB,
804                                 pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
805         pkgmgr_client::PkgInfoClient client(parcelable, 0,
806                         pkgmgr_common::ReqType::QUERY);
807         if (!client.SendRequest()) {
808                 return PMINFO_R_ERROR;
809         }
810
811         std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
812                         std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
813                                         client.GetResultParcel()));
814
815         if (return_parcel == nullptr) {
816                 LOG(ERROR) << "Fail to get return parcelable";
817                 return PMINFO_R_ERROR;
818         }
819
820         if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
821                 LOG(ERROR) << "Request fail";
822                 return return_parcel->GetRequestResult();
823         }
824
825         auto certinfo_list = return_parcel->GetResult();
826         if (certinfo_list.size() != 2)
827                 return PMINFO_R_ERROR;
828
829         std::map<std::string, std::string> result_map;
830         for (auto& certinfo : certinfo_list)
831                 result_map.insert(make_pair(certinfo.front(), certinfo.back()));
832
833         if (result_map.find(std::string(l_pkgid))->second == "-1" &&
834                         result_map.find(std::string(r_pkgid))->second == "-1")
835                 *result = PMINFO_CERT_COMPARE_BOTH_NO_CERT;
836         else if (result_map.find(std::string(l_pkgid))->second == "-1")
837                 *result = PMINFO_CERT_COMPARE_LHS_NO_CERT;
838         else if (result_map.find(std::string(r_pkgid))->second == "-1")
839                 *result = PMINFO_CERT_COMPARE_RHS_NO_CERT;
840         else if (result_map.find(std::string(l_pkgid))->second ==
841                         result_map.find(std::string(r_pkgid))->second)
842                 *result = PMINFO_CERT_COMPARE_MATCH;
843         else
844                 *result = PMINFO_CERT_COMPARE_MISMATCH;
845
846         return PMINFO_R_OK;
847 }
848
849 extern "C" EXPORT_API int _certinfo_compare_app_certinfo(uid_t uid,
850                 const char *l_appid, const char *r_appid,
851                 pkgmgrinfo_cert_compare_result_type_e *result) {
852         char* query = sqlite3_mprintf("SELECT app_id, package FROM "
853                         "package_app_info WHERE app_id IN (%Q, %Q)", l_appid, r_appid);
854         if (query == nullptr) {
855                 LOG(ERROR) << "Out of memory";
856                 return PMINFO_R_ERROR;
857         }
858         std::vector<std::string> queries;
859         queries.emplace_back(query);
860         sqlite3_free(query);
861
862         std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
863                 new pkgmgr_common::parcel::QueryParcelable(uid, queries,
864                                 pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
865                                 pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
866         pkgmgr_client::PkgInfoClient client(parcelable, uid,
867                         pkgmgr_common::ReqType::QUERY);
868         if (!client.SendRequest()) {
869                 return PMINFO_R_ERROR;
870         }
871
872         std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
873                         std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
874                                         client.GetResultParcel()));
875
876         if (return_parcel == nullptr) {
877                 LOG(ERROR) << "Fail to get return parcelable";
878                 return PMINFO_R_ERROR;
879         }
880
881         if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
882                 LOG(ERROR) << "Request fail";
883                 return return_parcel->GetRequestResult();
884         }
885
886         auto pkgid_list = return_parcel->GetResult();
887         std::map<std::string, std::string> result_map;
888         for (auto& pkgid : pkgid_list)
889                 result_map.insert(make_pair(pkgid.front(), pkgid.back()));
890
891         if (result_map.find(std::string(l_appid)) == result_map.end()) {
892                 LOG(ERROR) << "Cannot find pkgid of app " << l_appid
893                                 << " for uid " << uid;
894                 return PMINFO_R_ENOENT;
895         } else if (result_map.find(std::string(r_appid)) == result_map.end()) {
896                 LOG(ERROR) << "Cannot find pkgid of app " << r_appid
897                                 << " for uid " << uid;
898                 return PMINFO_R_ENOENT;
899         }
900
901         const char* l_pkgid = result_map.find(
902                         std::string(l_appid))->second.c_str();
903         const char* r_pkgid = result_map.find(
904                         std::string(r_appid))->second.c_str();
905
906         return _certinfo_compare_pkg_certinfo(l_pkgid, r_pkgid, result);
907 }
908
909 extern "C" EXPORT_API int _parser_execute_write_query(const char *query, uid_t uid)
910 {
911         std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
912                         new pkgmgr_common::parcel::QueryParcelable(uid, query,
913                                         pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
914                                         pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_WRITE));
915
916         pkgmgr_client::PkgInfoClient client(parcelable, uid,
917                         pkgmgr_common::ReqType::QUERY);
918         if (!client.SendRequest()) {
919                 return -1;
920         }
921
922         std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
923                         std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
924                                         client.GetResultParcel()));
925
926         if (return_parcel == nullptr) {
927                 LOG(ERROR) << "Fail to get return parcelable";
928                 return -1;
929         }
930
931         if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
932                 LOG(ERROR) << "Request fail";
933                 return -1;
934         }
935
936         auto result_list = return_parcel->GetResult();
937         if (result_list.size() != 1) {
938                 LOG(ERROR) << "Invalid result";
939                 return -1;
940         }
941
942         if (result_list[0].size() != 1) {
943                 LOG(ERROR) << "Invalid result";
944                 return -1;
945         }
946
947         LOG(ERROR) << "result : " << result_list[0][0];
948         if (result_list[0][0] != "SUCCESS")
949                 return -1;
950
951         return 0;
952 }
953
954 extern "C" EXPORT_API int _parser_execute_write_queries(const char **queries, int len, uid_t uid)
955 {
956         std::vector<std::string> query_vt;
957         for (int i = 0; i < len; ++i)
958                 query_vt.emplace_back(queries[i]);
959
960         std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
961                         new pkgmgr_common::parcel::QueryParcelable(uid, query_vt,
962                                         pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
963                                         pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_WRITE));
964
965         pkgmgr_client::PkgInfoClient client(parcelable, uid,
966                         pkgmgr_common::ReqType::QUERY);
967         if (!client.SendRequest()) {
968                 return -1;
969         }
970
971         std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
972                         std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
973                                         client.GetResultParcel()));
974
975         if (return_parcel == nullptr) {
976                 LOG(ERROR) << "Fail to get return parcelable";
977                 return -1;
978         }
979
980         if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
981                 LOG(ERROR) << "Request fail";
982                 return -1;
983         }
984
985         auto result_list = return_parcel->GetResult();
986         if (result_list.size() != 1) {
987                 LOG(ERROR) << "Invalid result";
988                 return -1;
989         }
990
991         if (result_list[0].size() != 1) {
992                 LOG(ERROR) << "Invalid result";
993                 return -1;
994         }
995
996         LOG(ERROR) << "result : " << result_list[0][0];
997         if (result_list[0][0] != "SUCCESS")
998                 return -1;
999
1000         return 0;
1001 }
1002
1003 extern "C" EXPORT_API int _parser_insert_manifest_info(manifest_x *mfx, uid_t uid)
1004 {
1005         std::vector<package_x *> vt { mfx };
1006
1007         std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
1008                         new pkgmgr_common::parcel::PkgInfoParcelable(uid, std::move(vt), WriteType::Insert));
1009
1010         pkgmgr_client::PkgInfoClient client(parcelable, uid,
1011                         pkgmgr_common::ReqType::SET_PKG_INFO);
1012         if (!client.SendRequest()) {
1013                 return -1;
1014         }
1015
1016         std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
1017                         std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
1018                                         client.GetResultParcel()));
1019
1020         if (return_parcel == nullptr) {
1021                 LOG(ERROR) << "Fail to get return parcelable";
1022                 return -1;
1023         }
1024
1025         if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
1026                 LOG(ERROR) << "Request fail";
1027                 return -1;
1028         }
1029
1030         return 0;
1031 }
1032
1033 extern "C" EXPORT_API int _parser_update_manifest_info(manifest_x *mfx, uid_t uid)
1034 {
1035         std::vector<package_x *> vt { mfx };
1036
1037         std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
1038                         new pkgmgr_common::parcel::PkgInfoParcelable(uid, std::move(vt), WriteType::Update));
1039
1040         pkgmgr_client::PkgInfoClient client(parcelable, uid,
1041                         pkgmgr_common::ReqType::SET_PKG_INFO);
1042         if (!client.SendRequest()) {
1043                 return -1;
1044         }
1045
1046         std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
1047                         std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
1048                                         client.GetResultParcel()));
1049
1050         if (return_parcel == nullptr) {
1051                 LOG(ERROR) << "Fail to get return parcelable";
1052                 return -1;
1053         }
1054
1055         if (return_parcel->GetRequestResult() != PM_PARSER_R_OK) {
1056                 LOG(ERROR) << "Request fail";
1057                 return -1;
1058         }
1059
1060         return 0;
1061 }
1062
1063 extern "C" EXPORT_API int _parser_delete_manifest_info(manifest_x *mfx, uid_t uid)
1064 {
1065         std::vector<package_x *> vt { mfx };
1066
1067         std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
1068                         new pkgmgr_common::parcel::PkgInfoParcelable(uid, std::move(vt), WriteType::Delete));
1069
1070         pkgmgr_client::PkgInfoClient client(parcelable, uid,
1071                         pkgmgr_common::ReqType::SET_PKG_INFO);
1072         if (!client.SendRequest()) {
1073                 return -1;
1074         }
1075
1076         std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
1077                         std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
1078                                         client.GetResultParcel()));
1079
1080         if (return_parcel == nullptr) {
1081                 LOG(ERROR) << "Fail to get return parcelable";
1082                 return -1;
1083         }
1084
1085         if (return_parcel->GetRequestResult() != PM_PARSER_R_OK) {
1086                 LOG(ERROR) << "Request fail";
1087                 return -1;
1088         }
1089
1090         return 0;
1091 }
1092
1093 extern "C" EXPORT_API int _pkginfo_insert_certinfo(const char* pkgid,
1094                 pkgmgr_certinfo_x* cert, uid_t uid)
1095 {
1096         std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
1097                         new pkgmgr_common::parcel::CertInfoParcelable(uid, cert));
1098
1099         pkgmgr_client::PkgInfoClient client(parcelable, uid,
1100                         pkgmgr_common::ReqType::SET_CERT_INFO);
1101         if (!client.SendRequest())
1102         return PMINFO_R_ERROR;
1103
1104         std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
1105                 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
1106                                 client.GetResultParcel()));
1107
1108         if (return_parcel == nullptr) {
1109                 LOG(ERROR) << "Fail to get return parcelable";
1110                 return PMINFO_R_ERROR;
1111         }
1112
1113         if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
1114                 LOG(ERROR) << "Request fail";
1115                 return return_parcel->GetRequestResult();
1116         }
1117
1118         return PMINFO_R_OK;
1119 }
1120
1121 extern "C" EXPORT_API int _pkginfo_get_certinfo(const char *pkgid,
1122                 pkgmgr_certinfo_x** cert, uid_t uid)
1123 {
1124         std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
1125                         new pkgmgr_common::parcel::CertInfoParcelable(uid,
1126                                         std::string(pkgid)));
1127
1128         pkgmgr_client::PkgInfoClient client(parcelable, uid,
1129                         pkgmgr_common::ReqType::GET_CERT_INFO);
1130         if (!client.SendRequest())
1131         return PMINFO_R_ERROR;
1132
1133         std::shared_ptr<pkgmgr_common::parcel::CertInfoParcelable> return_parcel(
1134                 std::static_pointer_cast<pkgmgr_common::parcel::CertInfoParcelable>(
1135                                 client.GetResultParcel()));
1136
1137         if (return_parcel == nullptr) {
1138                 LOG(ERROR) << "Fail to get return parcelable";
1139                 return PMINFO_R_ERROR;
1140         }
1141
1142         if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
1143                 LOG(ERROR) << "Request fail";
1144                 return return_parcel->GetRequestResult();
1145         }
1146
1147         tizen_base::Parcel parcel;
1148         parcel.ReadParcelable(return_parcel.get());
1149         auto certinfo = return_parcel->GetCertInfo();
1150         if (certinfo == nullptr)
1151                 return PMINFO_R_ERROR;
1152
1153         *cert = (pkgmgr_certinfo_x*)certinfo;
1154         return PMINFO_R_OK;
1155 }
1156
1157 extern "C" EXPORT_API int _pkginfo_delete_certinfo(const char *pkgid)
1158 {
1159         char* query = sqlite3_mprintf("UPDATE package_cert_info SET "
1160                         "package_count = package_count - 1 WHERE package=%Q", pkgid);
1161         if (query == nullptr) {
1162                 LOG(ERROR) << "Out of memory";
1163                 return PMINFO_R_ERROR;
1164         }
1165
1166         std::vector<std::string> queries;
1167         queries.emplace_back(query);
1168         sqlite3_free(query);
1169
1170         std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
1171                         new pkgmgr_common::parcel::QueryParcelable(0, queries,
1172                                         pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_CERTDB,
1173                                         pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_WRITE));
1174
1175         pkgmgr_client::PkgInfoClient client(parcelable, 0,
1176                         pkgmgr_common::ReqType::QUERY);
1177         if (!client.SendRequest()) {
1178                 return PMINFO_R_ERROR;
1179         }
1180
1181         std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
1182                         std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
1183                                         client.GetResultParcel()));
1184
1185         if (return_parcel == nullptr) {
1186                 LOG(ERROR) << "Fail to get return parcelable";
1187                 return PMINFO_R_ERROR;
1188         }
1189
1190         if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
1191                 LOG(ERROR) << "Request fail";
1192                 return return_parcel->GetRequestResult();
1193         }
1194
1195         auto result_list = return_parcel->GetResult();
1196         if (result_list.size() != 1) {
1197                 LOG(ERROR) << "Invalid result";
1198                 return PMINFO_R_ERROR;
1199         }
1200
1201         if (result_list[0].size() != 1) {
1202                 LOG(ERROR) << "Invalid result";
1203                 return PMINFO_R_ERROR;
1204         }
1205
1206         LOG(ERROR) << "result : " << result_list[0][0];
1207         if (result_list[0][0] != "SUCCESS")
1208                 return PMINFO_R_ERROR;
1209
1210         return PMINFO_R_OK;
1211 }