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>
49 #define DEFAULT_LOCALE "No Locale"
51 #define PKG_PARSERLIB "parserlib:"
52 #define PKG_PARSER_CONF_PATH "/usr/etc/package-manager/parser_path.conf"
54 #define PKG_STRING_LEN_MAX 1024
57 * @brief List definitions.
58 * All lists are doubly-linked, the last element is stored to list pointer,
59 * which means that lists must be looped using the prev pointer, or by
60 * calling LISTHEAD first to go to start in order to use the next pointer.
64 * @brief Convinience Macro to add node in list
67 #define LISTADD(list, node) \
69 (node)->prev = (list); \
70 if (list) (node)->next = (list)->next; \
71 else (node)->next = NULL; \
72 if (list) (list)->next = (node); \
77 * @brief Convinience Macro to add one node to another node
79 #define NODEADD(node1, node2) \
81 (node2)->prev = (node1); \
82 (node2)->next = (node1)->next; \
83 if ((node1)->next) (node1)->next->prev = (node2); \
84 (node1)->next = (node2); \
88 * @brief Convinience Macro to concatenate two lists
90 #define LISTCAT(list, first, last) \
91 if ((first) && (last)) { \
92 (first)->prev = (list); \
97 * @brief Convinience Macro to delete node from list
99 #define LISTDEL(list, node) \
101 if ((node)->prev) (node)->prev->next = (node)->next; \
102 if ((node)->next) (node)->next->prev = (node)->prev; \
103 if (!((node)->prev) && !((node)->next)) (list) = NULL; \
107 * @brief Convinience Macro to get list head
109 #define LISTHEAD(list, node) \
110 for ((node) = (list); (node)->prev; (node) = (node)->prev)
113 * @brief Convinience Macro to get list tail
115 #define LISTTAIL(list, node) \
116 for ((node) = (list); (node)->next; (node) = (node)->next)
118 typedef struct metadata_x {
121 struct metadata_x *prev;
122 struct metadata_x *next;
125 typedef struct privilege_x {
127 struct privilege_x *prev;
128 struct privilege_x *next;
131 typedef struct privileges_x {
132 struct privilege_x *privilege;
133 struct privileges_x *prev;
134 struct privileges_x *next;
137 typedef struct permission_x {
140 struct permission_x *prev;
141 struct permission_x *next;
144 typedef struct icon_x {
150 const char *resolution;
155 typedef struct image_x {
160 struct image_x *prev;
161 struct image_x *next;
164 typedef struct allowed_x {
167 struct allowed_x *prev;
168 struct allowed_x *next;
171 typedef struct request_x {
173 struct request_x *prev;
174 struct request_x *next;
177 typedef struct define_x {
179 struct allowed_x *allowed;
180 struct request_x *request;
181 struct define_x *prev;
182 struct define_x *next;
185 typedef struct datashare_x {
186 struct define_x *define;
187 struct request_x *request;
188 struct datashare_x *prev;
189 struct datashare_x *next;
192 typedef struct description_x {
196 struct description_x *prev;
197 struct description_x *next;
200 typedef struct registry_x {
203 struct registry_x *prev;
204 struct registry_x *next;
207 typedef struct database_x {
210 struct database_x *prev;
211 struct database_x *next;
214 typedef struct layout_x {
217 struct layout_x *prev;
218 struct layout_x *next;
221 typedef struct label_x {
225 struct label_x *prev;
226 struct label_x *next;
229 typedef struct author_x {
234 struct author_x *prev;
235 struct author_x *next;
238 typedef struct license_x {
241 struct license_x *prev;
242 struct license_x *next;
245 typedef struct operation_x {
248 struct operation_x *prev;
249 struct operation_x *next;
252 typedef struct uri_x {
259 typedef struct mime_x {
266 typedef struct subapp_x {
269 struct subapp_x *prev;
270 struct subapp_x *next;
273 typedef struct condition_x {
276 struct condition_x *prev;
277 struct condition_x *next;
280 typedef struct notification_x {
283 struct notification_x *prev;
284 struct notification_x *next;
287 typedef struct appsvc_x {
289 struct operation_x *operation;
292 struct subapp_x *subapp;
293 struct appsvc_x *prev;
294 struct appsvc_x *next;
297 typedef struct appcontrol_x {
299 struct operation_x *operation;
302 struct subapp_x *subapp;
303 struct appcontrol_x *prev;
304 struct appcontrol_x *next;
307 typedef struct category_x{
309 struct category_x *prev;
310 struct category_x *next;
313 typedef struct launchconditions_x {
315 struct condition_x *condition;
316 struct launchconditions_x *prev;
317 struct launchconditions_x *next;
318 } launchconditions_x;
320 typedef struct compatibility_x {
323 struct compatibility_x *prev;
324 struct compatibility_x *next;
327 typedef struct deviceprofile_x {
330 struct deviceprofile_x *prev;
331 struct deviceprofile_x *next;
334 typedef struct resolution_x {
335 const char *mimetype;
336 const char *urischeme;
337 struct resolution_x *prev;
338 struct resolution_x *next;
341 typedef struct capability_x {
342 const char *operationid;
344 struct resolution_x *resolution;
345 struct capability_x *prev;
346 struct capability_x *next;
349 typedef struct datacontrol_x {
350 const char *providerid;
351 struct capability_x *capability;
352 struct datacontrol_x *prev;
353 struct datacontrol_x *next;
356 typedef struct uiapplication_x {
359 const char *nodisplay;
360 const char *multiple;
361 const char *taskmanage;
364 const char *categories;
366 const char *hwacceleration;
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;
379 struct label_x *label;
381 struct image_x *image;
382 struct appsvc_x *appsvc;
383 struct appcontrol_x *appcontrol;
384 struct category_x *category;
385 struct metadata_x *metadata;
386 struct permission_x *permission;
387 struct launchconditions_x *launchconditions;
388 struct notification_x *notification;
389 struct datashare_x *datashare;
390 struct uiapplication_x *prev;
391 struct uiapplication_x *next;
394 typedef struct serviceapplication_x {
398 const char *autorestart;
402 const char *permission_type;
403 struct label_x *label;
405 struct appsvc_x *appsvc;
406 struct appcontrol_x *appcontrol;
407 struct category_x *category;
408 struct metadata_x *metadata;
409 struct permission_x *permission;
410 struct datacontrol_x *datacontrol;
411 struct launchconditions_x *launchconditions;
412 struct notification_x *notification;
413 struct datashare_x *datashare;
414 struct serviceapplication_x *prev;
415 struct serviceapplication_x *next;
416 } serviceapplication_x;
418 typedef struct daemon_x {
421 struct daemon_x *prev;
422 struct daemon_x *next;
425 typedef struct theme_x {
428 struct theme_x *prev;
429 struct theme_x *next;
432 typedef struct font_x {
439 typedef struct ime_x {
446 typedef struct manifest_x {
447 const char *package; /**< package name*/
448 const char *version; /**< package version*/
449 const char *installlocation; /**< package install location*/
450 const char *ns; /**<name space*/
451 const char *removable; /**< package removable flag*/
452 const char *preload; /**< package preload flag*/
453 const char *readonly; /**< package readonly flag*/
454 const char *update; /**< package update flag*/
455 const char *appsetting; /**< package app setting flag*/
456 const char *type; /**< package type*/
457 const char *package_size; /**< package size for external installation*/
458 const char *installed_time; /**< installed time after finishing of installation*/
459 const char *installed_storage; /**< package currently installed storage*/
460 const char *storeclient_id; /**< id of store client for installed package*/
461 const char *mainapp_id; /**< app id of main application*/
462 const char *package_url; /**< app id of main application*/
463 const char *root_path; /**< package root path*/
464 const char *csc_path; /**< package csc path*/
465 const char *nodisplay_setting; /**< package no display setting menu*/
466 struct icon_x *icon; /**< package icon*/
467 struct label_x *label; /**< package label*/
468 struct author_x *author; /**< package author*/
469 struct description_x *description; /**< package description*/
470 struct license_x *license; /**< package license*/
471 struct privileges_x *privileges; /**< package privileges*/
472 struct uiapplication_x *uiapplication; /**< package's ui application*/
473 struct serviceapplication_x *serviceapplication; /**< package's service application*/
474 struct daemon_x *daemon; /**< package daemon*/
475 struct theme_x *theme; /**< package theme*/
476 struct font_x *font; /**< package font*/
477 struct ime_x *ime; /**< package ime*/
478 struct compatibility_x *compatibility; /**< package compatibility*/
479 struct deviceprofile_x *deviceprofile; /**< package device profile*/
483 * @fn char *pkgmgr_parser_get_manifest_file(const char *pkgid)
484 * @brief This API gets the manifest file of the package.
486 * @par This API is for package-manager installer backends.
487 * @par Sync (or) Async : Synchronous API
489 * @param[in] pkgid pointer to package ID
490 * @return manifest file path on success, NULL on failure
492 * @post Free the manifest file pointer that is returned by API
494 static int get_manifest_file(const char *pkgid)
496 char *manifest = NULL;
497 manifest = pkgmgr_parser_get_manifest_file(pkgid);
498 if (manifest == NULL)
500 printf("Manifest File Path is %s\n", manifest);
506 char *pkgmgr_parser_get_manifest_file(const char *pkgid);
509 * @fn int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[])
510 * @brief This API parses the manifest file of the package after installation and stores the data in DB.
512 * @par This API is for package-manager installer backends.
513 * @par Sync (or) Async : Synchronous API
515 * @param[in] manifest pointer to package manifest file
516 * @param[in] tagv array of xml tags or NULL
517 * @return 0 if success, error code(<0) if fail
518 * @retval PMINFO_R_OK success
519 * @retval PMINFO_R_EINVAL invalid argument
520 * @retval PMINFO_R_ERROR internal error
524 static int parse_manifest_file_for_installation(const char *manifest)
527 ret = pkgmgr_parser_parse_manifest_for_installation(manifest, NULL);
534 int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[]);
537 * @fn int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[])
538 * @brief This API parses the manifest file of the package after upgrade and stores the data in DB.
540 * @par This API is for package-manager installer backends.
541 * @par Sync (or) Async : Synchronous API
543 * @param[in] manifest pointer to package manifest file
544 * @param[in] tagv array of xml tags or NULL
545 * @return 0 if success, error code(<0) if fail
546 * @retval PMINFO_R_OK success
547 * @retval PMINFO_R_EINVAL invalid argument
548 * @retval PMINFO_R_ERROR internal error
552 static int parse_manifest_file_for_upgrade(const char *manifest)
555 ret = pkgmgr_parser_parse_manifest_for_upgrade(manifest, NULL);
562 int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[]);
565 * @fn int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[])
566 * @brief This API parses the manifest file of the package after uninstallation and deletes the data from DB.
568 * @par This API is for package-manager installer backends.
569 * @par Sync (or) Async : Synchronous API
571 * @param[in] manifest pointer to package manifest file
572 * @param[in] tagv array of xml tags or NULL
573 * @return 0 if success, error code(<0) if fail
574 * @retval PMINFO_R_OK success
575 * @retval PMINFO_R_EINVAL invalid argument
576 * @retval PMINFO_R_ERROR internal error
580 static int parse_manifest_file_for_uninstallation(const char *manifest)
583 ret = pkgmgr_parser_parse_manifest_for_uninstallation(manifest, NULL);
590 int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[]);
593 * @fn int pkgmgr_parser_check_manifest_validation(const char *manifest)
594 * @brief This API validates the manifest file against the manifest schema.
596 * @par This API is for package-manager installer backends.
597 * @par Sync (or) Async : Synchronous API
599 * @param[in] manifest pointer to package manifest file
600 * @return 0 if success, error code(<0) if fail
601 * @retval PMINFO_R_OK success
602 * @retval PMINFO_R_EINVAL invalid argument
603 * @retval PMINFO_R_ERROR internal error
607 static int validate_manifest_file(const char *manifest)
610 ret = pkgmgr_parser_check_manifest_validation(manifest);
617 int pkgmgr_parser_check_manifest_validation(const char *manifest);
620 * @fn void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
621 * @brief This API will free the manifest pointer by recursively freeing all sub elements.
623 * @par This API is for package-manager installer backends.
624 * @par Sync (or) Async : Synchronous API
626 * @param[in] mfx pointer to parsed manifest data
627 * @pre pkgmgr_parser_process_manifest_xml()
630 static int parse_manifest_file(const char *manifest)
632 manifest_x *mfx = NULL
633 mfx = pkgmgr_parser_process_manifest_xml(manifest);
636 printf("Parsing Manifest Success\n");
637 pkgmgr_parser_free_manifest_xml(mfx);
642 void pkgmgr_parser_free_manifest_xml(manifest_x *mfx);
645 * @fn manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest)
646 * @brief This API parses the manifest file and stores all the data in the manifest structure.
648 * @par This API is for package-manager installer backends.
649 * @par Sync (or) Async : Synchronous API
651 * @param[in] manifest pointer to package manifest file
652 * @return manifest pointer on success, NULL on failure
654 * @post pkgmgr_parser_free_manifest_xml()
656 static int parse_manifest_file(const char *manifest)
658 manifest_x *mfx = NULL
659 mfx = pkgmgr_parser_process_manifest_xml(manifest);
662 printf("Parsing Manifest Success\n");
663 pkgmgr_parser_free_manifest_xml(mfx);
668 manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest);
671 * @fn manifest_x *pkgmgr_parser_get_manifest_info(const char *pkigid)
672 * @brief This API gets the manifest info from DB and stores all the data in the manifest structure.
674 * @par This API is for package-manager installer backends.
675 * @par Sync (or) Async : Synchronous API
677 * @param[in] pkgid package id for package
678 * @return manifest pointer on success, NULL on failure
680 * @post pkgmgr_parser_free_manifest_xml()
682 static int get_manifest_info(const char *pkgid)
684 manifest_x *mfx = NULL
685 mfx = pkgmgr_parser_get_manifest_info(pkgid);
688 printf("Parsing Manifest Success\n");
689 pkgmgr_parser_free_manifest_xml(mfx);
694 manifest_x *pkgmgr_parser_get_manifest_info(const char *pkigid);
696 /* These APIs are intended to call parser directly */
697 typedef int (*ps_iter_fn) (const char *tag, int type, void *userdata);
699 int pkgmgr_parser_has_parser(const char *tag, int *type);
700 int pkgmgr_parser_get_list(ps_iter_fn iter_fn, void *data);
703 * @fn int pkgmgr_parser_run_parser_for_installation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
704 * @brief This API calls the parser directly by supplying the xml docptr. It is used during package installation
706 * @par This API is for package-manager installer backends.
707 * @par Sync (or) Async : Synchronous API
709 * @param[in] docPtr XML doxument pointer
710 * @param[in] tag the xml tag corresponding to the parser that will parse the docPtr
711 * @param[in] pkgid the package id
712 * @return 0 if success, error code(<0) if fail
713 * @retval PMINFO_R_OK success
714 * @retval PMINFO_R_EINVAL invalid argument
715 * @retval PMINFO_R_ERROR internal error
719 static int parse_docptr_for_installation(xmlDocPtr docPtr)
722 ret = pkgmgr_parser_run_parser_for_installation(docPtr, "theme", "com.samsung.test");
729 int pkgmgr_parser_run_parser_for_installation(xmlDocPtr docPtr, const char *tag, const char *pkgid);
732 * @fn int pkgmgr_parser_run_parser_for_upgrade(xmlDocPtr docPtr, const char *tag, const char *pkgid)
733 * @brief This API calls the parser directly by supplying the xml docptr. It is used during package upgrade
735 * @par This API is for package-manager installer backends.
736 * @par Sync (or) Async : Synchronous API
738 * @param[in] docPtr XML doxument pointer
739 * @param[in] tag the xml tag corresponding to the parser that will parse the docPtr
740 * @param[in] pkgid the package id
741 * @return 0 if success, error code(<0) if fail
742 * @retval PMINFO_R_OK success
743 * @retval PMINFO_R_EINVAL invalid argument
744 * @retval PMINFO_R_ERROR internal error
748 static int parse_docptr_for_upgrade(xmlDocPtr docPtr)
751 ret = pkgmgr_parser_run_parser_for_upgrade(docPtr, "theme", "com.samsung.test");
758 int pkgmgr_parser_run_parser_for_upgrade(xmlDocPtr docPtr, const char *tag, const char *pkgid);
761 * @fn int pkgmgr_parser_run_parser_for_uninstallation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
762 * @brief This API calls the parser directly by supplying the xml docptr. It is used during package uninstallation
764 * @par This API is for package-manager installer backends.
765 * @par Sync (or) Async : Synchronous API
767 * @param[in] docPtr XML doxument pointer
768 * @param[in] tag the xml tag corresponding to the parser that will parse the docPtr
769 * @param[in] pkgid the package id
770 * @return 0 if success, error code(<0) if fail
771 * @retval PMINFO_R_OK success
772 * @retval PMINFO_R_EINVAL invalid argument
773 * @retval PMINFO_R_ERROR internal error
777 static int parse_docptr_for_uninstallation(xmlDocPtr docPtr)
780 ret = pkgmgr_parser_run_parser_for_uninstallation(docPtr, "theme", "com.samsung.test");
787 int pkgmgr_parser_run_parser_for_uninstallation(xmlDocPtr docPtr, const char *tag, const char *pkgid);
790 * @fn int pkgmgr_parser_create_desktop_file(manifest_x *mfx)
791 * @brief This API generates the application desktop file
793 * @par This API is for package-manager installer backends.
794 * @par Sync (or) Async : Synchronous API
796 * @param[in] mfx manifest pointer
797 * @return 0 if success, error code(<0) if fail
798 * @retval PMINFO_R_OK success
799 * @retval PMINFO_R_EINVAL invalid argument
800 * @retval PMINFO_R_ERROR internal error
801 * @pre pkgmgr_parser_process_manifest_xml()
802 * @post pkgmgr_parser_free_manifest_xml()
804 static int create_desktop_file(char *manifest)
807 manifest_x *mfx = NULL;
808 mfx = pkgmgr_parser_process_manifest_xml(manifest);
809 ret = pkgmgr_parser_create_desktop_file(mfx);
812 pkgmgr_parser_free_manifest_xml(mfx);
817 int pkgmgr_parser_create_desktop_file(manifest_x *mfx);
823 #endif /* __PKGMGR_PARSER_H__ */