rldap 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/ext/constants.h +2 -1
  2. data/ext/ldap.c +45 -39
  3. data/lib/ldap/version.rb +1 -1
  4. metadata +3 -3
data/ext/constants.h CHANGED
@@ -1,3 +1,5 @@
1
+ #include <ldap.h>
2
+
1
3
  #define DEFINE_CONST(s) rb_define_const(cLDAP, #s, INT2NUM(s))
2
4
 
3
5
  /* options */
@@ -5,7 +7,6 @@ DEFINE_CONST(LDAP_OPT_API_FEATURE_INFO);
5
7
  DEFINE_CONST(LDAP_OPT_API_INFO);
6
8
  DEFINE_CONST(LDAP_OPT_CLIENT_CONTROLS);
7
9
  DEFINE_CONST(LDAP_OPT_CONNECT_ASYNC);
8
- DEFINE_CONST(LDAP_OPT_CONNECT_CB);
9
10
  DEFINE_CONST(LDAP_OPT_DEBUG_LEVEL);
10
11
  DEFINE_CONST(LDAP_OPT_DEFBASE);
11
12
  DEFINE_CONST(LDAP_OPT_DEREF);
data/ext/ldap.c CHANGED
@@ -15,37 +15,37 @@ static VALUE cLDAP_Message;
15
15
  static VALUE eLDAP;
16
16
 
17
17
  typedef struct {
18
- LDAP* ld;
18
+ LDAP *ld;
19
19
  char connection;
20
20
  } RLDAP_WRAP;
21
21
 
22
22
  typedef struct {
23
- LDAP* ld;
24
- LDAPMessage* mesg;
23
+ LDAP *ld;
24
+ LDAPMessage *mesg;
25
25
  char freed;
26
26
  } RLDAP_MSG_WRAP;
27
27
 
28
- static RLDAP_WRAP* get_wrapper(VALUE obj)
28
+ static RLDAP_WRAP *get_wrapper(VALUE obj)
29
29
  {
30
- RLDAP_WRAP* wrapper;
30
+ RLDAP_WRAP *wrapper;
31
31
  Data_Get_Struct(obj, RLDAP_WRAP, wrapper);
32
32
  return wrapper;
33
33
  }
34
34
 
35
- static RLDAP_MSG_WRAP* get_msg_wrapper(VALUE obj)
35
+ static RLDAP_MSG_WRAP *get_msg_wrapper(VALUE obj)
36
36
  {
37
37
  RLDAP_MSG_WRAP* wrapper;
38
38
  Data_Get_Struct(obj, RLDAP_MSG_WRAP, wrapper);
39
39
  return wrapper;
40
40
  }
41
41
 
42
- static void free_wrapper(RLDAP_WRAP* wrapper)
42
+ static void free_wrapper(RLDAP_WRAP *wrapper)
43
43
  {
44
44
  ldap_memfree(wrapper->ld);
45
45
  xfree(wrapper);
46
46
  }
47
47
 
48
- static void free_msg_wrapper(RLDAP_MSG_WRAP* wrapper)
48
+ static void free_msg_wrapper(RLDAP_MSG_WRAP *wrapper)
49
49
  {
50
50
  if (wrapper->freed == Qfalse)
51
51
  ldap_msgfree(wrapper->mesg);
@@ -59,7 +59,7 @@ static void rldap_raise(int errno)
59
59
  rb_exc_raise(e);
60
60
  }
61
61
 
62
- static VALUE ldapmessage2obj(LDAP* ld, LDAPMessage* msg);
62
+ static VALUE ldapmessage2obj(LDAP *ld, LDAPMessage *msg);
63
63
 
64
64
  /* class LDAP */
65
65
 
@@ -72,7 +72,7 @@ static VALUE rldap_err2string(VALUE klass, VALUE rerrno)
72
72
 
73
73
  static VALUE rldap_alloc(VALUE klass)
74
74
  {
75
- RLDAP_WRAP* wrapper;
75
+ RLDAP_WRAP *wrapper;
76
76
  VALUE obj;
77
77
 
78
78
  obj = Data_Make_Struct(klass, RLDAP_WRAP, 0, free_wrapper, wrapper);
@@ -81,12 +81,12 @@ static VALUE rldap_alloc(VALUE klass)
81
81
  return obj;
82
82
  }
83
83
 
84
- static VALUE rldap_initialize(int argc, VALUE* argv, VALUE obj)
84
+ static VALUE rldap_initialize(int argc, VALUE *argv, VALUE obj)
85
85
  {
86
86
  VALUE rhost, rport;
87
- char* host;
87
+ char *host;
88
88
  int port;
89
- RLDAP_WRAP* wrapper;
89
+ RLDAP_WRAP *wrapper;
90
90
 
91
91
  rb_scan_args(argc, argv, "11", &rhost, &rport);
92
92
 
@@ -97,14 +97,14 @@ static VALUE rldap_initialize(int argc, VALUE* argv, VALUE obj)
97
97
  host = StringValuePtr(rhost);
98
98
  port = FIX2INT(rport);
99
99
 
100
- wrapper->ld = ldap_open(host, port);
100
+ wrapper->ld = (LDAP *)ldap_init(host, port);
101
101
 
102
102
  return obj;
103
103
  }
104
104
 
105
105
  static VALUE rldap_start_tls(VALUE obj)
106
106
  {
107
- RLDAP_WRAP* wrapper;
107
+ RLDAP_WRAP *wrapper;
108
108
  int retval;
109
109
 
110
110
  wrapper = get_wrapper(obj);
@@ -117,12 +117,10 @@ static VALUE rldap_start_tls(VALUE obj)
117
117
 
118
118
  static VALUE rldap_search(VALUE obj, VALUE rbase, VALUE rfilter)
119
119
  {
120
- RLDAP_WRAP* wrapper;
121
- char* base;
122
- char* filter;
120
+ RLDAP_WRAP *wrapper;
121
+ char *base, *filter;
123
122
  int retval, count, i;
124
- LDAPMessage* res;
125
- LDAPMessage* msg;
123
+ LDAPMessage *res, *msg;
126
124
  VALUE ary;
127
125
 
128
126
  wrapper = get_wrapper(obj);
@@ -156,12 +154,12 @@ static VALUE rldap_search(VALUE obj, VALUE rbase, VALUE rfilter)
156
154
 
157
155
  static VALUE rldap_set_option(VALUE obj, VALUE roption, VALUE rvalue)
158
156
  {
159
- RLDAP_WRAP* wrapper;
157
+ RLDAP_WRAP *wrapper;
160
158
  int retval;
161
159
  int option;
162
160
  int ival;
163
- char* sval;
164
- void* val;
161
+ char *sval;
162
+ void *val;
165
163
 
166
164
  wrapper = get_wrapper(obj);
167
165
  option = FIX2INT(roption);
@@ -184,7 +182,7 @@ static VALUE rldap_set_option(VALUE obj, VALUE roption, VALUE rvalue)
184
182
 
185
183
  static VALUE rldap_errno(VALUE obj)
186
184
  {
187
- RLDAP_WRAP* wrapper;
185
+ RLDAP_WRAP *wrapper;
188
186
  int errno;
189
187
 
190
188
  wrapper = get_wrapper(obj);
@@ -196,7 +194,7 @@ static VALUE rldap_errno(VALUE obj)
196
194
 
197
195
  int rldap_errno_c(VALUE obj)
198
196
  {
199
- RLDAP_WRAP* wrapper;
197
+ RLDAP_WRAP *wrapper;
200
198
  int errno;
201
199
 
202
200
  wrapper = get_wrapper(obj);
@@ -210,7 +208,7 @@ int rldap_errno_c(VALUE obj)
210
208
  static VALUE ldapmessage2obj(LDAP* ld, LDAPMessage* msg)
211
209
  {
212
210
  VALUE obj;
213
- RLDAP_MSG_WRAP* wrapper;
211
+ RLDAP_MSG_WRAP *wrapper;
214
212
 
215
213
  obj = Data_Make_Struct(cLDAP_Message, RLDAP_MSG_WRAP, 0, free_msg_wrapper, wrapper);
216
214
  wrapper->mesg = msg;
@@ -222,26 +220,27 @@ static VALUE ldapmessage2obj(LDAP* ld, LDAPMessage* msg)
222
220
 
223
221
  static VALUE rldap_msg_dn(VALUE obj)
224
222
  {
225
- RLDAP_MSG_WRAP* wrapper;
226
- char* dn;
223
+ RLDAP_MSG_WRAP *wrapper;
224
+ char *dn;
225
+ VALUE rdn;
227
226
 
228
227
  wrapper = get_msg_wrapper(obj);
229
228
 
230
229
  dn = ldap_get_dn(wrapper->ld, wrapper->mesg);
230
+ rdn = rb_str_new2(dn);
231
+ ldap_memfree(dn);
231
232
 
232
- return rb_str_new2(dn);
233
+ return rdn;
233
234
  }
234
235
 
235
236
  static VALUE rldap_msg_get_val(VALUE obj, VALUE key)
236
237
  {
237
- RLDAP_MSG_WRAP* wrapper;
238
- char* attr;
239
- BerValue** values;
240
- VALUE ary;
238
+ RLDAP_MSG_WRAP *wrapper;
239
+ char *attr, *strval;
240
+ BerValue **values;
241
+ VALUE ary, str;
241
242
  int i, length;
242
- BerValue* value;
243
- char* strval;
244
- VALUE str;
243
+ BerValue *value;
245
244
 
246
245
  wrapper = get_msg_wrapper(obj);
247
246
  attr = StringValuePtr(key);
@@ -268,11 +267,16 @@ static VALUE rldap_msg_get_val(VALUE obj, VALUE key)
268
267
 
269
268
  static VALUE rldap_msg_keys(VALUE obj)
270
269
  {
271
- RLDAP_MSG_WRAP* wrapper;
272
- char* attr;
273
- BerElement* ber;
270
+ RLDAP_MSG_WRAP *wrapper;
271
+ char *attr;
272
+ BerElement *ber;
274
273
  VALUE ary;
275
274
 
275
+ ary = rb_iv_get(obj, "@keys");
276
+
277
+ if (ary != Qnil)
278
+ return ary;
279
+
276
280
  wrapper = get_msg_wrapper(obj);
277
281
  ary = rb_ary_new();
278
282
 
@@ -284,6 +288,8 @@ static VALUE rldap_msg_keys(VALUE obj)
284
288
 
285
289
  ber_free(ber, 0);
286
290
 
291
+ rb_iv_set(obj, "@keys", ary);
292
+
287
293
  return ary;
288
294
  }
289
295
 
data/lib/ldap/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class LDAP
2
- Version = VERSION = '0.0.1'
2
+ Version = VERSION = '0.0.2'
3
3
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Henrik Hodne
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-07-05 00:00:00 +00:00
17
+ date: 2010-09-25 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies: []
20
20