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>
40 //TODO in current solution in each getter there exists a check
41 //"IsWidgetInstalled". Maybe it should be verified, if it could be done
42 //differently (check in WidgetDAO constructor)
44 #define SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN Try
46 #define SQL_CONNECTION_EXCEPTION_HANDLER_END(message) \
47 Catch(DPL::DB::SqlConnection::Exception::Base) { \
49 ReThrowMsg(WidgetDAO::Exception::DatabaseError, \
53 WidgetDAO::WidgetDAO(DPL::OptionalString widgetGUID) :
54 WidgetDAOReadOnly(WidgetDAOReadOnly::getHandle(widgetGUID))
57 WidgetDAO::WidgetDAO(DPL::String tzAppId) :
58 WidgetDAOReadOnly(WidgetDAOReadOnly::getHandle(tzAppId))
61 WidgetDAO::WidgetDAO(DbWidgetHandle handle) :
62 WidgetDAOReadOnly(handle)
65 WidgetDAO::~WidgetDAO()
68 void WidgetDAO::setTizenAppId(const DPL::OptionalString& tzAppId)
70 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
72 using namespace DPL::DB::ORM;
73 wrt::ScopedTransaction transaction(&WrtDatabase::interface());
75 if (!isWidgetInstalled(getHandle())) {
76 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
77 "Cannot find widget. Handle: " << getHandle());
80 wrt::WidgetInfo::Row row;
81 row.Set_tizen_appid(*tzAppId);
83 WRT_DB_UPDATE(update, wrt::WidgetInfo, &WrtDatabase::interface())
85 Equals<wrt::WidgetInfo::app_id>(getHandle()));
91 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register widget")
94 void WidgetDAO::setSecurityPopupUsage(const SettingsType value)
96 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
98 using namespace DPL::DB::ORM;
99 using namespace DPL::DB::ORM::wrt;
101 ScopedTransaction transaction(&WrtDatabase::interface());
102 if (!isWidgetInstalled(getHandle())) {
103 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
104 "Cannot find widget. Handle: " << getHandle());
107 WidgetSecuritySettings::Row row;
108 row.Set_security_popup_usage(value);
110 WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
111 update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
115 transaction.Commit();
117 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set security popup usage")
120 void WidgetDAO::setGeolocationUsage(const SettingsType value)
122 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
124 using namespace DPL::DB::ORM;
125 using namespace DPL::DB::ORM::wrt;
127 ScopedTransaction transaction(&WrtDatabase::interface());
128 if (!isWidgetInstalled(getHandle())) {
129 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
130 "Cannot find widget. Handle: " << getHandle());
133 WidgetSecuritySettings::Row row;
134 row.Set_geolocation_usage(value);
136 WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
137 update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
141 transaction.Commit();
143 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set geolocation usage")
146 void WidgetDAO::setWebNotificationUsage(const SettingsType value)
148 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
150 using namespace DPL::DB::ORM;
151 using namespace DPL::DB::ORM::wrt;
153 ScopedTransaction transaction(&WrtDatabase::interface());
154 if (!isWidgetInstalled(getHandle())) {
155 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
156 "Cannot find widget. Handle: " << getHandle());
159 WidgetSecuritySettings::Row row;
160 row.Set_web_notification_usage(value);
162 WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
163 update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
167 transaction.Commit();
169 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set web notification usage")
172 void WidgetDAO::setWebDatabaseUsage(const SettingsType value)
174 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
176 using namespace DPL::DB::ORM;
177 using namespace DPL::DB::ORM::wrt;
179 ScopedTransaction transaction(&WrtDatabase::interface());
180 if (!isWidgetInstalled(getHandle())) {
181 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
182 "Cannot find widget. Handle: " << getHandle());
185 WidgetSecuritySettings::Row row;
186 row.Set_web_database_usage(value);
188 WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
189 update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
193 transaction.Commit();
195 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set web database usage")
198 void WidgetDAO::registerWidget(
199 const TizenAppId & tzAppId,
200 const WidgetRegisterInfo &widgetRegInfo,
201 const IWacSecurity &wacSecurity)
203 LogDebug("Registering widget");
204 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
206 DPL::DB::ORM::wrt::ScopedTransaction transaction(
207 &WrtDatabase::interface());
208 registerWidgetInternal(tzAppId, widgetRegInfo, wacSecurity);
209 transaction.Commit();
211 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register widget")
214 DbWidgetHandle WidgetDAO::registerWidget(
215 const WidgetRegisterInfo &pWidgetRegisterInfo,
216 const IWacSecurity &wacSecurity)
218 //make it more precise due to very fast tests
220 gettimeofday(&tv, NULL);
221 DbWidgetHandle widgetHandle;
222 unsigned int seed = time(NULL);
224 widgetHandle = rand_r(&seed);
225 } while (isWidgetInstalled(widgetHandle));
227 registerWidget(*pWidgetRegisterInfo.configInfo.tizenAppId,
233 TizenAppId WidgetDAO::registerWidgetGeneratePkgId(
234 const WidgetRegisterInfo &pWidgetRegisterInfo,
235 const IWacSecurity &wacSecurity)
237 TizenAppId tzAppId = generatePkgId();
238 registerWidget(tzAppId, pWidgetRegisterInfo, wacSecurity);
242 void WidgetDAO::registerWidgetInternal(
243 const TizenAppId & tzAppId,
244 const WidgetRegisterInfo &widgetRegInfo,
245 const IWacSecurity &wacSecurity,
246 const DPL::Optional<DbWidgetHandle> handle)
248 //Register into WidgetInfo has to be first
249 //as all other tables depend upon that
250 DbWidgetHandle widgetHandle = registerWidgetInfo(tzAppId,
255 registerWidgetExtendedInfo(widgetHandle, widgetRegInfo);
257 registerWidgetLocalizedInfo(widgetHandle, widgetRegInfo);
259 registerWidgetIcons(widgetHandle, widgetRegInfo);
261 registerWidgetStartFile(widgetHandle, widgetRegInfo);
263 PropertyDAO::RegisterProperties(tzAppId, widgetRegInfo);
265 registerWidgetFeatures(widgetHandle, widgetRegInfo);
267 registerWidgetPrivilege(widgetHandle, widgetRegInfo);
269 registerWidgetWindowModes(widgetHandle, widgetRegInfo);
271 registerWidgetWarpInfo(widgetHandle, widgetRegInfo);
273 registerWidgetAllowNavigationInfo(widgetHandle, widgetRegInfo);
275 registerWidgetCertificates(widgetHandle, wacSecurity);
277 CertificateChainList list;
278 wacSecurity.getCertificateChainList(list, SIGNATURE_DISTRIBUTOR);
279 registerCertificatesChains(widgetHandle, SIGNATURE_DISTRIBUTOR, list);
282 wacSecurity.getCertificateChainList(list, SIGNATURE_AUTHOR);
283 registerCertificatesChains(widgetHandle, SIGNATURE_AUTHOR, list);
285 registerWidgetSettings(widgetHandle, widgetRegInfo);
287 registerAppControl(widgetHandle, widgetRegInfo);
289 registerEncryptedResouceInfo(widgetHandle, widgetRegInfo);
291 registerExternalLocations(widgetHandle, widgetRegInfo.externalLocations);
293 registerWidgetSecuritySettings(widgetHandle);
296 void WidgetDAO::registerOrUpdateWidget(
297 const TizenAppId & widgetName,
298 const WidgetRegisterInfo &widgetRegInfo,
299 const IWacSecurity &wacSecurity)
301 LogDebug("Reregistering widget");
302 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
304 DPL::DB::ORM::wrt::ScopedTransaction transaction(
305 &WrtDatabase::interface());
307 unregisterWidgetInternal(widgetName);
308 registerWidgetInternal(widgetName, widgetRegInfo, wacSecurity);
309 transaction.Commit();
311 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to reregister widget")
314 void WidgetDAO::backupAndUpdateWidget(
315 const TizenAppId & oldAppId,
316 const TizenAppId & newAppId,
317 const WidgetRegisterInfo &widgetRegInfo,
318 const IWacSecurity &wacSecurity)
320 LogDebug("Backup and Register widget");
321 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
323 DPL::DB::ORM::wrt::ScopedTransaction transaction(
324 &WrtDatabase::interface());
326 updateWidgetAppIdInternal(newAppId, oldAppId);
327 registerWidgetInternal(newAppId, widgetRegInfo, wacSecurity);
328 transaction.Commit();
330 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to reregister widget")
333 void WidgetDAO::restoreUpdateWidget(
334 const TizenAppId & oldAppId,
335 const TizenAppId & newAppId)
337 LogDebug("restore widget");
338 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
340 DPL::DB::ORM::wrt::ScopedTransaction transaction(
341 &WrtDatabase::interface());
343 unregisterWidgetInternal(newAppId);
344 updateWidgetAppIdInternal(oldAppId, newAppId);
345 transaction.Commit();
347 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to reregister widget")
350 #define DO_INSERT(row, table) \
352 WRT_DB_INSERT(insert, table, &WrtDatabase::interface()) \
353 insert->Values(row); \
357 void WidgetDAO::registerWidgetExtendedInfo(DbWidgetHandle widgetHandle,
358 const WidgetRegisterInfo ®Info)
360 //Try and transaction not needed
361 using namespace DPL::DB::ORM;
362 using namespace DPL::DB::ORM::wrt;
364 WidgetExtendedInfo::Row row;
365 row.Set_app_id(widgetHandle);
366 // row.Set_share_href (DPL::FromUTF8String(regInfo.shareHref));
367 row.Set_signature_type(regInfo.signatureType);
368 row.Set_test_widget(regInfo.isTestWidget);
369 row.Set_install_time(regInfo.installedTime);
370 row.Set_splash_img_src(regInfo.configInfo.splashImgSrc);
371 row.Set_background_page(regInfo.configInfo.backgroundPage);
372 row.Set_installed_path(regInfo.widgetInstalledPath);
374 DO_INSERT(row, WidgetExtendedInfo)
377 DbWidgetHandle WidgetDAO::registerWidgetInfo(
378 const TizenAppId & tzAppId,
379 const WidgetRegisterInfo ®Info,
380 const IWacSecurity &wacSecurity,
381 const DPL::Optional<DbWidgetHandle> handle)
383 using namespace DPL::DB::ORM;
384 using namespace DPL::DB::ORM::wrt;
385 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
387 // TODO in wrt_db all Columns in WidgetInfo have DEFAULT VALUE set.
388 // Because of that, "Optional" is not used there
392 row.Set_app_id(*handle);
395 row.Set_widget_type(regInfo.webAppType.appType);
397 row.Set_widget_id(widgetConfigurationInfo.widget_id);
398 row.Set_defaultlocale(widgetConfigurationInfo.defaultlocale);
399 row.Set_widget_version(widgetConfigurationInfo.version);
400 row.Set_widget_width(widgetConfigurationInfo.width);
401 row.Set_widget_height(widgetConfigurationInfo.height);
402 row.Set_author_name(widgetConfigurationInfo.authorName);
403 row.Set_author_email(widgetConfigurationInfo.authorEmail);
404 row.Set_author_href(widgetConfigurationInfo.authorHref);
405 row.Set_csp_policy(widgetConfigurationInfo.cspPolicy);
406 row.Set_csp_policy_report_only(widgetConfigurationInfo.cspPolicyReportOnly);
407 row.Set_base_folder(DPL::FromUTF8String(regInfo.baseFolder));
408 row.Set_webkit_plugins_required(widgetConfigurationInfo.flashNeeded);
409 row.Set_recognized(wacSecurity.isRecognized());
410 row.Set_wac_signed(wacSecurity.isWacSigned());
411 row.Set_distributor_signed(wacSecurity.isDistributorSigned());
412 row.Set_tizen_appid(tzAppId);
413 row.Set_tizen_pkgid(regInfo.tzPkgid);
415 std::stringstream tmp;
416 tmp << regInfo.minVersion;
417 row.Set_min_version(DPL::FromUTF8String(tmp.str()));
419 row.Set_back_supported(widgetConfigurationInfo.backSupported);
420 row.Set_access_network(widgetConfigurationInfo.accessNetwork);
421 row.Set_pkg_type(regInfo.packagingType.pkgType);
422 row.Set_security_model_version(
423 static_cast<int>(widgetConfigurationInfo.securityModelVersion));
427 DO_INSERT(row, WidgetInfo);
429 Catch(DPL::DB::SqlConnection::Exception::Base)
431 ReThrowMsg(WidgetDAO::Exception::DatabaseError,
432 "Failed to register widget info.");
436 //get autoincremented value of widgetHandle
437 WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
438 select->Where(Equals<WidgetInfo::tizen_appid>(tzAppId));
439 return select->GetSingleValue<WidgetInfo::app_id>();
445 void WidgetDAO::registerWidgetLocalizedInfo(DbWidgetHandle widgetHandle,
446 const WidgetRegisterInfo ®Info)
448 using namespace DPL::DB::ORM;
449 using namespace DPL::DB::ORM::wrt;
451 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
453 FOREACH(it, widgetConfigurationInfo.localizedDataSet)
455 const DPL::String& locale = it->first;
456 const ConfigParserData::LocalizedData& data = it->second;
458 LocalizedWidgetInfo::Row row;
459 row.Set_app_id(widgetHandle);
460 row.Set_widget_locale(locale);
461 row.Set_widget_name(data.name);
462 row.Set_widget_shortname(data.shortName);
463 row.Set_widget_description(data.description);
464 row.Set_widget_license(data.license);
465 row.Set_widget_license_file(data.licenseFile);
466 row.Set_widget_license_href(data.licenseHref);
468 DO_INSERT(row, LocalizedWidgetInfo)
472 void WidgetDAO::registerWidgetIcons(DbWidgetHandle widgetHandle,
473 const WidgetRegisterInfo ®Info)
475 using namespace DPL::DB::ORM;
476 using namespace DPL::DB::ORM::wrt;
478 FOREACH(i, regInfo.localizationData.icons)
480 wrt::WidgetIcon::icon_id::ColumnType icon_id;
482 wrt::WidgetIcon::Row row;
483 row.Set_app_id(widgetHandle);
484 row.Set_icon_src(i->src);
485 row.Set_icon_width(i->width);
486 row.Set_icon_height(i->height);
488 WRT_DB_INSERT(insert, wrt::WidgetIcon, &WrtDatabase::interface())
490 icon_id = static_cast<int>(insert->Execute());
493 FOREACH(j, i->availableLocales)
495 WidgetLocalizedIcon::Row row;
496 row.Set_app_id(widgetHandle);
497 row.Set_icon_id(icon_id);
498 row.Set_widget_locale(*j);
499 DO_INSERT(row, WidgetLocalizedIcon)
504 void WidgetDAO::registerWidgetStartFile(DbWidgetHandle widgetHandle,
505 const WidgetRegisterInfo ®Info)
507 using namespace DPL::DB::ORM;
508 using namespace DPL::DB::ORM::wrt;
510 FOREACH(i, regInfo.localizationData.startFiles)
512 WidgetStartFile::start_file_id::ColumnType startFileID;
514 WidgetStartFile::Row row;
515 row.Set_app_id(widgetHandle);
516 row.Set_src(i->path);
518 WRT_DB_INSERT(insert, WidgetStartFile, &WrtDatabase::interface())
520 startFileID = static_cast<int>(insert->Execute());
523 FOREACH(j, i->propertiesForLocales)
525 WidgetLocalizedStartFile::Row row;
526 row.Set_app_id(widgetHandle);
527 row.Set_start_file_id(startFileID);
528 row.Set_widget_locale(j->first);
529 row.Set_type(j->second.type);
530 row.Set_encoding(j->second.encoding);
532 DO_INSERT(row, WidgetLocalizedStartFile)
537 void WidgetDAO::registerWidgetFeatures(DbWidgetHandle widgetHandle,
538 const WidgetRegisterInfo ®Info)
540 using namespace DPL::DB::ORM;
541 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
543 FOREACH(pWidgetFeature, widgetConfigurationInfo.featuresList)
545 wrt::WidgetFeature::Row widgetFeature;
546 widgetFeature.Set_app_id(widgetHandle);
547 widgetFeature.Set_name(pWidgetFeature->name);
548 widgetFeature.Set_rejected(false);
550 DO_INSERT(widgetFeature, wrt::WidgetFeature)
554 void WidgetDAO::registerWidgetPrivilege(DbWidgetHandle widgetHandle,
555 const WidgetRegisterInfo ®Info)
557 using namespace DPL::DB::ORM;
558 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
560 FOREACH(it, widgetConfigurationInfo.privilegeList)
562 wrt::WidgetPrivilege::Row widgetPrivilege;
563 widgetPrivilege.Set_app_id(widgetHandle);
564 widgetPrivilege.Set_name(it->name);
566 DO_INSERT(widgetPrivilege, wrt::WidgetPrivilege)
570 void WidgetDAO::updateFeatureRejectStatus(const DbWidgetFeature &widgetFeature)
572 // This function could be merged with registerWidgetFeature but it requires
574 // 1. Check "ace step" in installer must be done before "update database
577 // ConfigurationParserData shouldn't be called "ParserData" any more.
578 using namespace DPL::DB::ORM;
580 wrt::ScopedTransaction transaction(&WrtDatabase::interface());
581 WRT_DB_SELECT(select, wrt::WidgetFeature, &WrtDatabase::interface())
582 select->Where(And(Equals<wrt::WidgetFeature::app_id>(m_widgetHandle),
583 Equals<wrt::WidgetFeature::name>(widgetFeature.name)));
585 auto row = select->GetSingleRow();
586 row.Set_rejected(widgetFeature.rejected);
588 WRT_DB_UPDATE(update, wrt::WidgetFeature, &WrtDatabase::interface())
589 update->Where(And(Equals<wrt::WidgetFeature::app_id>(m_widgetHandle),
590 Equals<wrt::WidgetFeature::name>(widgetFeature.name)));
593 transaction.Commit();
596 void WidgetDAO::registerWidgetWindowModes(DbWidgetHandle widgetHandle,
597 const WidgetRegisterInfo ®Info)
599 using namespace DPL::DB::ORM;
600 using namespace DPL::DB::ORM::wrt;
601 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
603 FOREACH(i, widgetConfigurationInfo.windowModes)
605 wrt::WidgetWindowModes::Row windowMode;
606 windowMode.Set_app_id(widgetHandle);
607 windowMode.Set_window_mode(*i);
609 DO_INSERT(windowMode, wrt::WidgetWindowModes)
613 void WidgetDAO::registerWidgetWarpInfo(DbWidgetHandle widgetHandle,
614 const WidgetRegisterInfo ®Info)
616 using namespace DPL::DB::ORM;
617 using namespace DPL::DB::ORM::wrt;
618 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
620 FOREACH(AccIt, widgetConfigurationInfo.accessInfoSet)
622 WidgetWARPInfo::Row row;
623 row.Set_app_id(widgetHandle);
624 row.Set_iri(AccIt->m_strIRI);
625 row.Set_subdomain_access(static_cast <int>(
626 AccIt->m_bSubDomainAccess));
628 DO_INSERT(row, WidgetWARPInfo)
632 void WidgetDAO::registerWidgetAllowNavigationInfo(DbWidgetHandle widgetHandle,
633 const WidgetRegisterInfo ®Info)
635 using namespace DPL::DB::ORM;
636 using namespace DPL::DB::ORM::wrt;
637 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
639 FOREACH(allowNaviIt, widgetConfigurationInfo.allowNavigationInfoList)
641 WidgetAllowNavigation::Row row;
642 row.Set_app_id(widgetHandle);
643 row.Set_scheme(allowNaviIt->m_scheme);
644 row.Set_host(allowNaviIt->m_host);
645 DO_INSERT(row, WidgetAllowNavigation)
649 void WidgetDAO::registerWidgetCertificates(DbWidgetHandle widgetHandle,
650 const IWacSecurity &wacSecurity)
652 using namespace DPL::DB::ORM;
653 using namespace DPL::DB::ORM::wrt;
655 FOREACH(it, wacSecurity.getCertificateList())
657 WidgetCertificateFingerprint::Row row;
658 row.Set_app_id(widgetHandle);
659 row.Set_owner(it->owner);
660 row.Set_chainid(it->chainId);
661 row.Set_type(it->type);
662 row.Set_md5_fingerprint(DPL::FromUTF8String(it->strMD5Fingerprint));
663 row.Set_sha1_fingerprint(DPL::FromUTF8String(it->strSHA1Fingerprint));
664 row.Set_common_name(it->strCommonName);
666 DO_INSERT(row, WidgetCertificateFingerprint)
670 void WidgetDAO::registerCertificatesChains(
671 DbWidgetHandle widgetHandle,
672 CertificateSource certificateSource,
673 const CertificateChainList &
674 certificateChainList)
676 using namespace DPL::DB::ORM;
677 using namespace DPL::DB::ORM::wrt;
678 FOREACH(certChain, certificateChainList)
680 WidgetCertificate::Row row;
681 row.Set_app_id(widgetHandle);
682 row.Set_cert_source(certificateSource);
683 row.Set_encoded_chain(DPL::FromASCIIString(*certChain));
685 DO_INSERT(row, WidgetCertificate);
689 void WidgetDAO::registerWidgetSettings(DbWidgetHandle widgetHandle,
690 const WidgetRegisterInfo ®Info)
692 using namespace DPL::DB::ORM;
693 using namespace DPL::DB::ORM::wrt;
695 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
697 FOREACH(pWidgetSetting, widgetConfigurationInfo.settingsList)
699 SettingsList::Row row;
700 row.Set_appId(widgetHandle);
701 row.Set_settingName(pWidgetSetting->m_name);
702 row.Set_settingValue(pWidgetSetting->m_value);
704 DO_INSERT(row, SettingsList)
708 void WidgetDAO::insertAppControlInfo(DbWidgetHandle handle,
710 DPL::String operation,
714 unsigned disposition)
716 using namespace DPL::DB::ORM;
717 using namespace DPL::DB::ORM::wrt;
719 AppControlInfo::Row row;
721 row.Set_app_id(handle);
722 row.Set_execute_index(index);
724 row.Set_operation(operation);
727 row.Set_disposition(disposition);
729 DO_INSERT(row, AppControlInfo);
732 void WidgetDAO::registerAppControl(DbWidgetHandle widgetHandle,
733 const WidgetRegisterInfo ®Info)
735 using namespace DPL::DB::ORM;
736 using namespace DPL::DB::ORM::wrt;
737 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
740 FOREACH(appControl_it, widgetConfigurationInfo.appControlList)
742 DPL::String src = appControl_it->m_src;
743 DPL::String operation = appControl_it->m_operation;
744 unsigned index = appControl_it->m_index;
745 unsigned disposition = appControl_it->m_disposition ==
746 ConfigParserData::AppControlInfo::Disposition::INLINE ? 1 : 0;
748 if (!appControl_it->m_uriList.empty())
750 FOREACH(uri_it, appControl_it->m_uriList)
752 DPL::String uri = *uri_it;
754 if (!appControl_it->m_mimeList.empty())
756 FOREACH(mime_it, appControl_it->m_mimeList)
758 DPL::String mime = *mime_it;
760 insertAppControlInfo(widgetHandle, src, operation, uri, mime, index, disposition);
765 DPL::String mime = L"";
767 insertAppControlInfo(widgetHandle, src, operation, uri, mime, index, disposition);
773 DPL::String uri = L"";
775 if (!appControl_it->m_mimeList.empty())
777 FOREACH(mime_it, appControl_it->m_mimeList)
779 DPL::String mime = *mime_it;
781 insertAppControlInfo(widgetHandle, src, operation, uri, mime, index, disposition);
786 DPL::String mime = L"";
788 insertAppControlInfo(widgetHandle, src, operation, uri, mime, index, disposition);
794 void WidgetDAO::registerEncryptedResouceInfo(DbWidgetHandle widgetHandle,
795 const WidgetRegisterInfo ®Info)
797 using namespace DPL::DB::ORM;
798 using namespace DPL::DB::ORM::wrt;
800 FOREACH(it, regInfo.encryptedFiles)
802 EncryptedResourceList::Row row;
803 row.Set_app_id(widgetHandle);
804 row.Set_resource(it->fileName);
805 row.Set_size(it->fileSize);
807 DO_INSERT(row, EncryptedResourceList)
811 void WidgetDAO::registerExternalLocations(
812 DbWidgetHandle widgetHandle,
813 const ExternalLocationList &
816 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
818 using namespace DPL::DB::ORM;
819 using namespace DPL::DB::ORM::wrt;
820 DPL::DB::ORM::wrt::ScopedTransaction transaction(
821 &WrtDatabase::interface());
822 LogDebug("Inserting external files for widgetHandle: " << widgetHandle);
823 FOREACH(it, externals)
825 WidgetExternalLocations::Row row;
826 row.Set_app_id(widgetHandle);
827 row.Set_path(DPL::FromUTF8String(*it));
829 DO_INSERT(row, WidgetExternalLocations)
831 transaction.Commit();
833 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register external files");
836 void WidgetDAO::registerWidgetSecuritySettings(DbWidgetHandle widgetHandle)
838 using namespace DPL::DB::ORM;
839 using namespace DPL::DB::ORM::wrt;
840 WidgetSecuritySettings::Row row;
841 row.Set_app_id(widgetHandle);
842 row.Set_security_popup_usage(SETTINGS_TYPE_ON);
843 row.Set_geolocation_usage(SETTINGS_TYPE_ON);
844 row.Set_web_notification_usage(SETTINGS_TYPE_ON);
845 row.Set_web_database_usage(SETTINGS_TYPE_ON);
847 DO_INSERT(row, WidgetSecuritySettings)
850 void WidgetDAO::unregisterAllExternalLocations()
852 using namespace DPL::DB::ORM;
853 using namespace DPL::DB::ORM::wrt;
854 LogDebug("Deleting external files for widgetHandle: " << m_widgetHandle);
855 WRT_DB_DELETE(del, WidgetExternalLocations, &WrtDatabase::interface());
856 del->Where(Equals<WidgetExternalLocations::app_id>(m_widgetHandle));
860 void WidgetDAO::unregisterWidget(const TizenAppId & tzAppId)
862 LogDebug("Unregistering widget from DB. tzAppId: " << tzAppId);
863 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
865 DPL::DB::ORM::wrt::ScopedTransaction transaction(
866 &WrtDatabase::interface());
867 unregisterWidgetInternal(tzAppId);
868 transaction.Commit();
870 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to unregister widget")
873 void WidgetDAO::unregisterWidget(WrtDB::DbWidgetHandle handle)
875 LogDebug("Unregistering widget from DB. Handle: " << handle);
876 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
878 using namespace DPL::DB::ORM;
879 using namespace DPL::DB::ORM::wrt;
880 ScopedTransaction transaction(&WrtDatabase::interface());
882 // Delete from table Widget Info
883 WRT_DB_DELETE(del, WidgetInfo, &WrtDatabase::interface())
884 del->Where(Equals<WidgetInfo::app_id>(handle));
887 transaction.Commit();
889 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to unregister widget")
892 void WidgetDAO::unregisterWidgetInternal(
893 const TizenAppId & tzAppId)
895 using namespace DPL::DB::ORM;
896 using namespace DPL::DB::ORM::wrt;
898 DbWidgetHandle handle = getHandle(tzAppId);
900 // Delete from table Widget Info
901 WRT_DB_DELETE(del, WidgetInfo, &WrtDatabase::interface())
902 del->Where(Equals<WidgetInfo::app_id>(handle));
905 // Deleting in other tables is done via "delete cascade" in SQL
908 void WidgetDAO::updateWidgetAppIdInternal(
909 const TizenAppId & fromAppId,
910 const TizenAppId & toAppId)
912 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
914 using namespace DPL::DB::ORM;
915 using namespace DPL::DB::ORM::wrt;
917 ScopedTransaction transaction(&WrtDatabase::interface());
918 if (!isWidgetInstalled(fromAppId)) {
919 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
920 "Cannot find widget. tzAppId: " << fromAppId);
924 row.Set_tizen_appid(toAppId);
926 WRT_DB_UPDATE(update, WidgetInfo, &WrtDatabase::interface())
927 update->Where(Equals<WidgetInfo::tizen_appid>(fromAppId));
931 transaction.Commit();
933 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to update appid")
938 #undef SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
939 #undef SQL_CONNECTION_EXCEPTION_HANDLER_END