Listing 1: CSslProvider class

... // other code not shown

// definition

class CSslProvider

{

public:

CSslProvider(void);

~CSslProvider(void);

private:

CSslCredentials m_sslCredentials;

CNbtCriticalSection m_critSec;

public:

// Intialization functions that must be

// called prior to calling ObtainTransport()

HRESULT Init(BOOL bAsServer, LPCTSTR strPrincipal,

LPCTSTR strStore, BOOL bMutualAuth);

HRESULT Init(BOOL bAsServer, LPCTSTR strPrincipal,

HCERTSTORE hStore, BOOL bMutualAuth);

HRESULT Init();

void Destroy();

HRESULT Attach(CredHandle hCredentials, BOOL bAsServer,

BOOL bMutualAuth);

HRESULT Detach();

HRESULT ObtainTransport(CSslTransport*& pSslTransport);

... // other code not shown

};

... // other code not shown

// implementation

HRESULT CSslProvider::ObtainTransport(

CSslTransport*& pSslTransport)

{

m_critSec.Lock();

HRESULT hr = S_OK;

pSslTransport = NULL;

// Make sure we obtained the credentials prior to this call

if (m_sslCredentials.HasCredHandle())

{

pSslTransport = new CSslTransport(m_sslCredentials);

if (pSslTransport == NULL)

hr = E_OUTOFMEMORY;

}

else

hr = SEC_E_NO_CREDENTIALS;

m_critSec.Unlock();

if (FAILED(hr))

TRACE1("Failed to obtain transport. Error: 0x%08X.\n", hr);

return hr;

}