dnssd 1.2 → 1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data.tar.gz.sig +0 -0
  2. data/.autotest +14 -0
  3. data/History.txt +22 -3
  4. data/Manifest.txt +15 -0
  5. data/README.txt +27 -3
  6. data/Rakefile +5 -4
  7. data/ext/dnssd/dnssd.c +4 -0
  8. data/ext/dnssd/dnssd.h +13 -18
  9. data/ext/dnssd/errors.c +9 -3
  10. data/ext/dnssd/extconf.rb +51 -44
  11. data/ext/dnssd/flags.c +68 -14
  12. data/ext/dnssd/record.c +218 -0
  13. data/ext/dnssd/service.c +341 -121
  14. data/lib/dnssd.rb +46 -11
  15. data/lib/dnssd/record.rb +97 -0
  16. data/lib/dnssd/reply.rb +39 -92
  17. data/lib/dnssd/reply/addr_info.rb +47 -0
  18. data/lib/dnssd/reply/browse.rb +52 -0
  19. data/lib/dnssd/reply/domain.rb +22 -0
  20. data/lib/dnssd/reply/query_record.rb +183 -0
  21. data/lib/dnssd/reply/register.rb +37 -0
  22. data/lib/dnssd/reply/resolve.rb +105 -0
  23. data/lib/dnssd/service.rb +123 -16
  24. data/lib/dnssd/text_record.rb +28 -19
  25. data/sample/browse.rb +24 -6
  26. data/sample/enumerate_domains.rb +7 -1
  27. data/sample/getaddrinfo.rb +28 -0
  28. data/sample/growl.rb +2 -0
  29. data/sample/query_record.rb +15 -0
  30. data/sample/register.rb +19 -20
  31. data/sample/resolve.rb +31 -7
  32. data/sample/resolve_ichat.rb +5 -6
  33. data/sample/server.rb +2 -0
  34. data/sample/socket.rb +4 -0
  35. data/test/test_dnssd.rb +6 -4
  36. data/test/test_dnssd_flags.rb +1 -15
  37. data/test/test_dnssd_record.rb +92 -0
  38. data/test/test_dnssd_reply.rb +13 -79
  39. data/test/test_dnssd_reply_browse.rb +28 -0
  40. data/test/test_dnssd_reply_query_record.rb +92 -0
  41. data/test/test_dnssd_reply_resolve.rb +47 -0
  42. data/test/test_dnssd_service.rb +12 -0
  43. data/test/test_dnssd_text_record.rb +3 -3
  44. metadata +32 -11
  45. metadata.gz.sig +0 -0
data.tar.gz.sig CHANGED
Binary file
data/.autotest CHANGED
@@ -1,10 +1,24 @@
1
+ require 'autotest/restart'
1
2
  begin
2
3
  require 'autotest/fsevent'
3
4
  rescue LoadError
4
5
  end
5
6
 
7
+ Autotest.add_hook :initialize do |at|
8
+ at.testlib = 'minitest/unit'
9
+
10
+ def at.path_to_classname(s)
11
+ sep = File::SEPARATOR
12
+ f = s.sub(/^test#{sep}/, '').sub(/\.rb$/, '').split(sep)
13
+ f = f.map { |path| path.split(/_|(\d+)/).map { |seg| seg.capitalize }.join }
14
+ f = f.map { |path| path =~ /^Test/ ? path : "Test#{path}" }
15
+ f.join('::').sub 'Dnssd', 'DNSSD'
16
+ end
17
+ end
18
+
6
19
  Autotest.add_hook :run_command do |at|
7
20
  at.unit_diff = 'cat'
21
+
8
22
  if ENV['ONENINE']
9
23
  system "rake1.9 compile"
10
24
  else
@@ -1,12 +1,31 @@
1
- === 1.2.0 / 2009-08-11
1
+ === 1.3 / 2009-08-18
2
2
 
3
- * 3 major enhancements
3
+ * 4 major enhancements
4
+ * Added DNSSD::Service.get_property
5
+ * Added DNSSD::Service#getaddrinfo
6
+ * Added DNSSD::Service#add_record
7
+ * Added DNSSD::Service#query_record
8
+
9
+ * 5 minor enhancements
10
+ * DNSSD::Reply#connect now uses DNSSD::Service#getaddrinfo (faster)
11
+ * DNSSD::Service#register behaves properly when blockless
12
+ * Broke up DNSSD::Reply into specific subclasses
13
+ * Added sample/query_record.rb
14
+ * sample/*.rb work with each other now for clarity of implementation
15
+
16
+ * 2 bug fixes
17
+ * Fix hierarchical domains like <tt>\.mac\.name.members.mac.com.</tt>
18
+ * Fix compilation against avahi 0.6.25
19
+
20
+ === 1.2 / 2009-08-11
21
+
22
+ * 4 major enhancements
4
23
  * DNSSD::Service is now directly instantiable
5
24
  * DNSSD.announce which registers a server socket you've created
6
25
  * DNSSD::Reply.connect which connects to a browsed service
7
26
  * Fix asynchronous service shutdown crash
8
27
 
9
- * 3 minor enhancements
28
+ * 8 minor enhancements
10
29
  * DNSSD.resolve now optionally accepts a DNSSD::Reply from DNSSD.browse
11
30
  * Use rb_thread_wait_fd instead of custom rb_thread_select code
12
31
  * DNSSD::Reply#protocol and DNSSD::Reply#service_name
@@ -8,15 +8,25 @@ ext/dnssd/dnssd.h
8
8
  ext/dnssd/errors.c
9
9
  ext/dnssd/extconf.rb
10
10
  ext/dnssd/flags.c
11
+ ext/dnssd/record.c
11
12
  ext/dnssd/service.c
12
13
  lib/dnssd.rb
13
14
  lib/dnssd/flags.rb
15
+ lib/dnssd/record.rb
14
16
  lib/dnssd/reply.rb
17
+ lib/dnssd/reply/addr_info.rb
18
+ lib/dnssd/reply/browse.rb
19
+ lib/dnssd/reply/domain.rb
20
+ lib/dnssd/reply/query_record.rb
21
+ lib/dnssd/reply/register.rb
22
+ lib/dnssd/reply/resolve.rb
15
23
  lib/dnssd/service.rb
16
24
  lib/dnssd/text_record.rb
17
25
  sample/browse.rb
18
26
  sample/enumerate_domains.rb
27
+ sample/getaddrinfo.rb
19
28
  sample/growl.rb
29
+ sample/query_record.rb
20
30
  sample/register.rb
21
31
  sample/resolve.rb
22
32
  sample/resolve_ichat.rb
@@ -24,5 +34,10 @@ sample/server.rb
24
34
  sample/socket.rb
25
35
  test/test_dnssd.rb
26
36
  test/test_dnssd_flags.rb
37
+ test/test_dnssd_record.rb
27
38
  test/test_dnssd_reply.rb
39
+ test/test_dnssd_reply_browse.rb
40
+ test/test_dnssd_reply_query_record.rb
41
+ test/test_dnssd_reply_resolve.rb
42
+ test/test_dnssd_service.rb
28
43
  test/test_dnssd_text_record.rb
data/README.txt CHANGED
@@ -2,11 +2,13 @@
2
2
 
3
3
  * http://rubyforge.org/projects/dnssd
4
4
  * http://github.com/tenderlove/dnssd
5
+ * http://developer.apple.com/documentation/Networking/Conceptual/dns_discovery_api/Introduction.html
5
6
 
6
7
  == DESCRIPTION:
7
8
 
8
9
  DNS Service Discovery (aka Bonjour, MDNS) API for Ruby. Implements browsing,
9
- resolving, registration and domain enumeration.
10
+ resolving, registration and domain enumeration. Supports avahi's DNSSD
11
+ compatibility layer for avahi 0.6.25 or newer.
10
12
 
11
13
  == FEATURES/PROBLEMS:
12
14
 
@@ -16,7 +18,7 @@ resolving, registration and domain enumeration.
16
18
 
17
19
  == SYNOPSIS:
18
20
 
19
- See the sample directory (Hint: gem contents --prefix dnssd)
21
+ See the sample directory (Hint: <tt>gem contents --prefix dnssd</tt>)
20
22
 
21
23
  Registering a service:
22
24
 
@@ -35,15 +37,37 @@ Browsing services:
35
37
  == REQUIREMENTS:
36
38
 
37
39
  * OS X
38
- * The dns-sd library on other operating systems (or dns-sd shim)
40
+ * The dns-sd library on other operating systems
41
+ * avahi 0.6.25+
39
42
 
40
43
  == INSTALL:
41
44
 
42
45
  sudo gem install dnssd
43
46
 
47
+ If you have dnssd installed in a non-standard location you can use the build
48
+ options --with-dnssd-dir and --with-dnssd-lib:
49
+
50
+ sudo gem install dnssd -- \
51
+ --with-dnssd-dir=/path/to/dnssd \
52
+ --with-dnssd-lib=/path/to/lib/dnssd
53
+
54
+ Using the default Bonjour SDK install for Windows, the command to build
55
+ the Ruby dnssd extension will look like this:
56
+
57
+ # Windows 2000 or Windows XP
58
+ sudo gem install dnssd -- \
59
+ --with-dnssd-dir=c:/progra~1/bonjou~1 \
60
+ --with-dnssd-lib=c:/progra~1/bonjou~1/lib/win32
61
+
62
+ # Windows Vista and later
63
+ sudo gem install dnssd -- \
64
+ --with-dnssd-dir=c:/progra~2/bonjou~1 \
65
+ --with-dnssd-lib=c:/progra~2/bonjou~1/lib/win32
66
+
44
67
  == LICENSE:
45
68
 
46
69
  Copyright (c) 2004 Chad Fowler, Charles Mills, Rich Kilmer
70
+
47
71
  Copyright (c) 2009 Phil Hagelberg, Aaron Patterson, Eric Hodel
48
72
 
49
73
  Licensed under the ruby license
data/Rakefile CHANGED
@@ -10,12 +10,12 @@ Hoe.plugin :git
10
10
  HOE = Hoe.spec 'dnssd' do
11
11
  self.rubyforge_name = 'dnssd'
12
12
 
13
+ developer 'Eric Hodel', 'drbrain@segment.net'
14
+ developer 'Aaron Patterson', 'aaronp@rubyforge.org'
15
+ developer 'Phil Hagelberg', 'phil@hagelb.org'
13
16
  developer 'Chad Fowler', 'chad@chadfowler.com'
14
17
  developer 'Charles Mills', ''
15
18
  developer 'Rich Kilmer', ''
16
- developer 'Phil Hagelberg', 'phil@hagelb.org'
17
- developer 'Aaron Patterson', 'aaronp@rubyforge.org'
18
- developer 'Eric Hodel', 'drbrain@segment.net'
19
19
 
20
20
  spec_extras[:extensions] = 'ext/dnssd/extconf.rb'
21
21
 
@@ -23,13 +23,14 @@ HOE = Hoe.spec 'dnssd' do
23
23
 
24
24
  extra_dev_deps << ['hoe-seattlerb', '~> 1.2']
25
25
  extra_dev_deps << ['minitest', '~> 1.4']
26
- extra_dev_deps << ['rake-complier', '~> 0.6']
26
+ extra_dev_deps << ['rake-compiler', '~> 0.6']
27
27
  end
28
28
 
29
29
  require 'rake/extensiontask'
30
30
 
31
31
  Rake::ExtensionTask.new 'dnssd', HOE.spec do |ext|
32
32
  ext.lib_dir = File.join 'lib', 'dnssd'
33
+ ext.config_options << '--with-warnings'
33
34
  end
34
35
 
35
36
  task :test => :compile
@@ -2,6 +2,7 @@
2
2
 
3
3
  void Init_DNSSD_Errors(void);
4
4
  void Init_DNSSD_Flags(void);
5
+ void Init_DNSSD_Record(void);
5
6
  void Init_DNSSD_Service(void);
6
7
 
7
8
  /*
@@ -82,9 +83,11 @@ Init_dnssd(void) {
82
83
  rb_define_const(mDNSSD, "InterfaceLocalOnly",
83
84
  ULONG2NUM(kDNSServiceInterfaceIndexLocalOnly));
84
85
 
86
+ #ifdef kDNSServiceInterfaceIndexUnicast
85
87
  /* Unicast interfaces */
86
88
  rb_define_const(mDNSSD, "InterfaceUnicast",
87
89
  ULONG2NUM(kDNSServiceInterfaceIndexUnicast));
90
+ #endif
88
91
 
89
92
  rb_define_singleton_method(mDNSSD, "getservbyport", dnssd_getservbyport, -1);
90
93
 
@@ -93,6 +96,7 @@ Init_dnssd(void) {
93
96
 
94
97
  Init_DNSSD_Errors();
95
98
  Init_DNSSD_Flags();
99
+ Init_DNSSD_Record();
96
100
  Init_DNSSD_Service();
97
101
  }
98
102
 
@@ -4,27 +4,22 @@
4
4
  #include <ruby.h>
5
5
  #include <dns_sd.h>
6
6
 
7
- /* for if_indextoname() and other unix networking functions */
8
- #ifdef HAVE_UNISTD_H
9
- #include <unistd.h>
10
- #endif
11
- #ifdef HAVE_SYS_TYPES_H
7
+ #include <arpa/inet.h> /* htons ntohs */
8
+ #include <sys/socket.h> /* struct sockaddr_in */
9
+ #include <netdb.h> /* getservbyport */
10
+
11
+ /* if_indextoname and if_nametoindex */
12
+ #ifdef HAVE_IPHLPAPI_H
13
+ #include <iphlpapi.h> /* Vista and newer */
14
+ #else
12
15
  #include <sys/types.h>
13
- #endif
14
- #ifdef HAVE_SYS_SOCKET_H
15
- #include <sys/socket.h>
16
- #endif
17
- #ifdef HAVE_SYS_PARAM_H
18
- #include <sys/param.h>
19
- #endif
20
- #ifdef HAVE_NET_IF_H
21
16
  #include <net/if.h>
22
17
  #endif
23
- #ifdef HAVE_SYS_IF_H
24
- #include <sys/if.h>
25
- #endif
26
- #ifdef HAVE_NETDB_H
27
- #include <netdb.h>
18
+
19
+ #ifdef HAVE_ST_SIN_LEN
20
+ #define SIN_LEN(si) (si)->sin_len
21
+ #else
22
+ #define SIN_LEN(si) sizeof(struct sockaddr_in)
28
23
  #endif
29
24
 
30
25
  extern VALUE eDNSSDError;
@@ -1,5 +1,4 @@
1
1
  #include "dnssd.h"
2
- #include <assert.h>
3
2
 
4
3
  VALUE eDNSSDError;
5
4
  static VALUE eDNSSDUnknownError;
@@ -11,8 +10,13 @@ static VALUE dnssd_errors[DNSSD_ERROR_END - DNSSD_ERROR_START];
11
10
 
12
11
  static void
13
12
  dnssd_errors_store(VALUE error, DNSServiceErrorType err) {
14
- assert(DNSSD_ERROR_START <= err && err <= DNSSD_ERROR_END);
15
- dnssd_errors[err - DNSSD_ERROR_START] = error;
13
+ if (DNSSD_ERROR_START <= err && err <= DNSSD_ERROR_END) {
14
+ dnssd_errors[err - DNSSD_ERROR_START] = error;
15
+ } else {
16
+ rb_raise(eDNSSDError,
17
+ "invalid error number %d (expected between %d and %d)",
18
+ err, DNSSD_ERROR_START, DNSSD_ERROR_END);
19
+ }
16
20
  }
17
21
 
18
22
  void
@@ -107,6 +111,7 @@ Init_DNSSD_Errors(void) {
107
111
  error_class = rb_define_class_under(mDNSSD, "BadTimeError", eDNSSDError);
108
112
  dnssd_errors_store(error_class, kDNSServiceErr_BadTime);
109
113
 
114
+ #ifdef HAVE_KDNSSERVICEERR_BADSIG
110
115
  error_class = rb_define_class_under(mDNSSD, "BadSigError", eDNSSDError);
111
116
  dnssd_errors_store(error_class, kDNSServiceErr_BadSig);
112
117
 
@@ -124,4 +129,5 @@ Init_DNSSD_Errors(void) {
124
129
 
125
130
  error_class = rb_define_class_under(mDNSSD, "NATPortMappingDisabled", eDNSSDError);
126
131
  dnssd_errors_store(error_class, kDNSServiceErr_NATPortMappingDisabled);
132
+ #endif
127
133
  }
@@ -1,59 +1,66 @@
1
- #!/usr/bin/env ruby
2
- # :stopdoc:
3
- #
4
- # Extension configuration script for DNS_SD C Extension.
1
+ require 'mkmf'
5
2
 
6
- def check_for_funcs(*funcs)
7
- funcs.flatten!
8
- funcs.each do |f|
9
- abort("need function #{f}") unless have_func(f)
10
- end
11
- end
3
+ $CFLAGS << ' -Wall' if with_config 'warnings'
12
4
 
13
- require "mkmf"
5
+ dir_config 'dnssd'
14
6
 
15
- $CFLAGS << " -Wall"
16
- $CFLAGS << " -DDEBUG" if $DEBUG
7
+ abort 'unable to find dnssd header' unless have_header 'dns_sd.h'
17
8
 
18
- libraries = {
19
- 'mdns' => 'DNSServiceRefSockFD',
20
- 'dns_sd' => 'DNSServiceRefSockFD',
21
- 'System' => 'DNSServiceRefSockFD'
22
- }.sort
9
+ have_library('dnssd') ||
10
+ have_library('dns_sd') ||
11
+ have_library('mdns') ||
12
+ have_library('System') ||
13
+ abort('unable to find dnssd library')
23
14
 
24
- dnssd_found = libraries.any? do |library, function|
25
- have_library library, function
26
- end
15
+ have_macro('htons', 'arpa/inet.h') ||
16
+ have_func('htons', 'arpa/inet.h') ||
17
+ abort("couldn't find htons")
27
18
 
28
- unless dnssd_found then
29
- abort "Couldn't find DNSSD in libraries #{libraries.keys.join ', '}"
30
- end
19
+ have_macro('ntohs', 'arpa/inet.h') ||
20
+ have_func('ntohs', 'arpa/inet.h') ||
21
+ abort("couldn't find ntohs")
31
22
 
32
- have_header "dns_sd.h" or abort "can't find the rendezvous client headers"
23
+ # These functions live in netioapi.h on Windows, not net/if.h. The MSDN
24
+ # documentation says to include iphlpapi.h, not netioapi.h directly.
25
+ #
26
+ # Note, however, that these functions only exist on Vista/Server 2008 or later.
27
+ # On Windows XP and earlier you will have to define a custom version of each
28
+ # function using native functions, such as ConvertInterfaceIndexToLuid() and
29
+ # ConvertInterfaceLuidToNameA().
30
+ #
31
+ if have_header 'iphlpapi.h' then
32
+ have_func('if_indextoname', %w[iphlpapi.h netioapi.h]) &&
33
+ have_func('if_nametoindex', %w[iphlpapi.h netioapi.h]) ||
34
+ abort('unable to find if_indextoname or if_nametoindex')
35
+ else
36
+ have_func('if_indextoname', %w[sys/types.h sys/socket.h net/if.h]) &&
37
+ have_func('if_nametoindex', %w[sys/types.h sys/socket.h net/if.h]) ||
38
+ abort('unable to find if_indextoname or if_nametoindex')
39
+ end
33
40
 
34
- have_header "unistd.h"
35
- have_header "sys/types.h"
36
- have_header "sys/socket.h"
37
- have_header "sys/param.h"
38
- have_header "sys/if.h"
39
- have_header "net/if.h"
40
- have_header "arpa/inet.h"
41
- have_header "netdb.h"
41
+ have_func('getservbyport', 'netdb.h') ||
42
+ abort('unable to find getservbyport')
42
43
 
43
- abort "need function #{f}" unless have_macro("htons") || have_func("htons")
44
- abort "need function #{f}" unless have_macro("ntohs") || have_func("ntohs")
44
+ have_type('struct sockaddr_in', 'netinet/in.h') ||
45
+ abort('unable to find struct sockaddr_in')
45
46
 
46
- check_for_funcs "if_indextoname", "if_nametoindex"
47
- have_func "gethostname"
47
+ have_struct_member 'struct sockaddr_in', 'sin_len', 'netinet/in.h'
48
+ # otherwise, use sizeof()
48
49
 
49
- s1 = check_sizeof "void*"
50
- s2 = check_sizeof("DNSServiceFlags", "dns_sd.h") or
51
- abort("can't determine sizeof(DNSServiceFlags)")
50
+ puts
51
+ puts 'checking for missing avahi features'
52
+ # avahi 0.6.25 is missing these functions
53
+ have_func 'DNSServiceGetProperty', 'dns_sd.h'
54
+ have_func 'DNSServiceGetAddrInfo', 'dns_sd.h'
52
55
 
53
- # need to make sure storing unsigned integer in void * is OK.
54
- s1 >= s2 or abort("sizeof(void*) < sizeof(DNSServiceFlags) please contact the authors!")
56
+ # avahi 0.6.25 is missing these flags
57
+ have_func 'kDNSServiceFlagsForce', 'dns_sd.h'
58
+ have_func 'kDNSServiceFlagsNonBrowsable', 'dns_sd.h'
59
+ have_func 'kDNSServiceFlagsReturnIntermediates', 'dns_sd.h'
60
+ have_func 'kDNSServiceFlagsShareConnection', 'dns_sd.h'
55
61
 
56
- create_makefile "dnssd"
62
+ # avahi 0.6.25 is missing errors after BadTime
63
+ have_func 'kDNSServiceErr_BadSig', 'dns_sd.h'
57
64
 
58
- # :startdoc:
65
+ create_makefile 'dnssd'
59
66
 
@@ -1,31 +1,43 @@
1
1
  #include "dnssd.h"
2
2
 
3
3
  /* dnssd flags, flag IDs, flag names */
4
- #define DNSSD_MAX_FLAGS 13
4
+ #define DNSSD_MAX_FLAGS 15
5
5
 
6
6
  static const DNSServiceFlags dnssd_flag[DNSSD_MAX_FLAGS] = {
7
7
  kDNSServiceFlagsMoreComing,
8
-
9
8
  kDNSServiceFlagsAdd,
10
9
  kDNSServiceFlagsDefault,
11
-
12
10
  kDNSServiceFlagsNoAutoRename,
13
-
14
11
  kDNSServiceFlagsShared,
15
12
  kDNSServiceFlagsUnique,
16
-
17
13
  kDNSServiceFlagsBrowseDomains,
18
14
  kDNSServiceFlagsRegistrationDomains,
19
-
20
15
  kDNSServiceFlagsLongLivedQuery,
21
-
22
16
  kDNSServiceFlagsAllowRemoteQuery,
17
+ kDNSServiceFlagsForceMulticast
18
+ #ifdef HAVE_KDNSSERVICEFLAGSFORCE
19
+ , kDNSServiceFlagsForce
20
+ #else
21
+ , (DNSServiceFlags)NULL
22
+ #endif
23
23
 
24
- kDNSServiceFlagsForceMulticast,
24
+ #ifdef HAVE_KDNSSERVICEFLAGSRETURNINTERMEDIATES
25
+ , kDNSServiceFlagsReturnIntermediates
26
+ #else
27
+ , (DNSServiceFlags)NULL
28
+ #endif
25
29
 
26
- kDNSServiceFlagsForce,
30
+ #ifdef HAVE_KDNSSERVICEFLAGSNONBROWSABLE
31
+ , kDNSServiceFlagsNonBrowsable
32
+ #else
33
+ , (DNSServiceFlags)NULL
34
+ #endif
27
35
 
28
- kDNSServiceFlagsReturnIntermediates
36
+ #ifdef HAVE_KDNSSERVICEFLAGSSHARECONNECTION
37
+ , kDNSServiceFlagsShareConnection
38
+ #else
39
+ , (DNSServiceFlags)NULL
40
+ #endif
29
41
  };
30
42
 
31
43
  static const char *dnssd_flag_name[DNSSD_MAX_FLAGS] = {
@@ -41,7 +53,9 @@ static const char *dnssd_flag_name[DNSSD_MAX_FLAGS] = {
41
53
  "allow_remote_query",
42
54
  "force_multicast",
43
55
  "force",
44
- "return_intermediates"
56
+ "return_intermediates",
57
+ "non_browsable",
58
+ "share_connection"
45
59
  };
46
60
 
47
61
  void
@@ -54,7 +68,7 @@ Init_DNSSD_Flags(void) {
54
68
  cDNSSDFlags = rb_define_class_under(mDNSSD, "Flags", rb_cObject);
55
69
 
56
70
  /* flag constants */
57
- #if DNSSD_MAX_FLAGS != 13
71
+ #if DNSSD_MAX_FLAGS != 15
58
72
  #error The code below needs to be updated.
59
73
  #endif
60
74
 
@@ -96,6 +110,24 @@ Init_DNSSD_Flags(void) {
96
110
  rb_define_const(cDNSSDFlags, "NoAutoRename",
97
111
  ULONG2NUM(kDNSServiceFlagsNoAutoRename));
98
112
 
113
+ #ifdef kDNSServiceFlagsShareConnection
114
+ /* For efficiency, clients that perform many concurrent operations may want
115
+ * to use a single Unix Domain Socket connection with the background daemon,
116
+ * instead of having a separate connection for each independent operation. To
117
+ * use this mode, clients first call DNSServiceCreateConnection(&MainRef) to
118
+ * initialize the main DNSServiceRef. For each subsequent operation that is
119
+ * to share that same connection, the client copies the MainRef, and then
120
+ * passes the address of that copy, setting the ShareConnection flag to tell
121
+ * the library that this DNSServiceRef is not a typical uninitialized
122
+ * DNSServiceRef; it's a copy of an existing DNSServiceRef whose connection
123
+ * information should be reused.
124
+ *
125
+ * NOTE: Not currently supported
126
+ */
127
+ rb_define_const(cDNSSDFlags, "ShareConnection",
128
+ ULONG2NUM(kDNSServiceFlagsShareConnection));
129
+ #endif
130
+
99
131
  /* Flag for registering individual records on a connected DNSSD::Service.
100
132
  *
101
133
  * DNSSD::Flags::Shared indicates that there may be multiple records with
@@ -148,6 +180,7 @@ Init_DNSSD_Flags(void) {
148
180
  rb_define_const(cDNSSDFlags, "ForceMulticast",
149
181
  ULONG2NUM(kDNSServiceFlagsForceMulticast));
150
182
 
183
+ #ifdef HAVE_KDNSSERVICEFLAGSFORCE
151
184
  /* Flag for signifying a "stronger" variant of an operation. Currently
152
185
  * defined only for DNSSD.reconfirm_record, where it forces a record to
153
186
  * be removed from the cache immediately, instead of querying for a few
@@ -158,7 +191,21 @@ Init_DNSSD_Flags(void) {
158
191
  * instance will disappear, and then re-appear moments later.
159
192
  */
160
193
  rb_define_const(cDNSSDFlags, "Force", ULONG2NUM(kDNSServiceFlagsForce));
194
+ #endif
195
+
196
+ #ifdef HAVE_KDNSSERVICEFLAGSNONBROWSABLE
197
+ /* A service registered with the NonBrowsable flag set can be resolved using
198
+ * DNSServiceResolve(), but will not be discoverable using
199
+ * DNSServiceBrowse(). This is for cases where the name is actually a GUID;
200
+ * it is found by other means; there is no end-user benefit to browsing to
201
+ * find a long list of opaque GUIDs. Using the NonBrowsable flag creates
202
+ * SRV+TXT without the cost of also advertising an associated PTR record.
203
+ */
204
+ rb_define_const(cDNSSDFlags, "NonBrowsable",
205
+ ULONG2NUM(kDNSServiceFlagsNonBrowsable));
206
+ #endif
161
207
 
208
+ #ifdef HAVE_KDNSSERVICEFLAGSRETURNINTERMEDIATES
162
209
  /* Flag for returning intermediate results. For example, if a query results
163
210
  * in an authoritative NXDomain (name does not exist) then that result is
164
211
  * returned to the client. However the query is not implicitly cancelled --
@@ -172,12 +219,19 @@ Init_DNSSD_Flags(void) {
172
219
  */
173
220
  rb_define_const(cDNSSDFlags, "ReturnIntermediates",
174
221
  ULONG2NUM(kDNSServiceFlagsReturnIntermediates));
222
+ #endif
223
+
224
+ #ifdef HAVE_KDNSSERVICEFLAGSSHARECONNECTION
225
+ rb_define_const(cDNSSDFlags, "ShareConnection",
226
+ ULONG2NUM(kDNSServiceFlagsShareConnection));
227
+ #endif
175
228
 
176
229
  flags_hash = rb_hash_new();
177
230
 
178
231
  for (i = 0; i < DNSSD_MAX_FLAGS; i++) {
179
- rb_hash_aset(flags_hash, rb_str_new2(dnssd_flag_name[i]),
180
- ULONG2NUM(dnssd_flag[i]));
232
+ if (dnssd_flag[i])
233
+ rb_hash_aset(flags_hash, rb_str_new2(dnssd_flag_name[i]),
234
+ ULONG2NUM(dnssd_flag[i]));
181
235
  }
182
236
 
183
237
  /* Hash of flags => flag_name */