diff --git a/Foundation/Foundation_vs100.vcxproj b/Foundation/Foundation_vs100.vcxproj index 5be73d8d2..bb79f5be5 100644 --- a/Foundation/Foundation_vs100.vcxproj +++ b/Foundation/Foundation_vs100.vcxproj @@ -1,1323 +1,1325 @@ - - - - - debug_shared - Win32 - - - debug_static_md - Win32 - - - debug_static_mt - Win32 - - - release_shared - Win32 - - - release_static_md - Win32 - - - release_static_mt - Win32 - - - - Foundation - {8164D41D-B053-405B-826C-CF37AC0EF176} - Foundation - Win32Proj - - - - StaticLibrary - MultiByte - - - StaticLibrary - MultiByte - - - StaticLibrary - MultiByte - - - StaticLibrary - MultiByte - - - DynamicLibrary - MultiByte - - - DynamicLibrary - MultiByte - - - - - - - - - - - - - - - - - - - - - - - - - - - <_ProjectFileVersion>10.0.30319.1 - ..\bin\ - obj\$(Configuration)\ - true - ..\bin\ - obj\$(Configuration)\ - false - ..\lib\ - obj\$(Configuration)\ - ..\lib\ - obj\$(Configuration)\ - ..\lib\ - obj\$(Configuration)\ - ..\lib\ - obj\$(Configuration)\ - PocoFoundationd - PocoFoundationmdd - PocoFoundationmtd - PocoFoundation - PocoFoundationmd - PocoFoundationmt - - - - Disabled - .\include;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_WINDOWS;_USRDLL;Foundation_EXPORTS;PCRE_STATIC;%(PreprocessorDefinitions) - true - true - EnableFastChecks - MultiThreadedDebugDLL - true - true - true - true - - - Level3 - EditAndContinue - Default - - - iphlpapi.lib;%(AdditionalDependencies) - ..\bin\PocoFoundationd.dll - true - true - ..\bin\PocoFoundationd.pdb - Console - ..\lib\PocoFoundationd.lib - MachineX86 - - - - - Disabled - OnlyExplicitInline - true - Speed - true - .\include;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;_WINDOWS;_USRDLL;Foundation_EXPORTS;PCRE_STATIC;%(PreprocessorDefinitions) - false - false - false - true - MultiThreadedDLL - false - true - true - true - - - Level3 - - - Default - - - iphlpapi.lib;%(AdditionalDependencies) - ..\bin\PocoFoundation.dll - true - false - - - Console - true - true - ..\lib\PocoFoundation.lib - MachineX86 - - - - - Disabled - OnlyExplicitInline - true - Speed - true - .\include;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;_WINDOWS;Foundation_EXPORTS;POCO_STATIC;PCRE_STATIC;%(PreprocessorDefinitions) - false - false - false - true - MultiThreadedDLL - false - true - true - true - - - Level3 - - - Default - - - ws2_32.lib;iphlpapi.lib;%(AdditionalDependencies) - ..\lib\PocoFoundationmd.lib - /ignore:4221 %(AdditionalOptions) - - - - - Disabled - .\include;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_WINDOWS;Foundation_EXPORTS;POCO_STATIC;PCRE_STATIC;%(PreprocessorDefinitions) - true - true - EnableFastChecks - MultiThreadedDebugDLL - true - true - true - true - - - Level3 - EditAndContinue - Default - ..\lib\PocoFoundationmdd.pdb - - - ws2_32.lib;iphlpapi.lib;%(AdditionalDependencies) - ..\lib\PocoFoundationmdd.lib - /ignore:4221 %(AdditionalOptions) - - - - - Disabled - .\include;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_WINDOWS;Foundation_EXPORTS;POCO_STATIC;PCRE_STATIC;%(PreprocessorDefinitions) - true - true - EnableFastChecks - MultiThreadedDebug - true - true - true - true - - - Level3 - EditAndContinue - Default - ..\lib\PocoFoundationmtd.pdb - - - ws2_32.lib;iphlpapi.lib;%(AdditionalDependencies) - ..\lib\PocoFoundationmtd.lib - /ignore:4221 %(AdditionalOptions) - - - - - Disabled - OnlyExplicitInline - true - Speed - true - .\include;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;_WINDOWS;Foundation_EXPORTS;POCO_STATIC;PCRE_STATIC;%(PreprocessorDefinitions) - false - false - false - true - MultiThreaded - false - true - true - true - - - Level3 - - - Default - /ignore:4221 %(AdditionalOptions) - - - ws2_32.lib;iphlpapi.lib;%(AdditionalDependencies) - ..\lib\PocoFoundationmt.lib - - - - - - - - - - - - - true - true - true - true - true - true - - - true - true - true - true - true - true - - - true - true - true - true - true - true - - - true - true - true - true - true - true - - - - - - - true - true - true - true - true - true - - - true - true - true - true - true - true - - - true - true - true - true - true - true - - - true - true - true - true - true - true - - - true - true - true - true - true - true - - - - - - - - - - - - - - - - - - - - - - true - true - true - true - true - true - - - true - true - true - true - true - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - true - true - true - true - true - true - - - true - true - true - true - true - true - - - - true - true - true - true - true - true - - - true - true - true - true - true - true - - - - - true - true - true - true - true - true - - - true - true - true - true - true - true - - - - true - true - true - true - true - true - - - true - true - true - true - true - true - - - - - - true - true - true - true - true - true - - - true - true - true - true - true - true - - - - - - - - - - - - - - - - true - true - true - true - true - true - - - true - true - true - true - true - true - - - true - true - true - true - true - true - - - true - true - true - true - true - true - - - true - true - true - true - true - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - true - true - true - true - true - true - - - true - true - true - true - true - true - - - true - true - true - true - true - true - - - true - true - true - true - true - true - - - - - - - - - true - true - true - true - true - true - - - - - - - - - true - true - true - true - true - true - - - - - - - - - - - true - true - true - true - true - true - - - true - true - true - true - true - true - - - true - true - true - true - true - true - - - true - true - true - true - true - true - - - - true - true - true - true - true - true - - - true - true - true - true - true - true - - - true - true - true - true - true - true - - - true - true - true - true - true - true - - - - - true - true - true - true - true - true - - - true - true - true - true - true - true - - - true - true - true - true - true - true - - - true - true - true - true - true - true - - - - - true - true - true - true - true - true - - - true - true - true - true - true - true - - - true - true - true - true - true - true - - - true - true - true - true - true - true - - - - true - true - true - true - true - true - - - true - true - true - true - true - true - - - true - true - true - true - true - true - - - true - true - true - true - true - true - - - - - true - true - true - true - true - true - - - true - true - true - true - true - true - - - true - true - true - true - true - true - - - - - true - true - true - true - true - true - - - true - true - true - true - true - true - - - true - true - true - true - true - true - - - true - true - true - true - true - true - - - - true - true - true - true - true - true - - - true - true - true - true - true - true - - - true - true - true - true - true - true - - - - - - - - - - - - - - true - true - true - true - true - true - - - true - true - true - true - true - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Document - mc -h "%(RootDir)%(Directory)." -r "%(RootDir)%(Directory)." "%(FullPath) - %(RootDir)%(Directory)\pocomsg.rc;%(RootDir)%(Directory)\pocomsg.h;%(Outputs) + + + + + debug_shared + Win32 + + + debug_static_md + Win32 + + + debug_static_mt + Win32 + + + release_shared + Win32 + + + release_static_md + Win32 + + + release_static_mt + Win32 + + + + Foundation + {8164D41D-B053-405B-826C-CF37AC0EF176} + Foundation + Win32Proj + + + + StaticLibrary + MultiByte + + + StaticLibrary + MultiByte + + + StaticLibrary + MultiByte + + + StaticLibrary + MultiByte + + + DynamicLibrary + MultiByte + + + DynamicLibrary + MultiByte + + + + + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30319.1 + ..\bin\ + obj\$(Configuration)\ + true + ..\bin\ + obj\$(Configuration)\ + false + ..\lib\ + obj\$(Configuration)\ + ..\lib\ + obj\$(Configuration)\ + ..\lib\ + obj\$(Configuration)\ + ..\lib\ + obj\$(Configuration)\ + PocoFoundationd + PocoFoundationmdd + PocoFoundationmtd + PocoFoundation + PocoFoundationmd + PocoFoundationmt + + + + Disabled + .\include;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_WINDOWS;_USRDLL;Foundation_EXPORTS;PCRE_STATIC;%(PreprocessorDefinitions) + true + true + EnableFastChecks + MultiThreadedDebugDLL + true + true + true + true + + + Level3 + EditAndContinue + Default + + + iphlpapi.lib;%(AdditionalDependencies) + ..\bin\PocoFoundationd.dll + true + true + ..\bin\PocoFoundationd.pdb + Console + ..\lib\PocoFoundationd.lib + MachineX86 + + + + + Disabled + OnlyExplicitInline + true + Speed + true + .\include;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;_WINDOWS;_USRDLL;Foundation_EXPORTS;PCRE_STATIC;%(PreprocessorDefinitions) + false + false + false + true + MultiThreadedDLL + false + true + true + true + + + Level3 + + + Default + + + iphlpapi.lib;%(AdditionalDependencies) + ..\bin\PocoFoundation.dll + true + false + + + Console + true + true + ..\lib\PocoFoundation.lib + MachineX86 + + + + + Disabled + OnlyExplicitInline + true + Speed + true + .\include;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;_WINDOWS;Foundation_EXPORTS;POCO_STATIC;PCRE_STATIC;%(PreprocessorDefinitions) + false + false + false + true + MultiThreadedDLL + false + true + true + true + + + Level3 + + + Default + + + ws2_32.lib;iphlpapi.lib;%(AdditionalDependencies) + ..\lib\PocoFoundationmd.lib + /ignore:4221 %(AdditionalOptions) + + + + + Disabled + .\include;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_WINDOWS;Foundation_EXPORTS;POCO_STATIC;PCRE_STATIC;%(PreprocessorDefinitions) + true + true + EnableFastChecks + MultiThreadedDebugDLL + true + true + true + true + + + Level3 + EditAndContinue + Default + ..\lib\PocoFoundationmdd.pdb + + + ws2_32.lib;iphlpapi.lib;%(AdditionalDependencies) + ..\lib\PocoFoundationmdd.lib + /ignore:4221 %(AdditionalOptions) + + + + + Disabled + .\include;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_WINDOWS;Foundation_EXPORTS;POCO_STATIC;PCRE_STATIC;%(PreprocessorDefinitions) + true + true + EnableFastChecks + MultiThreadedDebug + true + true + true + true + + + Level3 + EditAndContinue + Default + ..\lib\PocoFoundationmtd.pdb + + + ws2_32.lib;iphlpapi.lib;%(AdditionalDependencies) + ..\lib\PocoFoundationmtd.lib + /ignore:4221 %(AdditionalOptions) + + + + + Disabled + OnlyExplicitInline + true + Speed + true + .\include;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;_WINDOWS;Foundation_EXPORTS;POCO_STATIC;PCRE_STATIC;%(PreprocessorDefinitions) + false + false + false + true + MultiThreaded + false + true + true + true + + + Level3 + + + Default + /ignore:4221 %(AdditionalOptions) + + + ws2_32.lib;iphlpapi.lib;%(AdditionalDependencies) + ..\lib\PocoFoundationmt.lib + + + + + + + + + + + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + + + + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + + + + + + + + + + + + + + + + + + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + + + + + + + + + + + + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + + + + + + + true + true + true + true + true + true + + + + + + + + + true + true + true + true + true + true + + + + + + + + + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + + + + + + + + + + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Document + mc -h "%(RootDir)%(Directory)." -r "%(RootDir)%(Directory)." "%(FullPath) + %(RootDir)%(Directory)\pocomsg.rc;%(RootDir)%(Directory)\pocomsg.h;%(Outputs) mc -h "%(RootDir)%(Directory)." -r "%(RootDir)%(Directory)." "%(FullPath) - - %(RootDir)%(Directory)\pocomsg.rc;%(RootDir)%(Directory)\pocomsg.h;%(Outputs) + + %(RootDir)%(Directory)\pocomsg.rc;%(RootDir)%(Directory)\pocomsg.h;%(Outputs) mc -h "%(RootDir)%(Directory)." -r "%(RootDir)%(Directory)." "%(FullPath) - - %(RootDir)%(Directory)\pocomsg.rc;%(RootDir)%(Directory)\pocomsg.h;%(Outputs) + + %(RootDir)%(Directory)\pocomsg.rc;%(RootDir)%(Directory)\pocomsg.h;%(Outputs) mc -h "%(RootDir)%(Directory)." -r "%(RootDir)%(Directory)." "%(FullPath) - - %(RootDir)%(Directory)\pocomsg.rc;%(RootDir)%(Directory)\pocomsg.h;%(Outputs) + + %(RootDir)%(Directory)\pocomsg.rc;%(RootDir)%(Directory)\pocomsg.h;%(Outputs) mc -h "%(RootDir)%(Directory)." -r "%(RootDir)%(Directory)." "%(FullPath) - - %(RootDir)%(Directory)\pocomsg.rc;%(RootDir)%(Directory)\pocomsg.h;%(Outputs) + + %(RootDir)%(Directory)\pocomsg.rc;%(RootDir)%(Directory)\pocomsg.h;%(Outputs) mc -h "%(RootDir)%(Directory)." -r "%(RootDir)%(Directory)." "%(FullPath) - - %(RootDir)%(Directory)\pocomsg.rc;%(RootDir)%(Directory)\pocomsg.h;%(Outputs) - - - - - true - true - true - true - - - - - - + + %(RootDir)%(Directory)\pocomsg.rc;%(RootDir)%(Directory)\pocomsg.h;%(Outputs) + + + + + true + true + true + true + + + + + + \ No newline at end of file diff --git a/Foundation/Foundation_vs100.vcxproj.filters b/Foundation/Foundation_vs100.vcxproj.filters index 32d629673..b5213e459 100644 --- a/Foundation/Foundation_vs100.vcxproj.filters +++ b/Foundation/Foundation_vs100.vcxproj.filters @@ -885,6 +885,9 @@ Text\Source Files + + Core\Source Files + @@ -1832,6 +1835,9 @@ Core\Header Files + + Core\Header Files + diff --git a/Foundation/include/Poco/Error.h b/Foundation/include/Poco/Error.h new file mode 100644 index 000000000..c87e41d79 --- /dev/null +++ b/Foundation/include/Poco/Error.h @@ -0,0 +1,68 @@ +// +// Error.h +// +// $Id: //poco/1.4/Foundation/include/Poco/Error.h#1 $ +// +// Library: Foundation +// Package: Core +// Module: Error +// +// Definition of the Error class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef Foundation_Error_INCLUDED +#define Foundation_Error_INCLUDED + + +#include "Poco/Foundation.h" + + +namespace Poco { + + +class Foundation_API Error + /// The Error class provides utility functions + /// for error reporting. +{ +public: + +#ifdef POCO_OS_FAMILY_WINDOWS + static std::string getMessage(DWORD errorCode); + /// Utility function translating numeric error code to string. +#else + static std::string getMessage(int errorCode); + /// Utility function translating numeric error code to string. +#endif +}; + + +} // namespace Poco + + +#endif // Foundation_Error_INCLUDED diff --git a/Foundation/src/Error.cpp b/Foundation/src/Error.cpp new file mode 100644 index 000000000..2f864ecb9 --- /dev/null +++ b/Foundation/src/Error.cpp @@ -0,0 +1,77 @@ +// +// Error.cpp +// +// $Id: //poco/1.4/Foundation/src/Error.cpp#3 $ +// +// Library: Foundation +// Package: Core +// Module: Error +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/Foundation.h" +#include "Poco/UnicodeConverter.h" +#include "Poco/Error.h" +#include + + +namespace Poco { + + +#ifdef POCO_OS_FAMILY_WINDOWS + + std::string Error::getMessage(DWORD errorCode) + { + std::string errMsg; + DWORD dwFlg = FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS; + #if defined(POCO_WIN32_UTF8) && !defined(POCO_NO_WSTRING) + LPWSTR lpMsgBuf = 0; + if (FormatMessageW(dwFlg, 0, errorCode, 0, (LPWSTR) & lpMsgBuf, 0, NULL)) + UnicodeConverter::toUTF8(lpMsgBuf, errMsg); + #else + LPTSTR lpMsgBuf = 0; + if (FormatMessageA(dwFlg, 0, errorCode, 0, (LPTSTR) & lpMsgBuf, 0, NULL)) + errMsg = lpMsgBuf; + #endif + LocalFree(lpMsgBuf); + return errMsg; + } + +#else + + std::string Error::getMessage(int errorCode) + { +#error todo + char errmsg[256]; + return std::string(strerror_r(errorCode, errMsg, 256)); + } + +#endif + + +} // namespace Poco diff --git a/Net/include/Poco/Net/Route.h b/Net/include/Poco/Net/Route.h index 7849e9d7e..d05538b76 100644 --- a/Net/include/Poco/Net/Route.h +++ b/Net/include/Poco/Net/Route.h @@ -43,7 +43,7 @@ #include "Poco/Net/Net.h" -#if defined(POCO_OS_FAMILY_WINDOWS) +#if defined(POCO_OS_FAMILY_WINDOWS) && (_WIN32_WINNT >= 0x600) // only Vista/Longhorn and up #ifndef POCO_NET_HAS_ROUTE #define POCO_NET_HAS_ROUTE #endif diff --git a/Net/src/NetworkInterface.cpp b/Net/src/NetworkInterface.cpp index a6c37d7c9..df4f95cd2 100644 --- a/Net/src/NetworkInterface.cpp +++ b/Net/src/NetworkInterface.cpp @@ -43,6 +43,7 @@ #if defined(POCO_OS_FAMILY_WINDOWS) #if defined(POCO_WIN32_UTF8) #include "Poco/UnicodeConverter.h" + #include "Poco/Error.h" #endif #include #include @@ -892,24 +893,6 @@ IPAddress getBroadcastAddress(PIP_ADAPTER_PREFIX pPrefix, const IPAddress& addr, } -std::string getErrorMessage(DWORD errorCode) -{ - std::string errMsg; - DWORD dwFlg = FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS; -#if defined(POCO_WIN32_UTF8) && !defined(POCO_NO_WSTRING) - LPWSTR lpMsgBuf = 0; - if (FormatMessageW(dwFlg, 0, errorCode, 0, (LPWSTR) & lpMsgBuf, 0, NULL)) - UnicodeConverter::toUTF8(lpMsgBuf, errMsg); -#else - LPTSTR lpMsgBuf = 0; - if (FormatMessageA(dwFlg, 0, errorCode, 0, (LPTSTR) & lpMsgBuf, 0, NULL)) - errMsg = lpMsgBuf; -#endif - LocalFree(lpMsgBuf); - return errMsg; -} - - NetworkInterface::Type fromNative(DWORD type) { switch (type) @@ -957,7 +940,7 @@ NetworkInterface::Map NetworkInterface::map(bool ipOnly, bool upOnly) else if (ERROR_NO_DATA == dwRetVal) // no network interfaces found return result; else if (NO_ERROR != dwRetVal) // error occurred - throw SystemException(format("An error occurred while trying to obtain list of network interfaces: [%s]", getErrorMessage(dwRetVal))); + throw SystemException(format("An error occurred while trying to obtain list of network interfaces: [%s]", Error::getMessage(dwRetVal))); else break; } while ((ERROR_BUFFER_OVERFLOW == dwRetVal) && (++iterations <= 2)); diff --git a/Net/src/Route_WIN32.cpp b/Net/src/Route_WIN32.cpp index d8cf2bde6..d632e3a82 100644 --- a/Net/src/Route_WIN32.cpp +++ b/Net/src/Route_WIN32.cpp @@ -34,17 +34,48 @@ // +#include "Poco/Error.h" + + namespace Poco { namespace Net { +static unsigned int getCompleteMetric(PMIB_IPFORWARD_ROW2 pIp2) + /// The route metric specified in the Metric member of the MIB_IPFORWARD_ROW2 structure + /// represents just the route metric offset. The complete metric is a combination of this + /// route metric offset added to the interface metric specified in the Metric member of + /// the MIB_IPINTERFACE_ROW structure of the associated interface. +{ + MIB_IPINTERFACE_ROW intfcRow; + intfcRow.InterfaceLuid = pIp2->InterfaceLuid; + intfcRow.InterfaceIndex = pIp2->InterfaceIndex; + intfcRow.Family = pIp2->DestinationPrefix.Prefix.si_family; + DWORD ret = GetIpInterfaceEntry(&intfcRow); + if (NO_ERROR == ret) return pIp2->Metric + intfcRow.Metric; + + std::string error; + switch (ret) + { + case ERROR_FILE_NOT_FOUND: + throw RuntimeException("Unknown network interface LUID or interface index"); + case ERROR_INVALID_PARAMETER: + throw RuntimeException("An invalid parameter was passed to the function."); + case ERROR_NOT_FOUND: + throw RuntimeException("Network interface/family mismatch."); + default: + throw RuntimeException(Error::getMessage(ret)); + } +} + + Route::RouteList Route::list(IPAddress::Family family) { std::time_t now; - PMIB_IPFORWARD_TABLE2 pIpForwardTable2 = NULL; + PMIB_IPFORWARD_TABLE2 pIpForwardTable2 = 0; if (GetIpForwardTable2(((family == IPAddress::IPv4) ? AF_INET : AF_INET6), &pIpForwardTable2) != NO_ERROR) - throw std::runtime_error("Couldn't fetch routing table"); + throw RuntimeException("Couldn't fetch routing table."); ::time(&now); @@ -59,8 +90,9 @@ Route::RouteList Route::list(IPAddress::Family family) IPAddress netmask(pIp2->DestinationPrefix.PrefixLength, family2); IPAddress nexthop(*(struct sockaddr *)&pIp2->NextHop); - Route route(dest, netmask, nexthop, pIp2->InterfaceIndex, nexthop.isWildcard() ? ROUTE_INDIRECT : ROUTE_INDIRECT); - route.setMetric(pIp2->Metric); + Route route(dest, netmask, nexthop, pIp2->InterfaceIndex, nexthop.isWildcard() ? ROUTE_DIRECT : ROUTE_INDIRECT); + + route.setMetric(getCompleteMetric(pIp2)); route.setAge(now - pIp2->Age); route.setProto((RouteProto) pIp2->Protocol); diff --git a/Net/testsuite/src/RouteTest.cpp b/Net/testsuite/src/RouteTest.cpp index 7bc17a4c6..e33f9ff78 100644 --- a/Net/testsuite/src/RouteTest.cpp +++ b/Net/testsuite/src/RouteTest.cpp @@ -36,6 +36,7 @@ #include "Poco/Net/IPAddress.h" #include "Poco/Net/Route.h" #include "Poco/Net/NetException.h" +#include using Poco::Net::IPAddress; @@ -66,14 +67,65 @@ RouteTest::~RouteTest() // with results we get back from NetworkInterface::list(). // -void RouteTest::testDefaultRoute() +void RouteTest::testAllRoutes() { Route::RouteList routes = Route::list(IPAddress::IPv4); assert(routes.size() >= 3); + + std::cout << "Active IPv4 Routes:" << std::endl; + std::cout << "=============================================================================" << std::endl; + std::cout << std::setw(17) << "Destinaton" + << std::setw(17) << "Netmask" + << std::setw(17) << "Gateway" + << std::setw(17) << "Interface" + << std::setw(8) << "Metric" << std::endl; + + Route::RouteList::const_iterator it = routes.begin(); + Route::RouteList::const_iterator end = routes.end(); + for (; it != end; ++it) + { + IPAddress ip = it->getNetworkInterface().firstAddress(IPAddress::IPv4); + if (!ip.isLinkLocal()) + { + std::string gateway = it->getNextHop().isWildcard() ? "On-link" : it->getNextHop().toString(); + std::cout << std::setw(17) << it->getDest().toString() + << std::setw(17) << it->getNetmask().toString() + << std::setw(17) << gateway + << std::setw(17) << ip.toString() + << std::setw(8) << it->getMetric() << std::endl; + } + } + std::cout << "=============================================================================" << std::endl; + + routes = Route::list(IPAddress::IPv6); + assert(routes.size() >= 3); + + std::cout << std::endl << "Active IPv6 Routes:" << std::endl; + std::cout << "=============================================================" << std::endl; + std::cout << std::setw(4) << "If" + << std::setw(7) << "Metric" + << std::setw(41) << "Destinaton" + << std::setw(8) << "Gateway" + << std::endl; + + it = routes.begin(); + for (; it != end; ++it) + { + IPAddress ip = it->getNetworkInterface().firstAddress(IPAddress::IPv6); + if (!ip.isLinkLocal()) + { + std::string gateway = it->getNextHop().isWildcard() ? "On-link" : it->getNextHop().toString(); + std::cout << std::setw(4) << it->getIfIndex() + << std::setw(7) << it->getMetric() + << std::setw(41) << it->getDest().toString() + << std::setw(8) << gateway << std::endl; + } + } + std::cout << "=============================================================" << std::endl; } -void RouteTest::testAllRoutes() +void RouteTest::testDefaultRoute() { Route::RouteList defaults = Route::defaults(IPAddress::IPv4); assert(defaults.size() >= 1);