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 IWidgetSecurity &widgetSecurity)
203 LogDebug("Registering widget");
204 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
206 DPL::DB::ORM::wrt::ScopedTransaction transaction(
207 &WrtDatabase::interface());
208 registerWidgetInternal(tzAppId, widgetRegInfo, widgetSecurity);
209 transaction.Commit();
211 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register widget")
214 DbWidgetHandle WidgetDAO::registerWidget(
215 const WidgetRegisterInfo &pWidgetRegisterInfo,
216 const IWidgetSecurity &widgetSecurity)
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 IWidgetSecurity &widgetSecurity)
237 TizenAppId tzAppId = generatePkgId();
238 registerWidget(tzAppId, pWidgetRegisterInfo, widgetSecurity);
242 void WidgetDAO::registerWidgetInternal(
243 const TizenAppId & tzAppId,
244 const WidgetRegisterInfo &widgetRegInfo,
245 const IWidgetSecurity &widgetSecurity,
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(widgetHandle, 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, widgetSecurity);
277 CertificateChainList list;
278 widgetSecurity.getCertificateChainList(list, SIGNATURE_DISTRIBUTOR);
279 registerCertificatesChains(widgetHandle, SIGNATURE_DISTRIBUTOR, list);
282 widgetSecurity.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 IWidgetSecurity &widgetSecurity)
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, widgetSecurity);
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 IWidgetSecurity &widgetSecurity)
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, widgetSecurity);
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_install_time(regInfo.installedTime);
369 row.Set_splash_img_src(regInfo.configInfo.splashImgSrc);
370 row.Set_background_page(regInfo.configInfo.backgroundPage);
371 row.Set_installed_path(regInfo.widgetInstalledPath);
373 DO_INSERT(row, WidgetExtendedInfo)
376 DbWidgetHandle WidgetDAO::registerWidgetInfo(
377 const TizenAppId & tzAppId,
378 const WidgetRegisterInfo ®Info,
379 const IWidgetSecurity &widgetSecurity,
380 const DPL::Optional<DbWidgetHandle> handle)
382 using namespace DPL::DB::ORM;
383 using namespace DPL::DB::ORM::wrt;
384 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
386 // TODO in wrt_db all Columns in WidgetInfo have DEFAULT VALUE set.
387 // Because of that, "Optional" is not used there
391 row.Set_app_id(*handle);
394 row.Set_widget_type(regInfo.webAppType.appType);
396 row.Set_widget_id(widgetConfigurationInfo.widget_id);
397 row.Set_defaultlocale(widgetConfigurationInfo.defaultlocale);
398 row.Set_widget_version(widgetConfigurationInfo.version);
399 row.Set_widget_width(widgetConfigurationInfo.width);
400 row.Set_widget_height(widgetConfigurationInfo.height);
401 row.Set_author_name(widgetConfigurationInfo.authorName);
402 row.Set_author_email(widgetConfigurationInfo.authorEmail);
403 row.Set_author_href(widgetConfigurationInfo.authorHref);
404 row.Set_csp_policy(widgetConfigurationInfo.cspPolicy);
405 row.Set_csp_policy_report_only(widgetConfigurationInfo.cspPolicyReportOnly);
406 row.Set_base_folder(DPL::FromUTF8String(regInfo.baseFolder));
407 row.Set_webkit_plugins_required(widgetConfigurationInfo.flashNeeded);
408 row.Set_recognized(widgetSecurity.isRecognized());
409 row.Set_distributor_signed(widgetSecurity.isDistributorSigned());
410 row.Set_tizen_appid(tzAppId);
411 row.Set_tizen_pkgid(regInfo.tzPkgid);
413 std::stringstream tmp;
414 tmp << regInfo.minVersion;
415 row.Set_min_version(DPL::FromUTF8String(tmp.str()));
417 row.Set_back_supported(widgetConfigurationInfo.backSupported);
418 row.Set_access_network(widgetConfigurationInfo.accessNetwork);
419 row.Set_pkg_type(regInfo.packagingType.pkgType);
420 row.Set_security_model_version(
421 static_cast<int>(widgetConfigurationInfo.securityModelVersion));
425 DO_INSERT(row, WidgetInfo);
427 Catch(DPL::DB::SqlConnection::Exception::Base)
429 ReThrowMsg(WidgetDAO::Exception::DatabaseError,
430 "Failed to register widget info.");
434 //get autoincremented value of widgetHandle
435 WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
436 select->Where(Equals<WidgetInfo::tizen_appid>(tzAppId));
437 return select->GetSingleValue<WidgetInfo::app_id>();
443 void WidgetDAO::registerWidgetLocalizedInfo(DbWidgetHandle widgetHandle,
444 const WidgetRegisterInfo ®Info)
446 using namespace DPL::DB::ORM;
447 using namespace DPL::DB::ORM::wrt;
449 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
451 FOREACH(it, widgetConfigurationInfo.localizedDataSet)
453 const DPL::String& locale = it->first;
454 const ConfigParserData::LocalizedData& data = it->second;
456 LocalizedWidgetInfo::Row row;
457 row.Set_app_id(widgetHandle);
458 row.Set_widget_locale(locale);
459 row.Set_widget_name(data.name);
460 row.Set_widget_shortname(data.shortName);
461 row.Set_widget_description(data.description);
462 row.Set_widget_license(data.license);
463 row.Set_widget_license_file(data.licenseFile);
464 row.Set_widget_license_href(data.licenseHref);
466 DO_INSERT(row, LocalizedWidgetInfo)
470 void WidgetDAO::registerWidgetIcons(DbWidgetHandle widgetHandle,
471 const WidgetRegisterInfo ®Info)
473 using namespace DPL::DB::ORM;
474 using namespace DPL::DB::ORM::wrt;
476 FOREACH(i, regInfo.localizationData.icons)
478 wrt::WidgetIcon::icon_id::ColumnType icon_id;
480 wrt::WidgetIcon::Row row;
481 row.Set_app_id(widgetHandle);
482 row.Set_icon_src(i->src);
483 row.Set_icon_width(i->width);
484 row.Set_icon_height(i->height);
486 WRT_DB_INSERT(insert, wrt::WidgetIcon, &WrtDatabase::interface())
488 icon_id = static_cast<int>(insert->Execute());
491 FOREACH(j, i->availableLocales)
493 WidgetLocalizedIcon::Row row;
494 row.Set_app_id(widgetHandle);
495 row.Set_icon_id(icon_id);
496 row.Set_widget_locale(*j);
497 DO_INSERT(row, WidgetLocalizedIcon)
502 void WidgetDAO::registerWidgetStartFile(DbWidgetHandle widgetHandle,
503 const WidgetRegisterInfo ®Info)
505 using namespace DPL::DB::ORM;
506 using namespace DPL::DB::ORM::wrt;
508 FOREACH(i, regInfo.localizationData.startFiles)
510 WidgetStartFile::start_file_id::ColumnType startFileID;
512 WidgetStartFile::Row row;
513 row.Set_app_id(widgetHandle);
514 row.Set_src(i->path);
516 WRT_DB_INSERT(insert, WidgetStartFile, &WrtDatabase::interface())
518 startFileID = static_cast<int>(insert->Execute());
521 FOREACH(j, i->propertiesForLocales)
523 WidgetLocalizedStartFile::Row row;
524 row.Set_app_id(widgetHandle);
525 row.Set_start_file_id(startFileID);
526 row.Set_widget_locale(j->first);
527 row.Set_type(j->second.type);
528 row.Set_encoding(j->second.encoding);
530 DO_INSERT(row, WidgetLocalizedStartFile)
535 void WidgetDAO::registerWidgetFeatures(DbWidgetHandle widgetHandle,
536 const WidgetRegisterInfo ®Info)
538 using namespace DPL::DB::ORM;
539 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
541 FOREACH(pWidgetFeature, widgetConfigurationInfo.featuresList)
543 wrt::WidgetFeature::Row widgetFeature;
544 widgetFeature.Set_app_id(widgetHandle);
545 widgetFeature.Set_name(pWidgetFeature->name);
546 widgetFeature.Set_rejected(false);
548 DO_INSERT(widgetFeature, wrt::WidgetFeature)
552 void WidgetDAO::registerWidgetPrivilege(DbWidgetHandle widgetHandle,
553 const WidgetRegisterInfo ®Info)
555 using namespace DPL::DB::ORM;
556 using namespace DPL::DB::ORM::wrt;
557 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
559 FOREACH(it, widgetConfigurationInfo.privilegeList)
561 WidgetPrivilege::Row widgetPrivilege;
562 widgetPrivilege.Set_app_id(widgetHandle);
563 widgetPrivilege.Set_name(it->name);
565 DO_INSERT(widgetPrivilege, WidgetPrivilege)
569 void WidgetDAO::updateFeatureRejectStatus(const DbWidgetFeature &widgetFeature)
571 // This function could be merged with registerWidgetFeature but it requires
573 // 1. Check "ace step" in installer must be done before "update database
576 // ConfigurationParserData shouldn't be called "ParserData" any more.
577 using namespace DPL::DB::ORM;
579 wrt::ScopedTransaction transaction(&WrtDatabase::interface());
580 WRT_DB_SELECT(select, wrt::WidgetFeature, &WrtDatabase::interface())
581 select->Where(And(Equals<wrt::WidgetFeature::app_id>(m_widgetHandle),
582 Equals<wrt::WidgetFeature::name>(widgetFeature.name)));
584 auto row = select->GetSingleRow();
585 row.Set_rejected(widgetFeature.rejected);
587 WRT_DB_UPDATE(update, wrt::WidgetFeature, &WrtDatabase::interface())
588 update->Where(And(Equals<wrt::WidgetFeature::app_id>(m_widgetHandle),
589 Equals<wrt::WidgetFeature::name>(widgetFeature.name)));
592 transaction.Commit();
595 void WidgetDAO::registerWidgetWindowModes(DbWidgetHandle widgetHandle,
596 const WidgetRegisterInfo ®Info)
598 using namespace DPL::DB::ORM;
599 using namespace DPL::DB::ORM::wrt;
600 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
602 FOREACH(i, widgetConfigurationInfo.windowModes)
604 wrt::WidgetWindowModes::Row windowMode;
605 windowMode.Set_app_id(widgetHandle);
606 windowMode.Set_window_mode(*i);
608 DO_INSERT(windowMode, wrt::WidgetWindowModes)
612 void WidgetDAO::registerWidgetWarpInfo(DbWidgetHandle widgetHandle,
613 const WidgetRegisterInfo ®Info)
615 using namespace DPL::DB::ORM;
616 using namespace DPL::DB::ORM::wrt;
617 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
619 FOREACH(AccIt, widgetConfigurationInfo.accessInfoSet)
621 WidgetWARPInfo::Row row;
622 row.Set_app_id(widgetHandle);
623 row.Set_iri(AccIt->m_strIRI);
624 row.Set_subdomain_access(static_cast <int>(
625 AccIt->m_bSubDomainAccess));
627 DO_INSERT(row, WidgetWARPInfo)
631 void WidgetDAO::registerWidgetAllowNavigationInfo(DbWidgetHandle widgetHandle,
632 const WidgetRegisterInfo ®Info)
634 using namespace DPL::DB::ORM;
635 using namespace DPL::DB::ORM::wrt;
636 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
638 FOREACH(allowNaviIt, widgetConfigurationInfo.allowNavigationInfoList)
640 WidgetAllowNavigation::Row row;
641 row.Set_app_id(widgetHandle);
642 row.Set_scheme(allowNaviIt->m_scheme);
643 row.Set_host(allowNaviIt->m_host);
644 DO_INSERT(row, WidgetAllowNavigation)
648 void WidgetDAO::registerWidgetCertificates(DbWidgetHandle widgetHandle,
649 const IWidgetSecurity &widgetSecurity)
651 using namespace DPL::DB::ORM;
652 using namespace DPL::DB::ORM::wrt;
654 FOREACH(it, widgetSecurity.getCertificateList())
656 WidgetCertificateFingerprint::Row row;
657 row.Set_app_id(widgetHandle);
658 row.Set_owner(it->owner);
659 row.Set_chainid(it->chainId);
660 row.Set_type(it->type);
661 row.Set_md5_fingerprint(DPL::FromUTF8String(it->strMD5Fingerprint));
662 row.Set_sha1_fingerprint(DPL::FromUTF8String(it->strSHA1Fingerprint));
663 row.Set_common_name(it->strCommonName);
665 DO_INSERT(row, WidgetCertificateFingerprint)
669 void WidgetDAO::registerCertificatesChains(
670 DbWidgetHandle widgetHandle,
671 CertificateSource certificateSource,
672 const CertificateChainList &
673 certificateChainList)
675 using namespace DPL::DB::ORM;
676 using namespace DPL::DB::ORM::wrt;
677 FOREACH(certChain, certificateChainList)
679 WidgetCertificate::Row row;
680 row.Set_app_id(widgetHandle);
681 row.Set_cert_source(certificateSource);
682 row.Set_encoded_chain(DPL::FromASCIIString(*certChain));
684 DO_INSERT(row, WidgetCertificate);
688 void WidgetDAO::registerWidgetSettings(DbWidgetHandle widgetHandle,
689 const WidgetRegisterInfo ®Info)
691 using namespace DPL::DB::ORM;
692 using namespace DPL::DB::ORM::wrt;
694 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
696 FOREACH(pWidgetSetting, widgetConfigurationInfo.settingsList)
698 SettingsList::Row row;
699 row.Set_appId(widgetHandle);
700 row.Set_settingName(pWidgetSetting->m_name);
701 row.Set_settingValue(pWidgetSetting->m_value);
703 DO_INSERT(row, SettingsList)
707 void WidgetDAO::insertAppControlInfo(DbWidgetHandle handle,
709 DPL::String operation,
713 unsigned disposition)
715 using namespace DPL::DB::ORM;
716 using namespace DPL::DB::ORM::wrt;
718 AppControlInfo::Row row;
720 row.Set_app_id(handle);
721 row.Set_execute_index(index);
723 row.Set_operation(operation);
726 row.Set_disposition(disposition);
728 DO_INSERT(row, AppControlInfo);
731 void WidgetDAO::registerAppControl(DbWidgetHandle widgetHandle,
732 const WidgetRegisterInfo ®Info)
734 using namespace DPL::DB::ORM;
735 using namespace DPL::DB::ORM::wrt;
736 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
739 FOREACH(appControl_it, widgetConfigurationInfo.appControlList)
741 DPL::String src = appControl_it->m_src;
742 DPL::String operation = appControl_it->m_operation;
743 unsigned index = appControl_it->m_index;
744 unsigned disposition = appControl_it->m_disposition ==
745 ConfigParserData::AppControlInfo::Disposition::INLINE ? 1 : 0;
747 if (!appControl_it->m_uriList.empty())
749 FOREACH(uri_it, appControl_it->m_uriList)
751 DPL::String uri = *uri_it;
753 if (!appControl_it->m_mimeList.empty())
755 FOREACH(mime_it, appControl_it->m_mimeList)
757 DPL::String mime = *mime_it;
759 insertAppControlInfo(widgetHandle, src, operation, uri, mime, index, disposition);
764 DPL::String mime = L"";
766 insertAppControlInfo(widgetHandle, src, operation, uri, mime, index, disposition);
772 DPL::String uri = L"";
774 if (!appControl_it->m_mimeList.empty())
776 FOREACH(mime_it, appControl_it->m_mimeList)
778 DPL::String mime = *mime_it;
780 insertAppControlInfo(widgetHandle, src, operation, uri, mime, index, disposition);
785 DPL::String mime = L"";
787 insertAppControlInfo(widgetHandle, src, operation, uri, mime, index, disposition);
793 void WidgetDAO::registerEncryptedResouceInfo(DbWidgetHandle widgetHandle,
794 const WidgetRegisterInfo ®Info)
796 using namespace DPL::DB::ORM;
797 using namespace DPL::DB::ORM::wrt;
799 FOREACH(it, regInfo.encryptedFiles)
801 EncryptedResourceList::Row row;
802 row.Set_app_id(widgetHandle);
803 row.Set_resource(it->fileName);
804 row.Set_size(it->fileSize);
806 DO_INSERT(row, EncryptedResourceList)
810 void WidgetDAO::registerExternalLocations(
811 DbWidgetHandle widgetHandle,
812 const ExternalLocationList &
815 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
817 using namespace DPL::DB::ORM;
818 using namespace DPL::DB::ORM::wrt;
819 DPL::DB::ORM::wrt::ScopedTransaction transaction(
820 &WrtDatabase::interface());
821 LogDebug("Inserting external files for widgetHandle: " << widgetHandle);
822 FOREACH(it, externals)
824 WidgetExternalLocations::Row row;
825 row.Set_app_id(widgetHandle);
826 row.Set_path(DPL::FromUTF8String(*it));
828 DO_INSERT(row, WidgetExternalLocations)
830 transaction.Commit();
832 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register external files");
835 void WidgetDAO::registerWidgetSecuritySettings(DbWidgetHandle widgetHandle)
837 using namespace DPL::DB::ORM;
838 using namespace DPL::DB::ORM::wrt;
839 WidgetSecuritySettings::Row row;
840 row.Set_app_id(widgetHandle);
841 row.Set_security_popup_usage(SETTINGS_TYPE_ON);
842 row.Set_geolocation_usage(SETTINGS_TYPE_ON);
843 row.Set_web_notification_usage(SETTINGS_TYPE_ON);
844 row.Set_web_database_usage(SETTINGS_TYPE_ON);
846 DO_INSERT(row, WidgetSecuritySettings)
849 void WidgetDAO::unregisterAllExternalLocations()
851 using namespace DPL::DB::ORM;
852 using namespace DPL::DB::ORM::wrt;
853 LogDebug("Deleting external files for widgetHandle: " << m_widgetHandle);
854 WRT_DB_DELETE(del, WidgetExternalLocations, &WrtDatabase::interface());
855 del->Where(Equals<WidgetExternalLocations::app_id>(m_widgetHandle));
859 void WidgetDAO::unregisterWidget(const TizenAppId & tzAppId)
861 LogDebug("Unregistering widget from DB. tzAppId: " << tzAppId);
862 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
864 DPL::DB::ORM::wrt::ScopedTransaction transaction(
865 &WrtDatabase::interface());
866 unregisterWidgetInternal(tzAppId);
867 transaction.Commit();
869 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to unregister widget")
872 void WidgetDAO::unregisterWidget(WrtDB::DbWidgetHandle handle)
874 LogDebug("Unregistering widget from DB. Handle: " << handle);
875 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
877 using namespace DPL::DB::ORM;
878 using namespace DPL::DB::ORM::wrt;
879 ScopedTransaction transaction(&WrtDatabase::interface());
881 // Delete from table Widget Info
882 WRT_DB_DELETE(del, WidgetInfo, &WrtDatabase::interface())
883 del->Where(Equals<WidgetInfo::app_id>(handle));
886 transaction.Commit();
888 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to unregister widget")
891 void WidgetDAO::unregisterWidgetInternal(
892 const TizenAppId & tzAppId)
894 using namespace DPL::DB::ORM;
895 using namespace DPL::DB::ORM::wrt;
897 DbWidgetHandle handle = getHandle(tzAppId);
899 // Delete from table Widget Info
900 WRT_DB_DELETE(del, WidgetInfo, &WrtDatabase::interface())
901 del->Where(Equals<WidgetInfo::app_id>(handle));
904 // Deleting in other tables is done via "delete cascade" in SQL
907 void WidgetDAO::updateWidgetAppIdInternal(
908 const TizenAppId & fromAppId,
909 const TizenAppId & toAppId)
911 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
913 using namespace DPL::DB::ORM;
914 using namespace DPL::DB::ORM::wrt;
916 ScopedTransaction transaction(&WrtDatabase::interface());
917 if (!isWidgetInstalled(fromAppId)) {
918 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
919 "Cannot find widget. tzAppId: " << fromAppId);
922 WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
923 select->Where(Equals<WidgetInfo::tizen_appid>(fromAppId));
925 WidgetInfo::Row row = select->GetSingleRow();
927 //WidgetInfo::Row row;
928 row.Set_tizen_appid(toAppId);
930 WRT_DB_UPDATE(update, WidgetInfo, &WrtDatabase::interface())
931 update->Where(Equals<WidgetInfo::tizen_appid>(fromAppId));
935 transaction.Commit();
937 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to update appid")
942 #undef SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
943 #undef SQL_CONNECTION_EXCEPTION_HANDLER_END