2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * This file contains the definition of widget dao class.
19 * @file widget_dao.cpp
20 * @author Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
21 * @author Bartosz Janiak (b.janiak@samsung.com)
22 * @author Yang Jie (jie2.yang@samsung.com)
23 * @author Koeun Choi(koeun.choi@samsung.com)
24 * @author Pawel Sikorski(p.sikorski@samsung.com)
26 * @brief This file contains the definition of Configuration.
29 #include <dpl/wrt-dao-rw/widget_dao.h>
32 #include <dpl/log/log.h>
33 #include <dpl/foreach.h>
34 #include <dpl/wrt-dao-ro/webruntime_database.h>
35 #include <dpl/wrt-dao-rw/property_dao.h>
36 #include <orm_generator_wrt.h>
37 #include <dpl/wrt-dao-ro/WrtDatabase.h>
41 //TODO in current solution in each getter there exists a check
42 //"IsWidgetInstalled". Maybe it should be verified, if it could be done
43 //differently (check in WidgetDAO constructor)
45 #define SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN Try
47 #define SQL_CONNECTION_EXCEPTION_HANDLER_END(message) \
48 Catch(DPL::DB::SqlConnection::Exception::Base) { \
50 ReThrowMsg(WidgetDAO::Exception::DatabaseError, \
54 WidgetDAO::WidgetDAO(DPL::OptionalString widgetGUID) :
55 WidgetDAOReadOnly(WidgetDAOReadOnly::getHandle(widgetGUID))
59 WidgetDAO::WidgetDAO(DPL::String pkgName) :
60 WidgetDAOReadOnly(WidgetDAOReadOnly::getHandle(pkgName))
64 WidgetDAO::WidgetDAO(DbWidgetHandle handle) :
65 WidgetDAOReadOnly(handle)
69 WidgetDAO::~WidgetDAO()
73 void WidgetDAO::removeProperty(
74 const PropertyDAOReadOnly::WidgetPropertyKey &key)
77 PropertyDAO::RemoveProperty(m_widgetHandle, key);
79 Catch(PropertyDAOReadOnly::Exception::ReadOnlyProperty){
80 ReThrowMsg(WidgetDAO::Exception::DatabaseError,
81 "Failure during removing property");
85 void WidgetDAO::setProperty(
86 const PropertyDAOReadOnly::WidgetPropertyKey &key,
87 const PropertyDAOReadOnly::WidgetPropertyValue &value,
91 PropertyDAO::SetProperty(m_widgetHandle, key, value, readOnly);
93 Catch(PropertyDAOReadOnly::Exception::ReadOnlyProperty){
94 ReThrowMsg(WidgetDAO::Exception::DatabaseError,
95 "Failure during setting/updating property");
99 void WidgetDAO::setPkgName(const DPL::OptionalString& pkgName)
103 setPkgName_TEMPORARY_API(*pkgName);
107 void WidgetDAO::setPkgName_TEMPORARY_API(const WidgetPkgName& pkgName)
109 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
111 using namespace DPL::DB::ORM;
112 wrt::ScopedTransaction transaction(&WrtDatabase::interface());
114 isWidgetInstalled(getHandle());
116 wrt::WidgetInfo::Row row;
117 row.Set_pkgname(pkgName);
119 WRT_DB_UPDATE(update, wrt::WidgetInfo, &WrtDatabase::interface())
121 Equals<wrt::WidgetInfo::app_id>(getHandle()));
125 transaction.Commit();
127 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register widget")
130 void WidgetDAO::setSecurityPopupUsage(const SettingsType value)
132 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
134 using namespace DPL::DB::ORM;
135 using namespace DPL::DB::ORM::wrt;
137 ScopedTransaction transaction(&WrtDatabase::interface());
138 if (!isWidgetInstalled(getHandle())) {
139 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
140 "Cannot find widget. Handle: " << getHandle());
143 WidgetSecuritySettings::Row row;
144 row.Set_security_popup_usage(value);
146 WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
147 update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
151 transaction.Commit();
153 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set security popup usage")
156 void WidgetDAO::setGeolocationUsage(const SettingsType value)
158 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
160 using namespace DPL::DB::ORM;
161 using namespace DPL::DB::ORM::wrt;
163 ScopedTransaction transaction(&WrtDatabase::interface());
164 if (!isWidgetInstalled(getHandle())) {
165 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
166 "Cannot find widget. Handle: " << getHandle());
169 WidgetSecuritySettings::Row row;
170 row.Set_geolocation_usage(value);
172 WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
173 update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
177 transaction.Commit();
179 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set geolocation usage")
182 void WidgetDAO::setWebNotificationUsage(const SettingsType value)
184 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
186 using namespace DPL::DB::ORM;
187 using namespace DPL::DB::ORM::wrt;
189 ScopedTransaction transaction(&WrtDatabase::interface());
190 if (!isWidgetInstalled(getHandle())) {
191 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
192 "Cannot find widget. Handle: " << getHandle());
195 WidgetSecuritySettings::Row row;
196 row.Set_web_notification_usage(value);
198 WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
199 update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
203 transaction.Commit();
205 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set web notification usage")
208 void WidgetDAO::setWebDatabaseUsage(const SettingsType value)
210 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
212 using namespace DPL::DB::ORM;
213 using namespace DPL::DB::ORM::wrt;
215 ScopedTransaction transaction(&WrtDatabase::interface());
216 if (!isWidgetInstalled(getHandle())) {
217 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
218 "Cannot find widget. Handle: " << getHandle());
221 WidgetSecuritySettings::Row row;
222 row.Set_web_database_usage(value);
224 WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
225 update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
229 transaction.Commit();
231 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set web database usage")
234 void WidgetDAO::setFileSystemUsage(const SettingsType value)
236 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
238 using namespace DPL::DB::ORM;
239 using namespace DPL::DB::ORM::wrt;
241 ScopedTransaction transaction(&WrtDatabase::interface());
242 if (!isWidgetInstalled(getHandle())) {
243 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
244 "Cannot find widget. Handle: " << getHandle());
247 WidgetSecuritySettings::Row row;
248 row.Set_file_system_usage(value);
250 WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
251 update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
255 transaction.Commit();
257 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set filesystem usage")
260 void WidgetDAO::registerWidget(
261 const WidgetPkgName & widgetPkgname,
262 const WidgetRegisterInfo &widgetRegInfo,
263 const IWacSecurity &wacSecurity)
265 LogDebug("Registering widget");
266 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
268 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
269 registerWidgetInternal(widgetPkgname, widgetRegInfo, wacSecurity);
270 transaction.Commit();
272 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register widget")
275 void WidgetDAO::registerWidget(
276 WrtDB::DbWidgetHandle handle,
277 const WidgetRegisterInfo &widgetRegInfo,
278 const IWacSecurity &wacSecurity)
280 LogDebug("Registering widget");
281 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
283 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
284 registerWidgetInternal(generateTizenId(), widgetRegInfo, wacSecurity, handle);
285 transaction.Commit();
287 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register widget")
290 DbWidgetHandle WidgetDAO::registerWidget(
291 const WidgetRegisterInfo &pWidgetRegisterInfo,
292 const IWacSecurity &wacSecurity)
294 //make it more precise due to very fast tests
296 gettimeofday(&tv, NULL);
297 srand(time(NULL) + tv.tv_usec);
298 DbWidgetHandle widgetHandle;
300 widgetHandle = rand();
301 } while (isWidgetInstalled(widgetHandle));
303 registerWidget(widgetHandle, pWidgetRegisterInfo, wacSecurity);
307 WidgetPkgName WidgetDAO::registerWidgetGenerateTizenId(
308 const WidgetRegisterInfo &pWidgetRegisterInfo,
309 const IWacSecurity &wacSecurity)
311 WidgetPkgName widgetPkgName = generateTizenId();
312 registerWidget(widgetPkgName, pWidgetRegisterInfo, wacSecurity);
313 return widgetPkgName;
316 void WidgetDAO::registerWidgetInternal(
317 const WidgetPkgName & widgetName,
318 const WidgetRegisterInfo &widgetRegInfo,
319 const IWacSecurity &wacSecurity,
320 const DPL::Optional<DbWidgetHandle> handle)
322 //Register into WidgetInfo has to be first
323 //as all other tables depend upon that
324 DbWidgetHandle widgetHandle = registerWidgetInfo(widgetName, widgetRegInfo, wacSecurity, handle);
326 registerWidgetExtendedInfo(widgetHandle, widgetRegInfo);
328 registerWidgetLocalizedInfo(widgetHandle, widgetRegInfo);
330 registerWidgetIcons(widgetHandle, widgetRegInfo);
332 registerWidgetStartFile(widgetHandle, widgetRegInfo);
334 PropertyDAO::RegisterProperties(widgetHandle, widgetRegInfo);
336 registerWidgetFeatures(widgetHandle, widgetRegInfo);
338 registerWidgetWindowModes(widgetHandle, widgetRegInfo);
340 registerWidgetWarpInfo(widgetHandle, widgetRegInfo);
342 registerWidgetCertificates(widgetHandle, wacSecurity);
344 CertificateChainList list;
345 wacSecurity.getCertificateChainList(list, SIGNATURE_DISTRIBUTOR);
346 registerCertificatesChains(widgetHandle, SIGNATURE_DISTRIBUTOR, list);
349 wacSecurity.getCertificateChainList(list, SIGNATURE_AUTHOR);
350 registerCertificatesChains(widgetHandle, SIGNATURE_AUTHOR, list);
352 registerWidgetSettings(widgetHandle, widgetRegInfo);
354 registerAppService(widgetHandle, widgetRegInfo);
356 registerEncryptedResouceInfo(widgetHandle, widgetRegInfo);
358 registerExternalLocations(widgetHandle, widgetRegInfo.externalLocations);
360 registerWidgetSecuritySettings(widgetHandle);
363 void WidgetDAO::registerOrUpdateWidget(
364 const WidgetPkgName & widgetName,
365 const WidgetRegisterInfo &widgetRegInfo,
366 const IWacSecurity &wacSecurity)
368 LogDebug("Reregistering widget");
369 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
371 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
373 unregisterWidgetInternal(widgetName);
374 registerWidgetInternal(widgetName, widgetRegInfo, wacSecurity);
375 transaction.Commit();
377 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to reregister widget")
380 #define DO_INSERT(row, table) \
382 WRT_DB_INSERT(insert, table, &WrtDatabase::interface()) \
383 insert->Values(row); \
387 void WidgetDAO::registerWidgetExtendedInfo(DbWidgetHandle widgetHandle,
388 const WidgetRegisterInfo ®Info)
390 //Try and transaction not needed
391 using namespace DPL::DB::ORM;
392 using namespace DPL::DB::ORM::wrt;
395 WidgetExtendedInfo::Row row;
396 row.Set_app_id(widgetHandle);
397 // row.Set_share_href (DPL::FromUTF8String(regInfo.shareHref));
398 row.Set_signature_type(regInfo.signatureType);
399 row.Set_test_widget(regInfo.isTestWidget);
400 row.Set_install_time(regInfo.installedTime);
401 row.Set_splash_img_src(regInfo.configInfo.splashImgSrc);
402 row.Set_background_page(regInfo.configInfo.backgroundPage);
403 row.Set_installed_path(regInfo.widgetInstalledPath);
405 DO_INSERT(row, WidgetExtendedInfo)
408 DbWidgetHandle WidgetDAO::registerWidgetInfo(
409 const WidgetPkgName & widgetName,
410 const WidgetRegisterInfo ®Info,
411 const IWacSecurity &wacSecurity,
412 const DPL::Optional<DbWidgetHandle> handle)
414 using namespace DPL::DB::ORM;
415 using namespace DPL::DB::ORM::wrt;
416 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
418 // TODO in wrt_db all Columns in WidgetInfo have DEFAULT VALUE set.
419 // Because of that, "Optional" is not used there
424 row.Set_app_id(*handle);
427 if (regInfo.webAppType == APP_TYPE_UNKNOWN && regInfo.type !=
429 // TODO : regInfo.type is temporary code for security.
430 // This code will be removed.
431 row.Set_widget_type(regInfo.type.appType);
433 row.Set_widget_type(regInfo.webAppType.appType);
435 row.Set_widget_id(widgetConfigurationInfo.widget_id);
436 row.Set_defaultlocale(widgetConfigurationInfo.defaultlocale);
437 row.Set_widget_version(widgetConfigurationInfo.version);
438 row.Set_widget_width(widgetConfigurationInfo.width);
439 row.Set_widget_height(widgetConfigurationInfo.height);
440 row.Set_author_name(widgetConfigurationInfo.authorName);
441 row.Set_author_email(widgetConfigurationInfo.authorEmail);
442 row.Set_author_href(widgetConfigurationInfo.authorHref);
443 row.Set_base_folder(DPL::FromUTF8String(regInfo.baseFolder));
444 row.Set_webkit_plugins_required(widgetConfigurationInfo.flashNeeded);
445 row.Set_recognized(wacSecurity.isRecognized());
446 row.Set_wac_signed(wacSecurity.isWacSigned());
447 row.Set_distributor_signed(wacSecurity.isDistributorSigned());
448 row.Set_pkgname(widgetName);
450 std::stringstream tmp;
451 tmp << regInfo.minVersion;
452 row.Set_min_version(DPL::FromUTF8String(tmp.str()));
454 row.Set_back_supported(widgetConfigurationInfo.backSupported);
455 row.Set_access_network(widgetConfigurationInfo.accessNetwork);
456 row.Set_pkg_type(regInfo.packagingType.pkgType);
460 DO_INSERT(row, WidgetInfo);
462 Catch(DPL::DB::SqlConnection::Exception::Base)
464 ReThrowMsg(WidgetDAO::Exception::DatabaseError,
465 "Failed to register widget info.");
470 //get autoincremented value of widgetHandle
471 WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
472 select->Where(Equals<WidgetInfo::pkgname>(widgetName));
473 return select->GetSingleValue<WidgetInfo::app_id>();
481 void WidgetDAO::registerWidgetLocalizedInfo(DbWidgetHandle widgetHandle,
482 const WidgetRegisterInfo ®Info)
484 using namespace DPL::DB::ORM;
485 using namespace DPL::DB::ORM::wrt;
487 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
489 FOREACH(it, widgetConfigurationInfo.localizedDataSet)
491 const DPL::String& locale = it->first;
492 const ConfigParserData::LocalizedData& data = it->second;
494 LocalizedWidgetInfo::Row row;
495 row.Set_app_id(widgetHandle);
496 row.Set_widget_locale(locale);
497 row.Set_widget_name(data.name);
498 row.Set_widget_shortname(data.shortName);
499 row.Set_widget_description(data.description);
500 row.Set_widget_license(data.license);
501 row.Set_widget_license_file(data.licenseFile);
502 row.Set_widget_license_href(data.licenseHref);
504 DO_INSERT(row, LocalizedWidgetInfo)
508 void WidgetDAO::registerWidgetIcons(DbWidgetHandle widgetHandle,
509 const WidgetRegisterInfo ®Info)
511 using namespace DPL::DB::ORM;
512 using namespace DPL::DB::ORM::wrt;
515 FOREACH(i, regInfo.localizationData.icons)
517 wrt::WidgetIcon::icon_id::ColumnType icon_id;
519 wrt::WidgetIcon::Row row;
520 row.Set_app_id(widgetHandle);
521 row.Set_icon_src(i->src);
522 row.Set_icon_width(i->width);
523 row.Set_icon_height(i->height);
525 WRT_DB_INSERT(insert, wrt::WidgetIcon, &WrtDatabase::interface())
527 icon_id = insert->Execute();
530 FOREACH(j, i->availableLocales)
532 WidgetLocalizedIcon::Row row;
533 row.Set_app_id(widgetHandle);
534 row.Set_icon_id(icon_id);
535 row.Set_widget_locale(*j);
536 WRT_DB_SELECT(select, WidgetLocalizedIcon, &WrtDatabase::interface())
537 select->Where(And(Equals<WidgetLocalizedIcon::app_id>(widgetHandle),
538 Equals<WidgetLocalizedIcon::widget_locale>(*j)));
539 WidgetLocalizedIcon::Select::RowList rows = select->GetRowList();
541 bool flag = !rows.empty();
545 // already default icon value of same locale exists
546 WRT_DB_UPDATE(update, WidgetLocalizedIcon, &WrtDatabase::interface())
547 update->Where(And(Equals<WidgetLocalizedIcon::app_id>(widgetHandle),
548 Equals<WidgetLocalizedIcon::widget_locale>(*j)));
552 // any icon value of same locale doesn't exist
553 DO_INSERT(row, WidgetLocalizedIcon)
559 void WidgetDAO::registerWidgetStartFile(DbWidgetHandle widgetHandle,
560 const WidgetRegisterInfo ®Info)
562 using namespace DPL::DB::ORM;
563 using namespace DPL::DB::ORM::wrt;
566 FOREACH(i, regInfo.localizationData.startFiles)
568 WidgetStartFile::start_file_id::ColumnType startFileID;
570 WidgetStartFile::Row row;
571 row.Set_app_id(widgetHandle);
572 row.Set_src(i->path);
574 WRT_DB_INSERT(insert, WidgetStartFile, &WrtDatabase::interface())
576 startFileID = insert->Execute();
579 FOREACH(j, i->propertiesForLocales)
581 WidgetLocalizedStartFile::Row row;
582 row.Set_app_id(widgetHandle);
583 row.Set_start_file_id(startFileID);
584 row.Set_widget_locale(j->first);
585 row.Set_type(j->second.type);
586 row.Set_encoding(j->second.encoding);
588 DO_INSERT(row, WidgetLocalizedStartFile)
593 void WidgetDAO::registerWidgetFeatures(DbWidgetHandle widgetHandle,
594 const WidgetRegisterInfo ®Info)
596 using namespace DPL::DB::ORM;
597 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
600 FOREACH(pWidgetFeature, widgetConfigurationInfo.featuresList)
602 wrt::WidgetFeature::Row widgetFeature;
603 widgetFeature.Set_app_id(widgetHandle);
604 widgetFeature.Set_name(pWidgetFeature->name);
605 widgetFeature.Set_required(pWidgetFeature->required);
606 widgetFeature.Set_rejected(false);
608 wrt::WidgetFeature::widget_feature_id::ColumnType widgetFeatureID;
610 WRT_DB_INSERT(insert, wrt::WidgetFeature, &WrtDatabase::interface())
611 insert->Values(widgetFeature);
612 widgetFeatureID = insert->Execute();
615 // Insert into table FeatureParam
616 wrt::FeatureParam::Row featureParam;
617 featureParam.Set_widget_feature_id(widgetFeatureID);
619 FOREACH(iter, pWidgetFeature->paramsList)
621 featureParam.Set_name(iter->name);
622 featureParam.Set_value(iter->value);
624 DO_INSERT(featureParam, wrt::FeatureParam)
629 void WidgetDAO::updateFeatureRejectStatus(const DbWidgetFeature &widgetFeature){
630 // This function could be merged with registerWidgetFeature but it requires desing change:
631 // 1. Check "ace step" in installer must be done before "update database step"
633 // ConfigurationParserData shouldn't be called "ParserData" any more.
634 using namespace DPL::DB::ORM;
636 wrt::ScopedTransaction transaction(&WrtDatabase::interface());
637 WRT_DB_SELECT(select, wrt::WidgetFeature, &WrtDatabase::interface())
638 select->Where(And(Equals<wrt::WidgetFeature::app_id>(m_widgetHandle),
639 Equals<wrt::WidgetFeature::name>(widgetFeature.name)));
641 auto row = select->GetSingleRow();
642 row.Set_rejected(widgetFeature.rejected);
644 WRT_DB_UPDATE(update, wrt::WidgetFeature, &WrtDatabase::interface())
645 update->Where(And(Equals<wrt::WidgetFeature::app_id>(m_widgetHandle),
646 Equals<wrt::WidgetFeature::name>(widgetFeature.name)));
649 transaction.Commit();
652 void WidgetDAO::registerWidgetWindowModes(DbWidgetHandle widgetHandle,
653 const WidgetRegisterInfo ®Info)
655 using namespace DPL::DB::ORM;
656 using namespace DPL::DB::ORM::wrt;
657 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
660 FOREACH(i, widgetConfigurationInfo.windowModes)
662 wrt::WidgetWindowModes::Row windowMode;
663 windowMode.Set_app_id(widgetHandle);
664 windowMode.Set_window_mode(*i);
666 DO_INSERT(windowMode, wrt::WidgetWindowModes)
670 void WidgetDAO::registerWidgetWarpInfo(DbWidgetHandle widgetHandle,
671 const WidgetRegisterInfo ®Info)
673 using namespace DPL::DB::ORM;
674 using namespace DPL::DB::ORM::wrt;
675 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
678 FOREACH(AccIt, widgetConfigurationInfo.accessInfoSet)
680 WidgetWARPInfo::Row row;
681 row.Set_app_id(widgetHandle);
682 row.Set_iri(AccIt->m_strIRI);
683 row.Set_subdomain_access(static_cast <int>(
684 AccIt->m_bSubDomainAccess));
686 DO_INSERT(row, WidgetWARPInfo)
690 void WidgetDAO::registerWidgetCertificates(DbWidgetHandle widgetHandle,
691 const IWacSecurity &wacSecurity)
693 using namespace DPL::DB::ORM;
694 using namespace DPL::DB::ORM::wrt;
697 FOREACH(it, wacSecurity.getCertificateList())
699 WidgetCertificateFingerprint::Row row;
700 row.Set_app_id(widgetHandle);
701 row.Set_owner(it->owner);
702 row.Set_chainid(it->chainId);
703 row.Set_type(it->type);
704 row.Set_md5_fingerprint(DPL::FromUTF8String(it->strMD5Fingerprint));
705 row.Set_sha1_fingerprint(DPL::FromUTF8String(it->strSHA1Fingerprint));
706 row.Set_common_name(it->strCommonName);
708 DO_INSERT(row, WidgetCertificateFingerprint)
712 void WidgetDAO::registerCertificatesChains(DbWidgetHandle widgetHandle,
713 CertificateSource certificateSource,
714 const CertificateChainList &certificateChainList)
716 using namespace DPL::DB::ORM;
717 using namespace DPL::DB::ORM::wrt;
718 FOREACH(certChain, certificateChainList)
720 WidgetCertificate::Row row;
721 row.Set_app_id(widgetHandle);
722 row.Set_cert_source(certificateSource);
723 row.Set_encoded_chain(DPL::FromASCIIString(*certChain));
725 DO_INSERT(row, WidgetCertificate);
729 void WidgetDAO::registerWidgetSettings(DbWidgetHandle widgetHandle,
730 const WidgetRegisterInfo ®Info)
732 using namespace DPL::DB::ORM;
733 using namespace DPL::DB::ORM::wrt;
735 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
737 FOREACH(pWidgetSetting, widgetConfigurationInfo.settingsList)
739 SettingsList::Row row;
740 row.Set_appId(widgetHandle);
741 row.Set_settingName(pWidgetSetting->m_name);
742 row.Set_settingValue(pWidgetSetting->m_value);
744 DO_INSERT(row, SettingsList)
748 void WidgetDAO::registerAppService(DbWidgetHandle widgetHandle,
749 const WidgetRegisterInfo ®Info)
751 using namespace DPL::DB::ORM;
752 using namespace DPL::DB::ORM::wrt;
753 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
755 FOREACH(ASIt, widgetConfigurationInfo.appServiceList)
757 ApplicationServiceInfo::Row row;
758 row.Set_app_id(widgetHandle);
759 row.Set_src(ASIt->m_src);
760 row.Set_operation(ASIt->m_operation);
761 row.Set_scheme(ASIt->m_scheme);
762 row.Set_mime(ASIt->m_mime);
764 DO_INSERT(row, ApplicationServiceInfo)
768 void WidgetDAO::registerEncryptedResouceInfo(DbWidgetHandle widgetHandle,
769 const WidgetRegisterInfo ®Info)
771 using namespace DPL::DB::ORM;
772 using namespace DPL::DB::ORM::wrt;
774 FOREACH(it, regInfo.encryptedFiles)
776 EncryptedResourceList::Row row;
777 row.Set_app_id(widgetHandle);
778 row.Set_resource(it->fileName);
779 row.Set_size(it->fileSize);
781 DO_INSERT(row, EncryptedResourceList)
785 void WidgetDAO::registerExternalLocations(DbWidgetHandle widgetHandle,
786 const ExternalLocationList & externals)
788 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
790 using namespace DPL::DB::ORM;
791 using namespace DPL::DB::ORM::wrt;
792 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
793 LogDebug("Inserting external files for widgetHandle: " << widgetHandle);
794 FOREACH(it, externals)
796 WidgetExternalLocations::Row row;
797 row.Set_app_id(widgetHandle);
798 row.Set_path(DPL::FromUTF8String(*it));
800 DO_INSERT(row, WidgetExternalLocations)
802 transaction.Commit();
804 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register external files");
807 void WidgetDAO::registerWidgetSecuritySettings(DbWidgetHandle widgetHandle)
809 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
811 using namespace DPL::DB::ORM;
812 using namespace DPL::DB::ORM::wrt;
813 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
815 WidgetSecuritySettings::Row row;
816 row.Set_app_id(widgetHandle);
817 row.Set_security_popup_usage(SETTINGS_TYPE_ON);
818 row.Set_geolocation_usage(SETTINGS_TYPE_ON);
819 row.Set_web_notification_usage(SETTINGS_TYPE_ON);
820 row.Set_web_database_usage(SETTINGS_TYPE_ON);
821 row.Set_file_system_usage(SETTINGS_TYPE_ON);
823 DO_INSERT(row, WidgetSecuritySettings)
824 transaction.Commit();
826 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register external files");
829 void WidgetDAO::unregisterAllExternalLocations()
831 using namespace DPL::DB::ORM;
832 using namespace DPL::DB::ORM::wrt;
833 LogDebug("Deleting external files for widgetHandle: " << m_widgetHandle);
834 WRT_DB_DELETE(del, WidgetExternalLocations, &WrtDatabase::interface());
835 del->Where(Equals<WidgetExternalLocations::app_id>(m_widgetHandle));
839 void WidgetDAO::unregisterWidget(const WidgetPkgName & pkgName)
841 LogDebug("Unregistering widget from DB. PkgName: " << pkgName);
842 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
844 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
845 unregisterWidgetInternal(pkgName);
846 transaction.Commit();
848 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to unregister widget")
851 void WidgetDAO::unregisterWidget(WrtDB::DbWidgetHandle handle)
853 LogDebug("Unregistering widget from DB. Handle: " << handle);
854 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
856 using namespace DPL::DB::ORM;
857 using namespace DPL::DB::ORM::wrt;
858 ScopedTransaction transaction(&WrtDatabase::interface());
860 // Delete from table Widget Info
861 WRT_DB_DELETE(del, WidgetInfo, &WrtDatabase::interface())
862 del->Where(Equals<WidgetInfo::app_id>(handle));
865 transaction.Commit();
867 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to unregister widget")
870 void WidgetDAO::unregisterWidgetInternal(
871 const WidgetPkgName & pkgName)
873 using namespace DPL::DB::ORM;
874 using namespace DPL::DB::ORM::wrt;
876 DbWidgetHandle handle = getHandle(pkgName);
878 // Delete from table Widget Info
879 WRT_DB_DELETE(del, WidgetInfo, &WrtDatabase::interface())
880 del->Where(Equals<WidgetInfo::app_id>(handle));
883 // Deleting in other tables is done via "delete cascade" in SQL
888 #undef SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
889 #undef SQL_CONNECTION_EXCEPTION_HANDLER_END