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