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