DNS NULL record support in MYBonjourRegistration. Minor fix to IPAddress init. Force 4-char indent in source files.
authorJens Alfke <jens@mooseyard.com>
Mon Jul 20 14:50:49 2009 -0700 (2009-07-20)
changeset 60dd637bdd214e
parent 59 46c7844cb592
child 61 981f9d604c88
DNS NULL record support in MYBonjourRegistration. Minor fix to IPAddress init. Force 4-char indent in source files.
Bonjour/MYBonjourRegistration.h
Bonjour/MYBonjourRegistration.m
IPAddress.m
MYNetwork.xcodeproj/project.pbxproj
     1.1 --- a/Bonjour/MYBonjourRegistration.h	Mon Jul 20 13:26:29 2009 -0700
     1.2 +++ b/Bonjour/MYBonjourRegistration.h	Mon Jul 20 14:50:49 2009 -0700
     1.3 @@ -18,6 +18,8 @@
     1.4      BOOL _autoRename;
     1.5      BOOL _registered;
     1.6      NSMutableDictionary *_txtRecord;
     1.7 +    NSData *_nullRecord;
     1.8 +    struct _DNSRecordRef_t *_nullRecordReg;
     1.9  }
    1.10  
    1.11  /** Initializes a new registration.
    1.12 @@ -82,6 +84,11 @@
    1.13      This is used when signing (and verifying signatures of) TXT records. */
    1.14  + (NSData*) canonicalFormOfTXTRecordDictionary: (NSDictionary*)txtDict;
    1.15  
    1.16 +/** A DNS 'NULL' record that can be used to publish other metadata about the service.
    1.17 +    For example, iChat uses this to store the user's buddy icon.
    1.18 +    As with all DNS records, try not to exceed 1500 bytes in size. */
    1.19 +@property (copy) NSData *nullRecord;
    1.20 +
    1.21  //@}
    1.22  
    1.23  @end
     2.1 --- a/Bonjour/MYBonjourRegistration.m	Mon Jul 20 13:26:29 2009 -0700
     2.2 +++ b/Bonjour/MYBonjourRegistration.m	Mon Jul 20 14:50:49 2009 -0700
     2.3 @@ -19,6 +19,7 @@
     2.4  
     2.5  @interface MYBonjourRegistration ()
     2.6  @property BOOL registered;
     2.7 +- (void) _updateNullRecord;
     2.8  @end
     2.9  
    2.10  
    2.11 @@ -125,7 +126,8 @@
    2.12      NSData *txtData = nil;
    2.13      if (_txtRecord)
    2.14          txtData = [NSNetService dataFromTXTRecordDictionary: _txtRecord];
    2.15 -    return DNSServiceRegister(sdRefPtr,
    2.16 +    DNSServiceErrorType err;
    2.17 +    err = DNSServiceRegister(sdRefPtr,
    2.18                                flags,
    2.19                                0,
    2.20                                _name.UTF8String,         // _name is likely to be nil
    2.21 @@ -137,11 +139,20 @@
    2.22                                txtData.bytes,
    2.23                                &regCallback,
    2.24                                self);
    2.25 +    if (!err && _nullRecord)
    2.26 +        [self _updateNullRecord];
    2.27 +    return err;
    2.28  }
    2.29  
    2.30  
    2.31  - (void) cancel {
    2.32 +    if (_nullRecordReg && self.serviceRef) {
    2.33 +        DNSServiceRemoveRecord(self.serviceRef, _nullRecordReg, 0);
    2.34 +        _nullRecordReg = NULL;
    2.35 +    }
    2.36 +    
    2.37      [super cancel];
    2.38 +  
    2.39      if (_registered) {
    2.40          [[self class] priv_removeRegistration: self];
    2.41          self.registered = NO;
    2.42 @@ -269,6 +280,44 @@
    2.43      }
    2.44  }
    2.45  
    2.46 +
    2.47 +- (NSData*) nullRecord {
    2.48 +  return _nullRecord;
    2.49 +}
    2.50 +
    2.51 +- (void) setNullRecord: (NSData*)nullRecord {
    2.52 +    if (ifSetObj(&_nullRecord, nullRecord))
    2.53 +        if (self.serviceRef)
    2.54 +            [self _updateNullRecord];
    2.55 +}
    2.56 +
    2.57 +
    2.58 +- (void) _updateNullRecord {
    2.59 +    DNSServiceRef serviceRef = self.serviceRef;
    2.60 +    Assert(serviceRef);
    2.61 +    DNSServiceErrorType err = 0;
    2.62 +    if (!_nullRecord) {
    2.63 +        if (_nullRecordReg) {
    2.64 +            err = DNSServiceRemoveRecord(serviceRef, _nullRecordReg, 0);
    2.65 +            _nullRecordReg = NULL;
    2.66 +        }
    2.67 +    } else if (!_nullRecordReg) {
    2.68 +        err = DNSServiceAddRecord(serviceRef, &_nullRecordReg, 0,
    2.69 +                                  kDNSServiceType_NULL, 
    2.70 +                                  _nullRecord.length, _nullRecord.bytes, 
    2.71 +                                  0);
    2.72 +    } else {
    2.73 +        err = DNSServiceUpdateRecord(serviceRef, _nullRecordReg, 0,
    2.74 +                                     _nullRecord.length, _nullRecord.bytes, 
    2.75 +                                     0);
    2.76 +    }
    2.77 +    if (err)
    2.78 +        Warn(@"MYBonjourRegistration: Couldn't update NULL record, err=%i",err);
    2.79 +    else
    2.80 +        LogTo(DNS, @"MYBonjourRegistration: Set NULL record (%u bytes) %@",
    2.81 +              _nullRecord.length, _nullRecord);
    2.82 +}
    2.83 +
    2.84  @end
    2.85  
    2.86  
     3.1 --- a/IPAddress.m	Mon Jul 20 13:26:29 2009 -0700
     3.2 +++ b/IPAddress.m	Mon Jul 20 14:50:49 2009 -0700
     3.3 @@ -99,6 +99,10 @@
     3.4  
     3.5  - (id) initWithData: (NSData*)data
     3.6  {
     3.7 +    if (!data) {
     3.8 +        [self release];
     3.9 +        return nil;
    3.10 +    }
    3.11      const struct sockaddr* addr = data.bytes;
    3.12      if (data.length < sizeof(struct sockaddr_in))
    3.13          addr = nil;
     4.1 --- a/MYNetwork.xcodeproj/project.pbxproj	Mon Jul 20 13:26:29 2009 -0700
     4.2 +++ b/MYNetwork.xcodeproj/project.pbxproj	Mon Jul 20 14:50:49 2009 -0700
     4.3 @@ -169,15 +169,15 @@
     4.4  		270461880DE49634003D9D3F /* CollectionUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CollectionUtils.h; sourceTree = "<group>"; };
     4.5  		270462C00DE4A639003D9D3F /* MYUtilities_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MYUtilities_Prefix.pch; sourceTree = "<group>"; };
     4.6  		270462C10DE4A64B003D9D3F /* MYUtilitiesTest_main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MYUtilitiesTest_main.m; sourceTree = "<group>"; };
     4.7 -		270462C30DE4A65B003D9D3F /* BLIP Overview.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = "BLIP Overview.txt"; path = "BLIP/BLIP Overview.txt"; sourceTree = "<group>"; wrapsLines = 1; };
     4.8 +		270462C30DE4A65B003D9D3F /* BLIP Overview.txt */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = text; name = "BLIP Overview.txt"; path = "BLIP/BLIP Overview.txt"; sourceTree = "<group>"; wrapsLines = 1; };
     4.9  		2706F1D80F9D3EF300292CCF /* SecurityInterface.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SecurityInterface.framework; path = System/Library/Frameworks/SecurityInterface.framework; sourceTree = SDKROOT; };
    4.10  		27375DFA0FC9FB5C0033F8F5 /* TCPEndpoint+Certs.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "TCPEndpoint+Certs.m"; sourceTree = "<group>"; };
    4.11 -		273B45790FA681EE00276298 /* MYBonjourRegistration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MYBonjourRegistration.h; sourceTree = "<group>"; };
    4.12 -		273B457A0FA681EE00276298 /* MYBonjourRegistration.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MYBonjourRegistration.m; sourceTree = "<group>"; };
    4.13 +		273B45790FA681EE00276298 /* MYBonjourRegistration.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = MYBonjourRegistration.h; sourceTree = "<group>"; };
    4.14 +		273B457A0FA681EE00276298 /* MYBonjourRegistration.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = MYBonjourRegistration.m; sourceTree = "<group>"; };
    4.15  		274122DD0F9CDD1600F21842 /* MYUtilities_Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = MYUtilities_Debug.xcconfig; sourceTree = "<group>"; };
    4.16  		274122DE0F9CDD1600F21842 /* MYUtilities_Release.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = MYUtilities_Release.xcconfig; sourceTree = "<group>"; };
    4.17  		2777C9100F7602A7007F8D30 /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; };
    4.18 -		277903830DE8C2DD00C6D295 /* maindocs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = maindocs.h; sourceTree = "<group>"; wrapsLines = 1; };
    4.19 +		277903830DE8C2DD00C6D295 /* maindocs.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = maindocs.h; sourceTree = "<group>"; wrapsLines = 1; };
    4.20  		277903D50DE8EE4800C6D295 /* BLIPEchoServer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BLIPEchoServer.h; sourceTree = "<group>"; };
    4.21  		277903D60DE8EE4800C6D295 /* BLIPEchoServer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BLIPEchoServer.m; sourceTree = "<group>"; };
    4.22  		277903D80DE8EFC900C6D295 /* BLIP.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BLIP.h; sourceTree = "<group>"; };
    4.23 @@ -189,24 +189,24 @@
    4.24  		2779052D0DE9E5BC00C6D295 /* BLIPEchoServer */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = BLIPEchoServer; sourceTree = BUILT_PRODUCTS_DIR; };
    4.25  		2780F20A0FA194BD00C0FB83 /* MYDNSService.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MYDNSService.h; path = PortMapper/MYDNSService.h; sourceTree = "<group>"; };
    4.26  		2780F20B0FA194BD00C0FB83 /* MYDNSService.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MYDNSService.m; path = PortMapper/MYDNSService.m; sourceTree = "<group>"; };
    4.27 -		2780F4360FA28F4400C0FB83 /* MYBonjourQuery.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MYBonjourQuery.h; sourceTree = "<group>"; };
    4.28 -		2780F4370FA28F4400C0FB83 /* MYBonjourQuery.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MYBonjourQuery.m; sourceTree = "<group>"; };
    4.29 +		2780F4360FA28F4400C0FB83 /* MYBonjourQuery.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = MYBonjourQuery.h; sourceTree = "<group>"; };
    4.30 +		2780F4370FA28F4400C0FB83 /* MYBonjourQuery.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = MYBonjourQuery.m; sourceTree = "<group>"; };
    4.31  		2780F49F0FA2C59000C0FB83 /* MYAddressLookup.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MYAddressLookup.h; path = Bonjour/MYAddressLookup.h; sourceTree = "<group>"; };
    4.32  		2780F4A00FA2C59000C0FB83 /* MYAddressLookup.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MYAddressLookup.m; path = Bonjour/MYAddressLookup.m; sourceTree = "<group>"; };
    4.33  		278C1A340F9F687800954AE1 /* PortMapperTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PortMapperTest.m; sourceTree = "<group>"; };
    4.34  		278C1A350F9F687800954AE1 /* MYPortMapper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MYPortMapper.h; sourceTree = "<group>"; };
    4.35  		278C1A360F9F687800954AE1 /* MYPortMapper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MYPortMapper.m; sourceTree = "<group>"; };
    4.36 -		278C1B9E0F9F92EA00954AE1 /* MYBonjourBrowser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MYBonjourBrowser.h; sourceTree = "<group>"; };
    4.37 -		278C1B9F0F9F92EA00954AE1 /* MYBonjourBrowser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MYBonjourBrowser.m; sourceTree = "<group>"; };
    4.38 -		278C1BA00F9F92EA00954AE1 /* MYBonjourService.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MYBonjourService.h; sourceTree = "<group>"; };
    4.39 -		278C1BA10F9F92EA00954AE1 /* MYBonjourService.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MYBonjourService.m; sourceTree = "<group>"; };
    4.40 +		278C1B9E0F9F92EA00954AE1 /* MYBonjourBrowser.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = MYBonjourBrowser.h; sourceTree = "<group>"; };
    4.41 +		278C1B9F0F9F92EA00954AE1 /* MYBonjourBrowser.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = MYBonjourBrowser.m; sourceTree = "<group>"; };
    4.42 +		278C1BA00F9F92EA00954AE1 /* MYBonjourService.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = MYBonjourService.h; sourceTree = "<group>"; };
    4.43 +		278C1BA10F9F92EA00954AE1 /* MYBonjourService.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = MYBonjourService.m; sourceTree = "<group>"; };
    4.44  		278C1BB50F9F975700954AE1 /* ConcurrentOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ConcurrentOperation.h; sourceTree = "<group>"; };
    4.45  		278C1BB60F9F975700954AE1 /* ConcurrentOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ConcurrentOperation.m; sourceTree = "<group>"; };
    4.46  		279DD99E0F9E290500D75D91 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
    4.47  		279DD9B10F9E296200D75D91 /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = usr/lib/libz.dylib; sourceTree = SDKROOT; };
    4.48  		279DD9B30F9E296E00D75D91 /* CoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreServices.framework; path = System/Library/Frameworks/CoreServices.framework; sourceTree = SDKROOT; };
    4.49  		279DDC9A0F9E2F2A00D75D91 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
    4.50 -		279DDCCB0F9E381500D75D91 /* MYNetwork.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MYNetwork.h; sourceTree = "<group>"; };
    4.51 +		279DDCCB0F9E381500D75D91 /* MYNetwork.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = MYNetwork.h; sourceTree = "<group>"; };
    4.52  		279E8F9E0F9FDD0800608D8D /* libMYNetwork.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libMYNetwork.a; sourceTree = BUILT_PRODUCTS_DIR; };
    4.53  		27D5EC050DE5FEDE00CD84FA /* BLIPRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BLIPRequest.h; sourceTree = "<group>"; };
    4.54  		27D5EC060DE5FEDE00CD84FA /* BLIPRequest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BLIPRequest.m; sourceTree = "<group>"; };
    4.55 @@ -308,6 +308,7 @@
    4.56  				270461070DE49030003D9D3F /* TCP */,
    4.57  				270460F10DE49030003D9D3F /* BLIP */,
    4.58  			);
    4.59 +			indentWidth = 4;
    4.60  			name = MYNetwork;
    4.61  			sourceTree = "<group>";
    4.62  		};
    4.63 @@ -331,6 +332,7 @@
    4.64  				270461000DE49030003D9D3F /* BLIPWriter.m */,
    4.65  				270460F70DE49030003D9D3F /* BLIP_Internal.h */,
    4.66  			);
    4.67 +			indentWidth = 4;
    4.68  			path = BLIP;
    4.69  			sourceTree = "<group>";
    4.70  		};
    4.71 @@ -350,6 +352,7 @@
    4.72  				270461120DE49030003D9D3F /* TCPWriter.m */,
    4.73  				270461080DE49030003D9D3F /* TCP_Internal.h */,
    4.74  			);
    4.75 +			indentWidth = 4;
    4.76  			path = TCP;
    4.77  			sourceTree = "<group>";
    4.78  		};
    4.79 @@ -374,6 +377,7 @@
    4.80  				270461290DE49088003D9D3F /* Test.h */,
    4.81  				270461280DE49088003D9D3F /* Test.m */,
    4.82  			);
    4.83 +			indentWidth = 4;
    4.84  			name = MYUtilities;
    4.85  			sourceTree = MYUtilities;
    4.86  		};
    4.87 @@ -388,6 +392,7 @@
    4.88  				2779048A0DE9204300C6D295 /* BLIPEchoClient.xib */,
    4.89  				277904280DE91C7900C6D295 /* BLIP Echo Client-Info.plist */,
    4.90  			);
    4.91 +			indentWidth = 4;
    4.92  			name = Demo;
    4.93  			path = BLIP/Demo;
    4.94  			sourceTree = "<group>";
    4.95 @@ -402,6 +407,7 @@
    4.96  				2780F49F0FA2C59000C0FB83 /* MYAddressLookup.h */,
    4.97  				2780F4A00FA2C59000C0FB83 /* MYAddressLookup.m */,
    4.98  			);
    4.99 +			indentWidth = 4;
   4.100  			name = Addressing;
   4.101  			sourceTree = "<group>";
   4.102  		};
   4.103 @@ -412,6 +418,7 @@
   4.104  				278C1A360F9F687800954AE1 /* MYPortMapper.m */,
   4.105  				278C1A340F9F687800954AE1 /* PortMapperTest.m */,
   4.106  			);
   4.107 +			indentWidth = 4;
   4.108  			path = PortMapper;
   4.109  			sourceTree = "<group>";
   4.110  		};
   4.111 @@ -427,6 +434,7 @@
   4.112  				273B45790FA681EE00276298 /* MYBonjourRegistration.h */,
   4.113  				273B457A0FA681EE00276298 /* MYBonjourRegistration.m */,
   4.114  			);
   4.115 +			indentWidth = 4;
   4.116  			path = Bonjour;
   4.117  			sourceTree = "<group>";
   4.118  		};