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 *type; /**< package type*/
437 const char *package_size; /**< package size for external installation*/
438 const char *installed_time; /**< installed time after finishing of installation*/
439 const char *storeclient_id; /**< id of store client for installed package*/
440 const char *mainapp_id; /**< app id of main application*/
441 const char *package_url; /**< app id of main application*/
442 const char *root_path; /**< package root path*/
443 struct icon_x *icon; /**< package icon*/
444 struct label_x *label; /**< package label*/
445 struct author_x *author; /**< package author*/
446 struct description_x *description; /**< package description*/
447 struct license_x *license; /**< package license*/
448 struct uiapplication_x *uiapplication; /**< package's ui application*/
449 struct serviceapplication_x *serviceapplication; /**< package's service application*/
450 struct daemon_x *daemon; /**< package daemon*/
451 struct theme_x *theme; /**< package theme*/
452 struct font_x *font; /**< package font*/
453 struct ime_x *ime; /**< package ime*/
454 struct compatibility_x *compatibility; /**< package compatibility*/
455 struct deviceprofile_x *deviceprofile; /**< package device profile*/
459 * @fn char *pkgmgr_parser_get_manifest_file(const char *pkgid)
460 * @brief This API gets the manifest file of the package.
462 * @par This API is for package-manager installer backends.
463 * @par Sync (or) Async : Synchronous API
465 * @param[in] pkgid pointer to package ID
466 * @return manifest file path on success, NULL on failure
468 * @post Free the manifest file pointer that is returned by API
470 static int get_manifest_file(const char *pkgid)
472 char *manifest = NULL;
473 manifest = pkgmgr_parser_get_manifest_file(pkgid);
474 if (manifest == NULL)
476 printf("Manifest File Path is %s\n", manifest);
482 char *pkgmgr_parser_get_manifest_file(const char *pkgid);
485 * @fn int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[])
486 * @brief This API parses the manifest file of the package after installation and stores the data in DB.
488 * @par This API is for package-manager installer backends.
489 * @par Sync (or) Async : Synchronous API
491 * @param[in] manifest pointer to package manifest file
492 * @param[in] tagv array of xml tags or NULL
493 * @return 0 if success, error code(<0) if fail
494 * @retval PMINFO_R_OK success
495 * @retval PMINFO_R_EINVAL invalid argument
496 * @retval PMINFO_R_ERROR internal error
500 static int parse_manifest_file_for_installation(const char *manifest)
503 ret = pkgmgr_parser_parse_manifest_for_installation(manifest, NULL);
510 int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[]);
513 * @fn int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[])
514 * @brief This API parses the manifest file of the package after upgrade and stores the data in DB.
516 * @par This API is for package-manager installer backends.
517 * @par Sync (or) Async : Synchronous API
519 * @param[in] manifest pointer to package manifest file
520 * @param[in] tagv array of xml tags or NULL
521 * @return 0 if success, error code(<0) if fail
522 * @retval PMINFO_R_OK success
523 * @retval PMINFO_R_EINVAL invalid argument
524 * @retval PMINFO_R_ERROR internal error
528 static int parse_manifest_file_for_upgrade(const char *manifest)
531 ret = pkgmgr_parser_parse_manifest_for_upgrade(manifest, NULL);
538 int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[]);
541 * @fn int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[])
542 * @brief This API parses the manifest file of the package after uninstallation and deletes the data from 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] tagv array of xml tags or NULL
549 * @return 0 if success, error code(<0) if fail
550 * @retval PMINFO_R_OK success
551 * @retval PMINFO_R_EINVAL invalid argument
552 * @retval PMINFO_R_ERROR internal error
556 static int parse_manifest_file_for_uninstallation(const char *manifest)
559 ret = pkgmgr_parser_parse_manifest_for_uninstallation(manifest, NULL);
566 int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[]);
569 * @fn int pkgmgr_parser_check_manifest_validation(const char *manifest)
570 * @brief This API validates the manifest file against the manifest schema.
572 * @par This API is for package-manager installer backends.
573 * @par Sync (or) Async : Synchronous API
575 * @param[in] manifest pointer to package manifest file
576 * @return 0 if success, error code(<0) if fail
577 * @retval PMINFO_R_OK success
578 * @retval PMINFO_R_EINVAL invalid argument
579 * @retval PMINFO_R_ERROR internal error
583 static int validate_manifest_file(const char *manifest)
586 ret = pkgmgr_parser_check_manifest_validation(manifest);
593 int pkgmgr_parser_check_manifest_validation(const char *manifest);
596 * @fn void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
597 * @brief This API will free the manifest pointer by recursively freeing all sub elements.
599 * @par This API is for package-manager installer backends.
600 * @par Sync (or) Async : Synchronous API
602 * @param[in] mfx pointer to parsed manifest data
603 * @pre pkgmgr_parser_process_manifest_xml()
606 static int parse_manifest_file(const char *manifest)
608 manifest_x *mfx = NULL
609 mfx = pkgmgr_parser_process_manifest_xml(manifest);
612 printf("Parsing Manifest Success\n");
613 pkgmgr_parser_free_manifest_xml(mfx);
618 void pkgmgr_parser_free_manifest_xml(manifest_x *mfx);
621 * @fn manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest)
622 * @brief This API parses the manifest file and stores all the data in the manifest structure.
624 * @par This API is for package-manager installer backends.
625 * @par Sync (or) Async : Synchronous API
627 * @param[in] manifest pointer to package manifest file
628 * @return manifest pointer on success, NULL on failure
630 * @post pkgmgr_parser_free_manifest_xml()
632 static int parse_manifest_file(const char *manifest)
634 manifest_x *mfx = NULL
635 mfx = pkgmgr_parser_process_manifest_xml(manifest);
638 printf("Parsing Manifest Success\n");
639 pkgmgr_parser_free_manifest_xml(mfx);
644 manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest);
647 * @fn manifest_x *pkgmgr_parser_get_manifest_info(const char *pkigid)
648 * @brief This API gets the manifest info from DB and stores all the data in the manifest structure.
650 * @par This API is for package-manager installer backends.
651 * @par Sync (or) Async : Synchronous API
653 * @param[in] pkgid package id for package
654 * @return manifest pointer on success, NULL on failure
656 * @post pkgmgr_parser_free_manifest_xml()
658 static int get_manifest_info(const char *pkgid)
660 manifest_x *mfx = NULL
661 mfx = pkgmgr_parser_get_manifest_info(pkgid);
664 printf("Parsing Manifest Success\n");
665 pkgmgr_parser_free_manifest_xml(mfx);
670 manifest_x *pkgmgr_parser_get_manifest_info(const char *pkigid);
672 /* These APIs are intended to call parser directly */
673 typedef int (*ps_iter_fn) (const char *tag, int type, void *userdata);
675 int pkgmgr_parser_has_parser(const char *tag, int *type);
676 int pkgmgr_parser_get_list(ps_iter_fn iter_fn, void *data);
679 * @fn int pkgmgr_parser_run_parser_for_installation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
680 * @brief This API calls the parser directly by supplying the xml docptr. It is used during package installation
682 * @par This API is for package-manager installer backends.
683 * @par Sync (or) Async : Synchronous API
685 * @param[in] docPtr XML doxument pointer
686 * @param[in] tag the xml tag corresponding to the parser that will parse the docPtr
687 * @param[in] pkgid the package id
688 * @return 0 if success, error code(<0) if fail
689 * @retval PMINFO_R_OK success
690 * @retval PMINFO_R_EINVAL invalid argument
691 * @retval PMINFO_R_ERROR internal error
695 static int parse_docptr_for_installation(xmlDocPtr docPtr)
698 ret = pkgmgr_parser_run_parser_for_installation(docPtr, "theme", "com.samsung.test");
705 int pkgmgr_parser_run_parser_for_installation(xmlDocPtr docPtr, const char *tag, const char *pkgid);
708 * @fn int pkgmgr_parser_run_parser_for_upgrade(xmlDocPtr docPtr, const char *tag, const char *pkgid)
709 * @brief This API calls the parser directly by supplying the xml docptr. It is used during package upgrade
711 * @par This API is for package-manager installer backends.
712 * @par Sync (or) Async : Synchronous API
714 * @param[in] docPtr XML doxument pointer
715 * @param[in] tag the xml tag corresponding to the parser that will parse the docPtr
716 * @param[in] pkgid the package id
717 * @return 0 if success, error code(<0) if fail
718 * @retval PMINFO_R_OK success
719 * @retval PMINFO_R_EINVAL invalid argument
720 * @retval PMINFO_R_ERROR internal error
724 static int parse_docptr_for_upgrade(xmlDocPtr docPtr)
727 ret = pkgmgr_parser_run_parser_for_upgrade(docPtr, "theme", "com.samsung.test");
734 int pkgmgr_parser_run_parser_for_upgrade(xmlDocPtr docPtr, const char *tag, const char *pkgid);
737 * @fn int pkgmgr_parser_run_parser_for_uninstallation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
738 * @brief This API calls the parser directly by supplying the xml docptr. It is used during package uninstallation
740 * @par This API is for package-manager installer backends.
741 * @par Sync (or) Async : Synchronous API
743 * @param[in] docPtr XML doxument pointer
744 * @param[in] tag the xml tag corresponding to the parser that will parse the docPtr
745 * @param[in] pkgid the package id
746 * @return 0 if success, error code(<0) if fail
747 * @retval PMINFO_R_OK success
748 * @retval PMINFO_R_EINVAL invalid argument
749 * @retval PMINFO_R_ERROR internal error
753 static int parse_docptr_for_uninstallation(xmlDocPtr docPtr)
756 ret = pkgmgr_parser_run_parser_for_uninstallation(docPtr, "theme", "com.samsung.test");
763 int pkgmgr_parser_run_parser_for_uninstallation(xmlDocPtr docPtr, const char *tag, const char *pkgid);
766 * @fn int pkgmgr_parser_create_desktop_file(manifest_x *mfx)
767 * @brief This API generates the application desktop file
769 * @par This API is for package-manager installer backends.
770 * @par Sync (or) Async : Synchronous API
772 * @param[in] mfx manifest pointer
773 * @return 0 if success, error code(<0) if fail
774 * @retval PMINFO_R_OK success
775 * @retval PMINFO_R_EINVAL invalid argument
776 * @retval PMINFO_R_ERROR internal error
777 * @pre pkgmgr_parser_process_manifest_xml()
778 * @post pkgmgr_parser_free_manifest_xml()
780 static int create_desktop_file(char *manifest)
783 manifest_x *mfx = NULL;
784 mfx = pkgmgr_parser_process_manifest_xml(manifest);
785 ret = pkgmgr_parser_create_desktop_file(mfx);
788 pkgmgr_parser_free_manifest_xml(mfx);
793 int pkgmgr_parser_create_desktop_file(manifest_x *mfx);
799 #endif /* __PKGMGR_PARSER_H__ */