Bonjour/MYBonjourRegistration.h
author Jens Alfke <jens@mooseyard.com>
Mon Jul 20 13:26:29 2009 -0700 (2009-07-20)
changeset 59 46c7844cb592
parent 31 1d6924779df7
child 60 dd637bdd214e
permissions -rw-r--r--
* MYBonjourBrowser: Added delegate (no methods for it yet, just for client use.)
* MYBonjourRegistration: Added +canonicalFormOfTXTRecordDictionary:.
* MYBonjourService: Added back-reference to browser.
* IPAddress: Added conversions to/from struct sockaddr.
     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 }
    22 
    23 /** Initializes a new registration.
    24     If you're also browsing for the same service type, you should instead get an instance of this via
    25     the MYBonjourBrowser's 'myRegistration' property -- that way the browser knows about the
    26     registration and won't echo it back to you.
    27     Either way, don't forget to call -start! */
    28 - (id) initWithServiceType: (NSString*)serviceType port: (UInt16)port;
    29 
    30 /** The name to register this service under.
    31     This is often left nil, in which case the user's chosen "Computer Name" (from the Sharing system
    32     pref pane) will be used.
    33     This can only be set before calling -start! */
    34 @property (copy) NSString *name;
    35 
    36 /** The registration's service type. */
    37 @property (readonly) NSString *type;
    38 
    39 /** The registration's IP port number.
    40     You'll need to set this if you got this object from MYBonjourBrowser's 'myRegistration' property,
    41     as that object doesn't have a pre-set port number yet.
    42     This can only be set before calling -start!  */
    43 @property UInt16 port;
    44 
    45 /** The registration's full name -- the name, type and domain concatenated together. */
    46 @property (readonly) NSString *fullName;
    47 
    48 
    49 /** Is the registration currently active? */
    50 @property (readonly) BOOL registered;
    51 
    52 
    53 /** The service's metadata dictionary, stored in its DNS TXT record */
    54 @property (copy) NSDictionary *txtRecord;
    55 
    56 /** Convenience to store a string value in a single TXT record key. */
    57 - (void) setString: (NSString*)value forTxtKey: (NSString*)key;
    58 
    59 
    60 /** @name Expert
    61  *  Advanced methods you likely won't need
    62  */
    63 //@{
    64 
    65 /** The registration's domain name.
    66     This is almost always left nil, in which case the default registration domain is used
    67     (usually ".local".)
    68     This can only be set before calling -start!  */
    69 @property (copy) NSString *domain;
    70 
    71 /** Determines what to do if there's a name conflict with an already-registered service on the
    72     network.
    73     If set to YES (the default), a number will be appended to the name to make it unique.
    74     If set to NO, the registration will fail, and you can choose a different name and try again.
    75     This can only be set before calling -start!  */
    76 @property BOOL autoRename;
    77 
    78 /** Is this browsed service an echo of this local registration? (Compares fullNames.) */
    79 - (BOOL) isSameAsService: (MYBonjourService*)service;
    80 
    81 /** Converts a TXT record dictionary to data in a consistent way.
    82     This is used when signing (and verifying signatures of) TXT records. */
    83 + (NSData*) canonicalFormOfTXTRecordDictionary: (NSDictionary*)txtDict;
    84 
    85 //@}
    86 
    87 @end