Added -[MYBonjourRegistration updateTXTRecord]
authorJens Alfke <jens@mooseyard.com>
Tue Jul 21 15:06:15 2009 -0700 (2009-07-21)
changeset 628713f2d6a4c5
parent 61 981f9d604c88
child 63 5e4855a592ee
Added -[MYBonjourRegistration updateTXTRecord]
Bonjour/MYBonjourRegistration.h
Bonjour/MYBonjourRegistration.m
     1.1 --- a/Bonjour/MYBonjourRegistration.h	Tue Jul 21 10:04:10 2009 -0700
     1.2 +++ b/Bonjour/MYBonjourRegistration.h	Tue Jul 21 15:06:15 2009 -0700
     1.3 @@ -53,10 +53,10 @@
     1.4  
     1.5  
     1.6  /** The service's metadata dictionary, stored in its DNS TXT record */
     1.7 -@property (copy) NSDictionary *txtRecord;
     1.8 +@property (copy) NSDictionary *TXTRecord;
     1.9  
    1.10  /** Convenience to store a string value in a single TXT record key. */
    1.11 -- (void) setString: (NSString*)value forTxtKey: (NSString*)key;
    1.12 +- (void) setString: (NSString*)value forTXTKey: (NSString*)key;
    1.13  
    1.14  
    1.15  /** @name Expert
    1.16 @@ -80,6 +80,10 @@
    1.17  /** Is this browsed service an echo of this local registration? (Compares fullNames.) */
    1.18  - (BOOL) isSameAsService: (MYBonjourService*)service;
    1.19  
    1.20 +/** Immediately broadcast the current TXT record. (Normally, there is a 0.1 second delay
    1.21 +    after you make changes, in order to coalesce multiple changes.) */
    1.22 +- (void) updateTXTRecord;
    1.23 +
    1.24  /** Converts a TXT record dictionary to data in a consistent way.
    1.25      This is used when signing (and verifying signatures of) TXT records. */
    1.26  + (NSData*) canonicalFormOfTXTRecordDictionary: (NSDictionary*)txtDict;
     2.1 --- a/Bonjour/MYBonjourRegistration.m	Tue Jul 21 10:04:10 2009 -0700
     2.2 +++ b/Bonjour/MYBonjourRegistration.m	Tue Jul 21 15:06:15 2009 -0700
     2.3 @@ -160,6 +160,10 @@
     2.4  }
     2.5  
     2.6  
     2.7 +#pragma mark 
     2.8 +#pragma mark TXT RECORD:
     2.9 +
    2.10 +
    2.11  + (NSData*) dataFromTXTRecordDictionary: (NSDictionary*)txtDict {
    2.12      if (!txtDict)
    2.13          return nil;
    2.14 @@ -235,8 +239,8 @@
    2.15  }
    2.16  
    2.17  
    2.18 -- (void) updateTxtRecord {
    2.19 -    [NSObject cancelPreviousPerformRequestsWithTarget: self selector: @selector(updateTxtRecord) object: nil];
    2.20 +- (void) updateTXTRecord {
    2.21 +    [NSObject cancelPreviousPerformRequestsWithTarget: self selector: @selector(updateTXTRecord) object: nil];
    2.22      if (self.serviceRef) {
    2.23          NSData *data = [[self class] dataFromTXTRecordDictionary: _txtRecord];
    2.24          Assert(data!=nil || _txtRecord==nil, @"Can't convert dictionary to TXT record: %@", _txtRecord);
    2.25 @@ -254,19 +258,19 @@
    2.26  }
    2.27  
    2.28  
    2.29 -- (NSDictionary*) txtRecord {
    2.30 +- (NSDictionary*) TXTRecord {
    2.31      return _txtRecord;
    2.32  }
    2.33  
    2.34 -- (void) setTxtRecord: (NSDictionary*)txtDict {
    2.35 +- (void) setTXTRecord: (NSDictionary*)txtDict {
    2.36      if (!$equal(_txtRecord,txtDict)) {
    2.37          setObjCopy(&_txtRecord, txtDict);
    2.38 -        [NSObject cancelPreviousPerformRequestsWithTarget: self selector: @selector(updateTxtRecord) object: nil];
    2.39 -        [self performSelector: @selector(updateTxtRecord) withObject: nil afterDelay: 0.1];
    2.40 +        [NSObject cancelPreviousPerformRequestsWithTarget: self selector: @selector(updateTXTRecord) object: nil];
    2.41 +        [self performSelector: @selector(updateTXTRecord) withObject: nil afterDelay: 0.1];
    2.42      }
    2.43  }
    2.44  
    2.45 -- (void) setString: (NSString*)value forTxtKey: (NSString*)key
    2.46 +- (void) setString: (NSString*)value forTXTKey: (NSString*)key
    2.47  {
    2.48      NSData *data = [value dataUsingEncoding: NSUTF8StringEncoding];
    2.49      if (!$equal(data, [_txtRecord objectForKey: key])) {
    2.50 @@ -275,8 +279,8 @@
    2.51              [_txtRecord setObject: data forKey: key];
    2.52          } else
    2.53              [_txtRecord removeObjectForKey: key];
    2.54 -        [NSObject cancelPreviousPerformRequestsWithTarget: self selector: @selector(updateTxtRecord) object: nil];
    2.55 -        [self performSelector: @selector(updateTxtRecord) withObject: nil afterDelay: 0.1];
    2.56 +        [NSObject cancelPreviousPerformRequestsWithTarget: self selector: @selector(updateTXTRecord) object: nil];
    2.57 +        [self performSelector: @selector(updateTXTRecord) withObject: nil afterDelay: 0.1];
    2.58      }
    2.59  }
    2.60  
    2.61 @@ -342,8 +346,8 @@
    2.62  
    2.63  - (void) updateTXT {
    2.64      NSDictionary *txt = $dict({@"time", $sprintf(@"%.3lf", CFAbsoluteTimeGetCurrent())});
    2.65 -    _reg.txtRecord = txt;
    2.66 -    CAssertEqual(_reg.txtRecord, txt);
    2.67 +    _reg.TXTRecord = txt;
    2.68 +    CAssertEqual(_reg.TXTRecord, txt);
    2.69      [self performSelector: @selector(updateTXT) withObject: nil afterDelay: 3.0];
    2.70  }
    2.71