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