c2d2ee4d226690e66e36d357a3219f69af153335
[platform/core/appfw/pkgmgr-info.git] / parser / pkgmgr_parser.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 #ifndef __PKGMGR_PARSER_H__
24 #define __PKGMGR_PARSER_H__
25
26 /**
27  * @file pkgmgr_parser.h
28  * @author Sewook Park <sewook7.park@samsung.com>
29  * @author Shobhit Srivastava <shobhit.s@samsung.com>
30  * @version 0.1
31  * @brief    This file declares API of pkgmgr_parser
32  * @addtogroup          APPLICATION_FRAMEWORK
33  * @{
34  *
35  * @defgroup            PackageManagerParser
36  * @section             Header Header file to include:
37  * @code
38  * #include             <pkgmgr_parser.h>
39  * @endcode
40  *
41  * @}
42  */
43
44 #include <libxml/xmlreader.h>
45
46 /* For multi-user support */
47 #include <tzplatform_config.h>
48 #include "pkgmgrinfo_basic.h"
49
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53
54 #ifndef DEPRECATED
55 #define DEPRECATED      __attribute__ ((__deprecated__))
56 #endif
57
58 #define DEFAULT_LOCALE          "No Locale"
59
60 #define PKG_PARSERLIB   "parserlib:"
61 #define PKG_PARSER_CONF_PATH    SYSCONFDIR "/package-manager/parser_path.conf"
62
63 #define PKG_STRING_LEN_MAX 1024
64
65 #define PKGMGR_PARSER_EMPTY_STR         ""
66 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
67
68 /**
69  * @brief Structure which is used by metadata plugin
70  */
71 typedef struct {
72         const char *key;
73         const char *value;
74 } __metadata_t;
75
76
77 /**
78  * @brief Structure which is used by category plugin
79  */
80 typedef struct {
81         const char *name;
82 } __category_t;
83
84 /* operation_type */
85 typedef enum {
86         ACTION_INSTALL = 0,
87         ACTION_UPGRADE,
88         ACTION_UNINSTALL,
89         ACTION_FOTA,
90         ACTION_MAX
91 } ACTION_TYPE;
92
93 /**
94  * @brief API return values
95  */
96 enum {
97         PM_PARSER_R_EINVAL = -2,                /**< Invalid argument */
98         PM_PARSER_R_ERROR = -1,         /**< General error */
99         PM_PARSER_R_OK = 0                      /**< General success */
100 };
101
102 /**
103  * @fn int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[])
104  * @fn int pkgmgr_parser_parse_usr_manifest_for_installation(const char *manifest, uid_t uid, char *const tagv[])
105  * @brief       This API parses the manifest file of the package after installation and stores the data in DB.
106  *
107  * @par         This API is for package-manager installer backends.
108  * @par Sync (or) Async : Synchronous API
109  *
110  * @param[in]   manifest        pointer to package manifest file
111  * @param[in]   uid     the addressee user id of the instruction
112  * @param[in]   tagv            array of xml tags or NULL
113  * @return      0 if success, error code(<0) if fail
114  * @retval      PMINFO_R_OK     success
115  * @retval      PMINFO_R_EINVAL invalid argument
116  * @retval      PMINFO_R_ERROR  internal error
117  * @pre         None
118  * @post                None
119  * @code
120 static int parse_manifest_file_for_installation(const char *manifest)
121 {
122         int ret = 0;
123         ret = pkgmgr_parser_parse_manifest_for_installation(manifest, NULL);
124         if (ret)
125                 return -1;
126         return 0;
127 }
128  * @endcode
129  */
130 int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[]) DEPRECATED;
131 int pkgmgr_parser_parse_usr_manifest_for_installation(const char *manifest, uid_t uid, char *const tagv[]) DEPRECATED;
132 int pkgmgr_parser_process_manifest_x_for_installation(manifest_x* mfx, const char *manifest);
133 int pkgmgr_parser_process_usr_manifest_x_for_installation(manifest_x* mfx, const char *manifest, uid_t uid);
134
135 /**
136  * @fn int pkgmgr_parser_update_tep(const char* pkgid, const char * tep_path)
137  * @fn int pkgmgr_parser_usr_update_tep(const char* pkgid, const char* tep_path, uid_t uid)
138  * @brief       This API updates tep path information stored in DB.
139  *
140  * @par         This API is for package-manager installer backends.
141  * @par Sync (or) Async : Synchronous API
142  *
143  * @param[in]   pkgid   pointer to package ID
144   * @param[in]tep_path  pointer to path of TEP file
145  * @param[in]   uid     the addressee user id of the instruction
146  * @return      0 if success, error code(<0) if fail
147  * @retval      PMINFO_R_OK     success
148  * @retval      PMINFO_R_EINVAL invalid argument
149  * @retval      PMINFO_R_ERROR  internal error
150  * @pre         None
151  * @post                None
152  * @code
153 static int update_tep_info_for_upgrade(const char *pkgid, const char *tep_path)
154 {
155         int ret = 0;
156         ret = pkgmgr_parser_update_tep(pkgid, tep_path);
157         if (ret)
158                 return -1;
159         return 0;
160 }
161  * @endcode
162  */
163 int pkgmgr_parser_update_tep(const char* pkgid, const char* tep_path);
164 int pkgmgr_parser_usr_update_tep(const char* pkgid, const char* tep_path, uid_t uid);
165
166 /**
167  * @fn int pkgmgr_parser_parse_usr_manifest_for_upgrade(const char *manifest,  uid_t uid, char *const tagv[])
168  * @fn int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[])
169  * @brief       This API parses the manifest file of the package after upgrade and stores the data in DB.
170  *
171  * @par         This API is for package-manager installer backends.
172  * @par Sync (or) Async : Synchronous API
173  *
174  * @param[in]   manifest        pointer to package manifest file
175  * @param[in]   uid     the addressee user id of the instruction
176  * @param[in]   tagv            array of xml tags or NULL
177  * @return      0 if success, error code(<0) if fail
178  * @retval      PMINFO_R_OK     success
179  * @retval      PMINFO_R_EINVAL invalid argument
180  * @retval      PMINFO_R_ERROR  internal error
181  * @pre         None
182  * @post                None
183  * @code
184 static int parse_manifest_file_for_upgrade(const char *manifest)
185 {
186         int ret = 0;
187         ret = pkgmgr_parser_parse_manifest_for_upgrade(manifest, NULL);
188         if (ret)
189                 return -1;
190         return 0;
191 }
192  * @endcode
193  */
194 int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[]) DEPRECATED;
195 int pkgmgr_parser_parse_usr_manifest_for_upgrade(const char *manifest, uid_t uid, char *const tagv[]) DEPRECATED;
196 int pkgmgr_parser_process_manifest_x_for_upgrade(manifest_x* mfx, const char *manifest);
197 int pkgmgr_parser_process_usr_manifest_x_for_upgrade(manifest_x* mfx, const char *manifest, uid_t uid);
198
199 /**
200  * @fn int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[])
201  * @fn int pkgmgr_parser_parse_usr_manifest_for_uninstallation(const char *manifest, uid_t uid, char *const tagv[])
202  * @brief       This API parses the manifest file of the package after uninstallation and deletes the data from DB.
203  *
204  * @par         This API is for package-manager installer backends.
205  * @par Sync (or) Async : Synchronous API
206  *
207  * @param[in]   manifest        pointer to package manifest file
208  * @param[in]   uid     the addressee user id of the instruction
209  * @param[in]   tagv            array of xml tags or NULL
210  * @return      0 if success, error code(<0) if fail
211  * @retval      PMINFO_R_OK     success
212  * @retval      PMINFO_R_EINVAL invalid argument
213  * @retval      PMINFO_R_ERROR  internal error
214  * @pre         None
215  * @post                None
216  * @code
217 static int parse_manifest_file_for_uninstallation(const char *manifest)
218 {
219         int ret = 0;
220         ret = pkgmgr_parser_parse_manifest_for_uninstallation(manifest, NULL);
221         if (ret)
222                 return -1;
223         return 0;
224 }
225  * @endcode
226  */
227 int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[]) DEPRECATED;
228 int pkgmgr_parser_parse_usr_manifest_for_uninstallation(const char *manifest, uid_t uid, char *const tagv[]) DEPRECATED;
229 int pkgmgr_parser_process_manifest_x_for_uninstallation(manifest_x* mfx, const char *manifest);
230 int pkgmgr_parser_process_usr_manifest_x_for_uninstallation(manifest_x* mfx, const char *manifest, uid_t uid);
231
232 /**
233  * @fn int pkgmgr_parser_check_manifest_validation(const char *manifest)
234  * @brief       This API validates the manifest file against the manifest schema.
235  *
236  * @par         This API is for package-manager installer backends.
237  * @par Sync (or) Async : Synchronous API
238  *
239  * @param[in]   manifest        pointer to package manifest file
240  * @return      0 if success, error code(<0) if fail
241  * @retval      PMINFO_R_OK     success
242  * @retval      PMINFO_R_EINVAL invalid argument
243  * @retval      PMINFO_R_ERROR  internal error
244  * @pre         None
245  * @post                None
246  * @code
247 static int validate_manifest_file(const char *manifest)
248 {
249         int ret = 0;
250         ret = pkgmgr_parser_check_manifest_validation(manifest);
251         if (ret)
252                 return -1;
253         return 0;
254 }
255  * @endcode
256  */
257 int pkgmgr_parser_check_manifest_validation(const char *manifest);
258
259 /**
260  * @fn void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
261  * @brief       This API will free the manifest pointer by recursively freeing all sub elements.
262  *
263  * @par         This API is for package-manager installer backends.
264  * @par Sync (or) Async : Synchronous API
265  *
266  * @param[in]   mfx     pointer to parsed manifest data
267  * @pre         pkgmgr_parser_process_manifest_xml()
268  * @post                None
269  * @code
270 static int parse_manifest_file(const char *manifest)
271 {
272         manifest_x *mfx = NULL
273         mfx = pkgmgr_parser_process_manifest_xml(manifest);
274         if (mfx == NULL)
275                 return -1;
276         printf("Parsing Manifest Success\n");
277         pkgmgr_parser_free_manifest_xml(mfx);
278         return 0;
279 }
280  * @endcode
281  */
282 void pkgmgr_parser_free_manifest_xml(manifest_x *mfx);
283
284 /**
285  * @fn manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest)
286  * @fn manifest_x *pkgmgr_parser_usr_process_manifest_xml(const char *manifest, uid_t uid)
287  * @brief       This API parses the manifest file and stores all the data in the manifest structure.
288  *
289  * @par         This API is for package-manager installer backends.
290  * @par Sync (or) Async : Synchronous API
291  *
292  * @param[in]   manifest        pointer to package manifest file
293  * @param[in]   uid     the addressee user id of the instruction
294  * @return      manifest pointer on success, NULL on failure
295  * @pre         None
296  * @post                pkgmgr_parser_free_manifest_xml()
297  * @code
298 static int parse_manifest_file(const char *manifest)
299 {
300         manifest_x *mfx = NULL
301         mfx = pkgmgr_parser_process_manifest_xml(manifest);
302         if (mfx == NULL)
303                 return -1;
304         printf("Parsing Manifest Success\n");
305         pkgmgr_parser_free_manifest_xml(mfx);
306         return 0;
307 }
308  * @endcode
309  */
310 manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest) DEPRECATED;
311 manifest_x *pkgmgr_parser_usr_process_manifest_xml(const char *manifest, uid_t uid) DEPRECATED;
312
313 /** @} */
314 #ifdef __cplusplus
315 }
316 #endif
317 #endif                          /* __PKGMGR_PARSER_H__ */