From 3d26244c05849df6de11fc591adcdd7c992fdadd Mon Sep 17 00:00:00 2001
From: Pawel Andruszkiewicz
Date: Tue, 19 May 2015 10:25:42 +0200
Subject: [PATCH] [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
---
src/contact/contact_util.cc | 23 ++++++++++++++++++++---
1 file changed, 20 insertions(+), 3 deletions(-)
diff --git a/src/contact/contact_util.cc b/src/contact/contact_util.cc
index 5567036f..cf1ca84d 100644
--- 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";
@@ -2098,7 +2113,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()) return status;
}
--
2.34.1