config_provider::m_methods is a list of pointers to method configurations now paving the road to config_provider detemplatization
This commit is contained in:
parent
e87c0af221
commit
780b738842
@ -86,8 +86,9 @@ namespace eapserial
|
||||
#include <eaptypes.h> // Must include after <Windows.h>
|
||||
#include <tchar.h>
|
||||
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
|
||||
namespace eap
|
||||
@ -326,12 +327,6 @@ namespace eap
|
||||
template <class _Tmeth>
|
||||
class config_provider : public config
|
||||
{
|
||||
public:
|
||||
///
|
||||
/// Provider method configuration type
|
||||
///
|
||||
typedef _Tmeth config_method_type;
|
||||
|
||||
public:
|
||||
///
|
||||
/// Constructs configuration
|
||||
@ -359,9 +354,10 @@ namespace eap
|
||||
m_lbl_alt_credential(other.m_lbl_alt_credential),
|
||||
m_lbl_alt_identity(other.m_lbl_alt_identity),
|
||||
m_lbl_alt_password(other.m_lbl_alt_password),
|
||||
m_methods(other.m_methods),
|
||||
config(other)
|
||||
{
|
||||
for (std::list<std::unique_ptr<_Tmeth> >::const_iterator method = other.m_methods.cbegin(), method_end = other.m_methods.cend(); method != method_end; ++method)
|
||||
m_methods.push_back(std::move(std::unique_ptr<_Tmeth>(*method ? (_Tmeth*)method->get()->clone() : nullptr)));
|
||||
}
|
||||
|
||||
///
|
||||
@ -404,7 +400,10 @@ namespace eap
|
||||
m_lbl_alt_credential = other.m_lbl_alt_credential;
|
||||
m_lbl_alt_identity = other.m_lbl_alt_identity;
|
||||
m_lbl_alt_password = other.m_lbl_alt_password;
|
||||
m_methods = other.m_methods;
|
||||
|
||||
m_methods.clear();
|
||||
for (std::list<std::unique_ptr<_Tmeth> >::const_iterator method = other.m_methods.cbegin(), method_end = other.m_methods.cend(); method != method_end; ++method)
|
||||
m_methods.push_back(std::move(std::unique_ptr<_Tmeth>(*method ? (_Tmeth*)method->get()->clone() : nullptr)));
|
||||
}
|
||||
|
||||
return *this;
|
||||
@ -549,7 +548,7 @@ namespace eap
|
||||
return false;
|
||||
}
|
||||
|
||||
for (std::list<_Tmeth>::const_iterator method = m_methods.cbegin(), method_end = m_methods.cend(); method != method_end; ++method) {
|
||||
for (std::list<std::unique_ptr<_Tmeth> >::const_iterator method = m_methods.cbegin(), method_end = m_methods.cend(); method != method_end; ++method) {
|
||||
// <AuthenticationMethod>
|
||||
winstd::com_obj<IXMLDOMElement> pXmlElAuthenticationMethod;
|
||||
if ((dwResult = eapxml::create_element(pDoc, winstd::bstr(L"AuthenticationMethod"), bstrNamespace, &pXmlElAuthenticationMethod))) {
|
||||
@ -558,7 +557,7 @@ namespace eap
|
||||
}
|
||||
|
||||
// <AuthenticationMethod>/...
|
||||
if (!method->save(pDoc, pXmlElAuthenticationMethod, ppEapError))
|
||||
if (!method->get()->save(pDoc, pXmlElAuthenticationMethod, ppEapError))
|
||||
return false;
|
||||
|
||||
if (FAILED(hr = pXmlElAuthenticationMethods->appendChild(pXmlElAuthenticationMethod, NULL))) {
|
||||
@ -662,19 +661,19 @@ namespace eap
|
||||
winstd::com_obj<IXMLDOMNode> pXmlElMethod;
|
||||
pXmlListMethods->get_item(i, &pXmlElMethod);
|
||||
|
||||
_Tmeth cfg(m_module);
|
||||
std::unique_ptr<_Tmeth> cfg(new _Tmeth(m_module));
|
||||
|
||||
// Check EAP method type (<EAPMethod>).
|
||||
DWORD dwMethodID;
|
||||
if (eapxml::get_element_value(pXmlElMethod, winstd::bstr(L"eap-metadata:EAPMethod"), &dwMethodID) == ERROR_SUCCESS) {
|
||||
if ((type_t)dwMethodID != cfg.get_method_id()) {
|
||||
if ((type_t)dwMethodID != cfg->get_method_id()) {
|
||||
// Wrong type.
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Load configuration.
|
||||
if (!cfg.load(pXmlElMethod, ppEapError))
|
||||
if (!cfg->load(pXmlElMethod, ppEapError))
|
||||
return false;
|
||||
|
||||
// Add configuration to the list.
|
||||
@ -751,12 +750,17 @@ namespace eap
|
||||
eapserial::unpack(cursor, m_lbl_alt_password );
|
||||
|
||||
std::list<_Tmeth>::size_type count;
|
||||
bool is_nonnull;
|
||||
eapserial::unpack(cursor, count);
|
||||
m_methods.clear();
|
||||
for (std::list<_Tmeth>::size_type i = 0; i < count; i++) {
|
||||
_Tmeth el(m_module);
|
||||
el.unpack(cursor);
|
||||
eapserial::unpack(cursor, is_nonnull);
|
||||
if (is_nonnull) {
|
||||
std::unique_ptr<_Tmeth> el(new _Tmeth(m_module));
|
||||
el->unpack(cursor);
|
||||
m_methods.push_back(std::move(el));
|
||||
} else
|
||||
m_methods.push_back(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
@ -772,7 +776,7 @@ namespace eap
|
||||
winstd::tstring m_lbl_alt_credential; ///< Alternative label for credential prompt
|
||||
winstd::tstring m_lbl_alt_identity; ///< Alternative label for identity prompt
|
||||
winstd::tstring m_lbl_alt_password; ///< Alternative label for password prompt
|
||||
std::list<_Tmeth> m_methods; ///< List of method configurations
|
||||
std::list<std::unique_ptr<_Tmeth> > m_methods; ///< List of method configurations
|
||||
};
|
||||
|
||||
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include <sal.h>
|
||||
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@ -230,6 +231,33 @@ namespace eapserial
|
||||
///
|
||||
template<class _Ty, class _Ax> inline void unpack(_Inout_ const unsigned char *&cursor, _Out_ std::list<_Ty, _Ax> &val);
|
||||
|
||||
///
|
||||
/// Packs a std::unique_ptr
|
||||
///
|
||||
/// \param[inout] cursor Memory cursor
|
||||
/// \param[in] val std::unique_ptr to pack
|
||||
///
|
||||
template<class _Ty, class _Dx> inline void pack(_Inout_ unsigned char *&cursor, _In_ const std::unique_ptr<_Ty, _Dx> &val);
|
||||
|
||||
///
|
||||
/// Returns packed size of a std::unique_ptr
|
||||
///
|
||||
/// \param[in] val std::unique_ptr to pack
|
||||
///
|
||||
/// \returns Size of data when packed (in bytes)
|
||||
///
|
||||
template<class _Ty, class _Dx> inline size_t get_pk_size(const std::unique_ptr<_Ty, _Dx> &val);
|
||||
|
||||
/////
|
||||
///// Unpacks a std::unique_ptr
|
||||
/////
|
||||
///// \note Not generally unpackable, since we do not know, how to create a new instance of unique_ptr.
|
||||
/////
|
||||
///// \param[inout] cursor Memory cursor
|
||||
///// \param[out] val std::unique_ptr to unpack to
|
||||
/////
|
||||
//template<class _Ty, class _Dx> inline void unpack(_Inout_ const unsigned char *&cursor, _Out_ std::unique_ptr<_Ty, _Dx> &val);
|
||||
|
||||
///
|
||||
/// Packs a certificate context
|
||||
///
|
||||
@ -486,6 +514,28 @@ namespace eapserial
|
||||
}
|
||||
|
||||
|
||||
template<class _Ty, class _Dx>
|
||||
inline void pack(_Inout_ unsigned char *&cursor, _In_ const std::unique_ptr<_Ty, _Dx> &val)
|
||||
{
|
||||
if (val) {
|
||||
pack(cursor, true);
|
||||
pack(cursor, *val);
|
||||
} else
|
||||
pack(cursor, false);
|
||||
}
|
||||
|
||||
|
||||
template<class _Ty, class _Dx>
|
||||
inline size_t get_pk_size(const std::unique_ptr<_Ty, _Dx> &val)
|
||||
{
|
||||
return
|
||||
val ?
|
||||
get_pk_size(true) +
|
||||
get_pk_size(*val) :
|
||||
get_pk_size(false);
|
||||
}
|
||||
|
||||
|
||||
inline void pack(_Inout_ unsigned char *&cursor, _In_ const winstd::cert_context &val)
|
||||
{
|
||||
if (val) {
|
||||
|
@ -116,13 +116,13 @@ public:
|
||||
|
||||
for (std::list<_Tprov>::iterator provider = m_cfg.m_providers.begin(), provider_end = m_cfg.m_providers.end(); provider != provider_end; ++provider) {
|
||||
bool is_single = provider->m_methods.size() == 1;
|
||||
std::list<_Tmeth>::size_type count = 0;
|
||||
std::list<_Tmeth>::iterator method = provider->m_methods.begin(), method_end = provider->m_methods.end();
|
||||
std::list<std::unique_ptr<_Tmeth> >::size_type count = 0;
|
||||
std::list<std::unique_ptr<_Tmeth> >::iterator method = provider->m_methods.begin(), method_end = provider->m_methods.end();
|
||||
for (; method != method_end; ++method, count++)
|
||||
m_providers->AddPage(
|
||||
new _wxT(
|
||||
*provider,
|
||||
*method,
|
||||
*method->get(),
|
||||
provider->m_id.c_str(),
|
||||
m_providers),
|
||||
is_single ? provider->m_id : winstd::tstring_printf(_T("%s (%u)"), provider->m_id.c_str(), count));
|
||||
|
Loading…
x
Reference in New Issue
Block a user