Revert "Revert "Remove pkgmgrinfo_client_xxx""
[platform/core/appfw/pkgmgr-info.git] / src / pkgmgrinfo_private.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 #include <stdlib.h>
24 #include <string.h>
25 #include <stdio.h>
26 #include <ctype.h>
27
28 #include <vconf.h>
29 #include <sqlite3.h>
30 #include <glib.h>
31
32 #include "pkgmgr-info.h"
33 #include "pkgmgrinfo_debug.h"
34 #include "pkgmgrinfo_private.h"
35 #include "pkgmgr_parser.h"
36
37 struct _pkginfo_str_map_t {
38         pkgmgrinfo_pkginfo_filter_prop_str prop;
39         const char *property;
40 };
41
42 static struct _pkginfo_str_map_t pkginfo_str_prop_map[] = {
43         {E_PMINFO_PKGINFO_PROP_PACKAGE_ID,      PMINFO_PKGINFO_PROP_PACKAGE_ID},
44         {E_PMINFO_PKGINFO_PROP_PACKAGE_TYPE,    PMINFO_PKGINFO_PROP_PACKAGE_TYPE},
45         {E_PMINFO_PKGINFO_PROP_PACKAGE_VERSION, PMINFO_PKGINFO_PROP_PACKAGE_VERSION},
46         {E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALL_LOCATION,        PMINFO_PKGINFO_PROP_PACKAGE_INSTALL_LOCATION},
47         {E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE,       PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE},
48         {E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_NAME,     PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_NAME},
49         {E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_EMAIL,    PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_EMAIL},
50         {E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_HREF,     PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_HREF},
51         {E_PMINFO_PKGINFO_PROP_PACKAGE_PRIVILEGE,       PMINFO_PKGINFO_PROP_PACKAGE_PRIVILEGE}
52 };
53
54 struct _pkginfo_int_map_t {
55         pkgmgrinfo_pkginfo_filter_prop_int prop;
56         const char *property;
57 };
58
59 static struct _pkginfo_int_map_t pkginfo_int_prop_map[] = {
60         {E_PMINFO_PKGINFO_PROP_PACKAGE_SIZE,    PMINFO_PKGINFO_PROP_PACKAGE_SIZE}
61 };
62
63 struct _pkginfo_bool_map_t {
64         pkgmgrinfo_pkginfo_filter_prop_bool prop;
65         const char *property;
66 };
67
68 static struct _pkginfo_bool_map_t pkginfo_bool_prop_map[] = {
69         {E_PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE,       PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE},
70         {E_PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD,         PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD},
71         {E_PMINFO_PKGINFO_PROP_PACKAGE_READONLY,        PMINFO_PKGINFO_PROP_PACKAGE_READONLY},
72         {E_PMINFO_PKGINFO_PROP_PACKAGE_UPDATE,          PMINFO_PKGINFO_PROP_PACKAGE_UPDATE},
73         {E_PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING,      PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING},
74         {E_PMINFO_PKGINFO_PROP_PACKAGE_NODISPLAY_SETTING,       PMINFO_PKGINFO_PROP_PACKAGE_NODISPLAY_SETTING},
75         {E_PMINFO_PKGINFO_PROP_PACKAGE_SUPPORT_DISABLE, PMINFO_PKGINFO_PROP_PACKAGE_SUPPORT_DISABLE},
76         {E_PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, PMINFO_PKGINFO_PROP_PACKAGE_DISABLE}
77 };
78
79 struct _appinfo_str_map_t {
80         pkgmgrinfo_appinfo_filter_prop_str prop;
81         const char *property;
82 };
83
84 static struct _appinfo_str_map_t appinfo_str_prop_map[] = {
85         {E_PMINFO_APPINFO_PROP_APP_ID,          PMINFO_APPINFO_PROP_APP_ID},
86         {E_PMINFO_APPINFO_PROP_APP_COMPONENT,   PMINFO_APPINFO_PROP_APP_COMPONENT},
87         {E_PMINFO_APPINFO_PROP_APP_EXEC,        PMINFO_APPINFO_PROP_APP_EXEC},
88         {E_PMINFO_APPINFO_PROP_APP_ICON,        PMINFO_APPINFO_PROP_APP_ICON},
89         {E_PMINFO_APPINFO_PROP_APP_TYPE,        PMINFO_APPINFO_PROP_APP_TYPE},
90         {E_PMINFO_APPINFO_PROP_APP_OPERATION,   PMINFO_APPINFO_PROP_APP_OPERATION},
91         {E_PMINFO_APPINFO_PROP_APP_URI, PMINFO_APPINFO_PROP_APP_URI},
92         {E_PMINFO_APPINFO_PROP_APP_MIME,        PMINFO_APPINFO_PROP_APP_MIME},
93         {E_PMINFO_APPINFO_PROP_APP_CATEGORY,    PMINFO_APPINFO_PROP_APP_CATEGORY},
94         {E_PMINFO_APPINFO_PROP_APP_HWACCELERATION,      PMINFO_APPINFO_PROP_APP_HWACCELERATION},
95         {E_PMINFO_APPINFO_PROP_APP_SCREENREADER,        PMINFO_APPINFO_PROP_APP_SCREENREADER},
96         {E_PMINFO_APPINFO_PROP_APP_METADATA_KEY,        PMINFO_APPINFO_PROP_APP_METADATA_KEY},
97         {E_PMINFO_APPINFO_PROP_APP_METADATA_VALUE,      PMINFO_APPINFO_PROP_APP_METADATA_VALUE},
98         {E_PMINFO_APPINFO_PROP_APP_PACKAGE,     PMINFO_APPINFO_PROP_APP_PACKAGE},
99         {E_PMINFO_APPINFO_PROP_APP_INSTALLED_STORAGE,   PMINFO_APPINFO_PROP_APP_INSTALLED_STORAGE}
100 };
101
102 struct _appinfo_int_map_t {
103         pkgmgrinfo_appinfo_filter_prop_int prop;
104         const char *property;
105 };
106
107 static struct _appinfo_int_map_t appinfo_int_prop_map[] = {
108         {E_PMINFO_APPINFO_PROP_APP_DISABLE_FOR_USER,    PMINFO_APPINFO_PROP_APP_DISABLE_FOR_USER},
109         {E_PMINFO_APPINFO_PROP_APP_SUPPORT_MODE,        PMINFO_APPINFO_PROP_APP_SUPPORT_MODE}
110 };
111
112 struct _appinfo_bool_map_t {
113         pkgmgrinfo_appinfo_filter_prop_bool prop;
114         const char *property;
115 };
116
117 static struct _appinfo_bool_map_t appinfo_bool_prop_map[] = {
118         {E_PMINFO_APPINFO_PROP_APP_NODISPLAY,           PMINFO_APPINFO_PROP_APP_NODISPLAY},
119         {E_PMINFO_APPINFO_PROP_APP_MULTIPLE,            PMINFO_APPINFO_PROP_APP_MULTIPLE},
120         {E_PMINFO_APPINFO_PROP_APP_ONBOOT,              PMINFO_APPINFO_PROP_APP_ONBOOT},
121         {E_PMINFO_APPINFO_PROP_APP_AUTORESTART,         PMINFO_APPINFO_PROP_APP_AUTORESTART},
122         {E_PMINFO_APPINFO_PROP_APP_TASKMANAGE,          PMINFO_APPINFO_PROP_APP_TASKMANAGE},
123         {E_PMINFO_APPINFO_PROP_APP_LAUNCHCONDITION,             PMINFO_APPINFO_PROP_APP_LAUNCHCONDITION},
124         {E_PMINFO_APPINFO_PROP_APP_UI_GADGET,           PMINFO_APPINFO_PROP_APP_UI_GADGET},
125         {E_PMINFO_APPINFO_PROP_APP_SUPPORT_DISABLE,             PMINFO_APPINFO_PROP_APP_SUPPORT_DISABLE},
126         {E_PMINFO_APPINFO_PROP_APP_DISABLE,             PMINFO_APPINFO_PROP_APP_DISABLE}
127 };
128
129 inline pkgmgrinfo_pkginfo_filter_prop_str _pminfo_pkginfo_convert_to_prop_str(const char *property)
130 {
131         int i = 0;
132         int max = 0;
133         pkgmgrinfo_pkginfo_filter_prop_str prop = -1;
134
135         if (property == NULL)
136                 return -1;
137         max = E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR - E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR + 1;
138         for (i = 0 ; i < max; i++) {
139                 if (strcmp(property, pkginfo_str_prop_map[i].property) == 0) {
140                         prop =  pkginfo_str_prop_map[i].prop;
141                         break;
142                 }
143         }
144         return prop;
145 }
146
147 inline pkgmgrinfo_pkginfo_filter_prop_int _pminfo_pkginfo_convert_to_prop_int(const char *property)
148 {
149         int i = 0;
150         int max = 0;
151         pkgmgrinfo_pkginfo_filter_prop_int prop = -1;
152
153         if (property == NULL)
154                 return -1;
155         max = E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT - E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT + 1;
156         for (i = 0 ; i < max; i++) {
157                 if (strcmp(property, pkginfo_int_prop_map[i].property) == 0) {
158                         prop =  pkginfo_int_prop_map[i].prop;
159                         break;
160                 }
161         }
162         return prop;
163 }
164
165 inline pkgmgrinfo_pkginfo_filter_prop_bool _pminfo_pkginfo_convert_to_prop_bool(const char *property)
166 {
167         int i = 0;
168         int max = 0;
169         pkgmgrinfo_pkginfo_filter_prop_bool prop = -1;
170
171         if (property == NULL)
172                 return -1;
173         max = E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL - E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL + 1;
174         for (i = 0 ; i < max; i++) {
175                 if (strcmp(property, pkginfo_bool_prop_map[i].property) == 0) {
176                         prop =  pkginfo_bool_prop_map[i].prop;
177                         break;
178                 }
179         }
180         return prop;
181 }
182
183 inline pkgmgrinfo_appinfo_filter_prop_str _pminfo_appinfo_convert_to_prop_str(const char *property)
184 {
185         int i = 0;
186         int max = 0;
187         pkgmgrinfo_appinfo_filter_prop_str prop = -1;
188
189         if (property == NULL)
190                 return -1;
191         max = E_PMINFO_APPINFO_PROP_APP_MAX_STR - E_PMINFO_APPINFO_PROP_APP_MIN_STR + 1;
192         for (i = 0 ; i < max; i++) {
193                 if (strcmp(property, appinfo_str_prop_map[i].property) == 0) {
194                         prop =  appinfo_str_prop_map[i].prop;
195                         break;
196                 }
197         }
198         return prop;
199 }
200
201 inline pkgmgrinfo_appinfo_filter_prop_int _pminfo_appinfo_convert_to_prop_int(const char *property)
202 {
203         int i = 0;
204         int max = 0;
205         pkgmgrinfo_appinfo_filter_prop_int prop = -1;
206
207         if (property == NULL)
208                 return -1;
209         max = E_PMINFO_APPINFO_PROP_APP_MAX_INT - E_PMINFO_APPINFO_PROP_APP_MIN_INT + 1;
210         for (i = 0 ; i < max; i++) {
211                 if (strcmp(property, appinfo_int_prop_map[i].property) == 0) {
212                         prop =  appinfo_int_prop_map[i].prop;
213                         break;
214                 }
215         }
216         return prop;
217 }
218
219 inline pkgmgrinfo_appinfo_filter_prop_bool _pminfo_appinfo_convert_to_prop_bool(const char *property)
220 {
221         int i = 0;
222         int max = 0;
223         pkgmgrinfo_appinfo_filter_prop_bool prop = -1;
224
225         if (property == NULL)
226                 return -1;
227         max = E_PMINFO_APPINFO_PROP_APP_MAX_BOOL - E_PMINFO_APPINFO_PROP_APP_MIN_BOOL + 1;
228         for (i = 0 ; i < max; i++) {
229                 if (strcmp(property, appinfo_bool_prop_map[i].property) == 0) {
230                         prop =  appinfo_bool_prop_map[i].prop;
231                         break;
232                 }
233         }
234         return prop;
235 }
236
237 int __get_filter_condition(gpointer data, char **condition, GList **params)
238 {
239         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)data;
240         char buf[MAX_QUERY_LEN] = {'\0'};
241         int flag = 0;
242         char *ptr = NULL;
243         char *saveptr = NULL;
244
245         switch (node->prop) {
246         case E_PMINFO_PKGINFO_PROP_PACKAGE_ID:
247                 snprintf(buf, sizeof(buf), "pi.package=?");
248                 break;
249         case E_PMINFO_PKGINFO_PROP_PACKAGE_TYPE:
250                 snprintf(buf, sizeof(buf), "pi.package_type=?");
251                 break;
252         case E_PMINFO_PKGINFO_PROP_PACKAGE_VERSION:
253                 snprintf(buf, sizeof(buf), "pi.package_version=?");
254                 break;
255         case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALL_LOCATION:
256                 snprintf(buf, sizeof(buf), "pi.install_location=?");
257                 break;
258         case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE:
259                 snprintf(buf, sizeof(buf), "pi.installed_storage=?");
260                 break;
261         case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_NAME:
262                 snprintf(buf, sizeof(buf), "pi.author_name=?");
263                 break;
264         case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_HREF:
265                 snprintf(buf, sizeof(buf), "pi.author_href=?");
266                 break;
267         case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_EMAIL:
268                 snprintf(buf, sizeof(buf), "pi.author_email=?");
269                 break;
270         case E_PMINFO_PKGINFO_PROP_PACKAGE_PRIVILEGE:
271                 snprintf(buf, sizeof(buf), "package_privilege_info.privilege=?");
272                 flag = E_PMINFO_PKGINFO_JOIN_PRIVILEGE_INFO;
273                 break;
274         case E_PMINFO_PKGINFO_PROP_PACKAGE_SIZE:
275                 snprintf(buf, sizeof(buf), "pi.package_size=?");
276                 break;
277         case E_PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE:
278                 snprintf(buf, sizeof(buf), "pi.package_removable=? COLLATE NOCASE");
279                 break;
280         case E_PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD:
281                 snprintf(buf, sizeof(buf), "pi.package_preload=? COLLATE NOCASE");
282                 break;
283         case E_PMINFO_PKGINFO_PROP_PACKAGE_READONLY:
284                 snprintf(buf, sizeof(buf), "pi.package_readonly=? COLLATE NOCASE");
285                 break;
286         case E_PMINFO_PKGINFO_PROP_PACKAGE_UPDATE:
287                 snprintf(buf, sizeof(buf), "pi.package_update=? COLLATE NOCASE");
288                 break;
289         case E_PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING:
290                 snprintf(buf, sizeof(buf), "pi.package_appsetting=? COLLATE NOCASE");
291                 break;
292         case E_PMINFO_PKGINFO_PROP_PACKAGE_NODISPLAY_SETTING:
293                 snprintf(buf, sizeof(buf), "pi.package_nodisplay=? COLLATE NOCASE");
294                 break;
295         case E_PMINFO_PKGINFO_PROP_PACKAGE_SUPPORT_DISABLE:
296                 snprintf(buf, sizeof(buf), "pi.package_support_disable=? COLLATE NOCASE");
297                 break;
298         case E_PMINFO_PKGINFO_PROP_PACKAGE_DISABLE:
299                 snprintf(buf, sizeof(buf), "pi.package_disable=? COLLATE NOCASE");
300                 break;
301
302         case E_PMINFO_APPINFO_PROP_APP_ID:
303                 snprintf(buf, sizeof(buf), "ai.app_id=?");
304                 break;
305         case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
306                 snprintf(buf, sizeof(buf), "ai.app_component=?");
307                 break;
308         case E_PMINFO_APPINFO_PROP_APP_EXEC:
309                 snprintf(buf, sizeof(buf), "ai.app_exec=?");
310                 break;
311         case E_PMINFO_APPINFO_PROP_APP_ICON:
312                 snprintf(buf, sizeof(buf), "package_app_localized_info.app_icon=?");
313                 flag = E_PMINFO_APPINFO_JOIN_LOCALIZED_INFO;
314                 break;
315         case E_PMINFO_APPINFO_PROP_APP_TYPE:
316                 snprintf(buf, sizeof(buf), "ai.app_type=?");
317                 break;
318         case E_PMINFO_APPINFO_PROP_APP_OPERATION:
319                 snprintf(buf, sizeof(buf), "package_app_app_control.app_control LIKE ?||'|%%%%|%%%%'");
320                 flag = E_PMINFO_APPINFO_JOIN_APP_CONTROL;
321                 break;
322         case E_PMINFO_APPINFO_PROP_APP_URI:
323                 snprintf(buf, sizeof(buf), "package_app_app_control.app_control LIKE '%%%%|'||?||'|%%%%'");
324                 flag = E_PMINFO_APPINFO_JOIN_APP_CONTROL;
325                 break;
326         case E_PMINFO_APPINFO_PROP_APP_MIME:
327                 snprintf(buf, sizeof(buf), "package_app_app_control.app_control LIKE '%%%%|%%%%|'||?");
328                 flag = E_PMINFO_APPINFO_JOIN_APP_CONTROL;
329                 break;
330         case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
331                 snprintf(buf, sizeof(buf), "package_app_app_category.category IN (");
332                 ptr = strtok_r(node->value, ",", &saveptr);
333                 if (ptr == NULL)
334                         return 0;
335                 strncat(buf, "?", MAX_QUERY_LEN - 2);
336                 *params = g_list_append(*params, strdup(ptr));
337                 while ((ptr = strtok_r(NULL, ",", &saveptr))) {
338                         strncat(buf, ", ?", MAX_QUERY_LEN - strlen(", ?") - 1);
339                         *params = g_list_append(*params, strdup(ptr));
340                 }
341                 strncat(buf, ")", MAX_QUERY_LEN - 2);
342                 *condition = strdup(buf);
343                 flag = E_PMINFO_APPINFO_JOIN_CATEGORY;
344
345                 return flag;
346         case E_PMINFO_APPINFO_PROP_APP_NODISPLAY:
347                 snprintf(buf, sizeof(buf), "ai.app_nodisplay=? COLLATE NOCASE");
348                 break;
349         case E_PMINFO_APPINFO_PROP_APP_MULTIPLE:
350                 snprintf(buf, sizeof(buf), "ai.app_multiple=? COLLATE NOCASE");
351                 break;
352         case E_PMINFO_APPINFO_PROP_APP_ONBOOT:
353                 snprintf(buf, sizeof(buf), "ai.app_onboot=? COLLATE NOCASE");
354                 break;
355         case E_PMINFO_APPINFO_PROP_APP_AUTORESTART:
356                 snprintf(buf, sizeof(buf), "ai.app_autorestart=? COLLATE NOCASE");
357                 break;
358         case E_PMINFO_APPINFO_PROP_APP_TASKMANAGE:
359                 snprintf(buf, sizeof(buf), "ai.app_taskmanage=? COLLATE NOCASE");
360                 break;
361         case E_PMINFO_APPINFO_PROP_APP_HWACCELERATION:
362                 snprintf(buf, sizeof(buf), "ai.app_hwacceleration=?");
363                 break;
364         case E_PMINFO_APPINFO_PROP_APP_SCREENREADER:
365                 snprintf(buf, sizeof(buf), "ai.app_screenreader=?");
366                 break;
367         case E_PMINFO_APPINFO_PROP_APP_LAUNCHCONDITION:
368                 snprintf(buf, sizeof(buf), "ai.app_launchcondition=? COLLATE NOCASE");
369                 break;
370         case E_PMINFO_APPINFO_PROP_APP_PACKAGE:
371                 snprintf(buf, sizeof(buf), "ai.package=?");
372                 break;
373         case E_PMINFO_APPINFO_PROP_APP_INSTALLED_STORAGE:
374                 snprintf(buf, sizeof(buf), "ai.app_installed_storage=?");
375                 break;
376         case E_PMINFO_APPINFO_PROP_APP_UI_GADGET:
377                 snprintf(buf, sizeof(buf), "ai.app_ui_gadget=? COLLATE NOCASE");
378                 break;
379         case E_PMINFO_APPINFO_PROP_APP_METADATA_KEY:
380                 snprintf(buf, sizeof(buf), "package_app_app_metadata.md_key=?");
381                 flag = E_PMINFO_APPINFO_JOIN_METADATA;
382                 break;
383         case E_PMINFO_APPINFO_PROP_APP_METADATA_VALUE:
384                 snprintf(buf, sizeof(buf), "package_app_app_metadata.md_value=?");
385                 flag = E_PMINFO_APPINFO_JOIN_METADATA;
386                 break;
387         case E_PMINFO_APPINFO_PROP_APP_DISABLE:
388                 snprintf(buf, MAX_QUERY_LEN, "ai.app_disable=? COLLATE NOCASE");
389                 break;
390         case E_PMINFO_APPINFO_PROP_APP_SUPPORT_DISABLE:
391                 snprintf(buf, MAX_QUERY_LEN, "ai.app_support_disable=? COLLATE NOCASE");
392                 break;
393         case E_PMINFO_APPINFO_PROP_APP_DISABLE_FOR_USER:
394                 snprintf(buf, MAX_QUERY_LEN, "ai.app_id NOT IN "
395                                 "(SELECT app_id from package_app_info_for_uid WHERE uid=? " \
396                                 "AND is_disabled='true' COLLATE NOCASE)");
397                 break;
398         case E_PMINFO_APPINFO_PROP_APP_SUPPORT_MODE:
399                 snprintf(buf, sizeof(buf), "ai.app_support_mode=?");
400                 break;
401         default:
402                 _LOGE("Invalid Property Type\n");
403                 *condition = NULL;
404                 return 0;
405         }
406         *condition = strdup(buf);
407         *params = g_list_append(*params, strdup(node->value));
408         return flag;
409 }
410
411 int _add_icon_info_into_list(const char *locale, char *value, GList **icon)
412 {
413         icon_x *info;
414
415         info = calloc(1, sizeof(icon_x));
416         if (info == NULL) {
417                 LOGE("out of memory");
418                 return PMINFO_R_ERROR;
419         }
420         info->text = value;
421         info->lang = strdup(locale);
422         *icon = g_list_append(*icon, info);
423
424         return PMINFO_R_OK;
425 }
426
427 int _add_label_info_into_list(const char *locale, char *value, GList **label)
428 {
429         label_x *info;
430
431         info = calloc(1, sizeof(label_x));
432         if (info == NULL) {
433                 LOGE("out of memory");
434                 return PMINFO_R_ERROR;
435         }
436         info->text = value;
437         info->lang = strdup(locale);
438         *label = g_list_append(*label, info);
439
440         return PMINFO_R_OK;
441 }
442
443 char *_get_system_locale(void)
444 {
445         char *lang;
446         char *locale;
447
448         lang = vconf_get_str(VCONFKEY_LANGSET);
449         if (lang == NULL) {
450                 locale = strdup(DEFAULT_LOCALE);
451                 if (locale == NULL) {
452                         LOGE("out of memory");
453                         return NULL;
454                 }
455                 return locale;
456         }
457
458         locale = malloc(sizeof(char) * 6);
459         if (locale == NULL) {
460                 LOGE("out of memory");
461                 free(lang);
462                 return NULL;
463         }
464
465         strncpy(locale, lang, 2);
466         locale[2] = '-';
467         locale[3] = tolower(lang[3]);
468         locale[4] = tolower(lang[4]);
469         locale[5] = '\0';
470
471         free(lang);
472
473         return locale;
474 }
475
476 int __pkginfo_check_installed_storage(package_x *pkginfo)
477 {
478         char buf[MAX_QUERY_LEN] = {'\0'};
479         int ret;
480
481         retvm_if(pkginfo->package == NULL, PMINFO_R_OK, "pkgid is NULL\n");
482         retvm_if(pkginfo->installed_storage == NULL, PMINFO_R_ERROR,
483                         "installed_storage is NULL\n");
484
485         if (strcmp(pkginfo->installed_storage, "installed_external") == 0) {
486                 snprintf(buf, MAX_QUERY_LEN - 1, "%s", pkginfo->external_path);
487                 ret = access(buf, F_OK);
488                 if (ret != 0) {
489                         _LOGE("can not access [%s] - %d", buf, ret);
490                         return PMINFO_R_ERROR;
491                 }
492         }
493
494         return PMINFO_R_OK;
495 }
496
497 int __appinfo_check_installed_storage(application_x *appinfo)
498 {
499         retvm_if(appinfo->installed_storage == NULL, PMINFO_R_ERROR,
500                         "installed_storage is NULL\n");
501
502         if (strcmp(appinfo->installed_storage, "installed_external") == 0) {
503                 retvm_if(appinfo->external_path == NULL, PMINFO_R_ERROR,
504                                 "external path is NULL\n");
505                 if (access(appinfo->external_path, R_OK) != 0) {
506                         _LOGE("can not access [%s]", appinfo->external_path);
507                         return PMINFO_R_ERROR;
508                 }
509         }
510
511         return PMINFO_R_OK;
512 }
513