]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_keychain/lib/CCallbackMgr.h
Security-57337.50.23.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);
55
56 bool operator ==(const CallbackInfo& other) const;
57 bool operator !=(const CallbackInfo& other) const;
58
59 SecKeychainCallback mCallback;
60 SecKeychainEventMask mEventMask;
61 void *mContext;
62 };
63
64 // typedefs
65 typedef CallbackInfo *CallbackInfoPtr;
66 typedef CallbackInfo const *ConstCallbackInfoPtr;
67
68 typedef list<CallbackInfo>::iterator CallbackInfoListIterator;
69 typedef list<CallbackInfo>::const_iterator ConstCallbackInfoListIterator;
70
71
72 class CCallbackMgr : public SecurityServer::EventListener
73 {
74 public:
75 CCallbackMgr();
76 ~CCallbackMgr();
77
78 static CCallbackMgr& Instance();
79
80 static void AddCallback( SecKeychainCallback inCallbackFunction, SecKeychainEventMask inEventMask, void* inContext);
81
82 static void RemoveCallback( SecKeychainCallback inCallbackFunction );
83 //static void RemoveCallbackUPP(KCCallbackUPP inCallbackFunction);
84 static bool HasCallbacks()
85 { return CCallbackMgr::Instance().mEventCallbacks.size() > 0; };
86
87 private:
88
89 void consume (SecurityServer::NotificationDomain domain, SecurityServer::NotificationEvent whichEvent,
90 const CssmData &data);
91
92 static void AlertClients(const list<CallbackInfo> &eventCallbacks, SecKeychainEvent inEvent, pid_t inPid,
93 const Keychain& inKeychain, const Item &inItem);
94
95 list<CallbackInfo> mEventCallbacks;
96 };
97
98 } // end namespace KeychainCore
99
100 } // end namespace Security
101
102 #endif // !_SECURITY_CCALLBACKMGR_H_