summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSeungha Son <seungha.son@samsung.com>2017-09-21 00:09:57 (GMT)
committerSeungha Son <seungha.son@samsung.com>2017-09-21 04:06:38 (GMT)
commit12c7731f2729214437631e50d38bc427a24c6b7f (patch)
tree4276172d0e4531a57f6dbadd5476b56e8bbfee7d
parent5d62086c49cc7bab9c71da4e7688aee3d2c0a11c (diff)
downloadbadge-12c7731f2729214437631e50d38bc427a24c6b7f.zip
badge-12c7731f2729214437631e50d38bc427a24c6b7f.tar.gz
badge-12c7731f2729214437631e50d38bc427a24c6b7f.tar.bz2
Add function to check if appid existsrefs/changes/90/151390/3
Fixed the problem that badge can be created for nonexistent app Signed-off-by: Seungha Son <seungha.son@samsung.com> Change-Id: I69ed9b55d06559d76e8332e35313b552a4ae9bfe
-rw-r--r--include/badge_setting_service.h1
-rwxr-xr-xsrc/badge_internal.c12
-rw-r--r--src/badge_setting_service.c62
3 files changed, 75 insertions, 0 deletions
diff --git a/include/badge_setting_service.h b/include/badge_setting_service.h
index 9c38a4f..130ca2e 100644
--- a/include/badge_setting_service.h
+++ b/include/badge_setting_service.h
@@ -43,6 +43,7 @@ int badge_setting_insert_package_for_uid(const char *pkgname, uid_t uid);
int badge_setting_delete_package_for_uid(const char *pkgname, uid_t uid);
int badge_setting_refresh_setting_table(uid_t uid);
int badge_db_update_setting(char *pkgname, char *appid, int allow_to_display, uid_t uid);
+int badge_setting_is_existed_appid(const char *appid, bool *is_existed, uid_t uid);
/**
* @}
diff --git a/src/badge_internal.c b/src/badge_internal.c
index 7a63b1f..b625a28 100755
--- a/src/badge_internal.c
+++ b/src/badge_internal.c
@@ -37,6 +37,7 @@
#include "badge_ipc.h"
#include "badge_db.h"
#include "badge_private.h"
+#include "badge_setting_service.h"
#define BADGE_PKGNAME_LEN 512
#define BADGE_TABLE_NAME "badge_data"
@@ -473,10 +474,21 @@ int _badge_insert(badge_h *badge, uid_t uid)
int ret = BADGE_ERROR_NONE;
int result = BADGE_ERROR_NONE;
char *sqlbuf = NULL;
+ bool is_existed = false;
if (!badge || !badge->pkgname || !badge->writable_pkgs)
return BADGE_ERROR_INVALID_PARAMETER;
+ ret = badge_setting_is_existed_appid(badge->pkgname, &is_existed, uid);
+ if (ret == BADGE_ERROR_NONE && is_existed == false) {
+ result = BADGE_ERROR_INVALID_PACKAGE;
+ goto return_close_db;
+ } else if (ret != BADGE_ERROR_NONE) {
+ ERR("Failed to check existed appid [%d]", ret);
+ result = ret;
+ goto return_close_db;
+ }
+
sqlret = db_util_open(BADGE_DB_PATH, &db, 0);
if (sqlret != SQLITE_OK || !db) {
/* LCOV_EXCL_START */
diff --git a/src/badge_setting_service.c b/src/badge_setting_service.c
index 706cc05..ff22bc4 100644
--- a/src/badge_setting_service.c
+++ b/src/badge_setting_service.c
@@ -272,6 +272,68 @@ out:
return ret;
}
+EXPORT_API int badge_setting_is_existed_appid(const char *appid, bool *is_existed, uid_t uid)
+{
+ int ret = BADGE_ERROR_NONE;
+ int sqlret;
+ sqlite3 *db = NULL;
+ sqlite3_stmt *stmt = NULL;
+ char *sqlbuf = NULL;
+ int count = 0;
+
+ if (appid == NULL || is_existed == NULL) {
+ ERR("Invalid parameter");
+ return BADGE_ERROR_INVALID_PARAMETER;
+ }
+
+ sqlret = db_util_open(BADGE_DB_PATH, &db, 0);
+ if (sqlret != SQLITE_OK || !db) {
+ ERR("Failed to db_util_open [%d]", sqlret);
+ if (sqlret == SQLITE_PERM)
+ return BADGE_ERROR_PERMISSION_DENIED;
+ return BADGE_ERROR_FROM_DB;
+ }
+
+ sqlbuf = sqlite3_mprintf("SELECT count(*) FROM %q WHERE " \
+ "appid = %Q AND uid = %d",
+ BADGE_SETTING_DB_TABLE, appid, uid);
+ if (!sqlbuf) {
+ ERR("Failed to alloc query");
+ ret = BADGE_ERROR_OUT_OF_MEMORY;
+ goto out;
+ }
+
+ sqlret = sqlite3_prepare_v2(db, sqlbuf, -1, &stmt, NULL);
+ if (sqlret != SQLITE_OK) {
+ ERR("sqlite3_prepare_v2 failed [%d][%s]", sqlret,
+ sqlite3_errmsg(db));
+ ret = BADGE_ERROR_FROM_DB;
+ goto out;
+ }
+
+ sqlret = sqlite3_step(stmt);
+ if (sqlret == SQLITE_ROW)
+ count = sqlite3_column_int(stmt, 0);
+
+ if (count > 0)
+ *is_existed = true;
+ else
+ *is_existed = false;
+
+out:
+ if (sqlbuf)
+ sqlite3_free(sqlbuf);
+ if (stmt)
+ sqlite3_finalize(stmt);
+ if (db) {
+ sqlret = db_util_close(db);
+ if (sqlret != SQLITE_OK)
+ WARN("Failed to db_util_close [%d]", sqlret);
+ }
+
+ return ret;
+}
+
static bool _is_package_in_setting_table(sqlite3 *db, const char *pkgname, const char* appid, uid_t uid)
{
sqlite3_stmt *db_statement = NULL;