]> git.saurik.com Git - apple/security.git/blob - Keychain/CCallbackMgr.h
972fd95523a20b9efeb4422eb5f3226be3e4c176
[apple/security.git] / Keychain / CCallbackMgr.h
1 /*
2 * Copyright (c) 1998-2002 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 * CCallbackMgr.h -- Code that communicates with processes that install a callback
21 * with the Keychain Manager to receive keychain events.
22 */
23 #ifndef _SECURITY_CCALLBACKMGR_H_
24 #define _SECURITY_CCALLBACKMGR_H_
25
26 #include <Security/KCEventObserver.h>
27 #include <Security/KCEventNotifier.h>
28 #include <Security/Keychains.h>
29 #include <list>
30
31 namespace Security
32 {
33
34 namespace KeychainCore
35 {
36
37 class CallbackInfo;
38 class CCallbackMgr;
39
40 class CallbackInfo
41 {
42 public:
43 ~CallbackInfo();
44 CallbackInfo();
45 CallbackInfo(SecKeychainCallback inCallbackFunction,SecKeychainEventMask inEventMask,void *inContext);
46
47 bool operator ==(const CallbackInfo& other) const;
48 bool operator !=(const CallbackInfo& other) const;
49
50 SecKeychainCallback mCallback;
51 SecKeychainEventMask mEventMask;
52 void *mContext;
53 };
54
55 // typedefs
56 typedef CallbackInfo *CallbackInfoPtr;
57 typedef CallbackInfo const *ConstCallbackInfoPtr;
58
59 typedef list<CallbackInfo>::iterator CallbackInfoListIterator;
60 typedef list<CallbackInfo>::const_iterator ConstCallbackInfoListIterator;
61
62
63 class CCallbackMgr : private Observer
64 {
65 public:
66
67 CCallbackMgr();
68 ~CCallbackMgr();
69
70 static CCallbackMgr& Instance();
71
72 static void AddCallback( SecKeychainCallback inCallbackFunction, SecKeychainEventMask inEventMask, void* inContext);
73 //static void AddCallbackUPP(KCCallbackUPP inCallbackFunction, KCEventMask inEventMask, void* inContext);
74
75 static void RemoveCallback( SecKeychainCallback inCallbackFunction );
76 //static void RemoveCallbackUPP(KCCallbackUPP inCallbackFunction);
77 static bool HasCallbacks()
78 { return CCallbackMgr::Instance().mEventCallbacks.size() > 0; };
79
80 private:
81
82 void Event (Listener::Domain domain, Listener::Event whichEvent, NameValueDictionary &dictionary);
83
84 static void AlertClients(const list<CallbackInfo> &eventCallbacks, SecKeychainEvent inEvent, pid_t inPid,
85 const Keychain& inKeychain, const Item &inItem);
86
87 list<CallbackInfo> mEventCallbacks;
88 static CCallbackMgr* mCCallbackMgr;
89 };
90
91 } // end namespace KeychainCore
92
93 } // end namespace Security
94
95 #endif // !_SECURITY_CCALLBACKMGR_H_