dnssd 1.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ require 'autotest/restart'
2
+
3
+ Autotest.add_hook :initialize do |at|
4
+ at.testlib = 'minitest/unit'
5
+
6
+ def at.path_to_classname(s)
7
+ sep = File::SEPARATOR
8
+ f = s.sub(/^test#{sep}/, '').sub(/\.rb$/, '').split(sep)
9
+ f = f.map { |path| path.split(/_|(\d+)/).map { |seg| seg.capitalize }.join }
10
+ f = f.map { |path| path =~ /^Test/ ? path : "Test#{path}" }
11
+ f.join('::').sub 'Dnssd', 'DNSSD'
12
+ end
13
+
14
+ end
15
+
@@ -1,3 +1,15 @@
1
+ === 1.1.0 / 2009-08-10
2
+
3
+ * 2 Major enhancements
4
+ * Packaging files that need to be here
5
+ * Increased the version number
6
+
7
+ * 1 Minor enhancement
8
+ * Less C codes
9
+
10
+ * 1 Bugfix
11
+ * Increased INTERNET!
12
+
1
13
  === 0.7.2 / 2009-08-05
2
14
 
3
15
  * 1 major enhancement
@@ -1,3 +1,4 @@
1
+ .autotest
1
2
  History.txt
2
3
  Manifest.txt
3
4
  README.txt
@@ -5,8 +6,21 @@ Rakefile
5
6
  ext/dnssd/dns_sd.h
6
7
  ext/dnssd/dnssd.c
7
8
  ext/dnssd/dnssd.h
8
- ext/dnssd/dnssd_service.c
9
- ext/dnssd/dnssd_structs.c
10
- ext/dnssd/dnssd_tr.c
9
+ ext/dnssd/errors.c
11
10
  ext/dnssd/extconf.rb
11
+ ext/dnssd/flags.c
12
+ ext/dnssd/service.c
12
13
  lib/dnssd.rb
14
+ lib/dnssd/flags.rb
15
+ lib/dnssd/reply.rb
16
+ lib/dnssd/service.rb
17
+ lib/dnssd/text_record.rb
18
+ sample/browse.rb
19
+ sample/growl.rb
20
+ sample/highlevel_api.rb
21
+ sample/register.rb
22
+ sample/resolve.rb
23
+ sample/resolve_ichat.rb
24
+ test/test_dnssd_flags.rb
25
+ test/test_dnssd_reply.rb
26
+ test/test_dnssd_text_record.rb
data/Rakefile CHANGED
@@ -5,6 +5,7 @@ require 'hoe'
5
5
 
6
6
  Hoe.plugin :minitest
7
7
  Hoe.plugin :email
8
+ Hoe.plugin :git
8
9
 
9
10
  HOE = Hoe.spec 'dnssd' do
10
11
  self.rubyforge_name = 'dnssd'
@@ -31,4 +32,6 @@ Rake::ExtensionTask.new 'dnssd', HOE.spec do |ext|
31
32
  ext.lib_dir = File.join 'lib', 'dnssd'
32
33
  end
33
34
 
35
+ task :test => :compile
36
+
34
37
  # vim: syntax=Ruby
@@ -1,141 +1,21 @@
1
- /*
2
- * == Authors
3
- * Chad Fowler, Charles Mills, Rich Kilmer
4
- *
5
- * == Copyright
6
- * Copyright (c) 2004 Chad Fowler, Charles Mills, Rich Kilmer
7
- * Licensed under the same terms as Ruby.
8
- * This software has absolutely no warranty.
9
- */
10
-
11
1
  #include "dnssd.h"
12
- #include <assert.h>
13
-
14
- VALUE mDNSSD;
15
- VALUE eDNSSDError;
16
- static VALUE eDNSSDUnknownError;
17
-
18
- #define DNSSD_ERROR_START (-65556)
19
- #define DNSSD_ERROR_END (-65536)
20
-
21
- static VALUE dnssd_errors[DNSSD_ERROR_END - DNSSD_ERROR_START];
22
-
23
- static void
24
- dnssd_errors_store(VALUE error, int num) {
25
- assert(DNSSD_ERROR_START <= num && num < DNSSD_ERROR_END);
26
- dnssd_errors[num - DNSSD_ERROR_START] = error;
27
- }
28
2
 
29
- void
30
- dnssd_check_error_code(DNSServiceErrorType e) {
31
- int num = (int)e;
32
- if (num) {
33
- if(DNSSD_ERROR_START <= num && num < DNSSD_ERROR_END) {
34
- rb_raise(dnssd_errors[num - DNSSD_ERROR_START],
35
- "DNSSD operation failed with error code: %d", num);
36
- } else {
37
- rb_raise(eDNSSDUnknownError,
38
- "DNSSD operation failed with unrecognized error code: %d", num);
39
- }
40
- }
41
- }
3
+ void Init_DNSSD_Errors(void);
4
+ void Init_DNSSD_Flags(void);
5
+ void Init_DNSSD_Service(void);
42
6
 
43
7
  void
44
- dnssd_instantiation_error(const char *what) {
45
- rb_raise(rb_eRuntimeError,
46
- "cannot instantiate %s, use DNSSD "
47
- "enumerate_domains(), browse(), resolve() or register() instead",
48
- what);
49
- }
50
-
51
- /*
52
- * Document-module: DNSSD
53
- *
54
- */
55
-
56
- static void
57
- Init_DNSSD(void) {
58
- VALUE error_class;
59
- mDNSSD = rb_define_module("DNSSD");
60
- eDNSSDError = rb_define_class_under(mDNSSD, "Error", rb_eStandardError);
8
+ Init_dnssd(void) {
9
+ VALUE mDNSSD = rb_define_module("DNSSD");
61
10
 
62
11
  /* Specifies all interfaces. */
63
12
  rb_define_const(mDNSSD, "InterfaceAny", ULONG2NUM(kDNSServiceInterfaceIndexAny));
13
+
64
14
  /* Specifies local interfaces only. */
65
15
  rb_define_const(mDNSSD, "InterfaceLocalOnly", ULONG2NUM(kDNSServiceInterfaceIndexLocalOnly));
66
16
 
67
- /* errors - these are 2 stepped (create and store) so that rdoc is happy */
68
- eDNSSDUnknownError = rb_define_class_under(mDNSSD, "UnknownError", eDNSSDError);
69
- dnssd_errors_store(eDNSSDUnknownError, -65537);
70
-
71
- error_class = rb_define_class_under(mDNSSD, "NoSuchNameError", eDNSSDError);
72
- dnssd_errors_store(error_class, -65538);
73
-
74
- dnssd_errors_store(rb_eNoMemError, -65539);
75
-
76
- error_class = rb_define_class_under(mDNSSD, "BadParamError", eDNSSDError);
77
- dnssd_errors_store(error_class, -65540);
78
-
79
- error_class = rb_define_class_under(mDNSSD, "BadReferenceError", eDNSSDError);
80
- dnssd_errors_store(error_class, -65541);
81
-
82
- error_class = rb_define_class_under(mDNSSD, "BadStateError", eDNSSDError);
83
- dnssd_errors_store(error_class, -65542);
84
-
85
- error_class = rb_define_class_under(mDNSSD, "BadFlagsError", eDNSSDError);
86
- dnssd_errors_store(error_class, -65543);
87
-
88
- error_class = rb_define_class_under(mDNSSD, "UnsupportedError", eDNSSDError);
89
- dnssd_errors_store(error_class, -65544);
90
-
91
- error_class = rb_define_class_under(mDNSSD, "NotInitializedError", eDNSSDError);
92
- dnssd_errors_store(error_class, -65545);
93
-
94
- error_class = rb_define_class_under(mDNSSD, "AlreadyRegisteredError", eDNSSDError);
95
- dnssd_errors_store(error_class, -65547);
96
-
97
- error_class = rb_define_class_under(mDNSSD, "NameConflictError", eDNSSDError);
98
- dnssd_errors_store(error_class, -65548);
99
-
100
- error_class = rb_define_class_under(mDNSSD, "InvalidError", eDNSSDError);
101
- dnssd_errors_store(error_class, -65549);
102
-
103
- error_class = rb_define_class_under(mDNSSD, "ClientIncompatibleError", eDNSSDError);
104
- dnssd_errors_store(error_class, -65551);
105
-
106
- error_class = rb_define_class_under(mDNSSD, "BadInterfaceIndexError", eDNSSDError);
107
- dnssd_errors_store(error_class, -65552);
108
-
109
- error_class = rb_define_class_under(mDNSSD, "ReferenceUsedError", eDNSSDError);
110
- dnssd_errors_store(error_class, -65553);
111
-
112
- error_class = rb_define_class_under(mDNSSD, "NoSuchRecordError", eDNSSDError);
113
- dnssd_errors_store(error_class, -65554);
114
-
115
- error_class = rb_define_class_under(mDNSSD, "NoAuthenticationError", eDNSSDError);
116
- dnssd_errors_store(error_class, -65555);
117
-
118
- error_class = rb_define_class_under(mDNSSD, "NoSuchKeyError", eDNSSDError);
119
- dnssd_errors_store(error_class, -65556);
120
- }
121
-
122
- /* Document-class: DNSSD::Error
123
- *
124
- * Base class of all DNS Service Discovery related errors.
125
- *
126
- */
127
-
128
- /* defined in other .c files */
129
- void Init_DNSSD_Service(void);
130
- void Init_DNSSD_TextRecord(void);
131
- void Init_DNSSD_Replies(void);
132
-
133
- void
134
- Init_dnssd(void) {
135
- /* called when library is required */
136
- Init_DNSSD();
17
+ Init_DNSSD_Errors();
18
+ Init_DNSSD_Flags();
137
19
  Init_DNSSD_Service();
138
- Init_DNSSD_TextRecord();
139
- Init_DNSSD_Replies();
140
20
  }
141
21
 
@@ -1,8 +1,3 @@
1
- /*
2
- * Copyright (c) 2004 Chad Fowler, Charles Mills, Rich Kilmer
3
- * Licenced under the same terms as Ruby.
4
- * This software has absolutely no warrenty.
5
- */
6
1
  #ifndef RDNSSD_INCLUDED
7
2
  #define RDNSSD_INCLUDED
8
3
 
@@ -29,32 +24,10 @@
29
24
  #include <sys/if.h>
30
25
  #endif
31
26
 
32
- extern VALUE mDNSSD;
33
27
  extern VALUE eDNSSDError;
34
28
 
35
29
  void dnssd_check_error_code(DNSServiceErrorType e);
36
30
  void dnssd_instantiation_error(const char *what);
37
31
 
38
- VALUE dnssd_create_fullname(const char *name, const char *regtype, const char *domain, int err_flag);
39
- VALUE dnssd_split_fullname(VALUE fullname);
40
-
41
- /* decodes a buffer, creating a new text record */
42
- VALUE dnssd_tr_new(long len, const char *buf);
43
-
44
- VALUE dnssd_tr_to_encoded_str(VALUE v);
45
-
46
- VALUE dnssd_domain_enum_new(VALUE service, DNSServiceFlags flags,
47
- uint32_t interface, const char *domain);
48
-
49
- VALUE dnssd_browse_new(VALUE service, DNSServiceFlags flags, uint32_t interface,
50
- const char *name, const char *regtype, const char *domain);
51
-
52
- VALUE dnssd_register_new(VALUE service, DNSServiceFlags flags, const char *name,
53
- const char *regtype, const char *domain);
54
-
55
- VALUE dnssd_resolve_new(VALUE service, DNSServiceFlags flags, uint32_t interface,
56
- const char *fullname, const char *host_target,
57
- uint16_t opaqueport, uint16_t txt_len, const char *txt_rec);
58
-
59
32
  #endif /* RDNSSD_INCLUDED */
60
33
 
@@ -0,0 +1,105 @@
1
+ #include "dnssd.h"
2
+ #include <assert.h>
3
+
4
+ VALUE eDNSSDError;
5
+ static VALUE eDNSSDUnknownError;
6
+
7
+ #define DNSSD_ERROR_START (-65556)
8
+ #define DNSSD_ERROR_END (-65536)
9
+
10
+ static VALUE dnssd_errors[DNSSD_ERROR_END - DNSSD_ERROR_START];
11
+
12
+ static void
13
+ dnssd_errors_store(VALUE error, int num) {
14
+ assert(DNSSD_ERROR_START <= num && num < DNSSD_ERROR_END);
15
+ dnssd_errors[num - DNSSD_ERROR_START] = error;
16
+ }
17
+
18
+ void
19
+ dnssd_check_error_code(DNSServiceErrorType e) {
20
+ int num = (int)e;
21
+ if (num) {
22
+ if(DNSSD_ERROR_START <= num && num < DNSSD_ERROR_END) {
23
+ rb_raise(dnssd_errors[num - DNSSD_ERROR_START],
24
+ "DNSSD operation failed with error code: %d", num);
25
+ } else {
26
+ rb_raise(eDNSSDUnknownError,
27
+ "DNSSD operation failed with unrecognized error code: %d", num);
28
+ }
29
+ }
30
+ }
31
+
32
+ void
33
+ dnssd_instantiation_error(const char *what) {
34
+ rb_raise(rb_eRuntimeError,
35
+ "cannot instantiate %s, use DNSSD "
36
+ "enumerate_domains(), browse(), resolve() or register() instead",
37
+ what);
38
+ }
39
+
40
+ /* Document-class: DNSSD::Error
41
+ *
42
+ * Base class of all DNS Service Discovery related errors.
43
+ *
44
+ */
45
+
46
+ void
47
+ Init_DNSSD_Errors(void) {
48
+ VALUE error_class;
49
+ VALUE mDNSSD = rb_define_module("DNSSD");
50
+
51
+ eDNSSDError = rb_define_class_under(mDNSSD, "Error", rb_eStandardError);
52
+
53
+ eDNSSDUnknownError = rb_define_class_under(mDNSSD, "UnknownError", eDNSSDError);
54
+ dnssd_errors_store(eDNSSDUnknownError, -65537);
55
+
56
+ error_class = rb_define_class_under(mDNSSD, "NoSuchNameError", eDNSSDError);
57
+ dnssd_errors_store(error_class, -65538);
58
+
59
+ dnssd_errors_store(rb_eNoMemError, -65539);
60
+
61
+ error_class = rb_define_class_under(mDNSSD, "BadParamError", eDNSSDError);
62
+ dnssd_errors_store(error_class, -65540);
63
+
64
+ error_class = rb_define_class_under(mDNSSD, "BadReferenceError", eDNSSDError);
65
+ dnssd_errors_store(error_class, -65541);
66
+
67
+ error_class = rb_define_class_under(mDNSSD, "BadStateError", eDNSSDError);
68
+ dnssd_errors_store(error_class, -65542);
69
+
70
+ error_class = rb_define_class_under(mDNSSD, "BadFlagsError", eDNSSDError);
71
+ dnssd_errors_store(error_class, -65543);
72
+
73
+ error_class = rb_define_class_under(mDNSSD, "UnsupportedError", eDNSSDError);
74
+ dnssd_errors_store(error_class, -65544);
75
+
76
+ error_class = rb_define_class_under(mDNSSD, "NotInitializedError", eDNSSDError);
77
+ dnssd_errors_store(error_class, -65545);
78
+
79
+ error_class = rb_define_class_under(mDNSSD, "AlreadyRegisteredError", eDNSSDError);
80
+ dnssd_errors_store(error_class, -65547);
81
+
82
+ error_class = rb_define_class_under(mDNSSD, "NameConflictError", eDNSSDError);
83
+ dnssd_errors_store(error_class, -65548);
84
+
85
+ error_class = rb_define_class_under(mDNSSD, "InvalidError", eDNSSDError);
86
+ dnssd_errors_store(error_class, -65549);
87
+
88
+ error_class = rb_define_class_under(mDNSSD, "ClientIncompatibleError", eDNSSDError);
89
+ dnssd_errors_store(error_class, -65551);
90
+
91
+ error_class = rb_define_class_under(mDNSSD, "BadInterfaceIndexError", eDNSSDError);
92
+ dnssd_errors_store(error_class, -65552);
93
+
94
+ error_class = rb_define_class_under(mDNSSD, "ReferenceUsedError", eDNSSDError);
95
+ dnssd_errors_store(error_class, -65553);
96
+
97
+ error_class = rb_define_class_under(mDNSSD, "NoSuchRecordError", eDNSSDError);
98
+ dnssd_errors_store(error_class, -65554);
99
+
100
+ error_class = rb_define_class_under(mDNSSD, "NoAuthenticationError", eDNSSDError);
101
+ dnssd_errors_store(error_class, -65555);
102
+
103
+ error_class = rb_define_class_under(mDNSSD, "NoSuchKeyError", eDNSSDError);
104
+ dnssd_errors_store(error_class, -65556);
105
+ }
@@ -15,16 +15,21 @@ require "mkmf"
15
15
  $CFLAGS << " -Wall"
16
16
  $CFLAGS << " -DDEBUG" if $DEBUG
17
17
 
18
- unless RUBY_PLATFORM.include? "darwin"
19
- have_library( "mdns", "DNSServiceRefSockFD" ) or
20
- have_library( "dns_sd", "DNSServiceRefSockFD" ) or
21
- abort( "can't find rendezvous library" )
18
+ libraries = {
19
+ 'mdns' => 'DNSServiceRefSockFD',
20
+ 'dns_sd' => 'DNSServiceRefSockFD',
21
+ 'System' => 'DNSServiceRefSockFD'
22
+ }.sort
23
+
24
+ dnssd_found = libraries.any? do |library, function|
25
+ have_library library, function
22
26
  end
23
27
 
24
- #have_library( "dns-sd", "DNSServiceRefSockFD" ) or
25
- # abort( "Can't find rendezvous client library" )
28
+ unless dnssd_found then
29
+ abort "Couldn't find DNSSD in libraries #{libraries.keys.join ', '}"
30
+ end
26
31
 
27
- have_header("dns_sd.h") or abort("can't find the rendezvous client headers")
32
+ have_header "dns_sd.h" or abort "can't find the rendezvous client headers"
28
33
 
29
34
  have_header "unistd.h"
30
35
  have_header "sys/types.h"
@@ -0,0 +1,124 @@
1
+ #include "dnssd.h"
2
+
3
+ /* dns sd flags, flag ID's, flag names */
4
+ #define DNSSD_MAX_FLAGS 9
5
+
6
+ static const DNSServiceFlags dnssd_flag[DNSSD_MAX_FLAGS] = {
7
+ kDNSServiceFlagsMoreComing,
8
+
9
+ kDNSServiceFlagsAdd,
10
+ kDNSServiceFlagsDefault,
11
+
12
+ kDNSServiceFlagsNoAutoRename,
13
+
14
+ kDNSServiceFlagsShared,
15
+ kDNSServiceFlagsUnique,
16
+
17
+ kDNSServiceFlagsBrowseDomains,
18
+ kDNSServiceFlagsRegistrationDomains,
19
+
20
+ kDNSServiceFlagsLongLivedQuery
21
+ };
22
+
23
+ static const char *dnssd_flag_name[DNSSD_MAX_FLAGS] = {
24
+ "more_coming",
25
+ "add",
26
+ "default",
27
+ "no_auto_rename",
28
+ "shared",
29
+ "unique",
30
+ "browse_domains",
31
+ "registration_domains",
32
+ "long_lived_query"
33
+ };
34
+
35
+ void
36
+ Init_DNSSD_Flags(void) {
37
+ int i;
38
+ VALUE flags_hash;
39
+ VALUE cDNSSDFlags;
40
+ VALUE mDNSSD = rb_define_module("DNSSD");
41
+
42
+ cDNSSDFlags = rb_define_class_under(mDNSSD, "Flags", rb_cObject);
43
+
44
+ /* flag constants */
45
+ #if DNSSD_MAX_FLAGS != 9
46
+ #error The code below needs to be updated.
47
+ #endif
48
+
49
+ /* MoreComing indicates that at least one more result is queued and will be
50
+ * delivered following immediately after this one.
51
+ *
52
+ * Applications should not update their UI to display browse results when the
53
+ * MoreComing flag is set, because this would result in a great deal of ugly
54
+ * flickering on the screen. Applications should instead wait until
55
+ * MoreComing is not set, and then update their UI.
56
+ *
57
+ * When MoreComing is not set, that doesn't mean there will be no more
58
+ * answers EVER, just that there are no more answers immediately available
59
+ * right now at this instant. If more answers become available in the future
60
+ * they will be delivered as usual.
61
+ */
62
+ rb_define_const(cDNSSDFlags, "MoreComing",
63
+ ULONG2NUM(kDNSServiceFlagsMoreComing));
64
+
65
+ /* Applies only to enumeration. An enumeration callback with the
66
+ * DNSSD::Flags::Add flag NOT set indicates a DNSSD::Flags::Remove, i.e. the
67
+ * domain is no longer valid.
68
+ */
69
+ rb_define_const(cDNSSDFlags, "Add", ULONG2NUM(kDNSServiceFlagsAdd));
70
+
71
+ /* Applies only to enumeration and is only valid in conjunction with Add
72
+ */
73
+ rb_define_const(cDNSSDFlags, "Default", ULONG2NUM(kDNSServiceFlagsDefault));
74
+
75
+ /* Flag for specifying renaming behavior on name conflict when registering
76
+ * non-shared records.
77
+ *
78
+ * By default, name conflicts are automatically handled by renaming the
79
+ * service. DNSSD::Flags::NoAutoRename overrides this behavior - with this
80
+ * flag set, name conflicts will result in a callback. The NoAutoRename flag
81
+ * is only valid if a name is explicitly specified when registering a service
82
+ * (ie the default name is not used.)
83
+ */
84
+ rb_define_const(cDNSSDFlags, "NoAutoRename",
85
+ ULONG2NUM(kDNSServiceFlagsNoAutoRename));
86
+
87
+ /* Flag for registering individual records on a connected DNSServiceRef.
88
+ *
89
+ * DNSSD::Flags::Shared indicates that there may be multiple records with
90
+ * this name on the network (e.g. PTR records). DNSSD::Flags::Unique
91
+ * indicates that the record's name is to be unique on the network (e.g. SRV
92
+ * records). (DNSSD::Flags::Shared and DNSSD::Flags::Unique are currently
93
+ * not used by the Ruby API.)
94
+ */
95
+ rb_define_const(cDNSSDFlags, "Shared", ULONG2NUM(kDNSServiceFlagsShared));
96
+ rb_define_const(cDNSSDFlags, "Unique", ULONG2NUM(kDNSServiceFlagsUnique));
97
+
98
+ /* DNSSD::Flags::BrowseDomains enumerates domains recommended for browsing
99
+ */
100
+ rb_define_const(cDNSSDFlags, "BrowseDomains",
101
+ ULONG2NUM(kDNSServiceFlagsBrowseDomains));
102
+
103
+ /* DNSSD::Flags::RegistrationDomains enumerates domains recommended for
104
+ * registration.
105
+ */
106
+
107
+ rb_define_const(cDNSSDFlags, "RegistrationDomains",
108
+ ULONG2NUM(kDNSServiceFlagsRegistrationDomains));
109
+
110
+ /* Flag for creating a long-lived unicast query for the DNSDS.query_record()
111
+ * (currently not part of the Ruby API). */
112
+ rb_define_const(cDNSSDFlags, "LongLivedQuery",
113
+ ULONG2NUM(kDNSServiceFlagsLongLivedQuery));
114
+
115
+ flags_hash = rb_hash_new();
116
+
117
+ for (i = 0; i < DNSSD_MAX_FLAGS; i++) {
118
+ rb_hash_aset(flags_hash, rb_str_new2(dnssd_flag_name[i]),
119
+ ULONG2NUM(dnssd_flag[i]));
120
+ }
121
+
122
+ rb_define_const(cDNSSDFlags, "FLAGS", flags_hash);
123
+ }
124
+