From: Hwankyu Jhun Date: Tue, 18 Aug 2020 01:43:29 +0000 (+0900) Subject: Fix AUL metadata plugin parser X-Git-Tag: accepted/tizen/unified/20200820.034757~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F58%2F241058%2F6;p=platform%2Fcore%2Fappfw%2Faul-1.git Fix AUL metadata plugin parser - Adds db integrty check & busy handler - Fixes data deletion from appsvc db - Adds missing interfaces of pkgmgr metadata plugin Change-Id: Ieaf5f4dbfbf49d6384ef355e9d5480fdb310d218 Signed-off-by: Hwankyu Jhun --- diff --git a/data/appsvc_db.sql b/data/appsvc_db.sql index fc297b9..d7dbbc9 100755 --- a/data/appsvc_db.sql +++ b/data/appsvc_db.sql @@ -20,9 +20,6 @@ CREATE TABLE IF NOT EXISTS alias_info_for_uid ( uid INTEGER NOT NULL, is_enabled TEXT NOT NULL DEFAULT 'false', PRIMARY KEY (appid, uid) - FOREIGN KEY (appid) - REFERENCES alias_info(appid) - ON DELETE CASCADE ); CREATE TRIGGER IF NOT EXISTS update_alias_info_for_uid diff --git a/parser/metadata/inc/metadata_plugin_parser.h b/parser/metadata/inc/metadata_plugin_parser.h index ac51aac..8ec25b4 100644 --- a/parser/metadata/inc/metadata_plugin_parser.h +++ b/parser/metadata/inc/metadata_plugin_parser.h @@ -1,14 +1,14 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2016 - 2020 Samsung Electronics Co., Ltd All Rights Reserved * - * Licensed under the Apache License, Version 2.0 (the License); + * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, + * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. @@ -17,27 +17,16 @@ #ifndef __METADATA_PLUGIN_PARSER_H__ #define __METADATA_PLUGIN_PARSER_H__ -#include #include #include -#include -#ifndef API -#define API __attribute__ ((visibility("default"))) -#endif +int metadata_plugin_parser_install(const char *pkgid, const char *appid, + GList *list); -#ifdef LOG_TAG -#undef LOG_TAG -#define LOG_TAG "METADATA_PLUGIN_PARSER" -#endif +int metadata_plugin_parser_uninstall(const char *pkgid, const char *appid, + GList *list); -typedef enum { - METADATA_EVENT_TYPE_INSTALL, - METADATA_EVENT_TYPE_UNINSTALL, - METADATA_EVENT_TYPE_UPGRADE, -} metadata_event_type_e; - -int metadata_plugin_parser(const char *pkgid, const char *appid, GList *list, - metadata_event_type_e event_type); +int metadata_plugin_parser_upgrade(const char *pkgid, const char *appid, + GList *list); #endif /* __METADATA_PLUGIN_PARSER_H__ */ diff --git a/parser/metadata/inc/metadata_plugin_parser_db.h b/parser/metadata/inc/metadata_plugin_parser_db.h index c190bdc..d572980 100644 --- a/parser/metadata/inc/metadata_plugin_parser_db.h +++ b/parser/metadata/inc/metadata_plugin_parser_db.h @@ -1,14 +1,14 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2016 - 2020 Samsung Electronics Co., Ltd All Rights Reserved * - * Licensed under the Apache License, Version 2.0 (the License); + * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, + * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. @@ -19,11 +19,22 @@ int metadata_parser_db_insert_alias_info(const char *alias_appid, const char *appid); + int metadata_parser_db_delete_alias_info(const char *appid); + int metadata_parser_db_insert_allowed_info(const char *appid, const char *allowed_appid); + int metadata_parser_db_delete_allowed_info(const char *appid); + int metadata_parser_db_init(void); + void metadata_parser_db_fini(void); +int metadata_parser_db_begin_transaction(void); + +int metadata_parser_db_end_transaction(void); + +int metadata_parser_db_rollback(void); + #endif /* __METADATA_PLUGIN_PARSER_DB_H__ */ diff --git a/parser/metadata/inc/metadata_plugin_parser_handler.h b/parser/metadata/inc/metadata_plugin_parser_handler.h index 9aa7c19..3c8a355 100644 --- a/parser/metadata/inc/metadata_plugin_parser_handler.h +++ b/parser/metadata/inc/metadata_plugin_parser_handler.h @@ -1,14 +1,14 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2016 - 2020 Samsung Electronics Co., Ltd All Rights Reserved * - * Licensed under the Apache License, Version 2.0 (the License); + * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, + * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. @@ -19,8 +19,16 @@ int metadata_parser_handler_install(const char *appid, const char *key, const char *value); -int metadata_parser_handler_uninstall(const char *appid); + +int metadata_parser_handler_uninstall(const char *appid, + const char *key, const char *value); + +int metadata_parser_handler_uninstall_all(const char *appid); + int metadata_parser_handler_init(void); + void metadata_parser_handler_fini(void); +int metadata_parser_handler_rollback(void); + #endif /* __METADATA_PLUGIN_PARSER_HANDLER_H__ */ diff --git a/parser/metadata/inc/metadata_plugin_parser_private.h b/parser/metadata/inc/metadata_plugin_parser_private.h new file mode 100644 index 0000000..4f3aa3d --- /dev/null +++ b/parser/metadata/inc/metadata_plugin_parser_private.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __METADATA_PLUGIN_PARSER_PRIVATE_H__ +#define __METADATA_PLUGIN_PARSER_PRIVATE_H__ + +#include + +#undef LOG_TAG +#define LOG_TAG "METADATA_PLUGIN_PARSER" + +#undef _E +#define _E LOGE + +#undef _W +#define _W LOGW + +#undef _I +#define _I LOGI + +#undef _D +#define _D LOGD + +#undef API +#define API __attribute__ ((visibility("default"))) + +#endif /* __METADATA_PLUGIN_PARSER_PRIVATE_H__ */ diff --git a/parser/metadata/src/metadata_plugin_parser.c b/parser/metadata/src/metadata_plugin_parser.c index bef88ee..a0ec680 100644 --- a/parser/metadata/src/metadata_plugin_parser.c +++ b/parser/metadata/src/metadata_plugin_parser.c @@ -1,14 +1,14 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2016 - 2020 Samsung Electronics Co., Ltd All Rights Reserved * - * Licensed under the Apache License, Version 2.0 (the License); + * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, + * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. @@ -23,56 +23,83 @@ #include "metadata_plugin_parser.h" #include "metadata_plugin_parser_handler.h" +#include "metadata_plugin_parser_private.h" typedef struct metadata { const char *key; const char *value; } metadata; -int metadata_plugin_parser(const char *pkgid, const char *appid, GList *list, - metadata_event_type_e event_type) +int metadata_plugin_parser_install(const char *pkgid, const char *appid, + GList *list) { metadata *md; GList *iter; int ret; - if (pkgid == NULL || appid == NULL || list == NULL) { - LOGE("Invalid parameter"); - return -1; + ret = metadata_parser_handler_init(); + if (ret < 0) + return ret; + + iter = list; + while (iter) { + md = (metadata *)iter->data; + ret = metadata_parser_handler_install(appid, md->key, + md->value); + if (ret < 0) { + _E("Failed to install %s:%s", md->key, md->value); + metadata_parser_handler_rollback(); + break; + } + + iter = g_list_next(iter); } + metadata_parser_handler_fini(); + return ret; +} + +int metadata_plugin_parser_uninstall(const char *pkgid, const char *appid, + GList *list) +{ + metadata *md; + GList *iter; + int ret; + ret = metadata_parser_handler_init(); - if (ret < 0) { - LOGE("Failed to initialize metadata handler"); - return -1; - } + if (ret < 0) + return ret; - if (event_type == METADATA_EVENT_TYPE_UNINSTALL || - event_type == METADATA_EVENT_TYPE_UPGRADE) { - ret = metadata_parser_handler_uninstall(appid); - if (ret < 0) - LOGW("Failed to uninstall metadata"); - } + iter = list; + while (iter) { + md = (metadata *)iter->data; + ret = metadata_parser_handler_uninstall(appid, md->key, + md->value); + if (ret < 0) { + _E("Failed to uninstall %s:%s", md->key, md->value); + metadata_parser_handler_rollback(); + break; + } - if (event_type == METADATA_EVENT_TYPE_INSTALL || - event_type == METADATA_EVENT_TYPE_UPGRADE) { - iter = g_list_first(list); - while (iter) { - md = (metadata *)iter->data; - if (md) { - ret = metadata_parser_handler_install(appid, - md->key, md->value); - if (ret < 0) { - LOGE("Failed to install %s:%s", - md->key, md->value); - } - } + iter = g_list_next(iter); + } - iter = g_list_next(iter); + if (!list) { + ret = metadata_parser_handler_uninstall_all(appid); + if (ret < 0) { + _E("Failed to uninstall all metadata info. appid(%s)", + appid); + metadata_parser_handler_rollback(); } } metadata_parser_handler_fini(); + return ret; +} - return 0; +int metadata_plugin_parser_upgrade(const char *pkgid, const char *appid, + GList *list) +{ + metadata_plugin_parser_uninstall(pkgid, appid, list); + return metadata_plugin_parser_install(pkgid, appid, list); } diff --git a/parser/metadata/src/metadata_plugin_parser_db.c b/parser/metadata/src/metadata_plugin_parser_db.c index 779e597..d82538b 100644 --- a/parser/metadata/src/metadata_plugin_parser_db.c +++ b/parser/metadata/src/metadata_plugin_parser_db.c @@ -1,65 +1,60 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2016 - 2020 Samsung Electronics Co., Ltd All Rights Reserved * - * Licensed under the Apache License, Version 2.0 (the License); + * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, + * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ +#include +#include #include #include #include -#include -#include #include -#include +#include +#include #include #include -#include -#include #include "metadata_plugin_parser_db.h" - -#ifndef LOG_TAG -#define LOG_TAG "METADATA_PLUGIN_PARSER_DB" -#endif +#include "metadata_plugin_parser_private.h" #define ROOT_UID 0 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) +#define BUSY_WAITING_USEC 50000 +#define BUSY_WAITING_MAX 40 -static bool target_uid_initialized; -static uid_t target_uid; -static sqlite3 *appsvc_db; +static sqlite3 *__db; static uid_t __get_target_uid(void) { + static uid_t target_uid = (uid_t)-1; int ret; - if (target_uid_initialized) + if (target_uid != (uid_t)-1) return target_uid; ret = pkgmgr_installer_info_get_target_uid(&target_uid); if (ret < 0) { - LOGE("Failed to get target uid - %d", ret); + _E("Failed to get target uid. error(%d)", ret); return target_uid; } - target_uid_initialized = true; - return target_uid; } -static char *__get_appsvc_db_path(uid_t uid) +static const char *__get_db_path(uid_t uid) { - char db_path[PATH_MAX]; + static char db_path[PATH_MAX]; if (uid == ROOT_UID || uid == GLOBAL_USER) { snprintf(db_path, sizeof(db_path), "%s/.appsvc.db", @@ -69,49 +64,129 @@ static char *__get_appsvc_db_path(uid_t uid) tzplatform_getenv(TZ_SYS_DB), uid); } - return strdup(db_path); + return db_path; +} + +static int __db_busy_handler(void *data, int count) +{ + const char *path = (const char *)data; + + if (count < BUSY_WAITING_MAX) { + usleep(BUSY_WAITING_USEC); + return 1; + } + + _E("Database(%s) is busy", path); + + return 0; } -static int __appsvc_db_init(uid_t uid) +static sqlite3 *__open_db(const char *path) { + sqlite3 *db; int ret; - char *db_path; - if (appsvc_db) - return 0; + ret = sqlite3_open_v2(path, &db, SQLITE_OPEN_READWRITE, NULL); + if (ret != SQLITE_OK) { + _E("sqlite3_open_v2() is failed. error(%d)", ret); + return NULL; + } - db_path = __get_appsvc_db_path(uid); - if (db_path == NULL) { - LOGE("Failed to get service db path - %d", uid); - return -1; + ret = sqlite3_busy_handler(db, __db_busy_handler, (void *)path); + if (ret != SQLITE_OK) { + _E("sqlite3_busy_handler() is failed. error(%s:%d)", + sqlite3_errmsg(db), ret); + sqlite3_close_v2(db); + return NULL; } - ret = sqlite3_open_v2(db_path, &appsvc_db, SQLITE_OPEN_READWRITE, NULL); - free(db_path); + ret = sqlite3_exec(db, "PRAGMA foreign_keys=ON", NULL, NULL, NULL); if (ret != SQLITE_OK) { - LOGE("sqlite3_open_v2() is failed - %d(%s)", - ret, sqlite3_errmsg(appsvc_db)); - return -1; + _E("sqlite3_exec() is failed. error(%s:%d)", + sqlite3_errmsg(db), ret); + sqlite3_close_v2(db); + return NULL; } - return 0; + return db; } -static void __appsvc_db_fini(void) +static void __close_db(sqlite3 *db) { - if (!appsvc_db) + if (!db) return; - sqlite3_close(appsvc_db); - appsvc_db = NULL; + sqlite3_close_v2(db); +} + +static bool __integrity_check(sqlite3 *db) +{ + static const char query[] = "PRAGMA integrity_check"; + sqlite3_stmt *stmt = NULL; + const char *res; + int ret; + + ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); + if (ret != SQLITE_OK) { + _E("sqlite3_prepare_v2() is failed. error(%s:%d)", + sqlite3_errmsg(db), ret); + return false; + } + + ret = sqlite3_step(stmt); + if (ret != SQLITE_ROW) { + _E("sqlite3_step() is failed. error(%s:%d)", + sqlite3_errmsg(db), ret); + sqlite3_finalize(stmt); + return false; + } + + res = (const char *)sqlite3_column_text(stmt, 0); + if (!res) { + _E("Failed to check integrity db. error(%s:%d)", + sqlite3_errmsg(db), ret); + sqlite3_finalize(stmt); + return false; + } + + if (strcmp(res, "ok") != 0) { + sqlite3_finalize(stmt); + return false; + } + + sqlite3_finalize(stmt); + return true; } int metadata_parser_db_init(void) { uid_t uid = __get_target_uid(); + const char *path; + int ret; + + if (__db) + return 0; - if (__appsvc_db_init(uid) < 0) { - LOGE("Failed to initialize appsvc db"); + path = __get_db_path(uid); + if (!path) { + _E("Failed to get db path. uid(%u)", uid); + return -1; + } + + ret = access(path, F_OK); + if (ret != 0) + _E("Database(%s) does not exist", path); + + __db = __open_db(path); + if (!__db) { + _E("Failed to open db(%s)", path); + return -1; + } + + if (!__integrity_check(__db)) { + _E("Database(%s) is corrupted", path); + __close_db(__db); + __db = NULL; return -1; } @@ -120,185 +195,242 @@ int metadata_parser_db_init(void) void metadata_parser_db_fini(void) { - __appsvc_db_fini(); + if (!__db) + return; + + __close_db(__db); + __db = NULL; +} + +int metadata_parser_db_begin_transaction(void) +{ + int ret; + + if (!__db) { + _E("Database is not prepared"); + return -1; + } + + ret = sqlite3_exec(__db, "BEGIN TRANSACTION", NULL, NULL, NULL); + if (ret != SQLITE_OK) { + _E("sqlite3_exec() is failed. error(%s:%d)", + sqlite3_errmsg(__db), ret); + return -1; + } + + return 0; +} + +int metadata_parser_db_end_transaction(void) +{ + int ret; + + if (!__db) { + _E("Database is not preapred"); + return -1; + } + + ret = sqlite3_exec(__db, "END TRANSACTION", NULL, NULL, NULL); + if (ret != SQLITE_OK) { + _E("sqlite3_exec() is failed. error(%s:%d)", + sqlite3_errmsg(__db), ret); + return -1; + } + + return 0; +} + +int metadata_parser_db_rollback(void) +{ + int ret; + + if (!__db) { + _E("Database is not prepared"); + return -1; + } + + ret = sqlite3_exec(__db, "ROLLBACK", NULL, NULL, NULL); + if (ret != SQLITE_OK) { + _E("sqlite3_exec() is failed. error(%s:%d)", + sqlite3_errmsg(__db), ret); + return -1; + } + + return 0; } int metadata_parser_db_insert_alias_info(const char *alias_appid, const char *appid) { - int ret; - int result = 0; - sqlite3_stmt *stmt = NULL; const char *query = - "INSERT OR REPLACE INTO alias_info(alias_appid, appid) " \ + "INSERT OR REPLACE INTO alias_info(alias_appid, appid) " "values(?,?);"; + sqlite3_stmt *stmt; + int result = 0; + int ret; if (alias_appid == NULL || appid == NULL) { - LOGE("Invalid parameters"); + _E("Invalid parameters"); return -1; } - ret = sqlite3_prepare_v2(appsvc_db, query, strlen(query), &stmt, NULL); + ret = sqlite3_prepare_v2(__db, query, strlen(query), &stmt, NULL); if (ret != SQLITE_OK) { - LOGE("sqlite3_prepare_v2() error: %d(%s)", - ret, sqlite3_errmsg(appsvc_db)); + _E("sqlite3_prepare_v2() is failed. error(%s:%d)", + sqlite3_errmsg(__db), ret); return -1; } ret = sqlite3_bind_text(stmt, 1, alias_appid, -1, SQLITE_TRANSIENT); if (ret != SQLITE_OK) { - LOGE("sqlite3_bind_text() error: %d(%s)", - ret, sqlite3_errmsg(appsvc_db)); + _E("sqlite3_bind_text() is failed. error(%s:%d)", + sqlite3_errmsg(__db), ret); result = -1; goto end; } ret = sqlite3_bind_text(stmt, 2, appid, -1, SQLITE_TRANSIENT); if (ret != SQLITE_OK) { - LOGE("sqlite3_bind_text() error: %d(%s)", - ret, sqlite3_errmsg(appsvc_db)); + _E("sqlite3_bind_text() is failed. error(%s:%d)", + sqlite3_errmsg(__db), ret); result = -1; goto end; } ret = sqlite3_step(stmt); if (ret != SQLITE_DONE) { - LOGE("sqlite3_step() error: %d(%s)", - ret, sqlite3_errmsg(appsvc_db)); + _E("sqlite3_step() is failed. error(%s:%d)", + sqlite3_errmsg(__db), ret); result = -1; } end: sqlite3_finalize(stmt); - return result; } int metadata_parser_db_delete_alias_info(const char *appid) { - int ret; - int result = 0; - sqlite3_stmt *stmt = NULL; const char *query = "DELETE FROM alias_info WHERE appid = ?;"; + sqlite3_stmt *stmt; + int result = 0; + int ret; if (appid == NULL) { - LOGE("Invalid parameter"); + _E("Invalid parameter"); return -1; } - ret = sqlite3_prepare_v2(appsvc_db, query, strlen(query), &stmt, NULL); + ret = sqlite3_prepare_v2(__db, query, strlen(query), &stmt, NULL); if (ret != SQLITE_OK) { - LOGE("sqlite3_prepare_v2() error: %d(%s)", - ret, sqlite3_errmsg(appsvc_db)); + _E("sqlite3_prepare_v2() is failed. error(%s:%d)", + sqlite3_errmsg(__db), ret); return -1; } ret = sqlite3_bind_text(stmt, 1, appid, -1, SQLITE_TRANSIENT); if (ret != SQLITE_OK) { - LOGE("sqlite3_bind_text() error: %d(%s)", - ret, sqlite3_errmsg(appsvc_db)); + _E("sqlite3_bind_text() is failed. error(%s:%d)", + sqlite3_errmsg(__db), ret); result = -1; goto end; } ret = sqlite3_step(stmt); if (ret != SQLITE_DONE) { - LOGW("sqlite3_step() error: %d(%s)", - ret, sqlite3_errmsg(appsvc_db)); + _W("sqlite3_step() is failed. error(%s:%d)", + sqlite3_errmsg(__db), ret); } end: sqlite3_finalize(stmt); - return result; } int metadata_parser_db_insert_allowed_info(const char *appid, const char *allowed_appid) { - int ret; - int result = 0; - sqlite3_stmt *stmt = NULL; const char *query = - "INSERT OR REPLACE INTO allowed_info(appid, allowed_appid) " \ + "INSERT OR REPLACE INTO allowed_info(appid, allowed_appid) " "values(?,?);"; + sqlite3_stmt *stmt; + int result = 0; + int ret; if (allowed_appid == NULL || appid == NULL) { - LOGE("Invalid parameters"); + _E("Invalid parameters"); return -1; } - ret = sqlite3_prepare_v2(appsvc_db, query, strlen(query), &stmt, NULL); + ret = sqlite3_prepare_v2(__db, query, strlen(query), &stmt, NULL); if (ret != SQLITE_OK) { - LOGE("sqlite3_prepare_v2() error: %d(%s)", - ret, sqlite3_errmsg(appsvc_db)); + _E("sqlite3_prepare_v2() is failed. error(%s:%d)", + sqlite3_errmsg(__db), ret); return -1; } ret = sqlite3_bind_text(stmt, 1, appid, -1, SQLITE_TRANSIENT); if (ret != SQLITE_OK) { - LOGE("sqlite3_bind_text() error: %d(%s)", - ret, sqlite3_errmsg(appsvc_db)); + _E("sqlite3_bind_text() is failed. error(%s:%d)", + sqlite3_errmsg(__db), ret); result = -1; goto end; } ret = sqlite3_bind_text(stmt, 2, allowed_appid, -1, SQLITE_TRANSIENT); if (ret != SQLITE_OK) { - LOGE("sqlite3_bind_text() error: %d(%s)", - ret, sqlite3_errmsg(appsvc_db)); + _E("sqlite3_bind_text() is failed. error(%s:%d)", + sqlite3_errmsg(__db), ret); result = -1; goto end; } ret = sqlite3_step(stmt); if (ret != SQLITE_DONE) { - LOGE("sqlite3_step() error: %d(%s)", - ret, sqlite3_errmsg(appsvc_db)); + _E("sqlite3_step() is failed. error(%s:%d)", + sqlite3_errmsg(__db), ret); result = -1; } end: sqlite3_finalize(stmt); - return result; } int metadata_parser_db_delete_allowed_info(const char *appid) { - int ret; - int result = 0; - sqlite3_stmt *stmt = NULL; const char *query = "DELETE FROM allowed_info WHERE appid = ?;"; + sqlite3_stmt *stmt; + int result = 0; + int ret; if (appid == NULL) { - LOGE("Invalid parameter"); + _E("Invalid parameter"); return -1; } - ret = sqlite3_prepare_v2(appsvc_db, query, strlen(query), &stmt, NULL); + ret = sqlite3_prepare_v2(__db, query, strlen(query), &stmt, NULL); if (ret != SQLITE_OK) { - LOGE("sqlite3_prepare_v2() error: %d(%s)", - ret, sqlite3_errmsg(appsvc_db)); + _E("sqlite3_prepare_v2() is failed. error(%s:%d)", + sqlite3_errmsg(__db), ret); return -1; } ret = sqlite3_bind_text(stmt, 1, appid, -1, SQLITE_TRANSIENT); if (ret != SQLITE_OK) { - LOGE("sqlite3_bind_text() error: %d(%s)", - ret, sqlite3_errmsg(appsvc_db)); + _E("sqlite3_bind_text() is failed. error(%s:%d)", + sqlite3_errmsg(__db), ret); result = -1; goto end; } ret = sqlite3_step(stmt); if (ret != SQLITE_DONE) { - LOGW("sqlite3_step() error: %d(%s)", - ret, sqlite3_errmsg(appsvc_db)); + _W("sqlite3_step() is failed. error(%s:%d)", + sqlite3_errmsg(__db), ret); } end: sqlite3_finalize(stmt); - return result; } diff --git a/parser/metadata/src/metadata_plugin_parser_handler.c b/parser/metadata/src/metadata_plugin_parser_handler.c index 8583903..c1268a6 100644 --- a/parser/metadata/src/metadata_plugin_parser_handler.c +++ b/parser/metadata/src/metadata_plugin_parser_handler.c @@ -1,38 +1,35 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2016 - 2020 Samsung Electronics Co., Ltd All Rights Reserved * - * Licensed under the Apache License, Version 2.0 (the License); + * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, + * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include #include -#include #include #include #include -#include #include "metadata_plugin_parser_db.h" #include "metadata_plugin_parser_handler.h" - -#ifndef LOG_TAG -#define LOG_TAG "METADATA_PLUGIN_PARSER_HANDLER" -#endif +#include "metadata_plugin_parser_private.h" #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) typedef int (*metadata_parser_dispatch_install)(const char *appid, const char *key, const char *value); + typedef int (*metadata_parser_dispatch_uninstall)(const char *appid); typedef struct metadater_parser_dispatcher_s { @@ -74,7 +71,7 @@ static int __init_metadata_key_table(void) key_table = g_hash_table_new(g_int_hash, g_str_equal); if (key_table == NULL) { - LOGE("out of memory"); + _E("out of memory"); return -1; } @@ -101,17 +98,27 @@ int metadata_parser_handler_init(void) ret = metadata_parser_db_init(); if (ret < 0) - return -1; + return ret; + + ret = __init_metadata_key_table(); + if (ret < 0) + return ret; - return __init_metadata_key_table(); + return metadata_parser_db_begin_transaction(); } void metadata_parser_handler_fini(void) { + metadata_parser_db_end_transaction(); __fini_metadata_key_table(); metadata_parser_db_fini(); } +int metadata_parser_handler_rollback(void) +{ + return metadata_parser_db_rollback(); +} + static enum metadata_key __get_metadata_key(const char *key) { if (key == NULL) @@ -126,7 +133,7 @@ static int __install_alias_info(const char *appid, int ret; if (appid == NULL || key == NULL || value == NULL) { - LOGE("Invalid parameter"); + _E("Invalid parameter"); return -1; } @@ -142,7 +149,7 @@ static int __uninstall_alias_info(const char *appid) int ret; if (appid == NULL) { - LOGE("Invalid parameter"); + _E("Invalid parameter"); return -1; } @@ -159,7 +166,7 @@ static int __install_allowed_info(const char *appid, int ret; if (appid == NULL || key == NULL || value == NULL) { - LOGE("Invalid parameter"); + _E("Invalid parameter"); return -1; } @@ -175,7 +182,7 @@ static int __uninstall_allowed_info(const char *appid) int ret; if (appid == NULL) { - LOGE("Invalid parameter"); + _E("Invalid parameter"); return -1; } @@ -208,7 +215,26 @@ int metadata_parser_handler_install(const char *appid, dispatch_table[mkey].install) { ret = dispatch_table[mkey].install(appid, key, value); if (ret < 0) { - LOGE("[%s] error - %d", key, ret); + _E("Failed to install %s", key); + return -1; + } + } + + return 0; +} + +int metadata_parser_handler_uninstall(const char *appid, + const char *key, const char *value) +{ + enum metadata_key mkey; + int ret; + + mkey = __get_metadata_key(key); + if (mkey > KEY_NONE && mkey < KEY_MAX && + dispatch_table[mkey].uninstall) { + ret = dispatch_table[mkey].uninstall(appid); + if (ret < 0) { + _E("Failed to uninstall %s", key); return -1; } } @@ -216,16 +242,16 @@ int metadata_parser_handler_install(const char *appid, return 0; } -int metadata_parser_handler_uninstall(const char *appid) +int metadata_parser_handler_uninstall_all(const char *appid) { enum metadata_key iter; int ret; - for (iter = KEY_NONE + 1; iter < KEY_MAX; iter++) { + for (iter = KEY_NONE + 1; iter < KEY_MAX; ++iter) { if (dispatch_table[iter].uninstall) { ret = dispatch_table[iter].uninstall(appid); if (ret < 0) - LOGW("[%d] error - %d", iter, ret); + _W("Failed to uninstall %d", iter); } } diff --git a/parser/metadata/src/metadata_plugin_parser_pkgmgr_interface.c b/parser/metadata/src/metadata_plugin_parser_pkgmgr_interface.c index fc0500a..8ecf434 100644 --- a/parser/metadata/src/metadata_plugin_parser_pkgmgr_interface.c +++ b/parser/metadata/src/metadata_plugin_parser_pkgmgr_interface.c @@ -1,14 +1,14 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2016 - 2020 Samsung Electronics Co., Ltd All Rights Reserved * - * Licensed under the Apache License, Version 2.0 (the License); + * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, + * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. @@ -17,45 +17,67 @@ #include #include "metadata_plugin_parser.h" +#include "metadata_plugin_parser_private.h" API int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *list) { - return metadata_plugin_parser(pkgid, appid, list, - METADATA_EVENT_TYPE_INSTALL); + _W("pkgid(%s), appid(%s)", pkgid, appid); + return metadata_plugin_parser_install(pkgid, appid, list); } API int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList *list) { - return metadata_plugin_parser(pkgid, appid, list, - METADATA_EVENT_TYPE_UNINSTALL); + _W("pkgid(%s), appid(%s)", pkgid, appid); + return metadata_plugin_parser_uninstall(pkgid, appid, list); } API int PKGMGR_MDPARSER_PLUGIN_UPGRADE(const char *pkgid, const char *appid, GList *list) { - return metadata_plugin_parser(pkgid, appid, list, - METADATA_EVENT_TYPE_UPGRADE); + _W("pkgid(%s), appid(%s)", pkgid, appid); + return metadata_plugin_parser_upgrade(pkgid, appid, list); } API int PKGMGR_MDPARSER_PLUGIN_RECOVERINSTALL(const char *pkgid, const char *appid, GList *list) { - return metadata_plugin_parser(pkgid, appid, list, - METADATA_EVENT_TYPE_UNINSTALL); + _W("pkgid(%s), appid(%s)", pkgid, appid); + return metadata_plugin_parser_uninstall(pkgid, appid, list); } API int PKGMGR_MDPARSER_PLUGIN_RECOVERUNINSTALL(const char *pkgid, const char *appid, GList *list) { - return metadata_plugin_parser(pkgid, appid, list, - METADATA_EVENT_TYPE_UNINSTALL); + _W("pkgid(%s), appid(%s)", pkgid, appid); + return metadata_plugin_parser_uninstall(pkgid, appid, list); } API int PKGMGR_MDPARSER_PLUGIN_RECOVERUPGRADE(const char *pkgid, const char *appid, GList *list) { - return metadata_plugin_parser(pkgid, appid, list, - METADATA_EVENT_TYPE_UPGRADE); + _W("pkgid(%s), appid(%s)", pkgid, appid); + return metadata_plugin_parser_upgrade(pkgid, appid, list); +} + +API int PKGMGR_MDPARSER_PLUGIN_CLEAN(const char *pkgid, + const char *appid, GList *list) +{ + _W("pkgid(%s), appid(%s)", pkgid, appid); + return 0; +} + +API int PKGMGR_MDPARSER_PLUGIN_UNDO(const char *pkgid, + const char *appid, GList *list) +{ + _W("pkgid(%s), appid(%s)", pkgid, appid); + return metadata_plugin_parser_uninstall(pkgid, appid, list); +} + +API int PKGMGR_MDPARSER_PLUGIN_REMOVED(const char *pkgid, + const char *appid, GList *list) +{ + _W("pkgid(%s), appid(%s)", pkgid, appid); + return metadata_plugin_parser_uninstall(pkgid, appid, list); }