Add PMINFO_PKGINFO_PROP_PACKAGE_SYSTEM property
[platform/core/appfw/pkgmgr-info.git] / src / pkgmgrinfo_private.h
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
24 #ifndef __PKGMGRINFO_PRIVATE_H__
25 #define __PKGMGRINFO_PRIVATE_H__
26
27 #include <stdbool.h>
28 #include <unistd.h>
29 #include <sys/types.h>
30
31 #include <sqlite3.h>
32 #include <glib.h>
33 #include <tzplatform_config.h>
34
35 #include "pkgmgrinfo_type.h"
36 #include "pkgmgrinfo_basic.h"
37
38 #ifndef DEPRECATED
39 #define DEPRECATED      __attribute__ ((__deprecated__))
40 #endif
41
42 #ifndef API
43 #define API __attribute__ ((visibility("default")))
44 #endif
45
46 #ifdef LOG_TAG
47 #undef LOG_TAG
48 #endif
49 #define LOG_TAG "PKGMGR_INFO"
50
51 #define ASC_CHAR(s) (const char *)s
52 #define XML_CHAR(s) (const xmlChar *)s
53
54 #define MANIFEST_DB     tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db")
55 #define MAX_QUERY_LEN   4096
56 #define MAX_CERT_TYPE   9
57 #define CERT_DB         tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db")
58 #define PKG_STRING_LEN_MAX 1024
59 #define PKG_TYPE_STRING_LEN_MAX         128
60 #define PKG_VERSION_STRING_LEN_MAX      128
61 #define PKG_VALUE_STRING_LEN_MAX                512
62 #define PKG_RW_PATH tzplatform_mkpath(TZ_USER_APP, "")
63 #define PKG_RO_PATH tzplatform_mkpath(TZ_SYS_RO_APP, "")
64 #define BLOCK_SIZE      4096 /*in bytes*/
65 #define BUFSIZE 4096
66 #define ROOT_UID 0
67 #define APPFW_UID 301
68
69 #define PKG_SD_PATH tzplatform_mkpath3(TZ_SYS_STORAGE, "sdcard", "app2sd/")
70 #define PKG_INSTALLATION_PATH tzplatform_mkpath(TZ_USER_APP, "")
71
72 #define SERVICE_NAME "org.tizen.system.deviced"
73 #define PATH_NAME "/Org/Tizen/System/DeviceD/Mmc"
74 #define INTERFACE_NAME "org.tizen.system.deviced.Mmc"
75 #define METHOD_NAME "RequestMountApp2ext"
76
77 /*String properties for filtering based on package info*/
78 typedef enum _pkgmgrinfo_pkginfo_filter_prop_str {
79         E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR = 101,
80         E_PMINFO_PKGINFO_PROP_PACKAGE_ID = E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR,
81         E_PMINFO_PKGINFO_PROP_PACKAGE_TYPE,
82         E_PMINFO_PKGINFO_PROP_PACKAGE_VERSION,
83         E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALL_LOCATION,
84         E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE,
85         E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_NAME,
86         E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_EMAIL,
87         E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_HREF,
88         E_PMINFO_PKGINFO_PROP_PACKAGE_PRIVILEGE,
89         E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR = E_PMINFO_PKGINFO_PROP_PACKAGE_PRIVILEGE
90 } pkgmgrinfo_pkginfo_filter_prop_str;
91
92 /*Boolean properties for filtering based on package info*/
93 typedef enum _pkgmgrinfo_pkginfo_filter_prop_bool {
94         E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL = 201,
95         E_PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE = E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL,
96         E_PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD,
97         E_PMINFO_PKGINFO_PROP_PACKAGE_READONLY,
98         E_PMINFO_PKGINFO_PROP_PACKAGE_UPDATE,
99         E_PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING,
100         E_PMINFO_PKGINFO_PROP_PACKAGE_NODISPLAY_SETTING,
101         E_PMINFO_PKGINFO_PROP_PACKAGE_SUPPORT_DISABLE,
102         E_PMINFO_PKGINFO_PROP_PACKAGE_DISABLE,
103         E_PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE,
104         E_PMINFO_PKGINFO_PROP_PACKAGE_SYSTEM,
105         E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL = E_PMINFO_PKGINFO_PROP_PACKAGE_SYSTEM
106 } pkgmgrinfo_pkginfo_filter_prop_bool;
107
108 /*Integer properties for filtering based on package info*/
109 typedef enum _pkgmgrinfo_pkginfo_filter_prop_int {
110         E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT = 301,
111         E_PMINFO_PKGINFO_PROP_PACKAGE_SIZE = E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT,
112         E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT = E_PMINFO_PKGINFO_PROP_PACKAGE_SIZE
113 } pkgmgrinfo_pkginfo_filter_prop_int;
114
115 /*String properties for filtering based on app info*/
116 typedef enum _pkgmgrinfo_appinfo_filter_prop_str {
117         E_PMINFO_APPINFO_PROP_APP_MIN_STR = 401,
118         E_PMINFO_APPINFO_PROP_APP_ID = E_PMINFO_APPINFO_PROP_APP_MIN_STR,
119         E_PMINFO_APPINFO_PROP_APP_COMPONENT,
120         E_PMINFO_APPINFO_PROP_APP_EXEC,
121         E_PMINFO_APPINFO_PROP_APP_ICON,
122         E_PMINFO_APPINFO_PROP_APP_TYPE,
123         E_PMINFO_APPINFO_PROP_APP_OPERATION,
124         E_PMINFO_APPINFO_PROP_APP_URI,
125         E_PMINFO_APPINFO_PROP_APP_MIME,
126         E_PMINFO_APPINFO_PROP_APP_HWACCELERATION,
127         E_PMINFO_APPINFO_PROP_APP_CATEGORY,
128         E_PMINFO_APPINFO_PROP_APP_SCREENREADER,
129         E_PMINFO_APPINFO_PROP_APP_PACKAGE,
130         E_PMINFO_APPINFO_PROP_APP_INSTALLED_STORAGE,
131         E_PMINFO_APPINFO_PROP_APP_MAX_STR = E_PMINFO_APPINFO_PROP_APP_INSTALLED_STORAGE
132 } pkgmgrinfo_appinfo_filter_prop_str;
133
134 /*Boolean properties for filtering based on app info*/
135 typedef enum _pkgmgrinfo_appinfo_filter_prop_bool {
136         E_PMINFO_APPINFO_PROP_APP_MIN_BOOL = 501,
137         E_PMINFO_APPINFO_PROP_APP_NODISPLAY = E_PMINFO_APPINFO_PROP_APP_MIN_BOOL,
138         E_PMINFO_APPINFO_PROP_APP_MULTIPLE,
139         E_PMINFO_APPINFO_PROP_APP_ONBOOT,
140         E_PMINFO_APPINFO_PROP_APP_AUTORESTART,
141         E_PMINFO_APPINFO_PROP_APP_TASKMANAGE,
142         E_PMINFO_APPINFO_PROP_APP_LAUNCHCONDITION,
143         E_PMINFO_APPINFO_PROP_APP_UI_GADGET,
144         E_PMINFO_APPINFO_PROP_APP_DISABLE,
145         E_PMINFO_APPINFO_PROP_APP_SUPPORT_DISABLE,
146         E_PMINFO_APPINFO_PROP_APP_CHECK_STORAGE,
147         E_PMINFO_APPINFO_PROP_PKG_DISABLE,
148         E_PMINFO_APPINFO_PROP_APP_MAX_BOOL = E_PMINFO_APPINFO_PROP_PKG_DISABLE
149 } pkgmgrinfo_appinfo_filter_prop_bool;
150
151 /*Integer properties for filtering based on app info*/
152 typedef enum _pkgmgrinfo_appinfo_filter_prop_int {
153         /*Currently No Fields*/
154         E_PMINFO_APPINFO_PROP_APP_MIN_INT = 601,
155         E_PMINFO_APPINFO_PROP_APP_SUPPORT_MODE = E_PMINFO_APPINFO_PROP_APP_MIN_INT,
156         E_PMINFO_APPINFO_PROP_APP_MAX_INT = E_PMINFO_APPINFO_PROP_APP_SUPPORT_MODE
157 } pkgmgrinfo_appinfo_filter_prop_int;
158
159 /*Integer properties for filtering based on app info*/
160 typedef enum _pkgmgrinfo_pkginfo_filter_prop_range {
161         /*Currently No Fields*/
162         E_PMINFO_PKGINFO_PROP_RANGE_MIN_INT = 701,
163         E_PMINFO_PKGINFO_PROP_RANGE_BASIC,
164         E_PMINFO_PKGINFO_PROP_RANGE_MAX_INT = E_PMINFO_PKGINFO_PROP_RANGE_BASIC
165 } pkgmgrinfo_pkginfo_filter_prop_range;
166
167 typedef enum _pkgmgrinfo_pkginfo_join_flag {
168         E_PMINFO_PKGINFO_JOIN_LOCALIZED_INFO = 0x0001,
169         E_PMINFO_PKGINFO_JOIN_PRIVILEGE_INFO = 0x0002,
170 } pkgmgrinfo_pkginfo_join_flag;
171
172 typedef enum _pkgmgrinfo_appinfo_join_flag {
173         E_PMINFO_APPINFO_JOIN_LOCALIZED_INFO = 0x0001,
174         E_PMINFO_APPINFO_JOIN_CATEGORY = 0x0002,
175         E_PMINFO_APPINFO_JOIN_APP_CONTROL = 0x0004,
176         E_PMINFO_APPINFO_JOIN_METADATA = 0x0008,
177 } pkgmgrinfo_appinfo_join_flag;
178
179 typedef enum _pkgmgrinfo_appinfo_disable_type {
180         E_APPINFO_DISABLE_TYPE_PKG = 0,
181         E_APPINFO_DISABLE_TYPE_APP
182 } pkgmgrinfo_appinfo_disable_type;
183
184 typedef struct _pkgmgr_pkginfo_x {
185         uid_t uid;
186         package_x *pkg_info;
187         char *locale;
188 } pkgmgr_pkginfo_x;
189
190 typedef struct _pkgmgr_appinfo_x {
191         const char *package;
192         char *locale;
193         pkgmgrinfo_app_component app_component;
194         application_x *app_info;
195 } pkgmgr_appinfo_x;
196
197 /*For filter APIs*/
198 typedef struct _pkgmgrinfo_filter_x {
199         uid_t uid;
200         GSList *list;
201         GSList *list_metadata;
202 } pkgmgrinfo_filter_x;
203
204 typedef struct _pkgmgrinfo_node_x {
205         int prop;
206         char *key;
207         char *value;
208 } pkgmgrinfo_node_x;
209
210 typedef struct _pkgmgrinfo_metadata_node_x {
211         char *key;
212         char *value;
213 } pkgmgrinfo_metadata_node_x;
214
215 typedef struct _pkgmgrinfo_appcontrol_x {
216         int operation_count;
217         int uri_count;
218         int mime_count;
219         int subapp_count;
220         char **operation;
221         char **uri;
222         char **mime;
223         char **subapp;
224 } pkgmgrinfo_appcontrol_x;
225
226 typedef struct _db_handle {
227         sqlite3 *dbHandle;
228         int ref;
229 } db_handle;
230
231 /* TODO: refine below structures */
232 #define PKG_TYPE_STRING_LEN_MAX 128
233 #define PKG_NAME_STRING_LEN_MAX 128
234 #define PKG_VERSION_STRING_LEN_MAX      128
235 #define PKG_VALUE_STRING_LEN_MAX 512
236 #define PKG_URL_STRING_LEN_MAX 1024
237 #define PKG_LABEL_STRING_LEN_MAX 128
238 #define PKG_PATH_STRING_LEN_MAX 512
239
240 typedef struct _package_manager_pkg_info_t {
241         char pkg_type[PKG_TYPE_STRING_LEN_MAX];
242         char pkg_name[PKG_NAME_STRING_LEN_MAX];
243         char pkgid[PKG_NAME_STRING_LEN_MAX];
244         char version[PKG_VERSION_STRING_LEN_MAX];
245         struct _package_manager_pkg_info_t *next;
246 } package_manager_pkg_info_t;
247
248 typedef struct _package_manager_pkg_detail_info_t {
249         char pkg_type[PKG_TYPE_STRING_LEN_MAX];
250         char pkg_name[PKG_NAME_STRING_LEN_MAX];
251         char pkgid[PKG_NAME_STRING_LEN_MAX];
252         char version[PKG_VERSION_STRING_LEN_MAX];
253         char api_version[PKG_VERSION_STRING_LEN_MAX];
254         char pkg_description[PKG_VALUE_STRING_LEN_MAX];
255         char min_platform_version[PKG_VERSION_STRING_LEN_MAX];
256         time_t installed_time;  /* installed time it must be GMT+0 time */
257         int installed_size;             /* installed total size */
258         int app_size;                   /* installed app size */
259         int data_size;                  /* data size which is made on run time */
260         char optional_id[PKG_NAME_STRING_LEN_MAX]; /*package ID if exists */
261         void *pkg_optional_info;
262         char label[PKG_LABEL_STRING_LEN_MAX];
263         char author[PKG_VALUE_STRING_LEN_MAX];
264         char *icon_buf;
265         int icon_size;
266         GList *privilege_list;
267 } package_manager_pkg_detail_info_t;
268
269 typedef void (*_pkg_plugin_unload)(void);
270 typedef int (*_pkg_plugin_pkg_is_installed) (const char *pkgid);
271 typedef int (*_pkg_plugin_get_installed_pkg_list)(
272                 const char *category, const char *option,
273                 package_manager_pkg_info_t **list, int *count);
274 typedef int (*_pkg_plugin_get_pkg_detail_info)(const char *pkgid,
275                 package_manager_pkg_detail_info_t *pkg_detail_info);
276 typedef int (*_pkg_plugin_get_pkg_detail_info_from_package)(
277                 const char *pkg_path,
278                 package_manager_pkg_detail_info_t *pkg_detail_info);
279
280 typedef struct _pkg_plugin_set {
281         char pkg_type[PKG_TYPE_STRING_LEN_MAX];
282         void *plugin_handle;
283         _pkg_plugin_unload plugin_on_unload;
284         _pkg_plugin_pkg_is_installed pkg_is_installed;
285         _pkg_plugin_get_installed_pkg_list get_installed_pkg_list;
286         _pkg_plugin_get_pkg_detail_info get_pkg_detail_info;
287         _pkg_plugin_get_pkg_detail_info_from_package
288         get_pkg_detail_info_from_package;
289 } pkg_plugin_set;
290
291 pkgmgrinfo_pkginfo_filter_prop_str _pminfo_pkginfo_convert_to_prop_str(const char *property);
292 pkgmgrinfo_pkginfo_filter_prop_int _pminfo_pkginfo_convert_to_prop_int(const char *property);
293 pkgmgrinfo_pkginfo_filter_prop_bool _pminfo_pkginfo_convert_to_prop_bool(const char *property);
294
295 pkgmgrinfo_appinfo_filter_prop_str _pminfo_appinfo_convert_to_prop_str(const char *property);
296 pkgmgrinfo_appinfo_filter_prop_int _pminfo_appinfo_convert_to_prop_int(const char *property);
297 pkgmgrinfo_appinfo_filter_prop_bool _pminfo_appinfo_convert_to_prop_bool(const char *property);
298
299 pkgmgrinfo_pkginfo_filter_prop_range _pminfo_pkginfo_convert_to_prop_range(const char *property);
300
301 int _check_create_cert_db(void);
302 void _save_column_int(sqlite3_stmt *stmt, int idx, int *i);
303 void _save_column_str(sqlite3_stmt *stmt, int idx, char **str);
304 char *_get_system_locale(void);
305 int __get_filter_condition(gpointer data, uid_t uid, char **condition, GList **param);
306 int __get_metadata_filter_condition(gpointer data, char **condition, GList **param);
307 int _add_icon_info_into_list(const char *locale, char *value, GList **icon);
308 int _add_label_info_into_list(const char *locale, char *value, GList **label);
309 int __pkginfo_check_installed_storage(package_x *pkginfo);
310 int __appinfo_check_installed_storage(application_x *appinfo);
311 int __open_db(const char *path, sqlite3 **db, int flags);
312 char *__get_type_from_path(const char *pkg_path);
313 pkg_plugin_set *__load_library(const char *pkg_type);
314 void __unload_library(const char *pkg_type);
315
316 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
317 #define REGULAR_USER 5000
318 static inline uid_t _getuid(void)
319 {
320         uid_t uid = getuid();
321
322         if (uid < REGULAR_USER)
323                 return tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
324         else
325                 return uid;
326 }
327
328 #endif  /* __PKGMGRINFO_PRIVATE_H__ */