]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_keychain/lib/CCallbackMgr.h
Security-59306.101.1.tar.gz
[apple/security.git] / OSX / libsecurity_keychain / lib / CCallbackMgr.h
1 /*
2 * Copyright (c) 1998-2004,2011,2014 Apple Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24
25 /*
26 * CCallbackMgr.h -- Code that communicates with processes that install a callback
27 * with the Keychain Manager to receive keychain events.
28 */
29 #ifndef _SECURITY_CCALLBACKMGR_H_
30 #define _SECURITY_CCALLBACKMGR_H_
31
32 #include <security_keychain/Keychains.h>
33 #include <security_utilities/cfmach++.h>
34 #include <securityd_client/ssnotify.h>
35 #include <securityd_client/dictionary.h>
36 #include <securityd_client/eventlistener.h>
37 #include <list>
38 #include "KCEventNotifier.h"
39
40 namespace Security
41 {
42
43 namespace KeychainCore
44 {
45
46 class CallbackInfo;
47 class CCallbackMgr;
48
49 class CallbackInfo
50 {
51 public:
52 ~CallbackInfo();
53 CallbackInfo();
54 CallbackInfo(SecKeychainCallback inCallbackFunction,SecKeychainEventMask inEventMask,void *inContext, CFRunLoopRef runLoop);
55 CallbackInfo(const CallbackInfo& cb);
56
57 bool operator ==(const CallbackInfo& other) const;
58 bool operator !=(const CallbackInfo& other) const;
59
60 SecKeychainCallback mCallback;
61 SecKeychainEventMask mEventMask;
62 void *mContext;
63 CFRunLoopRef mRunLoop;
64 bool mActive;
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
75 class CCallbackMgr : public SecurityServer::EventListener
76 {
77 public:
78 CCallbackMgr();
79 ~CCallbackMgr();
80
81 static CCallbackMgr& Instance();
82
83 static void AddCallback( SecKeychainCallback inCallbackFunction, SecKeychainEventMask inEventMask, void* inContext);
84
85 static void RemoveCallback( SecKeychainCallback inCallbackFunction );
86 //static void RemoveCallbackUPP(KCCallbackUPP inCallbackFunction);
87 static bool HasCallbacks()
88 { return CCallbackMgr::Instance().mEventCallbacks.size() > 0; };
89
90 private:
91
92 void consume (SecurityServer::NotificationDomain domain, SecurityServer::NotificationEvent whichEvent,
93 const CssmData &data);
94
95 void AlertClients(const list<CallbackInfo> &eventCallbacks, SecKeychainEvent inEvent, pid_t inPid,
96 const Keychain& inKeychain, const Item &inItem);
97
98 // Use these as a CFRunLoop callback
99 static void tellClient(CFRunLoopTimerRef timer, void* ctx);
100 static void cfrunLoopActive(CFRunLoopTimerRef timer, void* info);
101
102 bool initialized() { return mInitialized; }
103
104 list<CallbackInfo> mEventCallbacks;
105 };
106
107 } // end namespace KeychainCore
108
109 } // end namespace Security
110
111 #endif // !_SECURITY_CCALLBACKMGR_H_