Class: ADNS::State
- Inherits:
-
Object
- Object
- ADNS::State
- Defined in:
- ext/adns/mod_adns.c,
ext/adns/mod_adns.c
Overview
ADNS::State class defines asychronous/synchronous methods to submit/check the query.
Class Method Summary collapse
-
.new([iflags, filename, filemode]) ⇒ Object
Create new ADNS::State object and initialize adns library using optional initialization flags <iflags>, debug log to filename <filename> (*only available if ADNS::IF::DEBUG flag is given*), debug log filemode <filemode>.
-
.new2(configtext, [iflags, filename, filemode]) ⇒ Object
Create new ADNS::State object and initialize adns library using resolve.conf style configuration text and optional initialization flags <iflags>, debug log to filename <filename> (*only available if ADNS::IF::DEBUG flag is given*), debug log filemode <filemode>.
Instance Method Summary collapse
-
#completed ⇒ Object
Returns an array of all the completed (ADNS::Query) queries submitted using ADNS::State.submit_*() methods.
-
#global_system_failure ⇒ nil
Call this function, If serious problem(s) occurs with adns library.
- #initialize(argv[], self) ⇒ Object constructor
-
#submit(domain, type[, qflags]) ⇒ ADNS::Query instance
Submit asynchronous request to resolve domain <domain> of record type <type> using optional query flags <qflags>.
-
#submit_reverse(ipaddr, type[, qflags]) ⇒ Object
Submit asynchronous request to reverse lookup address <ipaddr> using optional query flags <qflags>.
-
#submit_reverse_any(ip_addr, type[, qflags]) ⇒ Object
Submit asynchronous request to reverse lookup address <ipaddr> using optional query flags <qflags>.
-
#synchronous(domain, type[, qflags]) ⇒ Hash
Submit synchronous request to resolve domain <domain> of record type <type> using optional query flags <qflags>.
Constructor Details
#initialize(argv[], self) ⇒ Object
679 680 681 682 |
# File 'ext/adns/mod_adns.c', line 679
static VALUE cState_initialize(int argc, VALUE argv[], VALUE self)
{
return self;
}
|
Class Method Details
.new([iflags, filename, filemode]) ⇒ Object
Create new ADNS::State object and initialize adns library using optional initialization flags <iflags>, debug log to filename <filename> (*only available if ADNS::IF::DEBUG flag is given*), debug log filemode <filemode>.
705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 |
# File 'ext/adns/mod_adns.c', line 705
static VALUE cState_new(int argc, VALUE argv[], VALUE self)
{
VALUE state; /* return instance */
rb_adns_state_t *rb_ads_r = ALLOC(rb_adns_state_t);
rb_ads_r->ads = NULL;
rb_ads_r->diagfile = NULL;
adns_initflags iflags = adns_if_none;
const char *fname, *fmode;
if (argc > 3)
rb_raise(rb_eArgError, "excess number of arguments (%d for 3)", argc);
if (argc >= 1)
{
CHECK_TYPE(argv[0], T_FIXNUM);
iflags |= FIX2INT(argv[0]);
if (argc >= 2)
{
CHECK_TYPE(argv[1], T_STRING);
fname = STR2CSTR(argv[1]);
if (argc == 3)
{
CHECK_TYPE(argv[2], T_STRING);
fmode = STR2CSTR(argv[2]);
} else
fmode = DEFAULT_DIAG_FILEMODE;
rb_ads_r->diagfile = fopen(fname, fmode);
if (!rb_ads_r->diagfile)
rb_raise(rb_eIOError, "%s - %s", strerror(errno), fname);
}
}
adns_init(&rb_ads_r->ads, iflags, rb_ads_r->diagfile);
state = Data_Wrap_Struct(mADNS__cState, cState_mark, cState_free, rb_ads_r);
rb_obj_call_init(state, 0, 0);
return state;
}
|
.new2(configtext, [iflags, filename, filemode]) ⇒ Object
Create new ADNS::State object and initialize adns library using resolve.conf style configuration text and optional initialization flags <iflags>, debug log to filename <filename> (*only available if ADNS::IF::DEBUG flag is given*), debug log filemode <filemode>.
749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 |
# File 'ext/adns/mod_adns.c', line 749
static VALUE cState_new2(int argc, VALUE argv[], VALUE self)
{
VALUE state; /* return instance */
rb_adns_state_t *rb_ads_r = ALLOC(rb_adns_state_t);
rb_ads_r->ads = NULL;
rb_ads_r->diagfile = NULL;
adns_initflags iflags = adns_if_none;
const char *fname, *fmode, *cfgtxt;
if (argc > 4)
rb_raise(rb_eArgError, "excess number of arguments (%d for 3)", argc);
if (argc >= 1)
{
CHECK_TYPE(argv[0], T_STRING);
cfgtxt = STR2CSTR(argv[0]);
if (argc >= 2)
{
CHECK_TYPE(argv[1], T_FIXNUM);
iflags |= FIX2INT(argv[1]);
}
if (argc >= 3)
{
CHECK_TYPE(argv[2], T_STRING);
fname = STR2CSTR(argv[2]);
if (argc == 4)
{
CHECK_TYPE(argv[3], T_STRING);
fmode = STR2CSTR(argv[3]);
} else
fmode = DEFAULT_DIAG_FILEMODE;
rb_ads_r->diagfile = fopen(fname, fmode);
if (!rb_ads_r->diagfile)
rb_raise(rb_eIOError, "%s - %s", strerror(errno), fname);
}
}
adns_init_strcfg(&rb_ads_r->ads, iflags, rb_ads_r->diagfile, cfgtxt);
state = Data_Wrap_Struct(mADNS__cState, cState_mark, cState_free, rb_ads_r);
rb_obj_call_init(state, 0, 0);
return state;
}
|
Instance Method Details
#completed ⇒ Object
Returns an array of all the completed (ADNS::Query) queries submitted using ADNS::State.submit_*() methods.
578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 |
# File 'ext/adns/mod_adns.c', line 578
static VALUE cState_completed_queries(int argc, VALUE argv[], VALUE self)
{
VALUE a1, query_list = rb_ary_new();
VALUE query_ctx; /* ADNS::Query context passed from one of the submit_* */
rb_adns_state_t *rb_ads_r;
rb_adns_query_t *rb_adq_r;
adns_query adq;
adns_answer *answer_r;
double timeout;
int ecode;
if (argc == 1)
{
a1 = argv[0];
CHECK_TYPE(a1, T_FLOAT);
}
else
a1 = rb_float_new(0.0);
timeout = (double) RFLOAT_VALUE(a1);
Data_Get_Struct(self, rb_adns_state_t, rb_ads_r);
(void) adns_select_timeout(rb_ads_r, timeout);
for (adns_forallqueries_begin(rb_ads_r->ads);
(adq = adns_forallqueries_next(rb_ads_r->ads, 0)) != 0;)
{
ecode = adns_check(rb_ads_r->ads, &adq, &answer_r, (void **)&query_ctx);
if (ecode)
if (ecode == EWOULDBLOCK)
continue;
Data_Get_Struct(query_ctx, rb_adns_query_t, rb_adq_r);
rb_adq_r->answer = rb_hash_new();
rb_hash_aset(rb_adq_r->answer, CSTR2SYM("type"), INT2FIX(answer_r->type));
rb_hash_aset(rb_adq_r->answer, CSTR2SYM("owner"), CSTR2STR(answer_r->owner));
rb_hash_aset(rb_adq_r->answer, CSTR2SYM("status"), INT2FIX(answer_r->status));
rb_hash_aset(rb_adq_r->answer, CSTR2SYM("expires"), INT2FIX(answer_r->expires));
rb_hash_aset(rb_adq_r->answer, CSTR2SYM("answer"), parse_adns_answer(answer_r));
rb_adq_r->adq = NULL;
free(answer_r);
rb_ary_push(query_list, query_ctx);
}
return query_list;
}
|
#global_system_failure ⇒ nil
Call this function, If serious problem(s) occurs with adns library. All currently outstanding queries will be made to fail with ADNS::Status::SystemFail status code and adns library will close any stream sockets it has open since inception.
671 672 673 674 675 676 677 |
# File 'ext/adns/mod_adns.c', line 671
static VALUE cState_global_system_failure(VALUE self)
{
rb_adns_state_t *rb_ads_r;
Data_Get_Struct(self, rb_adns_state_t, rb_ads_r);
(void) adns_globalsystemfailure(rb_ads_r->ads);
return Qnil;
}
|
#submit(domain, type[, qflags]) ⇒ ADNS::Query instance
Submit asynchronous request to resolve domain <domain> of record type <type> using optional query flags <qflags>.
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 |
# File 'ext/adns/mod_adns.c', line 445
static VALUE cState_submit(int argc, VALUE argv[], VALUE self)
{
rb_adns_query_t *rb_adq_r = ALLOC(rb_adns_query_t);
const char *owner;
adns_rrtype type;
adns_queryflags qflags = adns_qf_owner;
VALUE query; /* return instance */
int ecode;
Data_Get_Struct(self, rb_adns_state_t, rb_adq_r->rb_ads_r);
if (argc < 2)
rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)", argc);
else if (argc > 3)
rb_raise(rb_eArgError, "excess number of arguments (%d for 3)", argc);
CHECK_TYPE(argv[0], T_STRING); /* DOMAIN */
CHECK_TYPE(argv[1], T_FIXNUM); /* RR */
if (argc == 3)
CHECK_TYPE(argv[2], T_FIXNUM); /* QFlags */
owner = STR2CSTR(argv[0]);
type = FIX2INT(argv[1]);
if (argc == 3)
qflags |= FIX2INT(argv[2]);
rb_adq_r->answer = Qnil;
query = Data_Wrap_Struct(mADNS__cQuery, cQuery_mark, cQuery_free, rb_adq_r);
ecode = adns_submit(rb_adq_r->rb_ads_r->ads, owner, type, qflags, (void *)query, &rb_adq_r->adq);
if (ecode)
rb_raise(mADNS__eError, strerror(ecode));
rb_obj_call_init(query, 0, 0);
return query;
}
|
#submit_reverse(ipaddr, type[, qflags]) ⇒ Object
Submit asynchronous request to reverse lookup address <ipaddr> using optional query flags <qflags>. Note: <type> can only be ADNS::RR::PTR or ADNS::RR::PTR_RAW
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 |
# File 'ext/adns/mod_adns.c', line 482
static VALUE cState_submit_reverse(int argc, VALUE argv[], VALUE self)
{
VALUE query; /* return instance */
rb_adns_query_t *rb_adq_r = ALLOC(rb_adns_query_t);
const char *owner;
struct sockaddr_in addr;
adns_rrtype type;
adns_queryflags qflags = adns_qf_owner;
int idx, ecode;
if (argc < 2)
rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)", argc);
if (argc > 3)
rb_raise(rb_eArgError, "excess number of arguments (%d for 2)", argc);
CHECK_TYPE(argv[0], T_STRING);
CHECK_TYPE(argv[1], T_FIXNUM);
if (argc == 3)
CHECK_TYPE(argv[2], T_FIXNUM);
owner = STR2CSTR(argv[0]);
type = FIX2INT(argv[1]);
if (argc == 3)
qflags |= FIX2INT(argv[2]);
switch(type)
{
case adns_r_ptr:
case adns_r_ptr_raw:
break;
default:
rb_raise(rb_eArgError, "invalid record type (PTR or PTR_RAW record expected)");
}
addr.sin_family = AF_INET;
ecode = inet_aton(owner, &addr.sin_addr);
if (ecode == -1)
rb_raise(mADNS__eQueryError, "invalid ip address");
Data_Get_Struct(self, rb_adns_state_t, rb_adq_r->rb_ads_r);
rb_adq_r->answer = Qnil;
query = Data_Wrap_Struct(mADNS__cQuery, cQuery_mark, cQuery_free, rb_adq_r);
rb_obj_call_init(query, 0, 0);
ecode = adns_submit_reverse(rb_adq_r->rb_ads_r->ads, (struct sockaddr *) &addr,
type, qflags, (void *)query, &rb_adq_r->adq);
if (ecode)
rb_raise(mADNS__eError, strerror(ecode));
return query;
}
|
#submit_reverse_any(ip_addr, type[, qflags]) ⇒ Object
Submit asynchronous request to reverse lookup address <ipaddr> using optional query flags <qflags>. Note: <type> can any resource record.
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 |
# File 'ext/adns/mod_adns.c', line 533
static VALUE cState_submit_reverse_any(int argc, VALUE argv[], VALUE self)
{
VALUE query; /* return instance */
rb_adns_query_t *rb_adq_r = ALLOC(rb_adns_query_t);
const char *owner;
struct sockaddr_in addr;
const char *zone; /* in-addr.arpa or any other reverse zones */
adns_rrtype type = adns_r_none;
adns_queryflags qflags = adns_qf_owner;
int idx, ecode;
Data_Get_Struct(self, rb_adns_state_t, rb_adq_r->rb_ads_r);
if (argc < 3)
rb_raise(rb_eArgError, "wrong number of arguments (%d for 3)", argc);
if (argc > 4)
rb_raise(rb_eArgError, "excess number of arguments (%d for 4)", argc);
CHECK_TYPE(argv[0], T_STRING); /* IP */
CHECK_TYPE(argv[1], T_STRING); /* Zone */
CHECK_TYPE(argv[2], T_FIXNUM); /* RR */
if (argc == 4)
CHECK_TYPE(argv[3], T_FIXNUM); /* )); */
owner = STR2CSTR(argv[0]);
zone = STR2CSTR(argv[1]);
type = FIX2INT(argv[2]);
if (argc == 4)
qflags |= FIX2INT(argv[3]);
addr.sin_family = AF_INET;
ecode = inet_aton(owner, &addr.sin_addr);
if (ecode == 0)
rb_raise(mADNS__eQueryError, "invalid ip address");
rb_adq_r->answer = Qnil;
query = Data_Wrap_Struct(mADNS__cQuery, cQuery_mark, cQuery_free, rb_adq_r);
rb_obj_call_init(query, 0, 0);
ecode = adns_submit_reverse_any(rb_adq_r->rb_ads_r->ads, (struct sockaddr*)&addr,
zone, type, qflags, (void *)query, &rb_adq_r->adq);
if (ecode)
rb_raise(mADNS__eError, strerror(ecode));
return query;
}
|
#synchronous(domain, type[, qflags]) ⇒ Hash
Submit synchronous request to resolve domain <domain> of record type <type> using optional query flags <qflags>.
625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 |
# File 'ext/adns/mod_adns.c', line 625
static VALUE cState_synchronous(int argc, VALUE argv[], VALUE self)
{
VALUE answer = rb_hash_new(); /* return instance */
rb_adns_state_t *rb_ads_r;
adns_answer *answer_r;
adns_queryflags qflags = adns_qf_owner;
adns_rrtype type = adns_r_none;
const char *owner;
int ecode;
Data_Get_Struct(self, rb_adns_state_t, rb_ads_r);
if (argc < 2)
rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)", argc);
if (argc > 3)
rb_raise(rb_eArgError, "excess number of arguments (%d for 3)", argc);
CHECK_TYPE(argv[0], T_STRING); /* DOMAIN */
CHECK_TYPE(argv[1], T_FIXNUM); /* RR */
if (argc == 3)
CHECK_TYPE(argv[2], T_FIXNUM); /* QFlags */
owner = STR2CSTR(argv[0]);
type = FIX2INT(argv[1]);
if (argc == 3)
qflags |= FIX2INT(argv[2]);
ecode = adns_synchronous(rb_ads_r->ads, owner, type, qflags, &answer_r);
if (ecode)
rb_raise(mADNS__eError, adns_strerror(ecode));
/* populate return hash */
rb_hash_aset(answer, CSTR2SYM("type"), INT2FIX(answer_r->type));
rb_hash_aset(answer, CSTR2SYM("owner"), CSTR2STR(answer_r->owner));
rb_hash_aset(answer, CSTR2SYM("status"), INT2FIX(answer_r->status));
rb_hash_aset(answer, CSTR2SYM("expires"), INT2FIX(answer_r->expires));
rb_hash_aset(answer, CSTR2SYM("answer"), Qnil);
if (answer_r->nrrs == 0)
return answer;
else
rb_hash_aset(answer, CSTR2SYM("answer"), parse_adns_answer(answer_r));
return answer;
}
|