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 // cssmplugin - common header for CSSM plugin modules
25 #include <security_cdsa_plugin/c++plugin.h>
26 #include <security_utilities/globalizer.h>
27 #include <security_cdsa_utilities/callback.h>
30 #include <ext/hash_map>
31 using __gnu_cxx::hash_map
;
38 // Inherit from this (abstract) class to implement your plugin
44 virtual ~CssmPlugin();
46 void moduleLoad(const Guid
&cssmGuid
,
47 const Guid
&moduleGuid
,
48 const ModuleCallback
&callback
);
49 void moduleUnload(const Guid
&cssmGuid
,
50 const Guid
&moduleGuid
,
51 const ModuleCallback
&callback
);
53 void moduleAttach(CSSM_MODULE_HANDLE theHandle
,
55 const Guid
&moduleGuid
,
56 const Guid
&moduleManagerGuid
,
57 const Guid
&callerGuid
,
58 const CSSM_VERSION
&Version
,
60 CSSM_SERVICE_TYPE SubServiceType
,
61 CSSM_ATTACH_FLAGS AttachFlags
,
62 CSSM_KEY_HIERARCHY KeyHierarchy
,
63 const CSSM_UPCALLS
&Upcalls
,
64 CSSM_MODULE_FUNCS_PTR
&FuncTbl
);
65 void moduleDetach(CSSM_MODULE_HANDLE handle
);
67 const Guid
&myGuid() const { return mMyGuid
; }
69 void sendCallback(CSSM_MODULE_EVENT event
,
71 CSSM_SERVICE_TYPE serviceType
) const;
73 void sendInsertion(uint32 subId
, CSSM_SERVICE_TYPE serviceType
) const
74 { sendCallback(CSSM_NOTIFY_INSERT
, subId
, serviceType
); }
76 void sendRemoval(uint32 subId
, CSSM_SERVICE_TYPE serviceType
) const
77 { sendCallback(CSSM_NOTIFY_REMOVE
, subId
, serviceType
); }
79 void sendFault(uint32 subId
, CSSM_SERVICE_TYPE serviceType
) const
80 { sendCallback(CSSM_NOTIFY_FAULT
, subId
, serviceType
); }
83 // subclass-defined methods
85 virtual void unload();
87 // make a session object for your plugin
88 virtual PluginSession
*makeSession(CSSM_MODULE_HANDLE handle
,
89 const CSSM_VERSION
&version
,
91 CSSM_SERVICE_TYPE subserviceType
,
92 CSSM_ATTACH_FLAGS attachFlags
,
93 const CSSM_UPCALLS
&upcalls
) = 0;
96 // map of (CSSM) handles to attachment objects
98 public hash_map
<CSSM_MODULE_HANDLE
, PluginSession
*>,
101 static ModuleNexus
<SessionMap
> sessionMap
;
105 // the registered callback. Set during load processing, unset during unload
106 ModuleCallback mCallback
;
110 static PluginSession
*find(CSSM_MODULE_HANDLE h
)
112 StLock
<Mutex
> _(sessionMap());
113 SessionMap::iterator it
= sessionMap().find(h
);
114 if (it
== sessionMap().end())
115 CssmError::throwMe(CSSMERR_CSSM_INVALID_ADDIN_HANDLE
);
120 template <class SessionClass
>
121 inline SessionClass
&findSession(CSSM_MODULE_HANDLE h
)
123 SessionClass
*session
= dynamic_cast<SessionClass
*>(CssmPlugin::find(h
));
125 CssmError::throwMe(CSSMERR_CSSM_INVALID_ADDIN_HANDLE
);
126 assert(session
->handle() == h
);
130 } // end namespace Security
132 #endif //_H_CSSMPLUGIN