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