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 #include <security_cdsa_plugin/pluginsession.h> 
  23 #include <security_cdsa_plugin/cssmplugin.h> 
  24 #include <security_cdsa_plugin/DLsession.h> 
  28 // Construct a PluginSession 
  30 PluginSession::PluginSession(CSSM_MODULE_HANDLE theHandle
, 
  32                              const CSSM_VERSION 
&version
, 
  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
), 
  48 PluginSession::~PluginSession() 
  54 // The default implementation of detach() does nothing 
  56 void PluginSession::detach() 
  62 // Allocation management 
  64 void *PluginSession::malloc(size_t size
) 
  66     if (void *addr 
= upcalls
.malloc_func(handle(), size
)) { 
  69     throw std::bad_alloc(); 
  72 void *PluginSession::realloc(void *oldAddr
, size_t size
) 
  74     if (void *addr 
= upcalls
.realloc_func(handle(), oldAddr
, size
)) { 
  77     throw std::bad_alloc(); 
  82 // Dispatch callback events through the plugin object. 
  83 // Subsystem ID and subservice type default to our own. 
  86 void PluginSession::sendCallback(CSSM_MODULE_EVENT event
, 
  88                                  CSSM_SERVICE_TYPE serviceType
) const 
  90     plugin
.sendCallback(event
, 
  91                         (ssid 
== uint32(-1)) ? mSubserviceId 
: ssid
, 
  92                         serviceType 
? serviceType 
: mSubserviceType
);