2 #include <CoreFoundation/CoreFoundation.h>
3 #include <Security/SecureObjectSync/SOSTransportCircle.h>
4 #include <Security/SecureObjectSync/SOSTransportCircleKVS.h>
5 #include <Security/SecureObjectSync/SOSTransport.h>
6 #include <Security/SecureObjectSync/SOSKVSKeys.h>
7 #include <Security/SecureObjectSync/SOSAccount.h>
8 #include <Security/SecureObjectSync/SOSAccountPriv.h>
9 #include <SOSPeerInfoDER.h>
11 #include <utilities/SecCFWrappers.h>
12 #include <SOSInternal.h>
13 #include <SOSCloudKeychainClient.h>
14 #include <AssertMacros.h>
16 CFGiblisWithCompareFor(SOSTransportCircle
);
18 SOSTransportCircleRef
SOSTransportCircleCreateForSubclass(size_t size
, SOSAccountRef account
, CFErrorRef
*error
)
20 SOSTransportCircleRef tpt
= CFTypeAllocateWithSpace(SOSTransportCircle
, size
, kCFAllocatorDefault
);
21 tpt
->account
= CFRetainSafe(account
);
25 static CFStringRef
SOSTransportCircleCopyFormatDescription(CFTypeRef aObj
, CFDictionaryRef formatOptions
) {
26 SOSTransportCircleRef t
= (SOSTransportCircleRef
) aObj
;
28 return CFStringCreateWithFormat(NULL
, NULL
, CFSTR("<SOSTransportCircle@%p\n>"), t
);
31 static void SOSTransportCircleDestroy(CFTypeRef aObj
) {
32 SOSTransportCircleRef transport
= (SOSTransportCircleRef
) aObj
;
33 if(transport
->destroy
)
34 transport
->destroy(transport
);
35 CFReleaseNull(transport
->account
);
38 static CFHashCode
SOSTransportCircleHash(CFTypeRef obj
)
40 return (intptr_t) obj
;
43 static Boolean
SOSTransportCircleCompare(CFTypeRef lhs
, CFTypeRef rhs
)
45 return SOSTransportCircleHash(lhs
) == SOSTransportCircleHash(rhs
);
48 SOSAccountRef
SOSTransportCircleGetAccount(SOSTransportCircleRef transport
){
49 return transport
->account
;
52 bool SOSTransportCircleFlushChanges(SOSTransportCircleRef transport
, CFErrorRef
*error
) {
53 return transport
->flushChanges(transport
, error
);
56 bool SOSTransportCirclePostCircle(SOSTransportCircleRef transport
, CFStringRef circleName
, CFDataRef circle_data
, CFErrorRef
*error
) {
57 return transport
->postCircle(transport
, circleName
, circle_data
, error
);
60 CFDictionaryRef
SOSTransportCircleHandleRetirementMessages(SOSTransportCircleRef transport
, CFMutableDictionaryRef circle_retirement_messages_table
, CFErrorRef
*error
) {
61 return transport
->handleRetirementMessages(transport
, circle_retirement_messages_table
, error
);
65 CFArrayRef
SOSTransportCircleHandleCircleMessages(SOSTransportCircleRef transport
, CFMutableDictionaryRef circle_circle_messages_table
, CFErrorRef
*error
) {
66 return transport
->handleCircleMessages(transport
, circle_circle_messages_table
, error
);
69 bool SOSTransportCirclePostRetirement(SOSTransportCircleRef transport
, CFStringRef circleName
, SOSPeerInfoRef peer
, CFErrorRef
*error
) {
71 CFDataRef retirement_data
= NULL
;
73 retirement_data
= SOSPeerInfoCopyEncodedData(peer
, kCFAllocatorDefault
, error
);
75 require_quiet(retirement_data
, fail
);
77 success
= transport
->postRetirement(transport
, circleName
, SOSPeerInfoGetPeerID(peer
), retirement_data
, error
);
80 CFReleaseNull(retirement_data
);
84 bool SOSTransportCircleExpireRetirementRecords(SOSTransportCircleRef transport
, CFDictionaryRef retirements
, CFErrorRef
*error
){
85 return transport
->expireRetirementRecords(transport
, retirements
, error
);
88 CFIndex
SOSTransportCircleGetTransportType(SOSTransportCircleRef transport
, CFErrorRef
*error
){
89 return transport
->getTransportType
? transport
->getTransportType(transport
, error
) : kUnknown
;
92 bool SOSTransportCircleSendPeerInfo(SOSTransportCircleRef transport
, CFStringRef peerID
, CFDataRef peerInfoData
, CFErrorRef
*error
){
93 return transport
->sendPeerInfo(transport
, peerID
, peerInfoData
, error
);
96 bool SOSTransportCircleRingFlushChanges(SOSTransportCircleRef transport
, CFErrorRef
* error
){
97 return transport
->flushRingChanges(transport
, error
);
100 bool SOSTransportCircleRingPostRing(SOSTransportCircleRef transport
, CFStringRef ringName
, CFDataRef ring
, CFErrorRef
*error
){
101 return transport
->postRing(transport
, ringName
, ring
, error
);
104 bool SOSTransportCircleSendDebugInfo(SOSTransportCircleRef transport
, CFStringRef type
, CFTypeRef debugInfo
, CFErrorRef
*error
){
105 return transport
->sendDebugInfo(transport
, type
, debugInfo
, error
);
108 bool SOSTransportCircleSendAccountChangedWithDSID(SOSTransportCircleRef transport
, CFStringRef dsid
, CFErrorRef
*error
){
109 return transport
->sendAccountChangedWithDSID(transport
, dsid
, error
);