Template for creating XML configuration simplified
This commit is contained in:
parent
5dfd079686
commit
510bbe10f6
@ -193,17 +193,17 @@ DWORD WINAPI EapPeerConfigBlob2Xml(
|
||||
HRESULT hr;
|
||||
|
||||
// Create configuration XML document.
|
||||
com_obj<IXMLDOMDocument2> pDoc;
|
||||
if (FAILED(hr = pDoc.create(CLSID_DOMDocument60, NULL, CLSCTX_INPROC_SERVER))) {
|
||||
com_obj<IXMLDOMDocument2> pConfigDoc;
|
||||
if (FAILED(hr = pConfigDoc.create(CLSID_DOMDocument60, NULL, CLSCTX_INPROC_SERVER))) {
|
||||
g_peer.log_error(*ppEapError = g_peer.make_error(dwResult = HRESULT_CODE(hr), _T(__FUNCTION__) _T(" Error creating XML document.")));
|
||||
return dwResult;
|
||||
}
|
||||
|
||||
pDoc->put_async(VARIANT_FALSE);
|
||||
pConfigDoc->put_async(VARIANT_FALSE);
|
||||
|
||||
// Load empty XML configuration.
|
||||
VARIANT_BOOL isSuccess = VARIANT_FALSE;
|
||||
if (FAILED((hr = pDoc->loadXML(L"<Config xmlns=\"http://www.microsoft.com/provisioning/EapHostConfig\"><EAPIdentityProviderList xmlns=\"urn:ietf:params:xml:ns:yang:ietf-eap-metadata\"></EAPIdentityProviderList></Config>", &isSuccess)))) {
|
||||
if (FAILED((hr = pConfigDoc->loadXML(L"<Config xmlns=\"http://www.microsoft.com/provisioning/EapHostConfig\"></Config>", &isSuccess)))) {
|
||||
g_peer.log_error(*ppEapError = g_peer.make_error(dwResult = HRESULT_CODE(hr), _T(__FUNCTION__) _T(" Error loading XML document template.")));
|
||||
return dwResult;
|
||||
}
|
||||
@ -214,16 +214,16 @@ DWORD WINAPI EapPeerConfigBlob2Xml(
|
||||
|
||||
// Select <Config> node.
|
||||
com_obj<IXMLDOMNode> pXmlElConfig;
|
||||
pDoc->setProperty(bstr(L"SelectionNamespaces"), variant(L"xmlns:eaphostconfig=\"http://www.microsoft.com/provisioning/EapHostConfig\""));
|
||||
if (FAILED(eapxml::select_node(pDoc, bstr(L"eaphostconfig:Config"), &pXmlElConfig))) {
|
||||
pConfigDoc->setProperty(bstr(L"SelectionNamespaces"), variant(L"xmlns:eaphostconfig=\"http://www.microsoft.com/provisioning/EapHostConfig\""));
|
||||
if (FAILED(eapxml::select_node(pConfigDoc, bstr(L"eaphostconfig:Config"), &pXmlElConfig))) {
|
||||
g_peer.log_error(*ppEapError = g_peer.make_error(dwResult = ERROR_NOT_FOUND, _T(__FUNCTION__) _T(" Error selecting <Config> element.")));
|
||||
return dwResult;
|
||||
}
|
||||
|
||||
// Save configuration.
|
||||
pDoc->setProperty(bstr(L"SelectionNamespaces"), variant(L"xmlns:eap-metadata=\"urn:ietf:params:xml:ns:yang:ietf-eap-metadata\""));
|
||||
pConfigDoc->setProperty(bstr(L"SelectionNamespaces"), variant(L"xmlns:eap-metadata=\"urn:ietf:params:xml:ns:yang:ietf-eap-metadata\""));
|
||||
try {
|
||||
g_peer.config_blob2xml(dwFlags, pConnectionData, dwConnectionDataSize, pDoc, pXmlElConfig);
|
||||
g_peer.config_blob2xml(dwFlags, pConnectionData, dwConnectionDataSize, pConfigDoc, pXmlElConfig);
|
||||
} catch (std::exception &err) {
|
||||
g_peer.log_error(*ppEapError = g_peer.make_error(err));
|
||||
return dwResult = (*ppEapError)->dwWinError;
|
||||
@ -231,7 +231,7 @@ DWORD WINAPI EapPeerConfigBlob2Xml(
|
||||
return dwResult = ERROR_INVALID_DATA;
|
||||
}
|
||||
|
||||
*ppConfigDoc = pDoc.detach();
|
||||
*ppConfigDoc = pConfigDoc.detach();
|
||||
}
|
||||
|
||||
return dwResult;
|
||||
|
@ -666,10 +666,10 @@ void eap::config_connection::save(_In_ IXMLDOMDocument *pDoc, _In_ IXMLDOMNode *
|
||||
const bstr bstrNamespace(L"urn:ietf:params:xml:ns:yang:ietf-eap-metadata");
|
||||
HRESULT hr;
|
||||
|
||||
// Select <EAPIdentityProviderList> node.
|
||||
com_obj<IXMLDOMNode> pXmlElIdentityProviderList;
|
||||
if (FAILED(hr = eapxml::select_node(pConfigRoot, bstr(L"eap-metadata:EAPIdentityProviderList"), &pXmlElIdentityProviderList)))
|
||||
throw com_runtime_error(hr, __FUNCTION__ " Error selecting <EAPIdentityProviderList> element.");
|
||||
// Create <EAPIdentityProviderList> node.
|
||||
com_obj<IXMLDOMElement> pXmlElIdentityProviderList;
|
||||
if (FAILED(hr = eapxml::create_element(pDoc, bstr(L"EAPIdentityProviderList"), bstrNamespace, &pXmlElIdentityProviderList)))
|
||||
throw com_runtime_error(hr, __FUNCTION__ " Error creating <EAPIdentityProviderList> element.");
|
||||
|
||||
for (provider_list::const_iterator provider = m_providers.cbegin(), provider_end = m_providers.cend(); provider != provider_end; ++provider) {
|
||||
// <EAPIdentityProvider>
|
||||
@ -683,6 +683,9 @@ void eap::config_connection::save(_In_ IXMLDOMDocument *pDoc, _In_ IXMLDOMNode *
|
||||
if (FAILED(hr = pXmlElIdentityProviderList->appendChild(pXmlElIdentityProvider, NULL)))
|
||||
throw com_runtime_error(hr, __FUNCTION__ " Error appending <EAPIdentityProvider> element.");
|
||||
}
|
||||
|
||||
if (FAILED(hr = pConfigRoot->appendChild(pXmlElIdentityProviderList, NULL)))
|
||||
throw com_runtime_error(hr, __FUNCTION__ " Error appending <EAPIdentityProviderList> element.");
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user