Remove package_app_app_svc
[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 };
77
78 struct _appinfo_str_map_t {
79         pkgmgrinfo_appinfo_filter_prop_str prop;
80         const char *property;
81 };
82
83 static struct _appinfo_str_map_t appinfo_str_prop_map[] = {
84         {E_PMINFO_APPINFO_PROP_APP_ID,          PMINFO_APPINFO_PROP_APP_ID},
85         {E_PMINFO_APPINFO_PROP_APP_COMPONENT,   PMINFO_APPINFO_PROP_APP_COMPONENT},
86         {E_PMINFO_APPINFO_PROP_APP_EXEC,        PMINFO_APPINFO_PROP_APP_EXEC},
87         {E_PMINFO_APPINFO_PROP_APP_ICON,        PMINFO_APPINFO_PROP_APP_ICON},
88         {E_PMINFO_APPINFO_PROP_APP_TYPE,        PMINFO_APPINFO_PROP_APP_TYPE},
89         {E_PMINFO_APPINFO_PROP_APP_OPERATION,   PMINFO_APPINFO_PROP_APP_OPERATION},
90         {E_PMINFO_APPINFO_PROP_APP_URI,         PMINFO_APPINFO_PROP_APP_URI},
91         {E_PMINFO_APPINFO_PROP_APP_MIME,        PMINFO_APPINFO_PROP_APP_MIME},
92         {E_PMINFO_APPINFO_PROP_APP_CATEGORY,    PMINFO_APPINFO_PROP_APP_CATEGORY},
93         {E_PMINFO_APPINFO_PROP_APP_HWACCELERATION,      PMINFO_APPINFO_PROP_APP_HWACCELERATION},
94         {E_PMINFO_APPINFO_PROP_APP_SCREENREADER,        PMINFO_APPINFO_PROP_APP_SCREENREADER},
95         {E_PMINFO_APPINFO_PROP_APP_METADATA_KEY,        PMINFO_APPINFO_PROP_APP_METADATA_KEY},
96         {E_PMINFO_APPINFO_PROP_APP_METADATA_VALUE,      PMINFO_APPINFO_PROP_APP_METADATA_VALUE},
97         {E_PMINFO_APPINFO_PROP_APP_PACKAGE,     PMINFO_APPINFO_PROP_APP_PACKAGE}
98 };
99
100 struct _appinfo_int_map_t {
101         pkgmgrinfo_appinfo_filter_prop_int prop;
102         const char *property;
103 };
104
105 static struct _appinfo_int_map_t appinfo_int_prop_map[] = {
106         /*Currently No Fields*/
107 };
108
109 struct _appinfo_bool_map_t {
110         pkgmgrinfo_appinfo_filter_prop_bool prop;
111         const char *property;
112 };
113
114 static struct _appinfo_bool_map_t appinfo_bool_prop_map[] = {
115         {E_PMINFO_APPINFO_PROP_APP_NODISPLAY,           PMINFO_APPINFO_PROP_APP_NODISPLAY},
116         {E_PMINFO_APPINFO_PROP_APP_MULTIPLE,            PMINFO_APPINFO_PROP_APP_MULTIPLE},
117         {E_PMINFO_APPINFO_PROP_APP_ONBOOT,              PMINFO_APPINFO_PROP_APP_ONBOOT},
118         {E_PMINFO_APPINFO_PROP_APP_AUTORESTART,         PMINFO_APPINFO_PROP_APP_AUTORESTART},
119         {E_PMINFO_APPINFO_PROP_APP_TASKMANAGE,          PMINFO_APPINFO_PROP_APP_TASKMANAGE},
120         {E_PMINFO_APPINFO_PROP_APP_LAUNCHCONDITION,             PMINFO_APPINFO_PROP_APP_LAUNCHCONDITION},
121         {E_PMINFO_APPINFO_PROP_APP_UI_GADGET,           PMINFO_APPINFO_PROP_APP_UI_GADGET},
122         {E_PMINFO_APPINFO_PROP_APP_SUPPORT_DISABLE,             PMINFO_APPINFO_PROP_APP_SUPPORT_DISABLE}
123 };
124
125 inline pkgmgrinfo_pkginfo_filter_prop_str _pminfo_pkginfo_convert_to_prop_str(const char *property)
126 {
127         int i = 0;
128         int max = 0;
129         pkgmgrinfo_pkginfo_filter_prop_str prop = -1;
130
131         if (property == NULL)
132                 return -1;
133         max = E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR - E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR + 1;
134         for (i = 0 ; i < max; i++) {
135                 if (strcmp(property, pkginfo_str_prop_map[i].property) == 0) {
136                         prop =  pkginfo_str_prop_map[i].prop;
137                         break;
138                 }
139         }
140         return prop;
141 }
142
143 inline pkgmgrinfo_pkginfo_filter_prop_int _pminfo_pkginfo_convert_to_prop_int(const char *property)
144 {
145         int i = 0;
146         int max = 0;
147         pkgmgrinfo_pkginfo_filter_prop_int prop = -1;
148
149         if (property == NULL)
150                 return -1;
151         max = E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT - E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT + 1;
152         for (i = 0 ; i < max; i++) {
153                 if (strcmp(property, pkginfo_int_prop_map[i].property) == 0) {
154                         prop =  pkginfo_int_prop_map[i].prop;
155                         break;
156                 }
157         }
158         return prop;
159 }
160
161 inline pkgmgrinfo_pkginfo_filter_prop_bool _pminfo_pkginfo_convert_to_prop_bool(const char *property)
162 {
163         int i = 0;
164         int max = 0;
165         pkgmgrinfo_pkginfo_filter_prop_bool prop = -1;
166
167         if (property == NULL)
168                 return -1;
169         max = E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL - E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL + 1;
170         for (i = 0 ; i < max; i++) {
171                 if (strcmp(property, pkginfo_bool_prop_map[i].property) == 0) {
172                         prop =  pkginfo_bool_prop_map[i].prop;
173                         break;
174                 }
175         }
176         return prop;
177 }
178
179 inline pkgmgrinfo_appinfo_filter_prop_str _pminfo_appinfo_convert_to_prop_str(const char *property)
180 {
181         int i = 0;
182         int max = 0;
183         pkgmgrinfo_appinfo_filter_prop_str prop = -1;
184
185         if (property == NULL)
186                 return -1;
187         max = E_PMINFO_APPINFO_PROP_APP_MAX_STR - E_PMINFO_APPINFO_PROP_APP_MIN_STR + 1;
188         for (i = 0 ; i < max; i++) {
189                 if (strcmp(property, appinfo_str_prop_map[i].property) == 0) {
190                         prop =  appinfo_str_prop_map[i].prop;
191                         break;
192                 }
193         }
194         return prop;
195 }
196
197 inline pkgmgrinfo_appinfo_filter_prop_int _pminfo_appinfo_convert_to_prop_int(const char *property)
198 {
199         int i = 0;
200         int max = 0;
201         pkgmgrinfo_appinfo_filter_prop_int prop = -1;
202
203         if (property == NULL)
204                 return -1;
205         max = E_PMINFO_APPINFO_PROP_APP_MAX_INT - E_PMINFO_APPINFO_PROP_APP_MIN_INT + 1;
206         for (i = 0 ; i < max; i++) {
207                 if (strcmp(property, appinfo_int_prop_map[i].property) == 0) {
208                         prop =  appinfo_int_prop_map[i].prop;
209                         break;
210                 }
211         }
212         return prop;
213 }
214
215 inline pkgmgrinfo_appinfo_filter_prop_bool _pminfo_appinfo_convert_to_prop_bool(const char *property)
216 {
217         int i = 0;
218         int max = 0;
219         pkgmgrinfo_appinfo_filter_prop_bool prop = -1;
220
221         if (property == NULL)
222                 return -1;
223         max = E_PMINFO_APPINFO_PROP_APP_MAX_BOOL - E_PMINFO_APPINFO_PROP_APP_MIN_BOOL + 1;
224         for (i = 0 ; i < max; i++) {
225                 if (strcmp(property, appinfo_bool_prop_map[i].property) == 0) {
226                         prop =  appinfo_bool_prop_map[i].prop;
227                         break;
228                 }
229         }
230         return prop;
231 }
232
233 void __get_filter_condition(gpointer data, char **condition)
234 {
235         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
236         char buf[MAX_QUERY_LEN] = {'\0'};
237         char temp[PKG_STRING_LEN_MAX] = {'\0'};
238         switch (node->prop) {
239         case E_PMINFO_PKGINFO_PROP_PACKAGE_ID:
240                 snprintf(buf, sizeof(buf), "package_info.package='%s'", node->value);
241                 break;
242         case E_PMINFO_PKGINFO_PROP_PACKAGE_TYPE:
243                 snprintf(buf, sizeof(buf), "package_info.package_type='%s'", node->value);
244                 break;
245         case E_PMINFO_PKGINFO_PROP_PACKAGE_VERSION:
246                 snprintf(buf, sizeof(buf), "package_info.package_version='%s'", node->value);
247                 break;
248         case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALL_LOCATION:
249                 snprintf(buf, sizeof(buf), "package_info.install_location='%s'", node->value);
250                 break;
251         case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE:
252                 snprintf(buf, sizeof(buf), "package_info.installed_storage='%s'", node->value);
253                 break;
254         case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_NAME:
255                 snprintf(buf, sizeof(buf), "package_info.author_name='%s'", node->value);
256                 break;
257         case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_HREF:
258                 snprintf(buf, sizeof(buf), "package_info.author_href='%s'", node->value);
259                 break;
260         case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_EMAIL:
261                 snprintf(buf, sizeof(buf), "package_info.author_email='%s'", node->value);
262                 break;
263         case E_PMINFO_PKGINFO_PROP_PACKAGE_PRIVILEGE:
264                 snprintf(buf, sizeof(buf), "package_privilege_info.privilege='%s'", node->value);
265                 break;
266         case E_PMINFO_PKGINFO_PROP_PACKAGE_SIZE:
267                 snprintf(buf, sizeof(buf), "package_info.package_size='%s'", node->value);
268                 break;
269         case E_PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE:
270                 snprintf(buf, sizeof(buf), "package_info.package_removable IN %s", node->value);
271                 break;
272         case E_PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD:
273                 snprintf(buf, sizeof(buf), "package_info.package_preload IN %s", node->value);
274                 break;
275         case E_PMINFO_PKGINFO_PROP_PACKAGE_READONLY:
276                 snprintf(buf, sizeof(buf), "package_info.package_readonly IN %s", node->value);
277                 break;
278         case E_PMINFO_PKGINFO_PROP_PACKAGE_UPDATE:
279                 snprintf(buf, sizeof(buf), "package_info.package_update IN %s", node->value);
280                 break;
281         case E_PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING:
282                 snprintf(buf, sizeof(buf), "package_info.package_appsetting IN %s", node->value);
283                 break;
284         case E_PMINFO_PKGINFO_PROP_PACKAGE_NODISPLAY_SETTING:
285                 snprintf(buf, sizeof(buf), "package_info.package_nodisplay IN %s", node->value);
286                 break;
287         case E_PMINFO_PKGINFO_PROP_PACKAGE_SUPPORT_DISABLE:
288                 snprintf(buf, sizeof(buf), "package_info.package_support_disable IN %s", node->value);
289                 break;
290
291         case E_PMINFO_APPINFO_PROP_APP_ID:
292                 snprintf(buf, sizeof(buf), "package_app_info.app_id='%s'", node->value);
293                 break;
294         case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
295                 snprintf(buf, sizeof(buf), "package_app_info.app_component='%s'", node->value);
296                 break;
297         case E_PMINFO_APPINFO_PROP_APP_EXEC:
298                 snprintf(buf, sizeof(buf), "package_app_info.app_exec='%s'", node->value);
299                 break;
300         case E_PMINFO_APPINFO_PROP_APP_ICON:
301                 snprintf(buf, sizeof(buf), "package_app_localized_info.app_icon='%s'", node->value);
302                 break;
303         case E_PMINFO_APPINFO_PROP_APP_TYPE:
304                 snprintf(buf, sizeof(buf), "package_app_info.app_type='%s'", node->value);
305                 break;
306         case E_PMINFO_APPINFO_PROP_APP_OPERATION:
307                 snprintf(temp, sizeof(temp), "(%s)", node->value);
308                 snprintf(buf, sizeof(buf), "package_app_app_control.app_control LIKE %s|%%|%%", temp);
309                 break;
310         case E_PMINFO_APPINFO_PROP_APP_URI:
311                 snprintf(temp, sizeof(temp), "(%s)", node->value);
312                 snprintf(buf, sizeof(buf), "package_app_app_control.app_control LIKE %%|%s|%%", temp);
313                 break;
314         case E_PMINFO_APPINFO_PROP_APP_MIME:
315                 snprintf(temp, sizeof(temp), "(%s)", node->value);
316                 snprintf(buf, sizeof(buf), "package_app_app_control.app_control LIKE %%|%%|%s", temp);
317                 break;
318         case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
319                 snprintf(temp, sizeof(temp), "(%s)", node->value);
320                 snprintf(buf, sizeof(buf), "package_app_app_category.category IN %s", temp);
321                 break;
322         case E_PMINFO_APPINFO_PROP_APP_NODISPLAY:
323                 snprintf(buf, sizeof(buf), "package_app_info.app_nodisplay IN %s", node->value);
324                 break;
325         case E_PMINFO_APPINFO_PROP_APP_MULTIPLE:
326                 snprintf(buf, sizeof(buf), "package_app_info.app_multiple IN %s", node->value);
327                 break;
328         case E_PMINFO_APPINFO_PROP_APP_ONBOOT:
329                 snprintf(buf, sizeof(buf), "package_app_info.app_onboot IN %s", node->value);
330                 break;
331         case E_PMINFO_APPINFO_PROP_APP_AUTORESTART:
332                 snprintf(buf, sizeof(buf), "package_app_info.app_autorestart IN %s", node->value);
333                 break;
334         case E_PMINFO_APPINFO_PROP_APP_TASKMANAGE:
335                 snprintf(buf, sizeof(buf), "package_app_info.app_taskmanage IN %s", node->value);
336                 break;
337         case E_PMINFO_APPINFO_PROP_APP_HWACCELERATION:
338                 snprintf(buf, sizeof(buf), "package_app_info.app_hwacceleration='%s'", node->value);
339                 break;
340         case E_PMINFO_APPINFO_PROP_APP_SCREENREADER:
341                 snprintf(buf, sizeof(buf), "package_app_info.app_screenreader='%s'", node->value);
342                 break;
343         case E_PMINFO_APPINFO_PROP_APP_LAUNCHCONDITION:
344                 snprintf(buf, sizeof(buf), "package_app_info.app_launchcondition IN %s", node->value);
345                 break;
346         case E_PMINFO_APPINFO_PROP_APP_PACKAGE:
347                 snprintf(buf, sizeof(buf), "package_app_info.package='%s'", node->value);
348                 break;
349         case E_PMINFO_APPINFO_PROP_APP_UI_GADGET:
350                 snprintf(buf, sizeof(buf), "package_app_info.app_ui_gadget IN %s", node->value);
351                 break;
352         case E_PMINFO_APPINFO_PROP_APP_METADATA_KEY:
353                 snprintf(buf, sizeof(buf), "package_app_app_metadata.md_key='%s'", node->value);
354                 break;
355         case E_PMINFO_APPINFO_PROP_APP_METADATA_VALUE:
356                 snprintf(buf, sizeof(buf), "package_app_app_metadata.md_value='%s'", node->value);
357                 break;
358         case E_PMINFO_APPINFO_PROP_APP_SUPPORT_DISABLE:
359                 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_support_disable IN %s", node->value);
360                 break;
361         default:
362                 _LOGE("Invalid Property Type\n");
363                 *condition = NULL;
364                 return;
365         }
366         *condition = strdup(buf);
367         return;
368 }
369
370 char *_get_system_locale(void)
371 {
372         char *lang;
373         char *locale;
374
375         lang = vconf_get_str(VCONFKEY_LANGSET);
376         if (lang == NULL) {
377                 locale = strdup(DEFAULT_LOCALE);
378                 if (locale == NULL) {
379                         LOGE("out of memory");
380                         return NULL;
381                 }
382                 return locale;
383         }
384
385         locale = malloc(sizeof(char) * 6);
386         if (locale == NULL) {
387                 LOGE("out of memory");
388                 free(lang);
389                 return NULL;
390         }
391
392         strncpy(locale, lang, 2);
393         locale[2] = '-';
394         locale[3] = tolower(lang[3]);
395         locale[4] = tolower(lang[4]);
396         locale[5] = '\0';
397
398         free(lang);
399
400         return locale;
401 }
402