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 // pluginsession - an attachment session for a CSSM plugin
22 #ifndef _H_PLUGINSESSION
23 #define _H_PLUGINSESSION
25 #include <security_cdsa_plugin/c++plugin.h>
26 #include <security_cdsa_utilities/handleobject.h>
27 #include <security_utilities/alloc.h>
34 // A PluginSession object describes an ongoing connection between a particular
35 // CSSM client and our plugin. Every time CSSM_SPI_ModuleAttach is called
36 // (due to the client calling CSSM_ModuleAttach), a new PluginSession object
37 // is created as a result. Sessions and CSSM_MODULE_HANDLES correspond one-to-one.
38 // Note that CSSM makes up our module handle; we just record it.
40 // A PluginSession *is* an Allocator, whose implementation is to call the
41 // "application allocator" functions provided by CSSM's caller for the attachment.
42 // Use the session object as the Allocator for anything you return to your caller.
44 class PluginSession
: public Allocator
, public HandledObject
{
46 friend class CssmPlugin
;
48 PluginSession(CSSM_MODULE_HANDLE theHandle
,
50 const CSSM_VERSION
&Version
,
52 CSSM_SERVICE_TYPE SubServiceType
,
53 CSSM_ATTACH_FLAGS AttachFlags
,
54 const CSSM_UPCALLS
&upcalls
);
55 virtual ~PluginSession();
56 virtual void detach();
60 void sendCallback(CSSM_MODULE_EVENT event
,
61 uint32 ssid
= uint32(-1),
62 CSSM_SERVICE_TYPE serviceType
= 0) const;
64 static void unimplemented() { CssmError::throwMe(CSSM_ERRCODE_FUNCTION_NOT_IMPLEMENTED
); }
67 virtual CSSM_MODULE_FUNCS_PTR
construct() = 0;
70 // implement Allocator
71 void *malloc(size_t size
) throw(std::bad_alloc
);
72 void *realloc(void *addr
, size_t size
) throw(std::bad_alloc
);
73 void free(void *addr
) throw() { upcalls
.free_func(handle(), addr
); }
76 const CSSM_VERSION
&version() const { return mVersion
; }
77 uint32
subserviceId() const { return mSubserviceId
; }
78 CSSM_SERVICE_TYPE
subserviceType() const { return mSubserviceType
; }
79 CSSM_ATTACH_FLAGS
attachFlags() const { return mAttachFlags
; }
82 CSSM_VERSION mVersion
;
84 CSSM_SERVICE_TYPE mSubserviceType
;
85 CSSM_ATTACH_FLAGS mAttachFlags
;
86 const CSSM_UPCALLS
&upcalls
;
89 } // end namespace Security
92 #endif //_H_PLUGINSESSION