From 66dd2bf283330c653409f40ee29a570961a98397 Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Tue, 7 Feb 2017 09:33:29 +0100 Subject: [PATCH] eap::config split to eap::config and eap::packable --- lib/EAPBase/include/Config.h | 78 +----------------------------- lib/EAPBase/include/EAP.h | 84 +++++++++++++++++++++++++++++++++ lib/EAPBase/include/UIContext.h | 5 +- lib/EAPBase/src/Config.cpp | 18 ------- lib/EAPBase/src/EAP.cpp | 29 ++++++++++++ lib/EAPBase/src/UIContext.cpp | 25 +++++----- lib/TTLS/include/UIContext.h | 10 +--- lib/TTLS/src/Module.cpp | 2 +- lib/TTLS/src/UIContext.cpp | 13 ++--- lib/TTLS_UI/src/Module.cpp | 2 +- 10 files changed, 136 insertions(+), 130 deletions(-) diff --git a/lib/EAPBase/include/Config.h b/lib/EAPBase/include/Config.h index 93c49d1..673c02b 100644 --- a/lib/EAPBase/include/Config.h +++ b/lib/EAPBase/include/Config.h @@ -31,36 +31,6 @@ namespace eap class config_connection; } -/// \addtogroup EAPBaseStream -/// @{ - -/// -/// Packs a configuration -/// -/// \param[inout] cursor Memory cursor -/// \param[in] val Configuration to pack -/// -inline void operator<<(_Inout_ eap::cursor_out &cursor, _In_ const eap::config &val); - -/// -/// Returns packed size of a configuration -/// -/// \param[in] val Configuration to pack -/// -/// \returns Size of data when packed (in bytes) -/// -inline size_t pksizeof(_In_ const eap::config &val); - -/// -/// Unpacks a configuration -/// -/// \param[inout] cursor Memory cursor -/// \param[out] val Configuration to unpack to -/// -inline void operator>>(_Inout_ eap::cursor_in &cursor, _Out_ eap::config &val); - -/// @} - #pragma once #include "Module.h" @@ -89,9 +59,9 @@ namespace eap /// @{ /// - /// Base class for configuration storage + /// Base class for packable and XML-exportable storage /// - class config + class config : public packable { public: /// @@ -160,32 +130,6 @@ namespace eap /// @} - /// \name BLOB management - /// @{ - - /// - /// Packs this object - /// - /// \param[inout] cursor Memory cursor - /// - virtual void operator<<(_Inout_ cursor_out &cursor) const; - - /// - /// Returns packed size of this object - /// - /// \returns Size of data when packed (in bytes) - /// - virtual size_t get_pk_size() const; - - /// - /// Unpacks this object - /// - /// \param[inout] cursor Memory cursor - /// - virtual void operator>>(_Inout_ cursor_in &cursor); - - /// @} - public: module &m_module; ///< EAP module @@ -530,24 +474,6 @@ namespace eap } -inline void operator<<(_Inout_ eap::cursor_out &cursor, _In_ const eap::config &val) -{ - val.operator<<(cursor); -} - - -inline size_t pksizeof(_In_ const eap::config &val) -{ - return val.get_pk_size(); -} - - -inline void operator>>(_Inout_ eap::cursor_in &cursor, _Out_ eap::config &val) -{ - val.operator>>(cursor); -} - - /// \addtogroup EAPBaseStream /// @{ diff --git a/lib/EAPBase/include/EAP.h b/lib/EAPBase/include/EAP.h index ada5370..8256201 100644 --- a/lib/EAPBase/include/EAP.h +++ b/lib/EAPBase/include/EAP.h @@ -80,6 +80,8 @@ namespace eap struct cursor_out; struct cursor_in; + class packable; + template struct WINSTD_NOVTABLE sanitizing_blob_f; template struct WINSTD_NOVTABLE sanitizing_blob_zf; @@ -499,6 +501,31 @@ inline size_t pksizeof(_In_ const EAP_METHOD_TYPE &val); /// inline void operator>>(_Inout_ eap::cursor_in &cursor, _Out_ EAP_METHOD_TYPE &val); +/// +/// Packs a packable object +/// +/// \param[inout] cursor Memory cursor +/// \param[in] val Object to pack +/// +inline void operator<<(_Inout_ eap::cursor_out &cursor, _In_ const eap::packable &val); + +/// +/// Returns packed size of a packable object +/// +/// \param[in] val Object to pack +/// +/// \returns Size of data when packed (in bytes) +/// +inline size_t pksizeof(_In_ const eap::packable &val); + +/// +/// Unpacks a packable object +/// +/// \param[inout] cursor Memory cursor +/// \param[out] val Object to unpack to +/// +inline void operator>>(_Inout_ eap::cursor_in &cursor, _Out_ eap::packable &val); + /// @} /// @@ -574,6 +601,45 @@ namespace eap ptr_type ptr_end; ///< Pointer to the end of BLOB }; + + /// + /// Base class for all packable data classes + /// + class packable + { + public: + /// + /// Constructs configuration + /// + packable(); + + /// \name BLOB management + /// @{ + + /// + /// Packs this object + /// + /// \param[inout] cursor Memory cursor + /// + virtual void operator<<(_Inout_ cursor_out &cursor) const; + + /// + /// Returns packed size of this object + /// + /// \returns Size of data when packed (in bytes) + /// + virtual size_t get_pk_size() const; + + /// + /// Unpacks this object + /// + /// \param[inout] cursor Memory cursor + /// + virtual void operator>>(_Inout_ cursor_in &cursor); + + /// @} + }; + /// @} /// \addtogroup EAPBaseSanitizing @@ -1198,6 +1264,24 @@ inline void operator>>(_Inout_ eap::cursor_in &cursor, _Out_ EAP_METHOD_TYPE &va } +inline void operator<<(_Inout_ eap::cursor_out &cursor, _In_ const eap::packable &val) +{ + val.operator<<(cursor); +} + + +inline size_t pksizeof(_In_ const eap::packable &val) +{ + return val.get_pk_size(); +} + + +inline void operator>>(_Inout_ eap::cursor_in &cursor, _Out_ eap::packable &val) +{ + val.operator>>(cursor); +} + + #ifndef htonll inline unsigned __int64 htonll(unsigned __int64 val) diff --git a/lib/EAPBase/include/UIContext.h b/lib/EAPBase/include/UIContext.h index 7c5cd4a..2d3c34e 100644 --- a/lib/EAPBase/include/UIContext.h +++ b/lib/EAPBase/include/UIContext.h @@ -43,17 +43,16 @@ namespace eap /// /// UI context /// - class ui_context : public config + class ui_context : public packable { public: /// /// Constructs context /// - /// \param[in] mod EAP module to use for global services /// \param[in] cfg Connection configuration /// \param[in] cred Connection credentials /// - ui_context(_In_ module &mod, _In_ config_connection &cfg, _In_ credentials_connection &cred); + ui_context(_In_ config_connection &cfg, _In_ credentials_connection &cred); /// /// Copies context diff --git a/lib/EAPBase/src/Config.cpp b/lib/EAPBase/src/Config.cpp index 5aeb4d6..1e87c3c 100644 --- a/lib/EAPBase/src/Config.cpp +++ b/lib/EAPBase/src/Config.cpp @@ -77,24 +77,6 @@ void eap::config::load(_In_ IXMLDOMNode *pConfigRoot) } -void eap::config::operator<<(_Inout_ cursor_out &cursor) const -{ - UNREFERENCED_PARAMETER(cursor); -} - - -size_t eap::config::get_pk_size() const -{ - return 0; -} - - -void eap::config::operator>>(_Inout_ cursor_in &cursor) -{ - UNREFERENCED_PARAMETER(cursor); -} - - const bstr eap::config::namespace_eapmetadata(L"urn:ietf:params:xml:ns:yang:ietf-eap-metadata"); diff --git a/lib/EAPBase/src/EAP.cpp b/lib/EAPBase/src/EAP.cpp index 16c6b45..6eebc5e 100644 --- a/lib/EAPBase/src/EAP.cpp +++ b/lib/EAPBase/src/EAP.cpp @@ -20,10 +20,39 @@ #include "StdAfx.h" +#pragma comment(lib, "Ws2_32.lib") + using namespace std; using namespace winstd; +////////////////////////////////////////////////////////////////////// +// eap::packable +////////////////////////////////////////////////////////////////////// + +eap::packable::packable() +{ +} + + +void eap::packable::operator<<(_Inout_ cursor_out &cursor) const +{ + UNREFERENCED_PARAMETER(cursor); +} + + +size_t eap::packable::get_pk_size() const +{ + return 0; +} + + +void eap::packable::operator>>(_Inout_ cursor_in &cursor) +{ + UNREFERENCED_PARAMETER(cursor); +} + + ////////////////////////////////////////////////////////////////////// // eap::diameter_avp_append ////////////////////////////////////////////////////////////////////// diff --git a/lib/EAPBase/src/UIContext.cpp b/lib/EAPBase/src/UIContext.cpp index ecb0658..e2f1946 100644 --- a/lib/EAPBase/src/UIContext.cpp +++ b/lib/EAPBase/src/UIContext.cpp @@ -28,8 +28,7 @@ using namespace winstd; // eap::ui_context ////////////////////////////////////////////////////////////////////// -eap::ui_context::ui_context(_In_ module &mod, _In_ config_connection &cfg, _In_ credentials_connection &cred) : - config(mod), +eap::ui_context::ui_context(_In_ config_connection &cfg, _In_ credentials_connection &cred) : m_cfg(cfg), m_cred(cred) { @@ -37,17 +36,17 @@ eap::ui_context::ui_context(_In_ module &mod, _In_ config_connection &cfg, _In_ eap::ui_context::ui_context(_In_ const ui_context &other) : - m_cfg (other.m_cfg ), - m_cred(other.m_cred), - config(other ) + m_cfg (other.m_cfg ), + m_cred (other.m_cred), + packable(other ) { } eap::ui_context::ui_context(_Inout_ ui_context &&other) : - m_cfg ( other.m_cfg ), - m_cred( other.m_cred ), - config(std::move(other )) + m_cfg ( other.m_cfg ), + m_cred ( other.m_cred ), + packable(std::move(other )) { } @@ -57,7 +56,7 @@ eap::ui_context& eap::ui_context::operator=(_In_ const ui_context &other) if (this != &other) { assert(std::addressof(m_cfg ) == std::addressof(other.m_cfg )); // Copy context within same configuration only! assert(std::addressof(m_cred) == std::addressof(other.m_cred)); // Copy context within same credentials only! - (config&)*this = other; + (packable&)*this = other; } return *this; @@ -69,7 +68,7 @@ eap::ui_context& eap::ui_context::operator=(_Inout_ ui_context &&other) if (this != &other) { assert(std::addressof(m_cfg ) == std::addressof(other.m_cfg )); // Move context within same configuration only! assert(std::addressof(m_cred) == std::addressof(other.m_cred)); // Move context within same credentials only! - (config&)*this = std::move(other); + (packable&)*this = std::move(other); } return *this; @@ -78,7 +77,7 @@ eap::ui_context& eap::ui_context::operator=(_Inout_ ui_context &&other) void eap::ui_context::operator<<(_Inout_ cursor_out &cursor) const { - config::operator<<(cursor); + packable::operator<<(cursor); cursor << m_cfg ; cursor << m_cred; } @@ -87,7 +86,7 @@ void eap::ui_context::operator<<(_Inout_ cursor_out &cursor) const size_t eap::ui_context::get_pk_size() const { return - config::get_pk_size() + + packable::get_pk_size() + pksizeof(m_cfg ) + pksizeof(m_cred); } @@ -95,7 +94,7 @@ size_t eap::ui_context::get_pk_size() const void eap::ui_context::operator>>(_Inout_ cursor_in &cursor) { - config::operator>>(cursor); + packable::operator>>(cursor); cursor >> m_cfg ; cursor >> m_cred; } diff --git a/lib/TTLS/include/UIContext.h b/lib/TTLS/include/UIContext.h index 5caa600..051363c 100644 --- a/lib/TTLS/include/UIContext.h +++ b/lib/TTLS/include/UIContext.h @@ -44,11 +44,10 @@ namespace eap /// /// Constructs context /// - /// \param[in] mod EAP module to use for global services /// \param[in] cfg Connection configuration /// \param[in] cred Connection credentials /// - ui_context_ttls(_In_ module &mod, _In_ config_connection &cfg, _In_ credentials_connection &cred); + ui_context_ttls(_In_ config_connection &cfg, _In_ credentials_connection &cred); /// /// Copies context @@ -82,13 +81,6 @@ namespace eap /// ui_context_ttls& operator=(_Inout_ ui_context_ttls &&other); - /// - /// Clones this object - /// - /// \returns Pointer to cloned object with identical data - /// - virtual config* clone() const; - /// \name BLOB management /// @{ virtual void operator<<(_Inout_ cursor_out &cursor) const; diff --git a/lib/TTLS/src/Module.cpp b/lib/TTLS/src/Module.cpp index dd41f5f..433ef89 100644 --- a/lib/TTLS/src/Module.cpp +++ b/lib/TTLS/src/Module.cpp @@ -367,7 +367,7 @@ void eap::peer_ttls::get_ui_context( auto s = static_cast(hSession); // Get context data from method. - ui_context_ttls ctx(*this, s->m_cfg, s->m_cred); + ui_context_ttls ctx(s->m_cfg, s->m_cred); s->m_method->get_ui_context(ctx.m_data); // Pack context data. diff --git a/lib/TTLS/src/UIContext.cpp b/lib/TTLS/src/UIContext.cpp index 26b1975..7b37ccf 100644 --- a/lib/TTLS/src/UIContext.cpp +++ b/lib/TTLS/src/UIContext.cpp @@ -28,14 +28,15 @@ using namespace winstd; // eap::ui_context_ttls ////////////////////////////////////////////////////////////////////// -eap::ui_context_ttls::ui_context_ttls(_In_ module &mod, _In_ config_connection &cfg, _In_ credentials_connection &cred) : - ui_context(mod, cfg, cred) +eap::ui_context_ttls::ui_context_ttls(_In_ config_connection &cfg, _In_ credentials_connection &cred) : + ui_context(cfg, cred) { } eap::ui_context_ttls::ui_context_ttls(_In_ const ui_context_ttls &other) : - ui_context(other) + m_data (other.m_data), + ui_context(other ) { } @@ -69,12 +70,6 @@ eap::ui_context_ttls& eap::ui_context_ttls::operator=(_Inout_ ui_context_ttls && } -eap::config* eap::ui_context_ttls::clone() const -{ - return new ui_context_ttls(*this); -} - - void eap::ui_context_ttls::operator<<(_Inout_ cursor_out &cursor) const { ui_context::operator<<(cursor); diff --git a/lib/TTLS_UI/src/Module.cpp b/lib/TTLS_UI/src/Module.cpp index 0912090..8ec537d 100644 --- a/lib/TTLS_UI/src/Module.cpp +++ b/lib/TTLS_UI/src/Module.cpp @@ -393,7 +393,7 @@ void eap::peer_ttls_ui::invoke_interactive_ui( // Unpack context data. config_connection cfg(*this); credentials_connection cred(*this, cfg); - ui_context_ttls ctx(*this, cfg, cred); + ui_context_ttls ctx(cfg, cred); unpack(ctx, pUIContextData, dwUIContextDataSize); // Look-up the provider.