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.
27 #include <libxml/parser.h>
28 #include <libxml/xmlschemas.h>
31 #include "pkgmgr-info.h"
32 #include "pkgmgrinfo_basic.h"
34 #include "pkgmgr_parser.h"
35 #include "pkgmgr_parser_internal.h"
36 #include "pkgmgr_parser_db.h"
37 #include "pkgmgr_parser_debug.h"
39 #define LIBAPPSVC_PATH LIB_PATH "/libappsvc.so.0"
41 static int __ps_remove_appsvc_db(manifest_x *mfx, uid_t uid)
43 void *lib_handle = NULL;
44 int (*appsvc_operation) (const char *, uid_t);
47 application_x *application;
49 if ((lib_handle = dlopen(LIBAPPSVC_PATH, RTLD_LAZY)) == NULL) {
50 _LOGE("dlopen is failed LIBAPPSVC_PATH[%s]\n", LIBAPPSVC_PATH);
54 if ((appsvc_operation =
55 dlsym(lib_handle, "appsvc_unset_defapp")) == NULL || dlerror() != NULL) {
56 _LOGE("can not find symbol \n");
60 for (tmp = mfx->application; tmp; tmp = tmp->next) {
61 application = (application_x *)tmp->data;
62 if (application == NULL)
64 ret = appsvc_operation(application->appid, uid);
66 _LOGE("can not operation symbol \n");
76 API void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
78 pkgmgrinfo_basic_free_package((package_x *)mfx);
81 API int pkgmgr_parser_usr_update_tep(const char *pkgid, const char *tep_path, uid_t uid)
83 return pkgmgr_parser_update_tep_info_in_usr_db(pkgid, tep_path, uid);
86 API int pkgmgr_parser_update_tep(const char *pkgid, const char *tep_path)
88 return pkgmgr_parser_update_tep_info_in_db(pkgid, tep_path);
91 API int pkgmgr_parser_process_manifest_x_for_installation(manifest_x* mfx)
93 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
96 ret = pkgmgr_parser_insert_manifest_info_in_db(mfx);
97 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
98 _LOGD("DB Insert Success\n");
103 API int pkgmgr_parser_process_usr_manifest_x_for_installation(manifest_x* mfx, uid_t uid)
105 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
108 ret = pkgmgr_parser_insert_manifest_info_in_usr_db(mfx, uid);
109 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
110 _LOGD("DB Insert Success\n");
115 API int pkgmgr_parser_process_manifest_x_for_upgrade(manifest_x* mfx)
117 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
120 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
121 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
122 _LOGD("DB Update Success\n");
127 API int pkgmgr_parser_process_usr_manifest_x_for_upgrade(manifest_x* mfx, uid_t uid)
129 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
132 ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
133 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
134 _LOGD("DB Update Success\n");
139 API int pkgmgr_parser_process_manifest_x_for_uninstallation(manifest_x* mfx)
141 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
144 ret = pkgmgr_parser_delete_manifest_info_from_db(mfx);
146 _LOGD("DB Delete failed\n");
148 _LOGD("DB Delete Success\n");
153 API int pkgmgr_parser_process_usr_manifest_x_for_uninstallation(manifest_x* mfx, uid_t uid)
155 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
158 ret = pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, uid);
160 _LOGD("DB Delete failed\n");
162 _LOGD("DB Delete Success\n");
164 ret = __ps_remove_appsvc_db(mfx, uid);
166 _LOGD("Removing appsvc_db failed\n");
168 _LOGD("Removing appsvc_db Success\n");
173 #define SCHEMA_FILE SYSCONFDIR "/package-manager/preload/manifest.xsd"
174 API int pkgmgr_parser_check_manifest_validation(const char *manifest)
176 if (manifest == NULL) {
177 _LOGE("manifest file is NULL\n");
178 return PMINFO_R_EINVAL;
181 xmlSchemaParserCtxtPtr ctx;
182 xmlSchemaValidCtxtPtr vctx;
183 xmlSchemaPtr xschema;
184 ctx = xmlSchemaNewParserCtxt(SCHEMA_FILE);
186 _LOGE("xmlSchemaNewParserCtxt() Failed\n");
187 return PMINFO_R_ERROR;
189 xschema = xmlSchemaParse(ctx);
190 if (xschema == NULL) {
191 _LOGE("xmlSchemaParse() Failed\n");
192 xmlSchemaFreeParserCtxt(ctx);
193 return PMINFO_R_ERROR;
195 vctx = xmlSchemaNewValidCtxt(xschema);
197 _LOGE("xmlSchemaNewValidCtxt() Failed\n");
198 xmlSchemaFree(xschema);
199 xmlSchemaFreeParserCtxt(ctx);
200 return PMINFO_R_ERROR;
202 xmlSchemaSetValidErrors(vctx, (xmlSchemaValidityErrorFunc) fprintf, (xmlSchemaValidityWarningFunc) fprintf, stderr);
203 ret = xmlSchemaValidateFile(vctx, manifest, 0);
205 _LOGE("xmlSchemaValidateFile() failed\n");
206 ret = PMINFO_R_ERROR;
207 } else if (ret == 0) {
208 _LOGD("Manifest is Valid\n");
211 _LOGE("Manifest Validation Failed with error code %d\n", ret);
212 ret = PMINFO_R_ERROR;
214 xmlSchemaFreeValidCtxt(vctx);
215 xmlSchemaFree(xschema);
216 xmlSchemaFreeParserCtxt(ctx);