Add pkgmgr_parser_process_* API to avoid parsing one more time
[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 #define DEFAULT_LOCALE          "No Locale"
54
55 #define PKG_PARSERLIB   "parserlib:"
56 #define PKG_PARSER_CONF_PATH    SYSCONFDIR "/package-manager/parser_path.conf"
57
58 #define PKG_STRING_LEN_MAX 1024
59
60 #define PKGMGR_PARSER_EMPTY_STR         ""
61 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
62
63 /**
64  * @brief API return values
65  */
66 enum {
67         PM_PARSER_R_EINVAL = -2,                /**< Invalid argument */
68         PM_PARSER_R_ERROR = -1,         /**< General error */
69         PM_PARSER_R_OK = 0                      /**< General success */
70 };
71
72 /**
73  * @brief Preload application type
74  */
75 enum {
76         PM_PRELOAD_NONE,                        /**< not preload */
77         PM_PRELOAD_RW_NORM,                     /**< not removable */
78         PM_PRELOAD_RW_RM                        /**< removable */
79 };
80
81 /**
82  * @fn int pkgmgr_parser_preload_package_type(const char *package)
83  * @brief       This API gets type of preload that package is expected to be
84  *
85  * @par         This API is for package-manager installer backends.
86  *
87  * @param[in]   package pointer to package ID
88  * @return      PM_PRELOAD defining what type of preload package it should be, -1 on failure
89  */
90 int pkgmgr_parser_preload_package_type(const char *package);
91
92 /**
93  * @fn char *pkgmgr_parser_get_manifest_file(const char *pkgid)
94  * @brief       This API gets the manifest file of the package.
95  *
96  * @par         This API is for package-manager installer backends.
97  * @par Sync (or) Async : Synchronous API
98  *
99  * @param[in]   pkgid   pointer to package ID
100  * @return      manifest file path on success, NULL on failure
101  * @pre         None
102  * @post                Free the manifest file pointer that is returned by API
103  * @code
104 static int get_manifest_file(const char *pkgid)
105 {
106         char *manifest = NULL;
107         manifest = pkgmgr_parser_get_manifest_file(pkgid);
108         if (manifest == NULL)
109                 return -1;
110         printf("Manifest File Path is %s\n", manifest);
111         free(manifest);
112         return 0;
113 }
114  * @endcode
115  */
116 char *pkgmgr_parser_get_manifest_file(const char *pkgid);
117 char *pkgmgr_parser_get_usr_manifest_file(const char *pkgid, uid_t uid);
118
119 /**
120  * @fn int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[])
121  * @fn int pkgmgr_parser_parse_usr_manifest_for_installation(const char *manifest, uid_t uid, char *const tagv[])
122  * @brief       This API parses the manifest file of the package after installation and stores the data in DB.
123  *
124  * @par         This API is for package-manager installer backends.
125  * @par Sync (or) Async : Synchronous API
126  *
127  * @param[in]   manifest        pointer to package manifest file
128  * @param[in]   uid     the addressee user id of the instruction
129  * @param[in]   tagv            array of xml tags or NULL
130  * @return      0 if success, error code(<0) if fail
131  * @retval      PMINFO_R_OK     success
132  * @retval      PMINFO_R_EINVAL invalid argument
133  * @retval      PMINFO_R_ERROR  internal error
134  * @pre         None
135  * @post                None
136  * @code
137 static int parse_manifest_file_for_installation(const char *manifest)
138 {
139         int ret = 0;
140         ret = pkgmgr_parser_parse_manifest_for_installation(manifest, NULL);
141         if (ret)
142                 return -1;
143         return 0;
144 }
145  * @endcode
146  */
147 int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[]);
148 int pkgmgr_parser_parse_usr_manifest_for_installation(const char *manifest, uid_t uid, char *const tagv[]);
149 int pkgmgr_parser_process_manifest_x_for_installation(manifest_x* mfx, const char *manifest);
150 int pkgmgr_parser_process_usr_manifest_x_for_installation(manifest_x* mfx, const char *manifest, uid_t uid);
151
152 /**
153  * @fn int pkgmgr_parser_update_tep(const char* pkgid, const char * tep_path)
154  * @fn int pkgmgr_parser_usr_update_tep(const char* pkgid, const char* tep_path, uid_t uid)
155  * @brief       This API updates tep path information stored in DB.
156  *
157  * @par         This API is for package-manager installer backends.
158  * @par Sync (or) Async : Synchronous API
159  *
160  * @param[in]   pkgid   pointer to package ID
161   * @param[in]tep_path  pointer to path of TEP file
162  * @param[in]   uid     the addressee user id of the instruction
163  * @return      0 if success, error code(<0) if fail
164  * @retval      PMINFO_R_OK     success
165  * @retval      PMINFO_R_EINVAL invalid argument
166  * @retval      PMINFO_R_ERROR  internal error
167  * @pre         None
168  * @post                None
169  * @code
170 static int update_tep_info_for_upgrade(const char *pkgid, const char *tep_path)
171 {
172         int ret = 0;
173         ret = pkgmgr_parser_update_tep(pkgid, tep_path);
174         if (ret)
175                 return -1;
176         return 0;
177 }
178  * @endcode
179  */
180 int pkgmgr_parser_update_tep(const char* pkgid, const char* tep_path);
181 int pkgmgr_parser_usr_update_tep(const char* pkgid, const char* tep_path, uid_t uid);
182
183 /**
184  * @fn int pkgmgr_parser_parse_usr_manifest_for_upgrade(const char *manifest,  uid_t uid, char *const tagv[])
185  * @fn int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[])
186  * @brief       This API parses the manifest file of the package after upgrade and stores the data in DB.
187  *
188  * @par         This API is for package-manager installer backends.
189  * @par Sync (or) Async : Synchronous API
190  *
191  * @param[in]   manifest        pointer to package manifest file
192  * @param[in]   uid     the addressee user id of the instruction
193  * @param[in]   tagv            array of xml tags or NULL
194  * @return      0 if success, error code(<0) if fail
195  * @retval      PMINFO_R_OK     success
196  * @retval      PMINFO_R_EINVAL invalid argument
197  * @retval      PMINFO_R_ERROR  internal error
198  * @pre         None
199  * @post                None
200  * @code
201 static int parse_manifest_file_for_upgrade(const char *manifest)
202 {
203         int ret = 0;
204         ret = pkgmgr_parser_parse_manifest_for_upgrade(manifest, NULL);
205         if (ret)
206                 return -1;
207         return 0;
208 }
209  * @endcode
210  */
211 int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[]);
212 int pkgmgr_parser_parse_usr_manifest_for_upgrade(const char *manifest, uid_t uid, char *const tagv[]);
213 int pkgmgr_parser_process_manifest_x_for_upgrade(manifest_x* mfx, const char *manifest);
214 int pkgmgr_parser_process_usr_manifest_x_for_upgrade(manifest_x* mfx, const char *manifest, uid_t uid);
215
216 /**
217  * @fn int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[])
218  * @fn int pkgmgr_parser_parse_usr_manifest_for_uninstallation(const char *manifest, uid_t uid, char *const tagv[])
219  * @brief       This API parses the manifest file of the package after uninstallation and deletes the data from DB.
220  *
221  * @par         This API is for package-manager installer backends.
222  * @par Sync (or) Async : Synchronous API
223  *
224  * @param[in]   manifest        pointer to package manifest file
225  * @param[in]   uid     the addressee user id of the instruction
226  * @param[in]   tagv            array of xml tags or NULL
227  * @return      0 if success, error code(<0) if fail
228  * @retval      PMINFO_R_OK     success
229  * @retval      PMINFO_R_EINVAL invalid argument
230  * @retval      PMINFO_R_ERROR  internal error
231  * @pre         None
232  * @post                None
233  * @code
234 static int parse_manifest_file_for_uninstallation(const char *manifest)
235 {
236         int ret = 0;
237         ret = pkgmgr_parser_parse_manifest_for_uninstallation(manifest, NULL);
238         if (ret)
239                 return -1;
240         return 0;
241 }
242  * @endcode
243  */
244 int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[]);
245 int pkgmgr_parser_parse_usr_manifest_for_uninstallation(const char *manifest, uid_t uid, char *const tagv[]);
246 int pkgmgr_parser_process_manifest_x_for_uninstallation(manifest_x* mfx, const char *manifest);
247 int pkgmgr_parser_process_usr_manifest_x_for_uninstallation(manifest_x* mfx, const char *manifest, uid_t uid);
248
249 /**
250  * @fn int pkgmgr_parser_parse_manifest_for_preload()
251  * @fn int pkgmgr_parser_parse_usr_manifest_for_preload(uid_t uid)
252  * @brief       This API update  preload information to DB.
253  *
254  * @par         This API is for package-manager installer backends.
255  * @par Sync (or) Async : Synchronous API
256  *
257  * @return      0 if success, error code(<0) if fail
258  * @retval      PMINFO_R_OK     success
259  * @retval      PMINFO_R_EINVAL invalid argument
260  * @retval      PMINFO_R_ERROR  internal error
261  * @pre         None
262  * @post                None
263  * @code
264 static int parser_parse_manifest_for_preload()
265 {
266         int ret = 0;
267         ret = pkgmgr_parser_parse_manifest_for_preload();
268         if (ret)
269                 return -1;
270         return 0;
271 }
272  * @endcode
273  */
274 int pkgmgr_parser_parse_manifest_for_preload();
275 int pkgmgr_parser_parse_usr_manifest_for_preload(uid_t uid);
276
277 /**
278  * @fn int pkgmgr_parser_check_manifest_validation(const char *manifest)
279  * @brief       This API validates the manifest file against the manifest schema.
280  *
281  * @par         This API is for package-manager installer backends.
282  * @par Sync (or) Async : Synchronous API
283  *
284  * @param[in]   manifest        pointer to package manifest file
285  * @return      0 if success, error code(<0) if fail
286  * @retval      PMINFO_R_OK     success
287  * @retval      PMINFO_R_EINVAL invalid argument
288  * @retval      PMINFO_R_ERROR  internal error
289  * @pre         None
290  * @post                None
291  * @code
292 static int validate_manifest_file(const char *manifest)
293 {
294         int ret = 0;
295         ret = pkgmgr_parser_check_manifest_validation(manifest);
296         if (ret)
297                 return -1;
298         return 0;
299 }
300  * @endcode
301  */
302 int pkgmgr_parser_check_manifest_validation(const char *manifest);
303
304 /**
305  * @fn void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
306  * @brief       This API will free the manifest pointer by recursively freeing all sub elements.
307  *
308  * @par         This API is for package-manager installer backends.
309  * @par Sync (or) Async : Synchronous API
310  *
311  * @param[in]   mfx     pointer to parsed manifest data
312  * @pre         pkgmgr_parser_process_manifest_xml()
313  * @post                None
314  * @code
315 static int parse_manifest_file(const char *manifest)
316 {
317         manifest_x *mfx = NULL
318         mfx = pkgmgr_parser_process_manifest_xml(manifest);
319         if (mfx == NULL)
320                 return -1;
321         printf("Parsing Manifest Success\n");
322         pkgmgr_parser_free_manifest_xml(mfx);
323         return 0;
324 }
325  * @endcode
326  */
327 void pkgmgr_parser_free_manifest_xml(manifest_x *mfx);
328
329 /**
330  * @fn manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest)
331  * @fn manifest_x *pkgmgr_parser_usr_process_manifest_xml(const char *manifest, uid_t uid)
332  * @brief       This API parses the manifest file and stores all the data in the manifest structure.
333  *
334  * @par         This API is for package-manager installer backends.
335  * @par Sync (or) Async : Synchronous API
336  *
337  * @param[in]   manifest        pointer to package manifest file
338  * @param[in]   uid     the addressee user id of the instruction
339  * @return      manifest pointer on success, NULL on failure
340  * @pre         None
341  * @post                pkgmgr_parser_free_manifest_xml()
342  * @code
343 static int parse_manifest_file(const char *manifest)
344 {
345         manifest_x *mfx = NULL
346         mfx = pkgmgr_parser_process_manifest_xml(manifest);
347         if (mfx == NULL)
348                 return -1;
349         printf("Parsing Manifest Success\n");
350         pkgmgr_parser_free_manifest_xml(mfx);
351         return 0;
352 }
353  * @endcode
354  */
355 manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest);
356 manifest_x *pkgmgr_parser_usr_process_manifest_xml(const char *manifest, uid_t uid);
357
358 /**
359  * @fn int pkgmgr_parser_run_parser_for_installation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
360  * @brief       This API calls the parser directly by supplying the xml docptr. It is used during package installation
361  *
362  * @par         This API is for package-manager installer backends.
363  * @par Sync (or) Async : Synchronous API
364  *
365  * @param[in]   docPtr  XML doxument pointer
366  * @param[in]   tag             the xml tag corresponding to the parser that will parse the docPtr
367  * @param[in]   pkgid           the package id
368  * @return      0 if success, error code(<0) if fail
369  * @retval      PMINFO_R_OK     success
370  * @retval      PMINFO_R_EINVAL invalid argument
371  * @retval      PMINFO_R_ERROR  internal error
372  * @pre         None
373  * @post                None
374  * @code
375 static int parse_docptr_for_installation(xmlDocPtr docPtr)
376 {
377         int ret = 0;
378         ret = pkgmgr_parser_run_parser_for_installation(docPtr, "theme", "com.samsung.test");
379         if (ret)
380                 return -1;
381         return 0;
382 }
383  * @endcode
384  */
385 int pkgmgr_parser_run_parser_for_installation(xmlDocPtr docPtr, const char *tag, const char *pkgid);
386
387 /**
388  * @fn int pkgmgr_parser_run_parser_for_upgrade(xmlDocPtr docPtr, const char *tag, const char *pkgid)
389  * @brief       This API calls the parser directly by supplying the xml docptr. It is used during package upgrade
390  *
391  * @par         This API is for package-manager installer backends.
392  * @par Sync (or) Async : Synchronous API
393  *
394  * @param[in]   docPtr  XML doxument pointer
395  * @param[in]   tag             the xml tag corresponding to the parser that will parse the docPtr
396  * @param[in]   pkgid           the package id
397  * @return      0 if success, error code(<0) if fail
398  * @retval      PMINFO_R_OK     success
399  * @retval      PMINFO_R_EINVAL invalid argument
400  * @retval      PMINFO_R_ERROR  internal error
401  * @pre         None
402  * @post                None
403  * @code
404 static int parse_docptr_for_upgrade(xmlDocPtr docPtr)
405 {
406         int ret = 0;
407         ret = pkgmgr_parser_run_parser_for_upgrade(docPtr, "theme", "com.samsung.test");
408         if (ret)
409                 return -1;
410         return 0;
411 }
412  * @endcode
413  */
414 int pkgmgr_parser_run_parser_for_upgrade(xmlDocPtr docPtr, const char *tag, const char *pkgid);
415
416 /**
417  * @fn int pkgmgr_parser_run_parser_for_uninstallation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
418  * @brief       This API calls the parser directly by supplying the xml docptr. It is used during package uninstallation
419  *
420  * @par         This API is for package-manager installer backends.
421  * @par Sync (or) Async : Synchronous API
422  *
423  * @param[in]   docPtr  XML doxument pointer
424  * @param[in]   tag             the xml tag corresponding to the parser that will parse the docPtr
425  * @param[in]   pkgid           the package id
426  * @return      0 if success, error code(<0) if fail
427  * @retval      PMINFO_R_OK     success
428  * @retval      PMINFO_R_EINVAL invalid argument
429  * @retval      PMINFO_R_ERROR  internal error
430  * @pre         None
431  * @post                None
432  * @code
433 static int parse_docptr_for_uninstallation(xmlDocPtr docPtr)
434 {
435         int ret = 0;
436         ret = pkgmgr_parser_run_parser_for_uninstallation(docPtr, "theme", "com.samsung.test");
437         if (ret)
438                 return -1;
439         return 0;
440 }
441  * @endcode
442  */
443 int pkgmgr_parser_run_parser_for_uninstallation(xmlDocPtr docPtr, const char *tag, const char *pkgid);
444
445
446
447 /**
448  * @fn int pkgmgr_parser_create_desktop_file(manifest_x *mfx)
449  * @fn int pkgmgr_parser_create_usr_desktop_file(manifest_x *mfx, uid_t uid)
450  * @brief       This API generates the application desktop file
451  *
452  * @par         This API is for package-manager installer backends.
453  * @par Sync (or) Async : Synchronous API
454  *
455  * @param[in]   mfx     manifest pointer
456  * @param[in]   uid     the addressee user id of the instruction
457  * @return      0 if success, error code(<0) if fail
458  * @retval      PMINFO_R_OK     success
459  * @retval      PMINFO_R_EINVAL invalid argument
460  * @retval      PMINFO_R_ERROR  internal error
461  * @pre         pkgmgr_parser_process_manifest_xml()
462  * @post        pkgmgr_parser_free_manifest_xml()
463  * @code
464 static int create_desktop_file(char *manifest)
465 {
466         int ret = 0;
467         manifest_x *mfx = NULL;
468         mfx = pkgmgr_parser_process_manifest_xml(manifest);
469         ret = pkgmgr_parser_create_desktop_file(mfx);
470         if (ret)
471                 return -1;
472         pkgmgr_parser_free_manifest_xml(mfx);
473         return 0;
474 }
475  * @endcode
476  */
477 int pkgmgr_parser_create_desktop_file(manifest_x *mfx);
478 int pkgmgr_parser_create_usr_desktop_file(manifest_x *mfx, uid_t uid);
479
480 /** @} */
481 #ifdef __cplusplus
482 }
483 #endif
484 #endif                          /* __PKGMGR_PARSER_H__ */