2 * Copyright (c) 2000-2001,2011,2014 Apple 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 <unordered_map>
36 // Inherit from this (abstract) class to implement your plugin
42 virtual ~CssmPlugin();
44 void moduleLoad(const Guid
&cssmGuid
,
45 const Guid
&moduleGuid
,
46 const ModuleCallback
&callback
);
47 void moduleUnload(const Guid
&cssmGuid
,
48 const Guid
&moduleGuid
,
49 const ModuleCallback
&callback
);
51 void moduleAttach(CSSM_MODULE_HANDLE theHandle
,
53 const Guid
&moduleGuid
,
54 const Guid
&moduleManagerGuid
,
55 const Guid
&callerGuid
,
56 const CSSM_VERSION
&Version
,
58 CSSM_SERVICE_TYPE SubServiceType
,
59 CSSM_ATTACH_FLAGS AttachFlags
,
60 CSSM_KEY_HIERARCHY KeyHierarchy
,
61 const CSSM_UPCALLS
&Upcalls
,
62 CSSM_MODULE_FUNCS_PTR
&FuncTbl
);
63 void moduleDetach(CSSM_MODULE_HANDLE handle
);
65 const Guid
&myGuid() const { return mMyGuid
; }
67 void sendCallback(CSSM_MODULE_EVENT event
,
69 CSSM_SERVICE_TYPE serviceType
) const;
71 void sendInsertion(uint32 subId
, CSSM_SERVICE_TYPE serviceType
) const
72 { sendCallback(CSSM_NOTIFY_INSERT
, subId
, serviceType
); }
74 void sendRemoval(uint32 subId
, CSSM_SERVICE_TYPE serviceType
) const
75 { sendCallback(CSSM_NOTIFY_REMOVE
, subId
, serviceType
); }
77 void sendFault(uint32 subId
, CSSM_SERVICE_TYPE serviceType
) const
78 { sendCallback(CSSM_NOTIFY_FAULT
, subId
, serviceType
); }
81 // subclass-defined methods
83 virtual void unload();
85 // make a session object for your plugin
86 virtual PluginSession
*makeSession(CSSM_MODULE_HANDLE handle
,
87 const CSSM_VERSION
&version
,
89 CSSM_SERVICE_TYPE subserviceType
,
90 CSSM_ATTACH_FLAGS attachFlags
,
91 const CSSM_UPCALLS
&upcalls
) = 0;
94 // map of (CSSM) handles to attachment objects
96 public std::unordered_map
<CSSM_MODULE_HANDLE
, PluginSession
*>,
99 static ModuleNexus
<SessionMap
> sessionMap
;
103 // the registered callback. Set during load processing, unset during unload
104 ModuleCallback mCallback
;
108 static PluginSession
*find(CSSM_MODULE_HANDLE h
)
110 StLock
<Mutex
> _(sessionMap());
111 SessionMap::iterator it
= sessionMap().find(h
);
112 if (it
== sessionMap().end())
113 CssmError::throwMe(CSSMERR_CSSM_INVALID_ADDIN_HANDLE
);
118 template <class SessionClass
>
119 inline SessionClass
&findSession(CSSM_MODULE_HANDLE h
)
121 SessionClass
*session
= dynamic_cast<SessionClass
*>(CssmPlugin::find(h
));
123 CssmError::throwMe(CSSMERR_CSSM_INVALID_ADDIN_HANDLE
);
124 assert(session
->handle() == h
);
128 } // end namespace Security
130 #endif //_H_CSSMPLUGIN