Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Apr 16th, 2018 47 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. #include "ruby.h"
  2. #include <ldap.h>
  3.  
  4. typedef struct _cldpwrap {
  5.   LDAP* ldap;
  6. } CLdapWrapper;
  7.  
  8. static VALUE cLdap;
  9.  
  10. static void cldap_free(CLdapWrapper* p) {
  11.   ldap_memfree(p->ldap);
  12.   free(p);
  13. }
  14.  
  15. LDAP* extract_ldap(VALUE self)
  16. {
  17.   CLdapWrapper* ldp;
  18.   Data_Get_Struct(self, CLdapWrapper, ldp);
  19.   return ldp->ldap;
  20. }
  21.  
  22. static VALUE cldap_alloc(VALUE klass) {
  23.   CLdapWrapper* ldp;
  24.   VALUE obj;
  25.   ldp = malloc(sizeof(ldp));
  26.   obj = Data_Wrap_Struct(klass, 0, cldap_free, ldp);
  27.   return obj;
  28. }
  29.  
  30. static VALUE cldap_initialize(int argc, VALUE* argv, VALUE self)
  31. {
  32.   VALUE hostname, port;
  33.   CLdapWrapper* ldpw;
  34.   LDAP* ldp;
  35.  
  36.   rb_scan_args(argc, argv, "11", &hostname, &port);
  37.  
  38.   if (RTEST(port) == 0) port = INT2FIX(389);
  39.  
  40.   rb_iv_set(self, "@host", hostname);
  41.   rb_iv_set(self, "@port", port);
  42.  
  43.   Data_Get_Struct(self, CLdapWrapper, ldpw);
  44.  
  45.   ldp = ldap_init(StringValueCStr(hostname), FIX2INT(port));
  46.   ldpw->ldap = ldp;
  47.  
  48.   return self;
  49. }
  50.  
  51. void Init_cldap()
  52. {
  53.   cLdap = rb_define_class("Ldap", rb_cObject);
  54.   rb_define_alloc_func(cLdap, cldap_alloc);
  55.   rb_define_method(cLdap, "initialize", cldap_initialize, -1);
  56. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top