[Contact] Verify if ringtone local path exists.
authorPawel Andruszkiewicz <p.andruszkie@samsung.com>
Tue, 19 May 2015 08:25:42 +0000 (10:25 +0200)
committerPawel Andruszkiewicz <p.andruszkie@samsung.com>
Tue, 19 May 2015 08:25:42 +0000 (10:25 +0200)
[Verification] AddressBook_addBatch_errorCallback_invoked passes, pass rate: 440/442.

Change-Id: Idae0f5f639fe0db0ef35972a0313c631aa701b4a
Signed-off-by: Pawel Andruszkiewicz <p.andruszkie@samsung.com>
src/contact/contact_util.cc

index 5567036fb111e8108157fcd0eced2af02fe88756..cf1ca84df93ad9cf018a3aa8293af943616d572e 100644 (file)
@@ -18,6 +18,7 @@
 #include <algorithm>
 #include <iomanip>
 #include <string>
+#include <unistd.h>
 #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<JsonString>(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;
   }