scsh-ldap/c/ldap.c

127 lines
3.2 KiB
C
Raw Permalink Normal View History

2003-10-28 10:27:54 -05:00
#include "scsh-ldap.h"
s48_value scsh_enter_ldap(LDAP *ldap)
{
s48_value rec = S48_FALSE;
S48_DECLARE_GC_PROTECT(1);
S48_GC_PROTECT_1(rec);
rec = s48_make_record(scsh_ldap_record_type);
S48_RECORD_SET(rec, 0, s48_enter_integer((long) ldap));
S48_GC_UNPROTECT();
return rec;
}
s48_value scsh_enter_ldapmessage(LDAPMessage *lm)
{
s48_value rec = S48_FALSE;
S48_DECLARE_GC_PROTECT(1);
S48_GC_PROTECT_1(rec);
rec = s48_make_record(scsh_ldapmessage_record_type);
S48_RECORD_SET(rec, 0, s48_enter_integer((long) lm));
S48_GC_UNPROTECT();
return rec;
}
s48_value scsh_ldap_open(s48_value host, s48_value port)
{
LDAP *ldap;
S48_DECLARE_GC_PROTECT(2);
S48_GC_PROTECT_2(host, port);
ldap = ldap_open(s48_extract_string(host), s48_extract_integer(port));
S48_GC_UNPROTECT();
return ldap == NULL ? S48_FALSE : scsh_enter_ldap(ldap);
}
s48_value scsh_ldap_init(s48_value host, s48_value port)
{
LDAP *ldap;
S48_DECLARE_GC_PROTECT(2);
S48_GC_PROTECT_2(host, port);
ldap = ldap_init(s48_extract_string(host), s48_extract_integer(port));
S48_GC_UNPROTECT();
return ldap == NULL ? S48_FALSE : scsh_enter_ldap(ldap);
}
s48_value scsh_ldap_bind_s(s48_value ldap, s48_value user,
s48_value cred, s48_value method)
{
int r;
S48_DECLARE_GC_PROTECT(4);
S48_GC_PROTECT_4(ldap, user, cred, method);
r = ldap_bind_s(scsh_extract_ldap(ldap), s48_extract_string(user),
s48_extract_string(cred), s48_extract_integer(method));
S48_GC_UNPROTECT();
return s48_enter_integer(r);
}
s48_value scsh_ldap_simple_bind_s(s48_value ldap, s48_value user, s48_value cred)
{
int r;
S48_DECLARE_GC_PROTECT(3);
S48_GC_PROTECT_3(ldap, user, cred);
r = ldap_simple_bind_s(scsh_extract_ldap(ldap), s48_extract_string(user),
s48_extract_string(cred));
S48_GC_UNPROTECT();
return r;
}
s48_value scsh_ldap_unbind_s(s48_value ldap)
{
return s48_enter_integer(ldap_unbind_s(scsh_extract_ldap(ldap)));
}
s48_value scsh_ldap_error_string(s48_value errcode)
{
return s48_enter_string(ldap_err2string(s48_extract_integer(errcode)));
}
s48_value scsh_ldap_result_error(s48_value ldap, s48_value res)
{
int r;
S48_DECLARE_GC_PROTECT(2);
S48_GC_PROTECT_2(ldap, res);
r = s48_enter_integer(ldap_result2error(scsh_extract_ldap(ldap),
scsh_extract_ldapmessage(res), 0));
S48_GC_UNPROTECT();
return s48_enter_integer(r);
}
s48_value scsh_ldap_memfree(s48_value ldap)
{
ldap_memfree(scsh_extract_ldap(ldap));
return S48_UNSPECIFIC;
}
s48_value scsh_ldap_msgfree(s48_value ldapmsg)
{
ldap_msgfree(scsh_extract_ldapmessage(ldapmsg));
return S48_UNSPECIFIC;
}
void scsh_ldap_main(void)
{
S48_GC_PROTECT_GLOBAL(scsh_ldap_record_type);
scsh_ldap_record_type = s48_get_imported_binding("ldap");
S48_GC_PROTECT_GLOBAL(scsh_ldapmessage_record_type);
scsh_ldapmessage_record_type = s48_get_imported_binding("ldap-message");
S48_EXPORT_FUNCTION(scsh_ldap_open);
S48_EXPORT_FUNCTION(scsh_ldap_init);
S48_EXPORT_FUNCTION(scsh_ldap_bind_s);
S48_EXPORT_FUNCTION(scsh_ldap_simple_bind_s);
S48_EXPORT_FUNCTION(scsh_ldap_unbind_s);
S48_EXPORT_FUNCTION(scsh_ldap_error_string);
S48_EXPORT_FUNCTION(scsh_ldap_result_error);
S48_EXPORT_FUNCTION(scsh_ldap_memfree);
S48_EXPORT_FUNCTION(scsh_ldap_msgfree);
}