%define crosswalk_extensions_path %{_libdir}/%{crosswalk_extensions}
Name: webapi-plugins
-Version: 1.91
+Version: 1.92
Release: 0
License: Apache-2.0 and BSD-3-Clause and MIT
Group: Development/Libraries
// categories
picojson::value categories = picojson::value(picojson::array());
picojson::array& categories_array = categories.get<picojson::array>();
- app_info->insert(std::make_pair("categories", categories));
ret = pkgmgrinfo_appinfo_foreach_category(
handle,
},
&categories_array);
+ app_info->insert(std::make_pair("categories", categories));
+
if (PMINFO_R_OK != ret) {
LoggerE("Failed to get categories: %d (%s)", ret, get_error_message(ret));
}
#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
for (auto& nickname : nicknames) {
contacts_record_h nickname_record = nullptr;
- err = contacts_record_get_child_record_at_p(
- contacts_record, _contacts_contact.nickname, 0, &nickname_record);
- if (CONTACTS_ERROR_NONE != err && nullptr == nickname_record) {
- err = contacts_record_create(_contacts_nickname._uri, &nickname_record);
- PlatformResult status =
- ContactUtil::ErrorChecker(err, "Contacts record create error");
- if (status.IsError()) {
- LoggerE("Error: %s", status.message().c_str());
- return status;
- }
-
- update = false;
+ err = contacts_record_create(_contacts_nickname._uri, &nickname_record);
+ PlatformResult status = ContactUtil::ErrorChecker(err, "Contacts record create error");
+ if (status.IsError()) {
+ LoggerE("Error: %s", status.message().c_str());
+ return status;
}
ContactsRecordHPtr nickname_ptr(&nickname_record, ContactsDeleter);
- PlatformResult status =
- ContactUtil::SetStrInRecord(*nickname_ptr, _contacts_nickname.name,
- JsonCast<JsonString>(nickname).c_str());
+ status = ContactUtil::SetStrInRecord(*nickname_ptr, _contacts_nickname.name,
+ JsonCast<JsonString>(nickname).c_str());
if (status.IsError()) {
LoggerE("Error: %s", status.message().c_str());
return status;
}
- if (!update) {
- err = contacts_record_add_child_record(
- contacts_record, _contacts_contact.nickname, *nickname_ptr);
- PlatformResult status =
- ContactUtil::ErrorChecker(err, "Contacts record add child error");
- if (status.IsError()) {
- LoggerE("Error: %s", status.message().c_str());
- return status;
- }
+ err = contacts_record_add_child_record(contacts_record, _contacts_contact.nickname,
+ *nickname_ptr);
+ status = ContactUtil::ErrorChecker(err, "Contacts record add child error");
+ if (status.IsError()) {
+ LoggerE("Error: %s", status.message().c_str());
+ return status;
}
+
// Do not delete record, it is passed to the platform
nickname_ptr.release();
}
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);
var propObj = !listener.isArrayType ?
_createProperty(property, eventObj.result.array[0]) :
_createPropertyArray(property, eventObj.result);
- var executeCall = (T_.isUndefined(listener.lowThreshold) ||
- (propObj.level <= listener.lowThreshold)) ||
- (T_.isUndefined(listener.highThreshold) ||
- (propObj.level >= listener.highThreshold));
+ /*
+ * According to documentation, the condition should look like this:
+ *
+ * (T_.isUndefined(listener.lowThreshold) && T_.isUndefined(listener.highThreshold)) ||
+ * (!T_.isUndefined(listener.lowThreshold) && !T_.isUndefined(listener.highThreshold) && (propObj.level <= listener.lowThreshold || propObj.level >= listener.highThreshold)) ||
+ * (!T_.isUndefined(listener.lowThreshold) && (propObj.level <= listener.lowThreshold)) ||
+ * (!T_.isUndefined(listener.highThreshold) && (propObj.level >= listener.highThreshold))
+ *
+ * but it can be optimized like this:
+ */
+ var executeCall = (T_.isUndefined(listener.lowThreshold) && T_.isUndefined(listener.highThreshold)) ||
+ (!T_.isUndefined(listener.lowThreshold) && propObj.level <= listener.lowThreshold) ||
+ (!T_.isUndefined(listener.highThreshold) && propObj.level >= listener.highThreshold);
+
if (executeCall) {
listener.callback(propObj);
}
var propObj = !listener.isArrayType ?
_createProperty(property, eventObj.result.array[0]) :
_createPropertyArray(property, eventObj.result);
- var executeCall = (T_.isUndefined(listener.lowThreshold) ||
- (propObj.load <= listener.lowThreshold)) ||
- (T_.isUndefined(listener.highThreshold) ||
- (propObj.load >= listener.highThreshold));
+ /*
+ * Optimized condition:
+ * */
+ var executeCall = (T_.isUndefined(listener.lowThreshold) && T_.isUndefined(listener.highThreshold)) ||
+ (!T_.isUndefined(listener.lowThreshold) && propObj.load <= listener.lowThreshold) ||
+ (!T_.isUndefined(listener.highThreshold) && propObj.load >= listener.highThreshold);
if (executeCall) {
listener.callback(propObj);
}
var propObj = !listener.isArrayType ?
_createProperty(property, eventObj.result.array[0]) :
_createPropertyArray(property, eventObj.result);
- var executeCall = (T_.isUndefined(listener.lowThreshold) ||
- (propObj.brightness <= listener.lowThreshold)) ||
- (T_.isUndefined(listener.highThreshold) ||
- (propObj.brightness >= listener.highThreshold));
+ /*
+ * Optimized condition:
+ * */
+ var executeCall = (T_.isUndefined(listener.lowThreshold) && T_.isUndefined(listener.highThreshold)) ||
+ (!T_.isUndefined(listener.lowThreshold) && propObj.brightness <= listener.lowThreshold) ||
+ (!T_.isUndefined(listener.highThreshold) && propObj.brightness >= listener.highThreshold);
if (executeCall) {
listener.callback(propObj);
}