]> git.saurik.com Git - apple/security.git/blob - cdsa/cdsa_pluginlib/pluginsession.h
Security-54.1.tar.gz
[apple/security.git] / cdsa / cdsa_pluginlib / pluginsession.h
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/c++plugin.h>
26 #include <Security/handleobject.h>
27 #include <Security/cssmalloc.h>
28
29
30 #ifdef _CPP_PLUGINSESSION
31 # pragma export on
32 #endif
33
34 namespace Security
35 {
36
37 //
38 // A PluginSession object describes an ongoing connection between a particular
39 // CSSM client and our plugin. Every time CSSM_SPI_ModuleAttach is called
40 // (due to the client calling CSSM_ModuleAttach), a new PluginSession object
41 // is created as a result. Sessions and CSSM_MODULE_HANDLES correspond one-to-one.
42 //
43 // PluginSession is meant to be the parent class of your session object.
44 // This is where you store per-session information.
45 //
46 class PluginSession : public CssmAllocator, public HandledObject {
47 NOCOPY(PluginSession)
48 friend class CssmPlugin;
49 public:
50 PluginSession(CSSM_MODULE_HANDLE theHandle,
51 CssmPlugin &plug,
52 const CSSM_VERSION &Version,
53 uint32 SubserviceID,
54 CSSM_SERVICE_TYPE SubServiceType,
55 CSSM_ATTACH_FLAGS AttachFlags,
56 const CSSM_UPCALLS &upcalls);
57 virtual ~PluginSession();
58 virtual void detach();
59
60 CssmPlugin &plugin;
61
62 void sendCallback(CSSM_MODULE_EVENT event,
63 uint32 subId = uint32(-1),
64 CSSM_SERVICE_TYPE serviceType = 0) const;
65
66 static void unimplemented() { CssmError::throwMe(CSSM_ERRCODE_FUNCTION_NOT_IMPLEMENTED); }
67
68 protected:
69 virtual CSSM_MODULE_FUNCS_PTR construct() = 0;
70
71 public:
72 // implement CssmHeap::Allocator
73 void *malloc(size_t size) throw(std::bad_alloc);
74 void *realloc(void *addr, size_t size) throw(std::bad_alloc);
75 void free(void *addr) throw() { upcalls.free_func(handle(), addr); }
76
77 const CSSM_VERSION &version() const { return mVersion; }
78 uint32 subserviceId() const { return mSubserviceId; }
79 CSSM_SERVICE_TYPE subserviceType() const { return mSubserviceType; }
80 CSSM_ATTACH_FLAGS attachFlags() const { return mAttachFlags; }
81
82 private:
83 CSSM_VERSION mVersion;
84 uint32 mSubserviceId;
85 CSSM_SERVICE_TYPE mSubserviceType;
86 CSSM_ATTACH_FLAGS mAttachFlags;
87 const CSSM_UPCALLS &upcalls;
88 };
89
90 } // end namespace Security
91
92 #ifdef _CPP_PLUGINSESSION
93 # pragma export off
94 #endif
95
96 #endif //_H_PLUGINSESSION