From 129b9c9a10c2145235e8f447706875dcafa4a4a3 Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Fri, 30 Sep 2016 15:19:43 +0200 Subject: [PATCH] Some EapHost peer helper classes introduced --- include/WinStd/EAP.h | 106 +++++++++++++++++++++++++++++++++++++++++++ src/EAP.cpp | 32 +++++++++++++ 2 files changed, 138 insertions(+) diff --git a/include/WinStd/EAP.h b/include/WinStd/EAP.h index 6f6aaaa3..000122dc 100644 --- a/include/WinStd/EAP.h +++ b/include/WinStd/EAP.h @@ -21,6 +21,7 @@ #include "Common.h" #include +#include #include // Must include after namespace winstd @@ -38,6 +39,16 @@ namespace winstd /// enum eap_type_t; + /// + /// Deleter for unique_ptr using EapHostPeerFreeMemory + /// + struct WINSTD_API EapHostPeerFreeMemory_delete; + + /// + /// Deleter for unique_ptr to EAP_ERROR using EapHostPeerFreeEapError + /// + struct WINSTD_API EapHostPeerFreeErrorMemory_delete; + /// /// EAP_ATTRIBUTE wrapper class /// @@ -53,6 +64,11 @@ namespace winstd /// class WINSTD_API eap_packet; + /// + /// EAP_METHOD_INFO_ARRAY wrapper class + /// + class WINSTD_API eap_method_info_array; + /// @} } @@ -87,6 +103,40 @@ namespace winstd }; + struct WINSTD_API EapHostPeerFreeMemory_delete + { + /// + /// Default constructor + /// + EapHostPeerFreeMemory_delete() {} + + /// + /// Delete a pointer + /// + void operator()(BYTE *_Ptr) const + { + EapHostPeerFreeMemory(_Ptr); + } + }; + + + struct WINSTD_API EapHostPeerFreeErrorMemory_delete + { + /// + /// Default constructor + /// + EapHostPeerFreeErrorMemory_delete() {} + + /// + /// Delete a pointer + /// + void operator()(EAP_ERROR *_Ptr) const + { + EapHostPeerFreeErrorMemory(_Ptr); + } + }; + + class WINSTD_API __declspec(novtable) eap_attr : public EAP_ATTRIBUTE { public: @@ -304,4 +354,60 @@ namespace winstd /// virtual handle_type duplicate_internal(_In_ handle_type h) const; }; + + + class WINSTD_API __declspec(novtable) eap_method_info_array : public EAP_METHOD_INFO_ARRAY + { + WINSTD_NONCOPYABLE(eap_method_info_array) + + public: + /// + /// Constructs an empty array + /// + inline eap_method_info_array() + { + dwNumberOfMethods = 0; + pEapMethods = NULL; + } + + /// + /// Move constructor + /// + /// \param[inout] other A rvalue reference of another object + /// + inline eap_method_info_array(_Inout_ eap_method_info_array &&other) + { + dwNumberOfMethods = other.dwNumberOfMethods; + pEapMethods = other.pEapMethods; + other.dwNumberOfMethods = 0; + other.pEapMethods = NULL; + } + + /// + /// Destructor + /// + ~eap_method_info_array(); + + /// + /// Move assignment + /// + /// \param[inout] other A rvalue reference of another object + /// + inline eap_method_info_array& operator=(_Inout_ eap_method_info_array &&other) + { + if (this != std::addressof(other)) { + if (pEapMethods) + free_internal(); + dwNumberOfMethods = other.dwNumberOfMethods; + pEapMethods = other.pEapMethods; + other.dwNumberOfMethods = 0; + other.pEapMethods = NULL; + } + return *this; + } + + protected: + void free_internal(); + static void free_internal(_In_ EAP_METHOD_INFO *pMethodInfo); + }; } diff --git a/src/EAP.cpp b/src/EAP.cpp index 9854324d..73f8e4cc 100644 --- a/src/EAP.cpp +++ b/src/EAP.cpp @@ -20,6 +20,8 @@ #include "StdAfx.h" +#pragma comment(lib, "Eappcfg.lib") + ////////////////////////////////////////////////////////////////////// // winstd::eap_attr @@ -99,3 +101,33 @@ winstd::eap_packet::handle_type winstd::eap_packet::duplicate_internal(_In_ hand return h2; } + + +////////////////////////////////////////////////////////////////////// +// winstd::eap_method_info_array +////////////////////////////////////////////////////////////////////// + +winstd::eap_method_info_array::~eap_method_info_array() +{ + if (pEapMethods) + free_internal(); +} + + +void winstd::eap_method_info_array::free_internal() +{ + for (DWORD i = 0; i < dwNumberOfMethods; i++) + free_internal(pEapMethods + i); + + EapHostPeerFreeMemory((BYTE*)pEapMethods); +} + + +void winstd::eap_method_info_array::free_internal(_In_ EAP_METHOD_INFO *pMethodInfo) +{ + if (pMethodInfo->pInnerMethodInfo) + free_internal(pMethodInfo->pInnerMethodInfo); + + EapHostPeerFreeMemory((BYTE*)pMethodInfo->pwszAuthorName); + EapHostPeerFreeMemory((BYTE*)pMethodInfo->pwszFriendlyName); +}