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