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>
46 /* For multi-user support */
47 #include <tzplatform_config.h>
48 #include "pkgmgrinfo_basic.h"
53 #define DEFAULT_LOCALE "No Locale"
55 #define PKG_PARSERLIB "parserlib:"
56 #define PKG_PARSER_CONF_PATH SYSCONFDIR "/package-manager/parser_path.conf"
58 #define PKG_STRING_LEN_MAX 1024
60 #define PKGMGR_PARSER_EMPTY_STR ""
61 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
64 * @brief API return values
67 PM_PARSER_R_EINVAL = -2, /**< Invalid argument */
68 PM_PARSER_R_ERROR = -1, /**< General error */
69 PM_PARSER_R_OK = 0 /**< General success */
73 * @brief Preload application type
76 PM_PRELOAD_NONE, /**< not preload */
77 PM_PRELOAD_RW_NORM, /**< not removable */
78 PM_PRELOAD_RW_RM /**< removable */
82 * @fn int pkgmgr_parser_preload_package_type(const char *package)
83 * @brief This API gets type of preload that package is expected to be
85 * @par This API is for package-manager installer backends.
87 * @param[in] package pointer to package ID
88 * @return PM_PRELOAD defining what type of preload package it should be, -1 on failure
90 int pkgmgr_parser_preload_package_type(const char *package);
93 * @fn char *pkgmgr_parser_get_manifest_file(const char *pkgid)
94 * @brief This API gets the manifest file of the package.
96 * @par This API is for package-manager installer backends.
97 * @par Sync (or) Async : Synchronous API
99 * @param[in] pkgid pointer to package ID
100 * @return manifest file path on success, NULL on failure
102 * @post Free the manifest file pointer that is returned by API
104 static int get_manifest_file(const char *pkgid)
106 char *manifest = NULL;
107 manifest = pkgmgr_parser_get_manifest_file(pkgid);
108 if (manifest == NULL)
110 printf("Manifest File Path is %s\n", manifest);
116 char *pkgmgr_parser_get_manifest_file(const char *pkgid);
117 char *pkgmgr_parser_get_usr_manifest_file(const char *pkgid, uid_t uid);
120 * @fn int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[])
121 * @fn int pkgmgr_parser_parse_usr_manifest_for_installation(const char *manifest, uid_t uid, char *const tagv[])
122 * @brief This API parses the manifest file of the package after installation and stores the data in DB.
124 * @par This API is for package-manager installer backends.
125 * @par Sync (or) Async : Synchronous API
127 * @param[in] manifest pointer to package manifest file
128 * @param[in] uid the addressee user id of the instruction
129 * @param[in] tagv array of xml tags or NULL
130 * @return 0 if success, error code(<0) if fail
131 * @retval PMINFO_R_OK success
132 * @retval PMINFO_R_EINVAL invalid argument
133 * @retval PMINFO_R_ERROR internal error
137 static int parse_manifest_file_for_installation(const char *manifest)
140 ret = pkgmgr_parser_parse_manifest_for_installation(manifest, NULL);
147 int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[]);
148 int pkgmgr_parser_parse_usr_manifest_for_installation(const char *manifest, uid_t uid, char *const tagv[]);
149 int pkgmgr_parser_process_manifest_x_for_installation(manifest_x* mfx, const char *manifest);
150 int pkgmgr_parser_process_usr_manifest_x_for_installation(manifest_x* mfx, const char *manifest, uid_t uid);
153 * @fn int pkgmgr_parser_update_tep(const char* pkgid, const char * tep_path)
154 * @fn int pkgmgr_parser_usr_update_tep(const char* pkgid, const char* tep_path, uid_t uid)
155 * @brief This API updates tep path information stored in DB.
157 * @par This API is for package-manager installer backends.
158 * @par Sync (or) Async : Synchronous API
160 * @param[in] pkgid pointer to package ID
161 * @param[in]tep_path pointer to path of TEP file
162 * @param[in] uid the addressee user id of the instruction
163 * @return 0 if success, error code(<0) if fail
164 * @retval PMINFO_R_OK success
165 * @retval PMINFO_R_EINVAL invalid argument
166 * @retval PMINFO_R_ERROR internal error
170 static int update_tep_info_for_upgrade(const char *pkgid, const char *tep_path)
173 ret = pkgmgr_parser_update_tep(pkgid, tep_path);
180 int pkgmgr_parser_update_tep(const char* pkgid, const char* tep_path);
181 int pkgmgr_parser_usr_update_tep(const char* pkgid, const char* tep_path, uid_t uid);
184 * @fn int pkgmgr_parser_parse_usr_manifest_for_upgrade(const char *manifest, uid_t uid, char *const tagv[])
185 * @fn int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[])
186 * @brief This API parses the manifest file of the package after upgrade and stores the data in DB.
188 * @par This API is for package-manager installer backends.
189 * @par Sync (or) Async : Synchronous API
191 * @param[in] manifest pointer to package manifest file
192 * @param[in] uid the addressee user id of the instruction
193 * @param[in] tagv array of xml tags or NULL
194 * @return 0 if success, error code(<0) if fail
195 * @retval PMINFO_R_OK success
196 * @retval PMINFO_R_EINVAL invalid argument
197 * @retval PMINFO_R_ERROR internal error
201 static int parse_manifest_file_for_upgrade(const char *manifest)
204 ret = pkgmgr_parser_parse_manifest_for_upgrade(manifest, NULL);
211 int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[]);
212 int pkgmgr_parser_parse_usr_manifest_for_upgrade(const char *manifest, uid_t uid, char *const tagv[]);
213 int pkgmgr_parser_process_manifest_x_for_upgrade(manifest_x* mfx, const char *manifest);
214 int pkgmgr_parser_process_usr_manifest_x_for_upgrade(manifest_x* mfx, const char *manifest, uid_t uid);
217 * @fn int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[])
218 * @fn int pkgmgr_parser_parse_usr_manifest_for_uninstallation(const char *manifest, uid_t uid, char *const tagv[])
219 * @brief This API parses the manifest file of the package after uninstallation and deletes the data from DB.
221 * @par This API is for package-manager installer backends.
222 * @par Sync (or) Async : Synchronous API
224 * @param[in] manifest pointer to package manifest file
225 * @param[in] uid the addressee user id of the instruction
226 * @param[in] tagv array of xml tags or NULL
227 * @return 0 if success, error code(<0) if fail
228 * @retval PMINFO_R_OK success
229 * @retval PMINFO_R_EINVAL invalid argument
230 * @retval PMINFO_R_ERROR internal error
234 static int parse_manifest_file_for_uninstallation(const char *manifest)
237 ret = pkgmgr_parser_parse_manifest_for_uninstallation(manifest, NULL);
244 int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[]);
245 int pkgmgr_parser_parse_usr_manifest_for_uninstallation(const char *manifest, uid_t uid, char *const tagv[]);
246 int pkgmgr_parser_process_manifest_x_for_uninstallation(manifest_x* mfx, const char *manifest);
247 int pkgmgr_parser_process_usr_manifest_x_for_uninstallation(manifest_x* mfx, const char *manifest, uid_t uid);
250 * @fn int pkgmgr_parser_parse_manifest_for_preload()
251 * @fn int pkgmgr_parser_parse_usr_manifest_for_preload(uid_t uid)
252 * @brief This API update preload information to DB.
254 * @par This API is for package-manager installer backends.
255 * @par Sync (or) Async : Synchronous API
257 * @return 0 if success, error code(<0) if fail
258 * @retval PMINFO_R_OK success
259 * @retval PMINFO_R_EINVAL invalid argument
260 * @retval PMINFO_R_ERROR internal error
264 static int parser_parse_manifest_for_preload()
267 ret = pkgmgr_parser_parse_manifest_for_preload();
274 int pkgmgr_parser_parse_manifest_for_preload();
275 int pkgmgr_parser_parse_usr_manifest_for_preload(uid_t uid);
278 * @fn int pkgmgr_parser_check_manifest_validation(const char *manifest)
279 * @brief This API validates the manifest file against the manifest schema.
281 * @par This API is for package-manager installer backends.
282 * @par Sync (or) Async : Synchronous API
284 * @param[in] manifest pointer to package manifest file
285 * @return 0 if success, error code(<0) if fail
286 * @retval PMINFO_R_OK success
287 * @retval PMINFO_R_EINVAL invalid argument
288 * @retval PMINFO_R_ERROR internal error
292 static int validate_manifest_file(const char *manifest)
295 ret = pkgmgr_parser_check_manifest_validation(manifest);
302 int pkgmgr_parser_check_manifest_validation(const char *manifest);
305 * @fn void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
306 * @brief This API will free the manifest pointer by recursively freeing all sub elements.
308 * @par This API is for package-manager installer backends.
309 * @par Sync (or) Async : Synchronous API
311 * @param[in] mfx pointer to parsed manifest data
312 * @pre pkgmgr_parser_process_manifest_xml()
315 static int parse_manifest_file(const char *manifest)
317 manifest_x *mfx = NULL
318 mfx = pkgmgr_parser_process_manifest_xml(manifest);
321 printf("Parsing Manifest Success\n");
322 pkgmgr_parser_free_manifest_xml(mfx);
327 void pkgmgr_parser_free_manifest_xml(manifest_x *mfx);
330 * @fn manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest)
331 * @fn manifest_x *pkgmgr_parser_usr_process_manifest_xml(const char *manifest, uid_t uid)
332 * @brief This API parses the manifest file and stores all the data in the manifest structure.
334 * @par This API is for package-manager installer backends.
335 * @par Sync (or) Async : Synchronous API
337 * @param[in] manifest pointer to package manifest file
338 * @param[in] uid the addressee user id of the instruction
339 * @return manifest pointer on success, NULL on failure
341 * @post pkgmgr_parser_free_manifest_xml()
343 static int parse_manifest_file(const char *manifest)
345 manifest_x *mfx = NULL
346 mfx = pkgmgr_parser_process_manifest_xml(manifest);
349 printf("Parsing Manifest Success\n");
350 pkgmgr_parser_free_manifest_xml(mfx);
355 manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest);
356 manifest_x *pkgmgr_parser_usr_process_manifest_xml(const char *manifest, uid_t uid);
359 * @fn int pkgmgr_parser_run_parser_for_installation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
360 * @brief This API calls the parser directly by supplying the xml docptr. It is used during package installation
362 * @par This API is for package-manager installer backends.
363 * @par Sync (or) Async : Synchronous API
365 * @param[in] docPtr XML doxument pointer
366 * @param[in] tag the xml tag corresponding to the parser that will parse the docPtr
367 * @param[in] pkgid the package id
368 * @return 0 if success, error code(<0) if fail
369 * @retval PMINFO_R_OK success
370 * @retval PMINFO_R_EINVAL invalid argument
371 * @retval PMINFO_R_ERROR internal error
375 static int parse_docptr_for_installation(xmlDocPtr docPtr)
378 ret = pkgmgr_parser_run_parser_for_installation(docPtr, "theme", "com.samsung.test");
385 int pkgmgr_parser_run_parser_for_installation(xmlDocPtr docPtr, const char *tag, const char *pkgid);
388 * @fn int pkgmgr_parser_run_parser_for_upgrade(xmlDocPtr docPtr, const char *tag, const char *pkgid)
389 * @brief This API calls the parser directly by supplying the xml docptr. It is used during package upgrade
391 * @par This API is for package-manager installer backends.
392 * @par Sync (or) Async : Synchronous API
394 * @param[in] docPtr XML doxument pointer
395 * @param[in] tag the xml tag corresponding to the parser that will parse the docPtr
396 * @param[in] pkgid the package id
397 * @return 0 if success, error code(<0) if fail
398 * @retval PMINFO_R_OK success
399 * @retval PMINFO_R_EINVAL invalid argument
400 * @retval PMINFO_R_ERROR internal error
404 static int parse_docptr_for_upgrade(xmlDocPtr docPtr)
407 ret = pkgmgr_parser_run_parser_for_upgrade(docPtr, "theme", "com.samsung.test");
414 int pkgmgr_parser_run_parser_for_upgrade(xmlDocPtr docPtr, const char *tag, const char *pkgid);
417 * @fn int pkgmgr_parser_run_parser_for_uninstallation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
418 * @brief This API calls the parser directly by supplying the xml docptr. It is used during package uninstallation
420 * @par This API is for package-manager installer backends.
421 * @par Sync (or) Async : Synchronous API
423 * @param[in] docPtr XML doxument pointer
424 * @param[in] tag the xml tag corresponding to the parser that will parse the docPtr
425 * @param[in] pkgid the package id
426 * @return 0 if success, error code(<0) if fail
427 * @retval PMINFO_R_OK success
428 * @retval PMINFO_R_EINVAL invalid argument
429 * @retval PMINFO_R_ERROR internal error
433 static int parse_docptr_for_uninstallation(xmlDocPtr docPtr)
436 ret = pkgmgr_parser_run_parser_for_uninstallation(docPtr, "theme", "com.samsung.test");
443 int pkgmgr_parser_run_parser_for_uninstallation(xmlDocPtr docPtr, const char *tag, const char *pkgid);
448 * @fn int pkgmgr_parser_create_desktop_file(manifest_x *mfx)
449 * @fn int pkgmgr_parser_create_usr_desktop_file(manifest_x *mfx, uid_t uid)
450 * @brief This API generates the application desktop file
452 * @par This API is for package-manager installer backends.
453 * @par Sync (or) Async : Synchronous API
455 * @param[in] mfx manifest pointer
456 * @param[in] uid the addressee user id of the instruction
457 * @return 0 if success, error code(<0) if fail
458 * @retval PMINFO_R_OK success
459 * @retval PMINFO_R_EINVAL invalid argument
460 * @retval PMINFO_R_ERROR internal error
461 * @pre pkgmgr_parser_process_manifest_xml()
462 * @post pkgmgr_parser_free_manifest_xml()
464 static int create_desktop_file(char *manifest)
467 manifest_x *mfx = NULL;
468 mfx = pkgmgr_parser_process_manifest_xml(manifest);
469 ret = pkgmgr_parser_create_desktop_file(mfx);
472 pkgmgr_parser_free_manifest_xml(mfx);
477 int pkgmgr_parser_create_desktop_file(manifest_x *mfx);
478 int pkgmgr_parser_create_usr_desktop_file(manifest_x *mfx, uid_t uid);
484 #endif /* __PKGMGR_PARSER_H__ */