#include <widget_install/widget_install_errors.h>
#include <widget_install/widget_install_context.h>
#include <widget_install/job_widget_install.h>
-#include <dpl/log/log.h>
#include <dpl/copy.h>
#include <dpl/file_output.h>
+#include "dpl/utils/path.h"
#include <dpl/abstract_waitable_input_adapter.h>
#include <dpl/wrt-dao-ro/global_config.h>
-#include <task_commons.h>
#include <sys/stat.h>
#include <dlfcn.h>
+#include <installer_log.h>
using namespace WrtDB;
void WidgetUnzip::unzipProgress(const std::string &destination)
{
// Show file info
- LogDebug("Unzipping: '" << m_zipIterator->name <<
- "', Comment: '" << m_zipIterator->comment <<
- "', Compressed size: " << m_zipIterator->compressedSize <<
- ", Uncompressed size: " << m_zipIterator->uncompressedSize);
+ _D("Unzipping: '%s', Comment: '%s', Compressed size: %lld, Uncompressed size: %lld",
+ m_zipIterator->name.c_str(), m_zipIterator->comment.c_str(), m_zipIterator->compressedSize, m_zipIterator->uncompressedSize);
// Normalize file paths
// FIXME: Implement checking for invalid characters
// This is path
std::string newPath = destination + "/" +
fileName.substr(0, fileName.size() - 1);
- LogPedantic("Path to extract: " << newPath);
+ _D("Path to extract: %s", newPath.c_str());
// Create path in case of it is empty
- createTempPath(newPath);
+ Try
+ {
+ DPL::Utils::MakeDir(DPL::Utils::Path(newPath));
+ }
+ Catch(DPL::Utils::Path::BaseException)
+ {
+ ThrowMsg(Exceptions::FileOperationFailed, "Failed to create temporary directory");
+ }
} else {
// This is regular file
std::string fileExtractPath = destination + "/" + fileName;
- LogPedantic("File to extract: " << fileExtractPath);
+ _D("File to extract: %s", fileExtractPath.c_str());
// Split into pat & file pair
PathAndFilePair pathAndFile = SplitFileAndPath(fileExtractPath);
- LogPedantic("Path and file: " <<
- pathAndFile.path <<
- " : " << pathAndFile.file);
+ _D("Path and file: %s : %s", pathAndFile.path.c_str(), pathAndFile.file.c_str());
// First, ensure that path exists
- createTempPath(pathAndFile.path);
+ Try
+ {
+ DPL::Utils::MakeDir(DPL::Utils::Path(pathAndFile.path));
+ }
+ Catch(DPL::Utils::Path::BaseException)
+ {
+ ThrowMsg(Exceptions::FileOperationFailed, "Failed to create temporary directory");
+ }
Try
{
// Check whether there are more files to extract
if (++m_zipIterator == m_zip->end()) {
- LogDebug("Unzip progress finished successfuly");
+ _D("Unzip progress finished successfuly");
} else {
unzipProgress(destination);
}
bool WidgetUnzip::isDRMPackage(const std::string &source)
{
- LogDebug("Enter : isDRMPackage()");
+ _D("Enter : isDRMPackage()");
int ret = 0;
void* pHandle = NULL;
char* pErrorMsg = NULL;
pHandle = dlopen(DRM_LIB_PATH, RTLD_LAZY | RTLD_GLOBAL);
if (!pHandle) {
- LogError("dlopen failed : " << source << " [" << dlerror() << "]");
+ _E("dlopen failed : %s [%s]", source.c_str(), dlerror());
return false;
}
+ // clear existing error
+ dlerror();
+
drm_oem_sapps_is_drm_file = reinterpret_cast <int (*)(const char*, int)>
(dlsym(pHandle, "drm_oem_sapps_is_drm_file"));
- pErrorMsg = dlerror();
- if ((pErrorMsg != NULL) || (drm_oem_sapps_is_drm_file == NULL)) {
- LogError("dlopen failed : " << source << " [" << dlerror() << "]");
+
+ if ((pErrorMsg = dlerror()) != NULL) {
+ _E("dlsym failed : %s [%s]", source.c_str(), pErrorMsg);
+ dlclose(pHandle);
+ return false;
+ }
+
+ if (drm_oem_sapps_is_drm_file == NULL) {
+ _E("drm_oem_sapps_is_drm_file is NULL : %s", source.c_str());
dlclose(pHandle);
return false;
}
ret = drm_oem_sapps_is_drm_file(source.c_str(), source.length());
dlclose(pHandle);
if (1 == ret) {
- LogDebug(source << " is DRM file");
+ _D("%s is DRM file", source.c_str());
return true;
}
- LogDebug(source << " isn't DRM file");
+ _D("%s isn't DRM file", source.c_str());
return false;
}
bool WidgetUnzip::decryptDRMPackage(const std::string &source, const std::string
&decryptedSource)
{
- LogDebug("Enter : decryptDRMPackage()");
+ _D("Enter : decryptDRMPackage()");
int ret = 0;
void* pHandle = NULL;
char* pErrorMsg = NULL;
pHandle = dlopen(DRM_LIB_PATH, RTLD_LAZY | RTLD_GLOBAL);
if (!pHandle) {
- LogError("dlopen failed : " << source << " [" << dlerror() << "]");
+ _E("dlopen failed : %s [%s]", source.c_str(), dlerror());
return false;
}
+ // clear existing error
+ dlerror();
+
drm_oem_sapps_decrypt_package = reinterpret_cast <int (*)(const char*, int,
const char*, int)>
(dlsym(pHandle, "drm_oem_sapps_decrypt_package"));
- pErrorMsg = dlerror();
- if ((pErrorMsg != NULL) || (drm_oem_sapps_decrypt_package == NULL)) {
- LogError("dlopen failed : " << source << " [" << dlerror() << "]");
+
+ if ((pErrorMsg = dlerror()) != NULL) {
+ _E("dlsym failed : %s [%s]", source.c_str(), pErrorMsg);
+ dlclose(pHandle);
+ return false;
+ }
+
+ if (drm_oem_sapps_decrypt_package == NULL) {
+ _E("drm_oem_sapps_decrypt_package is NULL : %s", source.c_str());
dlclose(pHandle);
return false;
}
decryptedSource.c_str(), decryptedSource.length());
dlclose(pHandle);
if (1 == ret) {
- LogDebug(source << " is decrypted : " << decryptedSource);
+ _D("%s is decrypted : %s", source.c_str(), decryptedSource.c_str());
return true;
}
return false;
std::string WidgetUnzip::getDecryptedPackage(const std::string &source)
{
- LogDebug("Check DRM...");
+ _D("Check DRM...");
if (isDRMPackage(source)) {
std::string decryptedFile;
size_t found = source.find_last_of(".wgt");
1) + "_tmp.wgt";
}
- LogDebug("decrypted file name : " << decryptedFile);
+ _D("decrypted file name : %s", decryptedFile.c_str());
if (!decryptDRMPackage(source, decryptedFile)) {
- LogError("Failed decrypt drm file");
+ _E("Failed decrypt drm file");
ThrowMsg(Exceptions::DrmDecryptFailed, source);
}
return decryptedFile;
void WidgetUnzip::unzipWgtFile(const std::string &source, const std::string &destination)
{
- LogDebug("Prepare to unzip...");
+ _D("Prepare to unzip...");
std::string wgtFile;
Try
{
wgtFile = getDecryptedPackage(source);
- LogDebug("wgtFile : " << wgtFile);
+ _D("wgtFile : %s", wgtFile.c_str());
m_zip.reset(new DPL::ZipInput(wgtFile));
- LogDebug("Widget package comment: " << m_zip->GetGlobalComment());
+ _D("Widget package comment: %s", m_zip->GetGlobalComment().c_str());
+
// Widget package must not be empty
if (m_zip->empty()) {
m_zip.reset();
// Done
- LogDebug("Unzip finished");
+ _D("Unzip finished");
}
Catch(DPL::ZipInput::Exception::OpenFailed)
{