]> git.saurik.com Git - apple/security.git/blob - Keychain/CCallbackMgr.h
Security-30.1.tar.gz
[apple/security.git] / Keychain / CCallbackMgr.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 File: CCallbackMgr.h
21
22 Contains: Code that communicates with processes that install a callback
23 with the Keychain Manager to receive keychain events.
24
25 Written by: Sari Harrison, Craig Mortensen
26
27 Copyright: © 1998-2000 by Apple Computer, Inc., all rights reserved.
28
29 Change History (most recent first):
30
31 To Do:
32 */
33
34 #ifndef __CCALLBACKMGR__
35 #define __CCALLBACKMGR__
36
37 #include <Security/SecKeychainAPI.h>
38 #include <Security/KCEventObserver.h>
39 #include <Security/KCEventNotifier.h>
40 #include <Security/Keychains.h>
41 #include <list>
42
43 namespace Security
44 {
45
46 namespace KeychainCore
47 {
48
49 class CallbackInfo;
50 class CCallbackMgr;
51
52 class CallbackInfo
53 {
54 public:
55 ~CallbackInfo();
56 CallbackInfo();
57 CallbackInfo(SecKeychainCallbackProcPtr inCallbackFunction,SecKeychainEventMask inEventMask,void *inContext);
58
59 bool operator ==(const CallbackInfo& other) const;
60 bool operator !=(const CallbackInfo& other) const;
61
62 SecKeychainCallbackProcPtr mCallback;
63 SecKeychainEventMask mEventMask;
64 void *mContext;
65 };
66
67 // typedefs
68 typedef CallbackInfo *CallbackInfoPtr;
69 typedef CallbackInfo const *ConstCallbackInfoPtr;
70
71 typedef list<CallbackInfo>::iterator CallbackInfoListIterator;
72 typedef list<CallbackInfo>::const_iterator ConstCallbackInfoListIterator;
73
74 #ifdef _CPP_CCALLBACKMGR
75 # pragma export on
76 #endif
77
78
79 class CCallbackMgr : Observer
80 {
81 public:
82
83 CCallbackMgr();
84 ~CCallbackMgr();
85
86 static CCallbackMgr& Instance();
87
88 static void AddCallback( SecKeychainCallbackProcPtr inCallbackFunction, SecKeychainEventMask inEventMask, void* inContext);
89 //static void AddCallbackUPP(KCCallbackUPP inCallbackFunction, KCEventMask inEventMask, void* inContext);
90
91 static void RemoveCallback( SecKeychainCallbackProcPtr inCallbackFunction );
92 //static void RemoveCallbackUPP(KCCallbackUPP inCallbackFunction);
93 static bool HasCallbacks() { return CCallbackMgr::Instance().mEventCallbacks.size() > 0; };
94 static bool ThisProcessUsesSystemEvtCallback();
95 static bool ThisProcessCanDisplayUI();
96
97 static void AlertClients( SecKeychainEvent inEvent, bool inOKToAllocateMemory);
98 #if 0
99 static void Idle();
100 #endif
101
102 private:
103
104 virtual void Event ( CFNotificationCenterRef center,
105 CFStringRef name,
106 const void* object,
107 CFDictionaryRef userInfo );
108
109 static void AlertClients( SecKeychainEvent inEvent, const Keychain& inKeychain,
110 const Item &inItem, bool inOKToAllocateMemory = true);
111
112 list<CallbackInfo> mEventCallbacks;
113 static CCallbackMgr* mCCallbackMgr;
114 };
115
116 } // end namespace KeychainCore
117
118 } // end namespace Security
119
120 #endif // __CCALLBACKMGR__