dnssd 1.3.4 → 1.4

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
Binary file
@@ -1,3 +1,8 @@
1
+ === 1.4 / 2010-09-07
2
+
3
+ * Minor enhancements
4
+ * Where Encoding is available dnssd now converts to/from UTF-8.
5
+
1
6
  === 1.3.4 / 2010-08-29
2
7
 
3
8
  * Bug fixes
@@ -2,6 +2,7 @@
2
2
  #define RDNSSD_INCLUDED
3
3
 
4
4
  #include <ruby.h>
5
+
5
6
  #include <dns_sd.h>
6
7
 
7
8
  #include <arpa/inet.h> /* htons ntohs */
@@ -22,6 +23,21 @@
22
23
  #define SIN_LEN(si) sizeof(struct sockaddr_in)
23
24
  #endif
24
25
 
26
+ #ifdef HAVE_RUBY_ENCODING_H
27
+ #include <ruby/encoding.h>
28
+ #define dnssd_utf8_cstr(str, to) \
29
+ do {\
30
+ VALUE utf8;\
31
+ utf8 = rb_str_encode(str, rb_enc_from_encoding(rb_utf8_encoding()),\
32
+ 0, Qnil);\
33
+ to = StringValueCStr(utf8);\
34
+ } while (0)
35
+ #else
36
+ #define dnssd_utf8_cstr(str, to) \
37
+ do { to = StringValueCStr(str); } while (0)
38
+ #define rb_enc_associate(a, b) do {} while (0)
39
+ #endif
40
+
25
41
  extern VALUE eDNSSDError;
26
42
 
27
43
  void dnssd_check_error_code(DNSServiceErrorType e);
@@ -45,6 +45,7 @@ else
45
45
  abort('unable to find if_indextoname or if_nametoindex')
46
46
  end
47
47
 
48
+ # HACK prefer Socket.getservbyport in 1.9
48
49
  have_func('getservbyport', 'netdb.h') ||
49
50
  abort('unable to find getservbyport')
50
51
 
@@ -69,5 +70,10 @@ have_func 'kDNSServiceFlagsShareConnection', 'dns_sd.h'
69
70
  # avahi 0.6.25 is missing errors after BadTime
70
71
  have_func 'kDNSServiceErr_BadSig', 'dns_sd.h'
71
72
 
73
+ puts
74
+ puts 'checking for ruby features'
75
+ have_header 'ruby/encoding.h'
76
+
77
+ puts
72
78
  create_makefile 'dnssd/dnssd'
73
79
 
@@ -61,6 +61,7 @@ dnssd_service_free(void *ptr) {
61
61
  static VALUE
62
62
  create_fullname(const char *name, const char *regtype,
63
63
  const char *domain) {
64
+ VALUE fullname;
64
65
  char buffer[kDNSServiceMaxDomainName];
65
66
 
66
67
  if (DNSServiceConstructFullName(buffer, name, regtype, domain)) {
@@ -69,7 +70,11 @@ create_fullname(const char *name, const char *regtype,
69
70
  }
70
71
 
71
72
  buffer[kDNSServiceMaxDomainName - 1] = '\000'; /* just in case */
72
- return rb_str_new2(buffer);
73
+
74
+ fullname = rb_str_new2(buffer);
75
+ rb_enc_associate(fullname, rb_utf8_encoding());
76
+
77
+ return fullname;
73
78
  }
74
79
 
75
80
  /*
@@ -95,9 +100,14 @@ create_fullname(const char *name, const char *regtype,
95
100
  */
96
101
 
97
102
  static VALUE
98
- dnssd_service_s_fullname(VALUE klass, VALUE name, VALUE type, VALUE domain) {
99
- return create_fullname(StringValueCStr(name), StringValueCStr(type),
100
- StringValueCStr(domain));
103
+ dnssd_service_s_fullname(VALUE klass, VALUE _name, VALUE _type, VALUE _domain) {
104
+ char * name, * type, * domain;
105
+
106
+ dnssd_utf8_cstr(_name, name);
107
+ dnssd_utf8_cstr(_type, type);
108
+ dnssd_utf8_cstr(_domain, domain);
109
+
110
+ return create_fullname(name, type, domain);
101
111
  }
102
112
 
103
113
  #ifdef HAVE_DNSSERVICEGETPROPERTY
@@ -109,12 +119,15 @@ dnssd_service_s_fullname(VALUE klass, VALUE name, VALUE type, VALUE domain) {
109
119
  * DNSSD is DaemonVersion
110
120
  */
111
121
  static VALUE
112
- dnssd_service_s_get_property(VALUE klass, VALUE property) {
122
+ dnssd_service_s_get_property(VALUE klass, VALUE _property) {
123
+ char * property;
113
124
  uint32_t result = 0;
114
125
  uint32_t size = sizeof(result);
115
126
  DNSServiceErrorType e;
116
127
 
117
- e = DNSServiceGetProperty(StringValueCStr(property), (void *)&result, &size);
128
+ dnssd_utf8_cstr(_property, property);
129
+
130
+ e = DNSServiceGetProperty(property, (void *)&result, &size);
118
131
 
119
132
  dnssd_check_error_code(e);
120
133
 
@@ -274,8 +287,11 @@ dnssd_service_browse_reply(DNSServiceRef client, DNSServiceFlags flags,
274
287
  argv[1] = ULONG2NUM(flags);
275
288
  argv[2] = ULONG2NUM(interface);
276
289
  argv[3] = rb_str_new2(name);
290
+ rb_enc_associate(argv[3], rb_utf8_encoding());
277
291
  argv[4] = rb_str_new2(type);
292
+ rb_enc_associate(argv[4], rb_utf8_encoding());
278
293
  argv[5] = rb_str_new2(domain);
294
+ rb_enc_associate(argv[5], rb_utf8_encoding());
279
295
 
280
296
  reply = rb_class_new_instance(6, argv, cDNSSDReplyBrowse);
281
297
 
@@ -299,10 +315,10 @@ dnssd_service_browse(VALUE self, VALUE _flags, VALUE _interface, VALUE _type,
299
315
  DNSServiceErrorType e;
300
316
  DNSServiceRef *client;
301
317
 
302
- type = StringValueCStr(_type);
318
+ dnssd_utf8_cstr(_type, type);
303
319
 
304
320
  if (!NIL_P(_domain))
305
- domain = StringValueCStr(_domain);
321
+ dnssd_utf8_cstr(_domain, domain);
306
322
 
307
323
  if (!NIL_P(_flags))
308
324
  flags = (DNSServiceFlags)NUM2ULONG(_flags);
@@ -334,6 +350,7 @@ dnssd_service_enumerate_domains_reply(DNSServiceRef client,
334
350
  argv[1] = ULONG2NUM(flags);
335
351
  argv[2] = ULONG2NUM(interface);
336
352
  argv[3] = rb_str_new2(domain);
353
+ rb_enc_associate(argv[3], rb_utf8_encoding());
337
354
 
338
355
  reply = rb_class_new_instance(4, argv, cDNSSDReplyDomain);
339
356
 
@@ -385,7 +402,9 @@ dnssd_service_getaddrinfo_reply(DNSServiceRef client, DNSServiceFlags flags,
385
402
  argv[1] = ULONG2NUM(flags);
386
403
  argv[2] = ULONG2NUM(interface);
387
404
  argv[3] = rb_str_new2(host);
405
+ rb_enc_associate(argv[3], rb_utf8_encoding());
388
406
  argv[4] = rb_str_new((char *)address, SIN_LEN((struct sockaddr_in*)address));
407
+ rb_enc_associate(argv[4], rb_utf8_encoding());
389
408
  argv[5] = ULONG2NUM(ttl);
390
409
 
391
410
  reply = rb_class_new_instance(6, argv, cDNSSDReplyAddrInfo);
@@ -410,7 +429,7 @@ dnssd_service_getaddrinfo(VALUE self, VALUE _flags, VALUE _interface,
410
429
  DNSServiceErrorType e;
411
430
  DNSServiceRef *client;
412
431
 
413
- host = StringValueCStr(_host);
432
+ dnssd_utf8_cstr(_host, host);
414
433
 
415
434
  protocol = (DNSServiceProtocol)NUM2ULONG(_protocol);
416
435
 
@@ -446,9 +465,11 @@ dnssd_service_query_record_reply(DNSServiceRef client, DNSServiceFlags flags,
446
465
  argv[1] = ULONG2NUM(flags);
447
466
  argv[2] = ULONG2NUM(interface);
448
467
  argv[3] = rb_str_new2(fullname);
468
+ rb_enc_associate(argv[3], rb_utf8_encoding());
449
469
  argv[4] = UINT2NUM(rrtype);
450
470
  argv[5] = UINT2NUM(rrclass);
451
471
  argv[6] = rb_str_new((char *)rdata, rdlen);
472
+ rb_enc_associate(argv[6], rb_utf8_encoding());
452
473
  argv[7] = ULONG2NUM(ttl);
453
474
 
454
475
  reply = rb_class_new_instance(8, argv, cDNSSDReplyQueryRecord);
@@ -475,7 +496,7 @@ dnssd_service_query_record(VALUE self, VALUE _flags, VALUE _interface,
475
496
 
476
497
  flags = (DNSServiceFlags)NUM2ULONG(_flags);
477
498
  interface = (uint32_t)NUM2ULONG(_interface);
478
- fullname = StringValueCStr(_fullname);
499
+ dnssd_utf8_cstr(_fullname, fullname);
479
500
  rrtype = NUM2UINT(_rrtype);
480
501
  rrclass = NUM2UINT(_rrclass);
481
502
 
@@ -502,8 +523,11 @@ dnssd_service_register_reply(DNSServiceRef client, DNSServiceFlags flags,
502
523
  argv[0] = service;
503
524
  argv[1] = ULONG2NUM(flags);
504
525
  argv[2] = rb_str_new2(name);
526
+ rb_enc_associate(argv[2], rb_utf8_encoding());
505
527
  argv[3] = rb_str_new2(type);
528
+ rb_enc_associate(argv[3], rb_utf8_encoding());
506
529
  argv[4] = rb_str_new2(domain);
530
+ rb_enc_associate(argv[4], rb_utf8_encoding());
507
531
 
508
532
  reply = rb_class_new_instance(5, argv, cDNSSDReplyRegister);
509
533
 
@@ -530,14 +554,14 @@ dnssd_service_register(VALUE self, VALUE _flags, VALUE _interface, VALUE _name,
530
554
  DNSServiceErrorType e;
531
555
  DNSServiceRef *client;
532
556
 
533
- name = StringValueCStr(_name);
534
- type = StringValueCStr(_type);
557
+ dnssd_utf8_cstr(_name, name);
558
+ dnssd_utf8_cstr(_type, type);
535
559
 
536
560
  if (!NIL_P(_host))
537
- host = StringValueCStr(_host);
561
+ dnssd_utf8_cstr(_host, host);
538
562
 
539
563
  if (!NIL_P(_domain))
540
- domain = StringValueCStr(_domain);
564
+ dnssd_utf8_cstr(_domain, domain);
541
565
 
542
566
  port = htons((uint16_t)NUM2UINT(_port));
543
567
 
@@ -580,9 +604,12 @@ dnssd_service_resolve_reply(DNSServiceRef client, DNSServiceFlags flags,
580
604
  argv[1] = ULONG2NUM(flags);
581
605
  argv[2] = ULONG2NUM(interface);
582
606
  argv[3] = rb_str_new2(name);
607
+ rb_enc_associate(argv[3], rb_utf8_encoding());
583
608
  argv[4] = rb_str_new2(target);
609
+ rb_enc_associate(argv[4], rb_utf8_encoding());
584
610
  argv[5] = UINT2NUM(ntohs(port));
585
611
  argv[6] = rb_str_new((char *)txt_rec, txt_len);
612
+ rb_enc_associate(argv[6], rb_utf8_encoding());
586
613
 
587
614
  reply = rb_class_new_instance(7, argv, cDNSSDReplyResolve);
588
615
 
@@ -605,9 +632,9 @@ dnssd_service_resolve(VALUE self, VALUE _flags, VALUE _interface, VALUE _name,
605
632
  DNSServiceErrorType e;
606
633
  DNSServiceRef *client;
607
634
 
608
- name = StringValueCStr(_name);
609
- type = StringValueCStr(_type);
610
- domain = StringValueCStr(_domain);
635
+ dnssd_utf8_cstr(_name, name);
636
+ dnssd_utf8_cstr(_type, type);
637
+ dnssd_utf8_cstr(_domain, domain);
611
638
 
612
639
  if (!NIL_P(_flags))
613
640
  flags = (uint32_t)NUM2ULONG(_flags);
@@ -13,7 +13,7 @@ module DNSSD
13
13
  ##
14
14
  # The version of DNSSD you're using.
15
15
 
16
- VERSION = '1.3.4'
16
+ VERSION = '1.4'
17
17
 
18
18
  ##
19
19
  # Registers +socket+ with DNSSD as +name+. If +service+ is omitted it is
@@ -3,19 +3,42 @@ require 'dnssd'
3
3
 
4
4
  class TestDNSSDReplyBrowse < MiniTest::Unit::TestCase
5
5
 
6
- def setup
7
- @reply = DNSSD::Reply::Browse.new nil, 0, 0, "blackjack\\032no\\032port",
8
- '_blackjack._tcp', 'local'
9
- end
10
-
11
6
  def test_connect
7
+ reply = DNSSD::Reply::Browse.new nil, 0, 0, 'blackjack no port',
8
+ '_blackjack._tcp', 'local'
9
+
12
10
  port = Socket.getservbyname 'blackjack'
13
11
  server = TCPServer.new nil, port
14
12
  Thread.start do server.accept end
15
13
 
16
14
  DNSSD.announce server, 'blackjack no port'
17
15
 
18
- socket = @reply.connect
16
+ socket = reply.connect
17
+
18
+ assert_instance_of TCPSocket, socket
19
+ assert_equal port, socket.peeraddr[1]
20
+ ensure
21
+ socket.close if socket
22
+ server.close if server
23
+ end
24
+
25
+ def test_connect_encoding
26
+ skip 'Encoding not defined' unless Object.const_defined? :Encoding
27
+
28
+ reply = DNSSD::Reply::Browse.new nil, 0, 0, "\u00E9",
29
+ '_blackjack._tcp', 'local'
30
+
31
+
32
+ port = Socket.getservbyname 'blackjack'
33
+ server = TCPServer.new nil, port
34
+ Thread.start do server.accept end
35
+
36
+ name = "\u00E9"
37
+ name.encode! Encoding::ISO_8859_1
38
+
39
+ DNSSD.announce server, name
40
+
41
+ socket = reply.connect
19
42
 
20
43
  assert_instance_of TCPSocket, socket
21
44
  assert_equal port, socket.peeraddr[1]
@@ -13,37 +13,37 @@ class TestDNSSDReplyQueryRecord < MiniTest::Unit::TestCase
13
13
 
14
14
  def test_record_data_A
15
15
  qr = util_qr DNSSD::Record::A, @ipv4
16
-
16
+
17
17
  assert_equal IPAddr.new_ntoh(@ipv4), qr.record_data
18
18
  end
19
19
 
20
20
  def test_record_data_AAAA
21
21
  qr = util_qr DNSSD::Record::A, @ipv6
22
-
22
+
23
23
  assert_equal IPAddr.new_ntoh(@ipv6), qr.record_data
24
24
  end
25
25
 
26
26
  def test_record_data_CNAME
27
27
  qr = util_qr DNSSD::Record::CNAME, @nowhere
28
-
28
+
29
29
  assert_equal 'nowhere.example.', qr.record_data
30
30
  end
31
31
 
32
32
  def test_record_data_MX
33
33
  qr = util_qr DNSSD::Record::MX, "\000\010#{@nowhere}"
34
-
34
+
35
35
  assert_equal [8, 'nowhere.example.'], qr.record_data
36
36
  end
37
37
 
38
38
  def test_record_data_NS
39
39
  qr = util_qr DNSSD::Record::NS, @nowhere
40
-
40
+
41
41
  assert_equal 'nowhere.example.', qr.record_data
42
42
  end
43
43
 
44
44
  def test_record_data_PTR
45
45
  qr = util_qr DNSSD::Record::PTR, @nowhere
46
-
46
+
47
47
  assert_equal 'nowhere.example.', qr.record_data
48
48
  end
49
49
 
@@ -62,7 +62,7 @@ class TestDNSSDReplyQueryRecord < MiniTest::Unit::TestCase
62
62
  'nowhere.example.', 'me.nowhere.example.',
63
63
  serial, refresh, rtry, expire, minimum
64
64
  ]
65
-
65
+
66
66
  assert_equal expected, qr.record_data
67
67
  end
68
68
 
@@ -74,13 +74,13 @@ class TestDNSSDReplyQueryRecord < MiniTest::Unit::TestCase
74
74
  data = "#{[priority, weight, port].pack 'nnn'}#{@nowhere}"
75
75
 
76
76
  qr = util_qr DNSSD::Record::SRV, data
77
-
77
+
78
78
  assert_equal [1, 5, 1025, 'nowhere.example.'], qr.record_data
79
79
  end
80
80
 
81
81
  def test_record_data_TXT
82
82
  qr = util_qr DNSSD::Record::TXT, "\005Hello\006World!"
83
-
83
+
84
84
  assert_equal %w[Hello World!], qr.record_data
85
85
  end
86
86
 
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dnssd
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 7
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
- - 3
9
8
  - 4
10
- version: 1.3.4
9
+ version: "1.4"
11
10
  platform: ruby
12
11
  authors:
13
12
  - Eric Hodel
@@ -41,7 +40,7 @@ cert_chain:
41
40
  x52qPcexcYZR7w==
42
41
  -----END CERTIFICATE-----
43
42
 
44
- date: 2010-08-29 00:00:00 +09:00
43
+ date: 2010-09-07 00:00:00 -07:00
45
44
  default_executable:
46
45
  dependencies:
47
46
  - !ruby/object:Gem::Dependency
metadata.gz.sig CHANGED
Binary file