/* * call-seq: * LDAP::Conn.open(host='localhost', port=LDAP_PORT) => LDAP::Conn * * Return a new LDAP::Conn connection to the server, +host+, on port +port+. */ VALUE rb_ldap_conn_s_open (int argc, VALUE argv[], VALUE klass) { LDAP *cldap; char *chost; int cport; VALUE host, port; VALUE conn; 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_open (chost, cport); if (!cldap) rb_raise (rb_eLDAP_ResultError, "can't open an LDAP session"); conn = rb_ldap_conn_new (klass, cldap); return conn; }