em-udns 0.2.6 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/em-udns.c +22 -28
- data/lib/em-udns/query.rb +24 -0
- data/lib/em-udns/resolver.rb +20 -4
- data/lib/em-udns/version.rb +1 -1
- data/lib/em-udns.rb +1 -0
- metadata +5 -4
data/ext/em-udns.c
CHANGED
@@ -7,7 +7,6 @@
|
|
7
7
|
|
8
8
|
|
9
9
|
static VALUE mEm;
|
10
|
-
static VALUE mEmDeferrable;
|
11
10
|
static VALUE mUdns;
|
12
11
|
|
13
12
|
static VALUE cResolver;
|
@@ -40,12 +39,11 @@ static VALUE symbol_dns_error_unknown;
|
|
40
39
|
static VALUE symbol_dns_error_badquery;
|
41
40
|
static VALUE symbol_dns_error_nomem;
|
42
41
|
static VALUE symbol_dns_error_unknown;
|
43
|
-
static VALUE symbol_failed;
|
44
|
-
static VALUE symbol_succeeded;
|
45
42
|
|
46
43
|
static ID method_cancel;
|
47
44
|
static ID method_set_timer;
|
48
|
-
static ID
|
45
|
+
static ID method_do_success;
|
46
|
+
static ID method_do_error;
|
49
47
|
|
50
48
|
|
51
49
|
void Resolver_free(struct dns_ctx *dns_context)
|
@@ -207,7 +205,7 @@ static void* check_query(struct dns_ctx *dns_context, void *rr, void *data)
|
|
207
205
|
error = symbol_dns_error_unknown;
|
208
206
|
break;
|
209
207
|
}
|
210
|
-
rb_funcall(query,
|
208
|
+
rb_funcall(query, method_do_error, 1, error);
|
211
209
|
return NULL;
|
212
210
|
}
|
213
211
|
|
@@ -229,7 +227,7 @@ static void dns_result_A_cb(struct dns_ctx *dns_context, struct dns_rr_a4 *rr, v
|
|
229
227
|
rb_ary_push(array, rb_str_new2((char *)dns_ntop(AF_INET, &(rr->dnsa4_addr[i].s_addr), ip, INET_ADDRSTRLEN)));
|
230
228
|
free(rr);
|
231
229
|
|
232
|
-
rb_funcall(query,
|
230
|
+
rb_funcall(query, method_do_success, 1, array);
|
233
231
|
}
|
234
232
|
|
235
233
|
|
@@ -247,7 +245,7 @@ static void dns_result_AAAA_cb(struct dns_ctx *dns_context, struct dns_rr_a6 *rr
|
|
247
245
|
rb_ary_push(array, rb_str_new2((char *)dns_ntop(AF_INET6, &(rr->dnsa6_addr[i].s6_addr), ip, INET6_ADDRSTRLEN)));
|
248
246
|
free(rr);
|
249
247
|
|
250
|
-
rb_funcall(query,
|
248
|
+
rb_funcall(query, method_do_success, 1, array);
|
251
249
|
}
|
252
250
|
|
253
251
|
|
@@ -264,7 +262,7 @@ static void dns_result_PTR_cb(struct dns_ctx *dns_context, struct dns_rr_ptr *rr
|
|
264
262
|
rb_ary_push(array, rb_str_new2(rr->dnsptr_ptr[i]));
|
265
263
|
free(rr);
|
266
264
|
|
267
|
-
rb_funcall(query,
|
265
|
+
rb_funcall(query, method_do_success, 1, array);
|
268
266
|
}
|
269
267
|
|
270
268
|
|
@@ -286,7 +284,7 @@ static void dns_result_MX_cb(struct dns_ctx *dns_context, struct dns_rr_mx *rr,
|
|
286
284
|
}
|
287
285
|
free(rr);
|
288
286
|
|
289
|
-
rb_funcall(query,
|
287
|
+
rb_funcall(query, method_do_success, 1, array);
|
290
288
|
}
|
291
289
|
|
292
290
|
|
@@ -303,7 +301,7 @@ static void dns_result_TXT_cb(struct dns_ctx *dns_context, struct dns_rr_txt *rr
|
|
303
301
|
rb_ary_push(array, rb_str_new(rr->dnstxt_txt[i].txt, rr->dnstxt_txt[i].len));
|
304
302
|
free(rr);
|
305
303
|
|
306
|
-
rb_funcall(query,
|
304
|
+
rb_funcall(query, method_do_success, 1, array);
|
307
305
|
}
|
308
306
|
|
309
307
|
|
@@ -327,7 +325,7 @@ static void dns_result_SRV_cb(struct dns_ctx *dns_context, struct dns_rr_srv *rr
|
|
327
325
|
}
|
328
326
|
free(rr);
|
329
327
|
|
330
|
-
rb_funcall(query,
|
328
|
+
rb_funcall(query, method_do_success, 1, array);
|
331
329
|
}
|
332
330
|
|
333
331
|
|
@@ -359,7 +357,7 @@ static void dns_result_NAPTR_cb(struct dns_ctx *dns_context, struct dns_rr_naptr
|
|
359
357
|
}
|
360
358
|
free(rr);
|
361
359
|
|
362
|
-
rb_funcall(query,
|
360
|
+
rb_funcall(query, method_do_success, 1, array);
|
363
361
|
}
|
364
362
|
|
365
363
|
|
@@ -402,7 +400,7 @@ VALUE Resolver_submit_A(VALUE self, VALUE rb_domain)
|
|
402
400
|
if (!dns_submit_a4(dns_context, domain, 0, dns_result_A_cb, (void *)data)) {
|
403
401
|
error = get_dns_error(dns_context);
|
404
402
|
xfree(data);
|
405
|
-
rb_funcall(query,
|
403
|
+
rb_funcall(query, method_do_error, 1, error);
|
406
404
|
}
|
407
405
|
else {
|
408
406
|
rb_hash_aset(rb_ivar_get(self, id_queries), query, Qtrue);
|
@@ -431,7 +429,7 @@ VALUE Resolver_submit_AAAA(VALUE self, VALUE rb_domain)
|
|
431
429
|
if (!dns_submit_a6(dns_context, domain, 0, dns_result_AAAA_cb, (void *)data)) {
|
432
430
|
error = get_dns_error(dns_context);
|
433
431
|
xfree(data);
|
434
|
-
rb_funcall(query,
|
432
|
+
rb_funcall(query, method_do_error, 1, error);
|
435
433
|
}
|
436
434
|
else {
|
437
435
|
rb_hash_aset(rb_ivar_get(self, id_queries), query, Qtrue);
|
@@ -465,7 +463,7 @@ VALUE Resolver_submit_PTR(VALUE self, VALUE rb_ip)
|
|
465
463
|
if (!dns_submit_a4ptr(dns_context, &addr, dns_result_PTR_cb, (void *)data)) {
|
466
464
|
error = get_dns_error(dns_context);
|
467
465
|
xfree(data);
|
468
|
-
rb_funcall(query,
|
466
|
+
rb_funcall(query, method_do_error, 1, error);
|
469
467
|
}
|
470
468
|
else {
|
471
469
|
rb_hash_aset(rb_ivar_get(self, id_queries), query, Qtrue);
|
@@ -479,7 +477,7 @@ VALUE Resolver_submit_PTR(VALUE self, VALUE rb_ip)
|
|
479
477
|
if (!dns_submit_a6ptr(dns_context, &addr6, dns_result_PTR_cb, (void *)data)) {
|
480
478
|
error = get_dns_error(dns_context);
|
481
479
|
xfree(data);
|
482
|
-
rb_funcall(query,
|
480
|
+
rb_funcall(query, method_do_error, 1, error);
|
483
481
|
}
|
484
482
|
else {
|
485
483
|
rb_hash_aset(rb_ivar_get(self, id_queries), query, Qtrue);
|
@@ -488,7 +486,7 @@ VALUE Resolver_submit_PTR(VALUE self, VALUE rb_ip)
|
|
488
486
|
/* Also an invalid IPv6 so the IP is invalid. */
|
489
487
|
case 0:
|
490
488
|
xfree(data);
|
491
|
-
rb_funcall(query,
|
489
|
+
rb_funcall(query, method_do_error, 1, symbol_dns_error_badquery);
|
492
490
|
break;
|
493
491
|
}
|
494
492
|
break;
|
@@ -517,7 +515,7 @@ VALUE Resolver_submit_MX(VALUE self, VALUE rb_domain)
|
|
517
515
|
if (!dns_submit_mx(dns_context, domain, 0, dns_result_MX_cb, (void *)data)) {
|
518
516
|
error = get_dns_error(dns_context);
|
519
517
|
xfree(data);
|
520
|
-
rb_funcall(query,
|
518
|
+
rb_funcall(query, method_do_error, 1, error);
|
521
519
|
}
|
522
520
|
else {
|
523
521
|
rb_hash_aset(rb_ivar_get(self, id_queries), query, Qtrue);
|
@@ -546,7 +544,7 @@ VALUE Resolver_submit_TXT(VALUE self, VALUE rb_domain)
|
|
546
544
|
if (!dns_submit_txt(dns_context, domain, DNS_C_IN, 0, dns_result_TXT_cb, (void *)data)) {
|
547
545
|
error = get_dns_error(dns_context);
|
548
546
|
xfree(data);
|
549
|
-
rb_funcall(query,
|
547
|
+
rb_funcall(query, method_do_error, 1, error);
|
550
548
|
}
|
551
549
|
else {
|
552
550
|
rb_hash_aset(rb_ivar_get(self, id_queries), query, Qtrue);
|
@@ -588,7 +586,7 @@ VALUE Resolver_submit_SRV(int argc, VALUE *argv, VALUE self)
|
|
588
586
|
if (!dns_submit_srv(dns_context, domain, service, protocol, 0, dns_result_SRV_cb, (void *)data)) {
|
589
587
|
error = get_dns_error(dns_context);
|
590
588
|
xfree(data);
|
591
|
-
rb_funcall(query,
|
589
|
+
rb_funcall(query, method_do_error, 1, error);
|
592
590
|
}
|
593
591
|
else {
|
594
592
|
rb_hash_aset(rb_ivar_get(self, id_queries), query, Qtrue);
|
@@ -617,7 +615,7 @@ VALUE Resolver_submit_NAPTR(VALUE self, VALUE rb_domain)
|
|
617
615
|
if (!dns_submit_naptr(dns_context, domain, 0, dns_result_NAPTR_cb, (void *)data)) {
|
618
616
|
error = get_dns_error(dns_context);
|
619
617
|
xfree(data);
|
620
|
-
rb_funcall(query,
|
618
|
+
rb_funcall(query, method_do_error, 1, error);
|
621
619
|
}
|
622
620
|
else {
|
623
621
|
rb_hash_aset(rb_ivar_get(self, id_queries), query, Qtrue);
|
@@ -647,10 +645,8 @@ VALUE RR_NAPTR_replacement(VALUE self) { return rb_ivar_get(self, id_replacemen
|
|
647
645
|
void Init_em_udns_ext()
|
648
646
|
{
|
649
647
|
mEm = rb_define_module("EventMachine");
|
650
|
-
mEmDeferrable = rb_define_module_under(mEm, "Deferrable");
|
651
648
|
mUdns = rb_define_module_under(mEm, "Udns");
|
652
|
-
|
653
|
-
eUdnsError = rb_define_class_under(mUdns, "UdnsError", rb_eStandardError);
|
649
|
+
eUdnsError = rb_define_class_under(mUdns, "UdnsError", rb_eStandardError);
|
654
650
|
|
655
651
|
cResolver = rb_define_class_under(mUdns, "Resolver", rb_cObject);
|
656
652
|
rb_define_alloc_func(cResolver, Resolver_alloc);
|
@@ -669,7 +665,6 @@ void Init_em_udns_ext()
|
|
669
665
|
rb_define_method(cResolver, "submit_NAPTR", Resolver_submit_NAPTR, 1);
|
670
666
|
|
671
667
|
cQuery = rb_define_class_under(mUdns, "Query", rb_cObject);
|
672
|
-
rb_include_module(cQuery, mEmDeferrable);
|
673
668
|
|
674
669
|
cRR_MX = rb_define_class_under(mUdns, "RR_MX", rb_cObject);
|
675
670
|
rb_define_method(cRR_MX, "domain", RR_MX_domain, 0);
|
@@ -710,10 +705,9 @@ void Init_em_udns_ext()
|
|
710
705
|
symbol_dns_error_badquery = ID2SYM(rb_intern("dns_error_badquery"));
|
711
706
|
symbol_dns_error_nomem = ID2SYM(rb_intern("dns_error_nomem"));
|
712
707
|
symbol_dns_error_unknown = ID2SYM(rb_intern("dns_error_unknown"));
|
713
|
-
symbol_failed = ID2SYM(rb_intern("failed"));
|
714
|
-
symbol_succeeded = ID2SYM(rb_intern("succeeded"));
|
715
708
|
|
716
709
|
method_cancel = rb_intern("cancel");
|
717
710
|
method_set_timer = rb_intern("set_timer");
|
718
|
-
|
711
|
+
method_do_success = rb_intern("do_success");
|
712
|
+
method_do_error = rb_intern("do_error");
|
719
713
|
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module EventMachine::Udns
|
2
|
+
|
3
|
+
class Query
|
4
|
+
def callback &block
|
5
|
+
@on_success_block = block
|
6
|
+
end
|
7
|
+
|
8
|
+
def errback &block
|
9
|
+
@on_error_block = block
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def do_success result
|
16
|
+
@on_success_block && @on_success_block.call(result)
|
17
|
+
end
|
18
|
+
|
19
|
+
def do_error error
|
20
|
+
@on_error_block && @on_error_block.call(error)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
data/lib/em-udns/resolver.rb
CHANGED
@@ -7,12 +7,28 @@ module EventMachine::Udns
|
|
7
7
|
dns_open
|
8
8
|
end
|
9
9
|
|
10
|
+
def callback &block
|
11
|
+
@on_success_block = block
|
12
|
+
end
|
13
|
+
|
14
|
+
def errback &block
|
15
|
+
@on_error_block = block
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
private
|
20
|
+
|
10
21
|
def set_timer(timeout)
|
11
|
-
@timer = EM::Timer.new(timeout)
|
12
|
-
|
13
|
-
|
22
|
+
@timer = EM::Timer.new(timeout) { timeouts }
|
23
|
+
end
|
24
|
+
|
25
|
+
def do_success result
|
26
|
+
@on_success_block && @on_success_block.call(result)
|
27
|
+
end
|
28
|
+
|
29
|
+
def do_error error
|
30
|
+
@on_error_block && @on_error_block.call(error)
|
14
31
|
end
|
15
|
-
private :set_timer
|
16
32
|
end
|
17
33
|
|
18
34
|
end
|
data/lib/em-udns/version.rb
CHANGED
data/lib/em-udns.rb
CHANGED
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 3
|
8
|
+
- 0
|
9
|
+
version: 0.3.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- "I\xC3\xB1aki Baz Castillo"
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-
|
17
|
+
date: 2011-10-29 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -42,6 +42,7 @@ files:
|
|
42
42
|
- lib/em-udns.rb
|
43
43
|
- lib/em-udns/version.rb
|
44
44
|
- lib/em-udns/resolver.rb
|
45
|
+
- lib/em-udns/query.rb
|
45
46
|
- ext/em-udns.c
|
46
47
|
- ext/em-udns.h
|
47
48
|
- ext/extconf.rb
|