From 71a055c81a959ea9e43ad7c673faee64e7d604bf Mon Sep 17 00:00:00 2001 From: Aleksandar Fabijanic Date: Tue, 21 Aug 2012 03:15:38 +0000 Subject: [PATCH] SF#3522081: WinRegistryConfiguration unable to read REG_QWORD values --- CHANGELOG | 1 + Util/include/Poco/Util/WinRegistryKey.h | 13 +++++++++++- Util/src/WinRegistryConfiguration.cpp | 3 +++ Util/src/WinRegistryKey.cpp | 23 ++++++++++++++++++++- Util/testsuite/src/WinConfigurationTest.cpp | 10 +++++++++ 5 files changed, 48 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 725fe5c2d..0107bd9e4 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -33,6 +33,7 @@ Release 1.5.0 (2012-08-??) - fixed SF#3534307: Building IPv6 for Linux by default - fixed SF#3516844: poco missing symbols with external >=lipcre-8.13 - added SF#3544720: AbstractConfigurator to support 64bit values +- fixed SF#3522081: WinRegistryConfiguration unable to read REG_QWORD values Release 1.4.4 (2012-08-??) ========================== diff --git a/Util/include/Poco/Util/WinRegistryKey.h b/Util/include/Poco/Util/WinRegistryKey.h index 6d5a974ae..8c68527dc 100644 --- a/Util/include/Poco/Util/WinRegistryKey.h +++ b/Util/include/Poco/Util/WinRegistryKey.h @@ -64,7 +64,8 @@ public: REGT_NONE = 0, REGT_STRING = 1, REGT_STRING_EXPAND = 2, - REGT_DWORD = 4 + REGT_DWORD = 4, + REGT_QWORD = 11 }; WinRegistryKey(const std::string& key, bool readOnly = false, REGSAM extraSam = 0); @@ -125,6 +126,16 @@ public: /// /// Throws a NotFoundException if the value does not exist. +#if defined(POCO_HAVE_INT64) + + Poco::Int64 getInt64(const std::string& name); + /// Returns the numeric value (REG_QWORD) with the given name. + /// An empty name denotes the default value. + /// + /// Throws a NotFoundException if the value does not exist. + +#endif // POCO_HAVE_INT64 + void deleteValue(const std::string& name); /// Deletes the value with the given name. /// diff --git a/Util/src/WinRegistryConfiguration.cpp b/Util/src/WinRegistryConfiguration.cpp index 6bf39981a..d3a33827e 100644 --- a/Util/src/WinRegistryConfiguration.cpp +++ b/Util/src/WinRegistryConfiguration.cpp @@ -85,6 +85,9 @@ bool WinRegistryConfiguration::getRaw(const std::string& key, std::string& value case WinRegistryKey::REGT_DWORD: value = Poco::NumberFormatter::format(aKey.getInt(keyName)); break; + case WinRegistryKey::REGT_QWORD: + value = Poco::NumberFormatter::format(aKey.getInt64(keyName)); + break; default: exists = false; } diff --git a/Util/src/WinRegistryKey.cpp b/Util/src/WinRegistryKey.cpp index 52825cac6..13dff109d 100644 --- a/Util/src/WinRegistryKey.cpp +++ b/Util/src/WinRegistryKey.cpp @@ -247,7 +247,7 @@ void WinRegistryKey::setInt(const std::string& name, int value) #endif } - + int WinRegistryKey::getInt(const std::string& name) { open(); @@ -266,6 +266,27 @@ int WinRegistryKey::getInt(const std::string& name) return data; } +#if defined(POCO_HAVE_INT64) + +Poco::Int64 WinRegistryKey::getInt64(const std::string& name) +{ + open(); + DWORD type; + Poco::Int64 data; + DWORD size = sizeof(data); +#if defined(POCO_WIN32_UTF8) + std::wstring uname; + Poco::UnicodeConverter::toUTF16(name, uname); + if (RegQueryValueExW(_hKey, uname.c_str(), NULL, &type, (BYTE*) &data, &size) != ERROR_SUCCESS || type != REG_DWORD) + throw NotFoundException(key(name)); +#else + if (RegQueryValueExA(_hKey, name.c_str(), NULL, &type, (BYTE*) &data, &size) != ERROR_SUCCESS || type != REG_DWORD) + throw NotFoundException(key(name)); +#endif + return data; +} + +#endif // POCO_HAVE_INT64 void WinRegistryKey::deleteValue(const std::string& name) { diff --git a/Util/testsuite/src/WinConfigurationTest.cpp b/Util/testsuite/src/WinConfigurationTest.cpp index 510bd977e..cc1c0c915 100644 --- a/Util/testsuite/src/WinConfigurationTest.cpp +++ b/Util/testsuite/src/WinConfigurationTest.cpp @@ -37,12 +37,18 @@ #include "Poco/Util/WinRegistryKey.h" #include "Poco/Environment.h" #include "Poco/AutoPtr.h" +#include "Poco/types.h" +#undef min +#undef max +#include using Poco::Util::WinRegistryConfiguration; using Poco::Util::WinRegistryKey; using Poco::Environment; using Poco::AutoPtr; +using Poco::Int64; +using Poco::UInt64; WinConfigurationTest::WinConfigurationTest(const std::string& name): CppUnit::TestCase(name) @@ -68,6 +74,10 @@ void WinConfigurationTest::testConfiguration() assert (pReg->getInt("name1") == 1); pReg->setString("name2", "value2"); assert (pReg->getString("name2") == "value2"); + pReg->setUInt64("name2", std::numeric_limits::max()); // overwrite should also change type + assert (pReg->getUInt64("name2") == std::numeric_limits::max()); + pReg->setInt64("name2", std::numeric_limits::min()); + assert (pReg->getInt64("name2") == std::numeric_limits::min()); assert (pReg->hasProperty("name1")); assert (pReg->hasProperty("name2"));