2 * Copyright (c) 2000-2004 Apple Computer, Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
26 // attachfactory - industrial grade production of Attachment objects
29 #define _CPP_ATTACHFACTORY
31 #include "attachfactory.h"
33 #include "cspattachment.h"
34 #include <Security/cssmdli.h>
35 #include <Security/cssmcli.h>
36 #include <Security/cssmaci.h>
37 #include <Security/cssmtpi.h>
38 #include <derived_src/funcnames.gen>
43 // A template to generate AttachmentMakers for the standard plugin types.
45 template <CSSM_SERVICE_TYPE type
, typename Table
, const char *const nameTable
[]>
46 class StandardAttachmentMaker
: public AttachmentMaker
{
48 StandardAttachmentMaker() : AttachmentMaker(type
)
50 for (unsigned n
= 0; n
< sizeof(nameTable
) / sizeof(nameTable
[0]); n
++)
51 nameMap
.insert(typename
NameMap::value_type(nameTable
[n
], n
));
54 Attachment
*make(Module
*module,
55 const CSSM_VERSION
&version
,
57 CSSM_SERVICE_TYPE subserviceType
,
58 const CSSM_API_MEMORY_FUNCS
&memoryOps
,
59 CSSM_ATTACH_FLAGS attachFlags
,
60 CSSM_KEY_HIERARCHY keyHierarchy
,
61 CSSM_FUNC_NAME_ADDR
*FunctionTable
,
64 StandardAttachment
<type
, Table
> *attachment
=
65 new StandardAttachment
<type
, Table
>(module,
73 attachment
->resolveSymbols(FunctionTable
, NumFunctions
);
78 typedef typename StandardAttachment
<type
, Table
>::NameMap NameMap
;
84 // Implementation of an attachment factory
86 AttachmentFactory::AttachmentFactory()
88 // generate explicitly known attachment types
89 factories
[CSSM_SERVICE_AC
] = new StandardAttachmentMaker
<CSSM_SERVICE_AC
, CSSM_SPI_AC_FUNCS
, ACNameTable
>;
90 factories
[CSSM_SERVICE_CL
] = new StandardAttachmentMaker
<CSSM_SERVICE_CL
, CSSM_SPI_CL_FUNCS
, CLNameTable
>;
91 factories
[CSSM_SERVICE_CSP
] = new StandardAttachmentMaker
<CSSM_SERVICE_CSP
, CSSM_SPI_CSP_FUNCS
, CSPNameTable
>;
92 factories
[CSSM_SERVICE_DL
] = new StandardAttachmentMaker
<CSSM_SERVICE_DL
, CSSM_SPI_DL_FUNCS
, DLNameTable
>;
93 factories
[CSSM_SERVICE_TP
] = new StandardAttachmentMaker
<CSSM_SERVICE_TP
, CSSM_SPI_TP_FUNCS
, TPNameTable
>;
97 AttachmentMaker
*AttachmentFactory::attachmentMakerFor(CSSM_SERVICE_TYPE type
) const
99 AttachFactories::const_iterator it
= factories
.find(type
);
100 if (it
== factories
.end())
101 CssmError::throwMe(CSSMERR_CSSM_INVALID_SERVICE_MASK
);
107 // Manage an AttachmentMaker
109 AttachmentMaker::~AttachmentMaker()