Ejemplo n.º 1
0
/*
 * call-seq:
 * entry.get_values(attr)  => Array of String
 * entry.vals(attr)        => Array of String
 * entry[attr]             => Array of String
 *
 * Return an array of all the values belonging to the attribute, +attr+, of
 * the entry.
 */
VALUE
rb_ldap_entry_get_values (VALUE self, VALUE attr)
{
  RB_LDAPENTRY_DATA *edata;
  char *c_attr;
  struct berval **c_vals;
  int i;
  int count;
  VALUE vals;

  GET_LDAPENTRY_DATA (self, edata);
  c_attr = StringValueCStr (attr);

  c_vals = ldap_get_values_len (edata->ldap, edata->msg, c_attr);
  if (c_vals)
    {
      vals = rb_ary_new ();
      count = ldap_count_values_len (c_vals);
      for (i = 0; i < count; i++)
	{
	  VALUE str;
	  str = rb_tainted_str_new (c_vals[i]->bv_val, c_vals[i]->bv_len);
	  rb_ary_push (vals, str);
	}
      ldap_value_free_len (c_vals);
    }
  else
    {
      vals = Qnil;
    }

  return vals;
}
Ejemplo n.º 2
0
/*
 * call-seq:
 * entry.get_attributes  => Array of String
 * entry.attrs           => Array of String
 *
 * Return an array of all the attributes belonging to the entry.
 */
VALUE
rb_ldap_entry_get_attributes (VALUE self)
{
  RB_LDAPENTRY_DATA *edata;
  VALUE vals;
  char *attr;
  BerElement *ber = NULL;

  GET_LDAPENTRY_DATA (self, edata);

  vals = rb_ary_new ();
  for (attr = ldap_first_attribute (edata->ldap, edata->msg, &ber);
       attr != NULL;
       attr = ldap_next_attribute (edata->ldap, edata->msg, ber))
    {
      rb_ary_push (vals, rb_tainted_str_new2 (attr));
      ldap_memfree(attr);
    }

    #if !defined(USE_OPENLDAP1)
    if( ber != NULL ){
      ber_free(ber, 0);
    }
    #endif

  return vals;
}
Ejemplo n.º 3
0
/*
 * call-seq:
 * entry.get_values(attr)  => Array of String
 * entry.vals(attr)        => Array of String
 * entry[attr]             => Array of String
 *
 * Return an array of all the values belonging to the attribute, +attr+, of
 * the entry.
 */
VALUE
rb_ldap_entry_get_values (VALUE self, VALUE attr)
{
  RB_LDAPENTRY_DATA *edata;

  GET_LDAPENTRY_DATA (self, edata);

  return rb_hash_aref(edata->attr, attr);
}
Ejemplo n.º 4
0
/*
 * call-seq:
 * entry.get_dn  => String
 * entry.dn      => String
 */
VALUE
rb_ldap_entry_get_dn (VALUE self)
{
  RB_LDAPENTRY_DATA *edata;

  GET_LDAPENTRY_DATA (self, edata);

  return edata->dn;
}
Ejemplo n.º 5
0
/*
 * call-seq:
 * entry.to_hash  => Hash
 *
 * Convert the entry to a hash.
 */
VALUE
rb_ldap_entry_to_hash (VALUE self)
{
  RB_LDAPENTRY_DATA *edata;
  VALUE hash, dn_ary;

  GET_LDAPENTRY_DATA (self, edata);
  hash = rb_hash_dup(edata->attr);
  dn_ary = rb_ary_new3(1, edata->dn);
  rb_hash_aset(hash, rb_tainted_str_new2("dn"), dn_ary);
  return hash;
}
Ejemplo n.º 6
0
/*
 * call-seq:
 * entry.get_attributes  => Array of String
 * entry.attrs           => Array of String
 *
 * Return an array of all the attributes belonging to the entry.
 */
VALUE
rb_ldap_entry_get_attributes (VALUE self)
{
  RB_LDAPENTRY_DATA *edata;
  VALUE attrs;

  GET_LDAPENTRY_DATA (self, edata);

  attrs = rb_funcall(edata->attr, rb_intern("keys"), 0);
  if (TYPE(attrs) != T_ARRAY) {
    return Qnil;
  }

  return attrs;
}
Ejemplo n.º 7
0
/*
 * call-seq:
 * entry.get_dn  => String
 * entry.dn      => String
 */
VALUE
rb_ldap_entry_get_dn (VALUE self)
{
  RB_LDAPENTRY_DATA *edata;
  char *cdn;
  VALUE dn;

  GET_LDAPENTRY_DATA (self, edata);

  cdn = ldap_get_dn (edata->ldap, edata->msg);
  if (cdn)
    {
      dn = rb_tainted_str_new2 (cdn);
      ldap_memfree (cdn);
    }
  else
    {
      dn = Qnil;
    }

  return dn;
}