#include <privilegemgr/privilege_manager.h>
#include <app_manager.h>
#include <pkgmgr-info.h>
+#include <sys/stat.h>
#ifdef PRIVILEGE_USE_DB
#include <sqlite3.h>
return hex;
}
+bool IsPathValid(const std::string& path) {
+ LoggerD("Enter");
+
+ /*
+ * Directory dot-referencing is not allowed
+ */
+ return std::string::npos == path.find("/../") &&
+ std::string::npos == path.find("/./") &&
+ 0 != path.find("./") &&
+ 0 != path.find("../") &&
+ path.length() - 2 != path.rfind("/.") &&
+ path.length() - 3 != path.rfind("/..");
+}
+
+PlatformResult CheckFileStatus(const std::string& path) {
+ LoggerD("Enter");
+
+ struct stat buf;
+
+ if (stat(path.c_str(), &buf)) {
+ LoggerD("Failed to stat path: %s", path.c_str());
+
+ if (ENOENT == errno) {
+ return PlatformResult(ErrorCode::NOT_FOUND_ERR, "File does not exist: " + path);
+ } else if (EACCES == errno) {
+ return PlatformResult(ErrorCode::IO_ERR, "The user cannot access the file: " + path);
+ }
+
+ LoggerD("stat() error: %s", common::tools::GetErrorString(errno).c_str());
+ return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot get status of the file: " + path);
+ }
+
+ if (!S_ISREG(buf.st_mode)) {
+ return PlatformResult(ErrorCode::NOT_FOUND_ERR, "Path does not point to a regular file: "
+ + path);
+ }
+
+ if (!(S_IRUSR & buf.st_mode)) {
+ return PlatformResult(ErrorCode::IO_ERR, "The user cannot read the file: " + path);
+ }
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult CheckFileAvailability(const std::string& path) {
+ LoggerD("Enter");
+
+ if (!IsPathValid(path)) {
+ return PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Invalid path: " + path);
+ }
+
+ return CheckFileStatus(path);
+}
+
} // namespace tools
} // namespace common
unsigned char* HexToBin(const char* hex, int size, unsigned char* bin, int bin_size);
char* BinToHex(const unsigned char* bin, int size, char* hex, int hex_size);
+bool IsPathValid(const std::string& path);
+
+PlatformResult CheckFileStatus(const std::string& path);
+
+PlatformResult CheckFileAvailability(const std::string& path);
+
} // namespace tools
} // namespace common
if (native_.isFailure(result)) {
native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
} else {
-
// call to c++ code. Fields that do not exist are undefined.
var exifInfoNative = native_.getResultObject(result);
}
};
- tizen.filesystem.resolve(args.uri,
- function() {
- native_.call('ExifManager_getExifInfo', {'uri': args.uri}, callback);
- },
- function() {
- native_.callIfPossible(args.errorCallback, new WebAPIException(
- WebAPIException.NOT_FOUND_ERR,
- 'File can not be found.'));
- });
+ native_.call('ExifManager_getExifInfo', {'uri': args.uri}, callback);
};
ExifManager.prototype.saveExifInfo = function() {
}
};
- tizen.filesystem.resolve(args.uri,
- function() {
- native_.call('ExifManager_getThumbnail', {'uri': args.uri}, _callback);
- },
- function() {
- native_.callIfPossible(args.errorCallback, new WebAPIException(
- WebAPIException.NOT_FOUND_ERR,
- 'File can not be found.'));
- });
+ native_.call('ExifManager_getThumbnail', {'uri': args.uri}, _callback);
};
tizen.ExifInformation = function() {
#include "common/logger.h"
#include "common/platform_result.h"
#include "common/task-queue.h"
+#include "common/tools.h"
#include "exif/exif_information.h"
#include "exif/exif_util.h"
PlatformResult status(ErrorCode::NO_ERROR);
const std::string &file_path = ExifUtil::convertUriToPath(uri);
+
+ PlatformResult fileAvailability(common::tools::CheckFileAvailability(file_path));
+ if (!fileAvailability) {
+ LogAndReportError(fileAvailability, &response->get<picojson::object>());
+ return;
+ }
+
LoggerD("file_path = %s", file_path.c_str());
status = GetExifInfo::LoadFromURI(uri, &result);
JsonValue result = JsonValue(JsonObject());
JsonObject &result_obj = result.get<JsonObject>();
+ PlatformResult fileAvailability(common::tools::CheckFileAvailability(file_path));
+ if (!fileAvailability) {
+ LogAndReportError(fileAvailability, &response->get<picojson::object>());
+ return;
+ }
+
+ LoggerD("file_path = %s", file_path.c_str());
+
std::string ext = file_path.substr(file_path.find_last_of(".") + 1);
std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower);