# HG changeset patch # User Jens Alfke # Date 1248213975 25200 # Node ID 8713f2d6a4c5bceffa53d32d98c5e0f087135011 # Parent 981f9d604c88ae2f79ddae132e24eda8267041d2 Added -[MYBonjourRegistration updateTXTRecord] diff -r 981f9d604c88 -r 8713f2d6a4c5 Bonjour/MYBonjourRegistration.h --- a/Bonjour/MYBonjourRegistration.h Tue Jul 21 10:04:10 2009 -0700 +++ b/Bonjour/MYBonjourRegistration.h Tue Jul 21 15:06:15 2009 -0700 @@ -53,10 +53,10 @@ /** The service's metadata dictionary, stored in its DNS TXT record */ -@property (copy) NSDictionary *txtRecord; +@property (copy) NSDictionary *TXTRecord; /** Convenience to store a string value in a single TXT record key. */ -- (void) setString: (NSString*)value forTxtKey: (NSString*)key; +- (void) setString: (NSString*)value forTXTKey: (NSString*)key; /** @name Expert @@ -80,6 +80,10 @@ /** Is this browsed service an echo of this local registration? (Compares fullNames.) */ - (BOOL) isSameAsService: (MYBonjourService*)service; +/** Immediately broadcast the current TXT record. (Normally, there is a 0.1 second delay + after you make changes, in order to coalesce multiple changes.) */ +- (void) updateTXTRecord; + /** Converts a TXT record dictionary to data in a consistent way. This is used when signing (and verifying signatures of) TXT records. */ + (NSData*) canonicalFormOfTXTRecordDictionary: (NSDictionary*)txtDict; diff -r 981f9d604c88 -r 8713f2d6a4c5 Bonjour/MYBonjourRegistration.m --- a/Bonjour/MYBonjourRegistration.m Tue Jul 21 10:04:10 2009 -0700 +++ b/Bonjour/MYBonjourRegistration.m Tue Jul 21 15:06:15 2009 -0700 @@ -160,6 +160,10 @@ } +#pragma mark +#pragma mark TXT RECORD: + + + (NSData*) dataFromTXTRecordDictionary: (NSDictionary*)txtDict { if (!txtDict) return nil; @@ -235,8 +239,8 @@ } -- (void) updateTxtRecord { - [NSObject cancelPreviousPerformRequestsWithTarget: self selector: @selector(updateTxtRecord) object: nil]; +- (void) updateTXTRecord { + [NSObject cancelPreviousPerformRequestsWithTarget: self selector: @selector(updateTXTRecord) object: nil]; if (self.serviceRef) { NSData *data = [[self class] dataFromTXTRecordDictionary: _txtRecord]; Assert(data!=nil || _txtRecord==nil, @"Can't convert dictionary to TXT record: %@", _txtRecord); @@ -254,19 +258,19 @@ } -- (NSDictionary*) txtRecord { +- (NSDictionary*) TXTRecord { return _txtRecord; } -- (void) setTxtRecord: (NSDictionary*)txtDict { +- (void) setTXTRecord: (NSDictionary*)txtDict { if (!$equal(_txtRecord,txtDict)) { setObjCopy(&_txtRecord, txtDict); - [NSObject cancelPreviousPerformRequestsWithTarget: self selector: @selector(updateTxtRecord) object: nil]; - [self performSelector: @selector(updateTxtRecord) withObject: nil afterDelay: 0.1]; + [NSObject cancelPreviousPerformRequestsWithTarget: self selector: @selector(updateTXTRecord) object: nil]; + [self performSelector: @selector(updateTXTRecord) withObject: nil afterDelay: 0.1]; } } -- (void) setString: (NSString*)value forTxtKey: (NSString*)key +- (void) setString: (NSString*)value forTXTKey: (NSString*)key { NSData *data = [value dataUsingEncoding: NSUTF8StringEncoding]; if (!$equal(data, [_txtRecord objectForKey: key])) { @@ -275,8 +279,8 @@ [_txtRecord setObject: data forKey: key]; } else [_txtRecord removeObjectForKey: key]; - [NSObject cancelPreviousPerformRequestsWithTarget: self selector: @selector(updateTxtRecord) object: nil]; - [self performSelector: @selector(updateTxtRecord) withObject: nil afterDelay: 0.1]; + [NSObject cancelPreviousPerformRequestsWithTarget: self selector: @selector(updateTXTRecord) object: nil]; + [self performSelector: @selector(updateTXTRecord) withObject: nil afterDelay: 0.1]; } } @@ -342,8 +346,8 @@ - (void) updateTXT { NSDictionary *txt = $dict({@"time", $sprintf(@"%.3lf", CFAbsoluteTimeGetCurrent())}); - _reg.txtRecord = txt; - CAssertEqual(_reg.txtRecord, txt); + _reg.TXTRecord = txt; + CAssertEqual(_reg.TXTRecord, txt); [self performSelector: @selector(updateTXT) withObject: nil afterDelay: 3.0]; }