* @version 1.0
* @brief This file contains the definition of Configuration.
*/
-
+#include <stddef.h>
#include <dpl/wrt-dao-rw/widget_dao.h>
#include <sstream>
message); \
}
-#define CHECK_WIDGET_EXISTENCE(macro_transaction, macro_handle) \
- if (!WidgetDAO::isWidgetInstalled(macro_handle)) \
- { \
- macro_transaction.Commit(); \
- LogWarning("Cannot find widget. Handle: " << macro_handle); \
- ThrowMsg(WidgetDAO::Exception::WidgetNotExist, \
- "Cannot find widget. Handle: " << macro_handle); \
- }
-
-
-WidgetDAO::WidgetDAO(DbWidgetHandle widgetHandle) :
- WidgetDAOReadOnly(widgetHandle)
-{
-}
-
WidgetDAO::WidgetDAO(DPL::OptionalString widgetGUID) :
WidgetDAOReadOnly(WidgetDAOReadOnly::getHandle(widgetGUID))
+// TODO THIS WILL BE DELETED
{
}
{
}
+WidgetDAO::WidgetDAO(DbWidgetHandle handle) :
+ WidgetDAOReadOnly(handle)
+{
+}
+
WidgetDAO::~WidgetDAO()
{
}
SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register widget")
}
+void WidgetDAO::setPkgName_NOTNULL(const DPL::String& pkgName)
+{
+ SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+ {
+ using namespace DPL::DB::ORM;
+ wrt::ScopedTransaction transaction(&WrtDatabase::interface());
+
+ isWidgetInstalled(getHandle());
+
+ wrt::WidgetInfo::Row row;
+ row.Set_pkgname(pkgName);
+
+ WRT_DB_UPDATE(update, wrt::WidgetInfo, &WrtDatabase::interface())
+ update->Where(
+ Equals<wrt::WidgetInfo::app_id>(getHandle()));
+
+ update->Values(row);
+ update->Execute();
+ transaction.Commit();
+ }
+ SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register widget")
+}
+
+void WidgetDAO::setSecurityPopupUsage(const SettingsType value)
+{
+ SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+ {
+ using namespace DPL::DB::ORM;
+ using namespace DPL::DB::ORM::wrt;
+
+ ScopedTransaction transaction(&WrtDatabase::interface());
+ if (!isWidgetInstalled(getHandle())) {
+ ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
+ "Cannot find widget. Handle: " << getHandle());
+ }
+
+ WidgetSecuritySettings::Row row;
+ row.Set_security_popup_usage(value);
+
+ WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
+ update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
+ update->Values(row);
+ update->Execute();
+
+ transaction.Commit();
+ }
+ SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set security popup usage")
+}
+
+void WidgetDAO::setGeolocationUsage(const SettingsType value)
+{
+ SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+ {
+ using namespace DPL::DB::ORM;
+ using namespace DPL::DB::ORM::wrt;
+
+ ScopedTransaction transaction(&WrtDatabase::interface());
+ if (!isWidgetInstalled(getHandle())) {
+ ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
+ "Cannot find widget. Handle: " << getHandle());
+ }
+
+ WidgetSecuritySettings::Row row;
+ row.Set_geolocation_usage(value);
+
+ WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
+ update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
+ update->Values(row);
+ update->Execute();
+
+ transaction.Commit();
+ }
+ SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set geolocation usage")
+}
+
+void WidgetDAO::setWebNotificationUsage(const SettingsType value)
+{
+ SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+ {
+ using namespace DPL::DB::ORM;
+ using namespace DPL::DB::ORM::wrt;
+
+ ScopedTransaction transaction(&WrtDatabase::interface());
+ if (!isWidgetInstalled(getHandle())) {
+ ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
+ "Cannot find widget. Handle: " << getHandle());
+ }
+
+ WidgetSecuritySettings::Row row;
+ row.Set_web_notification_usage(value);
+
+ WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
+ update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
+ update->Values(row);
+ update->Execute();
+
+ transaction.Commit();
+ }
+ SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set web notification usage")
+}
+
+void WidgetDAO::setWebDatabaseUsage(const SettingsType value)
+{
+ SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+ {
+ using namespace DPL::DB::ORM;
+ using namespace DPL::DB::ORM::wrt;
+
+ ScopedTransaction transaction(&WrtDatabase::interface());
+ if (!isWidgetInstalled(getHandle())) {
+ ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
+ "Cannot find widget. Handle: " << getHandle());
+ }
+
+ WidgetSecuritySettings::Row row;
+ row.Set_web_database_usage(value);
+
+ WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
+ update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
+ update->Values(row);
+ update->Execute();
+
+ transaction.Commit();
+ }
+ SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set web database usage")
+}
+
+void WidgetDAO::setFileSystemUsage(const SettingsType value)
+{
+ SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+ {
+ using namespace DPL::DB::ORM;
+ using namespace DPL::DB::ORM::wrt;
+
+ ScopedTransaction transaction(&WrtDatabase::interface());
+ if (!isWidgetInstalled(getHandle())) {
+ ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
+ "Cannot find widget. Handle: " << getHandle());
+ }
+
+ WidgetSecuritySettings::Row row;
+ row.Set_file_system_usage(value);
+
+ WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
+ update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
+ update->Values(row);
+ update->Execute();
+
+ transaction.Commit();
+ }
+ SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set filesystem usage")
+}
+
void WidgetDAO::registerWidget(
- const DbWidgetHandle& widgetHandle,
+ const WidgetPkgName & widgetPkgname,
const WidgetRegisterInfo &widgetRegInfo,
const IWacSecurity &wacSecurity)
{
SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
{
DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
+ registerWidgetInternal(widgetPkgname, widgetRegInfo, wacSecurity);
+ transaction.Commit();
+ }
+ SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register widget")
+}
+
+void WidgetDAO::registerWidget(
+ WrtDB::DbWidgetHandle handle,
+ const WidgetRegisterInfo &widgetRegInfo,
+ const IWacSecurity &wacSecurity)
+{
+ LogDebug("Registering widget");
+ SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+ {
+ DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
+ registerWidgetInternal(generateTizenId(), widgetRegInfo, wacSecurity, handle);
+ transaction.Commit();
+ }
+ SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register widget")
+}
- //Register into WidgetInfo has to be first
- //as all other tables depend upon that
- registerWidgetInfo(widgetHandle, widgetRegInfo, wacSecurity);
+DbWidgetHandle WidgetDAO::registerWidget(
+ const WidgetRegisterInfo &pWidgetRegisterInfo,
+ const IWacSecurity &wacSecurity)
+{
+ //make it more precise due to very fast tests
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ srand(time(NULL) + tv.tv_usec);
+ DbWidgetHandle widgetHandle;
+ do {
+ widgetHandle = rand();
+ } while (isWidgetInstalled(widgetHandle));
+
+ registerWidget(widgetHandle, pWidgetRegisterInfo, wacSecurity);
+ return widgetHandle;
+}
- registerWidgetExtendedInfo(widgetHandle, widgetRegInfo);
+WidgetPkgName WidgetDAO::registerWidgetGenerateTizenId(
+ const WidgetRegisterInfo &pWidgetRegisterInfo,
+ const IWacSecurity &wacSecurity)
+{
+ WidgetPkgName widgetPkgName = generateTizenId();
+ registerWidget(widgetPkgName, pWidgetRegisterInfo, wacSecurity);
+ return widgetPkgName;
+}
- registerWidgetLocalizedInfo(widgetHandle, widgetRegInfo);
+void WidgetDAO::registerWidgetInternal(
+ const WidgetPkgName & widgetName,
+ const WidgetRegisterInfo &widgetRegInfo,
+ const IWacSecurity &wacSecurity,
+ const DPL::Optional<DbWidgetHandle> handle)
+{
+ //Register into WidgetInfo has to be first
+ //as all other tables depend upon that
+ DbWidgetHandle widgetHandle = registerWidgetInfo(widgetName, widgetRegInfo, wacSecurity, handle);
+
+ registerWidgetExtendedInfo(widgetHandle, widgetRegInfo);
- registerWidgetIcons(widgetHandle, widgetRegInfo);
+ registerWidgetLocalizedInfo(widgetHandle, widgetRegInfo);
- registerWidgetStartFile(widgetHandle, widgetRegInfo);
+ registerWidgetIcons(widgetHandle, widgetRegInfo);
- PropertyDAO::RegisterProperties(widgetHandle, widgetRegInfo);
+ registerWidgetStartFile(widgetHandle, widgetRegInfo);
- registerWidgetFeatures(widgetHandle, widgetRegInfo);
+ PropertyDAO::RegisterProperties(widgetHandle, widgetRegInfo);
- registerWidgetWindowModes(widgetHandle, widgetRegInfo);
+ registerWidgetFeatures(widgetHandle, widgetRegInfo);
- registerWidgetWarpInfo(widgetHandle, widgetRegInfo);
+ registerWidgetWindowModes(widgetHandle, widgetRegInfo);
- registerWidgetCertificates(widgetHandle, wacSecurity);
+ registerWidgetWarpInfo(widgetHandle, widgetRegInfo);
- CertificateChainList list;
- wacSecurity.getCertificateChainList(list, SIGNATURE_DISTRIBUTOR);
- registerCertificatesChains(widgetHandle, SIGNATURE_DISTRIBUTOR, list);
+ registerWidgetCertificates(widgetHandle, wacSecurity);
- list.clear();
- wacSecurity.getCertificateChainList(list, SIGNATURE_AUTHOR);
- registerCertificatesChains(widgetHandle, SIGNATURE_AUTHOR, list);
+ CertificateChainList list;
+ wacSecurity.getCertificateChainList(list, SIGNATURE_DISTRIBUTOR);
+ registerCertificatesChains(widgetHandle, SIGNATURE_DISTRIBUTOR, list);
- registerWidgetSettings(widgetHandle, widgetRegInfo);
+ list.clear();
+ wacSecurity.getCertificateChainList(list, SIGNATURE_AUTHOR);
+ registerCertificatesChains(widgetHandle, SIGNATURE_AUTHOR, list);
- registerAppService(widgetHandle, widgetRegInfo);
+ registerWidgetSettings(widgetHandle, widgetRegInfo);
- registerEncryptedResouceInfo(widgetHandle, widgetRegInfo);
+ registerAppService(widgetHandle, widgetRegInfo);
+ registerEncryptedResouceInfo(widgetHandle, widgetRegInfo);
+
+ registerExternalLocations(widgetHandle, widgetRegInfo.externalLocations);
+
+ registerWidgetSecuritySettings(widgetHandle);
+}
+
+void WidgetDAO::registerOrUpdateWidget(
+ const WidgetPkgName & widgetName,
+ const WidgetRegisterInfo &widgetRegInfo,
+ const IWacSecurity &wacSecurity)
+{
+ LogDebug("Reregistering widget");
+ SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+ {
+ DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
+
+ unregisterWidgetInternal(widgetName);
+ registerWidgetInternal(widgetName, widgetRegInfo, wacSecurity);
transaction.Commit();
}
- SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register widget")
+ SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to reregister widget")
}
#define DO_INSERT(row, table) \
row.Set_install_time(regInfo.installedTime);
row.Set_splash_img_src(regInfo.configInfo.splashImgSrc);
row.Set_background_page(regInfo.configInfo.backgroundPage);
-
+ row.Set_installed_path(regInfo.widgetInstalledPath);
DO_INSERT(row, WidgetExtendedInfo)
}
-void WidgetDAO::registerWidgetInfo(
- const DbWidgetHandle& widgetHandle,
+DbWidgetHandle WidgetDAO::registerWidgetInfo(
+ const WidgetPkgName & widgetName,
const WidgetRegisterInfo ®Info,
- const IWacSecurity &wacSecurity)
+ const IWacSecurity &wacSecurity,
+ const DPL::Optional<DbWidgetHandle> handle)
{
using namespace DPL::DB::ORM;
using namespace DPL::DB::ORM::wrt;
// Because of that, "Optional" is not used there
WidgetInfo::Row row;
- row.Set_app_id(widgetHandle);
- row.Set_widget_type(regInfo.type.appType);
+ if(!!handle)
+ {
+ row.Set_app_id(*handle);
+ }
+
+ if (regInfo.webAppType == APP_TYPE_UNKNOWN && regInfo.type !=
+ APP_TYPE_UNKNOWN) {
+ // TODO : regInfo.type is temporary code for security.
+ // This code will be removed.
+ row.Set_widget_type(regInfo.type.appType);
+ } else {
+ row.Set_widget_type(regInfo.webAppType.appType);
+ }
row.Set_widget_id(widgetConfigurationInfo.widget_id);
row.Set_defaultlocale(widgetConfigurationInfo.defaultlocale);
row.Set_widget_version(widgetConfigurationInfo.version);
row.Set_recognized(wacSecurity.isRecognized());
row.Set_wac_signed(wacSecurity.isWacSigned());
row.Set_distributor_signed(wacSecurity.isDistributorSigned());
+ row.Set_pkgname(widgetName);
{
std::stringstream tmp;
tmp << regInfo.minVersion;
}
row.Set_back_supported(widgetConfigurationInfo.backSupported);
row.Set_access_network(widgetConfigurationInfo.accessNetwork);
- row.Set_pkgname(regInfo.pkgname);
- row.Set_pkg_type(regInfo.pType.pkgType);
+ row.Set_pkg_type(regInfo.packagingType.pkgType);
Try
{
ReThrowMsg(WidgetDAO::Exception::DatabaseError,
"Failed to register widget info.");
}
+
+ if(!handle)
+ {
+ //get autoincremented value of widgetHandle
+ WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
+ select->Where(Equals<WidgetInfo::pkgname>(widgetName));
+ return select->GetSingleValue<WidgetInfo::app_id>();
+ }
+ else
+ {
+ return *handle;
+ }
}
void WidgetDAO::registerWidgetLocalizedInfo(DbWidgetHandle widgetHandle,
wrt::FeatureParam::Row featureParam;
featureParam.Set_widget_feature_id(widgetFeatureID);
- ConfigParserData::ParamsList::const_iterator iter;
-
FOREACH(iter, pWidgetFeature->paramsList)
{
featureParam.Set_name(iter->name);
}
}
-void WidgetDAO::registerExternalLocations(const ExternalLocationList & externals)
+void WidgetDAO::registerExternalLocations(DbWidgetHandle widgetHandle,
+ const ExternalLocationList & externals)
{
SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
{
using namespace DPL::DB::ORM;
using namespace DPL::DB::ORM::wrt;
DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
- LogDebug("Inserting external files for widgetHandle: " << m_widgetHandle);
+ LogDebug("Inserting external files for widgetHandle: " << widgetHandle);
FOREACH(it, externals)
{
WidgetExternalLocations::Row row;
- row.Set_app_id(m_widgetHandle);
+ row.Set_app_id(widgetHandle);
row.Set_path(DPL::FromUTF8String(*it));
DO_INSERT(row, WidgetExternalLocations)
SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register external files");
}
+void WidgetDAO::registerWidgetSecuritySettings(DbWidgetHandle widgetHandle)
+{
+ SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+ {
+ using namespace DPL::DB::ORM;
+ using namespace DPL::DB::ORM::wrt;
+ DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
+
+ WidgetSecuritySettings::Row row;
+ row.Set_app_id(widgetHandle);
+ row.Set_security_popup_usage(SETTINGS_TYPE_ON);
+ row.Set_geolocation_usage(SETTINGS_TYPE_ON);
+ row.Set_web_notification_usage(SETTINGS_TYPE_ON);
+ row.Set_web_database_usage(SETTINGS_TYPE_ON);
+ row.Set_file_system_usage(SETTINGS_TYPE_ON);
+
+ DO_INSERT(row, WidgetSecuritySettings)
+ transaction.Commit();
+ }
+ SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register external files");
+}
+
void WidgetDAO::unregisterAllExternalLocations()
{
using namespace DPL::DB::ORM;
del->Execute();
}
-#undef DO_INSERT
-
-void WidgetDAO::unregisterWidget(DbWidgetHandle widgetHandle)
+void WidgetDAO::unregisterWidget(const WidgetPkgName & pkgName)
{
- LogDebug("Unregistering widget from DB. Handle: " << widgetHandle);
+ LogDebug("Unregistering widget from DB. PkgName: " << pkgName);
SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
{
DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
+ unregisterWidgetInternal(pkgName);
+ transaction.Commit();
+ }
+ SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to unregister widget")
+}
+
+void WidgetDAO::unregisterWidget(WrtDB::DbWidgetHandle handle)
+{
+ LogDebug("Unregistering widget from DB. Handle: " << handle);
+ SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+ {
using namespace DPL::DB::ORM;
using namespace DPL::DB::ORM::wrt;
-
- CHECK_WIDGET_EXISTENCE(transaction, widgetHandle)
+ ScopedTransaction transaction(&WrtDatabase::interface());
// Delete from table Widget Info
- {
- WRT_DB_DELETE(del, WidgetInfo, &WrtDatabase::interface())
- del->Where(Equals<WidgetInfo::app_id>(widgetHandle));
- del->Execute();
- }
-
- // Deleting in other tables is done via "delete cascade" in SQL
+ WRT_DB_DELETE(del, WidgetInfo, &WrtDatabase::interface())
+ del->Where(Equals<WidgetInfo::app_id>(handle));
+ del->Execute();
transaction.Commit();
}
SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to unregister widget")
}
+void WidgetDAO::unregisterWidgetInternal(
+ const WidgetPkgName & pkgName)
+{
+ using namespace DPL::DB::ORM;
+ using namespace DPL::DB::ORM::wrt;
+
+ DbWidgetHandle handle = getHandle(pkgName);
+
+ // Delete from table Widget Info
+ WRT_DB_DELETE(del, WidgetInfo, &WrtDatabase::interface())
+ del->Where(Equals<WidgetInfo::app_id>(handle));
+ del->Execute();
+
+ // Deleting in other tables is done via "delete cascade" in SQL
+}
+
+#undef DO_INSERT
+
#undef SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
#undef SQL_CONNECTION_EXCEPTION_HANDLER_END
-#undef CHECK_WIDGET_EXISTENCE
} // namespace WrtDB