summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorseungha.son <seungha.son@samsung.com>2017-04-04 13:42:13 +0900
committerseungha.son <seungha.son@samsung.com>2017-04-04 19:49:33 +0900
commit10d1320b595a56d4322ee3610a60c9a3a526b04e (patch)
tree00d54a9fbcf22c3399f5a39f32a8514569d4e57d
parent4e1463144e6e1910da14edbdce39fb55bc0bc2ca (diff)
downloadbadge-10d1320b595a56d4322ee3610a60c9a3a526b04e.tar.gz
badge-10d1320b595a56d4322ee3610a60c9a3a526b04e.tar.bz2
badge-10d1320b595a56d4322ee3610a60c9a3a526b04e.zip
Add function for remove badge data when pkg is uninstalled
Signed-off-by: seungha.son <seungha.son@samsung.com> Change-Id: I9556b2fa13807bdb66ccb207204e65201a71dc7b
-rwxr-xr-xinclude/badge_db.h1
-rwxr-xr-xinclude/badge_internal.h2
-rwxr-xr-xsrc/badge_db.c6
-rwxr-xr-xsrc/badge_internal.c168
4 files changed, 177 insertions, 0 deletions
diff --git a/include/badge_db.h b/include/badge_db.h
index b8ad800..00b22f1 100755
--- a/include/badge_db.h
+++ b/include/badge_db.h
@@ -35,6 +35,7 @@ extern "C" {
int badge_db_insert(const char *pkgname, const char *writable_pkg, const char *caller, uid_t uid);
int badge_db_delete(const char *pkgname, const char *caller_pkg, uid_t uid);
+int badge_db_delete_by_pkgname(const char *pkgname, uid_t uid);
int badge_db_set_count(const char *pkgname, const char *caller_pkg, unsigned int count, uid_t uid);
int badge_db_get_count(const char *pkgname, unsigned int *count, uid_t uid);
int badge_db_set_display_option(const char *pkgname, unsigned int is_display, uid_t uid);
diff --git a/include/badge_internal.h b/include/badge_internal.h
index 87905b6..c453960 100755
--- a/include/badge_internal.h
+++ b/include/badge_internal.h
@@ -143,6 +143,8 @@ int _badge_insert(badge_h *badge, uid_t uid);
int _badge_remove(const char *caller, const char *pkgname, uid_t uid);
+int _badge_remove_by_pkgname(const char *pkgname, uid_t uid);
+
int _badge_set_count(const char *caller, const char *pkgname,
unsigned int count, uid_t uid);
diff --git a/src/badge_db.c b/src/badge_db.c
index 5056a8c..73c0675 100755
--- a/src/badge_db.c
+++ b/src/badge_db.c
@@ -147,6 +147,12 @@ int badge_db_delete(const char *pkgname, const char *caller, uid_t uid)
}
EXPORT_API
+int badge_db_delete_by_pkgname(const char *pkgname, uid_t uid)
+{
+ return _badge_remove_by_pkgname(pkgname, uid);
+}
+
+EXPORT_API
int badge_db_set_count(const char *pkgname, const char *caller, unsigned int count, uid_t uid)
{
return _badge_set_count(caller, pkgname, count, uid);
diff --git a/src/badge_internal.c b/src/badge_internal.c
index b4e541f..dc5058f 100755
--- a/src/badge_internal.c
+++ b/src/badge_internal.c
@@ -634,6 +634,174 @@ return_close_db:
return result;
}
+static int _badge_remove_by_appid(const char *appid, uid_t uid, sqlite3 *db)
+{
+ int ret = BADGE_ERROR_NONE;
+ int result = BADGE_ERROR_NONE;
+ char *sqlbuf = NULL;
+
+ ret = _badge_check_data_inserted(appid, db, uid);
+ if (ret != BADGE_ERROR_ALREADY_EXIST) {
+ result = ret;
+ goto return_close_db;
+ }
+
+ sqlbuf = sqlite3_mprintf("DELETE FROM %q WHERE pkgname = %Q AND uid = %d",
+ BADGE_TABLE_NAME, appid, uid);
+ if (!sqlbuf) {
+ /* LCOV_EXCL_START */
+ ERR("fail to alloc query");
+ result = BADGE_ERROR_OUT_OF_MEMORY;
+ goto return_close_db;
+ /* LCOV_EXCL_STOP */
+ }
+
+ ret = badge_db_exec(db, sqlbuf, NULL);
+ if (ret != BADGE_ERROR_NONE) {
+ ERR("failed to remove badge[%s], err[%d]",
+ appid, ret);
+ result = ret;
+ goto return_close_db;
+ }
+
+ /* treating option table */
+ ret = _badge_check_option_inserted(appid, db, uid);
+ if (ret != BADGE_ERROR_ALREADY_EXIST) {
+ result = ret;
+ goto return_close_db;
+ }
+
+ sqlbuf = sqlite3_mprintf("DELETE FROM %q WHERE pkgname = %Q AND uid = %d",
+ BADGE_OPTION_TABLE_NAME, appid, uid);
+ if (!sqlbuf) {
+ /* LCOV_EXCL_START */
+ ERR("fail to alloc query");
+ result = BADGE_ERROR_OUT_OF_MEMORY;
+ goto return_close_db;
+ /* LCOV_EXCL_STOP */
+ }
+
+ ret = badge_db_exec(db, sqlbuf, NULL);
+ if (ret != BADGE_ERROR_NONE) {
+ /* LCOV_EXCL_START */
+ ERR("failed to remove badge option[%s], err[%d]",
+ appid, ret);
+ result = ret;
+ goto return_close_db;
+ /* LCOV_EXCL_STOP */
+ }
+
+return_close_db:
+ if (sqlbuf)
+ sqlite3_free(sqlbuf);
+
+ return result;
+}
+
+static bool _get_table_field_data_string(char **table, char **buf, int ucs2, int index)
+{
+ bool ret = false;
+ int sLen = 0;
+ char *pTemp;
+
+ if (table == NULL || buf == NULL || index < 0) {
+ /* LCOV_EXCL_START */
+ ERR("table[%p], buf[%p], index[%d]", table, buf, index);
+ return false;
+ /* LCOV_EXCL_STOP */
+ }
+
+ pTemp = table[index];
+ if (pTemp == NULL) {
+ *buf = NULL; /* LCOV_EXCL_LINE */
+ } else {
+ sLen = strlen(pTemp);
+ if (sLen) {
+ *buf = (char *)malloc(sLen + 1);
+ if (*buf == NULL) {
+ ERR("malloc is failed"); /* LCOV_EXCL_LINE */
+ goto out;
+ }
+ memset(*buf, 0, sLen + 1);
+ strncpy(*buf, pTemp, sLen);
+ } else {
+ *buf = NULL; /* LCOV_EXCL_LINE */
+ }
+ }
+
+ ret = true;
+
+out:
+ return ret;
+}
+
+int _badge_remove_by_pkgname(const char *pkgname, uid_t uid)
+{
+ int ret = BADGE_ERROR_NONE;
+ int sql_ret;
+ int row_count = 0;
+ int col_count = 0;
+ int col_index = 0;
+ int index;
+ char *sql_query = NULL;
+ char **query_result = NULL;
+ char *appid = NULL;
+ sqlite3 *db = NULL;
+
+ sql_ret = db_util_open(BADGE_DB_PATH, &db, 0);
+ if (sql_ret != SQLITE_OK || db == NULL) {
+ ERR("Failed db util open [%s][%d]", BADGE_DB_PATH, sql_ret);
+ return BADGE_ERROR_FROM_DB;
+ }
+
+ sql_query = sqlite3_mprintf("SELECT appid FROM %s WHERE pkgname = %Q" \
+ "AND (uid = %d OR uid = %d) ORDER BY uid DESC;",
+ BADGE_SETTING_DB_TABLE, pkgname, uid,
+ tzplatform_getuid(TZ_SYS_GLOBALAPP_USER));
+ if (!sql_query) {
+ ERR("fail to alloc query");
+ ret = BADGE_ERROR_FROM_DB;
+ goto out;
+ }
+
+ sql_ret = sqlite3_get_table(db, sql_query, &query_result, &row_count, &col_count, NULL);
+ if (sql_ret != SQLITE_OK && sql_ret != -1) {
+ ERR("sqlite3_get_table failed [%d][%s]", sql_ret, sql_query);
+ ret = BADGE_ERROR_FROM_DB;
+ goto out;
+ }
+
+ if (!row_count) {
+ DBG("No setting found for [%s]", pkgname);
+ ret = BADGE_ERROR_NOT_EXIST;
+ goto out;
+ }
+
+ col_index = col_count;
+
+ for (index = 0; index < row_count; index++) {
+ _get_table_field_data_string(query_result, &appid, 1, col_index++);
+ if (appid) {
+ _badge_remove_by_appid(appid, uid, db);
+ free(appid);
+ appid = NULL;
+ }
+ }
+
+out:
+ if (query_result)
+ sqlite3_free_table(query_result);
+ if (sql_query)
+ sqlite3_free(sql_query);
+ if (db) {
+ sql_ret = db_util_close(db);
+ if (sql_ret != SQLITE_OK)
+ WARN("fail to db_util_close");
+ }
+
+ return ret;
+}
+
int _badge_set_count(const char *caller, const char *pkgname,
unsigned int count, uid_t uid)
{