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;
358 struct capability_x *capability;
359 struct datacontrol_x *prev;
360 struct datacontrol_x *next;
363 typedef struct uiapplication_x {
366 const char *nodisplay;
367 const char *multiple;
368 const char *taskmanage;
371 const char *categories;
373 const char *hwacceleration;
374 const char *screenreader;
377 const char *recentimage;
378 const char *launchcondition;
379 const char *indicatordisplay;
380 const char *portraitimg;
381 const char *landscapeimg;
382 const char *guestmode_visibility;
383 const char *app_component;
384 const char *permission_type;
385 const char *component_type;
388 const char *submode_mainid;
389 struct label_x *label;
391 struct image_x *image;
392 struct appsvc_x *appsvc;
393 struct appcontrol_x *appcontrol;
394 struct category_x *category;
395 struct metadata_x *metadata;
396 struct permission_x *permission;
397 struct launchconditions_x *launchconditions;
398 struct notification_x *notification;
399 struct datashare_x *datashare;
400 struct uiapplication_x *prev;
401 struct uiapplication_x *next;
404 typedef struct serviceapplication_x {
408 const char *autorestart;
412 const char *permission_type;
413 struct label_x *label;
415 struct appsvc_x *appsvc;
416 struct appcontrol_x *appcontrol;
417 struct category_x *category;
418 struct metadata_x *metadata;
419 struct permission_x *permission;
420 struct datacontrol_x *datacontrol;
421 struct launchconditions_x *launchconditions;
422 struct notification_x *notification;
423 struct datashare_x *datashare;
424 struct serviceapplication_x *prev;
425 struct serviceapplication_x *next;
426 } serviceapplication_x;
428 typedef struct daemon_x {
431 struct daemon_x *prev;
432 struct daemon_x *next;
435 typedef struct theme_x {
438 struct theme_x *prev;
439 struct theme_x *next;
442 typedef struct font_x {
449 typedef struct ime_x {
456 typedef struct manifest_x {
457 const char *for_all_users; /**< Flag that indicates if the package is available for everyone or for current user only*/
458 const char *package; /**< package name*/
459 const char *version; /**< package version*/
460 const char *installlocation; /**< package install location*/
461 const char *ns; /**<name space*/
462 const char *removable; /**< package removable flag*/
463 const char *preload; /**< package preload flag*/
464 const char *readonly; /**< package readonly flag*/
465 const char *update; /**< package update flag*/
466 const char *appsetting; /**< package app setting flag*/
467 const char *system; /**< package system flag*/
468 const char *type; /**< package type*/
469 const char *package_size; /**< package size for external installation*/
470 const char *installed_time; /**< installed time after finishing of installation*/
471 const char *installed_storage; /**< package currently installed storage*/
472 const char *storeclient_id; /**< id of store client for installed package*/
473 const char *mainapp_id; /**< app id of main application*/
474 const char *package_url; /**< app id of main application*/
475 const char *root_path; /**< package root path*/
476 const char *csc_path; /**< package csc path*/
477 const char *nodisplay_setting; /**< package no display setting menu*/
478 const char *main_package; /**< main package id for sub-package(ug)*/
479 struct icon_x *icon; /**< package icon*/
480 struct label_x *label; /**< package label*/
481 struct author_x *author; /**< package author*/
482 struct description_x *description; /**< package description*/
483 struct license_x *license; /**< package license*/
484 struct privileges_x *privileges; /**< package privileges*/
485 struct uiapplication_x *uiapplication; /**< package's ui application*/
486 struct serviceapplication_x *serviceapplication; /**< package's service application*/
487 struct daemon_x *daemon; /**< package daemon*/
488 struct theme_x *theme; /**< package theme*/
489 struct font_x *font; /**< package font*/
490 struct ime_x *ime; /**< package ime*/
491 struct compatibility_x *compatibility; /**< package compatibility*/
492 struct deviceprofile_x *deviceprofile; /**< package device profile*/
504 /* int check_uid(uid_t uid)
508 case GLOBAL_USER: return GLOBAL;
510 default: goto user; break;
518 * @fn char *pkgmgr_parser_get_manifest_file(const char *pkgid)
519 * @brief This API gets the manifest file of the package.
521 * @par This API is for package-manager installer backends.
522 * @par Sync (or) Async : Synchronous API
524 * @param[in] pkgid pointer to package ID
525 * @return manifest file path on success, NULL on failure
527 * @post Free the manifest file pointer that is returned by API
529 static int get_manifest_file(const char *pkgid)
531 char *manifest = NULL;
532 manifest = pkgmgr_parser_get_manifest_file(pkgid);
533 if (manifest == NULL)
535 printf("Manifest File Path is %s\n", manifest);
541 char *pkgmgr_parser_get_manifest_file(const char *pkgid);
544 * @fn int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[])
545 * @fn int pkgmgr_parser_parse_usr_manifest_for_installation(const char *manifest, uid_t uid, char *const tagv[])
546 * @brief This API parses the manifest file of the package after installation and stores the data in DB.
548 * @par This API is for package-manager installer backends.
549 * @par Sync (or) Async : Synchronous API
551 * @param[in] manifest pointer to package manifest file
552 * @param[in] uid the addressee user id of the instruction
553 * @param[in] tagv array of xml tags or NULL
554 * @return 0 if success, error code(<0) if fail
555 * @retval PMINFO_R_OK success
556 * @retval PMINFO_R_EINVAL invalid argument
557 * @retval PMINFO_R_ERROR internal error
561 static int parse_manifest_file_for_installation(const char *manifest)
564 ret = pkgmgr_parser_parse_manifest_for_installation(manifest, NULL);
571 int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[]);
572 int pkgmgr_parser_parse_usr_manifest_for_installation(const char *manifest, uid_t uid, char *const tagv[]);
575 * @fn int pkgmgr_parser_parse_usr_manifest_for_upgrade(const char *manifest, uid_t uid, char *const tagv[])
576 * @fn int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[])
577 * @brief This API parses the manifest file of the package after upgrade and stores the data in DB.
579 * @par This API is for package-manager installer backends.
580 * @par Sync (or) Async : Synchronous API
582 * @param[in] manifest pointer to package manifest file
583 * @param[in] uid the addressee user id of the instruction
584 * @param[in] tagv array of xml tags or NULL
585 * @return 0 if success, error code(<0) if fail
586 * @retval PMINFO_R_OK success
587 * @retval PMINFO_R_EINVAL invalid argument
588 * @retval PMINFO_R_ERROR internal error
592 static int parse_manifest_file_for_upgrade(const char *manifest)
595 ret = pkgmgr_parser_parse_manifest_for_upgrade(manifest, NULL);
602 int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[]);
603 int pkgmgr_parser_parse_usr_manifest_for_upgrade(const char *manifest, uid_t uid, char *const tagv[]);
605 * @fn int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[])
606 * @fn int pkgmgr_parser_parse_usr_manifest_for_uninstallation(const char *manifest, uid_t uid, char *const tagv[])
607 * @brief This API parses the manifest file of the package after uninstallation and deletes the data from DB.
609 * @par This API is for package-manager installer backends.
610 * @par Sync (or) Async : Synchronous API
612 * @param[in] manifest pointer to package manifest file
613 * @param[in] uid the addressee user id of the instruction
614 * @param[in] tagv array of xml tags or NULL
615 * @return 0 if success, error code(<0) if fail
616 * @retval PMINFO_R_OK success
617 * @retval PMINFO_R_EINVAL invalid argument
618 * @retval PMINFO_R_ERROR internal error
622 static int parse_manifest_file_for_uninstallation(const char *manifest)
625 ret = pkgmgr_parser_parse_manifest_for_uninstallation(manifest, NULL);
632 int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[]);
633 int pkgmgr_parser_parse_usr_manifest_for_uninstallation(const char *manifest, uid_t uid, char *const tagv[]);
635 * @fn int pkgmgr_parser_parse_manifest_for_preload()
636 * @fn int pkgmgr_parser_parse_usr_manifest_for_preload(uid_t uid)
637 * @brief This API update preload information to DB.
639 * @par This API is for package-manager installer backends.
640 * @par Sync (or) Async : Synchronous API
642 * @return 0 if success, error code(<0) if fail
643 * @retval PMINFO_R_OK success
644 * @retval PMINFO_R_EINVAL invalid argument
645 * @retval PMINFO_R_ERROR internal error
649 static int parser_parse_manifest_for_preload()
652 ret = pkgmgr_parser_parse_manifest_for_preload();
659 int pkgmgr_parser_parse_manifest_for_preload();
660 int pkgmgr_parser_parse_usr_manifest_for_preload(uid_t uid);
663 * @fn int pkgmgr_parser_check_manifest_validation(const char *manifest)
664 * @brief This API validates the manifest file against the manifest schema.
666 * @par This API is for package-manager installer backends.
667 * @par Sync (or) Async : Synchronous API
669 * @param[in] manifest pointer to package manifest file
670 * @return 0 if success, error code(<0) if fail
671 * @retval PMINFO_R_OK success
672 * @retval PMINFO_R_EINVAL invalid argument
673 * @retval PMINFO_R_ERROR internal error
677 static int validate_manifest_file(const char *manifest)
680 ret = pkgmgr_parser_check_manifest_validation(manifest);
687 int pkgmgr_parser_check_manifest_validation(const char *manifest);
690 * @fn void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
691 * @brief This API will free the manifest pointer by recursively freeing all sub elements.
693 * @par This API is for package-manager installer backends.
694 * @par Sync (or) Async : Synchronous API
696 * @param[in] mfx pointer to parsed manifest data
697 * @pre pkgmgr_parser_process_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 void pkgmgr_parser_free_manifest_xml(manifest_x *mfx);
715 * @fn manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest)
716 * @fn manifest_x *pkgmgr_parser_usr_process_manifest_xml(const char *manifest, uid_t uid)
717 * @brief This API parses the manifest file and stores all the data in the manifest structure.
719 * @par This API is for package-manager installer backends.
720 * @par Sync (or) Async : Synchronous API
722 * @param[in] manifest pointer to package manifest file
723 * @param[in] uid the addressee user id of the instruction
724 * @return manifest pointer on success, NULL on failure
726 * @post pkgmgr_parser_free_manifest_xml()
728 static int parse_manifest_file(const char *manifest)
730 manifest_x *mfx = NULL
731 mfx = pkgmgr_parser_process_manifest_xml(manifest);
734 printf("Parsing Manifest Success\n");
735 pkgmgr_parser_free_manifest_xml(mfx);
740 manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest);
741 manifest_x *pkgmgr_parser_usr_process_manifest_xml(const char *manifest, uid_t uid);
744 * @fn manifest_x *pkgmgr_parser_get_manifest_info(const char *pkigid)
745 * @brief This API gets the manifest info from DB and stores all the data in the manifest structure.
747 * @par This API is for package-manager installer backends.
748 * @par Sync (or) Async : Synchronous API
750 * @param[in] pkgid package id for package
751 * @return manifest pointer on success, NULL on failure
753 * @post pkgmgr_parser_free_manifest_xml()
755 static int get_manifest_info(const char *pkgid)
757 manifest_x *mfx = NULL
758 mfx = pkgmgr_parser_get_manifest_info(pkgid);
761 printf("Parsing Manifest Success\n");
762 pkgmgr_parser_free_manifest_xml(mfx);
767 manifest_x *pkgmgr_parser_get_manifest_info(const char *pkigid);
769 /* These APIs are intended to call parser directly */
770 typedef int (*ps_iter_fn) (const char *tag, int type, void *userdata);
772 int pkgmgr_parser_has_parser(const char *tag, int *type);
773 int pkgmgr_parser_get_list(ps_iter_fn iter_fn, void *data);
776 * @fn int pkgmgr_parser_run_parser_for_installation(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 installation
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_installation(xmlDocPtr docPtr)
795 ret = pkgmgr_parser_run_parser_for_installation(docPtr, "theme", "com.samsung.test");
802 int pkgmgr_parser_run_parser_for_installation(xmlDocPtr docPtr, const char *tag, const char *pkgid);
805 * @fn int pkgmgr_parser_run_parser_for_upgrade(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 upgrade
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_upgrade(xmlDocPtr docPtr)
824 ret = pkgmgr_parser_run_parser_for_upgrade(docPtr, "theme", "com.samsung.test");
831 int pkgmgr_parser_run_parser_for_upgrade(xmlDocPtr docPtr, const char *tag, const char *pkgid);
834 * @fn int pkgmgr_parser_run_parser_for_uninstallation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
835 * @brief This API calls the parser directly by supplying the xml docptr. It is used during package uninstallation
837 * @par This API is for package-manager installer backends.
838 * @par Sync (or) Async : Synchronous API
840 * @param[in] docPtr XML doxument pointer
841 * @param[in] tag the xml tag corresponding to the parser that will parse the docPtr
842 * @param[in] pkgid the package id
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
850 static int parse_docptr_for_uninstallation(xmlDocPtr docPtr)
853 ret = pkgmgr_parser_run_parser_for_uninstallation(docPtr, "theme", "com.samsung.test");
860 int pkgmgr_parser_run_parser_for_uninstallation(xmlDocPtr docPtr, const char *tag, const char *pkgid);
865 * @fn int pkgmgr_parser_create_desktop_file(manifest_x *mfx)
866 * @fn int pkgmgr_parser_create_usr_desktop_file(manifest_x *mfx, uid_t uid)
867 * @brief This API generates the application desktop file
869 * @par This API is for package-manager installer backends.
870 * @par Sync (or) Async : Synchronous API
872 * @param[in] mfx manifest pointer
873 * @param[in] uid the addressee user id of the instruction
874 * @return 0 if success, error code(<0) if fail
875 * @retval PMINFO_R_OK success
876 * @retval PMINFO_R_EINVAL invalid argument
877 * @retval PMINFO_R_ERROR internal error
878 * @pre pkgmgr_parser_process_manifest_xml()
879 * @post pkgmgr_parser_free_manifest_xml()
881 static int create_desktop_file(char *manifest)
884 manifest_x *mfx = NULL;
885 mfx = pkgmgr_parser_process_manifest_xml(manifest);
886 ret = pkgmgr_parser_create_desktop_file(mfx);
889 pkgmgr_parser_free_manifest_xml(mfx);
894 int pkgmgr_parser_create_desktop_file(manifest_x *mfx);
895 int pkgmgr_parser_create_usr_desktop_file(manifest_x *mfx, uid_t uid);
901 #endif /* __PKGMGR_PARSER_H__ */