From: Pawel Andruszkiewicz
Date: Tue, 19 May 2015 08:25:42 +0000 (+0200)
Subject: [Contact] Verify if ringtone local path exists.
X-Git-Tag: submit/tizen_tv/20150603.064601^2~6
X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=033b4e25f4b92c62bc3922a82faeac9bd14c3635;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git
[Contact] Verify if ringtone local path exists.
[Verification] AddressBook_addBatch_errorCallback_invoked passes, pass rate: 440/442.
Change-Id: Idae0f5f639fe0db0ef35972a0313c631aa701b4a
Signed-off-by: Pawel Andruszkiewicz
---
diff --git a/src/contact/contact_util.cc b/src/contact/contact_util.cc
index d8a5eaa2..ff3fe12e 100755
--- a/src/contact/contact_util.cc
+++ b/src/contact/contact_util.cc
@@ -18,6 +18,7 @@
#include
#include
#include
+#include
#include "common/converter.h"
#include "common/logger.h"
@@ -25,6 +26,12 @@ namespace extension {
namespace contact {
namespace ContactUtil {
+using common::ErrorCode;
+using common::FromJson;
+using common::IsNull;
+using common::JsonCast;
+using common::PlatformResult;
+
namespace {
static const std::string kSchema("file://");
@@ -44,8 +51,18 @@ std::string ConvertPathToUri(const std::string& str) {
return kSchema + str;
}
+
+PlatformResult VerifyLocalPath(const std::string& path) {
+ // path should be either empty or point to existing local path
+ bool result = path.length() == 0
+ || (path.length() > 0 && path[0] == '/'
+ && (access(path.c_str(), F_OK) == 0));
+ return PlatformResult(
+ result ? ErrorCode::NO_ERROR : ErrorCode::INVALID_VALUES_ERR);
}
+} // namespace
+
void ContactsDeleter(contacts_record_h* contacts_record) {
if (CONTACTS_ERROR_NONE != contacts_record_destroy(*contacts_record, true)) {
LoggerE("failed to destroy contacts_record_h");
@@ -70,8 +87,6 @@ void ContactsQueryDeleter(contacts_query_h* contacts_query) {
}
}
-using namespace common;
-
namespace {
static const char kContactPhoneTypeHome[] = "HOME";
static const char kContactPhoneTypeWork[] = "WORK";
@@ -2562,7 +2577,9 @@ PlatformResult ExportContactToContactsRecord(contacts_record_h contacts_record,
if (!IsNull(in, "ringtoneURI")) {
real_path =
ContactUtil::ConvertUriToPath(FromJson(in, "ringtoneURI"));
- PlatformResult status = ContactUtil::SetStrInRecord(
+ PlatformResult status = VerifyLocalPath(real_path);
+ if (status.IsError()) return status;
+ status = ContactUtil::SetStrInRecord(
contacts_record, _contacts_contact.ringtone_path, real_path.c_str());
if (status.IsError()) {
LoggerE("Error: %s", status.message().c_str());