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 ""
60 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
63 * @brief API return values
66 PM_PARSER_R_EINVAL = -2, /**< Invalid argument */
67 PM_PARSER_R_ERROR = -1, /**< General error */
68 PM_PARSER_R_OK = 0 /**< General success */
72 * @brief List definitions.
73 * All lists are doubly-linked, the last element is stored to list pointer,
74 * which means that lists must be looped using the prev pointer, or by
75 * calling LISTHEAD first to go to start in order to use the next pointer.
79 * @brief Convinience Macro to add node in list
82 #define LISTADD(list, node) \
84 (node)->prev = (list); \
85 if (list) (node)->next = (list)->next; \
86 else (node)->next = NULL; \
87 if (list) (list)->next = (node); \
92 * @brief Convinience Macro to add one node to another node
94 #define NODEADD(node1, node2) \
96 (node2)->prev = (node1); \
97 (node2)->next = (node1)->next; \
98 if ((node1)->next) (node1)->next->prev = (node2); \
99 (node1)->next = (node2); \
103 * @brief Convinience Macro to concatenate two lists
105 #define LISTCAT(list, first, last) \
106 if ((first) && (last)) { \
107 (first)->prev = (list); \
112 * @brief Convinience Macro to delete node from list
114 #define LISTDEL(list, node) \
116 if ((node)->prev) (node)->prev->next = (node)->next; \
117 if ((node)->next) (node)->next->prev = (node)->prev; \
118 if (!((node)->prev) && !((node)->next)) (list) = NULL; \
122 * @brief Convinience Macro to get list head
124 #define LISTHEAD(list, node) \
125 for ((node) = (list); (node)->prev; (node) = (node)->prev)
128 * @brief Convinience Macro to get list tail
130 #define LISTTAIL(list, node) \
131 for ((node) = (list); (node)->next; (node) = (node)->next)
133 typedef struct metadata_x {
136 struct metadata_x *prev;
137 struct metadata_x *next;
140 typedef struct privilege_x {
142 struct privilege_x *prev;
143 struct privilege_x *next;
146 typedef struct privileges_x {
147 struct privilege_x *privilege;
148 struct privileges_x *prev;
149 struct privileges_x *next;
152 typedef struct permission_x {
155 struct permission_x *prev;
156 struct permission_x *next;
159 typedef struct icon_x {
165 const char *resolution;
170 typedef struct image_x {
175 struct image_x *prev;
176 struct image_x *next;
179 typedef struct allowed_x {
182 struct allowed_x *prev;
183 struct allowed_x *next;
186 typedef struct request_x {
188 struct request_x *prev;
189 struct request_x *next;
192 typedef struct define_x {
194 struct allowed_x *allowed;
195 struct request_x *request;
196 struct define_x *prev;
197 struct define_x *next;
200 typedef struct datashare_x {
201 struct define_x *define;
202 struct request_x *request;
203 struct datashare_x *prev;
204 struct datashare_x *next;
207 typedef struct description_x {
211 struct description_x *prev;
212 struct description_x *next;
215 typedef struct registry_x {
218 struct registry_x *prev;
219 struct registry_x *next;
222 typedef struct database_x {
225 struct database_x *prev;
226 struct database_x *next;
229 typedef struct layout_x {
232 struct layout_x *prev;
233 struct layout_x *next;
236 typedef struct label_x {
240 struct label_x *prev;
241 struct label_x *next;
244 typedef struct author_x {
249 struct author_x *prev;
250 struct author_x *next;
253 typedef struct license_x {
256 struct license_x *prev;
257 struct license_x *next;
260 typedef struct operation_x {
263 struct operation_x *prev;
264 struct operation_x *next;
267 typedef struct uri_x {
274 typedef struct mime_x {
281 typedef struct subapp_x {
284 struct subapp_x *prev;
285 struct subapp_x *next;
288 typedef struct condition_x {
291 struct condition_x *prev;
292 struct condition_x *next;
295 typedef struct notification_x {
298 struct notification_x *prev;
299 struct notification_x *next;
302 typedef struct appsvc_x {
304 struct operation_x *operation;
307 struct subapp_x *subapp;
308 struct appsvc_x *prev;
309 struct appsvc_x *next;
312 typedef struct appcontrol_x {
314 struct operation_x *operation;
317 struct subapp_x *subapp;
318 struct appcontrol_x *prev;
319 struct appcontrol_x *next;
322 typedef struct category_x{
324 struct category_x *prev;
325 struct category_x *next;
328 typedef struct launchconditions_x {
330 struct condition_x *condition;
331 struct launchconditions_x *prev;
332 struct launchconditions_x *next;
333 } launchconditions_x;
335 typedef struct compatibility_x {
338 struct compatibility_x *prev;
339 struct compatibility_x *next;
342 typedef struct deviceprofile_x {
345 struct deviceprofile_x *prev;
346 struct deviceprofile_x *next;
349 typedef struct resolution_x {
350 const char *mimetype;
351 const char *urischeme;
352 struct resolution_x *prev;
353 struct resolution_x *next;
356 typedef struct capability_x {
357 const char *operationid;
359 struct resolution_x *resolution;
360 struct capability_x *prev;
361 struct capability_x *next;
364 typedef struct datacontrol_x {
365 const char *providerid;
368 struct datacontrol_x *prev;
369 struct datacontrol_x *next;
372 typedef struct uiapplication_x {
375 const char *nodisplay;
376 const char *multiple;
377 const char *taskmanage;
380 const char *categories;
382 const char *hwacceleration;
383 const char *screenreader;
386 const char *recentimage;
387 const char *launchcondition;
388 const char *indicatordisplay;
389 const char *portraitimg;
390 const char *landscapeimg;
391 const char *guestmode_visibility;
392 const char *app_component;
393 const char *permission_type;
394 const char *component_type;
397 const char *submode_mainid;
398 struct label_x *label;
400 struct image_x *image;
401 struct appsvc_x *appsvc;
402 struct appcontrol_x *appcontrol;
403 struct category_x *category;
404 struct metadata_x *metadata;
405 struct permission_x *permission;
406 struct launchconditions_x *launchconditions;
407 struct notification_x *notification;
408 struct datashare_x *datashare;
409 struct datacontrol_x *datacontrol;
410 struct uiapplication_x *prev;
411 struct uiapplication_x *next;
414 typedef struct serviceapplication_x {
418 const char *autorestart;
422 const char *permission_type;
423 struct label_x *label;
425 struct appsvc_x *appsvc;
426 struct appcontrol_x *appcontrol;
427 struct category_x *category;
428 struct metadata_x *metadata;
429 struct permission_x *permission;
430 struct datacontrol_x *datacontrol;
431 struct launchconditions_x *launchconditions;
432 struct notification_x *notification;
433 struct datashare_x *datashare;
434 struct serviceapplication_x *prev;
435 struct serviceapplication_x *next;
436 } serviceapplication_x;
438 typedef struct daemon_x {
441 struct daemon_x *prev;
442 struct daemon_x *next;
445 typedef struct theme_x {
448 struct theme_x *prev;
449 struct theme_x *next;
452 typedef struct font_x {
459 typedef struct ime_x {
466 typedef struct manifest_x {
467 const char *for_all_users; /**< Flag that indicates if the package is available for everyone or for current user only*/
468 const char *package; /**< package name*/
469 const char *version; /**< package version*/
470 const char *installlocation; /**< package install location*/
471 const char *ns; /**<name space*/
472 const char *removable; /**< package removable flag*/
473 const char *preload; /**< package preload flag*/
474 const char *readonly; /**< package readonly flag*/
475 const char *update; /**< package update flag*/
476 const char *appsetting; /**< package app setting flag*/
477 const char *system; /**< package system flag*/
478 const char *type; /**< package type*/
479 const char *package_size; /**< package size for external installation*/
480 const char *installed_time; /**< installed time after finishing of installation*/
481 const char *installed_storage; /**< package currently installed storage*/
482 const char *storeclient_id; /**< id of store client for installed package*/
483 const char *mainapp_id; /**< app id of main application*/
484 const char *package_url; /**< app id of main application*/
485 const char *root_path; /**< package root path*/
486 const char *csc_path; /**< package csc path*/
487 const char *nodisplay_setting; /**< package no display setting menu*/
488 const char *main_package; /**< main package id for sub-package(ug)*/
489 struct icon_x *icon; /**< package icon*/
490 struct label_x *label; /**< package label*/
491 struct author_x *author; /**< package author*/
492 struct description_x *description; /**< package description*/
493 struct license_x *license; /**< package license*/
494 struct privileges_x *privileges; /**< package privileges*/
495 struct uiapplication_x *uiapplication; /**< package's ui application*/
496 struct serviceapplication_x *serviceapplication; /**< package's service application*/
497 struct daemon_x *daemon; /**< package daemon*/
498 struct theme_x *theme; /**< package theme*/
499 struct font_x *font; /**< package font*/
500 struct ime_x *ime; /**< package ime*/
501 struct compatibility_x *compatibility; /**< package compatibility*/
502 struct deviceprofile_x *deviceprofile; /**< package device profile*/
514 /* int check_uid(uid_t uid)
518 case GLOBAL_USER: return GLOBAL;
520 default: goto user; break;
528 * @fn char *pkgmgr_parser_get_manifest_file(const char *pkgid)
529 * @brief This API gets the manifest file of the package.
531 * @par This API is for package-manager installer backends.
532 * @par Sync (or) Async : Synchronous API
534 * @param[in] pkgid pointer to package ID
535 * @return manifest file path on success, NULL on failure
537 * @post Free the manifest file pointer that is returned by API
539 static int get_manifest_file(const char *pkgid)
541 char *manifest = NULL;
542 manifest = pkgmgr_parser_get_manifest_file(pkgid);
543 if (manifest == NULL)
545 printf("Manifest File Path is %s\n", manifest);
551 char *pkgmgr_parser_get_manifest_file(const char *pkgid);
552 char *pkgmgr_parser_get_usr_manifest_file(const char *pkgid, uid_t uid);
555 * @fn int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[])
556 * @fn int pkgmgr_parser_parse_usr_manifest_for_installation(const char *manifest, uid_t uid, char *const tagv[])
557 * @brief This API parses the manifest file of the package after installation and stores the data in DB.
559 * @par This API is for package-manager installer backends.
560 * @par Sync (or) Async : Synchronous API
562 * @param[in] manifest pointer to package manifest file
563 * @param[in] uid the addressee user id of the instruction
564 * @param[in] tagv array of xml tags or NULL
565 * @return 0 if success, error code(<0) if fail
566 * @retval PMINFO_R_OK success
567 * @retval PMINFO_R_EINVAL invalid argument
568 * @retval PMINFO_R_ERROR internal error
572 static int parse_manifest_file_for_installation(const char *manifest)
575 ret = pkgmgr_parser_parse_manifest_for_installation(manifest, NULL);
582 int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[]);
583 int pkgmgr_parser_parse_usr_manifest_for_installation(const char *manifest, uid_t uid, char *const tagv[]);
586 * @fn int pkgmgr_parser_parse_usr_manifest_for_upgrade(const char *manifest, uid_t uid, char *const tagv[])
587 * @fn int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[])
588 * @brief This API parses the manifest file of the package after upgrade and stores the data in DB.
590 * @par This API is for package-manager installer backends.
591 * @par Sync (or) Async : Synchronous API
593 * @param[in] manifest pointer to package manifest file
594 * @param[in] uid the addressee user id of the instruction
595 * @param[in] tagv array of xml tags or NULL
596 * @return 0 if success, error code(<0) if fail
597 * @retval PMINFO_R_OK success
598 * @retval PMINFO_R_EINVAL invalid argument
599 * @retval PMINFO_R_ERROR internal error
603 static int parse_manifest_file_for_upgrade(const char *manifest)
606 ret = pkgmgr_parser_parse_manifest_for_upgrade(manifest, NULL);
613 int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[]);
614 int pkgmgr_parser_parse_usr_manifest_for_upgrade(const char *manifest, uid_t uid, char *const tagv[]);
616 * @fn int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[])
617 * @fn int pkgmgr_parser_parse_usr_manifest_for_uninstallation(const char *manifest, uid_t uid, char *const tagv[])
618 * @brief This API parses the manifest file of the package after uninstallation and deletes the data from DB.
620 * @par This API is for package-manager installer backends.
621 * @par Sync (or) Async : Synchronous API
623 * @param[in] manifest pointer to package manifest file
624 * @param[in] uid the addressee user id of the instruction
625 * @param[in] tagv array of xml tags or NULL
626 * @return 0 if success, error code(<0) if fail
627 * @retval PMINFO_R_OK success
628 * @retval PMINFO_R_EINVAL invalid argument
629 * @retval PMINFO_R_ERROR internal error
633 static int parse_manifest_file_for_uninstallation(const char *manifest)
636 ret = pkgmgr_parser_parse_manifest_for_uninstallation(manifest, NULL);
643 int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[]);
644 int pkgmgr_parser_parse_usr_manifest_for_uninstallation(const char *manifest, uid_t uid, char *const tagv[]);
646 * @fn int pkgmgr_parser_parse_manifest_for_preload()
647 * @fn int pkgmgr_parser_parse_usr_manifest_for_preload(uid_t uid)
648 * @brief This API update preload information to DB.
650 * @par This API is for package-manager installer backends.
651 * @par Sync (or) Async : Synchronous API
653 * @return 0 if success, error code(<0) if fail
654 * @retval PMINFO_R_OK success
655 * @retval PMINFO_R_EINVAL invalid argument
656 * @retval PMINFO_R_ERROR internal error
660 static int parser_parse_manifest_for_preload()
663 ret = pkgmgr_parser_parse_manifest_for_preload();
670 int pkgmgr_parser_parse_manifest_for_preload();
671 int pkgmgr_parser_parse_usr_manifest_for_preload(uid_t uid);
674 * @fn int pkgmgr_parser_check_manifest_validation(const char *manifest)
675 * @brief This API validates the manifest file against the manifest schema.
677 * @par This API is for package-manager installer backends.
678 * @par Sync (or) Async : Synchronous API
680 * @param[in] manifest pointer to package manifest file
681 * @return 0 if success, error code(<0) if fail
682 * @retval PMINFO_R_OK success
683 * @retval PMINFO_R_EINVAL invalid argument
684 * @retval PMINFO_R_ERROR internal error
688 static int validate_manifest_file(const char *manifest)
691 ret = pkgmgr_parser_check_manifest_validation(manifest);
698 int pkgmgr_parser_check_manifest_validation(const char *manifest);
701 * @fn void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
702 * @brief This API will free the manifest pointer by recursively freeing all sub elements.
704 * @par This API is for package-manager installer backends.
705 * @par Sync (or) Async : Synchronous API
707 * @param[in] mfx pointer to parsed manifest data
708 * @pre pkgmgr_parser_process_manifest_xml()
711 static int parse_manifest_file(const char *manifest)
713 manifest_x *mfx = NULL
714 mfx = pkgmgr_parser_process_manifest_xml(manifest);
717 printf("Parsing Manifest Success\n");
718 pkgmgr_parser_free_manifest_xml(mfx);
723 void pkgmgr_parser_free_manifest_xml(manifest_x *mfx);
726 * @fn manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest)
727 * @fn manifest_x *pkgmgr_parser_usr_process_manifest_xml(const char *manifest, uid_t uid)
728 * @brief This API parses the manifest file and stores all the data in the manifest structure.
730 * @par This API is for package-manager installer backends.
731 * @par Sync (or) Async : Synchronous API
733 * @param[in] manifest pointer to package manifest file
734 * @param[in] uid the addressee user id of the instruction
735 * @return manifest pointer on success, NULL on failure
737 * @post pkgmgr_parser_free_manifest_xml()
739 static int parse_manifest_file(const char *manifest)
741 manifest_x *mfx = NULL
742 mfx = pkgmgr_parser_process_manifest_xml(manifest);
745 printf("Parsing Manifest Success\n");
746 pkgmgr_parser_free_manifest_xml(mfx);
751 manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest);
752 manifest_x *pkgmgr_parser_usr_process_manifest_xml(const char *manifest, uid_t uid);
755 * @fn int pkgmgr_parser_run_parser_for_installation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
756 * @brief This API calls the parser directly by supplying the xml docptr. It is used during package installation
758 * @par This API is for package-manager installer backends.
759 * @par Sync (or) Async : Synchronous API
761 * @param[in] docPtr XML doxument pointer
762 * @param[in] tag the xml tag corresponding to the parser that will parse the docPtr
763 * @param[in] pkgid the package id
764 * @return 0 if success, error code(<0) if fail
765 * @retval PMINFO_R_OK success
766 * @retval PMINFO_R_EINVAL invalid argument
767 * @retval PMINFO_R_ERROR internal error
771 static int parse_docptr_for_installation(xmlDocPtr docPtr)
774 ret = pkgmgr_parser_run_parser_for_installation(docPtr, "theme", "com.samsung.test");
781 int pkgmgr_parser_run_parser_for_installation(xmlDocPtr docPtr, const char *tag, const char *pkgid);
784 * @fn int pkgmgr_parser_run_parser_for_upgrade(xmlDocPtr docPtr, const char *tag, const char *pkgid)
785 * @brief This API calls the parser directly by supplying the xml docptr. It is used during package upgrade
787 * @par This API is for package-manager installer backends.
788 * @par Sync (or) Async : Synchronous API
790 * @param[in] docPtr XML doxument pointer
791 * @param[in] tag the xml tag corresponding to the parser that will parse the docPtr
792 * @param[in] pkgid the package id
793 * @return 0 if success, error code(<0) if fail
794 * @retval PMINFO_R_OK success
795 * @retval PMINFO_R_EINVAL invalid argument
796 * @retval PMINFO_R_ERROR internal error
800 static int parse_docptr_for_upgrade(xmlDocPtr docPtr)
803 ret = pkgmgr_parser_run_parser_for_upgrade(docPtr, "theme", "com.samsung.test");
810 int pkgmgr_parser_run_parser_for_upgrade(xmlDocPtr docPtr, const char *tag, const char *pkgid);
813 * @fn int pkgmgr_parser_run_parser_for_uninstallation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
814 * @brief This API calls the parser directly by supplying the xml docptr. It is used during package uninstallation
816 * @par This API is for package-manager installer backends.
817 * @par Sync (or) Async : Synchronous API
819 * @param[in] docPtr XML doxument pointer
820 * @param[in] tag the xml tag corresponding to the parser that will parse the docPtr
821 * @param[in] pkgid the package id
822 * @return 0 if success, error code(<0) if fail
823 * @retval PMINFO_R_OK success
824 * @retval PMINFO_R_EINVAL invalid argument
825 * @retval PMINFO_R_ERROR internal error
829 static int parse_docptr_for_uninstallation(xmlDocPtr docPtr)
832 ret = pkgmgr_parser_run_parser_for_uninstallation(docPtr, "theme", "com.samsung.test");
839 int pkgmgr_parser_run_parser_for_uninstallation(xmlDocPtr docPtr, const char *tag, const char *pkgid);
844 * @fn int pkgmgr_parser_create_desktop_file(manifest_x *mfx)
845 * @fn int pkgmgr_parser_create_usr_desktop_file(manifest_x *mfx, uid_t uid)
846 * @brief This API generates the application desktop file
848 * @par This API is for package-manager installer backends.
849 * @par Sync (or) Async : Synchronous API
851 * @param[in] mfx manifest pointer
852 * @param[in] uid the addressee user id of the instruction
853 * @return 0 if success, error code(<0) if fail
854 * @retval PMINFO_R_OK success
855 * @retval PMINFO_R_EINVAL invalid argument
856 * @retval PMINFO_R_ERROR internal error
857 * @pre pkgmgr_parser_process_manifest_xml()
858 * @post pkgmgr_parser_free_manifest_xml()
860 static int create_desktop_file(char *manifest)
863 manifest_x *mfx = NULL;
864 mfx = pkgmgr_parser_process_manifest_xml(manifest);
865 ret = pkgmgr_parser_create_desktop_file(mfx);
868 pkgmgr_parser_free_manifest_xml(mfx);
873 int pkgmgr_parser_create_desktop_file(manifest_x *mfx);
874 int pkgmgr_parser_create_usr_desktop_file(manifest_x *mfx, uid_t uid);
880 #endif /* __PKGMGR_PARSER_H__ */