]> git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSWindows/DLL.NET/dnssd_NET.h
999e6898af3b620b0a18a55baee92498f19e5e59
[apple/mdnsresponder.git] / mDNSWindows / DLL.NET / dnssd_NET.h
1 /* -*- Mode: C; tab-width: 4 -*-
2 *
3 * Copyright (c) 2003-2004 Apple Computer, Inc. All rights reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16
17 *
18 * NOTE:
19 *
20 * These .Net APIs are a work in progress, currently being discussed and refined.
21 * If you plan to build an application based on these APIs, you may wish to
22 * statically link this code into your application, or otherwise distribute
23 * the DLL so that it installs into the same folder as your application
24 * (not into any common system area where it might interfere with other
25 * applications using a future completed version of these APIs).
26 * If you plan to do this, please be sure to inform us by sending email
27 * to bonjour@apple.com to let us know.
28 * You may want to discuss what you're doing on the Bonjour mailing
29 * list to see if others in similar positions have any suggestions for you:
30 *
31 * <http://lists.apple.com/bonjour-dev/>
32 *
33
34 Change History (most recent first):
35
36 $Log: dnssd_NET.h,v $
37 Revision 1.9 2006/08/14 23:25:43 cheshire
38 Re-licensed mDNSResponder daemon source code under Apache License, Version 2.0
39
40 Revision 1.8 2005/02/10 22:35:33 cheshire
41 <rdar://problem/3727944> Update name
42
43 Revision 1.7 2004/12/16 19:56:12 cheshire
44 Update comments
45
46 Revision 1.6 2004/09/20 22:47:06 cheshire
47 Add cautionary comment
48
49 Revision 1.5 2004/09/16 18:16:27 shersche
50 Cleanup to parameter names
51 Submitted by: prepin@gmail.com
52
53 Revision 1.4 2004/09/13 19:35:57 shersche
54 <rdar://problem/3798941> Add Apple.DNSSD namespace to MC++ wrapper class
55 <rdar://problem/3798950> Change all instances of unsigned short to int
56 Bug #: 3798941, 3798950
57
58 Revision 1.3 2004/07/27 07:12:10 shersche
59 make TextRecord an instantiable class object
60
61 Revision 1.2 2004/07/19 07:48:34 shersche
62 fix bug in DNSService.Register when passing in NULL text record, add TextRecord APIs
63
64 Revision 1.1 2004/06/26 04:01:22 shersche
65 Initial revision
66
67
68 */
69
70 #pragma once
71
72 #include <dns_sd.h>
73 #include <vcclr.h>
74 #include <memory>
75 #include <winsock2.h>
76
77 using namespace System;
78 using namespace System::Net;
79 using namespace System::Runtime::InteropServices;
80 using namespace System::Threading;
81 using namespace System::Collections;
82
83
84 namespace Apple
85 {
86 namespace DNSSD
87 {
88 public __gc class ServiceRef;
89
90 public __value enum ServiceFlags : int
91 {
92 MoreComing = 1,
93 /* MoreComing indicates to a callback that at least one more result is
94 * queued and will be delivered following immediately after this one.
95 * Applications should not update their UI to display browse
96 * results when the MoreComing flag is set, because this would
97 * result in a great deal of ugly flickering on the screen.
98 * Applications should instead wait until until MoreComing is not set,
99 * and then update their UI.
100 * When MoreComing is not set, that doesn't mean there will be no more
101 * answers EVER, just that there are no more answers immediately
102 * available right now at this instant. If more answers become available
103 * in the future they will be delivered as usual.
104 */
105
106 Add = 2,
107 Default = 4,
108 /* Flags for domain enumeration and browse/query reply callbacks.
109 * "Default" applies only to enumeration and is only valid in
110 * conjuction with "Add". An enumeration callback with the "Add"
111 * flag NOT set indicates a "Remove", i.e. the domain is no longer
112 * valid.
113 */
114
115 NoAutoRename = 8,
116 /* Flag for specifying renaming behavior on name conflict when registering
117 * non-shared records. By default, name conflicts are automatically handled
118 * by renaming the service. NoAutoRename overrides this behavior - with this
119 * flag set, name conflicts will result in a callback. The NoAutorename flag
120 * is only valid if a name is explicitly specified when registering a service
121 * (i.e. the default name is not used.)
122 */
123
124 Shared = 16,
125 Unique = 32,
126 /* Flag for registering individual records on a connected
127 * DNSServiceRef. Shared indicates that there may be multiple records
128 * with this name on the network (e.g. PTR records). Unique indicates that
129 the
130 * record's name is to be unique on the network (e.g. SRV records).
131 */
132
133 BrowseDomains = 64,
134 RegistrationDomains = 128,
135 /* Flags for specifying domain enumeration type in DNSServiceEnumerateDomain
136 s.
137 * BrowseDomains enumerates domains recommended for browsing, RegistrationDo
138 mains
139 * enumerates domains recommended for registration.
140 */
141 };
142
143
144 public __value enum ErrorCode : int
145 {
146 NoError = 0,
147 Unknown = -65537,
148 NoSuchName = -65538,
149 NoMemory = -65539,
150 BadParam = -65540,
151 BadReference = -65541,
152 BadState = -65542,
153 BadFlags = -65543,
154 Unsupported = -65544,
155 AlreadyRegistered = -65547,
156 NameConflict = -65548,
157 Invalid = -65549,
158 Incompatible = -65551,
159 BadinterfaceIndex = -65552
160
161 /*
162 * mDNS Error codes are in the range
163 * FFFE FF00 (-65792) to FFFE FFFF (-65537)
164 */
165 };
166
167 public __gc class DNSServiceException
168 :
169 public Exception
170 {
171 public:
172
173 DNSServiceException
174 (
175 int err
176 );
177
178 DNSServiceException
179 (
180 String * message,
181 System::Exception * innerException
182 );
183
184 int err;
185 };
186
187
188 /*
189 * class RecordRef
190 *
191 * This is a thin MC++ class facade on top of a DNSRecordRef
192 */
193 public __gc class RecordRef
194 {
195 public:
196
197 RecordRef()
198 {
199 m_impl = new RecordRefImpl;
200 m_impl->m_ref = NULL;
201 }
202
203 ~RecordRef()
204 {
205 delete m_impl;
206 }
207
208 __nogc class RecordRefImpl
209 {
210 public:
211
212 DNSRecordRef m_ref;
213 };
214
215 RecordRefImpl * m_impl;
216 };
217
218
219 /*
220 * class ServiceRef
221 *
222 * This is a thin MC++ class facade on top of a DNSServiceRef
223 */
224 public __gc class ServiceRef : public IDisposable
225 {
226 public:
227
228 ServiceRef(Object * callback);
229
230 ~ServiceRef();
231
232 /*
233 * This does an underlying DNSServiceRefDeallocate(). After
234 * calling Dispose, the ServiceRef is no longer usable.
235 */
236 void
237 Dispose();
238
239 /*
240 * Internal - Dispatch an EnumerateDomains callback
241 */
242 void
243 EnumerateDomainsDispatch
244 (
245 ServiceFlags flags,
246 int interfaceIndex,
247 ErrorCode errorCode,
248 String * replyDomain
249 );
250
251 /*
252 * Internal - Dispatch a Register callback
253 */
254 void
255 RegisterDispatch
256 (
257 ServiceFlags flags,
258 ErrorCode errorCode,
259 String * name,
260 String * regtype,
261 String * domain
262 );
263
264 /*
265 * Internal - Dispatch a Browse callback
266 */
267 void
268 BrowseDispatch
269 (
270 ServiceFlags flags,
271 int interfaceIndex,
272 ErrorCode errorCode,
273 String * serviceName,
274 String * regtype,
275 String * replyDomain
276 );
277
278 /*
279 * Internal - Dispatch a Resolve callback
280 */
281 void
282 ResolveDispatch
283 (
284 ServiceFlags flags,
285 int interfaceIndex,
286 ErrorCode errorCode,
287 String * fullname,
288 String * hosttarget,
289 int port,
290 Byte txtRecord[]
291 );
292
293 /*
294 * Internal - Dispatch a RegisterRecord callback
295 */
296 void
297 RegisterRecordDispatch
298 (
299 ServiceFlags flags,
300 ErrorCode errorCode,
301 RecordRef * record
302 );
303
304 /*
305 * Internal - Dispatch a QueryRecord callback
306 */
307 void
308 QueryRecordDispatch
309 (
310 ServiceFlags flags,
311 int interfaceIndex,
312 ErrorCode errorCode,
313 String * fullname,
314 int rrtype,
315 int rrclass,
316 Byte rdata[],
317 int ttl
318 );
319
320 /*
321 * Internal - A non managed class to wrap a DNSServiceRef
322 */
323 __nogc class ServiceRefImpl
324 {
325 public:
326
327 ServiceRefImpl
328 (
329 ServiceRef * outer
330 );
331
332 ~ServiceRefImpl();
333
334 /*
335 * Sets up events for threaded operation
336 */
337 void
338 SetupEvents();
339
340 /*
341 * Main processing thread
342 */
343 void
344 ProcessingThread();
345
346 /*
347 * Calls DNSServiceRefDeallocate()
348 */
349 void
350 Dispose();
351
352 /*
353 * Called from dnssd.dll
354 */
355 static void DNSSD_API
356 EnumerateDomainsCallback
357 (
358 DNSServiceRef sdRef,
359 DNSServiceFlags flags,
360 uint32_t interfaceIndex,
361 DNSServiceErrorType errorCode,
362 const char * replyDomain,
363 void * context
364 );
365
366 static void DNSSD_API
367 RegisterCallback
368 (
369 DNSServiceRef ref,
370 DNSServiceFlags flags,
371 DNSServiceErrorType errorCode,
372 const char * name,
373 const char * regtype,
374 const char * domain,
375 void * context
376 );
377
378 static void DNSSD_API
379 BrowseCallback
380 (
381 DNSServiceRef sdRef,
382 DNSServiceFlags flags,
383 uint32_t interfaceIndex,
384 DNSServiceErrorType errorCode,
385 const char * serviceName,
386 const char * regtype,
387 const char * replyDomain,
388 void * context
389 );
390
391 static void DNSSD_API
392 ResolveCallback
393 (
394 DNSServiceRef sdRef,
395 DNSServiceFlags flags,
396 uint32_t interfaceIndex,
397 DNSServiceErrorType errorCode,
398 const char * fullname,
399 const char * hosttarget,
400 uint16_t notAnIntPort,
401 uint16_t txtLen,
402 const char * txtRecord,
403 void * context
404 );
405
406 static void DNSSD_API
407 RegisterRecordCallback
408 (
409 DNSServiceRef sdRef,
410 DNSRecordRef RecordRef,
411 DNSServiceFlags flags,
412 DNSServiceErrorType errorCode,
413 void * context
414 );
415
416 static void DNSSD_API
417 QueryRecordCallback
418 (
419 DNSServiceRef DNSServiceRef,
420 DNSServiceFlags flags,
421 uint32_t interfaceIndex,
422 DNSServiceErrorType errorCode,
423 const char * fullname,
424 uint16_t rrtype,
425 uint16_t rrclass,
426 uint16_t rdlen,
427 const void * rdata,
428 uint32_t ttl,
429 void * context
430 );
431
432 SOCKET m_socket;
433 HANDLE m_socketEvent;
434 HANDLE m_stopEvent;
435 DWORD m_threadId;
436 bool m_disposed;
437 DNSServiceRef m_ref;
438 gcroot<ServiceRef*> m_outer;
439 };
440
441 void
442 StartThread();
443
444 void
445 ProcessingThread();
446
447 bool m_bDisposed;
448 Object * m_callback;
449 Thread * m_thread;
450 ServiceRefImpl * m_impl;
451 };
452
453 /*********************************************************************************************
454 *
455 * TXT Record Construction Functions
456 *
457 *********************************************************************************************/
458
459 /*
460 * A typical calling sequence for TXT record construction is something like:
461 *
462 * DNSService.TextRecord tr = new DNSService.TextRecord(1024);
463 * tr.SetValue();
464 * tr.SetValue();
465 * tr.SetValue();
466 * ...
467 * DNSServiceRegister( ... tr.GetLength(), tr.GetBytes() ... );
468 */
469
470
471 /* TextRecord
472 *
473 * Opaque internal data type.
474 * Note: Represents a DNS-SD TXT record.
475 */
476
477
478 /* TextRecord::TextRecord()
479 *
480 * Creates a new empty TextRecord .
481 *
482 */
483
484 public __gc class TextRecord
485 {
486 public:
487
488 TextRecord()
489 {
490 m_impl = new TextRecordImpl();
491 TXTRecordCreate(&m_impl->m_ref, 0, NULL);
492 }
493
494 ~TextRecord()
495 {
496 TXTRecordDeallocate(&m_impl->m_ref);
497 delete m_impl;
498 }
499
500 __nogc class TextRecordImpl
501 {
502 public:
503
504 TXTRecordRef m_ref;
505 };
506
507 TextRecordImpl * m_impl;
508
509
510 /* SetValue()
511 *
512 * Adds a key (optionally with value) to a TextRecord. If the "key" already
513 * exists in the TextRecord, then the current value will be replaced with
514 * the new value.
515 * Keys may exist in four states with respect to a given TXT record:
516 * - Absent (key does not appear at all)
517 * - Present with no value ("key" appears alone)
518 * - Present with empty value ("key=" appears in TXT record)
519 * - Present with non-empty value ("key=value" appears in TXT record)
520 * For more details refer to "Data Syntax for DNS-SD TXT Records" in
521 * <http://files.dns-sd.org/draft-cheshire-dnsext-dns-sd.txt>
522 *
523 * key: A null-terminated string which only contains printable ASCII
524 * values (0x20-0x7E), excluding '=' (0x3D). Keys should be
525 * 14 characters or less (not counting the terminating null).
526 *
527 * value: Any binary value. For values that represent
528 * textual data, UTF-8 is STRONGLY recommended.
529 * For values that represent textual data, valueSize
530 * should NOT include the terminating null (if any)
531 * at the end of the string.
532 * If NULL, then "key" will be added with no value.
533 * If non-NULL but valueSize is zero, then "key=" will be
534 * added with empty value.
535 *
536 * exceptions: Throws kDNSServiceErr_Invalid if the "key" string contains
537 * illegal characters.
538 * Throws kDNSServiceErr_NoMemory if adding this key would
539 * exceed the available storage.
540 */
541
542 void
543 SetValue
544 (
545 String * key,
546 Byte value[] /* may be NULL */
547 );
548
549
550 /* RemoveValue()
551 *
552 * Removes a key from a TextRecord. The "key" must be an
553 * ASCII string which exists in the TextRecord.
554 *
555 * key: A key name which exists in the TextRecord.
556 *
557 * exceptions: Throws kDNSServiceErr_NoSuchKey if the "key" does not
558 * exist in the TextRecord.
559 *
560 */
561
562 void
563 RemoveValue
564 (
565 String * key
566 );
567
568
569 /* GetLength()
570 *
571 * Allows you to determine the length of the raw bytes within a TextRecord.
572 *
573 * return value : Returns the size of the raw bytes inside a TextRecord
574 * which you can pass directly to DNSServiceRegister() or
575 * to DNSServiceUpdateRecord().
576 * Returns 0 if the TextRecord is empty.
577 *
578 */
579
580 int
581 GetLength
582 (
583 );
584
585
586 /* GetBytes()
587 *
588 * Allows you to retrieve a pointer to the raw bytes within a TextRecord.
589 *
590 * return value: Returns a pointer to the bytes inside the TextRecord
591 * which you can pass directly to DNSServiceRegister() or
592 * to DNSServiceUpdateRecord().
593 *
594 */
595
596 Byte
597 GetBytes
598 (
599 ) __gc[];
600
601
602 /*********************************************************************************************
603 *
604 * TXT Record Parsing Functions
605 *
606 *********************************************************************************************/
607
608 /*
609 * A typical calling sequence for TXT record parsing is something like:
610 *
611 * Receive TXT record data in DNSServiceResolve() callback
612 * if (TXTRecordContainsKey(txtLen, txtRecord, "key")) then do something
613 * val1ptr = DNSService.TextService.GetValue(txtRecord, "key1", &len1);
614 * val2ptr = DNSService.TextService.GetValue(txtRecord, "key2", &len2);
615 * ...
616 * return;
617 *
618 */
619
620 /* ContainsKey()
621 *
622 * Allows you to determine if a given TXT Record contains a specified key.
623 *
624 * txtRecord: Pointer to the received TXT Record bytes.
625 *
626 * key: A null-terminated ASCII string containing the key name.
627 *
628 * return value: Returns 1 if the TXT Record contains the specified key.
629 * Otherwise, it returns 0.
630 *
631 */
632
633 static public bool
634 ContainsKey
635 (
636 Byte txtRecord[],
637 String * key
638 );
639
640
641 /* GetValueBytes()
642 *
643 * Allows you to retrieve the value for a given key from a TXT Record.
644 *
645 * txtRecord: Pointer to the received TXT Record bytes.
646 *
647 * key: A null-terminated ASCII string containing the key name.
648 *
649 * return value: Returns NULL if the key does not exist in this TXT record,
650 * or exists with no value (to differentiate between
651 * these two cases use ContainsKey()).
652 * Returns byte array
653 * if the key exists with empty or non-empty value.
654 * For empty value, length of byte array will be zero.
655 * For non-empty value, it will be the length of value data.
656 */
657
658 static public Byte
659 GetValueBytes
660 (
661 Byte txtRecord[],
662 String * key
663 ) __gc[];
664
665
666 /* GetCount()
667 *
668 * Returns the number of keys stored in the TXT Record. The count
669 * can be used with TXTRecordGetItemAtIndex() to iterate through the keys.
670 *
671 * txtRecord: Pointer to the received TXT Record bytes.
672 *
673 * return value: Returns the total number of keys in the TXT Record.
674 *
675 */
676
677 static public int
678 GetCount
679 (
680 Byte txtRecord[]
681 );
682
683
684 /* GetItemAtIndex()
685 *
686 * Allows you to retrieve a key name and value pointer, given an index into
687 * a TXT Record. Legal index values range from zero to TXTRecordGetCount()-1.
688 * It's also possible to iterate through keys in a TXT record by simply
689 * calling TXTRecordGetItemAtIndex() repeatedly, beginning with index zero
690 * and increasing until TXTRecordGetItemAtIndex() returns kDNSServiceErr_Invalid.
691 *
692 * On return:
693 * For keys with no value, *value is set to NULL and *valueLen is zero.
694 * For keys with empty value, *value is non-NULL and *valueLen is zero.
695 * For keys with non-empty value, *value is non-NULL and *valueLen is non-zero.
696 *
697 * txtRecord: Pointer to the received TXT Record bytes.
698 *
699 * index: An index into the TXT Record.
700 *
701 * key: A string buffer used to store the key name.
702 * On return, the buffer contains a string
703 * giving the key name. DNS-SD TXT keys are usually
704 * 14 characters or less.
705 *
706 * return value: Record bytes that holds the value data.
707 *
708 * exceptions: Throws kDNSServiceErr_Invalid if index is greater than
709 * GetCount()-1.
710 */
711
712 static public Byte
713 GetItemAtIndex
714 (
715 Byte txtRecord[],
716 int index,
717 [Out] String ** key
718 ) __gc[];
719 };
720
721
722 public __abstract __gc class DNSService
723 {
724 public:
725
726 /*********************************************************************************************
727 *
728 * Domain Enumeration
729 *
730 *********************************************************************************************/
731
732 /* DNSServiceEnumerateDomains()
733 *
734 * Asynchronously enumerate domains available for browsing and registration.
735 * Currently, the only domain returned is "local.", but other domains will be returned in future.
736 *
737 * The enumeration MUST be cancelled via DNSServiceRefDeallocate() when no more domains
738 * are to be found.
739 *
740 *
741 * EnumerateDomainsReply Delegate
742 *
743 * This Delegate is invoked upon a reply from an EnumerateDomains call.
744 *
745 * sdRef: The DNSServiceRef initialized by DNSServiceEnumerateDomains().
746 *
747 * flags: Possible values are:
748 * MoreComing
749 * Add
750 * Default
751 *
752 * interfaceIndex: Specifies the interface on which the domain exists. (The index for a given
753 * interface is determined via the if_nametoindex() family of calls.)
754 *
755 * errorCode: Will be NoError (0) on success, otherwise indicates
756 * the failure that occurred (other parameters are undefined if errorCode is nonzero).
757 *
758 * replyDomain: The name of the domain.
759 *
760 */
761
762 __delegate void
763 EnumerateDomainsReply
764 (
765 ServiceRef * sdRef,
766 ServiceFlags flags,
767 int interfaceIndex,
768 ErrorCode errorCode,
769 String * replyDomain
770 );
771
772 /* DNSServiceEnumerateDomains() Parameters:
773 *
774 *
775 * flags: Possible values are:
776 * BrowseDomains to enumerate domains recommended for browsing.
777 * RegistrationDomains to enumerate domains recommended
778 * for registration.
779 *
780 * interfaceIndex: If non-zero, specifies the interface on which to look for domains.
781 * (the index for a given interface is determined via the if_nametoindex()
782 * family of calls.) Most applications will pass 0 to enumerate domains on
783 * all interfaces.
784 *
785 * callback: The delegate to be called when a domain is found or the call asynchronously
786 * fails.
787 *
788 *
789 * return value: Returns initialize ServiceRef on succeses (any subsequent, asynchronous
790 * errors are delivered to the delegate), otherwise throws an exception indicating
791 * the error that occurred (the callback is not invoked and the ServiceRef
792 * is not initialized.)
793 */
794
795 static public ServiceRef*
796 EnumerateDomains
797 (
798 int flags,
799 int interfaceIndex,
800 EnumerateDomainsReply * callback
801 );
802
803 /*********************************************************************************************
804 *
805 * Service Registration
806 *
807 *********************************************************************************************/
808
809 /* Register a service that is discovered via Browse() and Resolve() calls.
810 *
811 * RegisterReply() Callback Parameters:
812 *
813 * sdRef: The ServiceRef initialized by Register().
814 *
815 * flags: Currently unused, reserved for future use.
816 *
817 * errorCode: Will be NoError on success, otherwise will
818 * indicate the failure that occurred (including name conflicts, if the
819 * NoAutoRename flag was passed to the
820 * callout.) Other parameters are undefined if errorCode is nonzero.
821 *
822 * name: The service name registered (if the application did not specify a name in
823 * DNSServiceRegister(), this indicates what name was automatically chosen).
824 *
825 * regtype: The type of service registered, as it was passed to the callout.
826 *
827 * domain: The domain on which the service was registered (if the application did not
828 * specify a domain in Register(), this indicates the default domain
829 * on which the service was registered).
830 *
831 */
832
833 __delegate void
834 RegisterReply
835 (
836 ServiceRef * sdRef,
837 ServiceFlags flags,
838 ErrorCode errorCode,
839 String * name,
840 String * regtype,
841 String * domain
842 );
843
844 /* Register() Parameters:
845 *
846 * flags: Indicates the renaming behavior on name conflict (most applications
847 * will pass 0). See flag definitions above for details.
848 *
849 * interfaceIndex: If non-zero, specifies the interface on which to register the service
850 * (the index for a given interface is determined via the if_nametoindex()
851 * family of calls.) Most applications will pass 0 to register on all
852 * available interfaces. Pass -1 to register a service only on the local
853 * machine (service will not be visible to remote hosts.)
854 *
855 * name: If non-NULL, specifies the service name to be registered.
856 * Most applications will not specify a name, in which case the
857 * computer name is used (this name is communicated to the client via
858 * the callback).
859 *
860 * regtype: The service type followed by the protocol, separated by a dot
861 * (e.g. "_ftp._tcp"). The transport protocol must be "_tcp" or "_udp".
862 * New service types should be registered at htp://www.dns-sd.org/ServiceTypes.html.
863 *
864 * domain: If non-NULL, specifies the domain on which to advertise the service.
865 * Most applications will not specify a domain, instead automatically
866 * registering in the default domain(s).
867 *
868 * host: If non-NULL, specifies the SRV target host name. Most applications
869 * will not specify a host, instead automatically using the machine's
870 * default host name(s). Note that specifying a non-NULL host does NOT
871 * create an address record for that host - the application is responsible
872 * for ensuring that the appropriate address record exists, or creating it
873 * via DNSServiceRegisterRecord().
874 *
875 * port: The port, in host byte order, on which the service accepts connections.
876 * Pass 0 for a "placeholder" service (i.e. a service that will not be discovered
877 * by browsing, but will cause a name conflict if another client tries to
878 * register that same name). Most clients will not use placeholder services.
879 *
880 * txtRecord: The txt record rdata. May be NULL. Note that a non-NULL txtRecord
881 * MUST be a properly formatted DNS TXT record, i.e. <length byte> <data>
882 * <length byte> <data> ...
883 *
884 * callback: The delegate to be called when the registration completes or asynchronously
885 * fails. The client MAY pass NULL for the callback - The client will NOT be notified
886 * of the default values picked on its behalf, and the client will NOT be notified of any
887 * asynchronous errors (e.g. out of memory errors, etc.) that may prevent the registration
888 * of the service. The client may NOT pass the NoAutoRename flag if the callback is NULL.
889 * The client may still deregister the service at any time via DNSServiceRefDeallocate().
890 *
891 * return value: Returns initialize ServiceRef (any subsequent, asynchronous
892 * errors are delivered to the callback), otherwise throws an exception indicating
893 * the error that occurred (the callback is never invoked and the DNSServiceRef
894 * is not initialized.)
895 *
896 */
897 static public ServiceRef*
898 Register
899 (
900 int flags,
901 int interfaceIndex,
902 String * name,
903 String * regtype,
904 String * domain,
905 String * host,
906 int port,
907 Byte txtRecord[],
908 RegisterReply * callback
909 );
910
911 /* AddRecord()
912 *
913 * Add a record to a registered service. The name of the record will be the same as the
914 * registered service's name.
915 * The record can later be updated or deregistered by passing the RecordRef initialized
916 * by this function to UpdateRecord() or RemoveRecord().
917 *
918 *
919 * Parameters;
920 *
921 * sdRef: A ServiceRef initialized by Register().
922 *
923 * RecordRef: A pointer to an uninitialized RecordRef. Upon succesfull completion of this
924 * call, this ref may be passed to UpdateRecord() or RemoveRecord().
925 * If the above ServiceRef is disposed, RecordRef is also
926 * invalidated and may not be used further.
927 *
928 * flags: Currently ignored, reserved for future use.
929 *
930 * rrtype: The type of the record (e.g. TXT, SRV, etc), as defined in nameser.h.
931 *
932 * rdata: The raw rdata to be contained in the added resource record.
933 *
934 * ttl: The time to live of the resource record, in seconds.
935 *
936 * return value: Returns initialized RecordRef, otherwise throws
937 * an exception indicating the error that occurred (the RecordRef is not initialized).
938 */
939
940 static public RecordRef*
941 AddRecord
942 (
943 ServiceRef * sref,
944 int flags,
945 int rrtype,
946 Byte rdata[],
947 int ttl
948 );
949
950 /* UpdateRecord
951 *
952 * Update a registered resource record. The record must either be:
953 * - The primary txt record of a service registered via Register()
954 * - A record added to a registered service via AddRecord()
955 * - An individual record registered by RegisterRecord()
956 *
957 *
958 * Parameters:
959 *
960 * sdRef: A ServiceRef that was initialized by Register()
961 * or CreateConnection().
962 *
963 * RecordRef: A RecordRef initialized by AddRecord, or NULL to update the
964 * service's primary txt record.
965 *
966 * flags: Currently ignored, reserved for future use.
967 *
968 * rdata: The new rdata to be contained in the updated resource record.
969 *
970 * ttl: The time to live of the updated resource record, in seconds.
971 *
972 * return value: No return value on success, otherwise throws an exception
973 * indicating the error that occurred.
974 */
975 static public void
976 UpdateRecord
977 (
978 ServiceRef * sref,
979 RecordRef * record,
980 int flags,
981 Byte rdata[],
982 int ttl
983 );
984
985 /* RemoveRecord
986 *
987 * Remove a record previously added to a service record set via AddRecord(), or deregister
988 * an record registered individually via RegisterRecord().
989 *
990 * Parameters:
991 *
992 * sdRef: A ServiceRef initialized by Register() (if the
993 * record being removed was registered via AddRecord()) or by
994 * CreateConnection() (if the record being removed was registered via
995 * RegisterRecord()).
996 *
997 * recordRef: A RecordRef initialized by a successful call to AddRecord()
998 * or RegisterRecord().
999 *
1000 * flags: Currently ignored, reserved for future use.
1001 *
1002 * return value: Nothing on success, otherwise throws an
1003 * exception indicating the error that occurred.
1004 */
1005
1006 static public void
1007 RemoveRecord
1008 (
1009 ServiceRef * sref,
1010 RecordRef * record,
1011 int flags
1012 );
1013
1014 /*********************************************************************************************
1015 *
1016 * Service Discovery
1017 *
1018 *********************************************************************************************/
1019
1020 /* Browse for instances of a service.
1021 *
1022 *
1023 * BrowseReply() Parameters:
1024 *
1025 * sdRef: The DNSServiceRef initialized by Browse().
1026 *
1027 * flags: Possible values are MoreComing and Add.
1028 * See flag definitions for details.
1029 *
1030 * interfaceIndex: The interface on which the service is advertised. This index should
1031 * be passed to Resolve() when resolving the service.
1032 *
1033 * errorCode: Will be NoError (0) on success, otherwise will
1034 * indicate the failure that occurred. Other parameters are undefined if
1035 * the errorCode is nonzero.
1036 *
1037 * serviceName: The service name discovered.
1038 *
1039 * regtype: The service type, as passed in to Browse().
1040 *
1041 * domain: The domain on which the service was discovered (if the application did not
1042 * specify a domain in Browse(), this indicates the domain on which the
1043 * service was discovered.)
1044 *
1045 */
1046
1047 __delegate void
1048 BrowseReply
1049 (
1050 ServiceRef * sdRef,
1051 ServiceFlags flags,
1052 int interfaceIndex,
1053 ErrorCode errorCode,
1054 String * name,
1055 String * type,
1056 String * domain
1057 );
1058
1059 /* DNSServiceBrowse() Parameters:
1060 *
1061 * sdRef: A pointer to an uninitialized ServiceRef. Call ServiceRef.Dispose()
1062 * to terminate the browse.
1063 *
1064 * flags: Currently ignored, reserved for future use.
1065 *
1066 * interfaceIndex: If non-zero, specifies the interface on which to browse for services
1067 * (the index for a given interface is determined via the if_nametoindex()
1068 * family of calls.) Most applications will pass 0 to browse on all available
1069 * interfaces. Pass -1 to only browse for services provided on the local host.
1070 *
1071 * regtype: The service type being browsed for followed by the protocol, separated by a
1072 * dot (e.g. "_ftp._tcp"). The transport protocol must be "_tcp" or "_udp".
1073 *
1074 * domain: If non-NULL, specifies the domain on which to browse for services.
1075 * Most applications will not specify a domain, instead browsing on the
1076 * default domain(s).
1077 *
1078 * callback: The delegate to be called when an instance of the service being browsed for
1079 * is found, or if the call asynchronously fails.
1080 *
1081 * return value: Returns initialized ServiceRef on succeses (any subsequent, asynchronous
1082 * errors are delivered to the callback), otherwise throws an exception indicating
1083 * the error that occurred (the callback is not invoked and the ServiceRef
1084 * is not initialized.)
1085 */
1086
1087 static public ServiceRef*
1088 Browse
1089 (
1090 int flags,
1091 int interfaceIndex,
1092 String * regtype,
1093 String * domain,
1094 BrowseReply * callback
1095 );
1096
1097 /* ResolveReply() Parameters:
1098 *
1099 * Resolve a service name discovered via Browse() to a target host name, port number, and
1100 * txt record.
1101 *
1102 * Note: Applications should NOT use Resolve() solely for txt record monitoring - use
1103 * QueryRecord() instead, as it is more efficient for this task.
1104 *
1105 * Note: When the desired results have been returned, the client MUST terminate the resolve by calling
1106 * ServiceRef.Dispose().
1107 *
1108 * Note: Resolve() behaves correctly for typical services that have a single SRV record and
1109 * a single TXT record (the TXT record may be empty.) To resolve non-standard services with multiple
1110 * SRV or TXT records, QueryRecord() should be used.
1111 *
1112 * ResolveReply Callback Parameters:
1113 *
1114 * sdRef: The DNSServiceRef initialized by Resolve().
1115 *
1116 * flags: Currently unused, reserved for future use.
1117 *
1118 * interfaceIndex: The interface on which the service was resolved.
1119 *
1120 * errorCode: Will be NoError (0) on success, otherwise will
1121 * indicate the failure that occurred. Other parameters are undefined if
1122 * the errorCode is nonzero.
1123 *
1124 * fullname: The full service domain name, in the form <servicename>.<protocol>.<domain>.
1125 * (Any literal dots (".") are escaped with a backslash ("\."), and literal
1126 * backslashes are escaped with a second backslash ("\\"), e.g. a web server
1127 * named "Dr. Pepper" would have the fullname "Dr\.\032Pepper._http._tcp.local.").
1128 * This is the appropriate format to pass to standard system DNS APIs such as
1129 * res_query(), or to the special-purpose functions included in this API that
1130 * take fullname parameters.
1131 *
1132 * hosttarget: The target hostname of the machine providing the service. This name can
1133 * be passed to functions like gethostbyname() to identify the host's IP address.
1134 *
1135 * port: The port, in host byte order, on which connections are accepted for this service.
1136 *
1137 * txtRecord: The service's primary txt record, in standard txt record format.
1138 *
1139 */
1140
1141 __delegate void
1142 ResolveReply
1143 (
1144 ServiceRef * sdRef,
1145 ServiceFlags flags,
1146 int interfaceIndex,
1147 ErrorCode errorCode,
1148 String * fullName,
1149 String * hostName,
1150 int port,
1151 Byte txtRecord[]
1152 );
1153
1154 /* Resolve() Parameters
1155 *
1156 * flags: Currently ignored, reserved for future use.
1157 *
1158 * interfaceIndex: The interface on which to resolve the service. The client should
1159 * pass the interface on which the servicename was discovered, i.e.
1160 * the interfaceIndex passed to the DNSServiceBrowseReply callback,
1161 * or 0 to resolve the named service on all available interfaces.
1162 *
1163 * name: The servicename to be resolved.
1164 *
1165 * regtype: The service type being resolved followed by the protocol, separated by a
1166 * dot (e.g. "_ftp._tcp"). The transport protocol must be "_tcp" or "_udp".
1167 *
1168 * domain: The domain on which the service is registered, i.e. the domain passed
1169 * to the DNSServiceBrowseReply callback.
1170 *
1171 * callback: The delegate to be called when a result is found, or if the call
1172 * asynchronously fails.
1173 *
1174 *
1175 * return value: Returns initialized ServiceRef on succeses (any subsequent, asynchronous
1176 * errors are delivered to the callback), otherwise throws an exception indicating
1177 * the error that occurred (the callback is never invoked and the DNSServiceRef
1178 * is not initialized.)
1179 */
1180
1181 static public ServiceRef*
1182 Resolve
1183 (
1184 int flags,
1185 int interfaceIndex,
1186 String * name,
1187 String * regtype,
1188 String * domain,
1189 ResolveReply * callback
1190 );
1191
1192 /*********************************************************************************************
1193 *
1194 * Special Purpose Calls (most applications will not use these)
1195 *
1196 *********************************************************************************************/
1197
1198 /* CreateConnection/RegisterRecord
1199 *
1200 * Register an individual resource record on a connected ServiceRef.
1201 *
1202 * Note that name conflicts occurring for records registered via this call must be handled
1203 * by the client in the callback.
1204 *
1205 *
1206 * RecordReply() parameters:
1207 *
1208 * sdRef: The connected ServiceRef initialized by
1209 * CreateConnection().
1210 *
1211 * RecordRef: The RecordRef initialized by RegisterRecord(). If the above
1212 * ServiceRef.Dispose is called, this RecordRef is
1213 * invalidated, and may not be used further.
1214 *
1215 * flags: Currently unused, reserved for future use.
1216 *
1217 * errorCode: Will be NoError on success, otherwise will
1218 * indicate the failure that occurred (including name conflicts.)
1219 * Other parameters are undefined if errorCode is nonzero.
1220 *
1221 */
1222
1223 __delegate void
1224 RegisterRecordReply
1225 (
1226 ServiceRef * sdRef,
1227 ServiceFlags flags,
1228 ErrorCode errorCode,
1229 RecordRef * record
1230 );
1231
1232 /* CreateConnection()
1233 *
1234 * Create a connection to the daemon allowing efficient registration of
1235 * multiple individual records.
1236 *
1237 *
1238 * Parameters:
1239 *
1240 * callback: The delegate to be called when a result is found, or if the call
1241 * asynchronously fails (e.g. because of a name conflict.)
1242 *
1243 * return value: Returns initialize ServiceRef on success, otherwise throws
1244 * an exception indicating the specific failure that occurred (in which
1245 * case the ServiceRef is not initialized).
1246 */
1247
1248 static public ServiceRef*
1249 CreateConnection
1250 (
1251 RegisterRecordReply * callback
1252 );
1253
1254
1255 /* RegisterRecord() Parameters:
1256 *
1257 * sdRef: A ServiceRef initialized by CreateConnection().
1258 *
1259 * RecordRef: A pointer to an uninitialized RecordRef. Upon succesfull completion of this
1260 * call, this ref may be passed to UpdateRecord() or RemoveRecord().
1261 * (To deregister ALL records registered on a single connected ServiceRef
1262 * and deallocate each of their corresponding RecordRefs, call
1263 * ServiceRef.Dispose()).
1264 *
1265 * flags: Possible values are Shared or Unique
1266 * (see flag type definitions for details).
1267 *
1268 * interfaceIndex: If non-zero, specifies the interface on which to register the record
1269 * (the index for a given interface is determined via the if_nametoindex()
1270 * family of calls.) Passing 0 causes the record to be registered on all interfaces.
1271 * Passing -1 causes the record to only be visible on the local host.
1272 *
1273 * fullname: The full domain name of the resource record.
1274 *
1275 * rrtype: The numerical type of the resource record (e.g. PTR, SRV, etc), as defined
1276 * in nameser.h.
1277 *
1278 * rrclass: The class of the resource record, as defined in nameser.h (usually 1 for the
1279 * Internet class).
1280 *
1281 * rdata: A pointer to the raw rdata, as it is to appear in the DNS record.
1282 *
1283 * ttl: The time to live of the resource record, in seconds.
1284 *
1285 *
1286 * return value: Returns initialize RecordRef on succeses (any subsequent, asynchronous
1287 * errors are delivered to the callback), otherwise throws an exception indicating
1288 * the error that occurred (the callback is never invoked and the RecordRef is
1289 * not initialized.)
1290 */
1291 static public RecordRef*
1292 RegisterRecord
1293 (
1294 ServiceRef * sdRef,
1295 ServiceFlags flags,
1296 int interfaceIndex,
1297 String * fullname,
1298 int rrtype,
1299 int rrclass,
1300 Byte rdata[],
1301 int ttl
1302 );
1303
1304
1305 /* DNSServiceQueryRecord
1306 *
1307 * Query for an arbitrary DNS record.
1308 *
1309 *
1310 * QueryRecordReply() Delegate Parameters:
1311 *
1312 * sdRef: The ServiceRef initialized by QueryRecord().
1313 *
1314 * flags: Possible values are MoreComing and
1315 * Add. The Add flag is NOT set for PTR records
1316 * with a ttl of 0, i.e. "Remove" events.
1317 *
1318 * interfaceIndex: The interface on which the query was resolved (the index for a given
1319 * interface is determined via the if_nametoindex() family of calls).
1320 *
1321 * errorCode: Will be kDNSServiceErr_NoError on success, otherwise will
1322 * indicate the failure that occurred. Other parameters are undefined if
1323 * errorCode is nonzero.
1324 *
1325 * fullname: The resource record's full domain name.
1326 *
1327 * rrtype: The resource record's type (e.g. PTR, SRV, etc) as defined in nameser.h.
1328 *
1329 * rrclass: The class of the resource record, as defined in nameser.h (usually 1).
1330 *
1331 * rdata: The raw rdata of the resource record.
1332 *
1333 * ttl: The resource record's time to live, in seconds.
1334 *
1335 */
1336
1337 __delegate void
1338 QueryRecordReply
1339 (
1340 ServiceRef * sdRef,
1341 ServiceFlags flags,
1342 int interfaceIndex,
1343 ErrorCode errorCode,
1344 String * fullName,
1345 int rrtype,
1346 int rrclass,
1347 Byte rdata[],
1348 int ttl
1349 );
1350
1351 /* QueryRecord() Parameters:
1352 *
1353 * flags: Pass LongLivedQuery to create a "long-lived" unicast
1354 * query in a non-local domain. Without setting this flag, unicast queries
1355 * will be one-shot - that is, only answers available at the time of the call
1356 * will be returned. By setting this flag, answers (including Add and Remove
1357 * events) that become available after the initial call is made will generate
1358 * callbacks. This flag has no effect on link-local multicast queries.
1359 *
1360 * interfaceIndex: If non-zero, specifies the interface on which to issue the query
1361 * (the index for a given interface is determined via the if_nametoindex()
1362 * family of calls.) Passing 0 causes the name to be queried for on all
1363 * interfaces. Passing -1 causes the name to be queried for only on the
1364 * local host.
1365 *
1366 * fullname: The full domain name of the resource record to be queried for.
1367 *
1368 * rrtype: The numerical type of the resource record to be queried for (e.g. PTR, SRV, etc)
1369 * as defined in nameser.h.
1370 *
1371 * rrclass: The class of the resource record, as defined in nameser.h
1372 * (usually 1 for the Internet class).
1373 *
1374 * callback: The delegate to be called when a result is found, or if the call
1375 * asynchronously fails.
1376 *
1377 *
1378 * return value: Returns initialized ServiceRef on succeses (any subsequent, asynchronous
1379 * errors are delivered to the callback), otherwise throws an exception indicating
1380 * the error that occurred (the callback is never invoked and the ServiceRef
1381 * is not initialized.)
1382 */
1383
1384 static public ServiceRef*
1385 QueryRecord
1386 (
1387 ServiceFlags flags,
1388 int interfaceIndex,
1389 String * fullname,
1390 int rrtype,
1391 int rrclass,
1392 QueryRecordReply * callback
1393 );
1394
1395 /* ReconfirmRecord
1396 *
1397 * Instruct the daemon to verify the validity of a resource record that appears to
1398 * be out of date (e.g. because tcp connection to a service's target failed.)
1399 * Causes the record to be flushed from the daemon's cache (as well as all other
1400 * daemons' caches on the network) if the record is determined to be invalid.
1401 *
1402 * Parameters:
1403 *
1404 * flags: Currently unused, reserved for future use.
1405 *
1406 * fullname: The resource record's full domain name.
1407 *
1408 * rrtype: The resource record's type (e.g. PTR, SRV, etc) as defined in nameser.h.
1409 *
1410 * rrclass: The class of the resource record, as defined in nameser.h (usually 1).
1411 *
1412 * rdata: The raw rdata of the resource record.
1413 *
1414 */
1415 static public void
1416 ReconfirmRecord
1417 (
1418 ServiceFlags flags,
1419 int interfaceIndex,
1420 String * fullname,
1421 int rrtype,
1422 int rrclass,
1423 Byte rdata[]
1424 );
1425 };
1426 }
1427 }