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/c++plugin.h>
26 #include <Security/globalizer.h>
27 #include <Security/callback.h>
35 // Inherit from this (abstract) class to implement your plugin
41 virtual ~CssmPlugin();
43 void moduleLoad(const Guid
&cssmGuid
,
44 const Guid
&moduleGuid
,
45 const ModuleCallback
&callback
);
46 void moduleUnload(const Guid
&cssmGuid
,
47 const Guid
&moduleGuid
,
48 const ModuleCallback
&callback
);
50 void moduleAttach(CSSM_MODULE_HANDLE theHandle
,
52 const Guid
&moduleGuid
,
53 const Guid
&moduleManagerGuid
,
54 const Guid
&callerGuid
,
55 const CSSM_VERSION
&Version
,
57 CSSM_SERVICE_TYPE SubServiceType
,
58 CSSM_ATTACH_FLAGS AttachFlags
,
59 CSSM_KEY_HIERARCHY KeyHierarchy
,
60 const CSSM_UPCALLS
&Upcalls
,
61 CSSM_MODULE_FUNCS_PTR
&FuncTbl
);
62 void moduleDetach(CSSM_MODULE_HANDLE handle
);
64 const Guid
&myGuid() const { return mMyGuid
; }
66 void sendCallback(CSSM_MODULE_EVENT event
,
68 CSSM_SERVICE_TYPE serviceType
) const;
70 void sendInsertion(uint32 subId
, CSSM_SERVICE_TYPE serviceType
) const
71 { sendCallback(CSSM_NOTIFY_INSERT
, subId
, serviceType
); }
73 void sendRemoval(uint32 subId
, CSSM_SERVICE_TYPE serviceType
) const
74 { sendCallback(CSSM_NOTIFY_REMOVE
, subId
, serviceType
); }
76 void sendFault(uint32 subId
, CSSM_SERVICE_TYPE serviceType
) const
77 { sendCallback(CSSM_NOTIFY_FAULT
, subId
, serviceType
); }
80 // subclass-defined methods
82 virtual void unload();
84 // make a session object for your plugin
85 virtual PluginSession
*makeSession(CSSM_MODULE_HANDLE handle
,
86 const CSSM_VERSION
&version
,
88 CSSM_SERVICE_TYPE subserviceType
,
89 CSSM_ATTACH_FLAGS attachFlags
,
90 const CSSM_UPCALLS
&upcalls
) = 0;
93 // map of (CSSM) handles to attachment objects
95 public hash_map
<CSSM_MODULE_HANDLE
, PluginSession
*>,
98 static ModuleNexus
<SessionMap
> sessionMap
;
102 // the registered callback. We currently allow only one
103 ModuleCallback callback
;
107 static PluginSession
*find(CSSM_MODULE_HANDLE h
)
109 StLock
<Mutex
> _(sessionMap());
110 SessionMap::iterator it
= sessionMap().find(h
);
111 if (it
== sessionMap().end())
112 CssmError::throwMe(CSSMERR_CSSM_INVALID_ADDIN_HANDLE
);
117 template <class SessionClass
>
118 inline SessionClass
&findSession(CSSM_MODULE_HANDLE h
)
120 SessionClass
*session
= dynamic_cast<SessionClass
*>(CssmPlugin::find(h
));
122 CssmError::throwMe(CSSMERR_CSSM_INVALID_ADDIN_HANDLE
);
123 assert(session
->handle() == h
);
127 } // end namespace Security
129 #endif //_H_CSSMPLUGIN