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