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() : AttachmentMaker(type
) 
  44         for (unsigned n 
= 0; n 
< sizeof(nameTable
) / sizeof(nameTable
[0]); n
++) 
  45             nameMap
.insert(typename 
NameMap::value_type(nameTable
[n
], n
)); 
  48     Attachment 
*make(Module 
*module, 
  49                      const CSSM_VERSION 
&version
, 
  51                      CSSM_SERVICE_TYPE subserviceType
, 
  52                      const CSSM_API_MEMORY_FUNCS 
&memoryOps
, 
  53                      CSSM_ATTACH_FLAGS attachFlags
, 
  54                      CSSM_KEY_HIERARCHY keyHierarchy
, 
  55                      CSSM_FUNC_NAME_ADDR 
*FunctionTable
, 
  58         StandardAttachment
<type
, Table
> *attachment 
= 
  59         new StandardAttachment
<type
, Table
>(module, 
  67         attachment
->resolveSymbols(FunctionTable
, NumFunctions
); 
  72     typedef typename StandardAttachment
<type
, Table
>::NameMap NameMap
; 
  78 // Implementation of an attachment factory 
  80 AttachmentFactory::AttachmentFactory() 
  82     // generate explicitly known attachment types 
  83     factories
[CSSM_SERVICE_AC
] = new StandardAttachmentMaker
<CSSM_SERVICE_AC
, CSSM_SPI_AC_FUNCS
, ACNameTable
>; 
  84     factories
[CSSM_SERVICE_CL
] = new StandardAttachmentMaker
<CSSM_SERVICE_CL
, CSSM_SPI_CL_FUNCS
, CLNameTable
>; 
  85     factories
[CSSM_SERVICE_CSP
] = new StandardAttachmentMaker
<CSSM_SERVICE_CSP
, CSSM_SPI_CSP_FUNCS
, CSPNameTable
>; 
  86     factories
[CSSM_SERVICE_DL
] = new StandardAttachmentMaker
<CSSM_SERVICE_DL
, CSSM_SPI_DL_FUNCS
, DLNameTable
>; 
  87     factories
[CSSM_SERVICE_TP
] = new StandardAttachmentMaker
<CSSM_SERVICE_TP
, CSSM_SPI_TP_FUNCS
, TPNameTable
>; 
  91 AttachmentMaker 
*AttachmentFactory::attachmentMakerFor(CSSM_SERVICE_TYPE type
) const 
  93     AttachFactories::const_iterator it 
= factories
.find(type
); 
  94     if (it 
== factories
.end()) 
  95         CssmError::throwMe(CSSMERR_CSSM_INVALID_SERVICE_MASK
); 
 101 // Manage an AttachmentMaker 
 103 AttachmentMaker::~AttachmentMaker()