Method: ADNS::State.new2

Defined in:
ext/adns/mod_adns.c

.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>.



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
789
# File 'ext/adns/mod_adns.c', line 750

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;
}