dnssd 1.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +15 -0
- data/History.txt +12 -0
- data/Manifest.txt +17 -3
- data/Rakefile +3 -0
- data/ext/dnssd/dnssd.c +8 -128
- data/ext/dnssd/dnssd.h +0 -27
- data/ext/dnssd/errors.c +105 -0
- data/ext/dnssd/extconf.rb +12 -7
- data/ext/dnssd/flags.c +124 -0
- data/ext/dnssd/{dnssd_service.c → service.c} +350 -248
- data/lib/dnssd.rb +4 -1
- data/lib/dnssd/flags.rb +104 -0
- data/lib/dnssd/reply.rb +87 -0
- data/lib/dnssd/service.rb +15 -0
- data/lib/dnssd/text_record.rb +69 -0
- data/sample/browse.rb +11 -0
- data/sample/growl.rb +14 -0
- data/sample/highlevel_api.rb +30 -0
- data/sample/register.rb +30 -0
- data/sample/resolve.rb +13 -0
- data/sample/resolve_ichat.rb +36 -0
- data/test/test_dnssd_reply.rb +64 -0
- data/test/test_dnssd_text_record.rb +83 -0
- metadata +23 -28
- data.tar.gz.sig +0 -0
- data/ext/dnssd/dnssd_structs.c +0 -397
- data/ext/dnssd/dnssd_tr.c +0 -248
- metadata.gz.sig +0 -0
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'dnssd'
|
3
|
+
|
4
|
+
class TestDNSSDTextRecord < MiniTest::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@TR = DNSSD::TextRecord
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_encode
|
11
|
+
tr = @TR.new
|
12
|
+
|
13
|
+
tr['key1'] = nil
|
14
|
+
tr['key2'] = ''
|
15
|
+
tr['key3'] = 'value'
|
16
|
+
|
17
|
+
assert_equal "\004key1\005key2=\012key3=value", tr.encode
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_encode_long
|
21
|
+
tr = @TR.new
|
22
|
+
|
23
|
+
tr['key'] = 'X' * 252
|
24
|
+
|
25
|
+
e = assert_raises DNSSD::Error do
|
26
|
+
tr.encode
|
27
|
+
end
|
28
|
+
|
29
|
+
assert_equal 'key value pair at \'key\' too large to encode', e.message
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_decode
|
33
|
+
text_record = "\fstatus=avail\006email=\004jid=\005node=\tversion=1\ttxtvers=1\016port.p2pj=5298\0161st=Eric Hodel\005nick=\004AIM=\005last=-phsh=59272d0c3ed947b4660fabc0dad9d67647507299\004ext="
|
34
|
+
|
35
|
+
expected = {
|
36
|
+
'status' => 'avail',
|
37
|
+
'ext' => '',
|
38
|
+
'node' => '',
|
39
|
+
'nick' => '',
|
40
|
+
'last' => '',
|
41
|
+
'txtvers' => '1',
|
42
|
+
'AIM' => '',
|
43
|
+
'jid' => '',
|
44
|
+
'phsh' => '59272d0c3ed947b4660fabc0dad9d67647507299',
|
45
|
+
'version' => '1',
|
46
|
+
'1st' => 'Eric Hodel',
|
47
|
+
'port.p2pj' => '5298',
|
48
|
+
'email' => ''
|
49
|
+
}
|
50
|
+
|
51
|
+
assert_equal expected, @TR.new(text_record).to_hash
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_decode_bad
|
55
|
+
assert_raises ArgumentError do
|
56
|
+
@TR.new("\x01") # length past end-of-record
|
57
|
+
end
|
58
|
+
|
59
|
+
assert_raises ArgumentError do
|
60
|
+
# no key
|
61
|
+
@TR.new("\x01=")
|
62
|
+
end
|
63
|
+
|
64
|
+
assert_raises ArgumentError do
|
65
|
+
# 0-length key
|
66
|
+
@TR.new("\x02=v")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_decode_empty
|
71
|
+
assert_equal({}, @TR.new("").to_hash)
|
72
|
+
assert_equal({}, @TR.new("\x00").to_hash)
|
73
|
+
assert_equal({}, @TR.new("\x00\x00").to_hash)
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_decode_value
|
77
|
+
assert_equal({ 'k' => nil }, @TR.new("\x01k").to_hash)
|
78
|
+
assert_equal({ 'k' => '' }, @TR.new("\x02k=").to_hash)
|
79
|
+
assert_equal({ 'k' => 'v' }, @TR.new("\x03k=v").to_hash)
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dnssd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chad Fowler
|
@@ -12,30 +12,9 @@ authors:
|
|
12
12
|
- Eric Hodel
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
|
-
cert_chain:
|
16
|
-
- |
|
17
|
-
-----BEGIN CERTIFICATE-----
|
18
|
-
MIIDNjCCAh6gAwIBAgIBADANBgkqhkiG9w0BAQUFADBBMRAwDgYDVQQDDAdkcmJy
|
19
|
-
YWluMRgwFgYKCZImiZPyLGQBGRYIc2VnbWVudDcxEzARBgoJkiaJk/IsZAEZFgNu
|
20
|
-
ZXQwHhcNMDcxMjIxMDIwNDE0WhcNMDgxMjIwMDIwNDE0WjBBMRAwDgYDVQQDDAdk
|
21
|
-
cmJyYWluMRgwFgYKCZImiZPyLGQBGRYIc2VnbWVudDcxEzARBgoJkiaJk/IsZAEZ
|
22
|
-
FgNuZXQwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCbbgLrGLGIDE76
|
23
|
-
LV/cvxdEzCuYuS3oG9PrSZnuDweySUfdp/so0cDq+j8bqy6OzZSw07gdjwFMSd6J
|
24
|
-
U5ddZCVywn5nnAQ+Ui7jMW54CYt5/H6f2US6U0hQOjJR6cpfiymgxGdfyTiVcvTm
|
25
|
-
Gj/okWrQl0NjYOYBpDi+9PPmaH2RmLJu0dB/NylsDnW5j6yN1BEI8MfJRR+HRKZY
|
26
|
-
mUtgzBwF1V4KIZQ8EuL6I/nHVu07i6IkrpAgxpXUfdJQJi0oZAqXurAV3yTxkFwd
|
27
|
-
g62YrrW26mDe+pZBzR6bpLE+PmXCzz7UxUq3AE0gPHbiMXie3EFE0oxnsU3lIduh
|
28
|
-
sCANiQ8BAgMBAAGjOTA3MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQW
|
29
|
-
BBS5k4Z75VSpdM0AclG2UvzFA/VW5DANBgkqhkiG9w0BAQUFAAOCAQEAHagT4lfX
|
30
|
-
kP/hDaiwGct7XPuVGbrOsKRVD59FF5kETBxEc9UQ1clKWngf8JoVuEoKD774dW19
|
31
|
-
bU0GOVWO+J6FMmT/Cp7nuFJ79egMf/gy4gfUfQMuvfcr6DvZUPIs9P/TlK59iMYF
|
32
|
-
DIOQ3DxdF3rMzztNUCizN4taVscEsjCcgW6WkUJnGdqlu3OHWpQxZBJkBTjPCoc6
|
33
|
-
UW6on70SFPmAy/5Cq0OJNGEWBfgD9q7rrs/X8GGwUWqXb85RXnUVi/P8Up75E0ag
|
34
|
-
14jEc90kN+C7oI/AGCBN0j6JnEtYIEJZibjjDJTSMWlUKKkj30kq7hlUC2CepJ4v
|
35
|
-
x52qPcexcYZR7w==
|
36
|
-
-----END CERTIFICATE-----
|
15
|
+
cert_chain: []
|
37
16
|
|
38
|
-
date: 2009-08-
|
17
|
+
date: 2009-08-10 00:00:00 -07:00
|
39
18
|
default_executable:
|
40
19
|
dependencies:
|
41
20
|
- !ruby/object:Gem::Dependency
|
@@ -97,6 +76,7 @@ extra_rdoc_files:
|
|
97
76
|
- Manifest.txt
|
98
77
|
- README.txt
|
99
78
|
files:
|
79
|
+
- .autotest
|
100
80
|
- History.txt
|
101
81
|
- Manifest.txt
|
102
82
|
- README.txt
|
@@ -104,11 +84,24 @@ files:
|
|
104
84
|
- ext/dnssd/dns_sd.h
|
105
85
|
- ext/dnssd/dnssd.c
|
106
86
|
- ext/dnssd/dnssd.h
|
107
|
-
- ext/dnssd/
|
108
|
-
- ext/dnssd/dnssd_structs.c
|
109
|
-
- ext/dnssd/dnssd_tr.c
|
87
|
+
- ext/dnssd/errors.c
|
110
88
|
- ext/dnssd/extconf.rb
|
89
|
+
- ext/dnssd/flags.c
|
90
|
+
- ext/dnssd/service.c
|
111
91
|
- lib/dnssd.rb
|
92
|
+
- lib/dnssd/flags.rb
|
93
|
+
- lib/dnssd/reply.rb
|
94
|
+
- lib/dnssd/service.rb
|
95
|
+
- lib/dnssd/text_record.rb
|
96
|
+
- sample/browse.rb
|
97
|
+
- sample/growl.rb
|
98
|
+
- sample/highlevel_api.rb
|
99
|
+
- sample/register.rb
|
100
|
+
- sample/resolve.rb
|
101
|
+
- sample/resolve_ichat.rb
|
102
|
+
- test/test_dnssd_flags.rb
|
103
|
+
- test/test_dnssd_reply.rb
|
104
|
+
- test/test_dnssd_text_record.rb
|
112
105
|
has_rdoc: true
|
113
106
|
homepage: http://rubyforge.org/projects/dnssd
|
114
107
|
licenses: []
|
@@ -135,9 +128,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
128
|
requirements: []
|
136
129
|
|
137
130
|
rubyforge_project: dnssd
|
138
|
-
rubygems_version: 1.3.
|
131
|
+
rubygems_version: 1.3.4
|
139
132
|
signing_key:
|
140
133
|
specification_version: 3
|
141
134
|
summary: DNS Service Discovery (aka Bonjour, MDNS) API for Ruby
|
142
135
|
test_files:
|
143
136
|
- test/test_dnssd_flags.rb
|
137
|
+
- test/test_dnssd_reply.rb
|
138
|
+
- test/test_dnssd_text_record.rb
|
data.tar.gz.sig
DELETED
Binary file
|
data/ext/dnssd/dnssd_structs.c
DELETED
@@ -1,397 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* Copyright (c) 2004 Chad Fowler, Charles Mills, Rich Kilmer
|
3
|
-
* Licensed under the same terms as Ruby.
|
4
|
-
* This software has absolutely no warranty.
|
5
|
-
*/
|
6
|
-
#include "dnssd.h"
|
7
|
-
|
8
|
-
static VALUE cDNSSDFlags;
|
9
|
-
static VALUE cDNSSDReply;
|
10
|
-
|
11
|
-
static ID dnssd_iv_flags;
|
12
|
-
static ID dnssd_iv_interface;
|
13
|
-
static ID dnssd_iv_fullname;
|
14
|
-
static ID dnssd_iv_target;
|
15
|
-
static ID dnssd_iv_port;
|
16
|
-
static ID dnssd_iv_text_record;
|
17
|
-
static ID dnssd_iv_name;
|
18
|
-
static ID dnssd_iv_type;
|
19
|
-
static ID dnssd_iv_domain;
|
20
|
-
static ID dnssd_iv_service;
|
21
|
-
|
22
|
-
/* dns sd flags, flag ID's, flag names */
|
23
|
-
#define DNSSD_MAX_FLAGS 9
|
24
|
-
|
25
|
-
static const DNSServiceFlags dnssd_flag[DNSSD_MAX_FLAGS] = {
|
26
|
-
kDNSServiceFlagsMoreComing,
|
27
|
-
|
28
|
-
kDNSServiceFlagsAdd,
|
29
|
-
kDNSServiceFlagsDefault,
|
30
|
-
|
31
|
-
kDNSServiceFlagsNoAutoRename,
|
32
|
-
|
33
|
-
kDNSServiceFlagsShared,
|
34
|
-
kDNSServiceFlagsUnique,
|
35
|
-
|
36
|
-
kDNSServiceFlagsBrowseDomains,
|
37
|
-
kDNSServiceFlagsRegistrationDomains,
|
38
|
-
|
39
|
-
kDNSServiceFlagsLongLivedQuery
|
40
|
-
};
|
41
|
-
|
42
|
-
static const char *dnssd_flag_name[DNSSD_MAX_FLAGS] = {
|
43
|
-
"more_coming",
|
44
|
-
"add",
|
45
|
-
"default",
|
46
|
-
"no_auto_rename",
|
47
|
-
"shared",
|
48
|
-
"unique",
|
49
|
-
"browse_domains",
|
50
|
-
"registration_domains",
|
51
|
-
"long_lived_query"
|
52
|
-
};
|
53
|
-
|
54
|
-
static VALUE
|
55
|
-
dnssd_struct_inspect(VALUE self, VALUE data) {
|
56
|
-
VALUE buf = rb_str_buf_new(20 + RSTRING_LEN(data));
|
57
|
-
rb_str_buf_cat2(buf, "#<");
|
58
|
-
rb_str_buf_cat2(buf, rb_obj_classname(self));
|
59
|
-
if (RSTRING_LEN(data) > 0) {
|
60
|
-
rb_str_buf_cat2(buf, " ");
|
61
|
-
rb_str_buf_append(buf, data);
|
62
|
-
}
|
63
|
-
rb_str_buf_cat2(buf, ">");
|
64
|
-
return buf;
|
65
|
-
}
|
66
|
-
|
67
|
-
VALUE
|
68
|
-
dnssd_create_fullname(const char *name, const char *regtype, const char *domain, int err_flag) {
|
69
|
-
char buffer[kDNSServiceMaxDomainName];
|
70
|
-
if ( DNSServiceConstructFullName(buffer, name, regtype, domain) ) {
|
71
|
-
static const char msg[] = "could not construct full service name";
|
72
|
-
if (err_flag) {
|
73
|
-
rb_raise(rb_eArgError, msg);
|
74
|
-
} else {
|
75
|
-
VALUE buf;
|
76
|
-
rb_warn(msg);
|
77
|
-
/* just join them all */
|
78
|
-
buf = rb_str_buf_new2(name);
|
79
|
-
rb_str_buf_cat2(buf, regtype);
|
80
|
-
rb_str_buf_cat2(buf, domain);
|
81
|
-
return buf;
|
82
|
-
}
|
83
|
-
}
|
84
|
-
buffer[kDNSServiceMaxDomainName - 1] = '\000'; /* just in case */
|
85
|
-
return rb_str_new2(buffer);
|
86
|
-
}
|
87
|
-
|
88
|
-
VALUE
|
89
|
-
dnssd_split_fullname(VALUE fullname) {
|
90
|
-
static const char re[] = "(?:\\\\.|[^\\.])+\\.";
|
91
|
-
VALUE regexp = rb_reg_new(re, sizeof(re)-1, 0);
|
92
|
-
return rb_funcall2(fullname, rb_intern("scan"), 1, ®exp);
|
93
|
-
}
|
94
|
-
|
95
|
-
#if 0
|
96
|
-
static void
|
97
|
-
quote_and_append(VALUE buf, VALUE str)
|
98
|
-
{
|
99
|
-
const char *ptr;
|
100
|
-
long i, last_mark, len;
|
101
|
-
|
102
|
-
ptr = RSTRING_PTR(str);
|
103
|
-
len = RSTRING_LEN(str);
|
104
|
-
last_mark = 0;
|
105
|
-
/* last character should be '.' */
|
106
|
-
for (i=0; i<len-1; i++) {
|
107
|
-
if (ptr[i] == '.') {
|
108
|
-
/* write 1 extra character and replace it with '\\' */
|
109
|
-
rb_str_buf_cat(buf, ptr + last_mark, i + 1 - last_mark);
|
110
|
-
RSTRING_PTR(buf)[i] = '\\';
|
111
|
-
last_mark = i;
|
112
|
-
}
|
113
|
-
}
|
114
|
-
rb_str_buf_cat(buf, ptr + last_mark, len - last_mark);
|
115
|
-
}
|
116
|
-
#endif
|
117
|
-
|
118
|
-
static VALUE
|
119
|
-
dnssd_join_names(int argc, VALUE *argv) {
|
120
|
-
int i;
|
121
|
-
VALUE buf;
|
122
|
-
long len = 0;
|
123
|
-
|
124
|
-
for (i=0; i<argc; i++) {
|
125
|
-
argv[i] = StringValue(argv[i]);
|
126
|
-
len += RSTRING_LEN(argv[i]);
|
127
|
-
}
|
128
|
-
buf = rb_str_buf_new(len);
|
129
|
-
for (i=0; i<argc; i++) {
|
130
|
-
rb_str_buf_append(buf, argv[i]);
|
131
|
-
}
|
132
|
-
return buf;
|
133
|
-
}
|
134
|
-
|
135
|
-
static void
|
136
|
-
reply_add_names(VALUE self, const char *name,
|
137
|
-
const char *regtype, const char *domain) {
|
138
|
-
rb_ivar_set(self, dnssd_iv_name, rb_str_new2(name));
|
139
|
-
rb_ivar_set(self, dnssd_iv_type, rb_str_new2(regtype));
|
140
|
-
rb_ivar_set(self, dnssd_iv_domain, rb_str_new2(domain));
|
141
|
-
rb_ivar_set(self, dnssd_iv_fullname, dnssd_create_fullname(name, regtype, domain, 0));
|
142
|
-
}
|
143
|
-
|
144
|
-
static void
|
145
|
-
reply_add_names2(VALUE self, const char *fullname) {
|
146
|
-
VALUE fn = rb_str_new2(fullname);
|
147
|
-
VALUE ary = dnssd_split_fullname(fn);
|
148
|
-
VALUE type[2] = { rb_ary_entry(ary, 1), rb_ary_entry(ary, 2) };
|
149
|
-
|
150
|
-
rb_ivar_set(self, dnssd_iv_name, rb_ary_entry(ary, 0));
|
151
|
-
rb_ivar_set(self, dnssd_iv_type, dnssd_join_names(2, type));
|
152
|
-
rb_ivar_set(self, dnssd_iv_domain, rb_ary_entry(ary, -1));
|
153
|
-
rb_ivar_set(self, dnssd_iv_fullname, fn);
|
154
|
-
}
|
155
|
-
|
156
|
-
static void
|
157
|
-
reply_set_interface(VALUE self, uint32_t interface) {
|
158
|
-
VALUE if_value;
|
159
|
-
char buffer[IF_NAMESIZE];
|
160
|
-
if (if_indextoname(interface, buffer)) {
|
161
|
-
if_value = rb_str_new2(buffer);
|
162
|
-
} else {
|
163
|
-
if_value = ULONG2NUM(interface);
|
164
|
-
}
|
165
|
-
rb_ivar_set(self, dnssd_iv_interface, if_value);
|
166
|
-
}
|
167
|
-
|
168
|
-
static void
|
169
|
-
reply_set_tr(VALUE self, uint16_t txt_len, const char *txt_rec) {
|
170
|
-
rb_ivar_set(self, dnssd_iv_text_record, dnssd_tr_new((long)txt_len, txt_rec));
|
171
|
-
}
|
172
|
-
|
173
|
-
static VALUE
|
174
|
-
reply_new(VALUE service, DNSServiceFlags flags) {
|
175
|
-
VALUE self = rb_obj_alloc(cDNSSDReply);
|
176
|
-
rb_ivar_set(self, dnssd_iv_service, service);
|
177
|
-
rb_ivar_set(self, dnssd_iv_flags,
|
178
|
-
rb_funcall(cDNSSDFlags, rb_intern("new"), 1, flags));
|
179
|
-
return self;
|
180
|
-
}
|
181
|
-
|
182
|
-
VALUE
|
183
|
-
dnssd_domain_enum_new(VALUE service, DNSServiceFlags flags,
|
184
|
-
uint32_t interface, const char *domain) {
|
185
|
-
VALUE d, self = reply_new(service, flags);
|
186
|
-
reply_set_interface(self, interface);
|
187
|
-
d = rb_str_new2(domain);
|
188
|
-
rb_ivar_set(self, dnssd_iv_domain, d);
|
189
|
-
rb_ivar_set(self, dnssd_iv_fullname, d);
|
190
|
-
return self;
|
191
|
-
}
|
192
|
-
|
193
|
-
VALUE
|
194
|
-
dnssd_browse_new(VALUE service, DNSServiceFlags flags, uint32_t interface,
|
195
|
-
const char *name, const char *regtype, const char *domain) {
|
196
|
-
VALUE self = reply_new(service, flags);
|
197
|
-
reply_set_interface(self, interface);
|
198
|
-
reply_add_names(self, name, regtype, domain);
|
199
|
-
return self;
|
200
|
-
}
|
201
|
-
|
202
|
-
#if 0
|
203
|
-
static VALUE
|
204
|
-
dnssd_gethostname(void)
|
205
|
-
{
|
206
|
-
#if HAVE_GETHOSTNAME
|
207
|
-
#ifndef MAXHOSTNAMELEN
|
208
|
-
#define MAXHOSTNAMELEN 256
|
209
|
-
#endif
|
210
|
-
char buffer[MAXHOSTNAMELEN + 1];
|
211
|
-
if (gethostname(buffer, MAXHOSTNAMELEN))
|
212
|
-
return Qnil;
|
213
|
-
buffer[MAXHOSTNAMELEN] = '\000';
|
214
|
-
return rb_str_new2(buffer);
|
215
|
-
#else
|
216
|
-
return Qnil;
|
217
|
-
#endif
|
218
|
-
}
|
219
|
-
#endif
|
220
|
-
|
221
|
-
VALUE
|
222
|
-
dnssd_register_new(VALUE service, DNSServiceFlags flags, const char *name,
|
223
|
-
const char *regtype, const char *domain) {
|
224
|
-
VALUE self = reply_new(service, flags);
|
225
|
-
reply_add_names(self, name, regtype, domain);
|
226
|
-
/* HACK */
|
227
|
-
/* See HACK in dnssd_service.c */
|
228
|
-
rb_ivar_set(self, dnssd_iv_interface, rb_ivar_get(service, dnssd_iv_interface));
|
229
|
-
rb_ivar_set(self, dnssd_iv_port, rb_ivar_get(service, dnssd_iv_port));
|
230
|
-
rb_ivar_set(self, dnssd_iv_text_record, rb_ivar_get(service, dnssd_iv_text_record));
|
231
|
-
/********/
|
232
|
-
return self;
|
233
|
-
}
|
234
|
-
|
235
|
-
VALUE
|
236
|
-
dnssd_resolve_new(VALUE service, DNSServiceFlags flags, uint32_t interface,
|
237
|
-
const char *fullname, const char *host_target,
|
238
|
-
uint16_t opaqueport, uint16_t txt_len, const char *txt_rec) {
|
239
|
-
uint16_t port = ntohs(opaqueport);
|
240
|
-
VALUE self = reply_new(service, flags);
|
241
|
-
reply_set_interface(self, interface);
|
242
|
-
reply_add_names2(self, fullname);
|
243
|
-
rb_ivar_set(self, dnssd_iv_target, rb_str_new2(host_target));
|
244
|
-
rb_ivar_set(self, dnssd_iv_port, UINT2NUM(port));
|
245
|
-
reply_set_tr(self, txt_len, txt_rec);
|
246
|
-
return self;
|
247
|
-
}
|
248
|
-
|
249
|
-
/*
|
250
|
-
* call-seq:
|
251
|
-
* reply.inspect => string
|
252
|
-
*
|
253
|
-
*/
|
254
|
-
static VALUE
|
255
|
-
reply_inspect(VALUE self) {
|
256
|
-
VALUE fullname = rb_ivar_get(self, dnssd_iv_fullname);
|
257
|
-
return dnssd_struct_inspect(self, StringValue(fullname));
|
258
|
-
}
|
259
|
-
|
260
|
-
/*
|
261
|
-
* call-seq:
|
262
|
-
* DNSSD::Reply.new() => raises a RuntimeError
|
263
|
-
*
|
264
|
-
*/
|
265
|
-
static VALUE
|
266
|
-
reply_initialize(int argc, VALUE *argv, VALUE reply) {
|
267
|
-
dnssd_instantiation_error(rb_obj_classname(reply));
|
268
|
-
return Qnil;
|
269
|
-
}
|
270
|
-
|
271
|
-
void
|
272
|
-
Init_DNSSD_Replies(void) {
|
273
|
-
int i;
|
274
|
-
VALUE flags_hash;
|
275
|
-
/* hack so rdoc documents the project correctly */
|
276
|
-
#ifdef mDNSSD_RDOC_HACK
|
277
|
-
mDNSSD = rb_define_module("DNSSD");
|
278
|
-
#endif
|
279
|
-
|
280
|
-
dnssd_iv_flags = rb_intern("@flags");
|
281
|
-
dnssd_iv_interface = rb_intern("@interface");
|
282
|
-
dnssd_iv_fullname = rb_intern("@fullname");
|
283
|
-
dnssd_iv_target = rb_intern("@target");
|
284
|
-
dnssd_iv_port = rb_intern("@port");
|
285
|
-
dnssd_iv_text_record = rb_intern("@text_record");
|
286
|
-
dnssd_iv_name = rb_intern("@name");
|
287
|
-
dnssd_iv_type = rb_intern("@type");
|
288
|
-
dnssd_iv_domain = rb_intern("@domain");
|
289
|
-
dnssd_iv_service = rb_intern("@service");
|
290
|
-
|
291
|
-
cDNSSDFlags = rb_define_class_under(mDNSSD, "Flags", rb_cObject);
|
292
|
-
|
293
|
-
cDNSSDReply = rb_define_class_under(mDNSSD, "Reply", rb_cObject);
|
294
|
-
/* DNSSD::Reply objects can only be instantiated by
|
295
|
-
* DNSSD.browse(), DNSSD.register(), DNSSD.resolve(), DNSSD.enumerate_domains(). */
|
296
|
-
rb_define_method(cDNSSDReply, "initialize", reply_initialize, -1);
|
297
|
-
/* The service associated with the reply. See DNSSD::Service for more information. */
|
298
|
-
rb_define_attr(cDNSSDReply, "service", 1, 0);
|
299
|
-
/* Flags describing the reply. See DNSSD::Flags for more information. */
|
300
|
-
rb_define_attr(cDNSSDReply, "flags", 1, 0);
|
301
|
-
/* The service name. (Not used by DNSSD.enumerate_domains().) */
|
302
|
-
rb_define_attr(cDNSSDReply, "name", 1, 0);
|
303
|
-
/* The service type. (Not used by DNSSD.enumerate_domains().) */
|
304
|
-
rb_define_attr(cDNSSDReply, "type", 1, 0);
|
305
|
-
/* The service domain. */
|
306
|
-
rb_define_attr(cDNSSDReply, "domain", 1, 0);
|
307
|
-
/* The interface on which the service is available. (Used only by DNSSSD.resolve().) */
|
308
|
-
rb_define_attr(cDNSSDReply, "interface", 1, 0);
|
309
|
-
/* The full service domain name, in the form "<servicename>.<protocol>.<domain>.".
|
310
|
-
* (Any literal dots (".") are escaped with a backslash ("\."), and literal
|
311
|
-
* backslashes are escaped with a second backslash ("\\"), e.g. a web server
|
312
|
-
* named "Dr. Pepper" would have the fullname "Dr\.\032Pepper._http._tcp.local.".)
|
313
|
-
* See DNSSD::Service.fullname() for more information. */
|
314
|
-
rb_define_attr(cDNSSDReply, "fullname", 1, 0);
|
315
|
-
/* The service's primary text record, see DNSSD::TextRecord for more information. */
|
316
|
-
rb_define_attr(cDNSSDReply, "text_record", 1, 0);
|
317
|
-
/* The target hostname of the machine providing the service.
|
318
|
-
* This name can be passed to functions like Socket.gethostbyname()
|
319
|
-
* to identify the host's IP address. */
|
320
|
-
rb_define_attr(cDNSSDReply, "target", 1, 0);
|
321
|
-
/* The port on which connections are accepted for this service. */
|
322
|
-
rb_define_attr(cDNSSDReply, "port", 1, 0);
|
323
|
-
|
324
|
-
rb_define_method(cDNSSDReply, "inspect", reply_inspect, 0);
|
325
|
-
|
326
|
-
/* flag constants */
|
327
|
-
#if DNSSD_MAX_FLAGS != 9
|
328
|
-
#error The code below needs to be updated.
|
329
|
-
#endif
|
330
|
-
/* MoreComing indicates that at least one more result is queued and will be delivered following immediately after this one.
|
331
|
-
* Applications should not update their UI to display browse
|
332
|
-
* results when the MoreComing flag is set, because this would
|
333
|
-
* result in a great deal of ugly flickering on the screen.
|
334
|
-
* Applications should instead wait until until MoreComing is not set,
|
335
|
-
* and then update their UI.
|
336
|
-
* When MoreComing is not set, that doesn't mean there will be no more
|
337
|
-
* answers EVER, just that there are no more answers immediately
|
338
|
-
* available right now at this instant. If more answers become available
|
339
|
-
* in the future they will be delivered as usual.
|
340
|
-
*/
|
341
|
-
rb_define_const(cDNSSDFlags, "MoreComing", ULONG2NUM(kDNSServiceFlagsMoreComing));
|
342
|
-
|
343
|
-
|
344
|
-
/* Flags for domain enumeration and DNSSD.browse() reply callbacks.
|
345
|
-
* DNSSD::Flags::Default applies only to enumeration and is only valid in
|
346
|
-
* conjuction with DNSSD::Flags::Add. An enumeration callback with the DNSSD::Flags::Add
|
347
|
-
* flag NOT set indicates a DNSSD::Flags::Remove, i.e. the domain is no longer valid.
|
348
|
-
*/
|
349
|
-
rb_define_const(cDNSSDFlags, "Add", ULONG2NUM(kDNSServiceFlagsAdd));
|
350
|
-
rb_define_const(cDNSSDFlags, "Default", ULONG2NUM(kDNSServiceFlagsDefault));
|
351
|
-
|
352
|
-
/* Flag for specifying renaming behavior on name conflict when registering non-shared records.
|
353
|
-
* By default, name conflicts are automatically handled by renaming the service.
|
354
|
-
* DNSSD::Flags::NoAutoRename overrides this behavior - with this
|
355
|
-
* flag set, name conflicts will result in a callback. The NoAutoRename flag
|
356
|
-
* is only valid if a name is explicitly specified when registering a service
|
357
|
-
* (ie the default name is not used.)
|
358
|
-
*/
|
359
|
-
rb_define_const(cDNSSDFlags, "NoAutoRename", ULONG2NUM(kDNSServiceFlagsNoAutoRename));
|
360
|
-
|
361
|
-
/* Flag for registering individual records on a connected DNSServiceRef.
|
362
|
-
* DNSSD::Flags::Shared indicates that there may be multiple records
|
363
|
-
* with this name on the network (e.g. PTR records). DNSSD::Flags::Unique indicates that the
|
364
|
-
* record's name is to be unique on the network (e.g. SRV records).
|
365
|
-
* (DNSSD::Flags::Shared and DNSSD::Flags::Unique are currently not used by the Ruby API.)
|
366
|
-
*/
|
367
|
-
rb_define_const(cDNSSDFlags, "Shared", ULONG2NUM(kDNSServiceFlagsShared));
|
368
|
-
rb_define_const(cDNSSDFlags, "Unique", ULONG2NUM(kDNSServiceFlagsUnique));
|
369
|
-
|
370
|
-
/* Flags for specifying domain enumeration type in DNSSD.enumerate_domains()
|
371
|
-
* (currently not part of the Ruby API).
|
372
|
-
* DNSSD::Flags::BrowseDomains enumerates domains recommended for browsing,
|
373
|
-
* DNSSD::Flags::RegistrationDomains enumerates domains recommended for registration.
|
374
|
-
*/
|
375
|
-
rb_define_const(cDNSSDFlags, "BrowseDomains", ULONG2NUM(kDNSServiceFlagsBrowseDomains));
|
376
|
-
rb_define_const(cDNSSDFlags, "RegistrationDomains", ULONG2NUM(kDNSServiceFlagsRegistrationDomains));
|
377
|
-
|
378
|
-
/* Flag for creating a long-lived unicast query for the DNSDS.query_record()
|
379
|
-
* (currently not part of the Ruby API). */
|
380
|
-
rb_define_const(cDNSSDFlags, "LongLivedQuery", ULONG2NUM(kDNSServiceFlagsLongLivedQuery));
|
381
|
-
|
382
|
-
flags_hash = rb_hash_new();
|
383
|
-
|
384
|
-
for (i = 0; i < DNSSD_MAX_FLAGS; i++) {
|
385
|
-
rb_hash_aset(flags_hash, rb_str_new2(dnssd_flag_name[i]),
|
386
|
-
ULONG2NUM(dnssd_flag[i]));
|
387
|
-
}
|
388
|
-
|
389
|
-
rb_define_const(cDNSSDFlags, "FLAGS", flags_hash);
|
390
|
-
}
|
391
|
-
|
392
|
-
/* Document-class: DNSSD::Reply
|
393
|
-
*
|
394
|
-
* DNSSD::Reply is used to return information
|
395
|
-
*
|
396
|
-
*/
|
397
|
-
|