tizen 2.3.1 release
[framework/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 #include "pkgmgrinfo_basic.h"
46 #include "pkgmgr_parser_feature.h"
47
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51
52 /* defined path and file*/
53 #define DESKTOP_RW_PATH "/opt/share/applications/"
54 #define DESKTOP_RO_PATH "/usr/share/applications/"
55 #define MANIFEST_RO_PREFIX "/usr/share/packages/"
56 #define MANIFEST_RW_PREFIX "/opt/share/packages/"
57
58 #define SCHEMA_FILE "/usr/etc/package-manager/preload/manifest.xsd"
59
60 #define BUFMAX 1024*128
61
62 /* so path */
63 #define LIBAPPSVC_PATH "/usr/lib/libappsvc.so.0"
64 #define LIBAIL_PATH "/usr/lib/libail.so.0"
65
66 /** Integer property for mode*/
67 #define PMINFO_SUPPORT_MODE_ULTRA_POWER_SAVING  0x00000001
68 #define PMINFO_SUPPORT_MODE_COOL_DOWN                   0x00000002
69 #define PMINFO_SUPPORT_MODE_SCREEN_READER               0x00000004
70
71 #define PMINFO_SUPPORT_FEATURE_MULTI_WINDOW                     0x00000001
72 #define PMINFO_SUPPORT_FEATURE_OOM_TERMINATION          0x00000002
73 #define PMINFO_SUPPORT_FEATURE_LARGE_MEMORY                     0x00000004
74
75 /* operation_type */
76 typedef enum {
77         ACTION_INSTALL = 0,
78         ACTION_UPGRADE,
79         ACTION_UNINSTALL,
80         ACTION_FOTA,
81         ACTION_MAX
82 } ACTION_TYPE;
83
84 typedef enum {
85         AIL_INSTALL = 0,
86         AIL_UPDATE,
87         AIL_REMOVE,
88         AIL_CLEAN,
89         AIL_FOTA,
90         AIL_MAX
91 } AIL_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 char *pkgmgr_parser_get_manifest_file(const char *pkgid)
104  * @brief       This API gets the manifest file of the package.
105  *
106  * @par         This API is for package-manager installer backends.
107  * @par Sync (or) Async : Synchronous API
108  *
109  * @param[in]   pkgid   pointer to package ID
110  * @return      manifest file path on success, NULL on failure
111  * @pre         None
112  * @post                Free the manifest file pointer that is returned by API
113  * @code
114 static int get_manifest_file(const char *pkgid)
115 {
116         char *manifest = NULL;
117         manifest = pkgmgr_parser_get_manifest_file(pkgid);
118         if (manifest == NULL)
119                 return -1;
120         printf("Manifest File Path is %s\n", manifest);
121         free(manifest);
122         return 0;
123 }
124  * @endcode
125  */
126 char *pkgmgr_parser_get_manifest_file(const char *pkgid);
127
128 /**
129  * @fn int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[])
130  * @brief       This API parses the manifest file of the package after installation and stores the data in DB.
131  *
132  * @par         This API is for package-manager installer backends.
133  * @par Sync (or) Async : Synchronous API
134  *
135  * @param[in]   manifest        pointer to package manifest file
136  * @param[in]   tagv            array of xml tags or NULL
137  * @return      0 if success, error code(<0) if fail
138  * @retval      PMINFO_R_OK     success
139  * @retval      PMINFO_R_EINVAL invalid argument
140  * @retval      PMINFO_R_ERROR  internal error
141  * @pre         None
142  * @post                None
143  * @code
144 static int parse_manifest_file_for_installation(const char *manifest)
145 {
146         int ret = 0;
147         ret = pkgmgr_parser_parse_manifest_for_installation(manifest, NULL);
148         if (ret)
149                 return -1;
150         return 0;
151 }
152  * @endcode
153  */
154 int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[]);
155
156 /**
157  * @fn int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[])
158  * @brief       This API parses the manifest file of the package after upgrade and stores the data in DB.
159  *
160  * @par         This API is for package-manager installer backends.
161  * @par Sync (or) Async : Synchronous API
162  *
163  * @param[in]   manifest        pointer to package manifest file
164  * @param[in]   tagv            array of xml tags or NULL
165  * @return      0 if success, error code(<0) if fail
166  * @retval      PMINFO_R_OK     success
167  * @retval      PMINFO_R_EINVAL invalid argument
168  * @retval      PMINFO_R_ERROR  internal error
169  * @pre         None
170  * @post                None
171  * @code
172 static int parse_manifest_file_for_upgrade(const char *manifest)
173 {
174         int ret = 0;
175         ret = pkgmgr_parser_parse_manifest_for_upgrade(manifest, NULL);
176         if (ret)
177                 return -1;
178         return 0;
179 }
180  * @endcode
181  */
182 int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[]);
183
184 /**
185  * @fn int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[])
186  * @brief       This API parses the manifest file of the package after uninstallation and deletes the data from 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]   tagv            array of xml tags or NULL
193  * @return      0 if success, error code(<0) if fail
194  * @retval      PMINFO_R_OK     success
195  * @retval      PMINFO_R_EINVAL invalid argument
196  * @retval      PMINFO_R_ERROR  internal error
197  * @pre         None
198  * @post                None
199  * @code
200 static int parse_manifest_file_for_uninstallation(const char *manifest)
201 {
202         int ret = 0;
203         ret = pkgmgr_parser_parse_manifest_for_uninstallation(manifest, NULL);
204         if (ret)
205                 return -1;
206         return 0;
207 }
208  * @endcode
209  */
210 int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[]);
211
212 /**
213  * @fn int pkgmgr_parser_parse_manifest_for_preload()
214  * @brief       This API update  preload information to DB.
215  *
216  * @par         This API is for package-manager installer backends.
217  * @par Sync (or) Async : Synchronous API
218  *
219  * @return      0 if success, error code(<0) if fail
220  * @retval      PMINFO_R_OK     success
221  * @retval      PMINFO_R_EINVAL invalid argument
222  * @retval      PMINFO_R_ERROR  internal error
223  * @pre         None
224  * @post                None
225  * @code
226 static int parser_parse_manifest_for_preload()
227 {
228         int ret = 0;
229         ret = pkgmgr_parser_parse_manifest_for_preload();
230         if (ret)
231                 return -1;
232         return 0;
233 }
234  * @endcode
235  */
236 int pkgmgr_parser_parse_manifest_for_preload();
237
238 /**
239  * @fn int pkgmgr_parser_check_manifest_validation(const char *manifest)
240  * @brief       This API validates the manifest file against the manifest schema.
241  *
242  * @par         This API is for package-manager installer backends.
243  * @par Sync (or) Async : Synchronous API
244  *
245  * @param[in]   manifest        pointer to package manifest file
246  * @return      0 if success, error code(<0) if fail
247  * @retval      PMINFO_R_OK     success
248  * @retval      PMINFO_R_EINVAL invalid argument
249  * @retval      PMINFO_R_ERROR  internal error
250  * @pre         None
251  * @post                None
252  * @code
253 static int validate_manifest_file(const char *manifest)
254 {
255         int ret = 0;
256         ret = pkgmgr_parser_check_manifest_validation(manifest);
257         if (ret)
258                 return -1;
259         return 0;
260 }
261  * @endcode
262  */
263 int pkgmgr_parser_check_manifest_validation(const char *manifest);
264
265 /**
266  * @fn void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
267  * @brief       This API will free the manifest pointer by recursively freeing all sub elements.
268  *
269  * @par         This API is for package-manager installer backends.
270  * @par Sync (or) Async : Synchronous API
271  *
272  * @param[in]   mfx     pointer to parsed manifest data
273  * @pre         pkgmgr_parser_process_manifest_xml()
274  * @post                None
275  * @code
276 static int parse_manifest_file(const char *manifest)
277 {
278         manifest_x *mfx = NULL
279         mfx = pkgmgr_parser_process_manifest_xml(manifest);
280         if (mfx == NULL)
281                 return -1;
282         printf("Parsing Manifest Success\n");
283         pkgmgr_parser_free_manifest_xml(mfx);
284         return 0;
285 }
286  * @endcode
287  */
288 void pkgmgr_parser_free_manifest_xml(manifest_x *mfx);
289
290 /**
291  * @fn manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest)
292  * @brief       This API parses the manifest file and stores all the data in the manifest structure.
293  *
294  * @par         This API is for package-manager installer backends.
295  * @par Sync (or) Async : Synchronous API
296  *
297  * @param[in]   manifest        pointer to package manifest file
298  * @return      manifest pointer on success, NULL on failure
299  * @pre         None
300  * @post                pkgmgr_parser_free_manifest_xml()
301  * @code
302 static int parse_manifest_file(const char *manifest)
303 {
304         manifest_x *mfx = NULL
305         mfx = pkgmgr_parser_process_manifest_xml(manifest);
306         if (mfx == NULL)
307                 return -1;
308         printf("Parsing Manifest Success\n");
309         pkgmgr_parser_free_manifest_xml(mfx);
310         return 0;
311 }
312  * @endcode
313  */
314 manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest);
315
316 /**
317  * @fn manifest_x *pkgmgr_parser_get_manifest_info(const char *pkigid)
318  * @brief       This API gets the manifest info from DB and stores all the data in the manifest structure.
319  *
320  * @par         This API is for package-manager installer backends.
321  * @par Sync (or) Async : Synchronous API
322  *
323  * @param[in]   pkgid   package id for package
324  * @return      manifest pointer on success, NULL on failure
325  * @pre         None
326  * @post                pkgmgr_parser_free_manifest_xml()
327  * @code
328 static int get_manifest_info(const char *pkgid)
329 {
330         manifest_x *mfx = NULL
331         mfx = pkgmgr_parser_get_manifest_info(pkgid);
332         if (mfx == NULL)
333                 return -1;
334         printf("Parsing Manifest Success\n");
335         pkgmgr_parser_free_manifest_xml(mfx);
336         return 0;
337 }
338  * @endcode
339  */
340 manifest_x *pkgmgr_parser_get_manifest_info(const char *pkigid);
341
342 /* These APIs are intended to call parser directly */
343 typedef int (*ps_iter_fn) (const char *tag, int type, void *userdata);
344
345 int pkgmgr_parser_has_parser(const char *tag, int *type);
346 int pkgmgr_parser_get_list(ps_iter_fn iter_fn, void *data);
347
348 /**
349  * @fn int pkgmgr_parser_run_parser_for_installation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
350  * @brief       This API calls the parser directly by supplying the xml docptr. It is used during package installation
351  *
352  * @par         This API is for package-manager installer backends.
353  * @par Sync (or) Async : Synchronous API
354  *
355  * @param[in]   docPtr  XML doxument pointer
356  * @param[in]   tag             the xml tag corresponding to the parser that will parse the docPtr
357  * @param[in]   pkgid           the package id
358  * @return      0 if success, error code(<0) if fail
359  * @retval      PMINFO_R_OK     success
360  * @retval      PMINFO_R_EINVAL invalid argument
361  * @retval      PMINFO_R_ERROR  internal error
362  * @pre         None
363  * @post                None
364  * @code
365 static int parse_docptr_for_installation(xmlDocPtr docPtr)
366 {
367         int ret = 0;
368         ret = pkgmgr_parser_run_parser_for_installation(docPtr, "theme", "org.tizen.test");
369         if (ret)
370                 return -1;
371         return 0;
372 }
373  * @endcode
374  */
375 int pkgmgr_parser_run_parser_for_installation(xmlDocPtr docPtr, const char *tag, const char *pkgid);
376
377 /**
378  * @fn int pkgmgr_parser_run_parser_for_upgrade(xmlDocPtr docPtr, const char *tag, const char *pkgid)
379  * @brief       This API calls the parser directly by supplying the xml docptr. It is used during package upgrade
380  *
381  * @par         This API is for package-manager installer backends.
382  * @par Sync (or) Async : Synchronous API
383  *
384  * @param[in]   docPtr  XML doxument pointer
385  * @param[in]   tag             the xml tag corresponding to the parser that will parse the docPtr
386  * @param[in]   pkgid           the package id
387  * @return      0 if success, error code(<0) if fail
388  * @retval      PMINFO_R_OK     success
389  * @retval      PMINFO_R_EINVAL invalid argument
390  * @retval      PMINFO_R_ERROR  internal error
391  * @pre         None
392  * @post                None
393  * @code
394 static int parse_docptr_for_upgrade(xmlDocPtr docPtr)
395 {
396         int ret = 0;
397         ret = pkgmgr_parser_run_parser_for_upgrade(docPtr, "theme", "org.tizen.test");
398         if (ret)
399                 return -1;
400         return 0;
401 }
402  * @endcode
403  */
404 int pkgmgr_parser_run_parser_for_upgrade(xmlDocPtr docPtr, const char *tag, const char *pkgid);
405
406 /**
407  * @fn int pkgmgr_parser_run_parser_for_uninstallation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
408  * @brief       This API calls the parser directly by supplying the xml docptr. It is used during package uninstallation
409  *
410  * @par         This API is for package-manager installer backends.
411  * @par Sync (or) Async : Synchronous API
412  *
413  * @param[in]   docPtr  XML doxument pointer
414  * @param[in]   tag             the xml tag corresponding to the parser that will parse the docPtr
415  * @param[in]   pkgid           the package id
416  * @return      0 if success, error code(<0) if fail
417  * @retval      PMINFO_R_OK     success
418  * @retval      PMINFO_R_EINVAL invalid argument
419  * @retval      PMINFO_R_ERROR  internal error
420  * @pre         None
421  * @post                None
422  * @code
423 static int parse_docptr_for_uninstallation(xmlDocPtr docPtr)
424 {
425         int ret = 0;
426         ret = pkgmgr_parser_run_parser_for_uninstallation(docPtr, "theme", "org.tizen.test");
427         if (ret)
428                 return -1;
429         return 0;
430 }
431  * @endcode
432  */
433 int pkgmgr_parser_run_parser_for_uninstallation(xmlDocPtr docPtr, const char *tag, const char *pkgid);
434
435
436
437 /**
438  * @fn int pkgmgr_parser_create_desktop_file(manifest_x *mfx)
439  * @brief       This API generates the application desktop file
440  *
441  * @par         This API is for package-manager installer backends.
442  * @par Sync (or) Async : Synchronous API
443  *
444  * @param[in]   mfx     manifest pointer
445  * @return      0 if success, error code(<0) if fail
446  * @retval      PMINFO_R_OK     success
447  * @retval      PMINFO_R_EINVAL invalid argument
448  * @retval      PMINFO_R_ERROR  internal error
449  * @pre         pkgmgr_parser_process_manifest_xml()
450  * @post        pkgmgr_parser_free_manifest_xml()
451  * @code
452 static int create_desktop_file(char *manifest)
453 {
454         int ret = 0;
455         manifest_x *mfx = NULL;
456         mfx = pkgmgr_parser_process_manifest_xml(manifest);
457         ret = pkgmgr_parser_create_desktop_file(mfx);
458         if (ret)
459                 return -1;
460         pkgmgr_parser_free_manifest_xml(mfx);
461         return 0;
462 }
463  * @endcode
464  */
465 int pkgmgr_parser_create_desktop_file(manifest_x *mfx);
466
467 /**
468  * @fn int pkgmgr_parser_enable_pkg(const char *pkgid, char *const tagv[])
469  * @brief       This API updates the data of the enabled package in DB.
470  *
471  * @par         This API is for package-manager.
472  * @par Sync (or) Async : Synchronous API
473  *
474  * @param[in]   pkgid   pointer to pkgid
475  * @param[in]   tagv            array of xml tags or NULL
476  * @return      0 if success, error code(<0) if fail
477  * @retval      PMINFO_R_OK     success
478  * @retval      PMINFO_R_EINVAL invalid argument
479  * @retval      PMINFO_R_ERROR  internal error
480  * @pre         None
481  * @post                None
482  * @code
483 static int parser_disabled_pkg_for_installation(const char *pkgid)
484 {
485         int ret = 0;
486         ret = pkgmgr_parser_enable_pkg(pkgid, NULL);
487         if (ret)
488                 return -1;
489         return 0;
490 }
491  * @endcode
492  */
493 int pkgmgr_parser_enable_pkg(const char *pkgid, char *const tagv[]);
494
495 /**
496  * @fn int pkgmgr_parser_disable_pkg(const char *pkgid, char *const tagv[])
497  * @brief       This API updates the data of the disabled package in DB.
498  *
499  * @par         This API is for package-manager.
500  * @par Sync (or) Async : Synchronous API
501  *
502  * @param[in]   pkgid   pointer to pkgid
503  * @param[in]   tagv            array of xml tags or NULL
504  * @return      0 if success, error code(<0) if fail
505  * @retval      PMINFO_R_OK     success
506  * @retval      PMINFO_R_EINVAL invalid argument
507  * @retval      PMINFO_R_ERROR  internal error
508  * @pre         None
509  * @post                None
510  * @code
511 static int parse_disabled_pkg_file_for_uninstallation(const char *pkgid)
512 {
513         int ret = 0;
514         ret = pkgmgr_parser_disable_pkg(pkgid, NULL);
515         if (ret)
516                 return -1;
517         return 0;
518 }
519  * @endcode
520  */
521 int pkgmgr_parser_disable_pkg(const char *pkgid, char *const tagv[]);
522
523 /**
524  * @fn int pkgmgr_parser_insert_app_aliasid(void)
525  * @brief       This API updates the app aliasid table.
526  *
527  * @par         This API is for pkg_initdb and pkg_fota.
528  * @par Sync (or) Async : Synchronous API
529  *
530  * @return      0 if success, error code(<0) if fail
531  * @retval      PMINFO_R_OK     success
532  * @retval      PMINFO_R_ERROR  internal error
533  * @pre         None
534  * @post                None
535  * @code
536 static int parse_insert_app_aliasid(void)
537 {
538         int ret = 0;
539         ret = pkgmgr_parser_insert_app_aliasid();
540         if (ret)
541                 return -1;
542         return 0;
543 }
544  * @endcode
545  */
546 int pkgmgr_parser_insert_app_aliasid(void );
547
548 /**
549  * @fn int pkgmgr_parser_update_app_aliasid(void)
550  * @brief       This API updates the app aliasid table.
551  *
552  * @par         This API is for csc.
553  * @par Sync (or) Async : Synchronous API
554  *
555  * @return      0 if success, error code(<0) if fail
556  * @retval      PMINFO_R_OK     success
557  * @retval      PMINFO_R_ERROR  internal error
558  * @pre         None
559  * @post                None
560  * @code
561 static int parse_update_app_aliasid(void)
562 {
563         int ret = 0;
564         ret = pkgmgr_parser_update_app_aliasid();
565         if (ret)
566                 return -1;
567         return 0;
568 }
569  * @endcode
570  */
571 int pkgmgr_parser_update_app_aliasid(void );
572
573 /** @} */
574 #ifdef __cplusplus
575 }
576 #endif
577 #endif                          /* __PKGMGR_PARSER_H__ */