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