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 * @fn char *pkgmgr_parser_get_manifest_file(const char *pkgid)
74 * @brief This API gets the manifest file of the package.
76 * @par This API is for package-manager installer backends.
77 * @par Sync (or) Async : Synchronous API
79 * @param[in] pkgid pointer to package ID
80 * @return manifest file path on success, NULL on failure
82 * @post Free the manifest file pointer that is returned by API
84 static int get_manifest_file(const char *pkgid)
86 char *manifest = NULL;
87 manifest = pkgmgr_parser_get_manifest_file(pkgid);
90 printf("Manifest File Path is %s\n", manifest);
96 char *pkgmgr_parser_get_manifest_file(const char *pkgid);
97 char *pkgmgr_parser_get_usr_manifest_file(const char *pkgid, uid_t uid);
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.
104 * @par This API is for package-manager installer backends.
105 * @par Sync (or) Async : Synchronous API
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
117 static int parse_manifest_file_for_installation(const char *manifest)
120 ret = pkgmgr_parser_parse_manifest_for_installation(manifest, NULL);
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 int pkgmgr_parser_process_manifest_x_for_installation(manifest_x* mfx, const char *manifest);
130 int pkgmgr_parser_process_usr_manifest_x_for_installation(manifest_x* mfx, const char *manifest, uid_t uid);
133 * @fn int pkgmgr_parser_update_tep(const char* pkgid, const char * tep_path)
134 * @fn int pkgmgr_parser_usr_update_tep(const char* pkgid, const char* tep_path, uid_t uid)
135 * @brief This API updates tep path information stored in DB.
137 * @par This API is for package-manager installer backends.
138 * @par Sync (or) Async : Synchronous API
140 * @param[in] pkgid pointer to package ID
141 * @param[in]tep_path pointer to path of TEP file
142 * @param[in] uid the addressee user id of the instruction
143 * @return 0 if success, error code(<0) if fail
144 * @retval PMINFO_R_OK success
145 * @retval PMINFO_R_EINVAL invalid argument
146 * @retval PMINFO_R_ERROR internal error
150 static int update_tep_info_for_upgrade(const char *pkgid, const char *tep_path)
153 ret = pkgmgr_parser_update_tep(pkgid, tep_path);
160 int pkgmgr_parser_update_tep(const char* pkgid, const char* tep_path);
161 int pkgmgr_parser_usr_update_tep(const char* pkgid, const char* tep_path, uid_t uid);
164 * @fn int pkgmgr_parser_parse_usr_manifest_for_upgrade(const char *manifest, uid_t uid, char *const tagv[])
165 * @fn int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[])
166 * @brief This API parses the manifest file of the package after upgrade and stores the data in DB.
168 * @par This API is for package-manager installer backends.
169 * @par Sync (or) Async : Synchronous API
171 * @param[in] manifest pointer to package manifest file
172 * @param[in] uid the addressee user id of the instruction
173 * @param[in] tagv array of xml tags or NULL
174 * @return 0 if success, error code(<0) if fail
175 * @retval PMINFO_R_OK success
176 * @retval PMINFO_R_EINVAL invalid argument
177 * @retval PMINFO_R_ERROR internal error
181 static int parse_manifest_file_for_upgrade(const char *manifest)
184 ret = pkgmgr_parser_parse_manifest_for_upgrade(manifest, NULL);
191 int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[]);
192 int pkgmgr_parser_parse_usr_manifest_for_upgrade(const char *manifest, uid_t uid, char *const tagv[]);
193 int pkgmgr_parser_process_manifest_x_for_upgrade(manifest_x* mfx, const char *manifest);
194 int pkgmgr_parser_process_usr_manifest_x_for_upgrade(manifest_x* mfx, const char *manifest, uid_t uid);
197 * @fn int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[])
198 * @fn int pkgmgr_parser_parse_usr_manifest_for_uninstallation(const char *manifest, uid_t uid, char *const tagv[])
199 * @brief This API parses the manifest file of the package after uninstallation and deletes the data from DB.
201 * @par This API is for package-manager installer backends.
202 * @par Sync (or) Async : Synchronous API
204 * @param[in] manifest pointer to package manifest file
205 * @param[in] uid the addressee user id of the instruction
206 * @param[in] tagv array of xml tags or NULL
207 * @return 0 if success, error code(<0) if fail
208 * @retval PMINFO_R_OK success
209 * @retval PMINFO_R_EINVAL invalid argument
210 * @retval PMINFO_R_ERROR internal error
214 static int parse_manifest_file_for_uninstallation(const char *manifest)
217 ret = pkgmgr_parser_parse_manifest_for_uninstallation(manifest, NULL);
224 int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[]);
225 int pkgmgr_parser_parse_usr_manifest_for_uninstallation(const char *manifest, uid_t uid, char *const tagv[]);
226 int pkgmgr_parser_process_manifest_x_for_uninstallation(manifest_x* mfx, const char *manifest);
227 int pkgmgr_parser_process_usr_manifest_x_for_uninstallation(manifest_x* mfx, const char *manifest, uid_t uid);
230 * @fn int pkgmgr_parser_parse_manifest_for_preload()
231 * @fn int pkgmgr_parser_parse_usr_manifest_for_preload(uid_t uid)
232 * @brief This API update preload information to DB.
234 * @par This API is for package-manager installer backends.
235 * @par Sync (or) Async : Synchronous API
237 * @return 0 if success, error code(<0) if fail
238 * @retval PMINFO_R_OK success
239 * @retval PMINFO_R_EINVAL invalid argument
240 * @retval PMINFO_R_ERROR internal error
244 static int parser_parse_manifest_for_preload()
247 ret = pkgmgr_parser_parse_manifest_for_preload();
254 int pkgmgr_parser_parse_manifest_for_preload();
255 int pkgmgr_parser_parse_usr_manifest_for_preload(uid_t uid);
258 * @fn int pkgmgr_parser_check_manifest_validation(const char *manifest)
259 * @brief This API validates the manifest file against the manifest schema.
261 * @par This API is for package-manager installer backends.
262 * @par Sync (or) Async : Synchronous API
264 * @param[in] manifest pointer to package manifest file
265 * @return 0 if success, error code(<0) if fail
266 * @retval PMINFO_R_OK success
267 * @retval PMINFO_R_EINVAL invalid argument
268 * @retval PMINFO_R_ERROR internal error
272 static int validate_manifest_file(const char *manifest)
275 ret = pkgmgr_parser_check_manifest_validation(manifest);
282 int pkgmgr_parser_check_manifest_validation(const char *manifest);
285 * @fn void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
286 * @brief This API will free the manifest pointer by recursively freeing all sub elements.
288 * @par This API is for package-manager installer backends.
289 * @par Sync (or) Async : Synchronous API
291 * @param[in] mfx pointer to parsed manifest data
292 * @pre pkgmgr_parser_process_manifest_xml()
295 static int parse_manifest_file(const char *manifest)
297 manifest_x *mfx = NULL
298 mfx = pkgmgr_parser_process_manifest_xml(manifest);
301 printf("Parsing Manifest Success\n");
302 pkgmgr_parser_free_manifest_xml(mfx);
307 void pkgmgr_parser_free_manifest_xml(manifest_x *mfx);
310 * @fn manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest)
311 * @fn manifest_x *pkgmgr_parser_usr_process_manifest_xml(const char *manifest, uid_t uid)
312 * @brief This API parses the manifest file and stores all the data in the manifest structure.
314 * @par This API is for package-manager installer backends.
315 * @par Sync (or) Async : Synchronous API
317 * @param[in] manifest pointer to package manifest file
318 * @param[in] uid the addressee user id of the instruction
319 * @return manifest pointer on success, NULL on failure
321 * @post pkgmgr_parser_free_manifest_xml()
323 static int parse_manifest_file(const char *manifest)
325 manifest_x *mfx = NULL
326 mfx = pkgmgr_parser_process_manifest_xml(manifest);
329 printf("Parsing Manifest Success\n");
330 pkgmgr_parser_free_manifest_xml(mfx);
335 manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest);
336 manifest_x *pkgmgr_parser_usr_process_manifest_xml(const char *manifest, uid_t uid);
339 * @fn int pkgmgr_parser_run_parser_for_installation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
340 * @brief This API calls the parser directly by supplying the xml docptr. It is used during package installation
342 * @par This API is for package-manager installer backends.
343 * @par Sync (or) Async : Synchronous API
345 * @param[in] docPtr XML doxument pointer
346 * @param[in] tag the xml tag corresponding to the parser that will parse the docPtr
347 * @param[in] pkgid the package id
348 * @return 0 if success, error code(<0) if fail
349 * @retval PMINFO_R_OK success
350 * @retval PMINFO_R_EINVAL invalid argument
351 * @retval PMINFO_R_ERROR internal error
355 static int parse_docptr_for_installation(xmlDocPtr docPtr)
358 ret = pkgmgr_parser_run_parser_for_installation(docPtr, "theme", "com.samsung.test");
365 int pkgmgr_parser_run_parser_for_installation(xmlDocPtr docPtr, const char *tag, const char *pkgid);
368 * @fn int pkgmgr_parser_run_parser_for_upgrade(xmlDocPtr docPtr, const char *tag, const char *pkgid)
369 * @brief This API calls the parser directly by supplying the xml docptr. It is used during package upgrade
371 * @par This API is for package-manager installer backends.
372 * @par Sync (or) Async : Synchronous API
374 * @param[in] docPtr XML doxument pointer
375 * @param[in] tag the xml tag corresponding to the parser that will parse the docPtr
376 * @param[in] pkgid the package id
377 * @return 0 if success, error code(<0) if fail
378 * @retval PMINFO_R_OK success
379 * @retval PMINFO_R_EINVAL invalid argument
380 * @retval PMINFO_R_ERROR internal error
384 static int parse_docptr_for_upgrade(xmlDocPtr docPtr)
387 ret = pkgmgr_parser_run_parser_for_upgrade(docPtr, "theme", "com.samsung.test");
394 int pkgmgr_parser_run_parser_for_upgrade(xmlDocPtr docPtr, const char *tag, const char *pkgid);
397 * @fn int pkgmgr_parser_run_parser_for_uninstallation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
398 * @brief This API calls the parser directly by supplying the xml docptr. It is used during package uninstallation
400 * @par This API is for package-manager installer backends.
401 * @par Sync (or) Async : Synchronous API
403 * @param[in] docPtr XML doxument pointer
404 * @param[in] tag the xml tag corresponding to the parser that will parse the docPtr
405 * @param[in] pkgid the package id
406 * @return 0 if success, error code(<0) if fail
407 * @retval PMINFO_R_OK success
408 * @retval PMINFO_R_EINVAL invalid argument
409 * @retval PMINFO_R_ERROR internal error
413 static int parse_docptr_for_uninstallation(xmlDocPtr docPtr)
416 ret = pkgmgr_parser_run_parser_for_uninstallation(docPtr, "theme", "com.samsung.test");
423 int pkgmgr_parser_run_parser_for_uninstallation(xmlDocPtr docPtr, const char *tag, const char *pkgid);
428 * @fn int pkgmgr_parser_create_desktop_file(manifest_x *mfx)
429 * @fn int pkgmgr_parser_create_usr_desktop_file(manifest_x *mfx, uid_t uid)
430 * @brief This API generates the application desktop file
432 * @par This API is for package-manager installer backends.
433 * @par Sync (or) Async : Synchronous API
435 * @param[in] mfx manifest pointer
436 * @param[in] uid the addressee user id of the instruction
437 * @return 0 if success, error code(<0) if fail
438 * @retval PMINFO_R_OK success
439 * @retval PMINFO_R_EINVAL invalid argument
440 * @retval PMINFO_R_ERROR internal error
441 * @pre pkgmgr_parser_process_manifest_xml()
442 * @post pkgmgr_parser_free_manifest_xml()
444 static int create_desktop_file(char *manifest)
447 manifest_x *mfx = NULL;
448 mfx = pkgmgr_parser_process_manifest_xml(manifest);
449 ret = pkgmgr_parser_create_desktop_file(mfx);
452 pkgmgr_parser_free_manifest_xml(mfx);
457 int pkgmgr_parser_create_desktop_file(manifest_x *mfx);
458 int pkgmgr_parser_create_usr_desktop_file(manifest_x *mfx, uid_t uid);
464 #endif /* __PKGMGR_PARSER_H__ */