dnssd 0.7.1 → 1.0
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/History.txt +5 -0
- data/Manifest.txt +12 -0
- data/README.txt +48 -0
- data/Rakefile +34 -0
- data/ext/{dns_sd.h → dnssd/dns_sd.h} +0 -0
- data/ext/dnssd/dnssd.c +141 -0
- data/ext/dnssd/dnssd.h +60 -0
- data/ext/dnssd/dnssd_service.c +698 -0
- data/ext/dnssd/dnssd_structs.c +397 -0
- data/ext/dnssd/dnssd_tr.c +248 -0
- data/ext/dnssd/extconf.rb +51 -0
- data/lib/dnssd.rb +38 -25
- data/test/test_dnssd_flags.rb +152 -0
- metadata +107 -29
- metadata.gz.sig +0 -0
- data/ext/MANIFEST +0 -0
- data/ext/extconf.rb +0 -58
- data/ext/rdnssd.c +0 -150
- data/ext/rdnssd.h +0 -63
- data/ext/rdnssd_service.c +0 -712
- data/ext/rdnssd_structs.c +0 -710
- data/ext/rdnssd_tr.c +0 -257
- data/ext/run_rdoc +0 -4
data/ext/rdnssd_structs.c
DELETED
@@ -1,710 +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 "rdnssd.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
|
-
#define IsDNSSDFlags(obj) (rb_obj_is_kind_of(obj,cDNSSDFlags)==Qtrue)
|
23
|
-
#define VerifyDNSSDFlags(obj) \
|
24
|
-
do { \
|
25
|
-
if(!IsDNSSDFlags(obj)) rb_fatal(__FILE__":%d: bug in DNSSD",__LINE__); \
|
26
|
-
} while (0)
|
27
|
-
|
28
|
-
/* dns sd flags, flag ID's, flag names */
|
29
|
-
#define DNSSD_MAX_FLAGS 9
|
30
|
-
|
31
|
-
static const DNSServiceFlags dnssd_flag[DNSSD_MAX_FLAGS] = {
|
32
|
-
kDNSServiceFlagsMoreComing,
|
33
|
-
|
34
|
-
kDNSServiceFlagsAdd,
|
35
|
-
kDNSServiceFlagsDefault,
|
36
|
-
|
37
|
-
kDNSServiceFlagsNoAutoRename,
|
38
|
-
|
39
|
-
kDNSServiceFlagsShared,
|
40
|
-
kDNSServiceFlagsUnique,
|
41
|
-
|
42
|
-
kDNSServiceFlagsBrowseDomains,
|
43
|
-
kDNSServiceFlagsRegistrationDomains,
|
44
|
-
|
45
|
-
kDNSServiceFlagsLongLivedQuery
|
46
|
-
};
|
47
|
-
|
48
|
-
/* used to make sure only valid bits are set in a flag. */
|
49
|
-
#define DNSSD_FLAGS_MASK(f) \
|
50
|
-
( (f) & (kDNSServiceFlagsMoreComing | \
|
51
|
-
kDNSServiceFlagsAdd | kDNSServiceFlagsDefault | \
|
52
|
-
kDNSServiceFlagsNoAutoRename | kDNSServiceFlagsShared | \
|
53
|
-
kDNSServiceFlagsUnique | kDNSServiceFlagsBrowseDomains | \
|
54
|
-
kDNSServiceFlagsRegistrationDomains | kDNSServiceFlagsLongLivedQuery) )
|
55
|
-
|
56
|
-
static const char *dnssd_flag_name[DNSSD_MAX_FLAGS] = {
|
57
|
-
"more_coming",
|
58
|
-
"add",
|
59
|
-
"default",
|
60
|
-
"no_auto_rename",
|
61
|
-
"shared",
|
62
|
-
"unique",
|
63
|
-
"browse_domains",
|
64
|
-
"registration_domains",
|
65
|
-
"long_lived_query"
|
66
|
-
};
|
67
|
-
|
68
|
-
static void
|
69
|
-
dnssd_init_flags_methods(VALUE klass)
|
70
|
-
{
|
71
|
-
char buffer[128];
|
72
|
-
int i;
|
73
|
-
for (i=0; i<DNSSD_MAX_FLAGS; i++) {
|
74
|
-
unsigned long flag = (unsigned long)dnssd_flag[i];
|
75
|
-
const char *flag_name = dnssd_flag_name[i];
|
76
|
-
VALUE str;
|
77
|
-
size_t len;
|
78
|
-
len = snprintf(buffer, sizeof(buffer),
|
79
|
-
"def %s?; self & %lu end",
|
80
|
-
flag_name, flag);
|
81
|
-
str = rb_str_new(buffer, (long)len);
|
82
|
-
rb_mod_module_eval(1, &str, klass);
|
83
|
-
|
84
|
-
/* similar to attr_writer method for each flag */
|
85
|
-
len = snprintf(buffer, sizeof(buffer),
|
86
|
-
"def %s=(val); "
|
87
|
-
"if val then self.set_flag(%lu) else self.clear_flag(%lu) end; "
|
88
|
-
"val end", /* return val */
|
89
|
-
flag_name, flag, flag);
|
90
|
-
str = rb_str_new(buffer, (long)len);
|
91
|
-
rb_mod_module_eval(1, &str, klass);
|
92
|
-
}
|
93
|
-
}
|
94
|
-
|
95
|
-
static VALUE
|
96
|
-
dnssd_flags_alloc(VALUE klass)
|
97
|
-
{
|
98
|
-
/* no free function or mark function, initialize flags/data to 0 */
|
99
|
-
return Data_Wrap_Struct(klass, 0, 0, 0);
|
100
|
-
}
|
101
|
-
|
102
|
-
static VALUE
|
103
|
-
dnssd_flags_init(VALUE self, DNSServiceFlags flags)
|
104
|
-
{
|
105
|
-
VerifyDNSSDFlags(self);
|
106
|
-
/* note DNSSD_FLAGS_MASK() here */
|
107
|
-
RDATA(self)->data = (void*)DNSSD_FLAGS_MASK(flags);
|
108
|
-
return self;
|
109
|
-
}
|
110
|
-
|
111
|
-
static DNSServiceFlags
|
112
|
-
dnssd_get_flags(VALUE self)
|
113
|
-
{
|
114
|
-
VerifyDNSSDFlags(self);
|
115
|
-
return (DNSServiceFlags)RDATA(self)->data;
|
116
|
-
}
|
117
|
-
|
118
|
-
DNSServiceFlags
|
119
|
-
dnssd_to_flags(VALUE obj)
|
120
|
-
{
|
121
|
-
DNSServiceFlags flags = 0;
|
122
|
-
if (IsDNSSDFlags(obj)) {
|
123
|
-
flags = dnssd_get_flags(obj);
|
124
|
-
} else {
|
125
|
-
/* don't want to include any bits that aren't flags */
|
126
|
-
flags = DNSSD_FLAGS_MASK((DNSServiceFlags)NUM2ULONG(obj));
|
127
|
-
}
|
128
|
-
return flags;
|
129
|
-
}
|
130
|
-
|
131
|
-
/*
|
132
|
-
* call-seq:
|
133
|
-
* DNSSD::Flags.new() => flags
|
134
|
-
* DNSSD::Flags.new(flag1, flag2, ...) => union_of_flags
|
135
|
-
*
|
136
|
-
* Returns a new set of flags.
|
137
|
-
* In the first form an empty set of flags is created.
|
138
|
-
* In the second a set of flags containing the union of
|
139
|
-
* each flag (or set of flags) given is created.
|
140
|
-
*
|
141
|
-
* flags = Flags.new()
|
142
|
-
* flags.more_coming = true
|
143
|
-
* flags.to_i #=> DNSSD::Flags::MoreComing
|
144
|
-
* f.shared = true
|
145
|
-
* flags.to_i #=> Flags::MoreComing | Flags::Shared
|
146
|
-
*
|
147
|
-
* same_flags = Flags.new(Flags::MoreComing | Flags::Shared)
|
148
|
-
* flags == same_flags #=> true
|
149
|
-
*
|
150
|
-
* same_flags_again = Flags.new(Flags::MoreComing, Flags::Shared)
|
151
|
-
* flags == same_flags_again #=> true
|
152
|
-
*
|
153
|
-
*/
|
154
|
-
|
155
|
-
static VALUE
|
156
|
-
dnssd_flags_initialize(int argc, VALUE *argv, VALUE self)
|
157
|
-
{
|
158
|
-
int i;
|
159
|
-
DNSServiceFlags flags = 0;
|
160
|
-
|
161
|
-
for (i=0; i<argc; i++) {
|
162
|
-
flags |= dnssd_to_flags(argv[i]);
|
163
|
-
}
|
164
|
-
return dnssd_flags_init(self, flags);
|
165
|
-
}
|
166
|
-
|
167
|
-
static VALUE
|
168
|
-
dnssd_flags_new2(VALUE klass, DNSServiceFlags flags)
|
169
|
-
{
|
170
|
-
return dnssd_flags_init(dnssd_flags_alloc(klass), flags);
|
171
|
-
}
|
172
|
-
|
173
|
-
static VALUE
|
174
|
-
dnssd_flags_new(DNSServiceFlags flags)
|
175
|
-
{
|
176
|
-
return dnssd_flags_new2(cDNSSDFlags, flags);
|
177
|
-
}
|
178
|
-
|
179
|
-
/*
|
180
|
-
* call-seq:
|
181
|
-
* flags.set_flag(f)
|
182
|
-
*
|
183
|
-
* Set the flag _f_ in _flags_.
|
184
|
-
*
|
185
|
-
* flags = Flags.new() #=> #<DNSSD::Flags>
|
186
|
-
* flags.set_flag(Flags::MoreComing) #=> #<DNSSD::Flags more_coming>
|
187
|
-
*
|
188
|
-
*/
|
189
|
-
|
190
|
-
static VALUE
|
191
|
-
dnssd_flags_set(VALUE self, VALUE num)
|
192
|
-
{
|
193
|
-
DNSServiceFlags flags;
|
194
|
-
VerifyDNSSDFlags(self);
|
195
|
-
flags = (DNSServiceFlags)RDATA(self)->data;
|
196
|
-
flags |= dnssd_to_flags(num);
|
197
|
-
RDATA(self)->data = (void*)flags;
|
198
|
-
return self;
|
199
|
-
}
|
200
|
-
|
201
|
-
/*
|
202
|
-
* call-seq:
|
203
|
-
* flags.clear_flag(f)
|
204
|
-
*
|
205
|
-
* Clear the flag _f_ in _flags_.
|
206
|
-
*
|
207
|
-
* flags = Flags.new(Flags::MoreComing) #=> #<DNSSD::Flags more_coming>
|
208
|
-
* flags.clear_flag(Flags::MoreComing) #=> #<DNSSD::Flags>
|
209
|
-
*
|
210
|
-
*/
|
211
|
-
|
212
|
-
static VALUE
|
213
|
-
dnssd_flags_clear(VALUE self, VALUE num)
|
214
|
-
{
|
215
|
-
DNSServiceFlags flags;
|
216
|
-
VerifyDNSSDFlags(self);
|
217
|
-
/* flags should stay masked here (see DNSSD_FLAGS_MASK() macro) */
|
218
|
-
flags = (DNSServiceFlags)RDATA(self)->data;
|
219
|
-
flags &= ~dnssd_to_flags(num);
|
220
|
-
RDATA(self)->data = (void*)flags;
|
221
|
-
return self;
|
222
|
-
}
|
223
|
-
|
224
|
-
/*
|
225
|
-
* call-seq:
|
226
|
-
* flags1 & flags2 => flags
|
227
|
-
*
|
228
|
-
* Returns the set of flags included in <i>flags1</i> and <i>flags2</i>.
|
229
|
-
*
|
230
|
-
*/
|
231
|
-
|
232
|
-
static VALUE
|
233
|
-
dnssd_flags_and(VALUE self, VALUE num)
|
234
|
-
{
|
235
|
-
return dnssd_flags_new2(CLASS_OF(self), dnssd_get_flags(self) & dnssd_to_flags(num));
|
236
|
-
}
|
237
|
-
|
238
|
-
/*
|
239
|
-
* call-seq:
|
240
|
-
* flags1 | flags2 => flags
|
241
|
-
*
|
242
|
-
* Returns the set of flags included in <i>flags1</i> or <i>flags2</i>.
|
243
|
-
*
|
244
|
-
*/
|
245
|
-
|
246
|
-
static VALUE
|
247
|
-
dnssd_flags_or(VALUE self, VALUE num)
|
248
|
-
{
|
249
|
-
return dnssd_flags_new2(CLASS_OF(self), dnssd_get_flags(self) | dnssd_to_flags(num));
|
250
|
-
}
|
251
|
-
|
252
|
-
/*
|
253
|
-
* call-seq:
|
254
|
-
* ~flags => unset_flags
|
255
|
-
*
|
256
|
-
* Returns the set of flags not included in _flags_.
|
257
|
-
*
|
258
|
-
*/
|
259
|
-
|
260
|
-
static VALUE
|
261
|
-
dnssd_flags_not(VALUE self)
|
262
|
-
{
|
263
|
-
/* doesn't totally make sence to return a set of flags here... */
|
264
|
-
return dnssd_flags_new2(CLASS_OF(self), ~dnssd_get_flags(self));
|
265
|
-
}
|
266
|
-
|
267
|
-
/*
|
268
|
-
* call-seq:
|
269
|
-
* flags.to_i => an_integer
|
270
|
-
*
|
271
|
-
* Get the integer representation of _flags_ by bitwise or'ing
|
272
|
-
* each of the set flags.
|
273
|
-
*
|
274
|
-
*/
|
275
|
-
|
276
|
-
static VALUE
|
277
|
-
dnssd_flags_to_i(VALUE self)
|
278
|
-
{
|
279
|
-
return ULONG2NUM(dnssd_get_flags(self));
|
280
|
-
}
|
281
|
-
|
282
|
-
static VALUE
|
283
|
-
dnssd_flags_list(VALUE self)
|
284
|
-
{
|
285
|
-
DNSServiceFlags flags = dnssd_get_flags(self);
|
286
|
-
VALUE buf = rb_str_buf_new(0);
|
287
|
-
int i;
|
288
|
-
for (i=0; i<DNSSD_MAX_FLAGS; i++) {
|
289
|
-
if (flags & dnssd_flag[i]) {
|
290
|
-
rb_str_buf_cat2(buf, dnssd_flag_name[i]);
|
291
|
-
rb_str_buf_cat2(buf, ",");
|
292
|
-
}
|
293
|
-
}
|
294
|
-
/* get rid of trailing comma */
|
295
|
-
if (RSTRING(buf)->len > 0) {
|
296
|
-
long len = --(RSTRING(buf)->len);
|
297
|
-
RSTRING(buf)->ptr[len] = '\000';
|
298
|
-
}
|
299
|
-
return buf;
|
300
|
-
}
|
301
|
-
|
302
|
-
static VALUE
|
303
|
-
dnssd_struct_inspect(VALUE self, VALUE data)
|
304
|
-
{
|
305
|
-
VALUE buf = rb_str_buf_new(20 + RSTRING(data)->len);
|
306
|
-
rb_str_buf_cat2(buf, "#<");
|
307
|
-
rb_str_buf_cat2(buf, rb_obj_classname(self));
|
308
|
-
if (RSTRING(data)->len > 0) {
|
309
|
-
rb_str_buf_cat2(buf, " ");
|
310
|
-
rb_str_buf_append(buf, data);
|
311
|
-
}
|
312
|
-
rb_str_buf_cat2(buf, ">");
|
313
|
-
return buf;
|
314
|
-
}
|
315
|
-
|
316
|
-
/*
|
317
|
-
* call-seq:
|
318
|
-
* flags.inspect => string
|
319
|
-
*
|
320
|
-
* Create a printable version of _flags_.
|
321
|
-
*
|
322
|
-
* flags = DNSSD::Flags.new
|
323
|
-
* flags.add = true
|
324
|
-
* flags.default = true
|
325
|
-
* flags.inspect # => "#<DNSSD::Flags add,default>"
|
326
|
-
*
|
327
|
-
*/
|
328
|
-
|
329
|
-
static VALUE
|
330
|
-
dnssd_flags_inspect(VALUE self)
|
331
|
-
{
|
332
|
-
return dnssd_struct_inspect(self, dnssd_flags_list(self));
|
333
|
-
}
|
334
|
-
|
335
|
-
/*
|
336
|
-
* call-seq:
|
337
|
-
* flags == obj => true or false
|
338
|
-
*
|
339
|
-
* Equality--Two sets of flags are equal if they contain the same flags.
|
340
|
-
*
|
341
|
-
* flags = Flags.new()
|
342
|
-
* flags.more_coming = true
|
343
|
-
* flags.shared = true
|
344
|
-
* flags == Flags::MoreComing | Flags::Shared #=> true
|
345
|
-
* flags == Flags.new(Flags::MoreComing | Flags::Shared) #=> true
|
346
|
-
*/
|
347
|
-
|
348
|
-
static VALUE
|
349
|
-
dnssd_flags_equal(VALUE self, VALUE obj)
|
350
|
-
{
|
351
|
-
DNSServiceFlags flags = dnssd_get_flags(self);
|
352
|
-
DNSServiceFlags obj_flags = dnssd_to_flags(obj);
|
353
|
-
|
354
|
-
return flags == obj_flags ? Qtrue : Qfalse;
|
355
|
-
}
|
356
|
-
|
357
|
-
VALUE
|
358
|
-
dnssd_create_fullname(const char *name, const char *regtype, const char *domain, int err_flag)
|
359
|
-
{
|
360
|
-
char buffer[kDNSServiceMaxDomainName];
|
361
|
-
if ( DNSServiceConstructFullName(buffer, name, regtype, domain) ) {
|
362
|
-
static const char msg[] = "could not construct full service name";
|
363
|
-
if (err_flag) {
|
364
|
-
rb_raise(rb_eArgError, msg);
|
365
|
-
} else {
|
366
|
-
VALUE buf;
|
367
|
-
rb_warn(msg);
|
368
|
-
/* just join them all */
|
369
|
-
buf = rb_str_buf_new2(name);
|
370
|
-
rb_str_buf_cat2(buf, regtype);
|
371
|
-
rb_str_buf_cat2(buf, domain);
|
372
|
-
return buf;
|
373
|
-
}
|
374
|
-
}
|
375
|
-
buffer[kDNSServiceMaxDomainName - 1] = '\000'; /* just in case */
|
376
|
-
return rb_str_new2(buffer);
|
377
|
-
}
|
378
|
-
|
379
|
-
VALUE
|
380
|
-
dnssd_split_fullname(VALUE fullname)
|
381
|
-
{
|
382
|
-
static const char re[] = "(?:\\\\.|[^\\.])+\\.";
|
383
|
-
VALUE regexp = rb_reg_new(re, sizeof(re)-1, 0);
|
384
|
-
return rb_funcall2(fullname, rb_intern("scan"), 1, ®exp);
|
385
|
-
}
|
386
|
-
|
387
|
-
#if 0
|
388
|
-
static void
|
389
|
-
quote_and_append(VALUE buf, VALUE str)
|
390
|
-
{
|
391
|
-
const char *ptr;
|
392
|
-
long i, last_mark, len;
|
393
|
-
|
394
|
-
ptr = RSTRING(str)->ptr;
|
395
|
-
len = RSTRING(str)->len;
|
396
|
-
last_mark = 0;
|
397
|
-
/* last character should be '.' */
|
398
|
-
for (i=0; i<len-1; i++) {
|
399
|
-
if (ptr[i] == '.') {
|
400
|
-
/* write 1 extra character and replace it with '\\' */
|
401
|
-
rb_str_buf_cat(buf, ptr + last_mark, i + 1 - last_mark);
|
402
|
-
RSTRING(buf)->ptr[i] = '\\';
|
403
|
-
last_mark = i;
|
404
|
-
}
|
405
|
-
}
|
406
|
-
rb_str_buf_cat(buf, ptr + last_mark, len - last_mark);
|
407
|
-
}
|
408
|
-
#endif
|
409
|
-
|
410
|
-
static VALUE
|
411
|
-
dnssd_join_names(int argc, VALUE *argv)
|
412
|
-
{
|
413
|
-
int i;
|
414
|
-
VALUE buf;
|
415
|
-
long len = 0;
|
416
|
-
|
417
|
-
for (i=0; i<argc; i++) {
|
418
|
-
argv[i] = StringValue(argv[i]);
|
419
|
-
len += RSTRING(argv[i])->len;
|
420
|
-
}
|
421
|
-
buf = rb_str_buf_new(len);
|
422
|
-
for (i=0; i<argc; i++) {
|
423
|
-
rb_str_buf_append(buf, argv[i]);
|
424
|
-
}
|
425
|
-
return buf;
|
426
|
-
}
|
427
|
-
|
428
|
-
static void
|
429
|
-
reply_add_names(VALUE self, const char *name,
|
430
|
-
const char *regtype, const char *domain)
|
431
|
-
{
|
432
|
-
rb_ivar_set(self, dnssd_iv_name, rb_str_new2(name));
|
433
|
-
rb_ivar_set(self, dnssd_iv_type, rb_str_new2(regtype));
|
434
|
-
rb_ivar_set(self, dnssd_iv_domain, rb_str_new2(domain));
|
435
|
-
rb_ivar_set(self, dnssd_iv_fullname, dnssd_create_fullname(name, regtype, domain, 0));
|
436
|
-
}
|
437
|
-
|
438
|
-
static void
|
439
|
-
reply_add_names2(VALUE self, const char *fullname)
|
440
|
-
{
|
441
|
-
VALUE fn = rb_str_new2(fullname);
|
442
|
-
VALUE ary = dnssd_split_fullname(fn);
|
443
|
-
VALUE type[2] = { rb_ary_entry(ary, 1), rb_ary_entry(ary, 2) };
|
444
|
-
|
445
|
-
rb_ivar_set(self, dnssd_iv_name, rb_ary_entry(ary, 0));
|
446
|
-
rb_ivar_set(self, dnssd_iv_type, dnssd_join_names(2, type));
|
447
|
-
rb_ivar_set(self, dnssd_iv_domain, rb_ary_entry(ary, -1));
|
448
|
-
rb_ivar_set(self, dnssd_iv_fullname, fn);
|
449
|
-
}
|
450
|
-
|
451
|
-
|
452
|
-
static void
|
453
|
-
reply_set_interface(VALUE self, uint32_t interface)
|
454
|
-
{
|
455
|
-
VALUE if_value;
|
456
|
-
char buffer[IF_NAMESIZE];
|
457
|
-
if (if_indextoname(interface, buffer)) {
|
458
|
-
if_value = rb_str_new2(buffer);
|
459
|
-
} else {
|
460
|
-
if_value = ULONG2NUM(interface);
|
461
|
-
}
|
462
|
-
rb_ivar_set(self, dnssd_iv_interface, if_value);
|
463
|
-
}
|
464
|
-
|
465
|
-
static void
|
466
|
-
reply_set_tr(VALUE self, uint16_t txt_len, const char *txt_rec)
|
467
|
-
{
|
468
|
-
rb_ivar_set(self, dnssd_iv_text_record, dnssd_tr_new((long)txt_len, txt_rec));
|
469
|
-
}
|
470
|
-
|
471
|
-
static VALUE
|
472
|
-
reply_new(VALUE service, DNSServiceFlags flags)
|
473
|
-
{
|
474
|
-
VALUE self = rb_obj_alloc(cDNSSDReply);
|
475
|
-
rb_ivar_set(self, dnssd_iv_service, service);
|
476
|
-
rb_ivar_set(self, dnssd_iv_flags, dnssd_flags_new(flags));
|
477
|
-
return self;
|
478
|
-
}
|
479
|
-
|
480
|
-
VALUE
|
481
|
-
dnssd_domain_enum_new(VALUE service, DNSServiceFlags flags,
|
482
|
-
uint32_t interface, const char *domain)
|
483
|
-
{
|
484
|
-
VALUE d, self = reply_new(service, flags);
|
485
|
-
reply_set_interface(self, interface);
|
486
|
-
d = rb_str_new2(domain);
|
487
|
-
rb_ivar_set(self, dnssd_iv_domain, d);
|
488
|
-
rb_ivar_set(self, dnssd_iv_fullname, d);
|
489
|
-
return self;
|
490
|
-
}
|
491
|
-
|
492
|
-
VALUE
|
493
|
-
dnssd_browse_new(VALUE service, DNSServiceFlags flags, uint32_t interface,
|
494
|
-
const char *name, const char *regtype, const char *domain)
|
495
|
-
{
|
496
|
-
VALUE self = reply_new(service, flags);
|
497
|
-
reply_set_interface(self, interface);
|
498
|
-
reply_add_names(self, name, regtype, domain);
|
499
|
-
return self;
|
500
|
-
}
|
501
|
-
|
502
|
-
#if 0
|
503
|
-
static VALUE
|
504
|
-
dnssd_gethostname(void)
|
505
|
-
{
|
506
|
-
#if HAVE_GETHOSTNAME
|
507
|
-
#ifndef MAXHOSTNAMELEN
|
508
|
-
#define MAXHOSTNAMELEN 256
|
509
|
-
#endif
|
510
|
-
char buffer[MAXHOSTNAMELEN + 1];
|
511
|
-
if (gethostname(buffer, MAXHOSTNAMELEN))
|
512
|
-
return Qnil;
|
513
|
-
buffer[MAXHOSTNAMELEN] = '\000';
|
514
|
-
return rb_str_new2(buffer);
|
515
|
-
#else
|
516
|
-
return Qnil;
|
517
|
-
#endif
|
518
|
-
}
|
519
|
-
#endif
|
520
|
-
|
521
|
-
VALUE
|
522
|
-
dnssd_register_new(VALUE service, DNSServiceFlags flags, const char *name,
|
523
|
-
const char *regtype, const char *domain )
|
524
|
-
{
|
525
|
-
VALUE self = reply_new(service, flags);
|
526
|
-
reply_add_names(self, name, regtype, domain);
|
527
|
-
/* HACK */
|
528
|
-
/* See HACK in rdnssd_service.c */
|
529
|
-
rb_ivar_set(self, dnssd_iv_interface, rb_ivar_get(service, dnssd_iv_interface));
|
530
|
-
rb_ivar_set(self, dnssd_iv_port, rb_ivar_get(service, dnssd_iv_port));
|
531
|
-
rb_ivar_set(self, dnssd_iv_text_record, rb_ivar_get(service, dnssd_iv_text_record));
|
532
|
-
/********/
|
533
|
-
return self;
|
534
|
-
}
|
535
|
-
|
536
|
-
VALUE
|
537
|
-
dnssd_resolve_new(VALUE service, DNSServiceFlags flags, uint32_t interface,
|
538
|
-
const char *fullname, const char *host_target,
|
539
|
-
uint16_t opaqueport, uint16_t txt_len, const char *txt_rec)
|
540
|
-
{
|
541
|
-
uint16_t port = ntohs(opaqueport);
|
542
|
-
VALUE self = reply_new(service, flags);
|
543
|
-
reply_set_interface(self, interface);
|
544
|
-
reply_add_names2(self, fullname);
|
545
|
-
rb_ivar_set(self, dnssd_iv_target, rb_str_new2(host_target));
|
546
|
-
rb_ivar_set(self, dnssd_iv_port, UINT2NUM(port));
|
547
|
-
reply_set_tr(self, txt_len, txt_rec);
|
548
|
-
return self;
|
549
|
-
}
|
550
|
-
|
551
|
-
/*
|
552
|
-
* call-seq:
|
553
|
-
* reply.inspect => string
|
554
|
-
*
|
555
|
-
*/
|
556
|
-
static VALUE
|
557
|
-
reply_inspect(VALUE self)
|
558
|
-
{
|
559
|
-
VALUE fullname = rb_ivar_get(self, dnssd_iv_fullname);
|
560
|
-
return dnssd_struct_inspect(self, StringValue(fullname));
|
561
|
-
}
|
562
|
-
|
563
|
-
/*
|
564
|
-
* call-seq:
|
565
|
-
* DNSSD::Reply.new() => raises a RuntimeError
|
566
|
-
*
|
567
|
-
*/
|
568
|
-
static VALUE
|
569
|
-
reply_initialize(int argc, VALUE *argv, VALUE reply)
|
570
|
-
{
|
571
|
-
dnssd_instantiation_error(rb_obj_classname(reply));
|
572
|
-
return Qnil;
|
573
|
-
}
|
574
|
-
|
575
|
-
void
|
576
|
-
Init_DNSSD_Replies(void)
|
577
|
-
{
|
578
|
-
/* hack so rdoc documents the project correctly */
|
579
|
-
#ifdef mDNSSD_RDOC_HACK
|
580
|
-
mDNSSD = rb_define_module("DNSSD");
|
581
|
-
#endif
|
582
|
-
|
583
|
-
dnssd_iv_flags = rb_intern("@flags");
|
584
|
-
dnssd_iv_interface = rb_intern("@interface");
|
585
|
-
dnssd_iv_fullname = rb_intern("@fullname");
|
586
|
-
dnssd_iv_target = rb_intern("@target");
|
587
|
-
dnssd_iv_port = rb_intern("@port");
|
588
|
-
dnssd_iv_text_record = rb_intern("@text_record");
|
589
|
-
dnssd_iv_name = rb_intern("@name");
|
590
|
-
dnssd_iv_type = rb_intern("@type");
|
591
|
-
dnssd_iv_domain = rb_intern("@domain");
|
592
|
-
dnssd_iv_service = rb_intern("@service");
|
593
|
-
|
594
|
-
cDNSSDFlags = rb_define_class_under(mDNSSD, "Flags", rb_cObject);
|
595
|
-
rb_define_alloc_func(cDNSSDFlags, dnssd_flags_alloc);
|
596
|
-
rb_define_method(cDNSSDFlags, "initialize", dnssd_flags_initialize, -1);
|
597
|
-
/* this creates all the attr_writer and flag? methods */
|
598
|
-
dnssd_init_flags_methods(cDNSSDFlags);
|
599
|
-
rb_define_method(cDNSSDFlags, "inspect", dnssd_flags_inspect, 0);
|
600
|
-
rb_define_method(cDNSSDFlags, "to_i", dnssd_flags_to_i, 0);
|
601
|
-
rb_define_method(cDNSSDFlags, "==", dnssd_flags_equal, 1);
|
602
|
-
|
603
|
-
rb_define_method(cDNSSDFlags, "&", dnssd_flags_and, 1);
|
604
|
-
rb_define_method(cDNSSDFlags, "|", dnssd_flags_or, 1);
|
605
|
-
rb_define_method(cDNSSDFlags, "~", dnssd_flags_not, 0);
|
606
|
-
|
607
|
-
rb_define_method(cDNSSDFlags, "set_flag", dnssd_flags_set, 1);
|
608
|
-
rb_define_method(cDNSSDFlags, "clear_flag", dnssd_flags_clear, 1);
|
609
|
-
|
610
|
-
cDNSSDReply = rb_define_class_under(mDNSSD, "Reply", rb_cObject);
|
611
|
-
/* DNSSD::Reply objects can only be instantiated by
|
612
|
-
* DNSSD.browse(), DNSSD.register(), DNSSD.resolve(), DNSSD.enumerate_domains(). */
|
613
|
-
rb_define_method(cDNSSDReply, "initialize", reply_initialize, -1);
|
614
|
-
/* The service associated with the reply. See DNSSD::Service for more information. */
|
615
|
-
rb_define_attr(cDNSSDReply, "service", 1, 0);
|
616
|
-
/* Flags describing the reply. See DNSSD::Flags for more information. */
|
617
|
-
rb_define_attr(cDNSSDReply, "flags", 1, 0);
|
618
|
-
/* The service name. (Not used by DNSSD.enumerate_domains().) */
|
619
|
-
rb_define_attr(cDNSSDReply, "name", 1, 0);
|
620
|
-
/* The service type. (Not used by DNSSD.enumerate_domains().) */
|
621
|
-
rb_define_attr(cDNSSDReply, "type", 1, 0);
|
622
|
-
/* The service domain. */
|
623
|
-
rb_define_attr(cDNSSDReply, "domain", 1, 0);
|
624
|
-
/* The interface on which the service is available. (Used only by DNSSSD.resolve().) */
|
625
|
-
rb_define_attr(cDNSSDReply, "interface", 1, 0);
|
626
|
-
/* The full service domain name, in the form "<servicename>.<protocol>.<domain>.".
|
627
|
-
* (Any literal dots (".") are escaped with a backslash ("\."), and literal
|
628
|
-
* backslashes are escaped with a second backslash ("\\"), e.g. a web server
|
629
|
-
* named "Dr. Pepper" would have the fullname "Dr\.\032Pepper._http._tcp.local.".)
|
630
|
-
* See DNSSD::Service.fullname() for more information. */
|
631
|
-
rb_define_attr(cDNSSDReply, "fullname", 1, 0);
|
632
|
-
/* The service's primary text record, see DNSSD::TextRecord for more information. */
|
633
|
-
rb_define_attr(cDNSSDReply, "text_record", 1, 0);
|
634
|
-
/* The target hostname of the machine providing the service.
|
635
|
-
* This name can be passed to functions like Socket.gethostbyname()
|
636
|
-
* to identify the host's IP address. */
|
637
|
-
rb_define_attr(cDNSSDReply, "target", 1, 0);
|
638
|
-
/* The port on which connections are accepted for this service. */
|
639
|
-
rb_define_attr(cDNSSDReply, "port", 1, 0);
|
640
|
-
|
641
|
-
rb_define_method(cDNSSDReply, "inspect", reply_inspect, 0);
|
642
|
-
|
643
|
-
/* flag constants */
|
644
|
-
#if DNSSD_MAX_FLAGS != 9
|
645
|
-
#error The code below needs to be updated.
|
646
|
-
#endif
|
647
|
-
/* MoreComing indicates that at least one more result is queued and will be delivered following immediately after this one.
|
648
|
-
* Applications should not update their UI to display browse
|
649
|
-
* results when the MoreComing flag is set, because this would
|
650
|
-
* result in a great deal of ugly flickering on the screen.
|
651
|
-
* Applications should instead wait until until MoreComing is not set,
|
652
|
-
* and then update their UI.
|
653
|
-
* When MoreComing is not set, that doesn't mean there will be no more
|
654
|
-
* answers EVER, just that there are no more answers immediately
|
655
|
-
* available right now at this instant. If more answers become available
|
656
|
-
* in the future they will be delivered as usual.
|
657
|
-
*/
|
658
|
-
rb_define_const(cDNSSDFlags, "MoreComing", ULONG2NUM(kDNSServiceFlagsMoreComing));
|
659
|
-
|
660
|
-
|
661
|
-
/* Flags for domain enumeration and DNSSD.browse() reply callbacks.
|
662
|
-
* DNSSD::Flags::Default applies only to enumeration and is only valid in
|
663
|
-
* conjuction with DNSSD::Flags::Add. An enumeration callback with the DNSSD::Flags::Add
|
664
|
-
* flag NOT set indicates a DNSSD::Flags::Remove, i.e. the domain is no longer valid.
|
665
|
-
*/
|
666
|
-
rb_define_const(cDNSSDFlags, "Add", ULONG2NUM(kDNSServiceFlagsAdd));
|
667
|
-
rb_define_const(cDNSSDFlags, "Default", ULONG2NUM(kDNSServiceFlagsDefault));
|
668
|
-
|
669
|
-
/* Flag for specifying renaming behavior on name conflict when registering non-shared records.
|
670
|
-
* By default, name conflicts are automatically handled by renaming the service.
|
671
|
-
* DNSSD::Flags::NoAutoRename overrides this behavior - with this
|
672
|
-
* flag set, name conflicts will result in a callback. The NoAutoRename flag
|
673
|
-
* is only valid if a name is explicitly specified when registering a service
|
674
|
-
* (ie the default name is not used.)
|
675
|
-
*/
|
676
|
-
rb_define_const(cDNSSDFlags, "NoAutoRename", ULONG2NUM(kDNSServiceFlagsNoAutoRename));
|
677
|
-
|
678
|
-
/* Flag for registering individual records on a connected DNSServiceRef.
|
679
|
-
* DNSSD::Flags::Shared indicates that there may be multiple records
|
680
|
-
* with this name on the network (e.g. PTR records). DNSSD::Flags::Unique indicates that the
|
681
|
-
* record's name is to be unique on the network (e.g. SRV records).
|
682
|
-
* (DNSSD::Flags::Shared and DNSSD::Flags::Unique are currently not used by the Ruby API.)
|
683
|
-
*/
|
684
|
-
rb_define_const(cDNSSDFlags, "Shared", ULONG2NUM(kDNSServiceFlagsShared));
|
685
|
-
rb_define_const(cDNSSDFlags, "Unique", ULONG2NUM(kDNSServiceFlagsUnique));
|
686
|
-
|
687
|
-
/* Flags for specifying domain enumeration type in DNSSD.enumerate_domains()
|
688
|
-
* (currently not part of the Ruby API).
|
689
|
-
* DNSSD::Flags::BrowseDomains enumerates domains recommended for browsing,
|
690
|
-
* DNSSD::Flags::RegistrationDomains enumerates domains recommended for registration.
|
691
|
-
*/
|
692
|
-
rb_define_const(cDNSSDFlags, "BrowseDomains", ULONG2NUM(kDNSServiceFlagsBrowseDomains));
|
693
|
-
rb_define_const(cDNSSDFlags, "RegistrationDomains", ULONG2NUM(kDNSServiceFlagsRegistrationDomains));
|
694
|
-
|
695
|
-
/* Flag for creating a long-lived unicast query for the DNSDS.query_record()
|
696
|
-
* (currently not part of the Ruby API). */
|
697
|
-
rb_define_const(cDNSSDFlags, "LongLivedQuery", ULONG2NUM(kDNSServiceFlagsLongLivedQuery));
|
698
|
-
}
|
699
|
-
|
700
|
-
/* Document-class: DNSSD::Reply
|
701
|
-
*
|
702
|
-
* DNSSD::Reply is used to return information
|
703
|
-
*
|
704
|
-
*/
|
705
|
-
|
706
|
-
/* Document-class: DNSSD::Flags
|
707
|
-
*
|
708
|
-
* Flags used in DNSSD Ruby API.
|
709
|
-
*/
|
710
|
-
|