2 * Copyright (c) 2015 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
26 @header SOSChangeTracker.h - Manifest caching and change propagation.
29 #ifndef _SEC_SOSCHANGETRACKER_H_
30 #define _SEC_SOSCHANGETRACKER_H_
32 #include <Security/SecureObjectSync/SOSDataSource.h>
37 kSOSErrorNotConcreteError
= 1042,
42 // Interface to encoding and decoding changes
45 typedef CFTypeRef SOSChangeRef
;
47 static inline void SOSChangesAppendDelete(CFMutableArrayRef changes
, CFTypeRef object
) {
48 const void *values
[] = { object
};
49 SOSChangeRef change
= CFArrayCreate(kCFAllocatorDefault
, values
, array_size(values
), &kCFTypeArrayCallBacks
);
50 CFArrayAppendValue(changes
, change
);
51 CFReleaseSafe(change
);
54 static inline void SOSChangesAppendAdd(CFMutableArrayRef changes
, CFTypeRef object
) {
55 CFArrayAppendValue(changes
, object
);
58 // Return the object and return true if it's an add and false if it's a delete.
59 static inline bool SOSChangeGetObject(SOSChangeRef change
, CFTypeRef
*object
) {
60 if (CFGetTypeID(change
) == CFArrayGetTypeID()) {
61 assert(CFArrayGetCount(change
) == 1);
62 *object
= CFArrayGetValueAtIndex(change
, 0);
70 CFDataRef
SOSChangeCopyDigest(SOSDataSourceRef dataSource
, SOSChangeRef change
, bool *isDel
, SOSObjectRef
*object
, CFErrorRef
*error
);
72 CFStringRef
SOSChangeCopyDescription(SOSChangeRef change
);
74 CFStringRef
SOSChangesCopyDescription(CFArrayRef changes
);
80 typedef struct __OpaqueSOSChangeTracker
*SOSChangeTrackerRef
;
82 SOSChangeTrackerRef
SOSChangeTrackerCreate(CFAllocatorRef allocator
, bool isConcrete
, CFArrayRef children
, CFErrorRef
*error
);
84 // Change the concreteness of the current ct (a non concrete ct does not support SOSChangeTrackerCopyManifest().
85 void SOSChangeTrackerSetConcrete(SOSChangeTrackerRef ct
, bool isConcrete
);
87 typedef bool(^SOSChangeTrackerUpdatesChanges
)(SOSChangeTrackerRef ct
, SOSEngineRef engine
, SOSTransactionRef txn
, SOSDataSourceTransactionSource source
, SOSDataSourceTransactionPhase phase
, CFArrayRef changes
, CFErrorRef
*error
);
89 void SOSChangeTrackerRegisterChangeUpdate(SOSChangeTrackerRef ct
, SOSChangeTrackerUpdatesChanges child
);
91 typedef bool(^SOSChangeTrackerUpdatesManifests
)(SOSChangeTrackerRef ct
, SOSEngineRef engine
, SOSTransactionRef txn
, SOSDataSourceTransactionSource source
, SOSDataSourceTransactionPhase phase
, SOSManifestRef removals
, SOSManifestRef additions
, CFErrorRef
*error
);
93 void SOSChangeTrackerRegisterManifestUpdate(SOSChangeTrackerRef ct
, SOSChangeTrackerUpdatesManifests child
);
95 // Remove any blocks registered though either SOSChangeTrackerRegisterChangeUpdate or SOSChangeTrackerRegisterManifestUpdate
96 void SOSChangeTrackerResetRegistration(SOSChangeTrackerRef ct
);
98 // Set the manifest for this changeTracker, causing it to be updated whenever changes pass by.
99 // Set the manifest to NULL to stop tracking changes (but not forwarding to children).
100 void SOSChangeTrackerSetManifest(SOSChangeTrackerRef ct
, SOSManifestRef manifest
);
102 // Return a snapshot of the current manifest of this ct.
103 SOSManifestRef
SOSChangeTrackerCopyManifest(SOSChangeTrackerRef ct
, CFErrorRef
*error
);
105 // Apply changes to the (cached) manifest, and notify all children accordingly
106 bool SOSChangeTrackerTrackChanges(SOSChangeTrackerRef ct
, SOSEngineRef engine
, SOSTransactionRef txn
, SOSDataSourceTransactionSource source
, SOSDataSourceTransactionPhase phase
, CFArrayRef changes
, CFErrorRef
*error
);
110 #endif /* !_SEC_SOSCHANGETRACKER_H_ */