Bonjour/MYBonjourRegistration.h
author Jens Alfke <jens@mooseyard.com>
Tue Jul 21 15:06:15 2009 -0700 (2009-07-21)
changeset 62 8713f2d6a4c5
parent 60 dd637bdd214e
permissions -rw-r--r--
Added -[MYBonjourRegistration updateTXTRecord]
     1 //
     2 //  MYBonjourRegistration.h
     3 //  MYNetwork
     4 //
     5 //  Created by Jens Alfke on 4/27/09.
     6 //  Copyright 2009 Jens Alfke. All rights reserved.
     7 //
     8 
     9 #import "MYDNSService.h"
    10 @class MYBonjourService;
    11 
    12 
    13 /** Registers a local network service with Bonjour, so it can be browsed by other computers. */
    14 @interface MYBonjourRegistration : MYDNSService
    15 {
    16     NSString *_name, *_type, *_domain;
    17     UInt16 _port;
    18     BOOL _autoRename;
    19     BOOL _registered;
    20     NSMutableDictionary *_txtRecord;
    21     NSData *_nullRecord;
    22     struct _DNSRecordRef_t *_nullRecordReg;
    23 }
    24 
    25 /** Initializes a new registration.
    26     If you're also browsing for the same service type, you should instead get an instance of this via
    27     the MYBonjourBrowser's 'myRegistration' property -- that way the browser knows about the
    28     registration and won't echo it back to you.
    29     Either way, don't forget to call -start! */
    30 - (id) initWithServiceType: (NSString*)serviceType port: (UInt16)port;
    31 
    32 /** The name to register this service under.
    33     This is often left nil, in which case the user's chosen "Computer Name" (from the Sharing system
    34     pref pane) will be used.
    35     This can only be set before calling -start! */
    36 @property (copy) NSString *name;
    37 
    38 /** The registration's service type. */
    39 @property (readonly) NSString *type;
    40 
    41 /** The registration's IP port number.
    42     You'll need to set this if you got this object from MYBonjourBrowser's 'myRegistration' property,
    43     as that object doesn't have a pre-set port number yet.
    44     This can only be set before calling -start!  */
    45 @property UInt16 port;
    46 
    47 /** The registration's full name -- the name, type and domain concatenated together. */
    48 @property (readonly) NSString *fullName;
    49 
    50 
    51 /** Is the registration currently active? */
    52 @property (readonly) BOOL registered;
    53 
    54 
    55 /** The service's metadata dictionary, stored in its DNS TXT record */
    56 @property (copy) NSDictionary *TXTRecord;
    57 
    58 /** Convenience to store a string value in a single TXT record key. */
    59 - (void) setString: (NSString*)value forTXTKey: (NSString*)key;
    60 
    61 
    62 /** @name Expert
    63  *  Advanced methods you likely won't need
    64  */
    65 //@{
    66 
    67 /** The registration's domain name.
    68     This is almost always left nil, in which case the default registration domain is used
    69     (usually ".local".)
    70     This can only be set before calling -start!  */
    71 @property (copy) NSString *domain;
    72 
    73 /** Determines what to do if there's a name conflict with an already-registered service on the
    74     network.
    75     If set to YES (the default), a number will be appended to the name to make it unique.
    76     If set to NO, the registration will fail, and you can choose a different name and try again.
    77     This can only be set before calling -start!  */
    78 @property BOOL autoRename;
    79 
    80 /** Is this browsed service an echo of this local registration? (Compares fullNames.) */
    81 - (BOOL) isSameAsService: (MYBonjourService*)service;
    82 
    83 /** Immediately broadcast the current TXT record. (Normally, there is a 0.1 second delay
    84     after you make changes, in order to coalesce multiple changes.) */
    85 - (void) updateTXTRecord;
    86 
    87 /** Converts a TXT record dictionary to data in a consistent way.
    88     This is used when signing (and verifying signatures of) TXT records. */
    89 + (NSData*) canonicalFormOfTXTRecordDictionary: (NSDictionary*)txtDict;
    90 
    91 /** A DNS 'NULL' record that can be used to publish other metadata about the service.
    92     For example, iChat uses this to store the user's buddy icon.
    93     As with all DNS records, try not to exceed 1500 bytes in size. */
    94 @property (copy) NSData *nullRecord;
    95 
    96 //@}
    97 
    98 @end