/* * call-seq: * LDAP::Conn.new(host='localhost', port=LDAP_PORT) => LDAP::Conn * * Return a new LDAP::Conn connection to the server, +host+, on port +port+. */ VALUE rb_ldap_conn_initialize (int argc, VALUE argv[], VALUE self) { LDAP *cldap; char *chost; int cport; int was_verbose = Qfalse; RB_LDAP_DATA *ldapdata; VALUE host, port; Data_Get_Struct (self, RB_LDAP_DATA, ldapdata); if (ldapdata->ldap) { return Qnil; } switch (rb_scan_args (argc, argv, "02", &host, &port)) { case 0: chost = ALLOCA_N (char, strlen ("localhost") + 1); strcpy (chost, "localhost"); cport = LDAP_PORT; break; case 1: chost = StringValueCStr (host); cport = LDAP_PORT; break; case 2: chost = StringValueCStr (host); cport = NUM2INT (port); break; default: rb_bug ("rb_ldap_conn_new"); }; cldap = ldap_init (chost, cport); if (!cldap) rb_raise (rb_eLDAP_ResultError, "can't initialise an LDAP session"); ldapdata->ldap = cldap; rb_iv_set (self, "@args", rb_ary_new4 (argc, argv)); /* Silence warning that next rb_iv_get produces. */ if (ruby_verbose == Qtrue) { was_verbose = Qtrue; ruby_verbose = Qfalse; } if (rb_iv_get (self, "@sasl_quiet") != Qtrue) rb_iv_set (self, "@sasl_quiet", Qfalse); if (was_verbose == Qtrue) ruby_verbose = Qtrue; return Qnil; }