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 icon_x {
124 const char *resolution;
129 typedef struct allowed_x {
132 struct allowed_x *prev;
133 struct allowed_x *next;
136 typedef struct request_x {
138 struct request_x *prev;
139 struct request_x *next;
142 typedef struct define_x {
144 struct allowed_x *allowed;
145 struct request_x *request;
146 struct define_x *prev;
147 struct define_x *next;
150 typedef struct datashare_x {
151 struct define_x *define;
152 struct request_x *request;
153 struct datashare_x *prev;
154 struct datashare_x *next;
157 typedef struct description_x {
161 struct description_x *prev;
162 struct description_x *next;
165 typedef struct registry_x {
168 struct registry_x *prev;
169 struct registry_x *next;
172 typedef struct database_x {
175 struct database_x *prev;
176 struct database_x *next;
179 typedef struct layout_x {
182 struct layout_x *prev;
183 struct layout_x *next;
186 typedef struct label_x {
190 struct label_x *prev;
191 struct label_x *next;
194 typedef struct author_x {
199 struct author_x *prev;
200 struct author_x *next;
203 typedef struct license_x {
206 struct license_x *prev;
207 struct license_x *next;
210 typedef struct operation_x {
213 struct operation_x *prev;
214 struct operation_x *next;
217 typedef struct uri_x {
224 typedef struct mime_x {
231 typedef struct subapp_x {
234 struct subapp_x *prev;
235 struct subapp_x *next;
238 typedef struct condition_x {
241 struct condition_x *prev;
242 struct condition_x *next;
245 typedef struct notification_x {
248 struct notification_x *prev;
249 struct notification_x *next;
252 typedef struct appsvc_x {
254 struct operation_x *operation;
257 struct subapp_x *subapp;
258 struct appsvc_x *prev;
259 struct appsvc_x *next;
262 typedef struct appcontrol_x {
264 struct operation_x *operation;
267 struct subapp_x *subapp;
268 struct appcontrol_x *prev;
269 struct appcontrol_x *next;
272 typedef struct category_x{
274 struct category_x *prev;
275 struct category_x *next;
278 typedef struct launchconditions_x {
280 struct condition_x *condition;
281 struct launchconditions_x *prev;
282 struct launchconditions_x *next;
283 } launchconditions_x;
285 typedef struct compatibility_x {
288 struct compatibility_x *prev;
289 struct compatibility_x *next;
292 typedef struct deviceprofile_x {
295 struct deviceprofile_x *prev;
296 struct deviceprofile_x *next;
299 typedef struct resolution_x {
300 const char *mimetype;
301 const char *urischeme;
302 struct resolution_x *prev;
303 struct resolution_x *next;
306 typedef struct capability_x {
307 const char *operationid;
309 struct resolution_x *resolution;
310 struct capability_x *prev;
311 struct capability_x *next;
314 typedef struct datacontrol_x {
315 const char *providerid;
316 struct capability_x *capability;
317 struct datacontrol_x *prev;
318 struct datacontrol_x *next;
321 typedef struct uiapplication_x {
324 const char *nodisplay;
325 const char *multiple;
326 const char *taskmanage;
328 const char *categories;
330 const char *hwacceleration;
333 const char *recentimage;
334 struct label_x *label;
336 struct appsvc_x *appsvc;
337 struct appcontrol_x *appcontrol;
338 struct category_x *category;
339 struct launchconditions_x *launchconditions;
340 struct notification_x *notification;
341 struct datashare_x *datashare;
342 struct uiapplication_x *prev;
343 struct uiapplication_x *next;
346 typedef struct serviceapplication_x {
350 const char *autorestart;
353 struct label_x *label;
355 struct appsvc_x *appsvc;
356 struct appcontrol_x *appcontrol;
357 struct category_x *category;
358 struct datacontrol_x *datacontrol;
359 struct launchconditions_x *launchconditions;
360 struct notification_x *notification;
361 struct datashare_x *datashare;
362 struct serviceapplication_x *prev;
363 struct serviceapplication_x *next;
364 } serviceapplication_x;
366 typedef struct daemon_x {
369 struct daemon_x *prev;
370 struct daemon_x *next;
373 typedef struct theme_x {
376 struct theme_x *prev;
377 struct theme_x *next;
380 typedef struct font_x {
387 typedef struct ime_x {
394 typedef struct manifest_x {
395 const char *package; /**< package name*/
396 const char *version; /**< package version*/
397 const char *installlocation; /**< package install location*/
398 const char *ns; /**<name space*/
399 const char *removable; /**< package removable flag*/
400 const char *preload; /**< package preload flag*/
401 const char *readonly; /**< package readonly flag*/
402 const char *type; /**< package type*/
403 const char *package_size; /**< package size for external installation*/
404 const char *installed_time; /**< installed time after finishing of installation*/
405 const char *storeclient_id; /**< id of store client for installed package*/
406 const char *mainapp_id; /**< app id of main application*/
407 const char *package_url; /**< app id of main application*/
408 struct icon_x *icon; /**< package icon*/
409 struct label_x *label; /**< package label*/
410 struct author_x *author; /**< package author*/
411 struct description_x *description; /**< package description*/
412 struct license_x *license; /**< package license*/
413 struct uiapplication_x *uiapplication; /**< package's ui application*/
414 struct serviceapplication_x *serviceapplication; /**< package's service application*/
415 struct daemon_x *daemon; /**< package daemon*/
416 struct theme_x *theme; /**< package theme*/
417 struct font_x *font; /**< package font*/
418 struct ime_x *ime; /**< package ime*/
419 struct compatibility_x *compatibility; /**< package compatibility*/
420 struct deviceprofile_x *deviceprofile; /**< package device profile*/
424 * @fn char *pkgmgr_parser_get_manifest_file(const char *pkgid)
425 * @brief This API gets the manifest file of the package.
427 * @par This API is for package-manager installer backends.
428 * @par Sync (or) Async : Synchronous API
430 * @param[in] pkgid pointer to package ID
431 * @return manifest file path on success, NULL on failure
433 * @post Free the manifest file pointer that is returned by API
435 static int get_manifest_file(const char *pkgid)
437 char *manifest = NULL;
438 manifest = pkgmgr_parser_get_manifest_file(pkgid);
439 if (manifest == NULL)
441 printf("Manifest File Path is %s\n", manifest);
447 char *pkgmgr_parser_get_manifest_file(const char *pkgid);
450 * @fn int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[])
451 * @brief This API parses the manifest file of the package after installation and stores the data in DB.
453 * @par This API is for package-manager installer backends.
454 * @par Sync (or) Async : Synchronous API
456 * @param[in] manifest pointer to package manifest file
457 * @param[in] tagv array of xml tags or NULL
458 * @return 0 if success, error code(<0) if fail
459 * @retval PMINFO_R_OK success
460 * @retval PMINFO_R_EINVAL invalid argument
461 * @retval PMINFO_R_ERROR internal error
465 static int parse_manifest_file_for_installation(const char *manifest)
468 ret = pkgmgr_parser_parse_manifest_for_installation(manifest, NULL);
475 int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[]);
478 * @fn int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[])
479 * @brief This API parses the manifest file of the package after upgrade and stores the data in DB.
481 * @par This API is for package-manager installer backends.
482 * @par Sync (or) Async : Synchronous API
484 * @param[in] manifest pointer to package manifest file
485 * @param[in] tagv array of xml tags or NULL
486 * @return 0 if success, error code(<0) if fail
487 * @retval PMINFO_R_OK success
488 * @retval PMINFO_R_EINVAL invalid argument
489 * @retval PMINFO_R_ERROR internal error
493 static int parse_manifest_file_for_upgrade(const char *manifest)
496 ret = pkgmgr_parser_parse_manifest_for_upgrade(manifest, NULL);
503 int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[]);
506 * @fn int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[])
507 * @brief This API parses the manifest file of the package after uninstallation and deletes the data from DB.
509 * @par This API is for package-manager installer backends.
510 * @par Sync (or) Async : Synchronous API
512 * @param[in] manifest pointer to package manifest file
513 * @param[in] tagv array of xml tags or NULL
514 * @return 0 if success, error code(<0) if fail
515 * @retval PMINFO_R_OK success
516 * @retval PMINFO_R_EINVAL invalid argument
517 * @retval PMINFO_R_ERROR internal error
521 static int parse_manifest_file_for_uninstallation(const char *manifest)
524 ret = pkgmgr_parser_parse_manifest_for_uninstallation(manifest, NULL);
531 int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[]);
534 * @fn int pkgmgr_parser_check_manifest_validation(const char *manifest)
535 * @brief This API validates the manifest file against the manifest schema.
537 * @par This API is for package-manager installer backends.
538 * @par Sync (or) Async : Synchronous API
540 * @param[in] manifest pointer to package manifest file
541 * @return 0 if success, error code(<0) if fail
542 * @retval PMINFO_R_OK success
543 * @retval PMINFO_R_EINVAL invalid argument
544 * @retval PMINFO_R_ERROR internal error
548 static int validate_manifest_file(const char *manifest)
551 ret = pkgmgr_parser_check_manifest_validation(manifest);
558 int pkgmgr_parser_check_manifest_validation(const char *manifest);
561 * @fn void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
562 * @brief This API will free the manifest pointer by recursively freeing all sub elements.
564 * @par This API is for package-manager installer backends.
565 * @par Sync (or) Async : Synchronous API
567 * @param[in] mfx pointer to parsed manifest data
568 * @pre pkgmgr_parser_process_manifest_xml()
571 static int parse_manifest_file(const char *manifest)
573 manifest_x *mfx = NULL
574 mfx = pkgmgr_parser_process_manifest_xml(manifest);
577 printf("Parsing Manifest Success\n");
578 pkgmgr_parser_free_manifest_xml(mfx);
583 void pkgmgr_parser_free_manifest_xml(manifest_x *mfx);
586 * @fn manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest)
587 * @brief This API parses the manifest file and stores all the data in the manifest structure.
589 * @par This API is for package-manager installer backends.
590 * @par Sync (or) Async : Synchronous API
592 * @param[in] manifest pointer to package manifest file
593 * @return manifest pointer on success, NULL on failure
595 * @post pkgmgr_parser_free_manifest_xml()
597 static int parse_manifest_file(const char *manifest)
599 manifest_x *mfx = NULL
600 mfx = pkgmgr_parser_process_manifest_xml(manifest);
603 printf("Parsing Manifest Success\n");
604 pkgmgr_parser_free_manifest_xml(mfx);
609 manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest);
611 /* These APIs are intended to call parser directly */
612 typedef int (*ps_iter_fn) (const char *tag, int type, void *userdata);
614 int pkgmgr_parser_has_parser(const char *tag, int *type);
615 int pkgmgr_parser_get_list(ps_iter_fn iter_fn, void *data);
618 * @fn int pkgmgr_parser_run_parser_for_installation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
619 * @brief This API calls the parser directly by supplying the xml docptr. It is used during package installation
621 * @par This API is for package-manager installer backends.
622 * @par Sync (or) Async : Synchronous API
624 * @param[in] docPtr XML doxument pointer
625 * @param[in] tag the xml tag corresponding to the parser that will parse the docPtr
626 * @param[in] pkgid the package id
627 * @return 0 if success, error code(<0) if fail
628 * @retval PMINFO_R_OK success
629 * @retval PMINFO_R_EINVAL invalid argument
630 * @retval PMINFO_R_ERROR internal error
634 static int parse_docptr_for_installation(xmlDocPtr docPtr)
637 ret = pkgmgr_parser_run_parser_for_installation(docPtr, "theme", "com.samsung.test");
644 int pkgmgr_parser_run_parser_for_installation(xmlDocPtr docPtr, const char *tag, const char *pkgid);
647 * @fn int pkgmgr_parser_run_parser_for_upgrade(xmlDocPtr docPtr, const char *tag, const char *pkgid)
648 * @brief This API calls the parser directly by supplying the xml docptr. It is used during package upgrade
650 * @par This API is for package-manager installer backends.
651 * @par Sync (or) Async : Synchronous API
653 * @param[in] docPtr XML doxument pointer
654 * @param[in] tag the xml tag corresponding to the parser that will parse the docPtr
655 * @param[in] pkgid the package id
656 * @return 0 if success, error code(<0) if fail
657 * @retval PMINFO_R_OK success
658 * @retval PMINFO_R_EINVAL invalid argument
659 * @retval PMINFO_R_ERROR internal error
663 static int parse_docptr_for_upgrade(xmlDocPtr docPtr)
666 ret = pkgmgr_parser_run_parser_for_upgrade(docPtr, "theme", "com.samsung.test");
673 int pkgmgr_parser_run_parser_for_upgrade(xmlDocPtr docPtr, const char *tag, const char *pkgid);
676 * @fn int pkgmgr_parser_run_parser_for_uninstallation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
677 * @brief This API calls the parser directly by supplying the xml docptr. It is used during package uninstallation
679 * @par This API is for package-manager installer backends.
680 * @par Sync (or) Async : Synchronous API
682 * @param[in] docPtr XML doxument pointer
683 * @param[in] tag the xml tag corresponding to the parser that will parse the docPtr
684 * @param[in] pkgid the package id
685 * @return 0 if success, error code(<0) if fail
686 * @retval PMINFO_R_OK success
687 * @retval PMINFO_R_EINVAL invalid argument
688 * @retval PMINFO_R_ERROR internal error
692 static int parse_docptr_for_uninstallation(xmlDocPtr docPtr)
695 ret = pkgmgr_parser_run_parser_for_uninstallation(docPtr, "theme", "com.samsung.test");
702 int pkgmgr_parser_run_parser_for_uninstallation(xmlDocPtr docPtr, const char *tag, const char *pkgid);
708 #endif /* __PKGMGR_PARSER_H__ */