net-mdns 0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,219 @@
1
+ =begin
2
+ Copyright (C) 2005 Sam Roberts
3
+
4
+ This library is free software; you can redistribute it and/or modify it
5
+ under the same terms as the ruby language itself, see the file COPYING for
6
+ details.
7
+ =end
8
+
9
+ require 'net/dns/resolv'
10
+
11
+ class Resolv
12
+ class DNS
13
+
14
+ class Message
15
+ # Returns true if message is a query.
16
+ def query?
17
+ qr == 0
18
+ end
19
+
20
+ # Returns true if message is a response.
21
+ def response?
22
+ !query?
23
+ end
24
+ end
25
+
26
+ end
27
+ end
28
+
29
+ class Resolv
30
+
31
+ # The default resolvers.
32
+ def self.default_resolvers
33
+ DefaultResolver.resolvers
34
+ end
35
+
36
+ # The resolvers configured.
37
+ attr_reader :resolvers
38
+
39
+ end
40
+
41
+ class Resolv
42
+ class DNS
43
+
44
+ class Config
45
+ # A name that has a number of labels greater than than +ndots+ will be looked
46
+ # up directly. The default value of +ndots+ is 1, so "example" would not be
47
+ # looked up directly, but "example.com" would be (it has 1 dot). Names ending in a dot, like
48
+ # "org.", will always be looked up directly, regardless of the setting of ndots.
49
+ attr_reader :ndots
50
+ # A series of search suffixes to use if the name being looked up does not end
51
+ # in a dot.
52
+ attr_reader :search
53
+ # The list of nameservers to query, should be dotted IP addresses, not
54
+ # domain names.
55
+ attr_reader :nameservers
56
+ end
57
+
58
+ end
59
+ end
60
+
61
+ class Resolv
62
+ class DNS
63
+ module Label
64
+
65
+ class Str
66
+ # Str is-a String, allow it to be compared to one.
67
+ def to_str
68
+ return @string
69
+ end
70
+ # Case-insensitive comparison.
71
+ def <=>(s)
72
+ @downcase <=> s.downcase
73
+ end
74
+ end
75
+
76
+ end
77
+ end
78
+ end
79
+
80
+
81
+ class Resolv
82
+ class DNS
83
+
84
+ class Name
85
+ # Append +arg+ to this Name. +arg+ can be a String or a Name.
86
+ #
87
+ # Returns +self+.
88
+ def <<(arg)
89
+ arg = Name.create(arg)
90
+ @labels.concat(arg.to_a)
91
+ @absolute = arg.absolute?
92
+ self
93
+ end
94
+
95
+ # Returns a new Name formed by concatenating +self+ with +arg+. +arg+ can
96
+ # be a String or a Name.
97
+ def +(arg)
98
+ arg = Name.create(arg)
99
+ Name.new(@labels + arg.to_a, arg.absolute?)
100
+ end
101
+
102
+ # Set whether +self+ is absolute or not. This is particularly useful when
103
+ # creating a Name from a String, since the trailing "." is rarely used in
104
+ # string representations of domain names, even when the domain name is
105
+ # fully qualified. This makes them very difficult to compare to a Name
106
+ # returned from the DNS record decoders, because DNS names are always
107
+ # absolute.
108
+ def absolute=(abs)
109
+ @absolute = abs ? true : false
110
+ end
111
+
112
+ # Returns whether two names are equal, disregarding the absolute? property
113
+ # of the names.
114
+ #
115
+ # Note that this differs from #==, which does not consider two names
116
+ # equal if they differ in absoluteness.
117
+ def equal?(name)
118
+ n = Name.create(name)
119
+
120
+ @labels == n.to_a
121
+ end
122
+ end
123
+
124
+ end
125
+ end
126
+
127
+
128
+ class Resolv
129
+ class DNS
130
+
131
+ # DNS names are hierarchical in a similar sense to ruby classes/modules,
132
+ # and the comparison operators are defined similarly to those of Module. A
133
+ # name is +<+ another if it is a subdomain of it.
134
+ # www.example.com < example.com # -> true
135
+ # example.com < example.com # -> false
136
+ # example.com <= example.com # -> true
137
+ # com < example.com # -> false
138
+ # bar.com < example.com # -> nil
139
+ class Name
140
+ def related?(name)
141
+ n = Name.create(name)
142
+
143
+ l = length < n.length ? length : n.length
144
+
145
+ @labels[-l, l] == n.to_a[-l, l]
146
+ end
147
+
148
+ def lt?(name)
149
+ n = Name.create(name)
150
+ length > n.length && to_a[-n.length, n.length] == n.to_a
151
+ end
152
+
153
+
154
+ # Summary:
155
+ # name < other => true, false, or nil
156
+ #
157
+ # Returns true if +name+ is a subdomain of +other+. Returns
158
+ # <code>nil</code> if there's no relationship between the two.
159
+ def <(name)
160
+ n = Name.create(name)
161
+
162
+ return nil unless self.related?(n)
163
+
164
+ lt?(n)
165
+ end
166
+
167
+ # Summary:
168
+ # name > other => true, false, or nil
169
+ #
170
+ # Same as +other < name+, see #<.
171
+ def >(name)
172
+ n = Name.create(name)
173
+
174
+ n < self
175
+ end
176
+
177
+ # Summary:
178
+ # name <= other => true, false, or nil
179
+ #
180
+ # Returns true if +name+ is a subdomain of +other+ or is the same as
181
+ # +other+. Returns <code>nil</code> if there's no relationship between
182
+ # the two.
183
+ def <=(name)
184
+ n = Name.create(name)
185
+ self.equal?(n) || self < n
186
+ end
187
+
188
+ # Summary:
189
+ # name >= other => true, false, or nil
190
+ #
191
+ # Returns true if +name+ is an ancestor of +other+, or the two DNS names
192
+ # are the same. Returns <code>nil</code> if there's no relationship
193
+ # between the two.
194
+ def >=(name)
195
+ n = Name.create(name)
196
+ self.equal?(n) || self > n
197
+ end
198
+
199
+ # Summary:
200
+ # name <=> other => -1, 0, +1, nil
201
+ #
202
+ # Returns -1 if +name+ is a subdomain of +other+, 0 if
203
+ # +name+ is the same as +other+, and +1 if +other+ is a subdomain of
204
+ # +name+, or nil if +name+ has no relationship with +other+.
205
+ def <=>(name)
206
+ n = Name.create(name)
207
+
208
+ return nil unless self.related?(n)
209
+
210
+ return -1 if self.lt?(n)
211
+ return +1 if n.lt?(self)
212
+ # must be #equal?
213
+ return 0
214
+ end
215
+ end
216
+
217
+ end
218
+ end
219
+
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.8.11
3
+ specification_version: 1
4
+ name: net-mdns
5
+ version: !ruby/object:Gem::Version
6
+ version: "0.4"
7
+ date: 2006-05-30 00:00:00 -07:00
8
+ summary: DNS-SD and mDNS implementation for ruby
9
+ require_paths:
10
+ - lib
11
+ email: sroberts@uniserve.com
12
+ homepage: http://dnssd.rubyforge.org/net-mdns/
13
+ rubyforge_project:
14
+ description:
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: false
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ authors:
29
+ - Sam Roberts
30
+ files:
31
+ - lib/net/dns.rb
32
+ - lib/net/dns/mdns-sd.rb
33
+ - lib/net/dns/mdns.rb
34
+ - lib/net/dns/resolv-mdns.rb
35
+ - lib/net/dns/resolv-replace.rb
36
+ - lib/net/dns/resolv.rb
37
+ - lib/net/dns/resolvx.rb
38
+ test_files: []
39
+
40
+ rdoc_options: []
41
+
42
+ extra_rdoc_files: []
43
+
44
+ executables: []
45
+
46
+ extensions: []
47
+
48
+ requirements: []
49
+
50
+ dependencies: []
51
+