#ifdef __MWERKS__
#define _CPP_ATTACHFACTORY
#endif
#include "attachfactory.h"
#include "cspattachment.h"
#include <Security/cssmdli.h>
#include <Security/cssmcli.h>
#include <Security/cssmaci.h>
#include <Security/cssmtpi.h>
#include "funcnames.gen"
#include <map>
template <CSSM_SERVICE_TYPE type, typename Table, const char *const nameTable[]>
class StandardAttachmentMaker : public AttachmentMaker {
public:
StandardAttachmentMaker() : AttachmentMaker(type)
{
for (unsigned n = 0; n < sizeof(nameTable) / sizeof(nameTable[0]); n++)
nameMap.insert(typename NameMap::value_type(nameTable[n], n));
}
Attachment *make(Module *module,
const CSSM_VERSION &version,
uint32 subserviceId,
CSSM_SERVICE_TYPE subserviceType,
const CSSM_API_MEMORY_FUNCS &memoryOps,
CSSM_ATTACH_FLAGS attachFlags,
CSSM_KEY_HIERARCHY keyHierarchy,
CSSM_FUNC_NAME_ADDR *FunctionTable,
uint32 NumFunctions)
{
StandardAttachment<type, Table> *attachment =
new StandardAttachment<type, Table>(module,
nameMap,
version,
subserviceId,
subserviceType,
memoryOps,
attachFlags,
keyHierarchy);
attachment->resolveSymbols(FunctionTable, NumFunctions);
return attachment;
}
private:
typedef typename StandardAttachment<type, Table>::NameMap NameMap;
NameMap nameMap;
};
AttachmentFactory::AttachmentFactory()
{
factories[CSSM_SERVICE_AC] = new StandardAttachmentMaker<CSSM_SERVICE_AC, CSSM_SPI_AC_FUNCS, ACNameTable>;
factories[CSSM_SERVICE_CL] = new StandardAttachmentMaker<CSSM_SERVICE_CL, CSSM_SPI_CL_FUNCS, CLNameTable>;
factories[CSSM_SERVICE_CSP] = new StandardAttachmentMaker<CSSM_SERVICE_CSP, CSSM_SPI_CSP_FUNCS, CSPNameTable>;
factories[CSSM_SERVICE_DL] = new StandardAttachmentMaker<CSSM_SERVICE_DL, CSSM_SPI_DL_FUNCS, DLNameTable>;
factories[CSSM_SERVICE_TP] = new StandardAttachmentMaker<CSSM_SERVICE_TP, CSSM_SPI_TP_FUNCS, TPNameTable>;
}
AttachmentMaker *AttachmentFactory::attachmentMakerFor(CSSM_SERVICE_TYPE type) const
{
AttachFactories::const_iterator it = factories.find(type);
if (it == factories.end())
CssmError::throwMe(CSSMERR_CSSM_INVALID_SERVICE_MASK);
return it->second;
}
AttachmentMaker::~AttachmentMaker()
{
}