]> git.saurik.com Git - apple/security.git/blob - Security/libsecurity_cdsa_plugin/lib/pluginsession.cpp
Security-57031.40.6.tar.gz
[apple/security.git] / Security / libsecurity_cdsa_plugin / lib / pluginsession.cpp
1 /*
2 * Copyright (c) 2000-2001,2011,2014 Apple Inc. All Rights Reserved.
3 *
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
8 * using this file.
9 *
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.
16 */
17
18
19 //
20 // pluginsession - an attachment session for a CSSM plugin
21 //
22 #include <security_cdsa_plugin/pluginsession.h>
23 #include <security_cdsa_plugin/cssmplugin.h>
24 #include <security_cdsa_plugin/DLsession.h>
25
26
27 //
28 // Construct a PluginSession
29 //
30 PluginSession::PluginSession(CSSM_MODULE_HANDLE theHandle,
31 CssmPlugin &myPlugin,
32 const CSSM_VERSION &version,
33 uint32 subserviceId,
34 CSSM_SERVICE_TYPE subserviceType,
35 CSSM_ATTACH_FLAGS attachFlags,
36 const CSSM_UPCALLS &inUpcalls)
37 : HandledObject(theHandle), plugin(myPlugin),
38 mVersion(version), mSubserviceId(subserviceId),
39 mSubserviceType(subserviceType), mAttachFlags(attachFlags),
40 upcalls(inUpcalls)
41 {
42 }
43
44
45 //
46 // Destruction
47 //
48 PluginSession::~PluginSession()
49 {
50 }
51
52
53 //
54 // The default implementation of detach() does nothing
55 //
56 void PluginSession::detach()
57 {
58 }
59
60
61 //
62 // Allocation management
63 //
64 void *PluginSession::malloc(size_t size) throw(std::bad_alloc)
65 {
66 if (void *addr = upcalls.malloc_func(handle(), size))
67 return addr;
68 throw std::bad_alloc();
69 }
70
71 void *PluginSession::realloc(void *oldAddr, size_t size) throw(std::bad_alloc)
72 {
73 if (void *addr = upcalls.realloc_func(handle(), oldAddr, size))
74 return addr;
75 throw std::bad_alloc();
76 }
77
78
79 //
80 // Dispatch callback events through the plugin object.
81 // Subsystem ID and subservice type default to our own.
82 //
83
84 void PluginSession::sendCallback(CSSM_MODULE_EVENT event,
85 uint32 ssid,
86 CSSM_SERVICE_TYPE serviceType) const
87 {
88 plugin.sendCallback(event,
89 (ssid == uint32(-1)) ? mSubserviceId : ssid,
90 serviceType ? serviceType : mSubserviceType);
91 }