implement TEP install, update
[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 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_manifest_for_installation_withtep(const char *manifest, const char *tep_path, char *const tagv[])
132  * @fn int pkgmgr_parser_parse_usr_manifest_for_installation_withtep(const char *manifest, const char *tep_path, uid_t uid, char *const tagv[])
133  * @brief       This API parses the manifest file of the package after installation and stores the parsed data and tep information in DB if exists.
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_installation(const char *manifest, const char *tep_path)
149 {
150         int ret = 0;
151         ret = pkgmgr_parser_parse_manifest_for_installation_withtep(manifest, tep_path, NULL);
152         if (ret)
153                 return -1;
154         return 0;
155 }
156  * @endcode
157  */
158 int pkgmgr_parser_parse_manifest_for_installation_withtep(const char *manifest, const char *tep_path, char *const tagv[]);
159 int pkgmgr_parser_parse_usr_manifest_for_installation_withtep(const char *manifest, const char *tep_path, uid_t uid, char *const tagv[]);
160
161 /**
162  * @fn int pkgmgr_parser_update_tep(const char* pkgid, const char * tep_path)
163  * @fn int pkgmgr_parser_usr_update_tep(const char* pkgid, const char* tep_path, uid_t uid)
164  * @brief       This API updates tep path information stored in DB.
165  *
166  * @par         This API is for package-manager installer backends.
167  * @par Sync (or) Async : Synchronous API
168  *
169  * @param[in]   pkgid   pointer to package ID
170   * @param[in]tep_path  pointer to path of TEP file
171  * @param[in]   uid     the addressee user id of the instruction
172  * @return      0 if success, error code(<0) if fail
173  * @retval      PMINFO_R_OK     success
174  * @retval      PMINFO_R_EINVAL invalid argument
175  * @retval      PMINFO_R_ERROR  internal error
176  * @pre         None
177  * @post                None
178  * @code
179 static int update_tep_info_for_upgrade(const char *pkgid, const char *tep_path)
180 {
181         int ret = 0;
182         ret = pkgmgr_parser_update_tep(pkgid, tep_path);
183         if (ret)
184                 return -1;
185         return 0;
186 }
187  * @endcode
188  */
189 int pkgmgr_parser_update_tep(const char* pkgid, const char* tep_path);
190 int pkgmgr_parser_usr_update_tep(const char* pkgid, const char* tep_path, uid_t uid);
191
192 /**
193  * @fn int pkgmgr_parser_parse_usr_manifest_for_upgrade(const char *manifest,  uid_t uid, char *const tagv[])
194  * @fn int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[])
195  * @brief       This API parses the manifest file of the package after upgrade and stores the data in DB.
196  *
197  * @par         This API is for package-manager installer backends.
198  * @par Sync (or) Async : Synchronous API
199  *
200  * @param[in]   manifest        pointer to package manifest file
201  * @param[in]   uid     the addressee user id of the instruction
202  * @param[in]   tagv            array of xml tags or NULL
203  * @return      0 if success, error code(<0) if fail
204  * @retval      PMINFO_R_OK     success
205  * @retval      PMINFO_R_EINVAL invalid argument
206  * @retval      PMINFO_R_ERROR  internal error
207  * @pre         None
208  * @post                None
209  * @code
210 static int parse_manifest_file_for_upgrade(const char *manifest)
211 {
212         int ret = 0;
213         ret = pkgmgr_parser_parse_manifest_for_upgrade(manifest, NULL);
214         if (ret)
215                 return -1;
216         return 0;
217 }
218  * @endcode
219  */
220 int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[]);
221 int pkgmgr_parser_parse_usr_manifest_for_upgrade(const char *manifest, uid_t uid, char *const tagv[]);
222 /**
223  * @fn int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[])
224  * @fn int pkgmgr_parser_parse_usr_manifest_for_uninstallation(const char *manifest, uid_t uid, char *const tagv[])
225  * @brief       This API parses the manifest file of the package after uninstallation and deletes the data from DB.
226  *
227  * @par         This API is for package-manager installer backends.
228  * @par Sync (or) Async : Synchronous API
229  *
230  * @param[in]   manifest        pointer to package manifest file
231  * @param[in]   uid     the addressee user id of the instruction
232  * @param[in]   tagv            array of xml tags or NULL
233  * @return      0 if success, error code(<0) if fail
234  * @retval      PMINFO_R_OK     success
235  * @retval      PMINFO_R_EINVAL invalid argument
236  * @retval      PMINFO_R_ERROR  internal error
237  * @pre         None
238  * @post                None
239  * @code
240 static int parse_manifest_file_for_uninstallation(const char *manifest)
241 {
242         int ret = 0;
243         ret = pkgmgr_parser_parse_manifest_for_uninstallation(manifest, NULL);
244         if (ret)
245                 return -1;
246         return 0;
247 }
248  * @endcode
249  */
250 int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[]);
251 int pkgmgr_parser_parse_usr_manifest_for_uninstallation(const char *manifest, uid_t uid, char *const tagv[]);
252 /**
253  * @fn int pkgmgr_parser_parse_manifest_for_preload()
254  * @fn int pkgmgr_parser_parse_usr_manifest_for_preload(uid_t uid)
255  * @brief       This API update  preload information to DB.
256  *
257  * @par         This API is for package-manager installer backends.
258  * @par Sync (or) Async : Synchronous API
259  *
260  * @return      0 if success, error code(<0) if fail
261  * @retval      PMINFO_R_OK     success
262  * @retval      PMINFO_R_EINVAL invalid argument
263  * @retval      PMINFO_R_ERROR  internal error
264  * @pre         None
265  * @post                None
266  * @code
267 static int parser_parse_manifest_for_preload()
268 {
269         int ret = 0;
270         ret = pkgmgr_parser_parse_manifest_for_preload();
271         if (ret)
272                 return -1;
273         return 0;
274 }
275  * @endcode
276  */
277 int pkgmgr_parser_parse_manifest_for_preload();
278 int pkgmgr_parser_parse_usr_manifest_for_preload(uid_t uid);
279
280 /**
281  * @fn int pkgmgr_parser_check_manifest_validation(const char *manifest)
282  * @brief       This API validates the manifest file against the manifest schema.
283  *
284  * @par         This API is for package-manager installer backends.
285  * @par Sync (or) Async : Synchronous API
286  *
287  * @param[in]   manifest        pointer to package manifest file
288  * @return      0 if success, error code(<0) if fail
289  * @retval      PMINFO_R_OK     success
290  * @retval      PMINFO_R_EINVAL invalid argument
291  * @retval      PMINFO_R_ERROR  internal error
292  * @pre         None
293  * @post                None
294  * @code
295 static int validate_manifest_file(const char *manifest)
296 {
297         int ret = 0;
298         ret = pkgmgr_parser_check_manifest_validation(manifest);
299         if (ret)
300                 return -1;
301         return 0;
302 }
303  * @endcode
304  */
305 int pkgmgr_parser_check_manifest_validation(const char *manifest);
306
307 /**
308  * @fn void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
309  * @brief       This API will free the manifest pointer by recursively freeing all sub elements.
310  *
311  * @par         This API is for package-manager installer backends.
312  * @par Sync (or) Async : Synchronous API
313  *
314  * @param[in]   mfx     pointer to parsed manifest data
315  * @pre         pkgmgr_parser_process_manifest_xml()
316  * @post                None
317  * @code
318 static int parse_manifest_file(const char *manifest)
319 {
320         manifest_x *mfx = NULL
321         mfx = pkgmgr_parser_process_manifest_xml(manifest);
322         if (mfx == NULL)
323                 return -1;
324         printf("Parsing Manifest Success\n");
325         pkgmgr_parser_free_manifest_xml(mfx);
326         return 0;
327 }
328  * @endcode
329  */
330 void pkgmgr_parser_free_manifest_xml(manifest_x *mfx);
331
332 /**
333  * @fn manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest)
334  * @fn manifest_x *pkgmgr_parser_usr_process_manifest_xml(const char *manifest, uid_t uid)
335  * @brief       This API parses the manifest file and stores all the data in the manifest structure.
336  *
337  * @par         This API is for package-manager installer backends.
338  * @par Sync (or) Async : Synchronous API
339  *
340  * @param[in]   manifest        pointer to package manifest file
341  * @param[in]   uid     the addressee user id of the instruction
342  * @return      manifest pointer on success, NULL on failure
343  * @pre         None
344  * @post                pkgmgr_parser_free_manifest_xml()
345  * @code
346 static int parse_manifest_file(const char *manifest)
347 {
348         manifest_x *mfx = NULL
349         mfx = pkgmgr_parser_process_manifest_xml(manifest);
350         if (mfx == NULL)
351                 return -1;
352         printf("Parsing Manifest Success\n");
353         pkgmgr_parser_free_manifest_xml(mfx);
354         return 0;
355 }
356  * @endcode
357  */
358 manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest);
359 manifest_x *pkgmgr_parser_usr_process_manifest_xml(const char *manifest, uid_t uid);
360
361 /**
362  * @fn int pkgmgr_parser_run_parser_for_installation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
363  * @brief       This API calls the parser directly by supplying the xml docptr. It is used during package installation
364  *
365  * @par         This API is for package-manager installer backends.
366  * @par Sync (or) Async : Synchronous API
367  *
368  * @param[in]   docPtr  XML doxument pointer
369  * @param[in]   tag             the xml tag corresponding to the parser that will parse the docPtr
370  * @param[in]   pkgid           the package id
371  * @return      0 if success, error code(<0) if fail
372  * @retval      PMINFO_R_OK     success
373  * @retval      PMINFO_R_EINVAL invalid argument
374  * @retval      PMINFO_R_ERROR  internal error
375  * @pre         None
376  * @post                None
377  * @code
378 static int parse_docptr_for_installation(xmlDocPtr docPtr)
379 {
380         int ret = 0;
381         ret = pkgmgr_parser_run_parser_for_installation(docPtr, "theme", "com.samsung.test");
382         if (ret)
383                 return -1;
384         return 0;
385 }
386  * @endcode
387  */
388 int pkgmgr_parser_run_parser_for_installation(xmlDocPtr docPtr, const char *tag, const char *pkgid);
389
390 /**
391  * @fn int pkgmgr_parser_run_parser_for_upgrade(xmlDocPtr docPtr, const char *tag, const char *pkgid)
392  * @brief       This API calls the parser directly by supplying the xml docptr. It is used during package upgrade
393  *
394  * @par         This API is for package-manager installer backends.
395  * @par Sync (or) Async : Synchronous API
396  *
397  * @param[in]   docPtr  XML doxument pointer
398  * @param[in]   tag             the xml tag corresponding to the parser that will parse the docPtr
399  * @param[in]   pkgid           the package id
400  * @return      0 if success, error code(<0) if fail
401  * @retval      PMINFO_R_OK     success
402  * @retval      PMINFO_R_EINVAL invalid argument
403  * @retval      PMINFO_R_ERROR  internal error
404  * @pre         None
405  * @post                None
406  * @code
407 static int parse_docptr_for_upgrade(xmlDocPtr docPtr)
408 {
409         int ret = 0;
410         ret = pkgmgr_parser_run_parser_for_upgrade(docPtr, "theme", "com.samsung.test");
411         if (ret)
412                 return -1;
413         return 0;
414 }
415  * @endcode
416  */
417 int pkgmgr_parser_run_parser_for_upgrade(xmlDocPtr docPtr, const char *tag, const char *pkgid);
418
419 /**
420  * @fn int pkgmgr_parser_run_parser_for_uninstallation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
421  * @brief       This API calls the parser directly by supplying the xml docptr. It is used during package uninstallation
422  *
423  * @par         This API is for package-manager installer backends.
424  * @par Sync (or) Async : Synchronous API
425  *
426  * @param[in]   docPtr  XML doxument pointer
427  * @param[in]   tag             the xml tag corresponding to the parser that will parse the docPtr
428  * @param[in]   pkgid           the package id
429  * @return      0 if success, error code(<0) if fail
430  * @retval      PMINFO_R_OK     success
431  * @retval      PMINFO_R_EINVAL invalid argument
432  * @retval      PMINFO_R_ERROR  internal error
433  * @pre         None
434  * @post                None
435  * @code
436 static int parse_docptr_for_uninstallation(xmlDocPtr docPtr)
437 {
438         int ret = 0;
439         ret = pkgmgr_parser_run_parser_for_uninstallation(docPtr, "theme", "com.samsung.test");
440         if (ret)
441                 return -1;
442         return 0;
443 }
444  * @endcode
445  */
446 int pkgmgr_parser_run_parser_for_uninstallation(xmlDocPtr docPtr, const char *tag, const char *pkgid);
447
448
449
450 /**
451  * @fn int pkgmgr_parser_create_desktop_file(manifest_x *mfx)
452  * @fn int pkgmgr_parser_create_usr_desktop_file(manifest_x *mfx, uid_t uid)
453  * @brief       This API generates the application desktop file
454  *
455  * @par         This API is for package-manager installer backends.
456  * @par Sync (or) Async : Synchronous API
457  *
458  * @param[in]   mfx     manifest pointer
459  * @param[in]   uid     the addressee user id of the instruction
460  * @return      0 if success, error code(<0) if fail
461  * @retval      PMINFO_R_OK     success
462  * @retval      PMINFO_R_EINVAL invalid argument
463  * @retval      PMINFO_R_ERROR  internal error
464  * @pre         pkgmgr_parser_process_manifest_xml()
465  * @post        pkgmgr_parser_free_manifest_xml()
466  * @code
467 static int create_desktop_file(char *manifest)
468 {
469         int ret = 0;
470         manifest_x *mfx = NULL;
471         mfx = pkgmgr_parser_process_manifest_xml(manifest);
472         ret = pkgmgr_parser_create_desktop_file(mfx);
473         if (ret)
474                 return -1;
475         pkgmgr_parser_free_manifest_xml(mfx);
476         return 0;
477 }
478  * @endcode
479  */
480 int pkgmgr_parser_create_desktop_file(manifest_x *mfx);
481 int pkgmgr_parser_create_usr_desktop_file(manifest_x *mfx, uid_t uid);
482
483 /** @} */
484 #ifdef __cplusplus
485 }
486 #endif
487 #endif                          /* __PKGMGR_PARSER_H__ */