From 31c999b9024157cde61e06cc629a54fe8372ec96 Mon Sep 17 00:00:00 2001 From: minamino Date: Wed, 28 Dec 2022 18:14:14 +0900 Subject: [PATCH 1/3] Update conn.c ruby >= 3.0: use rb_cObject instead of rb_cData ruby < 3.0: use rb_cData ruby 2.7 will be outdated soon. --- conn.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/conn.c b/conn.c index e628695..54c91a1 100644 --- a/conn.c +++ b/conn.c @@ -1855,7 +1855,13 @@ Init_ldap_conn () { rb_ldap_sort_obj = Qnil; +#if RUBY_VERSION_CODE >= 300 + rb_cLDAP_Conn = rb_define_class_under (rb_mLDAP, "Conn", rb_cObject); + rb_undef_alloc_func (rb_cLDAP_Conn); +#endif +#if RUBY_VERSION_CODE < 300 rb_cLDAP_Conn = rb_define_class_under (rb_mLDAP, "Conn", rb_cData); +#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); From 9a488dc19c185df3629d0093f65aa73a2370bd6c Mon Sep 17 00:00:00 2001 From: minamino Date: Fri, 19 May 2023 16:18:39 +0900 Subject: [PATCH 2/3] replace RUBY_VERSION_CODE with RB_LDAP_RVC --- conn.c | 14 +++++++------- entry.c | 26 +++++++++++++------------- extconf.rb | 6 ++++++ misc.c | 6 +++--- mod.c | 6 +++--- rbldap.h | 15 +++++++++++++-- 6 files changed, 45 insertions(+), 28 deletions(-) diff --git a/conn.c b/conn.c index 54c91a1..fb5ee7d 100644 --- a/conn.c +++ b/conn.c @@ -1855,20 +1855,20 @@ Init_ldap_conn () { rb_ldap_sort_obj = Qnil; -#if RUBY_VERSION_CODE >= 300 - rb_cLDAP_Conn = rb_define_class_under (rb_mLDAP, "Conn", rb_cObject); - rb_undef_alloc_func (rb_cLDAP_Conn); -#endif -#if RUBY_VERSION_CODE < 300 +#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", diff --git a/entry.c b/entry.c index 2cddcf9..c630ee8 100644 --- a/entry.c +++ b/entry.c @@ -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) { @@ -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 @@ -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) { @@ -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) { @@ -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; @@ -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); @@ -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; @@ -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; @@ -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; @@ -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))); @@ -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))); diff --git a/extconf.rb b/extconf.rb index 9df2349..3fae4f5 100755 --- a/extconf.rb +++ b/extconf.rb @@ -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") diff --git a/misc.c b/misc.c index 7b7b056..ac1061c 100644 --- a/misc.c +++ b/misc.c @@ -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) { @@ -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", diff --git a/mod.c b/mod.c index 0d8e7f2..7732261 100644 --- a/mod.c +++ b/mod.c @@ -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))); @@ -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", diff --git a/rbldap.h b/rbldap.h index 1fa04e1..2cf53f0 100644 --- a/rbldap.h +++ b/rbldap.h @@ -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 @@ -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 ){ \ @@ -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 From d8ab796dd9d45e34968d5a146d6ff9915f456d42 Mon Sep 17 00:00:00 2001 From: minamino Date: Wed, 25 Feb 2026 20:39:12 +0900 Subject: [PATCH 3/3] Migrate to Ruby TypedData API for Ruby 3.4+ compatibility Replace deprecated Data_Make_Struct / Data_Get_Struct / Data_Wrap_Struct with TypedData equivalents. All changes are version-guarded with - TypedData API migration for Conn, Entry, Mod, Control objects - RARRAY_PTR(ary)[i] -> RARRAY_AREF(ary, i) - rb_time_interval() -> rb_ldap_time_interval() (private API removal) - sprintf(RSTRING_PTR(...)) -> rb_sprintf() - gemspec: remove obsolete fields, add license Tested on Ruby 3.4.1 with OpenLDAP (LDAPS bind/search). --- ChangeLog | 78 +++++++++++++++++++++++++++++++++++++++++++++++ clientauth.c | 16 ++++++++-- conn.c | 59 ++++++++++++++++++++++++++++------- entry.c | 20 ++++++++++-- misc.c | 71 +++++++++++++++++++++++++++++++++++++++++- mod.c | 38 +++++++++++++++++++++-- rbldap.h | 63 +++++++++++++++++++++++++++++++++++--- ruby-ldap.gemspec | 4 +-- saslconn.c | 4 +++ sslconn.c | 16 ++++++++++ 10 files changed, 342 insertions(+), 27 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0ccf3b6..4dca9af 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,81 @@ +2026-02-25 Hisashi MINAMINO + + * Ruby 3.4 / 4.0 compatibility: migrate deprecated C APIs. + + All changes are guarded by #if RB_LDAP_RVC >= 30000 to preserve + backward compatibility with Ruby 2.x. + + * rbldap.h: Replace DATA_PTR() with RTYPEDDATA_DATA() in + RLDAP_DATA_PTR macro (version-guarded). + * rbldap.h: Replace rb_time_interval() extern declaration with + rb_ldap_time_interval() static inline implementation. + rb_time_interval is a Ruby private API not guaranteed across + versions. + * rbldap.h: Add extern declarations for TypedData type structs: + rb_ldap_conn_data_type, rb_ldap_entry_data_type, + rb_ldap_mod_data_type, rb_ldap_control_data_type, + rb_ldap_control_nofree_data_type. + * rbldap.h: Version-guard GET_LDAP_DATA, Check_LDAPENTRY, + GET_LDAPENTRY_DATA, GET_LDAPMOD_DATA macros to use + TypedData_Get_Struct on Ruby >= 3.0, Data_Get_Struct otherwise. + + * conn.c: Define rb_ldap_conn_data_type with mark/free functions. + * conn.c (rb_ldap_conn_new): Use TypedData_Make_Struct. + * conn.c (rb_ldap_conn_initialize, rb_ldap_conn_simple_bind_s, + rb_ldap_conn_bind_s, rb_ldap_conn_bound): Use + TypedData_Get_Struct. + * conn.c (rb_ldap_conn_rebind): Replace RARRAY_PTR(ary) used as + argv with ALLOCA_N + RARRAY_AREF loop. + * conn.c (rb_ldap_conn_set_option): Replace rb_time_interval() + with rb_ldap_time_interval(). + * conn.c (rb_ldap_conn_search_i, rb_ldap_conn_search_ext_i, + rb_ldap_conn_add_s, rb_ldap_conn_add_ext_s, + rb_ldap_conn_modify_s, rb_ldap_conn_modify_ext_s): Replace + RARRAY_PTR(x)[i] with RARRAY_AREF(x, i). + + * entry.c: Define rb_ldap_entry_data_type with mark/free + functions. + * entry.c (rb_ldap_entry_new): Add TypedData_Make_Struct branch + for Ruby >= 3.0, keeping Data_Make_Struct for older versions. + * entry.c (rb_ldap_entry_inspect): Use rb_sprintf() on + Ruby >= 3.0 instead of sprintf(RSTRING_PTR(...)). + + * mod.c: Define rb_ldap_mod_data_type with free function. + * mod.c (rb_ldap_mod_new, rb_ldap_mod_new2, + rb_ldap_mod_s_allocate): Use TypedData_Make_Struct. + * mod.c (rb_ldap_mod_initialize): Use TypedData_Get_Struct. + Replace RARRAY_PTR(x)[i] with RARRAY_AREF(x, i). + * mod.c (rb_ldap_mod_inspect): Use rb_sprintf() on Ruby >= 3.0. + + * misc.c: Define rb_ldap_control_data_type and + rb_ldap_control_nofree_data_type. + * misc.c (rb_ldap_control_new): Use TypedData_Wrap_Struct. + * misc.c (rb_ldap_control_new2): Use TypedData_Wrap_Struct with + nofree type. + * misc.c (rb_ldap_control_copy, rb_ldap_control_s_allocate, + rb_ldap_control_set_value, rb_ldap_control_get_value, + rb_ldap_control_set_oid, rb_ldap_control_get_oid, + rb_ldap_control_oid, rb_ldap_control_set_critical, + rb_ldap_control_get_critical, rb_ldap_control_critical, + rb_ldap_get_control): Use TypedData_Get_Struct. + * misc.c (rb_ldap_get_apiinfo): Replace RARRAY_PTR(x)[i] with + RARRAY_AREF(x, i). + + * sslconn.c (rb_openldap_sslconn_initialize, + rb_nssldap_sslconn_initialize, + rb_wldap32_sslconn_initialize, rb_ldap_sslconn_bind_f): Use + TypedData_Get_Struct. + + * saslconn.c (rb_ldap_conn_sasl_bind): Use TypedData_Get_Struct. + + * clientauth.c (rb_ldap_sslauthconn_rebind): Replace + RARRAY_PTR(ary) used as argv with ALLOCA_N + RARRAY_AREF loop. + * clientauth.c (rb_ldap_sslauthconn_s_bind, + rb_ldap_sslauthconn_initialize): Use TypedData_Get_Struct. + + * ruby-ldap.gemspec: Remove obsolete rubyforge_project and + has_rdoc. Add license 'BSD-2-Clause'. + Wed Jul 11 21:58:38 UTC 2018 Alexey Chebotar * Version 0.9.20 * Added support of LDAP_OPT_X_TLS_NEWCTX. Thanks to Kouhei Sutou. diff --git a/clientauth.c b/clientauth.c index 6b3dded..351df4d 100644 --- a/clientauth.c +++ b/clientauth.c @@ -367,8 +367,12 @@ VALUE rb_ldap_sslauthconn_rebind(VALUE self) { VALUE ary = rb_iv_get (self, "@args"); - - return rb_ldap_sslauthconn_initialize(RARRAY_LEN(ary), RARRAY_PTR(ary), self); + int _argc = (int)RARRAY_LEN(ary); + VALUE *_argv = ALLOCA_N(VALUE, _argc); + int i; + for (i = 0; i < _argc; i++) + _argv[i] = RARRAY_AREF(ary, i); + return rb_ldap_sslauthconn_initialize(_argc, _argv, self); } //////////////////////////////////////////////////////////////////////////////// @@ -394,7 +398,11 @@ rb_ldap_sslauthconn_s_bind(int argc, VALUE argv[], VALUE self) { LDAPControl **bindctrls = NULL; +#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000 + TypedData_Get_Struct(self, RB_LDAP_DATA, &rb_ldap_conn_data_type, ldapdata); +#else Data_Get_Struct(self, RB_LDAP_DATA, ldapdata); +#endif if (ldapdata->bind == 0) { if (rb_iv_get(self, "@args") != Qnil) { @@ -450,7 +458,11 @@ rb_ldap_sslauthconn_initialize(int argc, VALUE argv[], VALUE self) VALUE host, port, tls, cp, cn, key_pw, sctrls, cctrls; +#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000 + TypedData_Get_Struct(self, RB_LDAP_DATA, &rb_ldap_conn_data_type, ldapdata); +#else Data_Get_Struct(self, RB_LDAP_DATA, ldapdata); +#endif if (ldapdata->ldap) return Qnil; diff --git a/conn.c b/conn.c index fb5ee7d..df78a8c 100644 --- a/conn.c +++ b/conn.c @@ -17,6 +17,19 @@ * rb_mLDAP = rb_define_module ("LDAP"); */ +static void rb_ldap_conn_free (RB_LDAP_DATA *); +static void rb_ldap_conn_mark (RB_LDAP_DATA *); + +#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000 +const rb_data_type_t rb_ldap_conn_data_type = { + "LDAP::Conn", + { (void (*)(void*))rb_ldap_conn_mark, + (void (*)(void*))rb_ldap_conn_free, + NULL }, + NULL, NULL, 0 +}; +#endif + static VALUE rb_ldap_sort_obj = Qnil; extern VALUE rb_ldap_control_new2 (LDAPControl * ctl); extern VALUE rb_ldap_sslconn_initialize (int argc, VALUE argv[], VALUE self); @@ -46,8 +59,13 @@ rb_ldap_conn_new (VALUE klass, LDAP * cldap) VALUE conn; RB_LDAP_DATA *ldapdata; +#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000 + conn = TypedData_Make_Struct (klass, RB_LDAP_DATA, + &rb_ldap_conn_data_type, ldapdata); +#else conn = Data_Make_Struct (klass, RB_LDAP_DATA, rb_ldap_conn_mark, rb_ldap_conn_free, ldapdata); +#endif ldapdata->ldap = cldap; ldapdata->err = 0; ldapdata->bind = 0; @@ -78,7 +96,11 @@ rb_ldap_conn_initialize (int argc, VALUE argv[], VALUE self) VALUE host, port; +#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000 + TypedData_Get_Struct (self, RB_LDAP_DATA, &rb_ldap_conn_data_type, ldapdata); +#else Data_Get_Struct (self, RB_LDAP_DATA, ldapdata); +#endif if (ldapdata->ldap) { return Qnil; @@ -229,13 +251,16 @@ VALUE rb_ldap_conn_rebind (VALUE self) { VALUE ary = rb_iv_get (self, "@args"); + int argc = (int)RARRAY_LEN (ary); + VALUE *argv = ALLOCA_N (VALUE, argc); + int j; + for (j = 0; j < argc; j++) + argv[j] = RARRAY_AREF (ary, j); if (rb_obj_is_kind_of (self, rb_cLDAP_SSLConn) == Qtrue) - return rb_ldap_sslconn_initialize (RARRAY_LEN (ary), RARRAY_PTR (ary), - self); + return rb_ldap_sslconn_initialize (argc, argv, self); else - return rb_ldap_conn_initialize (RARRAY_LEN (ary), RARRAY_PTR (ary), - self); + return rb_ldap_conn_initialize (argc, argv, self); } /* @@ -255,7 +280,11 @@ rb_ldap_conn_simple_bind_s (int argc, VALUE argv[], VALUE self) char *dn = NULL; char *passwd = NULL; +#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000 + TypedData_Get_Struct (self, RB_LDAP_DATA, &rb_ldap_conn_data_type, ldapdata); +#else Data_Get_Struct (self, RB_LDAP_DATA, ldapdata); +#endif if (!ldapdata->ldap) { if (rb_iv_get (self, "@args") != Qnil) @@ -346,7 +375,11 @@ rb_ldap_conn_bind_s (int argc, VALUE argv[], VALUE self) char *passwd = NULL; int method = LDAP_AUTH_SIMPLE; +#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000 + TypedData_Get_Struct (self, RB_LDAP_DATA, &rb_ldap_conn_data_type, ldapdata); +#else Data_Get_Struct (self, RB_LDAP_DATA, ldapdata); +#endif if (!ldapdata->ldap) { if (rb_iv_get (self, "@args") != Qnil) @@ -431,7 +464,11 @@ rb_ldap_conn_bound (VALUE self) { RB_LDAP_DATA *ldapdata; +#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000 + TypedData_Get_Struct (self, RB_LDAP_DATA, &rb_ldap_conn_data_type, ldapdata); +#else Data_Get_Struct (self, RB_LDAP_DATA, ldapdata); +#endif return ldapdata->bind == 0 ? Qfalse : Qtrue; }; @@ -475,7 +512,7 @@ rb_ldap_conn_set_option (VALUE self, VALUE opt, VALUE data) case LDAP_OPT_NETWORK_TIMEOUT: { struct timeval tv; - tv = rb_time_interval(data); + tv = rb_ldap_time_interval(data); optdata = &tv; } break; @@ -908,7 +945,7 @@ rb_ldap_conn_search_i (int argc, VALUE argv[], VALUE self, cattrs = ALLOCA_N (char *, (RARRAY_LEN (attrs) + 1)); for (i = 0; i < RARRAY_LEN (attrs); i++) { - cattrs[i] = StringValueCStr (RARRAY_PTR (attrs)[i]); + cattrs[i] = StringValueCStr (RARRAY_AREF (attrs, i)); }; cattrs[RARRAY_LEN (attrs)] = NULL; } @@ -1241,7 +1278,7 @@ rb_ldap_conn_search_ext_i (int argc, VALUE argv[], VALUE self, cattrs = ALLOCA_N (char *, (RARRAY_LEN (attrs) + 1)); for (i = 0; i < RARRAY_LEN (attrs); i++) { - cattrs[i] = StringValueCStr (RARRAY_PTR (attrs)[i]); + cattrs[i] = StringValueCStr (RARRAY_AREF (attrs, i)); }; cattrs[RARRAY_LEN (attrs)] = NULL; } @@ -1450,7 +1487,7 @@ rb_ldap_conn_add_s (VALUE self, VALUE dn, VALUE attrs) for (i = 0; i < RARRAY_LEN (attrs); i++) { - VALUE mod = RARRAY_PTR (attrs)[i]; + VALUE mod = RARRAY_AREF (attrs, i); RB_LDAPMOD_DATA *moddata; Check_Kind (mod, rb_cLDAP_Mod); GET_LDAPMOD_DATA (mod, moddata); @@ -1505,7 +1542,7 @@ rb_ldap_conn_add_ext_s (VALUE self, VALUE dn, VALUE attrs, for (i = 0; i < RARRAY_LEN (attrs); i++) { - VALUE mod = RARRAY_PTR (attrs)[i]; + VALUE mod = RARRAY_AREF (attrs, i); RB_LDAPMOD_DATA *moddata; Check_Kind (mod, rb_cLDAP_Mod); GET_LDAPMOD_DATA (mod, moddata); @@ -1557,7 +1594,7 @@ rb_ldap_conn_modify_s (VALUE self, VALUE dn, VALUE attrs) for (i = 0; i < RARRAY_LEN (attrs); i++) { - VALUE mod = RARRAY_PTR (attrs)[i]; + VALUE mod = RARRAY_AREF (attrs, i); RB_LDAPMOD_DATA *moddata; Check_Kind (mod, rb_cLDAP_Mod); GET_LDAPMOD_DATA (mod, moddata); @@ -1614,7 +1651,7 @@ rb_ldap_conn_modify_ext_s (VALUE self, VALUE dn, VALUE attrs, for (i = 0; i < RARRAY_LEN (attrs); i++) { - VALUE mod = RARRAY_PTR (attrs)[i]; + VALUE mod = RARRAY_AREF (attrs, i); RB_LDAPMOD_DATA *moddata; Check_Kind (mod, rb_cLDAP_Mod); GET_LDAPMOD_DATA (mod, moddata); diff --git a/entry.c b/entry.c index c630ee8..12f220b 100644 --- a/entry.c +++ b/entry.c @@ -83,6 +83,16 @@ rb_ldap_entry_free (RB_LDAPENTRY_DATA * edata) /* ldap_msgfree should be called after ldap_search */ } +#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000 +const rb_data_type_t rb_ldap_entry_data_type = { + "LDAP::Entry", + { (void (*)(void*))rb_ldap_entry_mark, + (void (*)(void*))rb_ldap_entry_free, + NULL }, + NULL, NULL, 0 +}; +#endif + VALUE rb_ldap_entry_new (LDAP * ldap, LDAPMessage * msg) { @@ -92,7 +102,10 @@ rb_ldap_entry_new (LDAP * ldap, LDAPMessage * msg) char *c_dn; #endif -#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 10900 +#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000 + val = TypedData_Make_Struct (rb_cLDAP_Entry, RB_LDAPENTRY_DATA, + &rb_ldap_entry_data_type, edata); +#elif 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 @@ -302,13 +315,16 @@ rb_ldap_entry_inspect (VALUE self) const char *c; c = rb_obj_classname (self); +#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000 + str = rb_sprintf ("#<%s:0x%lx\n", c, self); +#else 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 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))); +#endif #endif rb_str_concat (str, rb_inspect (rb_ldap_entry_to_hash (self))); diff --git a/misc.c b/misc.c index ac1061c..48ecdfe 100644 --- a/misc.c +++ b/misc.c @@ -57,7 +57,7 @@ rb_ldap_get_apiinfo (VALUE data) c_extensions = ALLOCA_N (char *, len); for (i = 0; i <= len - 1; i++) { - VALUE str = RARRAY_PTR (r_extensions)[i]; + VALUE str = RARRAY_AREF (r_extensions, i); RB_LDAP_SET_STR (c_extensions[i], str); } info->ldapai_extensions = c_extensions; @@ -84,13 +84,33 @@ rb_ldap_control_free (LDAPControl * ctl) } } +#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000 +const rb_data_type_t rb_ldap_control_data_type = { + "LDAP::Control", + { NULL, + (void (*)(void*))rb_ldap_control_free, + NULL }, + NULL, NULL, 0 +}; + +const rb_data_type_t rb_ldap_control_nofree_data_type = { + "LDAP::Control(ref)", + { NULL, NULL, NULL }, + NULL, NULL, 0 +}; +#endif + VALUE rb_ldap_control_new (LDAPControl * ctl) { if (!ctl) return Qnil; else +#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000 + return TypedData_Wrap_Struct (rb_cLDAP_Control, &rb_ldap_control_data_type, ctl); +#else return Data_Wrap_Struct (rb_cLDAP_Control, 0, rb_ldap_control_free, ctl); +#endif } /* Identical to rb_ldap_control_new, but does not define a routine with which @@ -102,7 +122,11 @@ rb_ldap_control_new2 (LDAPControl * ctl) if (!ctl) return Qnil; else +#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000 + return TypedData_Wrap_Struct (rb_cLDAP_Control, &rb_ldap_control_nofree_data_type, ctl); +#else return Data_Wrap_Struct (rb_cLDAP_Control, 0, 0, ctl); +#endif } /* This is called by #initialize_copy and is using for duping/cloning. */ @@ -111,8 +135,13 @@ rb_ldap_control_copy (VALUE copy, VALUE orig) { LDAPControl *orig_ctl, *copy_ctl; +#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000 + TypedData_Get_Struct (orig, LDAPControl, &rb_ldap_control_data_type, orig_ctl); + TypedData_Get_Struct (copy, LDAPControl, &rb_ldap_control_data_type, copy_ctl); +#else Data_Get_Struct (orig, LDAPControl, orig_ctl); Data_Get_Struct (copy, LDAPControl, copy_ctl); +#endif memcpy (copy_ctl, orig_ctl, (size_t) sizeof (LDAPControl)); return copy; @@ -128,7 +157,11 @@ rb_ldap_control_s_allocate (VALUE klass) ctl->ldctl_value.bv_len = 0; ctl->ldctl_oid = NULL; ctl->ldctl_iscritical = 0; +#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000 + return TypedData_Wrap_Struct (klass, &rb_ldap_control_data_type, ctl); +#else return Data_Wrap_Struct (klass, 0, rb_ldap_control_free, ctl); +#endif } #if defined(RB_LDAP_RVC) && RB_LDAP_RVC < 10700 @@ -149,7 +182,11 @@ rb_ldap_control_set_value (VALUE self, VALUE val) { LDAPControl *ctl; + #if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000 + TypedData_Get_Struct (self, LDAPControl, &rb_ldap_control_data_type, ctl); + #else Data_Get_Struct (self, LDAPControl, ctl); + #endif if (ctl->ldctl_value.bv_val) free (ctl->ldctl_value.bv_val); @@ -174,7 +211,11 @@ rb_ldap_control_get_value (VALUE self) LDAPControl *ctl; VALUE val; + #if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000 + TypedData_Get_Struct (self, LDAPControl, &rb_ldap_control_data_type, ctl); + #else Data_Get_Struct (self, LDAPControl, ctl); + #endif if (ctl->ldctl_value.bv_len == 0 || ctl->ldctl_value.bv_val == NULL) { @@ -223,7 +264,11 @@ rb_ldap_control_set_oid (VALUE self, VALUE val) { LDAPControl *ctl; + #if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000 + TypedData_Get_Struct (self, LDAPControl, &rb_ldap_control_data_type, ctl); + #else Data_Get_Struct (self, LDAPControl, ctl); + #endif if (ctl->ldctl_oid) free (ctl->ldctl_oid); @@ -246,7 +291,11 @@ rb_ldap_control_get_oid (VALUE self) LDAPControl *ctl; VALUE val; + #if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000 + TypedData_Get_Struct (self, LDAPControl, &rb_ldap_control_data_type, ctl); + #else Data_Get_Struct (self, LDAPControl, ctl); + #endif if (ctl->ldctl_oid == NULL) { @@ -283,7 +332,11 @@ rb_ldap_control_oid (int argc, VALUE argv[], VALUE self) VALUE val; LDAPControl *ctl; + #if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000 + TypedData_Get_Struct (self, LDAPControl, &rb_ldap_control_data_type, ctl); + #else Data_Get_Struct (self, LDAPControl, ctl); + #endif if (rb_scan_args (argc, argv, "01", &val) == 1) { val = rb_ldap_control_set_oid (self, val); @@ -300,7 +353,11 @@ rb_ldap_control_set_critical (VALUE self, VALUE val) { LDAPControl *ctl; + #if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000 + TypedData_Get_Struct (self, LDAPControl, &rb_ldap_control_data_type, ctl); + #else Data_Get_Struct (self, LDAPControl, ctl); + #endif ctl->ldctl_iscritical = (val == Qtrue) ? 1 : 0; return val; } @@ -311,7 +368,11 @@ rb_ldap_control_get_critical (VALUE self) LDAPControl *ctl; VALUE val; + #if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000 + TypedData_Get_Struct (self, LDAPControl, &rb_ldap_control_data_type, ctl); + #else Data_Get_Struct (self, LDAPControl, ctl); + #endif val = ctl->ldctl_iscritical ? Qtrue : Qfalse; return val; @@ -343,7 +404,11 @@ rb_ldap_control_critical (int argc, VALUE argv[], VALUE self) VALUE val; LDAPControl *ctl; + #if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000 + TypedData_Get_Struct (self, LDAPControl, &rb_ldap_control_data_type, ctl); + #else Data_Get_Struct (self, LDAPControl, ctl); + #endif if (rb_scan_args (argc, argv, "01", &val) == 1) { val = rb_ldap_control_set_critical (self, val); @@ -436,7 +501,11 @@ rb_ldap_get_control (VALUE obj) } else { + #if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000 + TypedData_Get_Struct (obj, LDAPControl, &rb_ldap_control_data_type, ctl); + #else Data_Get_Struct (obj, LDAPControl, ctl); + #endif return ctl; } } diff --git a/mod.c b/mod.c index 7732261..61ca662 100644 --- a/mod.c +++ b/mod.c @@ -8,6 +8,17 @@ VALUE rb_cLDAP_Mod; +#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000 +extern void rb_ldap_mod_free (RB_LDAPMOD_DATA * data); + +const rb_data_type_t rb_ldap_mod_data_type = { + "LDAP::Mod", + { NULL, + (void (*)(void*))rb_ldap_mod_free, + NULL }, + NULL, NULL, 0 +}; +#endif void rb_ldap_mod_free (RB_LDAPMOD_DATA * data) @@ -67,8 +78,13 @@ rb_ldap_mod_new (int mod_op, char *mod_type, char **modv_strvals) VALUE obj; RB_LDAPMOD_DATA *moddata; +#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000 + obj = TypedData_Make_Struct (rb_cLDAP_Mod, RB_LDAPMOD_DATA, + &rb_ldap_mod_data_type, moddata); +#else obj = Data_Make_Struct (rb_cLDAP_Mod, RB_LDAPMOD_DATA, 0, rb_ldap_mod_free, moddata); +#endif moddata->mod = rb_ldap_new_mod (mod_op, mod_type, modv_strvals); return obj; @@ -99,8 +115,13 @@ rb_ldap_mod_new2 (int mod_op, char *mod_type, struct berval ** modv_bvals) VALUE obj; RB_LDAPMOD_DATA *moddata; +#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000 + obj = TypedData_Make_Struct (rb_cLDAP_Mod, RB_LDAPMOD_DATA, + &rb_ldap_mod_data_type, moddata); +#else obj = Data_Make_Struct (rb_cLDAP_Mod, RB_LDAPMOD_DATA, 0, rb_ldap_mod_free, moddata); +#endif moddata->mod = rb_ldap_new_mod2 (mod_op, mod_type, modv_bvals); return obj; @@ -113,7 +134,11 @@ rb_ldap_mod_s_allocate (VALUE klass) VALUE obj; obj = +#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000 + TypedData_Make_Struct (klass, RB_LDAPMOD_DATA, &rb_ldap_mod_data_type, moddata); +#else Data_Make_Struct (klass, RB_LDAPMOD_DATA, 0, rb_ldap_mod_free, moddata); +#endif moddata->mod = NULL; return obj; @@ -147,7 +172,11 @@ rb_ldap_mod_initialize (int argc, VALUE argv[], VALUE self) RB_LDAPMOD_DATA *moddata; rb_scan_args (argc, argv, "3", &op, &type, &vals); +#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000 + TypedData_Get_Struct (self, RB_LDAPMOD_DATA, &rb_ldap_mod_data_type, moddata); +#else Data_Get_Struct (self, RB_LDAPMOD_DATA, moddata); +#endif if (moddata->mod) return Qnil; @@ -162,7 +191,7 @@ rb_ldap_mod_initialize (int argc, VALUE argv[], VALUE self) { VALUE str; struct berval *bval; - str = RARRAY_PTR (vals)[i]; + str = RARRAY_AREF (vals, i); Check_Type (str, T_STRING); bval = ALLOC_N (struct berval, 1); bval->bv_len = RSTRING_LEN (str); @@ -179,7 +208,7 @@ rb_ldap_mod_initialize (int argc, VALUE argv[], VALUE self) { VALUE str; char *sval; - str = RARRAY_PTR (vals)[i]; + str = RARRAY_AREF (vals, i); RB_LDAP_SET_STR (sval, str); strvals[i] = sval; } @@ -280,13 +309,16 @@ rb_ldap_mod_inspect (VALUE self) const char *c; c = rb_obj_classname (self); +#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000 + str = rb_sprintf ("#<%s:0x%lx ", c, self); +#else 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 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))); +#endif #endif switch (FIX2INT (rb_ldap_mod_op (self)) & ~LDAP_MOD_BVALUES) diff --git a/rbldap.h b/rbldap.h index 2cf53f0..3d8942d 100644 --- a/rbldap.h +++ b/rbldap.h @@ -49,7 +49,11 @@ typedef struct rb_ldap_data int err; } RB_LDAP_DATA; +#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000 +#define RLDAP_DATA_PTR(obj) ((RB_LDAP_DATA*)RTYPEDDATA_DATA(obj)) +#else #define RLDAP_DATA_PTR(obj) ((RB_LDAP_DATA*)DATA_PTR(obj)) +#endif typedef struct rb_ldapentry_data { @@ -66,7 +70,23 @@ typedef struct rb_ldapmod_data LDAPMod *mod; } RB_LDAPMOD_DATA; -struct timeval rb_time_interval(VALUE num); +/* rb_time_interval is a private Ruby API; provide our own implementation */ +static inline struct timeval +rb_ldap_time_interval(VALUE num) { + struct timeval tv; + double d = NUM2DBL(num); + tv.tv_sec = (time_t)d; + tv.tv_usec = (long)((d - (double)tv.tv_sec) * 1e6); + return tv; +} + +#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000 +extern const rb_data_type_t rb_ldap_conn_data_type; +extern const rb_data_type_t rb_ldap_entry_data_type; +extern const rb_data_type_t rb_ldap_mod_data_type; +extern const rb_data_type_t rb_ldap_control_data_type; +extern const rb_data_type_t rb_ldap_control_nofree_data_type; +#endif #ifndef HAVE_LDAP_MEMFREE # define ldap_memfree(ptr) free(ptr) @@ -156,25 +176,35 @@ VALUE rb_ldap_mod_vals (VALUE); } \ } +#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000 +#define GET_LDAP_DATA(obj,ptr) {\ + TypedData_Get_Struct(obj, struct rb_ldap_data, &rb_ldap_conn_data_type, ptr); \ + if( ! ptr->ldap ){ \ + rb_raise(rb_eLDAP_InvalidDataError, "The LDAP handler has already unbound.");\ + } \ +} +#else #define GET_LDAP_DATA(obj,ptr) {\ Data_Get_Struct(obj, struct rb_ldap_data, ptr); \ if( ! ptr->ldap ){ \ rb_raise(rb_eLDAP_InvalidDataError, "The LDAP handler has already unbound.");\ } \ } +#endif +#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000 #define Check_LDAPENTRY(obj) {\ RB_LDAPENTRY_DATA *ptr; \ - Data_Get_Struct(obj, struct rb_ldapentry_data, ptr); \ + TypedData_Get_Struct(obj, struct rb_ldapentry_data, &rb_ldap_entry_data_type, ptr); \ if( ! ptr->msg ){ \ VALUE value = rb_inspect(obj); \ rb_raise(rb_eLDAP_InvalidEntryError, "%s is not a valid entry", \ StringValuePtr(value)); \ }; \ } - -#if defined(RB_LDAP_RVC) && RB_LDAP_RVC < 10900 -#define GET_LDAPENTRY_DATA(obj,ptr) { \ +#else +#define Check_LDAPENTRY(obj) {\ + RB_LDAPENTRY_DATA *ptr; \ Data_Get_Struct(obj, struct rb_ldapentry_data, ptr); \ if( ! ptr->msg ){ \ VALUE value = rb_inspect(obj); \ @@ -182,17 +212,40 @@ VALUE rb_ldap_mod_vals (VALUE); StringValuePtr(value)); \ }; \ } +#endif + +#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000 +#define GET_LDAPENTRY_DATA(obj,ptr) { \ + TypedData_Get_Struct(obj, struct rb_ldapentry_data, &rb_ldap_entry_data_type, ptr); \ +} +#elif defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 10900 +#define GET_LDAPENTRY_DATA(obj,ptr) { \ + Data_Get_Struct(obj, struct rb_ldapentry_data, ptr); \ +} #else #define GET_LDAPENTRY_DATA(obj,ptr) { \ Data_Get_Struct(obj, struct rb_ldapentry_data, ptr); \ + if( ! ptr->msg ){ \ + VALUE value = rb_inspect(obj); \ + rb_raise(rb_eLDAP_InvalidEntryError, "%s is not a valid entry", \ + StringValuePtr(value)); \ + }; \ } #endif +#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000 +#define GET_LDAPMOD_DATA(obj,ptr) {\ + TypedData_Get_Struct(obj, struct rb_ldapmod_data, &rb_ldap_mod_data_type, ptr); \ + if( ! ptr->mod ) \ + rb_raise(rb_eLDAP_InvalidDataError, "The Mod data is not ready for use."); \ +} +#else #define GET_LDAPMOD_DATA(obj,ptr) {\ Data_Get_Struct(obj, struct rb_ldapmod_data, ptr); \ if( ! ptr->mod ) \ rb_raise(rb_eLDAP_InvalidDataError, "The Mod data is not ready for use."); \ } +#endif #define rb_ldap_define_class(cname,parent) \ rb_define_class_under(rb_mLDAP,cname,parent) diff --git a/ruby-ldap.gemspec b/ruby-ldap.gemspec index b41fd70..0d2ec4e 100644 --- a/ruby-ldap.gemspec +++ b/ruby-ldap.gemspec @@ -10,11 +10,9 @@ It provides the interface to some LDAP libraries (e.g. OpenLDAP, Netscape SDK an EOF s.author = 'Alexey Chebotar' s.email = 'alexey.chebotar@gmail.com' - s.rubyforge_project = 'ruby-ldap' s.homepage = 'http://ruby-ldap.sourceforge.net/' + s.license = 'BSD-2-Clause' - s.has_rdoc = true - s.require_path = 'lib' s.files = [ 'ChangeLog', 'COPYING', 'FAQ', 'NOTES', 'README', 'TODO' ] diff --git a/saslconn.c b/saslconn.c index dbd796d..748a948 100644 --- a/saslconn.c +++ b/saslconn.c @@ -125,7 +125,11 @@ rb_ldap_conn_sasl_bind (int argc, VALUE argv[], VALUE self) unsigned sasl_flags = LDAP_SASL_AUTOMATIC; +#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000 + TypedData_Get_Struct (self, RB_LDAP_DATA, &rb_ldap_conn_data_type, ldapdata); +#else Data_Get_Struct (self, RB_LDAP_DATA, ldapdata); +#endif if (!ldapdata->ldap) { if (rb_iv_get (self, "@args") != Qnil) diff --git a/sslconn.c b/sslconn.c index 256352b..8b6b405 100644 --- a/sslconn.c +++ b/sslconn.c @@ -39,7 +39,11 @@ rb_openldap_sslconn_initialize (int argc, VALUE argv[], VALUE self) int start_tls; +#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000 + TypedData_Get_Struct (self, RB_LDAP_DATA, &rb_ldap_conn_data_type, ldapdata); +#else Data_Get_Struct (self, RB_LDAP_DATA, ldapdata); +#endif if (ldapdata->ldap) return Qnil; @@ -136,7 +140,11 @@ rb_nssldap_sslconn_initialize (int argc, VALUE argv[], VALUE self) VALUE arg1, arg2, arg3, arg4; +#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000 + TypedData_Get_Struct (self, RB_LDAP_DATA, &rb_ldap_conn_data_type, ldapdata); +#else Data_Get_Struct (self, RB_LDAP_DATA, ldapdata); +#endif if (ldapdata->ldap) return Qnil; @@ -206,7 +214,11 @@ rb_wldap32_sslconn_initialize (int argc, VALUE argv[], VALUE self) VALUE arg1, arg2, arg3; +#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000 + TypedData_Get_Struct (self, RB_LDAP_DATA, &rb_ldap_conn_data_type, ldapdata); +#else Data_Get_Struct (self, RB_LDAP_DATA, ldapdata); +#endif if (ldapdata->ldap) return Qnil; @@ -263,7 +275,11 @@ rb_ldap_sslconn_bind_f (int argc, VALUE argv[], VALUE self, { RB_LDAP_DATA *ldapdata; +#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000 + TypedData_Get_Struct (self, RB_LDAP_DATA, &rb_ldap_conn_data_type, ldapdata); +#else Data_Get_Struct (self, RB_LDAP_DATA, ldapdata); +#endif if (!ldapdata->ldap) { if (rb_iv_get (self, "@args") != Qnil)