From a2830d2aee15c71ffcb37ab34191af3c9f447a06 Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Tue, 4 Oct 2016 12:35:32 +0200 Subject: [PATCH] EAPMsg profile configuration XML load/save support added --- lib/EAPMsg/include/Config.h | 19 +++++++++++++ lib/EAPMsg/src/Config.cpp | 53 +++++++++++++++++++++++++++++++++++++ lib/WinStd | 2 +- 3 files changed, 73 insertions(+), 1 deletion(-) diff --git a/lib/EAPMsg/include/Config.h b/lib/EAPMsg/include/Config.h index f5ad838..c1af8d8 100644 --- a/lib/EAPMsg/include/Config.h +++ b/lib/EAPMsg/include/Config.h @@ -89,7 +89,26 @@ namespace eap /// virtual config* clone() const; + /// \name XML configuration management + /// @{ + /// + /// Save to XML document + /// + /// \param[in] pDoc XML document + /// \param[in] pConfigRoot Suggested root element for saving + /// + virtual void save(_In_ IXMLDOMDocument *pDoc, _In_ IXMLDOMNode *pConfigRoot) const; + + /// + /// Load from XML document + /// + /// \param[in] pConfigRoot Root element for loading + /// + virtual void load(_In_ IXMLDOMNode *pConfigRoot); + + /// @} + /// \name BLOB management /// @{ diff --git a/lib/EAPMsg/src/Config.cpp b/lib/EAPMsg/src/Config.cpp index b6c8dbb..36a0999 100644 --- a/lib/EAPMsg/src/Config.cpp +++ b/lib/EAPMsg/src/Config.cpp @@ -80,6 +80,59 @@ eap::config* eap::config_method_eapmsg::clone() const } +void eap::config_method_eapmsg::save(_In_ IXMLDOMDocument *pDoc, _In_ IXMLDOMNode *pConfigRoot) const +{ + assert(pDoc); + assert(pConfigRoot); + + config_method::save(pDoc, pConfigRoot); + + // Convert configuration BLOB to XML using EapHost (and ultimately method peer's EapPeerConfigBlob2Xml). + com_obj pConfigDoc; + eap_error error; + DWORD dwResult = EapHostPeerConfigBlob2Xml(0, m_type, (DWORD)m_cfg_blob.size(), const_cast(m_cfg_blob.data()), &pConfigDoc, &error._Myptr); + if (dwResult == ERROR_SUCCESS) { + HRESULT hr; + + com_obj pXmlElConfigDoc; + if (FAILED(hr = pConfigDoc->get_documentElement(&pXmlElConfigDoc))) + throw com_runtime_error(hr, __FUNCTION__ " Error getting XML document element."); + + // Insert method configuration into our XML configuration. + if (FAILED(hr = pConfigRoot->appendChild(pXmlElConfigDoc, NULL))) + throw com_runtime_error(hr, __FUNCTION__ " Error appending configuration document element."); + } else if (error) + throw eap_runtime_error(*error , __FUNCTION__ " EapHostPeerConfigBlob2Xml failed."); + else + throw win_runtime_error(dwResult, __FUNCTION__ " EapHostPeerConfigBlob2Xml failed."); +} + + +void eap::config_method_eapmsg::load(_In_ IXMLDOMNode *pConfigRoot) +{ + assert(pConfigRoot); + + config_method::load(pConfigRoot); + + // + winstd::com_obj pXmlElEapHostConfig; + if (SUCCEEDED(eapxml::select_element(pConfigRoot, winstd::bstr(L"eaphostconfig:EapHostConfig"), pXmlElEapHostConfig))) { + // Convert configuration XML to BLOB using EapHost (and ultimately method peer's EapPeerConfigXml2Blob). + DWORD cfg_data_size = 0; + eap_blob cfg_data; + eap_error error; + DWORD dwResult = EapHostPeerConfigXml2Blob(0, pXmlElEapHostConfig, &cfg_data_size, &cfg_data._Myptr, &m_type, &error._Myptr); + if (dwResult == ERROR_SUCCESS) { + const BYTE *_cfg_data = cfg_data.get(); + m_cfg_blob.assign(_cfg_data, _cfg_data + cfg_data_size); + } else if (error) + throw eap_runtime_error(*error , __FUNCTION__ " EapHostPeerConfigBlob2Xml failed."); + else + throw win_runtime_error(dwResult, __FUNCTION__ " EapHostPeerConfigBlob2Xml failed."); + } +} + + void eap::config_method_eapmsg::operator<<(_Inout_ cursor_out &cursor) const { config_method::operator<<(cursor); diff --git a/lib/WinStd b/lib/WinStd index 73bd1d5..244b00e 160000 --- a/lib/WinStd +++ b/lib/WinStd @@ -1 +1 @@ -Subproject commit 73bd1d5882b936abd7b1fa415539465e58a0942d +Subproject commit 244b00ea779895884570b401a59f3447ad73bb24