Skip to content

Update conn.c #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -1855,14 +1855,20 @@ Init_ldap_conn ()
{
rb_ldap_sort_obj = Qnil;

#if defined(RB_LDAP_RVC) && RB_LDAP_RVC < 30000
rb_cLDAP_Conn = rb_define_class_under (rb_mLDAP, "Conn", rb_cData);
#endif
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000
rb_cLDAP_Conn = rb_define_class_under (rb_mLDAP, "Conn", rb_cObject);
rb_undef_alloc_func(rb_cLDAP_Conn);
#endif
rb_define_attr (rb_cLDAP_Conn, "referrals", 1, 0);
rb_define_attr (rb_cLDAP_Conn, "controls", 1, 0);
rb_define_attr (rb_cLDAP_Conn, "sasl_quiet", 1, 1);
#if RUBY_VERSION_CODE < 170
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC < 10700
rb_define_singleton_method (rb_cLDAP_Conn, "new", rb_ldap_class_new, -1);
#endif
#if RUBY_VERSION_CODE >= 173
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 10703
rb_define_alloc_func (rb_cLDAP_Conn, rb_ldap_conn_s_allocate);
#else
rb_define_singleton_method (rb_cLDAP_Conn, "allocate",
Expand Down
26 changes: 13 additions & 13 deletions entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

VALUE rb_cLDAP_Entry;

#if RUBY_VERSION_CODE >= 190
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 10900
static void
rb_ldap_entry_mark(RB_LDAPENTRY_DATA *edata)
{
Expand Down Expand Up @@ -88,11 +88,11 @@ rb_ldap_entry_new (LDAP * ldap, LDAPMessage * msg)
{
VALUE val;
RB_LDAPENTRY_DATA *edata;
#if RUBY_VERSION_CODE >= 190
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 10900
char *c_dn;
#endif

#if RUBY_VERSION_CODE >= 190
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 10900
val = Data_Make_Struct (rb_cLDAP_Entry, RB_LDAPENTRY_DATA,
rb_ldap_entry_mark, rb_ldap_entry_free, edata);
#else
Expand All @@ -102,7 +102,7 @@ rb_ldap_entry_new (LDAP * ldap, LDAPMessage * msg)
edata->ldap = ldap;
edata->msg = msg;

#if RUBY_VERSION_CODE >= 190
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 10900
/* get dn */
c_dn = ldap_get_dn(ldap, msg);
if (c_dn) {
Expand All @@ -128,14 +128,14 @@ VALUE
rb_ldap_entry_get_dn (VALUE self)
{
RB_LDAPENTRY_DATA *edata;
#if RUBY_VERSION_CODE < 190
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC < 10900
char *cdn;
VALUE dn;
#endif

GET_LDAPENTRY_DATA (self, edata);

#if RUBY_VERSION_CODE < 190
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC < 10900
cdn = ldap_get_dn (edata->ldap, edata->msg);
if (cdn)
{
Expand Down Expand Up @@ -166,7 +166,7 @@ VALUE
rb_ldap_entry_get_values (VALUE self, VALUE attr)
{
RB_LDAPENTRY_DATA *edata;
#if RUBY_VERSION_CODE < 190
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC < 10900
char *c_attr;
struct berval **c_vals;
int i;
Expand All @@ -175,7 +175,7 @@ rb_ldap_entry_get_values (VALUE self, VALUE attr)
#endif

GET_LDAPENTRY_DATA (self, edata);
#if RUBY_VERSION_CODE < 190
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC < 10900
c_attr = StringValueCStr (attr);

c_vals = ldap_get_values_len (edata->ldap, edata->msg, c_attr);
Expand Down Expand Up @@ -213,7 +213,7 @@ VALUE
rb_ldap_entry_get_attributes (VALUE self)
{
RB_LDAPENTRY_DATA *edata;
#if RUBY_VERSION_CODE < 190
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC < 10900
VALUE vals;
char *attr;
BerElement *ber = NULL;
Expand All @@ -223,7 +223,7 @@ rb_ldap_entry_get_attributes (VALUE self)

GET_LDAPENTRY_DATA (self, edata);

#if RUBY_VERSION_CODE < 190
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC < 10900
vals = rb_ary_new ();
for (attr = ldap_first_attribute (edata->ldap, edata->msg, &ber);
attr != NULL;
Expand Down Expand Up @@ -259,7 +259,7 @@ rb_ldap_entry_get_attributes (VALUE self)
VALUE
rb_ldap_entry_to_hash (VALUE self)
{
#if RUBY_VERSION_CODE < 190
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC < 10900
VALUE attrs = rb_ldap_entry_get_attributes (self);
VALUE hash = rb_hash_new ();
VALUE attr, vals;
Expand All @@ -269,7 +269,7 @@ rb_ldap_entry_to_hash (VALUE self)
VALUE hash, dn_ary;
#endif

#if RUBY_VERSION_CODE < 190
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC < 10900
Check_Type (attrs, T_ARRAY);
rb_hash_aset (hash, rb_tainted_str_new2 ("dn"),
rb_ary_new3 (1, rb_ldap_entry_get_dn (self)));
Expand Down Expand Up @@ -305,7 +305,7 @@ rb_ldap_entry_inspect (VALUE self)
str = rb_str_new (0, strlen (c) + 10 + 16 + 1); /* 10:tags 16:addr 1:nul */
sprintf (RSTRING_PTR (str), "#<%s:0x%lx\n", c, self);

#if RUBY_VERSION_CODE < 190
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC < 10900
RSTRING(str)->len = strlen (RSTRING_PTR (str));
#else
rb_str_set_len(str, strlen (RSTRING_PTR (str)));
Expand Down
6 changes: 6 additions & 0 deletions extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,12 @@ def ldap_with_config(arg, default = nil)

$defs << "-DRUBY_VERSION_CODE=#{RUBY_VERSION.gsub(/\D/, '')}"

def rb_ldap_rb_ver_code
( _major, _minor, _teeny ) = RUBY_VERSION.split(/\D/)
_rvc = _major.to_i * 10000 + _minor.to_i * 100 + _teeny.to_i
end
$defs << "-DRB_LDAP_RVC=#{rb_ldap_rb_ver_code}"

create_makefile("ldap")


Expand Down
6 changes: 3 additions & 3 deletions misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ rb_ldap_control_s_allocate (VALUE klass)
return Data_Wrap_Struct (klass, 0, rb_ldap_control_free, ctl);
}

#if RUBY_VERSION_CODE < 170
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC < 10700
static VALUE
rb_ldap_control_s_new (int argc, VALUE argv[], VALUE klass)
{
Expand Down Expand Up @@ -479,11 +479,11 @@ Init_ldap_misc ()

#ifdef HAVE_LDAPCONTROL
rb_cLDAP_Control = rb_define_class_under (rb_mLDAP, "Control", rb_cObject);
#if RUBY_VERSION_CODE < 170
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC < 10700
rb_define_singleton_method (rb_cLDAP_Control, "new",
rb_ldap_control_s_new, -1);
#endif
#if RUBY_VERSION_CODE >= 173
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 10703
rb_define_alloc_func (rb_cLDAP_Control, rb_ldap_control_s_allocate);
#else
rb_define_singleton_method (rb_cLDAP_Control, "allocate",
Expand Down
6 changes: 3 additions & 3 deletions mod.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ rb_ldap_mod_inspect (VALUE self)
str = rb_str_new (0, strlen (c) + 10 + 16 + 1); /* 10:tags 16:addr 1:nul */
sprintf (RSTRING_PTR (str), "#<%s:0x%lx ", c, self);

#if RUBY_VERSION_CODE < 190
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC < 10900
RSTRING(str)->len = strlen (RSTRING_PTR (str));
#else
rb_str_set_len(str, strlen (RSTRING_PTR (str)));
Expand Down Expand Up @@ -336,10 +336,10 @@ void
Init_ldap_mod ()
{
rb_cLDAP_Mod = rb_define_class_under (rb_mLDAP, "Mod", rb_cObject);
#if RUBY_VERSION_CODE < 170
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC < 10700
rb_define_singleton_method (rb_cLDAP_Mod, "new", rb_ldap_class_new, -1);
#endif
#if RUBY_VERSION_CODE >= 173
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 10703
rb_define_alloc_func (rb_cLDAP_Mod, rb_ldap_mod_s_allocate);
#else
rb_define_singleton_method (rb_cLDAP_Mod, "allocate",
Expand Down
15 changes: 13 additions & 2 deletions rbldap.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ typedef struct rb_ldapentry_data
{
LDAP *ldap;
LDAPMessage *msg;
#if RUBY_VERSION_CODE >= 190
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 10900
VALUE dn;
VALUE attr;
#endif
Expand Down Expand Up @@ -173,7 +173,7 @@ VALUE rb_ldap_mod_vals (VALUE);
}; \
}

#if RUBY_VERSION_CODE < 190
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC < 10900
#define GET_LDAPENTRY_DATA(obj,ptr) { \
Data_Get_Struct(obj, struct rb_ldapentry_data, ptr); \
if( ! ptr->msg ){ \
Expand Down Expand Up @@ -205,3 +205,14 @@ VALUE rb_ldap_mod_vals (VALUE);
rb_define_method(rb_cLDAP_Mod,method,cfunc,argc)

#endif

#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 20700
# if defined rb_tainted_str_new
# undef rb_tainted_str_new
# endif
# if defined rb_tainted_str_new2
# undef rb_tainted_str_new2
# endif
# define rb_tainted_str_new(p,l) rb_str_new((p),(l))
# define rb_tainted_str_new2(p) rb_str_new_cstr((p))
#endif