#include <algorithm>
#include <iomanip>
#include <string>
+#include <unistd.h>
#include "common/converter.h"
#include "common/logger.h"
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://");
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");
}
}
-using namespace common;
-
namespace {
static const char kContactPhoneTypeHome[] = "HOME";
static const char kContactPhoneTypeWork[] = "WORK";
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;
}