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>
31 #include <ext/hash_map>
32 using __gnu_cxx::hash_map
;
41 // Inherit from this (abstract) class to implement your plugin
47 virtual ~CssmPlugin();
49 void moduleLoad(const Guid
&cssmGuid
,
50 const Guid
&moduleGuid
,
51 const ModuleCallback
&callback
);
52 void moduleUnload(const Guid
&cssmGuid
,
53 const Guid
&moduleGuid
,
54 const ModuleCallback
&callback
);
56 void moduleAttach(CSSM_MODULE_HANDLE theHandle
,
58 const Guid
&moduleGuid
,
59 const Guid
&moduleManagerGuid
,
60 const Guid
&callerGuid
,
61 const CSSM_VERSION
&Version
,
63 CSSM_SERVICE_TYPE SubServiceType
,
64 CSSM_ATTACH_FLAGS AttachFlags
,
65 CSSM_KEY_HIERARCHY KeyHierarchy
,
66 const CSSM_UPCALLS
&Upcalls
,
67 CSSM_MODULE_FUNCS_PTR
&FuncTbl
);
68 void moduleDetach(CSSM_MODULE_HANDLE handle
);
70 const Guid
&myGuid() const { return mMyGuid
; }
72 void sendCallback(CSSM_MODULE_EVENT event
,
74 CSSM_SERVICE_TYPE serviceType
) const;
76 void sendInsertion(uint32 subId
, CSSM_SERVICE_TYPE serviceType
) const
77 { sendCallback(CSSM_NOTIFY_INSERT
, subId
, serviceType
); }
79 void sendRemoval(uint32 subId
, CSSM_SERVICE_TYPE serviceType
) const
80 { sendCallback(CSSM_NOTIFY_REMOVE
, subId
, serviceType
); }
82 void sendFault(uint32 subId
, CSSM_SERVICE_TYPE serviceType
) const
83 { sendCallback(CSSM_NOTIFY_FAULT
, subId
, serviceType
); }
86 // subclass-defined methods
88 virtual void unload();
90 // make a session object for your plugin
91 virtual PluginSession
*makeSession(CSSM_MODULE_HANDLE handle
,
92 const CSSM_VERSION
&version
,
94 CSSM_SERVICE_TYPE subserviceType
,
95 CSSM_ATTACH_FLAGS attachFlags
,
96 const CSSM_UPCALLS
&upcalls
) = 0;
99 // map of (CSSM) handles to attachment objects
101 public hash_map
<CSSM_MODULE_HANDLE
, PluginSession
*>,
104 static ModuleNexus
<SessionMap
> sessionMap
;
108 // the registered callback. We currently allow only one
109 ModuleCallback callback
;
113 static PluginSession
*find(CSSM_MODULE_HANDLE h
)
115 StLock
<Mutex
> _(sessionMap());
116 SessionMap::iterator it
= sessionMap().find(h
);
117 if (it
== sessionMap().end())
118 CssmError::throwMe(CSSMERR_CSSM_INVALID_ADDIN_HANDLE
);
123 template <class SessionClass
>
124 inline SessionClass
&findSession(CSSM_MODULE_HANDLE h
)
126 SessionClass
*session
= dynamic_cast<SessionClass
*>(CssmPlugin::find(h
));
128 CssmError::throwMe(CSSMERR_CSSM_INVALID_ADDIN_HANDLE
);
129 assert(session
->handle() == h
);
133 } // end namespace Security
135 #endif //_H_CSSMPLUGIN