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 permission_x {
128 struct permission_x *prev;
129 struct permission_x *next;
132 typedef struct icon_x {
138 const char *resolution;
143 typedef struct image_x {
152 typedef struct allowed_x {
155 struct allowed_x *prev;
156 struct allowed_x *next;
159 typedef struct request_x {
161 struct request_x *prev;
162 struct request_x *next;
165 typedef struct define_x {
167 struct allowed_x *allowed;
168 struct request_x *request;
169 struct define_x *prev;
170 struct define_x *next;
173 typedef struct datashare_x {
174 struct define_x *define;
175 struct request_x *request;
176 struct datashare_x *prev;
177 struct datashare_x *next;
180 typedef struct description_x {
184 struct description_x *prev;
185 struct description_x *next;
188 typedef struct registry_x {
191 struct registry_x *prev;
192 struct registry_x *next;
195 typedef struct database_x {
198 struct database_x *prev;
199 struct database_x *next;
202 typedef struct layout_x {
205 struct layout_x *prev;
206 struct layout_x *next;
209 typedef struct label_x {
213 struct label_x *prev;
214 struct label_x *next;
217 typedef struct author_x {
222 struct author_x *prev;
223 struct author_x *next;
226 typedef struct license_x {
229 struct license_x *prev;
230 struct license_x *next;
233 typedef struct operation_x {
236 struct operation_x *prev;
237 struct operation_x *next;
240 typedef struct uri_x {
247 typedef struct mime_x {
254 typedef struct subapp_x {
257 struct subapp_x *prev;
258 struct subapp_x *next;
261 typedef struct condition_x {
264 struct condition_x *prev;
265 struct condition_x *next;
268 typedef struct notification_x {
271 struct notification_x *prev;
272 struct notification_x *next;
275 typedef struct appsvc_x {
277 struct operation_x *operation;
280 struct subapp_x *subapp;
281 struct appsvc_x *prev;
282 struct appsvc_x *next;
285 typedef struct appcontrol_x {
287 struct operation_x *operation;
290 struct subapp_x *subapp;
291 struct appcontrol_x *prev;
292 struct appcontrol_x *next;
295 typedef struct category_x{
297 struct category_x *prev;
298 struct category_x *next;
301 typedef struct launchconditions_x {
303 struct condition_x *condition;
304 struct launchconditions_x *prev;
305 struct launchconditions_x *next;
306 } launchconditions_x;
308 typedef struct compatibility_x {
311 struct compatibility_x *prev;
312 struct compatibility_x *next;
315 typedef struct deviceprofile_x {
318 struct deviceprofile_x *prev;
319 struct deviceprofile_x *next;
322 typedef struct resolution_x {
323 const char *mimetype;
324 const char *urischeme;
325 struct resolution_x *prev;
326 struct resolution_x *next;
329 typedef struct capability_x {
330 const char *operationid;
332 struct resolution_x *resolution;
333 struct capability_x *prev;
334 struct capability_x *next;
337 typedef struct datacontrol_x {
338 const char *providerid;
339 struct capability_x *capability;
340 struct datacontrol_x *prev;
341 struct datacontrol_x *next;
344 typedef struct uiapplication_x {
347 const char *nodisplay;
348 const char *multiple;
349 const char *taskmanage;
352 const char *categories;
354 const char *hwacceleration;
357 const char *recentimage;
358 const char *indicatordisplay;
359 const char *portraitimg;
360 const char *landscapeimg;
361 const char *guestmode_visibility;
362 struct label_x *label;
364 struct image_x *image;
365 struct appsvc_x *appsvc;
366 struct appcontrol_x *appcontrol;
367 struct category_x *category;
368 struct metadata_x *metadata;
369 struct permission_x *permission;
370 struct launchconditions_x *launchconditions;
371 struct notification_x *notification;
372 struct datashare_x *datashare;
373 struct uiapplication_x *prev;
374 struct uiapplication_x *next;
377 typedef struct serviceapplication_x {
381 const char *autorestart;
385 struct label_x *label;
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 datacontrol_x *datacontrol;
393 struct launchconditions_x *launchconditions;
394 struct notification_x *notification;
395 struct datashare_x *datashare;
396 struct serviceapplication_x *prev;
397 struct serviceapplication_x *next;
398 } serviceapplication_x;
400 typedef struct daemon_x {
403 struct daemon_x *prev;
404 struct daemon_x *next;
407 typedef struct theme_x {
410 struct theme_x *prev;
411 struct theme_x *next;
414 typedef struct font_x {
421 typedef struct ime_x {
428 typedef struct manifest_x {
429 const char *package; /**< package name*/
430 const char *version; /**< package version*/
431 const char *installlocation; /**< package install location*/
432 const char *ns; /**<name space*/
433 const char *removable; /**< package removable flag*/
434 const char *preload; /**< package preload flag*/
435 const char *readonly; /**< package readonly flag*/
436 const char *update; /**< package update flag*/
437 const char *appsetting; /**< package app setting flag*/
438 const char *type; /**< package type*/
439 const char *package_size; /**< package size for external installation*/
440 const char *installed_time; /**< installed time after finishing of installation*/
441 const char *installed_storage; /**< package currently installed storage*/
442 const char *storeclient_id; /**< id of store client for installed package*/
443 const char *mainapp_id; /**< app id of main application*/
444 const char *package_url; /**< app id of main application*/
445 const char *root_path; /**< package root path*/
446 struct icon_x *icon; /**< package icon*/
447 struct label_x *label; /**< package label*/
448 struct author_x *author; /**< package author*/
449 struct description_x *description; /**< package description*/
450 struct license_x *license; /**< package license*/
451 struct uiapplication_x *uiapplication; /**< package's ui application*/
452 struct serviceapplication_x *serviceapplication; /**< package's service application*/
453 struct daemon_x *daemon; /**< package daemon*/
454 struct theme_x *theme; /**< package theme*/
455 struct font_x *font; /**< package font*/
456 struct ime_x *ime; /**< package ime*/
457 struct compatibility_x *compatibility; /**< package compatibility*/
458 struct deviceprofile_x *deviceprofile; /**< package device profile*/
462 * @fn char *pkgmgr_parser_get_manifest_file(const char *pkgid)
463 * @brief This API gets the manifest file of the package.
465 * @par This API is for package-manager installer backends.
466 * @par Sync (or) Async : Synchronous API
468 * @param[in] pkgid pointer to package ID
469 * @return manifest file path on success, NULL on failure
471 * @post Free the manifest file pointer that is returned by API
473 static int get_manifest_file(const char *pkgid)
475 char *manifest = NULL;
476 manifest = pkgmgr_parser_get_manifest_file(pkgid);
477 if (manifest == NULL)
479 printf("Manifest File Path is %s\n", manifest);
485 char *pkgmgr_parser_get_manifest_file(const char *pkgid);
488 * @fn int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[])
489 * @brief This API parses the manifest file of the package after installation and stores the data in DB.
491 * @par This API is for package-manager installer backends.
492 * @par Sync (or) Async : Synchronous API
494 * @param[in] manifest pointer to package manifest file
495 * @param[in] tagv array of xml tags or NULL
496 * @return 0 if success, error code(<0) if fail
497 * @retval PMINFO_R_OK success
498 * @retval PMINFO_R_EINVAL invalid argument
499 * @retval PMINFO_R_ERROR internal error
503 static int parse_manifest_file_for_installation(const char *manifest)
506 ret = pkgmgr_parser_parse_manifest_for_installation(manifest, NULL);
513 int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[]);
516 * @fn int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[])
517 * @brief This API parses the manifest file of the package after upgrade 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_upgrade(const char *manifest)
534 ret = pkgmgr_parser_parse_manifest_for_upgrade(manifest, NULL);
541 int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[]);
544 * @fn int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[])
545 * @brief This API parses the manifest file of the package after uninstallation and deletes the data from 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_uninstallation(const char *manifest)
562 ret = pkgmgr_parser_parse_manifest_for_uninstallation(manifest, NULL);
569 int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[]);
572 * @fn int pkgmgr_parser_check_manifest_validation(const char *manifest)
573 * @brief This API validates the manifest file against the manifest schema.
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 * @return 0 if success, error code(<0) if fail
580 * @retval PMINFO_R_OK success
581 * @retval PMINFO_R_EINVAL invalid argument
582 * @retval PMINFO_R_ERROR internal error
586 static int validate_manifest_file(const char *manifest)
589 ret = pkgmgr_parser_check_manifest_validation(manifest);
596 int pkgmgr_parser_check_manifest_validation(const char *manifest);
599 * @fn void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
600 * @brief This API will free the manifest pointer by recursively freeing all sub elements.
602 * @par This API is for package-manager installer backends.
603 * @par Sync (or) Async : Synchronous API
605 * @param[in] mfx pointer to parsed manifest data
606 * @pre pkgmgr_parser_process_manifest_xml()
609 static int parse_manifest_file(const char *manifest)
611 manifest_x *mfx = NULL
612 mfx = pkgmgr_parser_process_manifest_xml(manifest);
615 printf("Parsing Manifest Success\n");
616 pkgmgr_parser_free_manifest_xml(mfx);
621 void pkgmgr_parser_free_manifest_xml(manifest_x *mfx);
624 * @fn manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest)
625 * @brief This API parses the manifest file and stores all the data in the manifest structure.
627 * @par This API is for package-manager installer backends.
628 * @par Sync (or) Async : Synchronous API
630 * @param[in] manifest pointer to package manifest file
631 * @return manifest pointer on success, NULL on failure
633 * @post pkgmgr_parser_free_manifest_xml()
635 static int parse_manifest_file(const char *manifest)
637 manifest_x *mfx = NULL
638 mfx = pkgmgr_parser_process_manifest_xml(manifest);
641 printf("Parsing Manifest Success\n");
642 pkgmgr_parser_free_manifest_xml(mfx);
647 manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest);
650 * @fn manifest_x *pkgmgr_parser_get_manifest_info(const char *pkigid)
651 * @brief This API gets the manifest info from DB and stores all the data in the manifest structure.
653 * @par This API is for package-manager installer backends.
654 * @par Sync (or) Async : Synchronous API
656 * @param[in] pkgid package id for package
657 * @return manifest pointer on success, NULL on failure
659 * @post pkgmgr_parser_free_manifest_xml()
661 static int get_manifest_info(const char *pkgid)
663 manifest_x *mfx = NULL
664 mfx = pkgmgr_parser_get_manifest_info(pkgid);
667 printf("Parsing Manifest Success\n");
668 pkgmgr_parser_free_manifest_xml(mfx);
673 manifest_x *pkgmgr_parser_get_manifest_info(const char *pkigid);
675 /* These APIs are intended to call parser directly */
676 typedef int (*ps_iter_fn) (const char *tag, int type, void *userdata);
678 int pkgmgr_parser_has_parser(const char *tag, int *type);
679 int pkgmgr_parser_get_list(ps_iter_fn iter_fn, void *data);
682 * @fn int pkgmgr_parser_run_parser_for_installation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
683 * @brief This API calls the parser directly by supplying the xml docptr. It is used during package installation
685 * @par This API is for package-manager installer backends.
686 * @par Sync (or) Async : Synchronous API
688 * @param[in] docPtr XML doxument pointer
689 * @param[in] tag the xml tag corresponding to the parser that will parse the docPtr
690 * @param[in] pkgid the package id
691 * @return 0 if success, error code(<0) if fail
692 * @retval PMINFO_R_OK success
693 * @retval PMINFO_R_EINVAL invalid argument
694 * @retval PMINFO_R_ERROR internal error
698 static int parse_docptr_for_installation(xmlDocPtr docPtr)
701 ret = pkgmgr_parser_run_parser_for_installation(docPtr, "theme", "com.samsung.test");
708 int pkgmgr_parser_run_parser_for_installation(xmlDocPtr docPtr, const char *tag, const char *pkgid);
711 * @fn int pkgmgr_parser_run_parser_for_upgrade(xmlDocPtr docPtr, const char *tag, const char *pkgid)
712 * @brief This API calls the parser directly by supplying the xml docptr. It is used during package upgrade
714 * @par This API is for package-manager installer backends.
715 * @par Sync (or) Async : Synchronous API
717 * @param[in] docPtr XML doxument pointer
718 * @param[in] tag the xml tag corresponding to the parser that will parse the docPtr
719 * @param[in] pkgid the package id
720 * @return 0 if success, error code(<0) if fail
721 * @retval PMINFO_R_OK success
722 * @retval PMINFO_R_EINVAL invalid argument
723 * @retval PMINFO_R_ERROR internal error
727 static int parse_docptr_for_upgrade(xmlDocPtr docPtr)
730 ret = pkgmgr_parser_run_parser_for_upgrade(docPtr, "theme", "com.samsung.test");
737 int pkgmgr_parser_run_parser_for_upgrade(xmlDocPtr docPtr, const char *tag, const char *pkgid);
740 * @fn int pkgmgr_parser_run_parser_for_uninstallation(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 uninstallation
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_uninstallation(xmlDocPtr docPtr)
759 ret = pkgmgr_parser_run_parser_for_uninstallation(docPtr, "theme", "com.samsung.test");
766 int pkgmgr_parser_run_parser_for_uninstallation(xmlDocPtr docPtr, const char *tag, const char *pkgid);
769 * @fn int pkgmgr_parser_create_desktop_file(manifest_x *mfx)
770 * @brief This API generates the application desktop file
772 * @par This API is for package-manager installer backends.
773 * @par Sync (or) Async : Synchronous API
775 * @param[in] mfx manifest pointer
776 * @return 0 if success, error code(<0) if fail
777 * @retval PMINFO_R_OK success
778 * @retval PMINFO_R_EINVAL invalid argument
779 * @retval PMINFO_R_ERROR internal error
780 * @pre pkgmgr_parser_process_manifest_xml()
781 * @post pkgmgr_parser_free_manifest_xml()
783 static int create_desktop_file(char *manifest)
786 manifest_x *mfx = NULL;
787 mfx = pkgmgr_parser_process_manifest_xml(manifest);
788 ret = pkgmgr_parser_create_desktop_file(mfx);
791 pkgmgr_parser_free_manifest_xml(mfx);
796 int pkgmgr_parser_create_desktop_file(manifest_x *mfx);
802 #endif /* __PKGMGR_PARSER_H__ */