2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
20 // attachfactory - industrial grade production of Attachment objects
23 #define _CPP_ATTACHFACTORY
25 #include "attachfactory.h"
27 #include "cspattachment.h"
28 #include <Security/cssmdli.h>
29 #include <Security/cssmcli.h>
30 #include <Security/cssmaci.h>
31 #include <Security/cssmtpi.h>
32 #include "funcnames.gen"
37 // A template to generate AttachmentMakers for the standard plugin types.
39 template <CSSM_SERVICE_TYPE type
, typename Table
, const char *const nameTable
[]>
40 class StandardAttachmentMaker
: public AttachmentMaker
{
42 StandardAttachmentMaker();
44 Attachment
*make(Module
*module,
45 const CSSM_VERSION
&version
,
47 CSSM_SERVICE_TYPE subserviceType
,
48 const CSSM_API_MEMORY_FUNCS
&memoryOps
,
49 CSSM_ATTACH_FLAGS attachFlags
,
50 CSSM_KEY_HIERARCHY keyHierarchy
,
51 CSSM_FUNC_NAME_ADDR
*FunctionTable
,
54 StandardAttachment
<type
, Table
> *attachment
=
55 new StandardAttachment
<type
, Table
>(module,
63 attachment
->resolveSymbols(FunctionTable
, NumFunctions
);
68 typedef StandardAttachment
<type
, Table
>::NameMap NameMap
;
74 // The constructor of the StandardAttachmentMaker builds a dictionary
75 // derived from the plugin type's function name tables.
77 template <CSSM_SERVICE_TYPE type
, typename Table
, const char *nameTable
[]>
78 StandardAttachmentMaker
<type
, Table
, nameTable
>::StandardAttachmentMaker()
79 : AttachmentMaker(type
)
81 for (unsigned n
= 0; n
< sizeof(nameTable
) / sizeof(nameTable
[0]); n
++)
82 nameMap
.insert(NameMap::value_type(nameTable
[n
], n
));
86 // Implementation of an attachment factory
88 AttachmentFactory::AttachmentFactory()
90 // generate explicitly known attachment types
91 factories
[CSSM_SERVICE_AC
] = new StandardAttachmentMaker
<CSSM_SERVICE_AC
, CSSM_SPI_AC_FUNCS
, ACNameTable
>;
92 factories
[CSSM_SERVICE_CL
] = new StandardAttachmentMaker
<CSSM_SERVICE_CL
, CSSM_SPI_CL_FUNCS
, CLNameTable
>;
93 factories
[CSSM_SERVICE_CSP
] = new StandardAttachmentMaker
<CSSM_SERVICE_CSP
, CSSM_SPI_CSP_FUNCS
, CSPNameTable
>;
94 factories
[CSSM_SERVICE_DL
] = new StandardAttachmentMaker
<CSSM_SERVICE_DL
, CSSM_SPI_DL_FUNCS
, DLNameTable
>;
95 factories
[CSSM_SERVICE_TP
] = new StandardAttachmentMaker
<CSSM_SERVICE_TP
, CSSM_SPI_TP_FUNCS
, TPNameTable
>;
99 AttachmentMaker
*AttachmentFactory::attachmentMakerFor(CSSM_SERVICE_TYPE type
) const
101 AttachFactories::const_iterator it
= factories
.find(type
);
102 if (it
== factories
.end())
103 CssmError::throwMe(CSSMERR_CSSM_INVALID_SERVICE_MASK
);
109 // Manage an AttachmentMaker
111 AttachmentMaker::~AttachmentMaker()