Tizen 2.1 base
[platform/core/appfw/pkgmgr-info.git] / parser / pkgmgr_parser.h
1 /*
2  * pkgmgr-info
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
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>
8  *
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
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
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.
20  *
21  */
22
23 #ifndef __PKGMGR_PARSER_H__
24 #define __PKGMGR_PARSER_H__
25
26 /**
27  * @file pkgmgr_parser.h
28  * @author Sewook Park <sewook7.park@samsung.com>
29  * @author Shobhit Srivastava <shobhit.s@samsung.com>
30  * @version 0.1
31  * @brief    This file declares API of pkgmgr_parser
32  * @addtogroup          APPLICATION_FRAMEWORK
33  * @{
34  *
35  * @defgroup            PackageManagerParser
36  * @section             Header Header file to include:
37  * @code
38  * #include             <pkgmgr_parser.h>
39  * @endcode
40  *
41  * @}
42  */
43
44 #include <libxml/xmlreader.h>
45
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 #define DEFAULT_LOCALE          "No Locale"
50
51 #define PKG_PARSERLIB   "parserlib:"
52 #define PKG_PARSER_CONF_PATH    "/usr/etc/package-manager/parser_path.conf"
53
54 #define PKG_STRING_LEN_MAX 1024
55
56 /**
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.
61  */
62
63  /**
64  * @brief Convinience Macro to add node in list
65  */
66
67 #define LISTADD(list, node)                     \
68     do {                                        \
69         (node)->prev = (list);                  \
70         if (list) (node)->next = (list)->next;  \
71         else (node)->next = NULL;               \
72         if (list) (list)->next = (node);        \
73         (list) = (node);                        \
74     } while (0);
75
76  /**
77  * @brief Convinience Macro to add one node to another node
78  */
79 #define NODEADD(node1, node2)                                   \
80     do {                                                        \
81         (node2)->prev = (node1);                                \
82         (node2)->next = (node1)->next;                          \
83         if ((node1)->next) (node1)->next->prev = (node2);       \
84         (node1)->next = (node2);                                \
85     } while (0);
86
87  /**
88  * @brief Convinience Macro to concatenate two lists
89  */
90 #define LISTCAT(list, first, last)              \
91     if ((first) && (last)) {                    \
92         (first)->prev = (list);                 \
93         (list) = (last);                        \
94     }
95
96  /**
97  * @brief Convinience Macro to delete node from list
98  */
99 #define LISTDEL(list, node)                                     \
100     do {                                                        \
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;  \
104     } while (0);
105
106  /**
107  * @brief Convinience Macro to get list head
108  */
109 #define LISTHEAD(list, node)                                    \
110     for ((node) = (list); (node)->prev; (node) = (node)->prev);
111
112  /**
113  * @brief Convinience Macro to get list tail
114  */
115 #define LISTTAIL(list, node)                                    \
116     for ((node) = (list); (node)->next; (node) = (node)->next);
117
118 typedef struct icon_x {
119         const char *name;
120         const char *text;
121         const char *lang;
122         const char *section;
123         const char *size;
124         const char *resolution;
125         struct icon_x *prev;
126         struct icon_x *next;
127 } icon_x;
128
129 typedef struct allowed_x {
130         const char *name;
131         const char *text;
132         struct allowed_x *prev;
133         struct allowed_x *next;
134 } allowed_x;
135
136 typedef struct request_x {
137         const char *text;
138         struct request_x *prev;
139         struct request_x *next;
140 } request_x;
141
142 typedef struct define_x {
143         const char *path;
144         struct allowed_x *allowed;
145         struct request_x *request;
146         struct define_x *prev;
147         struct define_x *next;
148 } define_x;
149
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;
155 } datashare_x;
156
157 typedef struct description_x {
158         const char *name;
159         const char *text;
160         const char *lang;
161         struct description_x *prev;
162         struct description_x *next;
163 } description_x;
164
165 typedef struct registry_x {
166         const char *name;
167         const char *text;
168         struct registry_x *prev;
169         struct registry_x *next;
170 } registry_x;
171
172 typedef struct database_x {
173         const char *name;
174         const char *text;
175         struct database_x *prev;
176         struct database_x *next;
177 } database_x;
178
179 typedef struct layout_x {
180         const char *name;
181         const char *text;
182         struct layout_x *prev;
183         struct layout_x *next;
184 } layout_x;
185
186 typedef struct label_x {
187         const char *name;
188         const char *text;
189         const char *lang;
190         struct label_x *prev;
191         struct label_x *next;
192 } label_x;
193
194 typedef struct author_x {
195         const char *email;
196         const char *href;
197         const char *text;
198         const char *lang;
199         struct author_x *prev;
200         struct author_x *next;
201 } author_x;
202
203 typedef struct license_x {
204         const char *text;
205         const char *lang;
206         struct license_x *prev;
207         struct license_x *next;
208 } license_x;
209
210 typedef struct operation_x {
211         const char *name;
212         const char *text;
213         struct operation_x *prev;
214         struct operation_x *next;
215 } operation_x;
216
217 typedef struct uri_x {
218         const char *name;
219         const char *text;
220         struct uri_x *prev;
221         struct uri_x *next;
222 } uri_x;
223
224 typedef struct mime_x {
225         const char *name;
226         const char *text;
227         struct mime_x *prev;
228         struct mime_x *next;
229 } mime_x;
230
231 typedef struct subapp_x {
232         const char *name;
233         const char *text;
234         struct subapp_x *prev;
235         struct subapp_x *next;
236 } subapp_x;
237
238 typedef struct condition_x {
239         const char *name;
240         const char *text;
241         struct condition_x *prev;
242         struct condition_x *next;
243 } condition_x;
244
245 typedef struct notification_x {
246         const char *name;
247         const char *text;
248         struct notification_x *prev;
249         struct notification_x *next;
250 } notification_x;
251
252 typedef struct appsvc_x {
253         const char *text;
254         struct operation_x *operation;
255         struct uri_x *uri;
256         struct mime_x *mime;
257         struct subapp_x *subapp;
258         struct appsvc_x *prev;
259         struct appsvc_x *next;
260 } appsvc_x;
261
262 typedef struct appcontrol_x {
263         const char *text;
264         struct operation_x *operation;
265         struct uri_x *uri;
266         struct mime_x *mime;
267         struct subapp_x *subapp;
268         struct appcontrol_x *prev;
269         struct appcontrol_x *next;
270 } appcontrol_x;
271
272 typedef struct category_x{
273         const char *name;
274         struct category_x *prev;
275         struct category_x *next;
276 } category_x;
277
278 typedef struct launchconditions_x {
279         const char *text;
280         struct condition_x *condition;
281         struct launchconditions_x *prev;
282         struct launchconditions_x *next;
283 } launchconditions_x;
284
285 typedef struct compatibility_x {
286         const char *name;
287         const char *text;
288         struct compatibility_x *prev;
289         struct compatibility_x *next;
290 }compatibility_x;
291
292 typedef struct deviceprofile_x {
293         const char *name;
294         const char *text;
295         struct deviceprofile_x *prev;
296         struct deviceprofile_x *next;
297 }deviceprofile_x;
298
299 typedef struct resolution_x {
300         const char *mimetype;
301         const char *urischeme;
302         struct resolution_x *prev;
303         struct resolution_x *next;
304 } resolution_x;
305
306 typedef struct capability_x {
307         const char *operationid;
308         const char *access;
309         struct resolution_x *resolution;
310         struct capability_x *prev;
311         struct capability_x *next;
312 } capability_x;
313
314 typedef struct datacontrol_x {
315         const char *providerid;
316         struct capability_x *capability;
317         struct datacontrol_x *prev;
318         struct datacontrol_x *next;
319 } datacontrol_x;
320
321 typedef struct uiapplication_x {
322         const char *appid;
323         const char *exec;
324         const char *nodisplay;
325         const char *multiple;
326         const char *taskmanage;
327         const char *type;
328         const char *categories;
329         const char *extraid;
330         const char *hwacceleration;
331         const char *mainapp;
332         const char *package;
333         const char *recentimage;
334         struct label_x *label;
335         struct icon_x *icon;
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;
344 } uiapplication_x;
345
346 typedef struct serviceapplication_x {
347         const char *appid;
348         const char *exec;
349         const char *onboot;
350         const char *autorestart;
351         const char *type;
352         const char *package;
353         struct label_x *label;
354         struct icon_x *icon;
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;
365
366 typedef struct daemon_x {
367         const char *name;
368         const char *text;
369         struct daemon_x *prev;
370         struct daemon_x *next;
371 } daemon_x;
372
373 typedef struct theme_x {
374         const char *name;
375         const char *text;
376         struct theme_x *prev;
377         struct theme_x *next;
378 } theme_x;
379
380 typedef struct font_x {
381         const char *name;
382         const char *text;
383         struct font_x *prev;
384         struct font_x *next;
385 } font_x;
386
387 typedef struct ime_x {
388         const char *name;
389         const char *text;
390         struct ime_x *prev;
391         struct ime_x *next;
392 } ime_x;
393
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*/
421 } manifest_x;
422
423 /**
424  * @fn char *pkgmgr_parser_get_manifest_file(const char *pkgid)
425  * @brief       This API gets the manifest file of the package.
426  *
427  * @par         This API is for package-manager installer backends.
428  * @par Sync (or) Async : Synchronous API
429  *
430  * @param[in]   pkgid   pointer to package ID
431  * @return      manifest file path on success, NULL on failure
432  * @pre         None
433  * @post                Free the manifest file pointer that is returned by API
434  * @code
435 static int get_manifest_file(const char *pkgid)
436 {
437         char *manifest = NULL;
438         manifest = pkgmgr_parser_get_manifest_file(pkgid);
439         if (manifest == NULL)
440                 return -1;
441         printf("Manifest File Path is %s\n", manifest);
442         free(manifest);
443         return 0;
444 }
445  * @endcode
446  */
447 char *pkgmgr_parser_get_manifest_file(const char *pkgid);
448
449 /**
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.
452  *
453  * @par         This API is for package-manager installer backends.
454  * @par Sync (or) Async : Synchronous API
455  *
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
462  * @pre         None
463  * @post                None
464  * @code
465 static int parse_manifest_file_for_installation(const char *manifest)
466 {
467         int ret = 0;
468         ret = pkgmgr_parser_parse_manifest_for_installation(manifest, NULL);
469         if (ret)
470                 return -1;
471         return 0;
472 }
473  * @endcode
474  */
475 int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[]);
476
477 /**
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.
480  *
481  * @par         This API is for package-manager installer backends.
482  * @par Sync (or) Async : Synchronous API
483  *
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
490  * @pre         None
491  * @post                None
492  * @code
493 static int parse_manifest_file_for_upgrade(const char *manifest)
494 {
495         int ret = 0;
496         ret = pkgmgr_parser_parse_manifest_for_upgrade(manifest, NULL);
497         if (ret)
498                 return -1;
499         return 0;
500 }
501  * @endcode
502  */
503 int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[]);
504
505 /**
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.
508  *
509  * @par         This API is for package-manager installer backends.
510  * @par Sync (or) Async : Synchronous API
511  *
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
518  * @pre         None
519  * @post                None
520  * @code
521 static int parse_manifest_file_for_uninstallation(const char *manifest)
522 {
523         int ret = 0;
524         ret = pkgmgr_parser_parse_manifest_for_uninstallation(manifest, NULL);
525         if (ret)
526                 return -1;
527         return 0;
528 }
529  * @endcode
530  */
531 int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[]);
532
533 /**
534  * @fn int pkgmgr_parser_check_manifest_validation(const char *manifest)
535  * @brief       This API validates the manifest file against the manifest schema.
536  *
537  * @par         This API is for package-manager installer backends.
538  * @par Sync (or) Async : Synchronous API
539  *
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
545  * @pre         None
546  * @post                None
547  * @code
548 static int validate_manifest_file(const char *manifest)
549 {
550         int ret = 0;
551         ret = pkgmgr_parser_check_manifest_validation(manifest);
552         if (ret)
553                 return -1;
554         return 0;
555 }
556  * @endcode
557  */
558 int pkgmgr_parser_check_manifest_validation(const char *manifest);
559
560 /**
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.
563  *
564  * @par         This API is for package-manager installer backends.
565  * @par Sync (or) Async : Synchronous API
566  *
567  * @param[in]   mfx     pointer to parsed manifest data
568  * @pre         pkgmgr_parser_process_manifest_xml()
569  * @post                None
570  * @code
571 static int parse_manifest_file(const char *manifest)
572 {
573         manifest_x *mfx = NULL
574         mfx = pkgmgr_parser_process_manifest_xml(manifest);
575         if (mfx == NULL)
576                 return -1;
577         printf("Parsing Manifest Success\n");
578         pkgmgr_parser_free_manifest_xml(mfx);
579         return 0;
580 }
581  * @endcode
582  */
583 void pkgmgr_parser_free_manifest_xml(manifest_x *mfx);
584
585 /**
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.
588  *
589  * @par         This API is for package-manager installer backends.
590  * @par Sync (or) Async : Synchronous API
591  *
592  * @param[in]   manifest        pointer to package manifest file
593  * @return      manifest pointer on success, NULL on failure
594  * @pre         None
595  * @post                pkgmgr_parser_free_manifest_xml()
596  * @code
597 static int parse_manifest_file(const char *manifest)
598 {
599         manifest_x *mfx = NULL
600         mfx = pkgmgr_parser_process_manifest_xml(manifest);
601         if (mfx == NULL)
602                 return -1;
603         printf("Parsing Manifest Success\n");
604         pkgmgr_parser_free_manifest_xml(mfx);
605         return 0;
606 }
607  * @endcode
608  */
609 manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest);
610
611 /* These APIs are intended to call parser directly */
612 typedef int (*ps_iter_fn) (const char *tag, int type, void *userdata);
613
614 int pkgmgr_parser_has_parser(const char *tag, int *type);
615 int pkgmgr_parser_get_list(ps_iter_fn iter_fn, void *data);
616
617 /**
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
620  *
621  * @par         This API is for package-manager installer backends.
622  * @par Sync (or) Async : Synchronous API
623  *
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
631  * @pre         None
632  * @post                None
633  * @code
634 static int parse_docptr_for_installation(xmlDocPtr docPtr)
635 {
636         int ret = 0;
637         ret = pkgmgr_parser_run_parser_for_installation(docPtr, "theme", "com.samsung.test");
638         if (ret)
639                 return -1;
640         return 0;
641 }
642  * @endcode
643  */
644 int pkgmgr_parser_run_parser_for_installation(xmlDocPtr docPtr, const char *tag, const char *pkgid);
645
646 /**
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
649  *
650  * @par         This API is for package-manager installer backends.
651  * @par Sync (or) Async : Synchronous API
652  *
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
660  * @pre         None
661  * @post                None
662  * @code
663 static int parse_docptr_for_upgrade(xmlDocPtr docPtr)
664 {
665         int ret = 0;
666         ret = pkgmgr_parser_run_parser_for_upgrade(docPtr, "theme", "com.samsung.test");
667         if (ret)
668                 return -1;
669         return 0;
670 }
671  * @endcode
672  */
673 int pkgmgr_parser_run_parser_for_upgrade(xmlDocPtr docPtr, const char *tag, const char *pkgid);
674
675 /**
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
678  *
679  * @par         This API is for package-manager installer backends.
680  * @par Sync (or) Async : Synchronous API
681  *
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
689  * @pre         None
690  * @post                None
691  * @code
692 static int parse_docptr_for_uninstallation(xmlDocPtr docPtr)
693 {
694         int ret = 0;
695         ret = pkgmgr_parser_run_parser_for_uninstallation(docPtr, "theme", "com.samsung.test");
696         if (ret)
697                 return -1;
698         return 0;
699 }
700  * @endcode
701  */
702 int pkgmgr_parser_run_parser_for_uninstallation(xmlDocPtr docPtr, const char *tag, const char *pkgid);
703
704 /** @} */
705 #ifdef __cplusplus
706 }
707 #endif
708 #endif                          /* __PKGMGR_PARSER_H__ */