Fix memory leak
[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 #ifdef __cplusplus
39 extern "C" {
40 #endif
41
42 #ifndef DEPRECATED
43 #define DEPRECATED      __attribute__ ((__deprecated__))
44 #endif
45
46 #ifndef API
47 #define API __attribute__ ((visibility("default")))
48 #endif
49
50 #ifdef LOG_TAG
51 #undef LOG_TAG
52 #endif
53 #define LOG_TAG "PKGMGR_INFO"
54
55 #define ASC_CHAR(s) (const char *)s
56 #define XML_CHAR(s) (const xmlChar *)s
57
58 #define MANIFEST_DB     tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db")
59 #define MAX_QUERY_LEN   4096
60 #define MAX_CERT_TYPE   9
61 #define CERT_DB         tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db")
62 #define PKG_STRING_LEN_MAX 1024
63 #define PKG_TYPE_STRING_LEN_MAX         128
64 #define PKG_VERSION_STRING_LEN_MAX      128
65 #define PKG_VALUE_STRING_LEN_MAX                512
66 #define PKG_RW_PATH tzplatform_mkpath(TZ_USER_APP, "")
67 #define PKG_RO_PATH tzplatform_mkpath(TZ_SYS_RO_APP, "")
68 #define BLOCK_SIZE      4096 /*in bytes*/
69 #define BUFSIZE 4096
70 #define ROOT_UID 0
71 #define APPFW_UID 301
72
73 #define PKG_SD_PATH tzplatform_mkpath3(TZ_SYS_STORAGE, "sdcard", "app2sd/")
74 #define PKG_INSTALLATION_PATH tzplatform_mkpath(TZ_USER_APP, "")
75
76 #define SERVICE_NAME "org.tizen.system.deviced"
77 #define PATH_NAME "/Org/Tizen/System/DeviceD/Mmc"
78 #define INTERFACE_NAME "org.tizen.system.deviced.Mmc"
79 #define METHOD_NAME "RequestMountApp2ext"
80
81 /*String properties for filtering based on package info*/
82 typedef enum _pkgmgrinfo_pkginfo_filter_prop_str {
83         E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR = 101,
84         E_PMINFO_PKGINFO_PROP_PACKAGE_ID = E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR,
85         E_PMINFO_PKGINFO_PROP_PACKAGE_TYPE,
86         E_PMINFO_PKGINFO_PROP_PACKAGE_VERSION,
87         E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALL_LOCATION,
88         E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE,
89         E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_NAME,
90         E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_EMAIL,
91         E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_HREF,
92         E_PMINFO_PKGINFO_PROP_PACKAGE_PRIVILEGE,
93         E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR = E_PMINFO_PKGINFO_PROP_PACKAGE_PRIVILEGE
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 } pkgmgrinfo_pkginfo_join_flag;
176
177 typedef enum _pkgmgrinfo_appinfo_join_flag {
178         E_PMINFO_APPINFO_JOIN_LOCALIZED_INFO = 0x0001,
179         E_PMINFO_APPINFO_JOIN_CATEGORY = 0x0002,
180         E_PMINFO_APPINFO_JOIN_APP_CONTROL = 0x0004,
181         E_PMINFO_APPINFO_JOIN_METADATA = 0x0008,
182         E_PMINFO_APPINFO_JOIN_PRIVILEGE = 0x0010,
183 } pkgmgrinfo_appinfo_join_flag;
184
185 typedef enum _pkgmgrinfo_appinfo_disable_type {
186         E_APPINFO_DISABLE_TYPE_PKG = 0,
187         E_APPINFO_DISABLE_TYPE_APP
188 } pkgmgrinfo_appinfo_disable_type;
189
190 typedef struct _pkgmgr_pkginfo_x {
191         uid_t uid;
192         package_x *pkg_info;
193         char *locale;
194 } pkgmgr_pkginfo_x;
195
196 typedef struct _pkgmgr_appinfo_x {
197         const char *package;
198         char *locale;
199         pkgmgrinfo_app_component app_component;
200         application_x *app_info;
201 } pkgmgr_appinfo_x;
202
203 /*For filter APIs*/
204 typedef struct _pkgmgrinfo_filter_x {
205         uid_t uid;
206         GSList *list;
207         GSList *list_metadata;
208 } pkgmgrinfo_filter_x;
209
210 typedef struct _pkgmgrinfo_node_x {
211         int prop;
212         char *key;
213         char *value;
214 } pkgmgrinfo_node_x;
215
216 typedef struct _pkgmgrinfo_metadata_node_x {
217         char *key;
218         char *value;
219 } pkgmgrinfo_metadata_node_x;
220
221 typedef struct _pkgmgrinfo_appcontrol_x {
222         int operation_count;
223         int uri_count;
224         int mime_count;
225         int subapp_count;
226         char **operation;
227         char **uri;
228         char **mime;
229         char **subapp;
230 } pkgmgrinfo_appcontrol_x;
231
232 typedef struct _pkgmgr_certinfo_x {
233         int for_all_users;
234         char *pkgid;
235         char *cert_value;
236         char *cert_info[MAX_CERT_TYPE]; /*certificate info*/
237         int cert_id[MAX_CERT_TYPE];             /*certificate ID in index table*/
238 } pkgmgr_certinfo_x;
239
240 typedef struct _db_handle {
241         sqlite3 *dbHandle;
242         int ref;
243 } db_handle;
244
245 /* TODO: refine below structures */
246 #define PKG_TYPE_STRING_LEN_MAX 128
247 #define PKG_NAME_STRING_LEN_MAX 128
248 #define PKG_VERSION_STRING_LEN_MAX      128
249 #define PKG_VALUE_STRING_LEN_MAX 512
250 #define PKG_URL_STRING_LEN_MAX 1024
251 #define PKG_LABEL_STRING_LEN_MAX 128
252 #define PKG_PATH_STRING_LEN_MAX 512
253 #define PKG_DEP_TYPE_STRING_LEN_MAX 128
254
255 typedef struct _package_manager_pkg_info_t {
256         char pkg_type[PKG_TYPE_STRING_LEN_MAX];
257         char pkg_name[PKG_NAME_STRING_LEN_MAX];
258         char pkgid[PKG_NAME_STRING_LEN_MAX];
259         char version[PKG_VERSION_STRING_LEN_MAX];
260         struct _package_manager_pkg_info_t *next;
261 } package_manager_pkg_info_t;
262
263 typedef struct _package_manager_pkg_dependency_info_t {
264         char pkgid[PKG_NAME_STRING_LEN_MAX];
265         char type[PKG_DEP_TYPE_STRING_LEN_MAX];
266         char required_version[PKG_VERSION_STRING_LEN_MAX];
267 } pkg_dependency_info_t;
268
269 typedef struct _package_manager_pkg_detail_info_t {
270         char pkg_type[PKG_TYPE_STRING_LEN_MAX];
271         char pkg_name[PKG_NAME_STRING_LEN_MAX];
272         char pkgid[PKG_NAME_STRING_LEN_MAX];
273         char version[PKG_VERSION_STRING_LEN_MAX];
274         char api_version[PKG_VERSION_STRING_LEN_MAX];
275         char pkg_description[PKG_VALUE_STRING_LEN_MAX];
276         char min_platform_version[PKG_VERSION_STRING_LEN_MAX];
277         time_t installed_time;  /* installed time it must be GMT+0 time */
278         int installed_size;             /* installed total size */
279         int app_size;                   /* installed app size */
280         int data_size;                  /* data size which is made on run time */
281         char optional_id[PKG_NAME_STRING_LEN_MAX]; /*package ID if exists */
282         void *pkg_optional_info;
283         char label[PKG_LABEL_STRING_LEN_MAX];
284         char author[PKG_VALUE_STRING_LEN_MAX];
285         char *icon_buf;
286         int icon_size;
287         GList *privilege_list;
288         GList *dependency_list;
289 } package_manager_pkg_detail_info_t;
290
291 typedef void (*_pkg_plugin_unload)(void);
292 typedef int (*_pkg_plugin_pkg_is_installed) (const char *pkgid);
293 typedef int (*_pkg_plugin_get_installed_pkg_list)(
294                 const char *category, const char *option,
295                 package_manager_pkg_info_t **list, int *count);
296 typedef int (*_pkg_plugin_get_pkg_detail_info)(const char *pkgid,
297                 package_manager_pkg_detail_info_t *pkg_detail_info);
298 typedef int (*_pkg_plugin_get_pkg_detail_info_from_package)(
299                 const char *pkg_path,
300                 package_manager_pkg_detail_info_t *pkg_detail_info);
301
302 typedef struct _pkg_plugin_set {
303         char pkg_type[PKG_TYPE_STRING_LEN_MAX];
304         void *plugin_handle;
305         _pkg_plugin_unload plugin_on_unload;
306         _pkg_plugin_pkg_is_installed pkg_is_installed;
307         _pkg_plugin_get_installed_pkg_list get_installed_pkg_list;
308         _pkg_plugin_get_pkg_detail_info get_pkg_detail_info;
309         _pkg_plugin_get_pkg_detail_info_from_package
310         get_pkg_detail_info_from_package;
311 } pkg_plugin_set;
312
313 pkgmgrinfo_pkginfo_filter_prop_str _pminfo_pkginfo_convert_to_prop_str(const char *property);
314 pkgmgrinfo_pkginfo_filter_prop_int _pminfo_pkginfo_convert_to_prop_int(const char *property);
315 pkgmgrinfo_pkginfo_filter_prop_bool _pminfo_pkginfo_convert_to_prop_bool(const char *property);
316
317 pkgmgrinfo_appinfo_filter_prop_str _pminfo_appinfo_convert_to_prop_str(const char *property);
318 pkgmgrinfo_appinfo_filter_prop_int _pminfo_appinfo_convert_to_prop_int(const char *property);
319 pkgmgrinfo_appinfo_filter_prop_bool _pminfo_appinfo_convert_to_prop_bool(const char *property);
320
321 pkgmgrinfo_pkginfo_filter_prop_range _pminfo_pkginfo_convert_to_prop_range(const char *property);
322
323 int _check_create_cert_db(void);
324 void _save_column_int(sqlite3_stmt *stmt, int idx, int *i);
325 void _save_column_str(sqlite3_stmt *stmt, int idx, char **str);
326 char *_get_system_locale(void);
327 int __get_filter_condition(gpointer data, uid_t uid, char **condition, GList **param);
328 int __get_metadata_filter_condition(gpointer data, char **condition, GList **param);
329 int _add_icon_info_into_list(const char *locale, char *value, GList **icon);
330 int _add_label_info_into_list(const char *locale, char *value, GList **label);
331 int __pkginfo_check_installed_storage(package_x *pkginfo);
332 int __appinfo_check_installed_storage(application_x *appinfo);
333 char *__get_type_from_path(const char *pkg_path);
334 pkg_plugin_set *__load_library(const char *pkg_type);
335 void __unload_library(const char *pkg_type);
336
337 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
338 #define REGULAR_USER 5000
339 static inline uid_t _getuid(void)
340 {
341         uid_t uid = getuid();
342
343         if (uid < REGULAR_USER)
344                 return tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
345         else
346                 return uid;
347 }
348
349 #ifdef __cplusplus
350 }
351 #endif
352
353 #endif  /* __PKGMGRINFO_PRIVATE_H__ */