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 SYSCONFDIR "/package-manager/parser_path.conf"
54 #define PKG_STRING_LEN_MAX 1024
56 #define PKGMGR_PARSER_EMPTY_STR ""
59 * @brief List definitions.
60 * All lists are doubly-linked, the last element is stored to list pointer,
61 * which means that lists must be looped using the prev pointer, or by
62 * calling LISTHEAD first to go to start in order to use the next pointer.
66 * @brief Convinience Macro to add node in list
69 #define LISTADD(list, node) \
71 (node)->prev = (list); \
72 if (list) (node)->next = (list)->next; \
73 else (node)->next = NULL; \
74 if (list) (list)->next = (node); \
79 * @brief Convinience Macro to add one node to another node
81 #define NODEADD(node1, node2) \
83 (node2)->prev = (node1); \
84 (node2)->next = (node1)->next; \
85 if ((node1)->next) (node1)->next->prev = (node2); \
86 (node1)->next = (node2); \
90 * @brief Convinience Macro to concatenate two lists
92 #define LISTCAT(list, first, last) \
93 if ((first) && (last)) { \
94 (first)->prev = (list); \
99 * @brief Convinience Macro to delete node from list
101 #define LISTDEL(list, node) \
103 if ((node)->prev) (node)->prev->next = (node)->next; \
104 if ((node)->next) (node)->next->prev = (node)->prev; \
105 if (!((node)->prev) && !((node)->next)) (list) = NULL; \
109 * @brief Convinience Macro to get list head
111 #define LISTHEAD(list, node) \
112 for ((node) = (list); (node)->prev; (node) = (node)->prev)
115 * @brief Convinience Macro to get list tail
117 #define LISTTAIL(list, node) \
118 for ((node) = (list); (node)->next; (node) = (node)->next)
120 typedef struct metadata_x {
123 struct metadata_x *prev;
124 struct metadata_x *next;
127 typedef struct privilege_x {
129 struct privilege_x *prev;
130 struct privilege_x *next;
133 typedef struct privileges_x {
134 struct privilege_x *privilege;
135 struct privileges_x *prev;
136 struct privileges_x *next;
139 typedef struct permission_x {
142 struct permission_x *prev;
143 struct permission_x *next;
146 typedef struct icon_x {
152 const char *resolution;
157 typedef struct image_x {
162 struct image_x *prev;
163 struct image_x *next;
166 typedef struct allowed_x {
169 struct allowed_x *prev;
170 struct allowed_x *next;
173 typedef struct request_x {
175 struct request_x *prev;
176 struct request_x *next;
179 typedef struct define_x {
181 struct allowed_x *allowed;
182 struct request_x *request;
183 struct define_x *prev;
184 struct define_x *next;
187 typedef struct datashare_x {
188 struct define_x *define;
189 struct request_x *request;
190 struct datashare_x *prev;
191 struct datashare_x *next;
194 typedef struct description_x {
198 struct description_x *prev;
199 struct description_x *next;
202 typedef struct registry_x {
205 struct registry_x *prev;
206 struct registry_x *next;
209 typedef struct database_x {
212 struct database_x *prev;
213 struct database_x *next;
216 typedef struct layout_x {
219 struct layout_x *prev;
220 struct layout_x *next;
223 typedef struct label_x {
227 struct label_x *prev;
228 struct label_x *next;
231 typedef struct author_x {
236 struct author_x *prev;
237 struct author_x *next;
240 typedef struct license_x {
243 struct license_x *prev;
244 struct license_x *next;
247 typedef struct operation_x {
250 struct operation_x *prev;
251 struct operation_x *next;
254 typedef struct uri_x {
261 typedef struct mime_x {
268 typedef struct subapp_x {
271 struct subapp_x *prev;
272 struct subapp_x *next;
275 typedef struct condition_x {
278 struct condition_x *prev;
279 struct condition_x *next;
282 typedef struct notification_x {
285 struct notification_x *prev;
286 struct notification_x *next;
289 typedef struct appsvc_x {
291 struct operation_x *operation;
294 struct subapp_x *subapp;
295 struct appsvc_x *prev;
296 struct appsvc_x *next;
299 typedef struct appcontrol_x {
301 struct operation_x *operation;
304 struct subapp_x *subapp;
305 struct appcontrol_x *prev;
306 struct appcontrol_x *next;
309 typedef struct category_x{
311 struct category_x *prev;
312 struct category_x *next;
315 typedef struct launchconditions_x {
317 struct condition_x *condition;
318 struct launchconditions_x *prev;
319 struct launchconditions_x *next;
320 } launchconditions_x;
322 typedef struct compatibility_x {
325 struct compatibility_x *prev;
326 struct compatibility_x *next;
329 typedef struct deviceprofile_x {
332 struct deviceprofile_x *prev;
333 struct deviceprofile_x *next;
336 typedef struct resolution_x {
337 const char *mimetype;
338 const char *urischeme;
339 struct resolution_x *prev;
340 struct resolution_x *next;
343 typedef struct capability_x {
344 const char *operationid;
346 struct resolution_x *resolution;
347 struct capability_x *prev;
348 struct capability_x *next;
351 typedef struct datacontrol_x {
352 const char *providerid;
353 struct capability_x *capability;
354 struct datacontrol_x *prev;
355 struct datacontrol_x *next;
358 typedef struct uiapplication_x {
361 const char *nodisplay;
362 const char *multiple;
363 const char *taskmanage;
366 const char *categories;
368 const char *hwacceleration;
369 const char *screenreader;
372 const char *recentimage;
373 const char *launchcondition;
374 const char *indicatordisplay;
375 const char *portraitimg;
376 const char *landscapeimg;
377 const char *guestmode_visibility;
378 const char *app_component;
379 const char *permission_type;
380 const char *component_type;
383 const char *submode_mainid;
384 struct label_x *label;
386 struct image_x *image;
387 struct appsvc_x *appsvc;
388 struct appcontrol_x *appcontrol;
389 struct category_x *category;
390 struct metadata_x *metadata;
391 struct permission_x *permission;
392 struct launchconditions_x *launchconditions;
393 struct notification_x *notification;
394 struct datashare_x *datashare;
395 struct uiapplication_x *prev;
396 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 *package; /**< package name*/
453 const char *version; /**< package version*/
454 const char *installlocation; /**< package install location*/
455 const char *ns; /**<name space*/
456 const char *removable; /**< package removable flag*/
457 const char *preload; /**< package preload flag*/
458 const char *readonly; /**< package readonly flag*/
459 const char *update; /**< package update flag*/
460 const char *appsetting; /**< package app setting flag*/
461 const char *system; /**< package system flag*/
462 const char *type; /**< package type*/
463 const char *package_size; /**< package size for external installation*/
464 const char *installed_time; /**< installed time after finishing of installation*/
465 const char *installed_storage; /**< package currently installed storage*/
466 const char *storeclient_id; /**< id of store client for installed package*/
467 const char *mainapp_id; /**< app id of main application*/
468 const char *package_url; /**< app id of main application*/
469 const char *root_path; /**< package root path*/
470 const char *csc_path; /**< package csc path*/
471 const char *nodisplay_setting; /**< package no display setting menu*/
472 const char *main_package; /**< main package id for sub-package(ug)*/
473 struct icon_x *icon; /**< package icon*/
474 struct label_x *label; /**< package label*/
475 struct author_x *author; /**< package author*/
476 struct description_x *description; /**< package description*/
477 struct license_x *license; /**< package license*/
478 struct privileges_x *privileges; /**< package privileges*/
479 struct uiapplication_x *uiapplication; /**< package's ui application*/
480 struct serviceapplication_x *serviceapplication; /**< package's service application*/
481 struct daemon_x *daemon; /**< package daemon*/
482 struct theme_x *theme; /**< package theme*/
483 struct font_x *font; /**< package font*/
484 struct ime_x *ime; /**< package ime*/
485 struct compatibility_x *compatibility; /**< package compatibility*/
486 struct deviceprofile_x *deviceprofile; /**< package device profile*/
490 * @fn char *pkgmgr_parser_get_manifest_file(const char *pkgid)
491 * @brief This API gets the manifest file of the package.
493 * @par This API is for package-manager installer backends.
494 * @par Sync (or) Async : Synchronous API
496 * @param[in] pkgid pointer to package ID
497 * @return manifest file path on success, NULL on failure
499 * @post Free the manifest file pointer that is returned by API
501 static int get_manifest_file(const char *pkgid)
503 char *manifest = NULL;
504 manifest = pkgmgr_parser_get_manifest_file(pkgid);
505 if (manifest == NULL)
507 printf("Manifest File Path is %s\n", manifest);
513 char *pkgmgr_parser_get_manifest_file(const char *pkgid);
516 * @fn int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[])
517 * @brief This API parses the manifest file of the package after installation and stores the data in DB.
519 * @par This API is for package-manager installer backends.
520 * @par Sync (or) Async : Synchronous API
522 * @param[in] manifest pointer to package manifest file
523 * @param[in] tagv array of xml tags or NULL
524 * @return 0 if success, error code(<0) if fail
525 * @retval PMINFO_R_OK success
526 * @retval PMINFO_R_EINVAL invalid argument
527 * @retval PMINFO_R_ERROR internal error
531 static int parse_manifest_file_for_installation(const char *manifest)
534 ret = pkgmgr_parser_parse_manifest_for_installation(manifest, NULL);
541 int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[]);
544 * @fn int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[])
545 * @brief This API parses the manifest file of the package after upgrade and stores the data in DB.
547 * @par This API is for package-manager installer backends.
548 * @par Sync (or) Async : Synchronous API
550 * @param[in] manifest pointer to package manifest file
551 * @param[in] tagv array of xml tags or NULL
552 * @return 0 if success, error code(<0) if fail
553 * @retval PMINFO_R_OK success
554 * @retval PMINFO_R_EINVAL invalid argument
555 * @retval PMINFO_R_ERROR internal error
559 static int parse_manifest_file_for_upgrade(const char *manifest)
562 ret = pkgmgr_parser_parse_manifest_for_upgrade(manifest, NULL);
569 int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[]);
572 * @fn int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[])
573 * @brief This API parses the manifest file of the package after uninstallation and deletes the data from 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] tagv array of xml tags or NULL
580 * @return 0 if success, error code(<0) if fail
581 * @retval PMINFO_R_OK success
582 * @retval PMINFO_R_EINVAL invalid argument
583 * @retval PMINFO_R_ERROR internal error
587 static int parse_manifest_file_for_uninstallation(const char *manifest)
590 ret = pkgmgr_parser_parse_manifest_for_uninstallation(manifest, NULL);
597 int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[]);
600 * @fn int pkgmgr_parser_parse_manifest_for_preload()
601 * @brief This API update preload information to DB.
603 * @par This API is for package-manager installer backends.
604 * @par Sync (or) Async : Synchronous API
606 * @return 0 if success, error code(<0) if fail
607 * @retval PMINFO_R_OK success
608 * @retval PMINFO_R_EINVAL invalid argument
609 * @retval PMINFO_R_ERROR internal error
613 static int parser_parse_manifest_for_preload()
616 ret = pkgmgr_parser_parse_manifest_for_preload();
623 int pkgmgr_parser_parse_manifest_for_preload();
626 * @fn int pkgmgr_parser_check_manifest_validation(const char *manifest)
627 * @brief This API validates the manifest file against the manifest schema.
629 * @par This API is for package-manager installer backends.
630 * @par Sync (or) Async : Synchronous API
632 * @param[in] manifest pointer to package manifest file
633 * @return 0 if success, error code(<0) if fail
634 * @retval PMINFO_R_OK success
635 * @retval PMINFO_R_EINVAL invalid argument
636 * @retval PMINFO_R_ERROR internal error
640 static int validate_manifest_file(const char *manifest)
643 ret = pkgmgr_parser_check_manifest_validation(manifest);
650 int pkgmgr_parser_check_manifest_validation(const char *manifest);
653 * @fn void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
654 * @brief This API will free the manifest pointer by recursively freeing all sub elements.
656 * @par This API is for package-manager installer backends.
657 * @par Sync (or) Async : Synchronous API
659 * @param[in] mfx pointer to parsed manifest data
660 * @pre pkgmgr_parser_process_manifest_xml()
663 static int parse_manifest_file(const char *manifest)
665 manifest_x *mfx = NULL
666 mfx = pkgmgr_parser_process_manifest_xml(manifest);
669 printf("Parsing Manifest Success\n");
670 pkgmgr_parser_free_manifest_xml(mfx);
675 void pkgmgr_parser_free_manifest_xml(manifest_x *mfx);
678 * @fn manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest)
679 * @brief This API parses the manifest file and stores all the data in the manifest structure.
681 * @par This API is for package-manager installer backends.
682 * @par Sync (or) Async : Synchronous API
684 * @param[in] manifest pointer to package manifest file
685 * @return manifest pointer on success, NULL on failure
687 * @post pkgmgr_parser_free_manifest_xml()
689 static int parse_manifest_file(const char *manifest)
691 manifest_x *mfx = NULL
692 mfx = pkgmgr_parser_process_manifest_xml(manifest);
695 printf("Parsing Manifest Success\n");
696 pkgmgr_parser_free_manifest_xml(mfx);
701 manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest);
704 * @fn manifest_x *pkgmgr_parser_get_manifest_info(const char *pkigid)
705 * @brief This API gets the manifest info from DB and stores all the data in the manifest structure.
707 * @par This API is for package-manager installer backends.
708 * @par Sync (or) Async : Synchronous API
710 * @param[in] pkgid package id for package
711 * @return manifest pointer on success, NULL on failure
713 * @post pkgmgr_parser_free_manifest_xml()
715 static int get_manifest_info(const char *pkgid)
717 manifest_x *mfx = NULL
718 mfx = pkgmgr_parser_get_manifest_info(pkgid);
721 printf("Parsing Manifest Success\n");
722 pkgmgr_parser_free_manifest_xml(mfx);
727 manifest_x *pkgmgr_parser_get_manifest_info(const char *pkigid);
729 /* These APIs are intended to call parser directly */
730 typedef int (*ps_iter_fn) (const char *tag, int type, void *userdata);
732 int pkgmgr_parser_has_parser(const char *tag, int *type);
733 int pkgmgr_parser_get_list(ps_iter_fn iter_fn, void *data);
736 * @fn int pkgmgr_parser_run_parser_for_installation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
737 * @brief This API calls the parser directly by supplying the xml docptr. It is used during package installation
739 * @par This API is for package-manager installer backends.
740 * @par Sync (or) Async : Synchronous API
742 * @param[in] docPtr XML doxument pointer
743 * @param[in] tag the xml tag corresponding to the parser that will parse the docPtr
744 * @param[in] pkgid the package id
745 * @return 0 if success, error code(<0) if fail
746 * @retval PMINFO_R_OK success
747 * @retval PMINFO_R_EINVAL invalid argument
748 * @retval PMINFO_R_ERROR internal error
752 static int parse_docptr_for_installation(xmlDocPtr docPtr)
755 ret = pkgmgr_parser_run_parser_for_installation(docPtr, "theme", "com.samsung.test");
762 int pkgmgr_parser_run_parser_for_installation(xmlDocPtr docPtr, const char *tag, const char *pkgid);
765 * @fn int pkgmgr_parser_run_parser_for_upgrade(xmlDocPtr docPtr, const char *tag, const char *pkgid)
766 * @brief This API calls the parser directly by supplying the xml docptr. It is used during package upgrade
768 * @par This API is for package-manager installer backends.
769 * @par Sync (or) Async : Synchronous API
771 * @param[in] docPtr XML doxument pointer
772 * @param[in] tag the xml tag corresponding to the parser that will parse the docPtr
773 * @param[in] pkgid the package id
774 * @return 0 if success, error code(<0) if fail
775 * @retval PMINFO_R_OK success
776 * @retval PMINFO_R_EINVAL invalid argument
777 * @retval PMINFO_R_ERROR internal error
781 static int parse_docptr_for_upgrade(xmlDocPtr docPtr)
784 ret = pkgmgr_parser_run_parser_for_upgrade(docPtr, "theme", "com.samsung.test");
791 int pkgmgr_parser_run_parser_for_upgrade(xmlDocPtr docPtr, const char *tag, const char *pkgid);
794 * @fn int pkgmgr_parser_run_parser_for_uninstallation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
795 * @brief This API calls the parser directly by supplying the xml docptr. It is used during package uninstallation
797 * @par This API is for package-manager installer backends.
798 * @par Sync (or) Async : Synchronous API
800 * @param[in] docPtr XML doxument pointer
801 * @param[in] tag the xml tag corresponding to the parser that will parse the docPtr
802 * @param[in] pkgid the package id
803 * @return 0 if success, error code(<0) if fail
804 * @retval PMINFO_R_OK success
805 * @retval PMINFO_R_EINVAL invalid argument
806 * @retval PMINFO_R_ERROR internal error
810 static int parse_docptr_for_uninstallation(xmlDocPtr docPtr)
813 ret = pkgmgr_parser_run_parser_for_uninstallation(docPtr, "theme", "com.samsung.test");
820 int pkgmgr_parser_run_parser_for_uninstallation(xmlDocPtr docPtr, const char *tag, const char *pkgid);
825 * @fn int pkgmgr_parser_create_desktop_file(manifest_x *mfx)
826 * @brief This API generates the application desktop file
828 * @par This API is for package-manager installer backends.
829 * @par Sync (or) Async : Synchronous API
831 * @param[in] mfx manifest pointer
832 * @return 0 if success, error code(<0) if fail
833 * @retval PMINFO_R_OK success
834 * @retval PMINFO_R_EINVAL invalid argument
835 * @retval PMINFO_R_ERROR internal error
836 * @pre pkgmgr_parser_process_manifest_xml()
837 * @post pkgmgr_parser_free_manifest_xml()
839 static int create_desktop_file(char *manifest)
842 manifest_x *mfx = NULL;
843 mfx = pkgmgr_parser_process_manifest_xml(manifest);
844 ret = pkgmgr_parser_create_desktop_file(mfx);
847 pkgmgr_parser_free_manifest_xml(mfx);
852 int pkgmgr_parser_create_desktop_file(manifest_x *mfx);
858 #endif /* __PKGMGR_PARSER_H__ */