Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "ruby.h"
- #include <ldap.h>
- static VALUE cRLdap;
- static char* string_to_char(VALUE string)
- {
- VALUE str;
- char* p;
- int i;
- char *charstr;
- str = StringValue(string);
- p = RSTRING_PTR(str);
- charstr = ALLOC_N(char, RSTRING_LEN(str)+1);
- for(i = 0; i < RSTRING_LEN(str); i++, p++, charstr++) {
- *charstr = *p;
- }
- return charstr;
- }
- static LDAP* l_get_ldap(VALUE klass)
- {
- LDAP* ldap;
- Data_Get_Struct(klass, LDAP, ldap);
- return ldap;
- }
- static void l_free(void *p)
- {
- ldap_memfree(p);
- }
- static VALUE l_alloc(VALUE klass)
- {
- LDAP* ldap;
- VALUE obj;
- ldap = ALLOC(LDAP);
- obj = Data_Wrap_Struct(klass, 0, l_free, ldap);
- return obj;
- }
- static VALUE l_ldap_initialize(VALUE self, VALUE uri)
- {
- LDAP* ldap;
- int rv;
- ldap = l_get_ldap(self);
- rv = ldap_initialize(*ldap, string_to_char(uri));
- return INT2FIX(rv);
- }
- void Init_RLdap() {
- cRLdap = rb_define_class("LDAP::C", rb_cObject);
- }
Add Comment
Please, Sign In to add comment