/* * call-seq: * conn.add(dn, attrs) => self * * Add an entry with the DN, +dn+, and the attributes, +attrs+. +attrs+ * should be either an array of LDAP#Mod objects or a hash of attribute/value * array pairs. */ VALUE rb_ldap_conn_add_s (VALUE self, VALUE dn, VALUE attrs) { RB_LDAP_DATA *ldapdata; char *c_dn; LDAPMod **c_attrs; int i; switch (TYPE (attrs)) { case T_HASH: attrs = rb_ldap_hash2mods (rb_mLDAP, INT2NUM (LDAP_MOD_ADD | LDAP_MOD_BVALUES), attrs); break; case T_ARRAY: break; default: rb_raise (rb_eTypeError, "must be a hash or an array"); }; GET_LDAP_DATA (self, ldapdata); c_dn = StringValueCStr (dn); c_attrs = ALLOCA_N (LDAPMod *, (RARRAY (attrs)->len + 1)); for (i = 0; i < RARRAY (attrs)->len; i++) { VALUE mod = RARRAY (attrs)->ptr[i]; RB_LDAPMOD_DATA *moddata; Check_Kind (mod, rb_cLDAP_Mod); GET_LDAPMOD_DATA (mod, moddata); c_attrs[i] = moddata->mod; }; c_attrs[i] = NULL; ldapdata->err = ldap_add_s (ldapdata->ldap, c_dn, c_attrs); Check_LDAP_Result (ldapdata->err); return self; }