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 {
313 const char *operation;
316 struct appcontrol_x *prev;
317 struct appcontrol_x *next;
320 typedef struct category_x{
322 struct category_x *prev;
323 struct category_x *next;
326 typedef struct launchconditions_x {
328 struct condition_x *condition;
329 struct launchconditions_x *prev;
330 struct launchconditions_x *next;
331 } launchconditions_x;
333 typedef struct compatibility_x {
336 struct compatibility_x *prev;
337 struct compatibility_x *next;
340 typedef struct deviceprofile_x {
343 struct deviceprofile_x *prev;
344 struct deviceprofile_x *next;
347 typedef struct datacontrol_x {
348 const char *providerid;
351 struct datacontrol_x *prev;
352 struct datacontrol_x *next;
355 typedef struct uiapplication_x {
358 const char *nodisplay;
359 const char *multiple;
360 const char *taskmanage;
363 const char *categories;
365 const char *hwacceleration;
366 const char *screenreader;
369 const char *recentimage;
370 const char *launchcondition;
371 const char *indicatordisplay;
372 const char *portraitimg;
373 const char *landscapeimg;
374 const char *guestmode_visibility;
375 const char *app_component;
376 const char *permission_type;
377 const char *component_type;
380 const char *submode_mainid;
381 const char *launch_mode;
382 struct label_x *label;
384 struct image_x *image;
385 struct appsvc_x *appsvc;
386 struct appcontrol_x *appcontrol;
387 struct category_x *category;
388 struct metadata_x *metadata;
389 struct permission_x *permission;
390 struct launchconditions_x *launchconditions;
391 struct notification_x *notification;
392 struct datashare_x *datashare;
393 struct datacontrol_x *datacontrol;
394 struct uiapplication_x *prev;
395 struct uiapplication_x *next;
399 typedef struct serviceapplication_x {
403 const char *autorestart;
407 const char *permission_type;
408 struct label_x *label;
410 struct appsvc_x *appsvc;
411 struct appcontrol_x *appcontrol;
412 struct category_x *category;
413 struct metadata_x *metadata;
414 struct permission_x *permission;
415 struct datacontrol_x *datacontrol;
416 struct launchconditions_x *launchconditions;
417 struct notification_x *notification;
418 struct datashare_x *datashare;
419 struct serviceapplication_x *prev;
420 struct serviceapplication_x *next;
421 } serviceapplication_x;
423 typedef struct daemon_x {
426 struct daemon_x *prev;
427 struct daemon_x *next;
430 typedef struct theme_x {
433 struct theme_x *prev;
434 struct theme_x *next;
437 typedef struct font_x {
444 typedef struct ime_x {
451 typedef struct manifest_x {
452 const char *for_all_users; /**< Flag that indicates if the package is available for everyone or for current user only*/
453 const char *package; /**< package name*/
454 const char *version; /**< package version*/
455 const char *installlocation; /**< package install location*/
456 const char *ns; /**<name space*/
457 const char *removable; /**< package removable flag*/
458 const char *preload; /**< package preload flag*/
459 const char *readonly; /**< package readonly flag*/
460 const char *update; /**< package update flag*/
461 const char *appsetting; /**< package app setting flag*/
462 const char *system; /**< package system flag*/
463 const char *type; /**< package type*/
464 const char *package_size; /**< package size for external installation*/
465 const char *installed_time; /**< installed time after finishing of installation*/
466 const char *installed_storage; /**< package currently installed storage*/
467 const char *storeclient_id; /**< id of store client for installed package*/
468 const char *mainapp_id; /**< app id of main application*/
469 const char *package_url; /**< app id of main application*/
470 const char *root_path; /**< package root path*/
471 const char *csc_path; /**< package csc path*/
472 const char *nodisplay_setting; /**< package no display setting menu*/
473 const char *api_version; /**< minimum version of API package using*/
474 struct icon_x *icon; /**< package icon*/
475 struct label_x *label; /**< package label*/
476 struct author_x *author; /**< package author*/
477 struct description_x *description; /**< package description*/
478 struct license_x *license; /**< package license*/
479 struct privileges_x *privileges; /**< package privileges*/
480 struct uiapplication_x *uiapplication; /**< package's ui application*/
481 struct serviceapplication_x *serviceapplication; /**< package's service application*/
482 struct daemon_x *daemon; /**< package daemon*/
483 struct theme_x *theme; /**< package theme*/
484 struct font_x *font; /**< package font*/
485 struct ime_x *ime; /**< package ime*/
486 struct compatibility_x *compatibility; /**< package compatibility*/
487 struct deviceprofile_x *deviceprofile; /**< package device profile*/
499 /* int check_uid(uid_t uid)
503 case GLOBAL_USER: return GLOBAL;
505 default: goto user; break;
513 * @fn char *pkgmgr_parser_get_manifest_file(const char *pkgid)
514 * @brief This API gets the manifest file of the package.
516 * @par This API is for package-manager installer backends.
517 * @par Sync (or) Async : Synchronous API
519 * @param[in] pkgid pointer to package ID
520 * @return manifest file path on success, NULL on failure
522 * @post Free the manifest file pointer that is returned by API
524 static int get_manifest_file(const char *pkgid)
526 char *manifest = NULL;
527 manifest = pkgmgr_parser_get_manifest_file(pkgid);
528 if (manifest == NULL)
530 printf("Manifest File Path is %s\n", manifest);
536 char *pkgmgr_parser_get_manifest_file(const char *pkgid);
537 char *pkgmgr_parser_get_usr_manifest_file(const char *pkgid, uid_t uid);
540 * @fn int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[])
541 * @fn int pkgmgr_parser_parse_usr_manifest_for_installation(const char *manifest, uid_t uid, char *const tagv[])
542 * @brief This API parses the manifest file of the package after installation and stores the data in DB.
544 * @par This API is for package-manager installer backends.
545 * @par Sync (or) Async : Synchronous API
547 * @param[in] manifest pointer to package manifest file
548 * @param[in] uid the addressee user id of the instruction
549 * @param[in] tagv array of xml tags or NULL
550 * @return 0 if success, error code(<0) if fail
551 * @retval PMINFO_R_OK success
552 * @retval PMINFO_R_EINVAL invalid argument
553 * @retval PMINFO_R_ERROR internal error
557 static int parse_manifest_file_for_installation(const char *manifest)
560 ret = pkgmgr_parser_parse_manifest_for_installation(manifest, NULL);
567 int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[]);
568 int pkgmgr_parser_parse_usr_manifest_for_installation(const char *manifest, uid_t uid, char *const tagv[]);
571 * @fn int pkgmgr_parser_parse_usr_manifest_for_upgrade(const char *manifest, uid_t uid, char *const tagv[])
572 * @fn int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[])
573 * @brief This API parses the manifest file of the package after upgrade and stores the data in DB.
575 * @par This API is for package-manager installer backends.
576 * @par Sync (or) Async : Synchronous API
578 * @param[in] manifest pointer to package manifest file
579 * @param[in] uid the addressee user id of the instruction
580 * @param[in] tagv array of xml tags or NULL
581 * @return 0 if success, error code(<0) if fail
582 * @retval PMINFO_R_OK success
583 * @retval PMINFO_R_EINVAL invalid argument
584 * @retval PMINFO_R_ERROR internal error
588 static int parse_manifest_file_for_upgrade(const char *manifest)
591 ret = pkgmgr_parser_parse_manifest_for_upgrade(manifest, NULL);
598 int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[]);
599 int pkgmgr_parser_parse_usr_manifest_for_upgrade(const char *manifest, uid_t uid, char *const tagv[]);
601 * @fn int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[])
602 * @fn int pkgmgr_parser_parse_usr_manifest_for_uninstallation(const char *manifest, uid_t uid, char *const tagv[])
603 * @brief This API parses the manifest file of the package after uninstallation and deletes the data from DB.
605 * @par This API is for package-manager installer backends.
606 * @par Sync (or) Async : Synchronous API
608 * @param[in] manifest pointer to package manifest file
609 * @param[in] uid the addressee user id of the instruction
610 * @param[in] tagv array of xml tags or NULL
611 * @return 0 if success, error code(<0) if fail
612 * @retval PMINFO_R_OK success
613 * @retval PMINFO_R_EINVAL invalid argument
614 * @retval PMINFO_R_ERROR internal error
618 static int parse_manifest_file_for_uninstallation(const char *manifest)
621 ret = pkgmgr_parser_parse_manifest_for_uninstallation(manifest, NULL);
628 int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[]);
629 int pkgmgr_parser_parse_usr_manifest_for_uninstallation(const char *manifest, uid_t uid, char *const tagv[]);
631 * @fn int pkgmgr_parser_parse_manifest_for_preload()
632 * @fn int pkgmgr_parser_parse_usr_manifest_for_preload(uid_t uid)
633 * @brief This API update preload information to DB.
635 * @par This API is for package-manager installer backends.
636 * @par Sync (or) Async : Synchronous API
638 * @return 0 if success, error code(<0) if fail
639 * @retval PMINFO_R_OK success
640 * @retval PMINFO_R_EINVAL invalid argument
641 * @retval PMINFO_R_ERROR internal error
645 static int parser_parse_manifest_for_preload()
648 ret = pkgmgr_parser_parse_manifest_for_preload();
655 int pkgmgr_parser_parse_manifest_for_preload();
656 int pkgmgr_parser_parse_usr_manifest_for_preload(uid_t uid);
659 * @fn int pkgmgr_parser_check_manifest_validation(const char *manifest)
660 * @brief This API validates the manifest file against the manifest schema.
662 * @par This API is for package-manager installer backends.
663 * @par Sync (or) Async : Synchronous API
665 * @param[in] manifest pointer to package manifest file
666 * @return 0 if success, error code(<0) if fail
667 * @retval PMINFO_R_OK success
668 * @retval PMINFO_R_EINVAL invalid argument
669 * @retval PMINFO_R_ERROR internal error
673 static int validate_manifest_file(const char *manifest)
676 ret = pkgmgr_parser_check_manifest_validation(manifest);
683 int pkgmgr_parser_check_manifest_validation(const char *manifest);
686 * @fn void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
687 * @brief This API will free the manifest pointer by recursively freeing all sub elements.
689 * @par This API is for package-manager installer backends.
690 * @par Sync (or) Async : Synchronous API
692 * @param[in] mfx pointer to parsed manifest data
693 * @pre pkgmgr_parser_process_manifest_xml()
696 static int parse_manifest_file(const char *manifest)
698 manifest_x *mfx = NULL
699 mfx = pkgmgr_parser_process_manifest_xml(manifest);
702 printf("Parsing Manifest Success\n");
703 pkgmgr_parser_free_manifest_xml(mfx);
708 void pkgmgr_parser_free_manifest_xml(manifest_x *mfx);
711 * @fn manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest)
712 * @fn manifest_x *pkgmgr_parser_usr_process_manifest_xml(const char *manifest, uid_t uid)
713 * @brief This API parses the manifest file and stores all the data in the manifest structure.
715 * @par This API is for package-manager installer backends.
716 * @par Sync (or) Async : Synchronous API
718 * @param[in] manifest pointer to package manifest file
719 * @param[in] uid the addressee user id of the instruction
720 * @return manifest pointer on success, NULL on failure
722 * @post pkgmgr_parser_free_manifest_xml()
724 static int parse_manifest_file(const char *manifest)
726 manifest_x *mfx = NULL
727 mfx = pkgmgr_parser_process_manifest_xml(manifest);
730 printf("Parsing Manifest Success\n");
731 pkgmgr_parser_free_manifest_xml(mfx);
736 manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest);
737 manifest_x *pkgmgr_parser_usr_process_manifest_xml(const char *manifest, uid_t uid);
740 * @fn int pkgmgr_parser_run_parser_for_installation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
741 * @brief This API calls the parser directly by supplying the xml docptr. It is used during package installation
743 * @par This API is for package-manager installer backends.
744 * @par Sync (or) Async : Synchronous API
746 * @param[in] docPtr XML doxument pointer
747 * @param[in] tag the xml tag corresponding to the parser that will parse the docPtr
748 * @param[in] pkgid the package id
749 * @return 0 if success, error code(<0) if fail
750 * @retval PMINFO_R_OK success
751 * @retval PMINFO_R_EINVAL invalid argument
752 * @retval PMINFO_R_ERROR internal error
756 static int parse_docptr_for_installation(xmlDocPtr docPtr)
759 ret = pkgmgr_parser_run_parser_for_installation(docPtr, "theme", "com.samsung.test");
766 int pkgmgr_parser_run_parser_for_installation(xmlDocPtr docPtr, const char *tag, const char *pkgid);
769 * @fn int pkgmgr_parser_run_parser_for_upgrade(xmlDocPtr docPtr, const char *tag, const char *pkgid)
770 * @brief This API calls the parser directly by supplying the xml docptr. It is used during package upgrade
772 * @par This API is for package-manager installer backends.
773 * @par Sync (or) Async : Synchronous API
775 * @param[in] docPtr XML doxument pointer
776 * @param[in] tag the xml tag corresponding to the parser that will parse the docPtr
777 * @param[in] pkgid the package id
778 * @return 0 if success, error code(<0) if fail
779 * @retval PMINFO_R_OK success
780 * @retval PMINFO_R_EINVAL invalid argument
781 * @retval PMINFO_R_ERROR internal error
785 static int parse_docptr_for_upgrade(xmlDocPtr docPtr)
788 ret = pkgmgr_parser_run_parser_for_upgrade(docPtr, "theme", "com.samsung.test");
795 int pkgmgr_parser_run_parser_for_upgrade(xmlDocPtr docPtr, const char *tag, const char *pkgid);
798 * @fn int pkgmgr_parser_run_parser_for_uninstallation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
799 * @brief This API calls the parser directly by supplying the xml docptr. It is used during package uninstallation
801 * @par This API is for package-manager installer backends.
802 * @par Sync (or) Async : Synchronous API
804 * @param[in] docPtr XML doxument pointer
805 * @param[in] tag the xml tag corresponding to the parser that will parse the docPtr
806 * @param[in] pkgid the package id
807 * @return 0 if success, error code(<0) if fail
808 * @retval PMINFO_R_OK success
809 * @retval PMINFO_R_EINVAL invalid argument
810 * @retval PMINFO_R_ERROR internal error
814 static int parse_docptr_for_uninstallation(xmlDocPtr docPtr)
817 ret = pkgmgr_parser_run_parser_for_uninstallation(docPtr, "theme", "com.samsung.test");
824 int pkgmgr_parser_run_parser_for_uninstallation(xmlDocPtr docPtr, const char *tag, const char *pkgid);
829 * @fn int pkgmgr_parser_create_desktop_file(manifest_x *mfx)
830 * @fn int pkgmgr_parser_create_usr_desktop_file(manifest_x *mfx, uid_t uid)
831 * @brief This API generates the application desktop file
833 * @par This API is for package-manager installer backends.
834 * @par Sync (or) Async : Synchronous API
836 * @param[in] mfx manifest pointer
837 * @param[in] uid the addressee user id of the instruction
838 * @return 0 if success, error code(<0) if fail
839 * @retval PMINFO_R_OK success
840 * @retval PMINFO_R_EINVAL invalid argument
841 * @retval PMINFO_R_ERROR internal error
842 * @pre pkgmgr_parser_process_manifest_xml()
843 * @post pkgmgr_parser_free_manifest_xml()
845 static int create_desktop_file(char *manifest)
848 manifest_x *mfx = NULL;
849 mfx = pkgmgr_parser_process_manifest_xml(manifest);
850 ret = pkgmgr_parser_create_desktop_file(mfx);
853 pkgmgr_parser_free_manifest_xml(mfx);
858 int pkgmgr_parser_create_desktop_file(manifest_x *mfx);
859 int pkgmgr_parser_create_usr_desktop_file(manifest_x *mfx, uid_t uid);
865 #endif /* __PKGMGR_PARSER_H__ */