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)
64 * @brief List definitions.
65 * All lists are doubly-linked, the last element is stored to list pointer,
66 * which means that lists must be looped using the prev pointer, or by
67 * calling LISTHEAD first to go to start in order to use the next pointer.
71 * @brief Convinience Macro to add node in list
74 #define LISTADD(list, node) \
76 (node)->prev = (list); \
77 if (list) (node)->next = (list)->next; \
78 else (node)->next = NULL; \
79 if (list) (list)->next = (node); \
84 * @brief Convinience Macro to add one node to another node
86 #define NODEADD(node1, node2) \
88 (node2)->prev = (node1); \
89 (node2)->next = (node1)->next; \
90 if ((node1)->next) (node1)->next->prev = (node2); \
91 (node1)->next = (node2); \
95 * @brief Convinience Macro to concatenate two lists
97 #define LISTCAT(list, first, last) \
98 if ((first) && (last)) { \
99 (first)->prev = (list); \
104 * @brief Convinience Macro to delete node from list
106 #define LISTDEL(list, node) \
108 if ((node)->prev) (node)->prev->next = (node)->next; \
109 if ((node)->next) (node)->next->prev = (node)->prev; \
110 if (!((node)->prev) && !((node)->next)) (list) = NULL; \
114 * @brief Convinience Macro to get list head
116 #define LISTHEAD(list, node) \
117 for ((node) = (list); (node)->prev; (node) = (node)->prev)
120 * @brief Convinience Macro to get list tail
122 #define LISTTAIL(list, node) \
123 for ((node) = (list); (node)->next; (node) = (node)->next)
125 typedef struct metadata_x {
128 struct metadata_x *prev;
129 struct metadata_x *next;
132 typedef struct privilege_x {
134 struct privilege_x *prev;
135 struct privilege_x *next;
138 typedef struct privileges_x {
139 struct privilege_x *privilege;
140 struct privileges_x *prev;
141 struct privileges_x *next;
144 typedef struct permission_x {
147 struct permission_x *prev;
148 struct permission_x *next;
151 typedef struct icon_x {
157 const char *resolution;
162 typedef struct image_x {
167 struct image_x *prev;
168 struct image_x *next;
171 typedef struct allowed_x {
174 struct allowed_x *prev;
175 struct allowed_x *next;
178 typedef struct request_x {
180 struct request_x *prev;
181 struct request_x *next;
184 typedef struct define_x {
186 struct allowed_x *allowed;
187 struct request_x *request;
188 struct define_x *prev;
189 struct define_x *next;
192 typedef struct datashare_x {
193 struct define_x *define;
194 struct request_x *request;
195 struct datashare_x *prev;
196 struct datashare_x *next;
199 typedef struct description_x {
203 struct description_x *prev;
204 struct description_x *next;
207 typedef struct registry_x {
210 struct registry_x *prev;
211 struct registry_x *next;
214 typedef struct database_x {
217 struct database_x *prev;
218 struct database_x *next;
221 typedef struct layout_x {
224 struct layout_x *prev;
225 struct layout_x *next;
228 typedef struct label_x {
232 struct label_x *prev;
233 struct label_x *next;
236 typedef struct author_x {
241 struct author_x *prev;
242 struct author_x *next;
245 typedef struct license_x {
248 struct license_x *prev;
249 struct license_x *next;
252 typedef struct operation_x {
255 struct operation_x *prev;
256 struct operation_x *next;
259 typedef struct uri_x {
266 typedef struct mime_x {
273 typedef struct subapp_x {
276 struct subapp_x *prev;
277 struct subapp_x *next;
280 typedef struct condition_x {
283 struct condition_x *prev;
284 struct condition_x *next;
287 typedef struct notification_x {
290 struct notification_x *prev;
291 struct notification_x *next;
294 typedef struct appsvc_x {
296 struct operation_x *operation;
299 struct subapp_x *subapp;
300 struct appsvc_x *prev;
301 struct appsvc_x *next;
304 typedef struct appcontrol_x {
306 struct operation_x *operation;
309 struct subapp_x *subapp;
310 struct appcontrol_x *prev;
311 struct appcontrol_x *next;
314 typedef struct category_x{
316 struct category_x *prev;
317 struct category_x *next;
320 typedef struct launchconditions_x {
322 struct condition_x *condition;
323 struct launchconditions_x *prev;
324 struct launchconditions_x *next;
325 } launchconditions_x;
327 typedef struct compatibility_x {
330 struct compatibility_x *prev;
331 struct compatibility_x *next;
334 typedef struct deviceprofile_x {
337 struct deviceprofile_x *prev;
338 struct deviceprofile_x *next;
341 typedef struct resolution_x {
342 const char *mimetype;
343 const char *urischeme;
344 struct resolution_x *prev;
345 struct resolution_x *next;
348 typedef struct capability_x {
349 const char *operationid;
351 struct resolution_x *resolution;
352 struct capability_x *prev;
353 struct capability_x *next;
356 typedef struct datacontrol_x {
357 const char *providerid;
360 struct datacontrol_x *prev;
361 struct datacontrol_x *next;
364 typedef struct uiapplication_x {
367 const char *nodisplay;
368 const char *multiple;
369 const char *taskmanage;
372 const char *categories;
374 const char *hwacceleration;
375 const char *screenreader;
378 const char *recentimage;
379 const char *launchcondition;
380 const char *indicatordisplay;
381 const char *portraitimg;
382 const char *landscapeimg;
383 const char *guestmode_visibility;
384 const char *app_component;
385 const char *permission_type;
386 const char *component_type;
389 const char *submode_mainid;
390 const char *launch_mode;
391 struct label_x *label;
393 struct image_x *image;
394 struct appsvc_x *appsvc;
395 struct appcontrol_x *appcontrol;
396 struct category_x *category;
397 struct metadata_x *metadata;
398 struct permission_x *permission;
399 struct launchconditions_x *launchconditions;
400 struct notification_x *notification;
401 struct datashare_x *datashare;
402 struct datacontrol_x *datacontrol;
403 struct uiapplication_x *prev;
404 struct uiapplication_x *next;
408 typedef struct serviceapplication_x {
412 const char *autorestart;
416 const char *permission_type;
417 struct label_x *label;
419 struct appsvc_x *appsvc;
420 struct appcontrol_x *appcontrol;
421 struct category_x *category;
422 struct metadata_x *metadata;
423 struct permission_x *permission;
424 struct datacontrol_x *datacontrol;
425 struct launchconditions_x *launchconditions;
426 struct notification_x *notification;
427 struct datashare_x *datashare;
428 struct serviceapplication_x *prev;
429 struct serviceapplication_x *next;
430 } serviceapplication_x;
432 typedef struct daemon_x {
435 struct daemon_x *prev;
436 struct daemon_x *next;
439 typedef struct theme_x {
442 struct theme_x *prev;
443 struct theme_x *next;
446 typedef struct font_x {
453 typedef struct ime_x {
460 typedef struct manifest_x {
461 const char *for_all_users; /**< Flag that indicates if the package is available for everyone or for current user only*/
462 const char *package; /**< package name*/
463 const char *version; /**< package version*/
464 const char *installlocation; /**< package install location*/
465 const char *ns; /**<name space*/
466 const char *removable; /**< package removable flag*/
467 const char *preload; /**< package preload flag*/
468 const char *readonly; /**< package readonly flag*/
469 const char *update; /**< package update flag*/
470 const char *appsetting; /**< package app setting flag*/
471 const char *system; /**< package system flag*/
472 const char *type; /**< package type*/
473 const char *package_size; /**< package size for external installation*/
474 const char *installed_time; /**< installed time after finishing of installation*/
475 const char *installed_storage; /**< package currently installed storage*/
476 const char *storeclient_id; /**< id of store client for installed package*/
477 const char *mainapp_id; /**< app id of main application*/
478 const char *package_url; /**< app id of main application*/
479 const char *root_path; /**< package root path*/
480 const char *csc_path; /**< package csc path*/
481 const char *nodisplay_setting; /**< package no display setting menu*/
482 const char *main_package; /**< main package id for sub-package(ug)*/
483 struct icon_x *icon; /**< package icon*/
484 struct label_x *label; /**< package label*/
485 struct author_x *author; /**< package author*/
486 struct description_x *description; /**< package description*/
487 struct license_x *license; /**< package license*/
488 struct privileges_x *privileges; /**< package privileges*/
489 struct uiapplication_x *uiapplication; /**< package's ui application*/
490 struct serviceapplication_x *serviceapplication; /**< package's service application*/
491 struct daemon_x *daemon; /**< package daemon*/
492 struct theme_x *theme; /**< package theme*/
493 struct font_x *font; /**< package font*/
494 struct ime_x *ime; /**< package ime*/
495 struct compatibility_x *compatibility; /**< package compatibility*/
496 struct deviceprofile_x *deviceprofile; /**< package device profile*/
508 /* int check_uid(uid_t uid)
512 case GLOBAL_USER: return GLOBAL;
514 default: goto user; break;
522 * @fn char *pkgmgr_parser_get_manifest_file(const char *pkgid)
523 * @brief This API gets the manifest file of the package.
525 * @par This API is for package-manager installer backends.
526 * @par Sync (or) Async : Synchronous API
528 * @param[in] pkgid pointer to package ID
529 * @return manifest file path on success, NULL on failure
531 * @post Free the manifest file pointer that is returned by API
533 static int get_manifest_file(const char *pkgid)
535 char *manifest = NULL;
536 manifest = pkgmgr_parser_get_manifest_file(pkgid);
537 if (manifest == NULL)
539 printf("Manifest File Path is %s\n", manifest);
545 char *pkgmgr_parser_get_manifest_file(const char *pkgid);
546 char *pkgmgr_parser_get_usr_manifest_file(const char *pkgid, uid_t uid);
549 * @fn int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[])
550 * @fn int pkgmgr_parser_parse_usr_manifest_for_installation(const char *manifest, uid_t uid, char *const tagv[])
551 * @brief This API parses the manifest file of the package after installation and stores the data in DB.
553 * @par This API is for package-manager installer backends.
554 * @par Sync (or) Async : Synchronous API
556 * @param[in] manifest pointer to package manifest file
557 * @param[in] uid the addressee user id of the instruction
558 * @param[in] tagv array of xml tags or NULL
559 * @return 0 if success, error code(<0) if fail
560 * @retval PMINFO_R_OK success
561 * @retval PMINFO_R_EINVAL invalid argument
562 * @retval PMINFO_R_ERROR internal error
566 static int parse_manifest_file_for_installation(const char *manifest)
569 ret = pkgmgr_parser_parse_manifest_for_installation(manifest, NULL);
576 int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[]);
577 int pkgmgr_parser_parse_usr_manifest_for_installation(const char *manifest, uid_t uid, char *const tagv[]);
580 * @fn int pkgmgr_parser_parse_usr_manifest_for_upgrade(const char *manifest, uid_t uid, char *const tagv[])
581 * @fn int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[])
582 * @brief This API parses the manifest file of the package after upgrade and stores the data in DB.
584 * @par This API is for package-manager installer backends.
585 * @par Sync (or) Async : Synchronous API
587 * @param[in] manifest pointer to package manifest file
588 * @param[in] uid the addressee user id of the instruction
589 * @param[in] tagv array of xml tags or NULL
590 * @return 0 if success, error code(<0) if fail
591 * @retval PMINFO_R_OK success
592 * @retval PMINFO_R_EINVAL invalid argument
593 * @retval PMINFO_R_ERROR internal error
597 static int parse_manifest_file_for_upgrade(const char *manifest)
600 ret = pkgmgr_parser_parse_manifest_for_upgrade(manifest, NULL);
607 int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[]);
608 int pkgmgr_parser_parse_usr_manifest_for_upgrade(const char *manifest, uid_t uid, char *const tagv[]);
610 * @fn int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[])
611 * @fn int pkgmgr_parser_parse_usr_manifest_for_uninstallation(const char *manifest, uid_t uid, char *const tagv[])
612 * @brief This API parses the manifest file of the package after uninstallation and deletes the data from DB.
614 * @par This API is for package-manager installer backends.
615 * @par Sync (or) Async : Synchronous API
617 * @param[in] manifest pointer to package manifest file
618 * @param[in] uid the addressee user id of the instruction
619 * @param[in] tagv array of xml tags or NULL
620 * @return 0 if success, error code(<0) if fail
621 * @retval PMINFO_R_OK success
622 * @retval PMINFO_R_EINVAL invalid argument
623 * @retval PMINFO_R_ERROR internal error
627 static int parse_manifest_file_for_uninstallation(const char *manifest)
630 ret = pkgmgr_parser_parse_manifest_for_uninstallation(manifest, NULL);
637 int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[]);
638 int pkgmgr_parser_parse_usr_manifest_for_uninstallation(const char *manifest, uid_t uid, char *const tagv[]);
640 * @fn int pkgmgr_parser_parse_manifest_for_preload()
641 * @fn int pkgmgr_parser_parse_usr_manifest_for_preload(uid_t uid)
642 * @brief This API update preload information to DB.
644 * @par This API is for package-manager installer backends.
645 * @par Sync (or) Async : Synchronous API
647 * @return 0 if success, error code(<0) if fail
648 * @retval PMINFO_R_OK success
649 * @retval PMINFO_R_EINVAL invalid argument
650 * @retval PMINFO_R_ERROR internal error
654 static int parser_parse_manifest_for_preload()
657 ret = pkgmgr_parser_parse_manifest_for_preload();
664 int pkgmgr_parser_parse_manifest_for_preload();
665 int pkgmgr_parser_parse_usr_manifest_for_preload(uid_t uid);
668 * @fn int pkgmgr_parser_check_manifest_validation(const char *manifest)
669 * @brief This API validates the manifest file against the manifest schema.
671 * @par This API is for package-manager installer backends.
672 * @par Sync (or) Async : Synchronous API
674 * @param[in] manifest pointer to package manifest file
675 * @return 0 if success, error code(<0) if fail
676 * @retval PMINFO_R_OK success
677 * @retval PMINFO_R_EINVAL invalid argument
678 * @retval PMINFO_R_ERROR internal error
682 static int validate_manifest_file(const char *manifest)
685 ret = pkgmgr_parser_check_manifest_validation(manifest);
692 int pkgmgr_parser_check_manifest_validation(const char *manifest);
695 * @fn void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
696 * @brief This API will free the manifest pointer by recursively freeing all sub elements.
698 * @par This API is for package-manager installer backends.
699 * @par Sync (or) Async : Synchronous API
701 * @param[in] mfx pointer to parsed manifest data
702 * @pre pkgmgr_parser_process_manifest_xml()
705 static int parse_manifest_file(const char *manifest)
707 manifest_x *mfx = NULL
708 mfx = pkgmgr_parser_process_manifest_xml(manifest);
711 printf("Parsing Manifest Success\n");
712 pkgmgr_parser_free_manifest_xml(mfx);
717 void pkgmgr_parser_free_manifest_xml(manifest_x *mfx);
720 * @fn manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest)
721 * @fn manifest_x *pkgmgr_parser_usr_process_manifest_xml(const char *manifest, uid_t uid)
722 * @brief This API parses the manifest file and stores all the data in the manifest structure.
724 * @par This API is for package-manager installer backends.
725 * @par Sync (or) Async : Synchronous API
727 * @param[in] manifest pointer to package manifest file
728 * @param[in] uid the addressee user id of the instruction
729 * @return manifest pointer on success, NULL on failure
731 * @post pkgmgr_parser_free_manifest_xml()
733 static int parse_manifest_file(const char *manifest)
735 manifest_x *mfx = NULL
736 mfx = pkgmgr_parser_process_manifest_xml(manifest);
739 printf("Parsing Manifest Success\n");
740 pkgmgr_parser_free_manifest_xml(mfx);
745 manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest);
746 manifest_x *pkgmgr_parser_usr_process_manifest_xml(const char *manifest, uid_t uid);
749 * @fn int pkgmgr_parser_run_parser_for_installation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
750 * @brief This API calls the parser directly by supplying the xml docptr. It is used during package installation
752 * @par This API is for package-manager installer backends.
753 * @par Sync (or) Async : Synchronous API
755 * @param[in] docPtr XML doxument pointer
756 * @param[in] tag the xml tag corresponding to the parser that will parse the docPtr
757 * @param[in] pkgid the package id
758 * @return 0 if success, error code(<0) if fail
759 * @retval PMINFO_R_OK success
760 * @retval PMINFO_R_EINVAL invalid argument
761 * @retval PMINFO_R_ERROR internal error
765 static int parse_docptr_for_installation(xmlDocPtr docPtr)
768 ret = pkgmgr_parser_run_parser_for_installation(docPtr, "theme", "com.samsung.test");
775 int pkgmgr_parser_run_parser_for_installation(xmlDocPtr docPtr, const char *tag, const char *pkgid);
778 * @fn int pkgmgr_parser_run_parser_for_upgrade(xmlDocPtr docPtr, const char *tag, const char *pkgid)
779 * @brief This API calls the parser directly by supplying the xml docptr. It is used during package upgrade
781 * @par This API is for package-manager installer backends.
782 * @par Sync (or) Async : Synchronous API
784 * @param[in] docPtr XML doxument pointer
785 * @param[in] tag the xml tag corresponding to the parser that will parse the docPtr
786 * @param[in] pkgid the package id
787 * @return 0 if success, error code(<0) if fail
788 * @retval PMINFO_R_OK success
789 * @retval PMINFO_R_EINVAL invalid argument
790 * @retval PMINFO_R_ERROR internal error
794 static int parse_docptr_for_upgrade(xmlDocPtr docPtr)
797 ret = pkgmgr_parser_run_parser_for_upgrade(docPtr, "theme", "com.samsung.test");
804 int pkgmgr_parser_run_parser_for_upgrade(xmlDocPtr docPtr, const char *tag, const char *pkgid);
807 * @fn int pkgmgr_parser_run_parser_for_uninstallation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
808 * @brief This API calls the parser directly by supplying the xml docptr. It is used during package uninstallation
810 * @par This API is for package-manager installer backends.
811 * @par Sync (or) Async : Synchronous API
813 * @param[in] docPtr XML doxument pointer
814 * @param[in] tag the xml tag corresponding to the parser that will parse the docPtr
815 * @param[in] pkgid the package id
816 * @return 0 if success, error code(<0) if fail
817 * @retval PMINFO_R_OK success
818 * @retval PMINFO_R_EINVAL invalid argument
819 * @retval PMINFO_R_ERROR internal error
823 static int parse_docptr_for_uninstallation(xmlDocPtr docPtr)
826 ret = pkgmgr_parser_run_parser_for_uninstallation(docPtr, "theme", "com.samsung.test");
833 int pkgmgr_parser_run_parser_for_uninstallation(xmlDocPtr docPtr, const char *tag, const char *pkgid);
838 * @fn int pkgmgr_parser_create_desktop_file(manifest_x *mfx)
839 * @fn int pkgmgr_parser_create_usr_desktop_file(manifest_x *mfx, uid_t uid)
840 * @brief This API generates the application desktop file
842 * @par This API is for package-manager installer backends.
843 * @par Sync (or) Async : Synchronous API
845 * @param[in] mfx manifest pointer
846 * @param[in] uid the addressee user id of the instruction
847 * @return 0 if success, error code(<0) if fail
848 * @retval PMINFO_R_OK success
849 * @retval PMINFO_R_EINVAL invalid argument
850 * @retval PMINFO_R_ERROR internal error
851 * @pre pkgmgr_parser_process_manifest_xml()
852 * @post pkgmgr_parser_free_manifest_xml()
854 static int create_desktop_file(char *manifest)
857 manifest_x *mfx = NULL;
858 mfx = pkgmgr_parser_process_manifest_xml(manifest);
859 ret = pkgmgr_parser_create_desktop_file(mfx);
862 pkgmgr_parser_free_manifest_xml(mfx);
867 int pkgmgr_parser_create_desktop_file(manifest_x *mfx);
868 int pkgmgr_parser_create_usr_desktop_file(manifest_x *mfx, uid_t uid);
874 #endif /* __PKGMGR_PARSER_H__ */