4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
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>
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 #ifndef __PKGMGR_PARSER_H__
24 #define __PKGMGR_PARSER_H__
27 * @file pkgmgr_parser.h
28 * @author Sewook Park <sewook7.park@samsung.com>
29 * @author Shobhit Srivastava <shobhit.s@samsung.com>
31 * @brief This file declares API of pkgmgr_parser
32 * @addtogroup APPLICATION_FRAMEWORK
35 * @defgroup PackageManagerParser
36 * @section Header Header file to include:
38 * #include <pkgmgr_parser.h>
44 #include <libxml/xmlreader.h>
46 /* For multi-user support */
47 #include <tzplatform_config.h>
52 #define DEFAULT_LOCALE "No Locale"
54 #define PKG_PARSERLIB "parserlib:"
55 #define PKG_PARSER_CONF_PATH SYSCONFDIR "/package-manager/parser_path.conf"
57 #define PKG_STRING_LEN_MAX 1024
59 #define PKGMGR_PARSER_EMPTY_STR ""
62 * @brief List definitions.
63 * All lists are doubly-linked, the last element is stored to list pointer,
64 * which means that lists must be looped using the prev pointer, or by
65 * calling LISTHEAD first to go to start in order to use the next pointer.
69 * @brief Convinience Macro to add node in list
72 #define LISTADD(list, node) \
74 (node)->prev = (list); \
75 if (list) (node)->next = (list)->next; \
76 else (node)->next = NULL; \
77 if (list) (list)->next = (node); \
82 * @brief Convinience Macro to add one node to another node
84 #define NODEADD(node1, node2) \
86 (node2)->prev = (node1); \
87 (node2)->next = (node1)->next; \
88 if ((node1)->next) (node1)->next->prev = (node2); \
89 (node1)->next = (node2); \
93 * @brief Convinience Macro to concatenate two lists
95 #define LISTCAT(list, first, last) \
96 if ((first) && (last)) { \
97 (first)->prev = (list); \
102 * @brief Convinience Macro to delete node from list
104 #define LISTDEL(list, node) \
106 if ((node)->prev) (node)->prev->next = (node)->next; \
107 if ((node)->next) (node)->next->prev = (node)->prev; \
108 if (!((node)->prev) && !((node)->next)) (list) = NULL; \
112 * @brief Convinience Macro to get list head
114 #define LISTHEAD(list, node) \
115 for ((node) = (list); (node)->prev; (node) = (node)->prev)
118 * @brief Convinience Macro to get list tail
120 #define LISTTAIL(list, node) \
121 for ((node) = (list); (node)->next; (node) = (node)->next)
123 typedef struct metadata_x {
126 struct metadata_x *prev;
127 struct metadata_x *next;
130 typedef struct privilege_x {
132 struct privilege_x *prev;
133 struct privilege_x *next;
136 typedef struct privileges_x {
137 struct privilege_x *privilege;
138 struct privileges_x *prev;
139 struct privileges_x *next;
142 typedef struct permission_x {
145 struct permission_x *prev;
146 struct permission_x *next;
149 typedef struct icon_x {
155 const char *resolution;
160 typedef struct image_x {
165 struct image_x *prev;
166 struct image_x *next;
169 typedef struct allowed_x {
172 struct allowed_x *prev;
173 struct allowed_x *next;
176 typedef struct request_x {
178 struct request_x *prev;
179 struct request_x *next;
182 typedef struct define_x {
184 struct allowed_x *allowed;
185 struct request_x *request;
186 struct define_x *prev;
187 struct define_x *next;
190 typedef struct datashare_x {
191 struct define_x *define;
192 struct request_x *request;
193 struct datashare_x *prev;
194 struct datashare_x *next;
197 typedef struct description_x {
201 struct description_x *prev;
202 struct description_x *next;
205 typedef struct registry_x {
208 struct registry_x *prev;
209 struct registry_x *next;
212 typedef struct database_x {
215 struct database_x *prev;
216 struct database_x *next;
219 typedef struct layout_x {
222 struct layout_x *prev;
223 struct layout_x *next;
226 typedef struct label_x {
230 struct label_x *prev;
231 struct label_x *next;
234 typedef struct author_x {
239 struct author_x *prev;
240 struct author_x *next;
243 typedef struct license_x {
246 struct license_x *prev;
247 struct license_x *next;
250 typedef struct operation_x {
253 struct operation_x *prev;
254 struct operation_x *next;
257 typedef struct uri_x {
264 typedef struct mime_x {
271 typedef struct subapp_x {
274 struct subapp_x *prev;
275 struct subapp_x *next;
278 typedef struct condition_x {
281 struct condition_x *prev;
282 struct condition_x *next;
285 typedef struct notification_x {
288 struct notification_x *prev;
289 struct notification_x *next;
292 typedef struct appsvc_x {
294 struct operation_x *operation;
297 struct subapp_x *subapp;
298 struct appsvc_x *prev;
299 struct appsvc_x *next;
302 typedef struct appcontrol_x {
304 struct operation_x *operation;
307 struct subapp_x *subapp;
308 struct appcontrol_x *prev;
309 struct appcontrol_x *next;
312 typedef struct category_x{
314 struct category_x *prev;
315 struct category_x *next;
318 typedef struct launchconditions_x {
320 struct condition_x *condition;
321 struct launchconditions_x *prev;
322 struct launchconditions_x *next;
323 } launchconditions_x;
325 typedef struct compatibility_x {
328 struct compatibility_x *prev;
329 struct compatibility_x *next;
332 typedef struct deviceprofile_x {
335 struct deviceprofile_x *prev;
336 struct deviceprofile_x *next;
339 typedef struct resolution_x {
340 const char *mimetype;
341 const char *urischeme;
342 struct resolution_x *prev;
343 struct resolution_x *next;
346 typedef struct capability_x {
347 const char *operationid;
349 struct resolution_x *resolution;
350 struct capability_x *prev;
351 struct capability_x *next;
354 typedef struct datacontrol_x {
355 const char *providerid;
356 struct capability_x *capability;
357 struct datacontrol_x *prev;
358 struct datacontrol_x *next;
361 typedef struct uiapplication_x {
364 const char *nodisplay;
365 const char *multiple;
366 const char *taskmanage;
369 const char *categories;
371 const char *hwacceleration;
372 const char *screenreader;
375 const char *recentimage;
376 const char *launchcondition;
377 const char *indicatordisplay;
378 const char *portraitimg;
379 const char *landscapeimg;
380 const char *guestmode_visibility;
381 const char *app_component;
382 const char *permission_type;
383 const char *component_type;
386 const char *submode_mainid;
387 struct label_x *label;
389 struct image_x *image;
390 struct appsvc_x *appsvc;
391 struct appcontrol_x *appcontrol;
392 struct category_x *category;
393 struct metadata_x *metadata;
394 struct permission_x *permission;
395 struct launchconditions_x *launchconditions;
396 struct notification_x *notification;
397 struct datashare_x *datashare;
398 struct uiapplication_x *prev;
399 struct uiapplication_x *next;
402 typedef struct serviceapplication_x {
406 const char *autorestart;
410 const char *permission_type;
411 struct label_x *label;
413 struct appsvc_x *appsvc;
414 struct appcontrol_x *appcontrol;
415 struct category_x *category;
416 struct metadata_x *metadata;
417 struct permission_x *permission;
418 struct datacontrol_x *datacontrol;
419 struct launchconditions_x *launchconditions;
420 struct notification_x *notification;
421 struct datashare_x *datashare;
422 struct serviceapplication_x *prev;
423 struct serviceapplication_x *next;
424 } serviceapplication_x;
426 typedef struct daemon_x {
429 struct daemon_x *prev;
430 struct daemon_x *next;
433 typedef struct theme_x {
436 struct theme_x *prev;
437 struct theme_x *next;
440 typedef struct font_x {
447 typedef struct ime_x {
454 typedef struct manifest_x {
455 const char *package; /**< package name*/
456 const char *version; /**< package version*/
457 const char *installlocation; /**< package install location*/
458 const char *ns; /**<name space*/
459 const char *removable; /**< package removable flag*/
460 const char *preload; /**< package preload flag*/
461 const char *readonly; /**< package readonly flag*/
462 const char *update; /**< package update flag*/
463 const char *appsetting; /**< package app setting flag*/
464 const char *system; /**< package system flag*/
465 const char *type; /**< package type*/
466 const char *package_size; /**< package size for external installation*/
467 const char *installed_time; /**< installed time after finishing of installation*/
468 const char *installed_storage; /**< package currently installed storage*/
469 const char *storeclient_id; /**< id of store client for installed package*/
470 const char *mainapp_id; /**< app id of main application*/
471 const char *package_url; /**< app id of main application*/
472 const char *root_path; /**< package root path*/
473 const char *csc_path; /**< package csc path*/
474 const char *nodisplay_setting; /**< package no display setting menu*/
475 const char *main_package; /**< main package id for sub-package(ug)*/
476 struct icon_x *icon; /**< package icon*/
477 struct label_x *label; /**< package label*/
478 struct author_x *author; /**< package author*/
479 struct description_x *description; /**< package description*/
480 struct license_x *license; /**< package license*/
481 struct privileges_x *privileges; /**< package privileges*/
482 struct uiapplication_x *uiapplication; /**< package's ui application*/
483 struct serviceapplication_x *serviceapplication; /**< package's service application*/
484 struct daemon_x *daemon; /**< package daemon*/
485 struct theme_x *theme; /**< package theme*/
486 struct font_x *font; /**< package font*/
487 struct ime_x *ime; /**< package ime*/
488 struct compatibility_x *compatibility; /**< package compatibility*/
489 struct deviceprofile_x *deviceprofile; /**< package device profile*/
492 /* For multiuser support */
493 char *getUserDBLabel(void);
494 char *getUserPkgParserDBPath(void);
495 char *getUserPkgParserDBPathUID(uid_t uid);
496 char *getUserPkgParserJournalDBPath(void);
497 char *getUserPkgCertDBPath(void);
498 char *getUserPkgCertJournalDBPath(void);
501 * @fn char *pkgmgr_parser_get_manifest_file(const char *pkgid)
502 * @brief This API gets the manifest file of the package.
504 * @par This API is for package-manager installer backends.
505 * @par Sync (or) Async : Synchronous API
507 * @param[in] pkgid pointer to package ID
508 * @return manifest file path on success, NULL on failure
510 * @post Free the manifest file pointer that is returned by API
512 static int get_manifest_file(const char *pkgid)
514 char *manifest = NULL;
515 manifest = pkgmgr_parser_get_manifest_file(pkgid);
516 if (manifest == NULL)
518 printf("Manifest File Path is %s\n", manifest);
524 char *pkgmgr_parser_get_manifest_file(const char *pkgid);
527 * @fn int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[])
528 * @brief This API parses the manifest file of the package after installation and stores the data in DB.
530 * @par This API is for package-manager installer backends.
531 * @par Sync (or) Async : Synchronous API
533 * @param[in] manifest pointer to package manifest file
534 * @param[in] tagv array of xml tags or NULL
535 * @return 0 if success, error code(<0) if fail
536 * @retval PMINFO_R_OK success
537 * @retval PMINFO_R_EINVAL invalid argument
538 * @retval PMINFO_R_ERROR internal error
542 static int parse_manifest_file_for_installation(const char *manifest)
545 ret = pkgmgr_parser_parse_manifest_for_installation(manifest, NULL);
552 int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[]);
555 * @fn int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[])
556 * @brief This API parses the manifest file of the package after upgrade and stores the data in DB.
558 * @par This API is for package-manager installer backends.
559 * @par Sync (or) Async : Synchronous API
561 * @param[in] manifest pointer to package manifest file
562 * @param[in] tagv array of xml tags or NULL
563 * @return 0 if success, error code(<0) if fail
564 * @retval PMINFO_R_OK success
565 * @retval PMINFO_R_EINVAL invalid argument
566 * @retval PMINFO_R_ERROR internal error
570 static int parse_manifest_file_for_upgrade(const char *manifest)
573 ret = pkgmgr_parser_parse_manifest_for_upgrade(manifest, NULL);
580 int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[]);
583 * @fn int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[])
584 * @brief This API parses the manifest file of the package after uninstallation and deletes the data from DB.
586 * @par This API is for package-manager installer backends.
587 * @par Sync (or) Async : Synchronous API
589 * @param[in] manifest pointer to package manifest file
590 * @param[in] tagv array of xml tags or NULL
591 * @return 0 if success, error code(<0) if fail
592 * @retval PMINFO_R_OK success
593 * @retval PMINFO_R_EINVAL invalid argument
594 * @retval PMINFO_R_ERROR internal error
598 static int parse_manifest_file_for_uninstallation(const char *manifest)
601 ret = pkgmgr_parser_parse_manifest_for_uninstallation(manifest, NULL);
608 int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[]);
611 * @fn int pkgmgr_parser_parse_manifest_for_preload()
612 * @brief This API update preload information to DB.
614 * @par This API is for package-manager installer backends.
615 * @par Sync (or) Async : Synchronous API
617 * @return 0 if success, error code(<0) if fail
618 * @retval PMINFO_R_OK success
619 * @retval PMINFO_R_EINVAL invalid argument
620 * @retval PMINFO_R_ERROR internal error
624 static int parser_parse_manifest_for_preload()
627 ret = pkgmgr_parser_parse_manifest_for_preload();
634 int pkgmgr_parser_parse_manifest_for_preload();
637 * @fn int pkgmgr_parser_check_manifest_validation(const char *manifest)
638 * @brief This API validates the manifest file against the manifest schema.
640 * @par This API is for package-manager installer backends.
641 * @par Sync (or) Async : Synchronous API
643 * @param[in] manifest pointer to package manifest file
644 * @return 0 if success, error code(<0) if fail
645 * @retval PMINFO_R_OK success
646 * @retval PMINFO_R_EINVAL invalid argument
647 * @retval PMINFO_R_ERROR internal error
651 static int validate_manifest_file(const char *manifest)
654 ret = pkgmgr_parser_check_manifest_validation(manifest);
661 int pkgmgr_parser_check_manifest_validation(const char *manifest);
664 * @fn void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
665 * @brief This API will free the manifest pointer by recursively freeing all sub elements.
667 * @par This API is for package-manager installer backends.
668 * @par Sync (or) Async : Synchronous API
670 * @param[in] mfx pointer to parsed manifest data
671 * @pre pkgmgr_parser_process_manifest_xml()
674 static int parse_manifest_file(const char *manifest)
676 manifest_x *mfx = NULL
677 mfx = pkgmgr_parser_process_manifest_xml(manifest);
680 printf("Parsing Manifest Success\n");
681 pkgmgr_parser_free_manifest_xml(mfx);
686 void pkgmgr_parser_free_manifest_xml(manifest_x *mfx);
689 * @fn manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest)
690 * @brief This API parses the manifest file and stores all the data in the manifest structure.
692 * @par This API is for package-manager installer backends.
693 * @par Sync (or) Async : Synchronous API
695 * @param[in] manifest pointer to package manifest file
696 * @return manifest pointer on success, NULL on failure
698 * @post pkgmgr_parser_free_manifest_xml()
700 static int parse_manifest_file(const char *manifest)
702 manifest_x *mfx = NULL
703 mfx = pkgmgr_parser_process_manifest_xml(manifest);
706 printf("Parsing Manifest Success\n");
707 pkgmgr_parser_free_manifest_xml(mfx);
712 manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest);
715 * @fn manifest_x *pkgmgr_parser_get_manifest_info(const char *pkigid)
716 * @brief This API gets the manifest info from DB and stores all the data in the manifest structure.
718 * @par This API is for package-manager installer backends.
719 * @par Sync (or) Async : Synchronous API
721 * @param[in] pkgid package id for package
722 * @return manifest pointer on success, NULL on failure
724 * @post pkgmgr_parser_free_manifest_xml()
726 static int get_manifest_info(const char *pkgid)
728 manifest_x *mfx = NULL
729 mfx = pkgmgr_parser_get_manifest_info(pkgid);
732 printf("Parsing Manifest Success\n");
733 pkgmgr_parser_free_manifest_xml(mfx);
738 manifest_x *pkgmgr_parser_get_manifest_info(const char *pkigid);
740 /* These APIs are intended to call parser directly */
741 typedef int (*ps_iter_fn) (const char *tag, int type, void *userdata);
743 int pkgmgr_parser_has_parser(const char *tag, int *type);
744 int pkgmgr_parser_get_list(ps_iter_fn iter_fn, void *data);
747 * @fn int pkgmgr_parser_run_parser_for_installation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
748 * @brief This API calls the parser directly by supplying the xml docptr. It is used during package installation
750 * @par This API is for package-manager installer backends.
751 * @par Sync (or) Async : Synchronous API
753 * @param[in] docPtr XML doxument pointer
754 * @param[in] tag the xml tag corresponding to the parser that will parse the docPtr
755 * @param[in] pkgid the package id
756 * @return 0 if success, error code(<0) if fail
757 * @retval PMINFO_R_OK success
758 * @retval PMINFO_R_EINVAL invalid argument
759 * @retval PMINFO_R_ERROR internal error
763 static int parse_docptr_for_installation(xmlDocPtr docPtr)
766 ret = pkgmgr_parser_run_parser_for_installation(docPtr, "theme", "com.samsung.test");
773 int pkgmgr_parser_run_parser_for_installation(xmlDocPtr docPtr, const char *tag, const char *pkgid);
776 * @fn int pkgmgr_parser_run_parser_for_upgrade(xmlDocPtr docPtr, const char *tag, const char *pkgid)
777 * @brief This API calls the parser directly by supplying the xml docptr. It is used during package upgrade
779 * @par This API is for package-manager installer backends.
780 * @par Sync (or) Async : Synchronous API
782 * @param[in] docPtr XML doxument pointer
783 * @param[in] tag the xml tag corresponding to the parser that will parse the docPtr
784 * @param[in] pkgid the package id
785 * @return 0 if success, error code(<0) if fail
786 * @retval PMINFO_R_OK success
787 * @retval PMINFO_R_EINVAL invalid argument
788 * @retval PMINFO_R_ERROR internal error
792 static int parse_docptr_for_upgrade(xmlDocPtr docPtr)
795 ret = pkgmgr_parser_run_parser_for_upgrade(docPtr, "theme", "com.samsung.test");
802 int pkgmgr_parser_run_parser_for_upgrade(xmlDocPtr docPtr, const char *tag, const char *pkgid);
805 * @fn int pkgmgr_parser_run_parser_for_uninstallation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
806 * @brief This API calls the parser directly by supplying the xml docptr. It is used during package uninstallation
808 * @par This API is for package-manager installer backends.
809 * @par Sync (or) Async : Synchronous API
811 * @param[in] docPtr XML doxument pointer
812 * @param[in] tag the xml tag corresponding to the parser that will parse the docPtr
813 * @param[in] pkgid the package id
814 * @return 0 if success, error code(<0) if fail
815 * @retval PMINFO_R_OK success
816 * @retval PMINFO_R_EINVAL invalid argument
817 * @retval PMINFO_R_ERROR internal error
821 static int parse_docptr_for_uninstallation(xmlDocPtr docPtr)
824 ret = pkgmgr_parser_run_parser_for_uninstallation(docPtr, "theme", "com.samsung.test");
831 int pkgmgr_parser_run_parser_for_uninstallation(xmlDocPtr docPtr, const char *tag, const char *pkgid);
836 * @fn int pkgmgr_parser_create_desktop_file(manifest_x *mfx)
837 * @brief This API generates the application desktop file
839 * @par This API is for package-manager installer backends.
840 * @par Sync (or) Async : Synchronous API
842 * @param[in] mfx manifest pointer
843 * @return 0 if success, error code(<0) if fail
844 * @retval PMINFO_R_OK success
845 * @retval PMINFO_R_EINVAL invalid argument
846 * @retval PMINFO_R_ERROR internal error
847 * @pre pkgmgr_parser_process_manifest_xml()
848 * @post pkgmgr_parser_free_manifest_xml()
850 static int create_desktop_file(char *manifest)
853 manifest_x *mfx = NULL;
854 mfx = pkgmgr_parser_process_manifest_xml(manifest);
855 ret = pkgmgr_parser_create_desktop_file(mfx);
858 pkgmgr_parser_free_manifest_xml(mfx);
863 int pkgmgr_parser_create_desktop_file(manifest_x *mfx);
869 #endif /* __PKGMGR_PARSER_H__ */