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