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[]);
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.
135 * @par This API is for package-manager installer backends.
136 * @par Sync (or) Async : Synchronous API
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
148 static int parse_manifest_file_for_installation(const char *manifest, const char *tep_path)
151 ret = pkgmgr_parser_parse_manifest_for_installation_withtep(manifest, tep_path, NULL);
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[]);
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.
166 * @par This API is for package-manager installer backends.
167 * @par Sync (or) Async : Synchronous API
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
179 static int update_tep_info_for_upgrade(const char *pkgid, const char *tep_path)
182 ret = pkgmgr_parser_update_tep(pkgid, tep_path);
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);
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.
197 * @par This API is for package-manager installer backends.
198 * @par Sync (or) Async : Synchronous API
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
210 static int parse_manifest_file_for_upgrade(const char *manifest)
213 ret = pkgmgr_parser_parse_manifest_for_upgrade(manifest, NULL);
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[]);
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.
227 * @par This API is for package-manager installer backends.
228 * @par Sync (or) Async : Synchronous API
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
240 static int parse_manifest_file_for_uninstallation(const char *manifest)
243 ret = pkgmgr_parser_parse_manifest_for_uninstallation(manifest, NULL);
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[]);
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.
257 * @par This API is for package-manager installer backends.
258 * @par Sync (or) Async : Synchronous API
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
267 static int parser_parse_manifest_for_preload()
270 ret = pkgmgr_parser_parse_manifest_for_preload();
277 int pkgmgr_parser_parse_manifest_for_preload();
278 int pkgmgr_parser_parse_usr_manifest_for_preload(uid_t uid);
281 * @fn int pkgmgr_parser_check_manifest_validation(const char *manifest)
282 * @brief This API validates the manifest file against the manifest schema.
284 * @par This API is for package-manager installer backends.
285 * @par Sync (or) Async : Synchronous API
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
295 static int validate_manifest_file(const char *manifest)
298 ret = pkgmgr_parser_check_manifest_validation(manifest);
305 int pkgmgr_parser_check_manifest_validation(const char *manifest);
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.
311 * @par This API is for package-manager installer backends.
312 * @par Sync (or) Async : Synchronous API
314 * @param[in] mfx pointer to parsed manifest data
315 * @pre pkgmgr_parser_process_manifest_xml()
318 static int parse_manifest_file(const char *manifest)
320 manifest_x *mfx = NULL
321 mfx = pkgmgr_parser_process_manifest_xml(manifest);
324 printf("Parsing Manifest Success\n");
325 pkgmgr_parser_free_manifest_xml(mfx);
330 void pkgmgr_parser_free_manifest_xml(manifest_x *mfx);
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.
337 * @par This API is for package-manager installer backends.
338 * @par Sync (or) Async : Synchronous API
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
344 * @post pkgmgr_parser_free_manifest_xml()
346 static int parse_manifest_file(const char *manifest)
348 manifest_x *mfx = NULL
349 mfx = pkgmgr_parser_process_manifest_xml(manifest);
352 printf("Parsing Manifest Success\n");
353 pkgmgr_parser_free_manifest_xml(mfx);
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);
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
365 * @par This API is for package-manager installer backends.
366 * @par Sync (or) Async : Synchronous API
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
378 static int parse_docptr_for_installation(xmlDocPtr docPtr)
381 ret = pkgmgr_parser_run_parser_for_installation(docPtr, "theme", "com.samsung.test");
388 int pkgmgr_parser_run_parser_for_installation(xmlDocPtr docPtr, const char *tag, const char *pkgid);
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
394 * @par This API is for package-manager installer backends.
395 * @par Sync (or) Async : Synchronous API
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
407 static int parse_docptr_for_upgrade(xmlDocPtr docPtr)
410 ret = pkgmgr_parser_run_parser_for_upgrade(docPtr, "theme", "com.samsung.test");
417 int pkgmgr_parser_run_parser_for_upgrade(xmlDocPtr docPtr, const char *tag, const char *pkgid);
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
423 * @par This API is for package-manager installer backends.
424 * @par Sync (or) Async : Synchronous API
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
436 static int parse_docptr_for_uninstallation(xmlDocPtr docPtr)
439 ret = pkgmgr_parser_run_parser_for_uninstallation(docPtr, "theme", "com.samsung.test");
446 int pkgmgr_parser_run_parser_for_uninstallation(xmlDocPtr docPtr, const char *tag, const char *pkgid);
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
455 * @par This API is for package-manager installer backends.
456 * @par Sync (or) Async : Synchronous API
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()
467 static int create_desktop_file(char *manifest)
470 manifest_x *mfx = NULL;
471 mfx = pkgmgr_parser_process_manifest_xml(manifest);
472 ret = pkgmgr_parser_create_desktop_file(mfx);
475 pkgmgr_parser_free_manifest_xml(mfx);
480 int pkgmgr_parser_create_desktop_file(manifest_x *mfx);
481 int pkgmgr_parser_create_usr_desktop_file(manifest_x *mfx, uid_t uid);
487 #endif /* __PKGMGR_PARSER_H__ */