Fix build error
[platform/core/appfw/pkgmgr-info.git] / src / pkgmgrinfo_pkginfo.c
1 /*
2  * pkgmgr-info
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
7  * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  */
22
23 #define _GNU_SOURCE
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <stdbool.h>
28 #include <unistd.h>
29 #include <ctype.h>
30 #include <sys/smack.h>
31 #include <linux/limits.h>
32 #include <libgen.h>
33 #include <sys/stat.h>
34
35 #include <sqlite3.h>
36 #include <glib.h>
37
38 #include "pkgmgrinfo_basic.h"
39 #include "pkgmgrinfo_private.h"
40 #include "pkgmgrinfo_debug.h"
41 #include "pkgmgr-info.h"
42 #include "manager/pkginfo_manager.h"
43
44 static bool _get_bool_value(const char *str)
45 {
46         if (str && !strcmp(str, "true"))
47                 return true;
48         else
49                 return false;
50 }
51
52 static gint __compare_func(gconstpointer data1, gconstpointer data2)
53 {
54         pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x *)data1;
55         pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x *)data2;
56         if (node1->prop == node2->prop)
57                 return 0;
58         else if (node1->prop > node2->prop)
59                 return 1;
60         else
61                 return -1;
62 }
63
64 static gint __pkg_disable_chk_func(gconstpointer data1, gconstpointer data2)
65 {
66         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)data1;
67
68         if (node->prop == E_PMINFO_PKGINFO_PROP_PACKAGE_DISABLE)
69                 return 0;
70         else
71                 return 1;
72 }
73
74 static void __destroy_each_node(gpointer data, gpointer user_data)
75 {
76         ret_if(data == NULL);
77         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)data;
78         if (node->value) {
79                 free(node->value);
80                 node->value = NULL;
81         }
82         if (node->key) {
83                 free(node->key);
84                 node->key = NULL;
85         }
86         free(node);
87         node = NULL;
88 }
89
90 static void __destroy_metadata_node(gpointer data)
91 {
92         pkgmgrinfo_metadata_node_x *node = (pkgmgrinfo_metadata_node_x *)data;
93         if (node->key)
94                 free(node->key);
95         if (node->value)
96                 free(node->value);
97         free(node);
98 }
99
100 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data)
101 {
102         ret_if(data == NULL);
103         if (data->locale) {
104                 free((void *)data->locale);
105                 data->locale = NULL;
106         }
107
108         pkgmgrinfo_basic_free_package(data->pkg_info);
109         free((void *)data);
110         data = NULL;
111         return;
112 }
113
114 static void __free_packages(gpointer data)
115 {
116         pkgmgrinfo_basic_free_package((package_x *)data);
117 }
118
119 static bool __check_disable_filter_exist(pkgmgrinfo_filter_x *filter)
120 {
121         GSList *link;
122
123         if (filter == NULL)
124                 return false;
125
126         link = g_slist_find_custom(filter->list, NULL, __pkg_disable_chk_func);
127         if (link)
128                 return true;
129
130         return false;
131 }
132
133 static int _pkginfo_get_filtered_foreach_pkginfo(uid_t uid,
134                 pkgmgrinfo_filter_x *filter, int flag,
135                 pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
136 {
137         int ret;
138         package_x *pkg;
139         pkgmgr_pkginfo_x info;
140         GHashTable *list;
141         GHashTableIter iter;
142         gpointer value;
143
144         list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
145                         __free_packages);
146         if (list == NULL)
147                 return PMINFO_R_ERROR;
148
149         if (__check_disable_filter_exist(filter) == false) {
150                 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
151                                 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
152                 if (ret != PMINFO_R_OK) {
153                         _LOGE("Failed to add filter");
154                         g_hash_table_destroy(list);
155                         return PMINFO_R_ERROR;
156                 }
157         }
158
159         ret = _pkginfo_get_packages(uid, filter, flag, list);
160         pkgmgrinfo_pkginfo_filter_destroy(filter);
161         if (ret != PMINFO_R_OK) {
162                 g_hash_table_destroy(list);
163                 return PMINFO_R_ERROR;
164         }
165
166         g_hash_table_iter_init(&iter, list);
167         while (g_hash_table_iter_next(&iter, NULL, &value)) {
168                 pkg = (package_x *)value;
169                 info.uid = uid;
170                 info.pkg_info = pkg;
171                 info.locale = pkg->locale;
172                 if (pkg_list_cb(&info, user_data) < 0)
173                         break;
174         }
175
176         g_hash_table_destroy(list);
177
178         return PMINFO_R_OK;
179 }
180
181 static int _pkgmgrinfo_get_pkginfo(const char *pkgid, uid_t uid,
182         pkgmgrinfo_pkginfo_filter_h filter, pkgmgrinfo_pkginfo_h *handle)
183 {
184         int ret;
185         GHashTable *list;
186         pkgmgr_pkginfo_x *info;
187
188         if (pkgid == NULL || filter == NULL || handle == NULL) {
189                         LOGE("invalid parameter");
190                         return PMINFO_R_EINVAL;
191         }
192
193         list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
194                         __free_packages);
195         if (list == NULL)
196                 return PMINFO_R_ERROR;
197
198         ret = _pkginfo_get_packages(uid, filter, PMINFO_PKGINFO_GET_ALL, list);
199         if (ret != PMINFO_R_OK) {
200                 g_hash_table_destroy(list);
201                 return ret;
202         }
203
204         if (!g_hash_table_size(list)) {
205                 _LOGD("pkginfo for [%s] is not existed for user [%d]",
206                                 pkgid, uid);
207                 g_hash_table_destroy(list);
208                 return PMINFO_R_ENOENT;
209         }
210
211         info = calloc(1, sizeof(pkgmgr_pkginfo_x));
212         if (info == NULL) {
213                 _LOGE("out of memory");
214                 g_hash_table_destroy(list);
215                 return PMINFO_R_ERROR;
216         }
217
218         info->uid = uid;
219         info->pkg_info = (package_x *)g_hash_table_lookup(list, pkgid);
220         info->locale = strdup(info->pkg_info->locale);
221         if (info->locale == NULL) {
222                 _LOGE("Out of memory");
223                 g_hash_table_destroy(list);
224                 free(info);
225                 return PMINFO_R_ERROR;
226         }
227
228         /* just free list only */
229         g_hash_table_steal(list, (gconstpointer)pkgid);
230         g_hash_table_destroy(list);
231
232         *handle = info;
233
234         return ret;
235 }
236
237 API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid,
238                 pkgmgrinfo_pkginfo_h *handle)
239 {
240         int ret;
241         pkgmgrinfo_pkginfo_filter_h filter;
242         GHashTable *list;
243
244         if (pkgid == NULL || handle == NULL) {
245                 LOGE("invalid parameter");
246                 return PMINFO_R_EINVAL;
247         }
248
249         list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
250                         __free_packages);
251         if (list == NULL)
252                 return PMINFO_R_ERROR;
253
254         ret = pkgmgrinfo_pkginfo_filter_create(&filter);
255         if (ret != PMINFO_R_OK)
256                 return ret;
257
258         ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
259                         PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
260         if (ret != PMINFO_R_OK) {
261                 pkgmgrinfo_pkginfo_filter_destroy(filter);
262                 return PMINFO_R_ERROR;
263         }
264
265         ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
266                         PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
267         if (ret != PMINFO_R_OK) {
268                 pkgmgrinfo_pkginfo_filter_destroy(filter);
269                 return PMINFO_R_ERROR;
270         }
271         ret = _pkgmgrinfo_get_pkginfo(pkgid, uid, filter, handle);
272         pkgmgrinfo_pkginfo_filter_destroy(filter);
273
274         return ret;
275 }
276
277 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid,
278                 pkgmgrinfo_pkginfo_h *handle)
279 {
280         return pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, _getuid(), handle);
281 }
282
283 API int pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(const char *pkgid,
284                 uid_t uid, pkgmgrinfo_pkginfo_h *handle)
285 {
286         int ret;
287         pkgmgrinfo_pkginfo_filter_h filter;
288
289         if (pkgid == NULL || handle == NULL) {
290                 LOGE("invalid parameter");
291                 return PMINFO_R_EINVAL;
292         }
293
294         ret = pkgmgrinfo_pkginfo_filter_create(&filter);
295         if (ret != PMINFO_R_OK) {
296                 return ret;
297         }
298
299         ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
300                         PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
301         if (ret != PMINFO_R_OK) {
302                 pkgmgrinfo_pkginfo_filter_destroy(filter);
303                 return PMINFO_R_ERROR;
304         }
305
306         ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
307                         PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, true);
308         if (ret != PMINFO_R_OK) {
309                 pkgmgrinfo_pkginfo_filter_destroy(filter);
310                 return PMINFO_R_ERROR;
311         }
312
313         ret = _pkgmgrinfo_get_pkginfo(pkgid, uid, filter, handle);
314         if (ret == PMINFO_R_ENOENT)
315                 LOGE("disabled pkginfo for [%s] is not existed for user [%d]",
316                                 pkgid, uid);
317         pkgmgrinfo_pkginfo_filter_destroy(filter);
318         return ret;
319 }
320
321 API int pkgmgrinfo_pkginfo_get_usr_all_pkginfo(const char *pkgid, uid_t uid,
322                 pkgmgrinfo_pkginfo_h *handle)
323 {
324         int ret;
325         pkgmgrinfo_pkginfo_filter_h filter;
326
327         if (pkgid == NULL || handle == NULL) {
328                 LOGE("invalid parameter");
329                 return PMINFO_R_EINVAL;
330         }
331
332         ret = pkgmgrinfo_pkginfo_filter_create(&filter);
333         if (ret != PMINFO_R_OK)
334                 return ret;
335
336         ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
337                         PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
338         if (ret != PMINFO_R_OK) {
339                 pkgmgrinfo_pkginfo_filter_destroy(filter);
340                 return PMINFO_R_ERROR;
341         }
342
343         ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
344                         PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE, false);
345         if (ret != PMINFO_R_OK) {
346                 pkgmgrinfo_pkginfo_filter_destroy(filter);
347                 return PMINFO_R_ERROR;
348         }
349
350         ret = _pkgmgrinfo_get_pkginfo(pkgid, uid, filter, handle);
351         pkgmgrinfo_pkginfo_filter_destroy(filter);
352
353         return ret;
354 }
355
356 API int pkgmgrinfo_pkginfo_get_disabled_pkginfo(const char *pkgid,
357                 pkgmgrinfo_pkginfo_h *handle)
358 {
359         return pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(pkgid, _getuid(),
360                         handle);
361 }
362
363 API int pkgmgrinfo_pkginfo_get_all_pkginfo(const char *pkgid,
364                 pkgmgrinfo_pkginfo_h *handle)
365 {
366         return pkgmgrinfo_pkginfo_get_usr_all_pkginfo(pkgid, _getuid(), handle);
367 }
368
369 API int pkgmgrinfo_pkginfo_get_usr_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
370                 int flag, void *user_data, uid_t uid)
371 {
372         int ret;
373         pkgmgrinfo_pkginfo_filter_h filter;
374
375         if (pkg_list_cb == NULL) {
376                 LOGE("invalid parameter");
377                 return PMINFO_R_EINVAL;
378         }
379
380         /* create an empty filter */
381         ret = pkgmgrinfo_pkginfo_filter_create(&filter);
382         if (ret != PMINFO_R_OK)
383                 return ret;
384
385         ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter, flag,
386                         pkg_list_cb, user_data);
387
388         pkgmgrinfo_pkginfo_filter_destroy(filter);
389
390         return ret;
391 }
392
393 API int pkgmgrinfo_pkginfo_get_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
394                 int flag, void *user_data)
395 {
396         return pkgmgrinfo_pkginfo_get_usr_list_full(pkg_list_cb, flag,
397                         user_data, _getuid());
398 }
399
400 API int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
401                 void *user_data, uid_t uid)
402 {
403         int ret;
404         pkgmgrinfo_pkginfo_filter_h filter;
405
406         if (pkg_list_cb == NULL) {
407                 LOGE("invalid parameter");
408                 return PMINFO_R_EINVAL;
409         }
410
411         /* create an empty filter */
412         ret = pkgmgrinfo_pkginfo_filter_create(&filter);
413         if (ret != PMINFO_R_OK)
414                 return ret;
415
416         ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter,
417                         PMINFO_PKGINFO_GET_ALL, pkg_list_cb, user_data);
418
419         pkgmgrinfo_pkginfo_filter_destroy(filter);
420
421         return ret;
422 }
423
424 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
425                 void *user_data)
426 {
427         return pkgmgrinfo_pkginfo_get_usr_list(pkg_list_cb, user_data,
428                         _getuid());
429 }
430
431 API int pkgmgrinfo_pkginfo_get_usr_disabled_list(
432                 pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data, uid_t uid)
433 {
434         int ret;
435         pkgmgrinfo_pkginfo_filter_h filter;
436
437         if (pkg_list_cb == NULL) {
438                 LOGE("invalid parameter");
439                 return PMINFO_R_EINVAL;
440         }
441
442         ret = pkgmgrinfo_pkginfo_filter_create(&filter);
443         if (ret != PMINFO_R_OK)
444                 return ret;
445
446         ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
447                         PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, true);
448         if (ret != PMINFO_R_OK) {
449                 pkgmgrinfo_pkginfo_filter_destroy(filter);
450                 return PMINFO_R_ERROR;
451         }
452
453         ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter,
454                         PMINFO_PKGINFO_GET_ALL, pkg_list_cb, user_data);
455
456         pkgmgrinfo_pkginfo_filter_destroy(filter);
457
458         return ret;
459 }
460
461 API int pkgmgrinfo_pkginfo_get_disabled_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
462                 void *user_data)
463 {
464         return pkgmgrinfo_pkginfo_get_usr_disabled_list(pkg_list_cb, user_data,
465                         _getuid());
466 }
467
468 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
469 {
470         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
471
472         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
473         retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
474
475         if (info->pkg_info == NULL || info->pkg_info->package == NULL)
476                 return PMINFO_R_ERROR;
477
478         *pkg_name = (char *)info->pkg_info->package;
479
480         return PMINFO_R_OK;
481 }
482
483 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
484 {
485         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
486
487         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
488         retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
489
490         if (info->pkg_info == NULL || info->pkg_info->package == NULL)
491                 return PMINFO_R_ERROR;
492
493         *pkgid = (char *)info->pkg_info->package;
494
495         return PMINFO_R_OK;
496 }
497
498 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
499 {
500         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
501
502         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
503         retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
504
505         if (info->pkg_info == NULL)
506                 return PMINFO_R_ERROR;
507
508         if (info->pkg_info->type == NULL)
509                 *type = "";
510         else
511                 *type = (char *)info->pkg_info->type;
512
513         return PMINFO_R_OK;
514 }
515
516 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
517 {
518         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
519
520         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
521         retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
522
523         if (info->pkg_info == NULL)
524                 return PMINFO_R_ERROR;
525
526         if (info->pkg_info->version == NULL)
527                 *version = "";
528         else
529                 *version = (char *)info->pkg_info->version;
530
531         return PMINFO_R_OK;
532 }
533
534 API int pkgmgrinfo_pkginfo_get_api_version(pkgmgrinfo_pkginfo_h handle, char **api_version)
535 {
536         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
537
538         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
539         retvm_if(api_version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
540
541         if (info->pkg_info == NULL)
542                 return PMINFO_R_ERROR;
543
544         if (info->pkg_info->api_version == NULL)
545                 *api_version = "";
546         else
547                 *api_version = (char *)info->pkg_info->api_version;
548
549         return PMINFO_R_OK;
550 }
551
552 API int pkgmgrinfo_pkginfo_get_tep_name(pkgmgrinfo_pkginfo_h handle, char **tep_name)
553 {
554         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
555
556         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
557         retvm_if(tep_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
558
559         if (info->pkg_info == NULL || info->pkg_info->tep_name == NULL)
560                 return PMINFO_R_ERROR;
561
562         *tep_name = (char *)info->pkg_info->tep_name;
563
564         return PMINFO_R_OK;
565 }
566
567 API int pkgmgrinfo_pkginfo_get_zip_mount_file(pkgmgrinfo_pkginfo_h handle, char **zip_mount_file)
568 {
569         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
570
571         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
572         retvm_if(zip_mount_file == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
573
574         if (info->pkg_info == NULL)
575                 return PMINFO_R_ERROR;
576
577         if (info->pkg_info->zip_mount_file == NULL)
578                 *zip_mount_file = "";
579         else
580                 *zip_mount_file = (char *)info->pkg_info->zip_mount_file;
581
582         return PMINFO_R_OK;
583 }
584
585 API int pkgmgrinfo_pkginfo_get_external_image_path(pkgmgrinfo_pkginfo_h handle, char **ext_image_path)
586 {
587         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
588
589         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
590         retvm_if(ext_image_path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
591
592         if (info->pkg_info == NULL)
593                 return PMINFO_R_ERROR;
594
595         if (info->pkg_info->external_path == NULL)
596                 return PMINFO_R_ENOENT;
597
598         *ext_image_path = (char *)info->pkg_info->external_path;
599
600         return PMINFO_R_OK;
601 }
602
603 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
604 {
605         char *val;
606         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
607
608         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
609         retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
610
611         if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
612                 return PMINFO_R_ERROR;
613
614         val = (char *)info->pkg_info->installlocation;
615         if (strcmp(val, "internal-only") == 0)
616                 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
617         else if (strcmp(val, "prefer-external") == 0)
618                 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
619         else
620                 *location = PMINFO_INSTALL_LOCATION_AUTO;
621
622         return PMINFO_R_OK;
623 }
624
625 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
626 {
627         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
628         char *temp = NULL;
629
630         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
631         retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
632
633         if (info->pkg_info == NULL)
634                 return PMINFO_R_ERROR;
635
636         if (info->pkg_info->package_size == NULL) {
637                 temp = strdup("");
638                 if (temp == NULL) {
639                         _LOGE("out of memory");
640                         return PMINFO_R_ERROR;
641                 } else {
642                         info->pkg_info->package_size = temp;
643                 }
644         }
645
646         *size = atoi((char *)info->pkg_info->package_size);
647
648         return PMINFO_R_OK;
649 }
650
651 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
652 {
653         icon_x *ptr;
654         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
655
656         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
657         retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
658
659         if (info->pkg_info == NULL || info->pkg_info->icon == NULL)
660                 return PMINFO_R_ERROR;
661
662         ptr = (icon_x *)info->pkg_info->icon->data;
663         if (ptr == NULL)
664                 return PMINFO_R_ERROR;
665
666         /* TODO : should we return empty string if there was no icon? */
667         if (ptr->text == NULL)
668                 *icon = "";
669         else
670                 *icon = ptr->text;
671
672         return PMINFO_R_OK;
673 }
674
675 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
676 {
677         label_x *ptr;
678         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
679
680         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
681         retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
682
683         if (info->pkg_info == NULL || info->pkg_info->label == NULL)
684                 return PMINFO_R_ERROR;
685
686         ptr = (label_x *)info->pkg_info->label->data;
687         if (ptr == NULL)
688                 return PMINFO_R_ERROR;
689
690         /* TODO : should we return empty string if there was no label? */
691         if (ptr->text == NULL)
692                 *label = "";
693         else
694                 *label = ptr->text;
695
696         return PMINFO_R_OK;
697 }
698
699 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
700 {
701         description_x *ptr;
702         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
703
704         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
705         retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
706
707         if (info->pkg_info == NULL || info->pkg_info->description == NULL)
708                 return PMINFO_R_ERROR;
709
710         ptr = (description_x *)info->pkg_info->description->data;
711         if (ptr == NULL)
712                 return PMINFO_R_ERROR;
713
714         if (ptr->text == NULL)
715                 *description = "";
716         else
717                 *description = (char *)ptr->text;
718
719         return PMINFO_R_OK;
720 }
721
722 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
723 {
724         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
725         author_x *author;
726
727         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
728         retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
729
730         if (info->pkg_info == NULL || info->pkg_info->author == NULL)
731                 return PMINFO_R_ERROR;
732
733         author = (author_x *)info->pkg_info->author->data;
734         if (author == NULL)
735                 return PMINFO_R_ERROR;
736
737         if (author->text == NULL)
738                 *author_name = "";
739         else
740                 *author_name = (char *)author->text;
741
742         return PMINFO_R_OK;
743 }
744
745 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
746 {
747         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
748         author_x *author;
749
750         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
751         retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
752
753         if (info->pkg_info == NULL || info->pkg_info->author == NULL)
754                 return PMINFO_R_ERROR;
755
756         author = (author_x *)info->pkg_info->author->data;
757         if (author == NULL)
758                 return PMINFO_R_ERROR;
759
760         if (author->email == NULL)
761                 *author_email = "";
762         else
763                 *author_email = (char *)author->email;
764
765         return PMINFO_R_OK;
766 }
767
768 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
769 {
770         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
771         author_x *author;
772
773         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
774         retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
775
776         if (info->pkg_info == NULL || info->pkg_info->author == NULL)
777                 return PMINFO_R_ERROR;
778
779         author = (author_x *)info->pkg_info->author->data;
780         if (author == NULL)
781                 return PMINFO_R_ERROR;
782
783         if (author->href == NULL)
784                 *author_href = "";
785         else
786                 *author_href = (char *)author->href;
787
788         return PMINFO_R_OK;
789 }
790
791 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
792 {
793         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
794
795         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
796         retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
797
798         if (info->pkg_info == NULL || info->pkg_info->installed_storage == NULL)
799                 return PMINFO_R_ERROR;
800
801         if (strcmp(info->pkg_info->installed_storage, "installed_internal") == 0)
802                 *storage = PMINFO_INTERNAL_STORAGE;
803         else if (strcmp(info->pkg_info->installed_storage, "installed_external") == 0)
804                 *storage = PMINFO_EXTERNAL_STORAGE;
805         else if (strcmp(info->pkg_info->installed_storage, "installed_extended") == 0)
806                 *storage = PMINFO_EXTENDED_STORAGE;
807         else
808                 return PMINFO_R_ERROR;
809
810         return PMINFO_R_OK;
811 }
812
813 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
814 {
815         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
816
817         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
818         retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
819
820         if (info->pkg_info == NULL || info->pkg_info->installed_time == NULL)
821                 return PMINFO_R_ERROR;
822
823         *installed_time = atoi(info->pkg_info->installed_time);
824
825         return PMINFO_R_OK;
826 }
827
828 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
829 {
830         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
831
832         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
833         retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
834
835         if (info->pkg_info == NULL)
836                 return PMINFO_R_ERROR;
837
838         if (info->pkg_info->storeclient_id == NULL)
839                 *storeclientid = "";
840         else
841                 *storeclientid = (char *)info->pkg_info->storeclient_id;
842
843         return PMINFO_R_OK;
844 }
845
846 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
847 {
848         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
849
850         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
851         retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
852
853         if (info->pkg_info == NULL || info->pkg_info->mainapp_id == NULL)
854                 return PMINFO_R_ERROR;
855
856         *mainappid = (char *)info->pkg_info->mainapp_id;
857
858         return PMINFO_R_OK;
859 }
860
861 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
862 {
863         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
864
865         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
866         retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
867
868         if (info->pkg_info == NULL)
869                 return PMINFO_R_ERROR;
870
871         if (info->pkg_info->package_url == NULL)
872                 *url = "";
873         else
874                 *url = (char *)info->pkg_info->package_url;
875
876         return PMINFO_R_OK;
877 }
878
879 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
880 {
881         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
882
883         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
884         retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
885
886         if (info->pkg_info == NULL || info->pkg_info->root_path == NULL)
887                 return PMINFO_R_ERROR;
888
889         *path = (char *)info->pkg_info->root_path;
890
891         return PMINFO_R_OK;
892 }
893
894 API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
895 {
896         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
897
898         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
899         retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
900
901         if (info->pkg_info == NULL)
902                 return PMINFO_R_ERROR;
903
904         if (info->pkg_info->csc_path == NULL)
905                 *path = "";
906         else
907                 *path = (char *)info->pkg_info->csc_path;
908
909         return PMINFO_R_OK;
910 }
911
912 API int pkgmgrinfo_pkginfo_get_support_mode(pkgmgrinfo_pkginfo_h handle, int *support_mode)
913 {
914         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
915         retvm_if(support_mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
916
917         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
918         if (info->pkg_info->support_mode)
919                 *support_mode = atoi(info->pkg_info->support_mode);
920         else
921                 *support_mode = 0;
922
923         return PMINFO_R_OK;
924 }
925
926 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
927 {
928         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
929         retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
930
931 #if 0 /* smack issue occured, check later */
932         char *pkgid = NULL;
933         pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
934         if (pkgid == NULL) {
935                  _LOGD("invalid func parameters\n");
936                  return PMINFO_R_ERROR;
937         }
938          _LOGD("pkgmgr_get_pkg_external_validation() called\n");
939
940         FILE *fp = NULL;
941         char app_mmc_path[FILENAME_MAX] = { 0, };
942         char app_dir_path[FILENAME_MAX] = { 0, };
943         char app_mmc_internal_path[FILENAME_MAX] = { 0, };
944         snprintf(app_dir_path, FILENAME_MAX, "%s%s", PKG_INSTALLATION_PATH, pkgid);
945         snprintf(app_mmc_path, FILENAME_MAX, "%s%s", PKG_SD_PATH, pkgid);
946         snprintf(app_mmc_internal_path, FILENAME_MAX, "%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
947
948         /*check whether application is in external memory or not */
949         fp = fopen(app_mmc_path, "r");
950         if (fp == NULL) {
951                 _LOGD(" app path in external memory not accesible\n");
952         } else {
953                 fclose(fp);
954                 fp = NULL;
955                 *accessible = 1;
956                 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
957                 return PMINFO_R_OK;
958         }
959
960         /*check whether application is in internal or not */
961         if (fp == NULL) {
962                 _LOGD(" app path in internal memory not accesible\n");
963                 *accessible = 0;
964                 return PMINFO_R_ERROR;
965         } else {
966                 fclose(fp);
967                 /*check whether the application is installed in SD card
968                 but SD card is not present*/
969                 fp = fopen(app_mmc_internal_path, "r");
970                 if (fp == NULL) {
971                         *accessible = 1;
972                         _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
973                         return PMINFO_R_OK;
974                 } else {
975                         *accessible = 0;
976                         _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
977                 }
978                 fclose(fp);
979         }
980
981         _LOGD("pkgmgr_get_pkg_external_validation() end\n");
982 #endif
983
984         *accessible = 1;
985         return PMINFO_R_OK;
986 }
987
988 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
989 {
990         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
991
992         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
993         retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
994
995         if (info->pkg_info == NULL || info->pkg_info->removable == NULL)
996                 return PMINFO_R_ERROR;
997
998         *removable = _get_bool_value(info->pkg_info->removable);
999
1000         return PMINFO_R_OK;
1001 }
1002
1003 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
1004 {
1005         char *val;
1006         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1007
1008         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1009         retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1010
1011         if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
1012                 return PMINFO_R_ERROR;
1013
1014         val = (char *)info->pkg_info->installlocation;
1015         if (strcmp(val, "internal-only") == 0)
1016                 *movable = 0;
1017         else
1018                 *movable = 1;
1019
1020         return PMINFO_R_OK;
1021 }
1022
1023 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
1024 {
1025         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1026
1027         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1028         retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1029
1030         if (info->pkg_info == NULL || info->pkg_info->preload == NULL)
1031                 return PMINFO_R_ERROR;
1032
1033         *preload = _get_bool_value(info->pkg_info->preload);
1034
1035         return PMINFO_R_OK;
1036 }
1037
1038 API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
1039 {
1040         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1041
1042         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1043         retvm_if(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1044
1045         if (info->pkg_info == NULL || info->pkg_info->system == NULL)
1046                 return PMINFO_R_ERROR;
1047
1048         *system = _get_bool_value(info->pkg_info->system);
1049
1050         return PMINFO_R_OK;
1051 }
1052
1053 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
1054 {
1055         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1056
1057         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1058         retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1059
1060         if (info->pkg_info == NULL || info->pkg_info->readonly == NULL)
1061                 return PMINFO_R_ERROR;
1062
1063         *readonly = _get_bool_value(info->pkg_info->readonly);
1064
1065         return PMINFO_R_OK;
1066 }
1067
1068 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
1069 {
1070         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1071
1072         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1073         retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1074
1075         if (info->pkg_info == NULL || info->pkg_info->update == NULL)
1076                 return PMINFO_R_ERROR;
1077
1078         *update = _get_bool_value(info->pkg_info->update);
1079
1080         return PMINFO_R_OK;
1081 }
1082
1083 API int pkgmgrinfo_pkginfo_is_support_disable(pkgmgrinfo_pkginfo_h handle, bool *support_disable)
1084 {
1085         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1086
1087         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1088         retvm_if(support_disable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1089
1090         if (info->pkg_info == NULL || info->pkg_info->support_disable == NULL)
1091                 return PMINFO_R_ERROR;
1092
1093         *support_disable = _get_bool_value(info->pkg_info->support_disable);
1094
1095         return PMINFO_R_OK;
1096 }
1097
1098 API int pkgmgrinfo_pkginfo_is_global(pkgmgrinfo_pkginfo_h handle, bool *global)
1099 {
1100         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1101
1102         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1103         retvm_if(global == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1104
1105         if (info->pkg_info == NULL || info->pkg_info->for_all_users == NULL)
1106                 return PMINFO_R_ERROR;
1107
1108         *global = _get_bool_value(info->pkg_info->for_all_users);
1109
1110         return PMINFO_R_OK;
1111 }
1112
1113 API int pkgmgrinfo_pkginfo_is_for_all_users(pkgmgrinfo_pkginfo_h handle, bool *for_all_users)
1114 {
1115         return pkgmgrinfo_pkginfo_is_global(handle, for_all_users);
1116 }
1117
1118 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
1119 {
1120         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1121
1122         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1123
1124         __cleanup_pkginfo(info);
1125
1126         return PMINFO_R_OK;
1127 }
1128
1129 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
1130 {
1131         pkgmgrinfo_filter_x *filter;
1132
1133         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
1134
1135         filter = (pkgmgrinfo_filter_x *)calloc(1, sizeof(pkgmgrinfo_filter_x));
1136         if (filter == NULL) {
1137                 _LOGE("Out of Memory!!!");
1138                 return PMINFO_R_ERROR;
1139         }
1140
1141         *handle = filter;
1142
1143         return PMINFO_R_OK;
1144 }
1145
1146 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
1147 {
1148         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1149
1150         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1151
1152         if (filter->list) {
1153                 g_slist_foreach(filter->list, __destroy_each_node, NULL);
1154                 g_slist_free(filter->list);
1155         }
1156
1157         g_slist_free_full(filter->list_metadata, __destroy_metadata_node);
1158
1159         free(filter);
1160
1161         return PMINFO_R_OK;
1162 }
1163
1164 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
1165                                 const char *property, const int value)
1166 {
1167         char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
1168         char *val;
1169         GSList *link;
1170         int prop;
1171         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1172         pkgmgrinfo_node_x *node;
1173
1174         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1175         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1176
1177         prop = _pminfo_pkginfo_convert_to_prop_int(property);
1178         if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
1179                 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
1180                 _LOGE("Invalid Integer Property\n");
1181                 return PMINFO_R_EINVAL;
1182         }
1183         node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1184         if (node == NULL) {
1185                 _LOGE("Out of Memory!!!\n");
1186                 return PMINFO_R_ERROR;
1187         }
1188         snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
1189         val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
1190         if (val == NULL) {
1191                 _LOGE("Out of Memory\n");
1192                 free(node);
1193                 return PMINFO_R_ERROR;
1194         }
1195         node->prop = prop;
1196         node->value = val;
1197         /*If API is called multiple times for same property, we should override the previous values.
1198         Last value set will be used for filtering.*/
1199         link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1200         if (link)
1201                 filter->list = g_slist_delete_link(filter->list, link);
1202         filter->list = g_slist_append(filter->list, (gpointer)node);
1203         return PMINFO_R_OK;
1204
1205 }
1206
1207 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
1208                                 const char *property, const bool value)
1209 {
1210         char *val;
1211         GSList *link;
1212         int prop;
1213         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1214         pkgmgrinfo_node_x *node;
1215
1216         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1217         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1218
1219         prop = _pminfo_pkginfo_convert_to_prop_bool(property);
1220         if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
1221                 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
1222                 _LOGE("Invalid Boolean Property\n");
1223                 return PMINFO_R_EINVAL;
1224         }
1225         node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1226         if (node == NULL) {
1227                 _LOGE("Out of Memory!!!\n");
1228                 return PMINFO_R_ERROR;
1229         }
1230         if (value)
1231                 val = strndup("true", 4);
1232         else
1233                 val = strndup("false", 5);
1234         if (val == NULL) {
1235                 _LOGE("Out of Memory\n");
1236                 free(node);
1237                 return PMINFO_R_ERROR;
1238         }
1239         node->prop = prop;
1240         node->value = val;
1241         /*If API is called multiple times for same property, we should override the previous values.
1242         Last value set will be used for filtering.*/
1243         link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1244         if (link)
1245                 filter->list = g_slist_delete_link(filter->list, link);
1246         filter->list = g_slist_append(filter->list, (gpointer)node);
1247         return PMINFO_R_OK;
1248
1249 }
1250
1251 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
1252                                 const char *property, const char *value)
1253 {
1254         char *val;
1255         GSList *link;
1256         int prop;
1257         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1258         pkgmgrinfo_node_x *node;
1259
1260         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1261         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1262         retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1263
1264         prop = _pminfo_pkginfo_convert_to_prop_str(property);
1265         if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
1266                 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
1267                 _LOGE("Invalid String Property\n");
1268                 return PMINFO_R_EINVAL;
1269         }
1270         node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1271         if (node == NULL) {
1272                 _LOGE("Out of Memory!!!\n");
1273                 return PMINFO_R_ERROR;
1274         }
1275         if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
1276                 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
1277         else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
1278                 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
1279         else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
1280                 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
1281         else if (strcmp(value, "installed_internal") == 0)
1282                 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
1283         else if (strcmp(value, "installed_external") == 0)
1284                 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
1285         else
1286                 val = strndup(value, PKG_STRING_LEN_MAX - 1);
1287         if (val == NULL) {
1288                 _LOGE("Out of Memory\n");
1289                 free(node);
1290                 return PMINFO_R_ERROR;
1291         }
1292         node->prop = prop;
1293         node->value = val;
1294         /*If API is called multiple times for same property, we should override the previous values.
1295         Last value set will be used for filtering.*/
1296         link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1297         if (link)
1298                 filter->list = g_slist_delete_link(filter->list, link);
1299         filter->list = g_slist_append(filter->list, (gpointer)node);
1300         return PMINFO_R_OK;
1301
1302 }
1303
1304 API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
1305 {
1306         int ret;
1307         GHashTable *list = NULL;
1308
1309         if (handle == NULL || count == NULL) {
1310                 _LOGE("invalid parameter");
1311                 return PMINFO_R_EINVAL;
1312         }
1313
1314         list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
1315                         __free_packages);
1316         if (list == NULL)
1317                 return PMINFO_R_ERROR;
1318
1319         if (__check_disable_filter_exist((pkgmgrinfo_filter_x *)handle) == false) {
1320                 ret = pkgmgrinfo_pkginfo_filter_add_bool(handle,
1321                                 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
1322                 if (ret != PMINFO_R_OK) {
1323                         g_hash_table_destroy(list);
1324                         return PMINFO_R_ERROR;
1325                 }
1326         }
1327
1328         ret = _pkginfo_get_packages(uid, handle, PMINFO_PKGINFO_GET_BASICINFO, list);
1329         if (ret != PMINFO_R_OK) {
1330                 g_hash_table_destroy(list);
1331                 return PMINFO_R_ERROR;
1332         }
1333         *count = g_hash_table_size(list);
1334
1335         g_hash_table_destroy(list);
1336
1337         return PMINFO_R_OK;
1338 }
1339
1340 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
1341 {
1342         return pkgmgrinfo_pkginfo_usr_filter_count(handle, count, _getuid());
1343 }
1344
1345 API int pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(
1346                 pkgmgrinfo_pkginfo_filter_h handle,
1347                 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data, uid_t uid)
1348 {
1349         if (handle == NULL || pkg_cb == NULL) {
1350                 LOGE("invalid parameter");
1351                 return PMINFO_R_EINVAL;
1352         }
1353
1354         return _pkginfo_get_filtered_foreach_pkginfo(uid, handle,
1355                         PMINFO_PKGINFO_GET_ALL, pkg_cb, user_data);
1356 }
1357
1358 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
1359                                 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
1360 {
1361         return pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, pkg_cb, user_data, _getuid());
1362 }
1363
1364 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
1365                         pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
1366 {
1367         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1368         retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1369         int ret;
1370         privilege_x *privilege;
1371         appdefined_privilege_x *appdefined_privilege;
1372         GList *tmp;
1373         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1374
1375         if (info->pkg_info == NULL)
1376                 return PMINFO_R_ERROR;
1377
1378         for (tmp = info->pkg_info->privileges; tmp; tmp = tmp->next) {
1379                 privilege = (privilege_x *)tmp->data;
1380                 if (privilege == NULL)
1381                         continue;
1382                 ret = privilege_func(privilege->value, user_data);
1383                 if (ret < 0)
1384                         return PMINFO_R_OK;
1385         }
1386
1387         for (tmp = info->pkg_info->appdefined_privileges; tmp;
1388                         tmp = tmp->next) {
1389                 appdefined_privilege = (appdefined_privilege_x *)tmp->data;
1390                 if (appdefined_privilege == NULL)
1391                         continue;
1392                 ret = privilege_func(appdefined_privilege->value, user_data);
1393                 if (ret < 0)
1394                         return PMINFO_R_OK;
1395         }
1396         return PMINFO_R_OK;
1397 }
1398
1399 API int pkgmgrinfo_pkginfo_foreach_plugin(pkgmgrinfo_pkginfo_h handle,
1400                         pkgmgrinfo_plugin_list_cb plugin_func, void *user_data)
1401 {
1402         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1403         retvm_if(plugin_func == NULL, PMINFO_R_EINVAL,
1404                         "Callback function is NULL");
1405         int ret;
1406         plugin_x *plugin;
1407         GList *tmp;
1408         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1409
1410         if (info->pkg_info == NULL)
1411                 return PMINFO_R_ERROR;
1412
1413         for (tmp = info->pkg_info->plugin; tmp; tmp = tmp->next) {
1414                 plugin = (plugin_x *)tmp->data;
1415                 if (plugin == NULL)
1416                         continue;
1417                 ret = plugin_func(plugin->pkgid, plugin->appid,
1418                                 plugin->plugin_type, plugin->plugin_name, user_data);
1419                 if (ret < 0)
1420                         return PMINFO_R_OK;
1421         }
1422
1423         return PMINFO_R_OK;
1424 }
1425
1426 API int pkgmgrinfo_pkginfo_foreach_appdefined_privilege(
1427                 pkgmgrinfo_pkginfo_h handle,
1428                 pkgmgrinfo_pkg_appdefined_privilege_list_cb privilege_func,
1429                 void *user_data)
1430 {
1431         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1432         retvm_if(privilege_func == NULL, PMINFO_R_EINVAL,
1433                         "Callback function is NULL");
1434         int ret;
1435         appdefined_privilege_x *privilege;
1436         GList *tmp;
1437         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1438
1439         if (info->pkg_info == NULL)
1440                 return PMINFO_R_ERROR;
1441
1442         for (tmp = info->pkg_info->appdefined_privileges; tmp;
1443                         tmp = tmp->next) {
1444                 privilege = (appdefined_privilege_x *)tmp->data;
1445                 if (privilege == NULL)
1446                         continue;
1447                 ret = privilege_func(privilege->value, privilege->license,
1448                                 user_data);
1449                 if (ret < 0)
1450                         break;
1451         }
1452         return PMINFO_R_OK;
1453 }
1454
1455 API int pkgmgrinfo_pkginfo_foreach_dependency(pkgmgrinfo_pkginfo_h handle,
1456                 pkgmgrinfo_pkg_dependency_list_cb dependency_cb,
1457                 void *user_data)
1458 {
1459         int ret;
1460         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1461         GList *tmp;
1462         dependency_x *dependency;
1463
1464         if (handle == NULL || dependency_cb == NULL) {
1465                 LOGE("invalid parameter");
1466                 return PMINFO_R_EINVAL;
1467         }
1468
1469         if (info->pkg_info == NULL)
1470                 return PMINFO_R_ERROR;
1471
1472         for (tmp = info->pkg_info->dependencies; tmp; tmp = tmp->next) {
1473                 dependency = (dependency_x *)tmp->data;
1474                 if (dependency == NULL)
1475                         continue;
1476                 ret = dependency_cb(info->pkg_info->package,
1477                                 dependency->depends_on, dependency->type,
1478                                 dependency->required_version, user_data);
1479                 if (ret < 0)
1480                         break;
1481         }
1482
1483         return PMINFO_R_OK;
1484 }
1485
1486 struct depends_on {
1487         char *from;
1488         char *to;
1489         char *type;
1490         char *version;
1491 };
1492
1493 static int _get_depends_on(sqlite3 *db, const char *pkgid, GQueue **queue,
1494                 GHashTable **table, GList **pkg_list)
1495 {
1496         static const char query[] =
1497                 "SELECT package, depends_on, type, required_version "
1498                 "FROM package_dependency_info WHERE depends_on=?";
1499         int ret;
1500         sqlite3_stmt *stmt;
1501         struct depends_on *req;
1502
1503         /* already checked */
1504         if (!g_hash_table_insert(*table, strdup(pkgid), GINT_TO_POINTER(1)))
1505                 return PMINFO_R_OK;
1506
1507         ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
1508         if (ret != SQLITE_OK) {
1509                 LOGE("prepare failed: %s", sqlite3_errmsg(db));
1510                 return PMINFO_R_ERROR;
1511         }
1512
1513         ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_STATIC);
1514         if (ret != SQLITE_OK) {
1515                 LOGE("bind failed: %s", sqlite3_errmsg(db));
1516                 sqlite3_finalize(stmt);
1517                 return PMINFO_R_ERROR;
1518         }
1519
1520         while (sqlite3_step(stmt) == SQLITE_ROW) {
1521                 req = calloc(1, sizeof(struct depends_on));
1522                 if (req == NULL) {
1523                         LOGE("out of memory");
1524                         sqlite3_finalize(stmt);
1525                         return PMINFO_R_ERROR;
1526                 }
1527                 _save_column_str(stmt, 0, &req->from);
1528                 _save_column_str(stmt, 1, &req->to);
1529                 _save_column_str(stmt, 2, &req->type);
1530                 _save_column_str(stmt, 3, &req->version);
1531
1532                 *pkg_list = g_list_prepend(*pkg_list, req);
1533                 g_queue_push_tail(*queue, strdup(req->from));
1534         }
1535
1536         sqlite3_finalize(stmt);
1537
1538         return PMINFO_R_OK;
1539 }
1540
1541 static int _pkginfo_foreach_depends_on(uid_t uid, const char *pkgid,
1542                 GList **pkg_list)
1543 {
1544         int ret;
1545         char *dbpath;
1546         sqlite3 *db;
1547         GQueue *queue;
1548         GHashTable *table;
1549         char *item;
1550
1551         dbpath = getUserPkgParserDBPathUID(uid);
1552         if (dbpath == NULL)
1553                 return PMINFO_R_ERROR;
1554
1555         ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
1556         if (ret != SQLITE_OK) {
1557                 LOGD("failed to open db(%s): %d", dbpath, ret);
1558                 free(dbpath);
1559                 return PMINFO_R_ERROR;
1560         }
1561         free(dbpath);
1562
1563         queue = g_queue_new();
1564         if (queue == NULL) {
1565                 LOGE("out of memory");
1566                 sqlite3_close_v2(db);
1567                 return PMINFO_R_ERROR;
1568         }
1569
1570         table = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL);
1571
1572         g_queue_push_tail(queue, strdup(pkgid));
1573         while (!g_queue_is_empty(queue)) {
1574                 item = g_queue_pop_head(queue);
1575                 ret = _get_depends_on(db, item, &queue, &table, pkg_list);
1576                 free(item);
1577                 if (ret != PMINFO_R_OK) {
1578                         LOGE("failed to get pkgs depends on %s", pkgid);
1579                         g_hash_table_destroy(table);
1580                         g_queue_free_full(queue, free);
1581                         sqlite3_close_v2(db);
1582                         return PMINFO_R_ERROR;
1583                 }
1584         }
1585
1586         g_hash_table_destroy(table);
1587         g_queue_free_full(queue, free);
1588         sqlite3_close_v2(db);
1589
1590         return PMINFO_R_OK;
1591 }
1592
1593 static void __free_depends_on(gpointer data)
1594 {
1595         struct depends_on *dep = (struct depends_on *)data;
1596
1597         free(dep->from);
1598         free(dep->to);
1599         free(dep->type);
1600         free(dep->version);
1601         free(dep);
1602 }
1603
1604 // TODO: need to change this
1605 API int pkgmgrinfo_pkginfo_foreach_depends_on(pkgmgrinfo_pkginfo_h handle,
1606                 pkgmgrinfo_pkg_dependency_list_cb dependency_cb,
1607                 void *user_data)
1608 {
1609         int ret;
1610         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1611         GList *pkg_list = NULL;
1612         GList *l;
1613         struct depends_on *dep;
1614
1615         if (handle == NULL || dependency_cb == NULL || info->pkg_info == NULL) {
1616                 LOGE("invalid parameter");
1617                 return PMINFO_R_EINVAL;
1618         }
1619
1620         ret = _pkginfo_foreach_depends_on(info->uid, info->pkg_info->package,
1621                         &pkg_list);
1622         if (ret == PMINFO_R_OK && info->uid != GLOBAL_USER)
1623                 ret = _pkginfo_foreach_depends_on(GLOBAL_USER,
1624                                 info->pkg_info->package, &pkg_list);
1625
1626         if (ret != PMINFO_R_OK) {
1627                 g_list_free_full(pkg_list, __free_depends_on);
1628                 return ret;
1629         }
1630
1631         for (l = pkg_list; l != NULL; l = l->next) {
1632                 dep = (struct depends_on *)l->data;
1633                 ret = dependency_cb(dep->from, dep->to, dep->type, dep->version,
1634                                 user_data);
1635                 if (ret < 0)
1636                         break;
1637         }
1638
1639         g_list_free_full(pkg_list, __free_depends_on);
1640
1641         return PMINFO_R_OK;
1642 }
1643
1644 int __compare_package_version(const char *version, int *major,
1645                 int *minor, int *macro, int *nano)
1646 {
1647         char *version_temp = NULL;
1648         char *major_str = NULL;
1649         char *minor_str = NULL;
1650         char *macro_str = NULL;
1651         char *nano_str = NULL;
1652         char *save_str = NULL;
1653
1654         if (version == NULL || major == NULL || minor == NULL ||
1655                 macro == NULL || nano == NULL) {
1656                 return PMINFO_R_EINVAL;
1657         }
1658
1659         version_temp = strdup(version);
1660         if (version_temp == NULL) {
1661                 LOGE("Out of memory");
1662                 return PMINFO_R_ERROR;
1663         }
1664
1665         major_str = strtok_r(version_temp, ".", &save_str);
1666         if (major_str == NULL) {
1667                 _LOGE("major version is NULL");
1668                 free(version_temp);
1669                 return PMINFO_R_ERROR;
1670         }
1671
1672         minor_str = strtok_r(NULL, ".", &save_str);
1673         if (minor_str == NULL) {
1674                 _LOGE("minor version is NULL");
1675                 free(version_temp);
1676                 return PMINFO_R_ERROR;
1677         }
1678
1679         *major = atoi(major_str);
1680         *minor = atoi(minor_str);
1681         *macro = 0;
1682         *nano = 0;
1683         macro_str = strtok_r(NULL, ".", &save_str);
1684         if (macro_str == NULL) {
1685                 _LOGD("macro version is NULL");
1686         } else {
1687                 *macro = atoi(macro_str);
1688                 nano_str = strtok_r(NULL, ".", &save_str);
1689                 if (nano_str) {
1690                         *nano = atoi(nano_str);
1691                         _LOGD("nano version exists");
1692                 }
1693         }
1694         _LOGD("version = [%s] -> major = [%d], minor = [%d]," \
1695                 " macro = [%d], nano = [%d]", version, *major,
1696                 *minor, *macro, *nano);
1697
1698         free(version_temp);
1699
1700         return PMINFO_R_OK;
1701 }
1702
1703 API int pkgmgrinfo_compare_package_version(const char *current_version,
1704                 const char *target_version,
1705                 pkgmgrinfo_version_compare_type *res)
1706 {
1707         int ret = 0;
1708         int current_version_major = 0;
1709         int current_version_minor = 0;
1710         int current_version_macro = 0;
1711         int current_version_nano = 0;
1712         int target_version_major = 0;
1713         int target_version_minor = 0;
1714         int target_version_macro = 0;
1715         int target_version_nano = 0;
1716
1717         if (current_version == NULL || target_version == NULL ||
1718                 res == NULL) {
1719                 _LOGE("Invalid parameter");
1720                 return PMINFO_R_EINVAL;
1721         }
1722
1723         ret = __compare_package_version(target_version,
1724                 &target_version_major, &target_version_minor,
1725                 &target_version_macro, &target_version_nano);
1726         if (ret < 0) {
1727                 _LOGE("Failed to compare target version(%d)", ret);
1728                 return PMINFO_R_ERROR;
1729         }
1730
1731         ret = __compare_package_version(current_version,
1732                 &current_version_major, &current_version_minor,
1733                 &current_version_macro, &current_version_nano);
1734         if (ret < 0) {
1735                 _LOGE("Failed to compare current version(%d)", ret);
1736                 return PMINFO_R_ERROR;
1737         }
1738
1739         _LOGD("new[%d.%d.%d.%d] old[%d.%d.%d.%d]", target_version_major,
1740                 target_version_minor, target_version_macro,
1741                 target_version_nano, current_version_major,
1742                 current_version_minor, current_version_macro,
1743                 target_version_nano);
1744
1745         if (target_version_major > current_version_major)
1746                 *res = PMINFO_VERSION_NEW;
1747         else if (target_version_major < current_version_major)
1748                 *res = PMINFO_VERSION_OLD;
1749         else if (target_version_minor > current_version_minor)
1750                 *res = PMINFO_VERSION_NEW;
1751         else if (target_version_minor < current_version_minor)
1752                 *res = PMINFO_VERSION_OLD;
1753         else if (target_version_macro > current_version_macro)
1754                 *res = PMINFO_VERSION_NEW;
1755         else if (target_version_macro < current_version_macro)
1756                 *res = PMINFO_VERSION_OLD;
1757         else if (target_version_nano > current_version_nano)
1758                 *res = PMINFO_VERSION_NEW;
1759         else if (target_version_nano < current_version_nano)
1760                 *res = PMINFO_VERSION_OLD;
1761         else
1762                 *res = PMINFO_VERSION_SAME;
1763
1764         return PMINFO_R_OK;
1765 }