1/* 2 * Copyright (c) 2000-2001 Apple Computer, 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#ifndef _H_PLUGINSESSION 23#define _H_PLUGINSESSION 24 25#include <security_cdsa_plugin/c++plugin.h> 26#include <security_cdsa_utilities/handleobject.h> 27#include <security_utilities/alloc.h> 28 29 30namespace Security { 31 32 33// 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. 39// 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. 43// 44class PluginSession : public Allocator, public HandledObject { 45 NOCOPY(PluginSession) 46 friend class CssmPlugin; 47public: 48 PluginSession(CSSM_MODULE_HANDLE theHandle, 49 CssmPlugin &myPlugin, 50 const CSSM_VERSION &Version, 51 uint32 SubserviceID, 52 CSSM_SERVICE_TYPE SubServiceType, 53 CSSM_ATTACH_FLAGS AttachFlags, 54 const CSSM_UPCALLS &upcalls); 55 virtual ~PluginSession(); 56 virtual void detach(); 57 58 CssmPlugin &plugin; 59 60 void sendCallback(CSSM_MODULE_EVENT event, 61 uint32 ssid = uint32(-1), 62 CSSM_SERVICE_TYPE serviceType = 0) const; 63 64 static void unimplemented() { CssmError::throwMe(CSSM_ERRCODE_FUNCTION_NOT_IMPLEMENTED); } 65 66protected: 67 virtual CSSM_MODULE_FUNCS_PTR construct() = 0; 68 69public: 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); } 74 75 // about ourselves 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; } 80 81private: 82 CSSM_VERSION mVersion; 83 uint32 mSubserviceId; 84 CSSM_SERVICE_TYPE mSubserviceType; 85 CSSM_ATTACH_FLAGS mAttachFlags; 86 const CSSM_UPCALLS &upcalls; 87}; 88 89} // end namespace Security 90 91 92#endif //_H_PLUGINSESSION 93