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