# HG changeset patch # User Jens Alfke # Date 1248126649 25200 # Node ID dd637bdd214e6fa8f66a1a9b76c97e37499bf987 # Parent 46c7844cb59233501ee42306dcd0ecf87e3f674c DNS NULL record support in MYBonjourRegistration. Minor fix to IPAddress init. Force 4-char indent in source files. diff -r 46c7844cb592 -r dd637bdd214e Bonjour/MYBonjourRegistration.h --- a/Bonjour/MYBonjourRegistration.h Mon Jul 20 13:26:29 2009 -0700 +++ b/Bonjour/MYBonjourRegistration.h Mon Jul 20 14:50:49 2009 -0700 @@ -18,6 +18,8 @@ BOOL _autoRename; BOOL _registered; NSMutableDictionary *_txtRecord; + NSData *_nullRecord; + struct _DNSRecordRef_t *_nullRecordReg; } /** Initializes a new registration. @@ -82,6 +84,11 @@ This is used when signing (and verifying signatures of) TXT records. */ + (NSData*) canonicalFormOfTXTRecordDictionary: (NSDictionary*)txtDict; +/** A DNS 'NULL' record that can be used to publish other metadata about the service. + For example, iChat uses this to store the user's buddy icon. + As with all DNS records, try not to exceed 1500 bytes in size. */ +@property (copy) NSData *nullRecord; + //@} @end diff -r 46c7844cb592 -r dd637bdd214e Bonjour/MYBonjourRegistration.m --- a/Bonjour/MYBonjourRegistration.m Mon Jul 20 13:26:29 2009 -0700 +++ b/Bonjour/MYBonjourRegistration.m Mon Jul 20 14:50:49 2009 -0700 @@ -19,6 +19,7 @@ @interface MYBonjourRegistration () @property BOOL registered; +- (void) _updateNullRecord; @end @@ -125,7 +126,8 @@ NSData *txtData = nil; if (_txtRecord) txtData = [NSNetService dataFromTXTRecordDictionary: _txtRecord]; - return DNSServiceRegister(sdRefPtr, + DNSServiceErrorType err; + err = DNSServiceRegister(sdRefPtr, flags, 0, _name.UTF8String, // _name is likely to be nil @@ -137,11 +139,20 @@ txtData.bytes, ®Callback, self); + if (!err && _nullRecord) + [self _updateNullRecord]; + return err; } - (void) cancel { + if (_nullRecordReg && self.serviceRef) { + DNSServiceRemoveRecord(self.serviceRef, _nullRecordReg, 0); + _nullRecordReg = NULL; + } + [super cancel]; + if (_registered) { [[self class] priv_removeRegistration: self]; self.registered = NO; @@ -269,6 +280,44 @@ } } + +- (NSData*) nullRecord { + return _nullRecord; +} + +- (void) setNullRecord: (NSData*)nullRecord { + if (ifSetObj(&_nullRecord, nullRecord)) + if (self.serviceRef) + [self _updateNullRecord]; +} + + +- (void) _updateNullRecord { + DNSServiceRef serviceRef = self.serviceRef; + Assert(serviceRef); + DNSServiceErrorType err = 0; + if (!_nullRecord) { + if (_nullRecordReg) { + err = DNSServiceRemoveRecord(serviceRef, _nullRecordReg, 0); + _nullRecordReg = NULL; + } + } else if (!_nullRecordReg) { + err = DNSServiceAddRecord(serviceRef, &_nullRecordReg, 0, + kDNSServiceType_NULL, + _nullRecord.length, _nullRecord.bytes, + 0); + } else { + err = DNSServiceUpdateRecord(serviceRef, _nullRecordReg, 0, + _nullRecord.length, _nullRecord.bytes, + 0); + } + if (err) + Warn(@"MYBonjourRegistration: Couldn't update NULL record, err=%i",err); + else + LogTo(DNS, @"MYBonjourRegistration: Set NULL record (%u bytes) %@", + _nullRecord.length, _nullRecord); +} + @end diff -r 46c7844cb592 -r dd637bdd214e IPAddress.m --- a/IPAddress.m Mon Jul 20 13:26:29 2009 -0700 +++ b/IPAddress.m Mon Jul 20 14:50:49 2009 -0700 @@ -99,6 +99,10 @@ - (id) initWithData: (NSData*)data { + if (!data) { + [self release]; + return nil; + } const struct sockaddr* addr = data.bytes; if (data.length < sizeof(struct sockaddr_in)) addr = nil; diff -r 46c7844cb592 -r dd637bdd214e MYNetwork.xcodeproj/project.pbxproj --- a/MYNetwork.xcodeproj/project.pbxproj Mon Jul 20 13:26:29 2009 -0700 +++ b/MYNetwork.xcodeproj/project.pbxproj Mon Jul 20 14:50:49 2009 -0700 @@ -169,15 +169,15 @@ 270461880DE49634003D9D3F /* CollectionUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CollectionUtils.h; sourceTree = ""; }; 270462C00DE4A639003D9D3F /* MYUtilities_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MYUtilities_Prefix.pch; sourceTree = ""; }; 270462C10DE4A64B003D9D3F /* MYUtilitiesTest_main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MYUtilitiesTest_main.m; sourceTree = ""; }; - 270462C30DE4A65B003D9D3F /* BLIP Overview.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = "BLIP Overview.txt"; path = "BLIP/BLIP Overview.txt"; sourceTree = ""; wrapsLines = 1; }; + 270462C30DE4A65B003D9D3F /* BLIP Overview.txt */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = text; name = "BLIP Overview.txt"; path = "BLIP/BLIP Overview.txt"; sourceTree = ""; wrapsLines = 1; }; 2706F1D80F9D3EF300292CCF /* SecurityInterface.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SecurityInterface.framework; path = System/Library/Frameworks/SecurityInterface.framework; sourceTree = SDKROOT; }; 27375DFA0FC9FB5C0033F8F5 /* TCPEndpoint+Certs.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "TCPEndpoint+Certs.m"; sourceTree = ""; }; - 273B45790FA681EE00276298 /* MYBonjourRegistration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MYBonjourRegistration.h; sourceTree = ""; }; - 273B457A0FA681EE00276298 /* MYBonjourRegistration.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MYBonjourRegistration.m; sourceTree = ""; }; + 273B45790FA681EE00276298 /* MYBonjourRegistration.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = MYBonjourRegistration.h; sourceTree = ""; }; + 273B457A0FA681EE00276298 /* MYBonjourRegistration.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = MYBonjourRegistration.m; sourceTree = ""; }; 274122DD0F9CDD1600F21842 /* MYUtilities_Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = MYUtilities_Debug.xcconfig; sourceTree = ""; }; 274122DE0F9CDD1600F21842 /* MYUtilities_Release.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = MYUtilities_Release.xcconfig; sourceTree = ""; }; 2777C9100F7602A7007F8D30 /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; }; - 277903830DE8C2DD00C6D295 /* maindocs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = maindocs.h; sourceTree = ""; wrapsLines = 1; }; + 277903830DE8C2DD00C6D295 /* maindocs.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = maindocs.h; sourceTree = ""; wrapsLines = 1; }; 277903D50DE8EE4800C6D295 /* BLIPEchoServer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BLIPEchoServer.h; sourceTree = ""; }; 277903D60DE8EE4800C6D295 /* BLIPEchoServer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BLIPEchoServer.m; sourceTree = ""; }; 277903D80DE8EFC900C6D295 /* BLIP.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BLIP.h; sourceTree = ""; }; @@ -189,24 +189,24 @@ 2779052D0DE9E5BC00C6D295 /* BLIPEchoServer */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = BLIPEchoServer; sourceTree = BUILT_PRODUCTS_DIR; }; 2780F20A0FA194BD00C0FB83 /* MYDNSService.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MYDNSService.h; path = PortMapper/MYDNSService.h; sourceTree = ""; }; 2780F20B0FA194BD00C0FB83 /* MYDNSService.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MYDNSService.m; path = PortMapper/MYDNSService.m; sourceTree = ""; }; - 2780F4360FA28F4400C0FB83 /* MYBonjourQuery.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MYBonjourQuery.h; sourceTree = ""; }; - 2780F4370FA28F4400C0FB83 /* MYBonjourQuery.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MYBonjourQuery.m; sourceTree = ""; }; + 2780F4360FA28F4400C0FB83 /* MYBonjourQuery.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = MYBonjourQuery.h; sourceTree = ""; }; + 2780F4370FA28F4400C0FB83 /* MYBonjourQuery.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = MYBonjourQuery.m; sourceTree = ""; }; 2780F49F0FA2C59000C0FB83 /* MYAddressLookup.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MYAddressLookup.h; path = Bonjour/MYAddressLookup.h; sourceTree = ""; }; 2780F4A00FA2C59000C0FB83 /* MYAddressLookup.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MYAddressLookup.m; path = Bonjour/MYAddressLookup.m; sourceTree = ""; }; 278C1A340F9F687800954AE1 /* PortMapperTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PortMapperTest.m; sourceTree = ""; }; 278C1A350F9F687800954AE1 /* MYPortMapper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MYPortMapper.h; sourceTree = ""; }; 278C1A360F9F687800954AE1 /* MYPortMapper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MYPortMapper.m; sourceTree = ""; }; - 278C1B9E0F9F92EA00954AE1 /* MYBonjourBrowser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MYBonjourBrowser.h; sourceTree = ""; }; - 278C1B9F0F9F92EA00954AE1 /* MYBonjourBrowser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MYBonjourBrowser.m; sourceTree = ""; }; - 278C1BA00F9F92EA00954AE1 /* MYBonjourService.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MYBonjourService.h; sourceTree = ""; }; - 278C1BA10F9F92EA00954AE1 /* MYBonjourService.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MYBonjourService.m; sourceTree = ""; }; + 278C1B9E0F9F92EA00954AE1 /* MYBonjourBrowser.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = MYBonjourBrowser.h; sourceTree = ""; }; + 278C1B9F0F9F92EA00954AE1 /* MYBonjourBrowser.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = MYBonjourBrowser.m; sourceTree = ""; }; + 278C1BA00F9F92EA00954AE1 /* MYBonjourService.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = MYBonjourService.h; sourceTree = ""; }; + 278C1BA10F9F92EA00954AE1 /* MYBonjourService.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = MYBonjourService.m; sourceTree = ""; }; 278C1BB50F9F975700954AE1 /* ConcurrentOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ConcurrentOperation.h; sourceTree = ""; }; 278C1BB60F9F975700954AE1 /* ConcurrentOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ConcurrentOperation.m; sourceTree = ""; }; 279DD99E0F9E290500D75D91 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 279DD9B10F9E296200D75D91 /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = usr/lib/libz.dylib; sourceTree = SDKROOT; }; 279DD9B30F9E296E00D75D91 /* CoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreServices.framework; path = System/Library/Frameworks/CoreServices.framework; sourceTree = SDKROOT; }; 279DDC9A0F9E2F2A00D75D91 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; }; - 279DDCCB0F9E381500D75D91 /* MYNetwork.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MYNetwork.h; sourceTree = ""; }; + 279DDCCB0F9E381500D75D91 /* MYNetwork.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = MYNetwork.h; sourceTree = ""; }; 279E8F9E0F9FDD0800608D8D /* libMYNetwork.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libMYNetwork.a; sourceTree = BUILT_PRODUCTS_DIR; }; 27D5EC050DE5FEDE00CD84FA /* BLIPRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BLIPRequest.h; sourceTree = ""; }; 27D5EC060DE5FEDE00CD84FA /* BLIPRequest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BLIPRequest.m; sourceTree = ""; }; @@ -308,6 +308,7 @@ 270461070DE49030003D9D3F /* TCP */, 270460F10DE49030003D9D3F /* BLIP */, ); + indentWidth = 4; name = MYNetwork; sourceTree = ""; }; @@ -331,6 +332,7 @@ 270461000DE49030003D9D3F /* BLIPWriter.m */, 270460F70DE49030003D9D3F /* BLIP_Internal.h */, ); + indentWidth = 4; path = BLIP; sourceTree = ""; }; @@ -350,6 +352,7 @@ 270461120DE49030003D9D3F /* TCPWriter.m */, 270461080DE49030003D9D3F /* TCP_Internal.h */, ); + indentWidth = 4; path = TCP; sourceTree = ""; }; @@ -374,6 +377,7 @@ 270461290DE49088003D9D3F /* Test.h */, 270461280DE49088003D9D3F /* Test.m */, ); + indentWidth = 4; name = MYUtilities; sourceTree = MYUtilities; }; @@ -388,6 +392,7 @@ 2779048A0DE9204300C6D295 /* BLIPEchoClient.xib */, 277904280DE91C7900C6D295 /* BLIP Echo Client-Info.plist */, ); + indentWidth = 4; name = Demo; path = BLIP/Demo; sourceTree = ""; @@ -402,6 +407,7 @@ 2780F49F0FA2C59000C0FB83 /* MYAddressLookup.h */, 2780F4A00FA2C59000C0FB83 /* MYAddressLookup.m */, ); + indentWidth = 4; name = Addressing; sourceTree = ""; }; @@ -412,6 +418,7 @@ 278C1A360F9F687800954AE1 /* MYPortMapper.m */, 278C1A340F9F687800954AE1 /* PortMapperTest.m */, ); + indentWidth = 4; path = PortMapper; sourceTree = ""; }; @@ -427,6 +434,7 @@ 273B45790FA681EE00276298 /* MYBonjourRegistration.h */, 273B457A0FA681EE00276298 /* MYBonjourRegistration.m */, ); + indentWidth = 4; path = Bonjour; sourceTree = ""; };