Rewrite query apis
[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 /* For multi-user support */
47 #include <tzplatform_config.h>
48 #include "pkgmgr-info-basic.h"
49
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53 #define DEFAULT_LOCALE          "No Locale"
54
55 #define PKG_PARSERLIB   "parserlib:"
56 #define PKG_PARSER_CONF_PATH    SYSCONFDIR "/package-manager/parser_path.conf"
57
58 #define PKG_STRING_LEN_MAX 1024
59
60 #define PKGMGR_PARSER_EMPTY_STR         ""
61 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
62
63 /**
64  * @brief API return values
65  */
66 enum {
67         PM_PARSER_R_EINVAL = -2,                /**< Invalid argument */
68         PM_PARSER_R_ERROR = -1,         /**< General error */
69         PM_PARSER_R_OK = 0                      /**< General success */
70 };
71
72 /**
73  * @fn char *pkgmgr_parser_get_manifest_file(const char *pkgid)
74  * @brief       This API gets the manifest file of the package.
75  *
76  * @par         This API is for package-manager installer backends.
77  * @par Sync (or) Async : Synchronous API
78  *
79  * @param[in]   pkgid   pointer to package ID
80  * @return      manifest file path on success, NULL on failure
81  * @pre         None
82  * @post                Free the manifest file pointer that is returned by API
83  * @code
84 static int get_manifest_file(const char *pkgid)
85 {
86         char *manifest = NULL;
87         manifest = pkgmgr_parser_get_manifest_file(pkgid);
88         if (manifest == NULL)
89                 return -1;
90         printf("Manifest File Path is %s\n", manifest);
91         free(manifest);
92         return 0;
93 }
94  * @endcode
95  */
96 char *pkgmgr_parser_get_manifest_file(const char *pkgid);
97 char *pkgmgr_parser_get_usr_manifest_file(const char *pkgid, uid_t uid);
98
99 /**
100  * @fn int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[])
101  * @fn int pkgmgr_parser_parse_usr_manifest_for_installation(const char *manifest, uid_t uid, char *const tagv[])
102  * @brief       This API parses the manifest file of the package after installation and stores the data in DB.
103  *
104  * @par         This API is for package-manager installer backends.
105  * @par Sync (or) Async : Synchronous API
106  *
107  * @param[in]   manifest        pointer to package manifest file
108  * @param[in]   uid     the addressee user id of the instruction
109  * @param[in]   tagv            array of xml tags or NULL
110  * @return      0 if success, error code(<0) if fail
111  * @retval      PMINFO_R_OK     success
112  * @retval      PMINFO_R_EINVAL invalid argument
113  * @retval      PMINFO_R_ERROR  internal error
114  * @pre         None
115  * @post                None
116  * @code
117 static int parse_manifest_file_for_installation(const char *manifest)
118 {
119         int ret = 0;
120         ret = pkgmgr_parser_parse_manifest_for_installation(manifest, NULL);
121         if (ret)
122                 return -1;
123         return 0;
124 }
125  * @endcode
126  */
127 int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[]);
128 int pkgmgr_parser_parse_usr_manifest_for_installation(const char *manifest, uid_t uid, char *const tagv[]);
129
130 /**
131  * @fn int pkgmgr_parser_parse_usr_manifest_for_upgrade(const char *manifest,  uid_t uid, char *const tagv[])
132  * @fn int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[])
133  * @brief       This API parses the manifest file of the package after upgrade and stores the data in DB.
134  *
135  * @par         This API is for package-manager installer backends.
136  * @par Sync (or) Async : Synchronous API
137  *
138  * @param[in]   manifest        pointer to package manifest file
139  * @param[in]   uid     the addressee user id of the instruction
140  * @param[in]   tagv            array of xml tags or NULL
141  * @return      0 if success, error code(<0) if fail
142  * @retval      PMINFO_R_OK     success
143  * @retval      PMINFO_R_EINVAL invalid argument
144  * @retval      PMINFO_R_ERROR  internal error
145  * @pre         None
146  * @post                None
147  * @code
148 static int parse_manifest_file_for_upgrade(const char *manifest)
149 {
150         int ret = 0;
151         ret = pkgmgr_parser_parse_manifest_for_upgrade(manifest, NULL);
152         if (ret)
153                 return -1;
154         return 0;
155 }
156  * @endcode
157  */
158 int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[]);
159 int pkgmgr_parser_parse_usr_manifest_for_upgrade(const char *manifest, uid_t uid, char *const tagv[]);
160 /**
161  * @fn int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[])
162  * @fn int pkgmgr_parser_parse_usr_manifest_for_uninstallation(const char *manifest, uid_t uid, char *const tagv[])
163  * @brief       This API parses the manifest file of the package after uninstallation and deletes the data from DB.
164  *
165  * @par         This API is for package-manager installer backends.
166  * @par Sync (or) Async : Synchronous API
167  *
168  * @param[in]   manifest        pointer to package manifest file
169  * @param[in]   uid     the addressee user id of the instruction
170  * @param[in]   tagv            array of xml tags or NULL
171  * @return      0 if success, error code(<0) if fail
172  * @retval      PMINFO_R_OK     success
173  * @retval      PMINFO_R_EINVAL invalid argument
174  * @retval      PMINFO_R_ERROR  internal error
175  * @pre         None
176  * @post                None
177  * @code
178 static int parse_manifest_file_for_uninstallation(const char *manifest)
179 {
180         int ret = 0;
181         ret = pkgmgr_parser_parse_manifest_for_uninstallation(manifest, NULL);
182         if (ret)
183                 return -1;
184         return 0;
185 }
186  * @endcode
187  */
188 int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[]);
189 int pkgmgr_parser_parse_usr_manifest_for_uninstallation(const char *manifest, uid_t uid, char *const tagv[]);
190 /**
191  * @fn int pkgmgr_parser_parse_manifest_for_preload()
192  * @fn int pkgmgr_parser_parse_usr_manifest_for_preload(uid_t uid)
193  * @brief       This API update  preload information to DB.
194  *
195  * @par         This API is for package-manager installer backends.
196  * @par Sync (or) Async : Synchronous API
197  *
198  * @return      0 if success, error code(<0) if fail
199  * @retval      PMINFO_R_OK     success
200  * @retval      PMINFO_R_EINVAL invalid argument
201  * @retval      PMINFO_R_ERROR  internal error
202  * @pre         None
203  * @post                None
204  * @code
205 static int parser_parse_manifest_for_preload()
206 {
207         int ret = 0;
208         ret = pkgmgr_parser_parse_manifest_for_preload();
209         if (ret)
210                 return -1;
211         return 0;
212 }
213  * @endcode
214  */
215 int pkgmgr_parser_parse_manifest_for_preload();
216 int pkgmgr_parser_parse_usr_manifest_for_preload(uid_t uid);
217
218 /**
219  * @fn int pkgmgr_parser_check_manifest_validation(const char *manifest)
220  * @brief       This API validates the manifest file against the manifest schema.
221  *
222  * @par         This API is for package-manager installer backends.
223  * @par Sync (or) Async : Synchronous API
224  *
225  * @param[in]   manifest        pointer to package manifest file
226  * @return      0 if success, error code(<0) if fail
227  * @retval      PMINFO_R_OK     success
228  * @retval      PMINFO_R_EINVAL invalid argument
229  * @retval      PMINFO_R_ERROR  internal error
230  * @pre         None
231  * @post                None
232  * @code
233 static int validate_manifest_file(const char *manifest)
234 {
235         int ret = 0;
236         ret = pkgmgr_parser_check_manifest_validation(manifest);
237         if (ret)
238                 return -1;
239         return 0;
240 }
241  * @endcode
242  */
243 int pkgmgr_parser_check_manifest_validation(const char *manifest);
244
245 /**
246  * @fn void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
247  * @brief       This API will free the manifest pointer by recursively freeing all sub elements.
248  *
249  * @par         This API is for package-manager installer backends.
250  * @par Sync (or) Async : Synchronous API
251  *
252  * @param[in]   mfx     pointer to parsed manifest data
253  * @pre         pkgmgr_parser_process_manifest_xml()
254  * @post                None
255  * @code
256 static int parse_manifest_file(const char *manifest)
257 {
258         manifest_x *mfx = NULL
259         mfx = pkgmgr_parser_process_manifest_xml(manifest);
260         if (mfx == NULL)
261                 return -1;
262         printf("Parsing Manifest Success\n");
263         pkgmgr_parser_free_manifest_xml(mfx);
264         return 0;
265 }
266  * @endcode
267  */
268 void pkgmgr_parser_free_manifest_xml(manifest_x *mfx);
269
270 /**
271  * @fn manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest)
272  * @fn manifest_x *pkgmgr_parser_usr_process_manifest_xml(const char *manifest, uid_t uid)
273  * @brief       This API parses the manifest file and stores all the data in the manifest structure.
274  *
275  * @par         This API is for package-manager installer backends.
276  * @par Sync (or) Async : Synchronous API
277  *
278  * @param[in]   manifest        pointer to package manifest file
279  * @param[in]   uid     the addressee user id of the instruction
280  * @return      manifest pointer on success, NULL on failure
281  * @pre         None
282  * @post                pkgmgr_parser_free_manifest_xml()
283  * @code
284 static int parse_manifest_file(const char *manifest)
285 {
286         manifest_x *mfx = NULL
287         mfx = pkgmgr_parser_process_manifest_xml(manifest);
288         if (mfx == NULL)
289                 return -1;
290         printf("Parsing Manifest Success\n");
291         pkgmgr_parser_free_manifest_xml(mfx);
292         return 0;
293 }
294  * @endcode
295  */
296 manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest);
297 manifest_x *pkgmgr_parser_usr_process_manifest_xml(const char *manifest, uid_t uid);
298
299 /**
300  * @fn int pkgmgr_parser_run_parser_for_installation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
301  * @brief       This API calls the parser directly by supplying the xml docptr. It is used during package installation
302  *
303  * @par         This API is for package-manager installer backends.
304  * @par Sync (or) Async : Synchronous API
305  *
306  * @param[in]   docPtr  XML doxument pointer
307  * @param[in]   tag             the xml tag corresponding to the parser that will parse the docPtr
308  * @param[in]   pkgid           the package id
309  * @return      0 if success, error code(<0) if fail
310  * @retval      PMINFO_R_OK     success
311  * @retval      PMINFO_R_EINVAL invalid argument
312  * @retval      PMINFO_R_ERROR  internal error
313  * @pre         None
314  * @post                None
315  * @code
316 static int parse_docptr_for_installation(xmlDocPtr docPtr)
317 {
318         int ret = 0;
319         ret = pkgmgr_parser_run_parser_for_installation(docPtr, "theme", "com.samsung.test");
320         if (ret)
321                 return -1;
322         return 0;
323 }
324  * @endcode
325  */
326 int pkgmgr_parser_run_parser_for_installation(xmlDocPtr docPtr, const char *tag, const char *pkgid);
327
328 /**
329  * @fn int pkgmgr_parser_run_parser_for_upgrade(xmlDocPtr docPtr, const char *tag, const char *pkgid)
330  * @brief       This API calls the parser directly by supplying the xml docptr. It is used during package upgrade
331  *
332  * @par         This API is for package-manager installer backends.
333  * @par Sync (or) Async : Synchronous API
334  *
335  * @param[in]   docPtr  XML doxument pointer
336  * @param[in]   tag             the xml tag corresponding to the parser that will parse the docPtr
337  * @param[in]   pkgid           the package id
338  * @return      0 if success, error code(<0) if fail
339  * @retval      PMINFO_R_OK     success
340  * @retval      PMINFO_R_EINVAL invalid argument
341  * @retval      PMINFO_R_ERROR  internal error
342  * @pre         None
343  * @post                None
344  * @code
345 static int parse_docptr_for_upgrade(xmlDocPtr docPtr)
346 {
347         int ret = 0;
348         ret = pkgmgr_parser_run_parser_for_upgrade(docPtr, "theme", "com.samsung.test");
349         if (ret)
350                 return -1;
351         return 0;
352 }
353  * @endcode
354  */
355 int pkgmgr_parser_run_parser_for_upgrade(xmlDocPtr docPtr, const char *tag, const char *pkgid);
356
357 /**
358  * @fn int pkgmgr_parser_run_parser_for_uninstallation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
359  * @brief       This API calls the parser directly by supplying the xml docptr. It is used during package uninstallation
360  *
361  * @par         This API is for package-manager installer backends.
362  * @par Sync (or) Async : Synchronous API
363  *
364  * @param[in]   docPtr  XML doxument pointer
365  * @param[in]   tag             the xml tag corresponding to the parser that will parse the docPtr
366  * @param[in]   pkgid           the package id
367  * @return      0 if success, error code(<0) if fail
368  * @retval      PMINFO_R_OK     success
369  * @retval      PMINFO_R_EINVAL invalid argument
370  * @retval      PMINFO_R_ERROR  internal error
371  * @pre         None
372  * @post                None
373  * @code
374 static int parse_docptr_for_uninstallation(xmlDocPtr docPtr)
375 {
376         int ret = 0;
377         ret = pkgmgr_parser_run_parser_for_uninstallation(docPtr, "theme", "com.samsung.test");
378         if (ret)
379                 return -1;
380         return 0;
381 }
382  * @endcode
383  */
384 int pkgmgr_parser_run_parser_for_uninstallation(xmlDocPtr docPtr, const char *tag, const char *pkgid);
385
386
387
388 /**
389  * @fn int pkgmgr_parser_create_desktop_file(manifest_x *mfx)
390  * @fn int pkgmgr_parser_create_usr_desktop_file(manifest_x *mfx, uid_t uid)
391  * @brief       This API generates the application desktop file
392  *
393  * @par         This API is for package-manager installer backends.
394  * @par Sync (or) Async : Synchronous API
395  *
396  * @param[in]   mfx     manifest pointer
397  * @param[in]   uid     the addressee user id of the instruction
398  * @return      0 if success, error code(<0) if fail
399  * @retval      PMINFO_R_OK     success
400  * @retval      PMINFO_R_EINVAL invalid argument
401  * @retval      PMINFO_R_ERROR  internal error
402  * @pre         pkgmgr_parser_process_manifest_xml()
403  * @post        pkgmgr_parser_free_manifest_xml()
404  * @code
405 static int create_desktop_file(char *manifest)
406 {
407         int ret = 0;
408         manifest_x *mfx = NULL;
409         mfx = pkgmgr_parser_process_manifest_xml(manifest);
410         ret = pkgmgr_parser_create_desktop_file(mfx);
411         if (ret)
412                 return -1;
413         pkgmgr_parser_free_manifest_xml(mfx);
414         return 0;
415 }
416  * @endcode
417  */
418 int pkgmgr_parser_create_desktop_file(manifest_x *mfx);
419 int pkgmgr_parser_create_usr_desktop_file(manifest_x *mfx, uid_t uid);
420
421 /** @} */
422 #ifdef __cplusplus
423 }
424 #endif
425 #endif                          /* __PKGMGR_PARSER_H__ */