#include "ldappr-int.h"
LDAP * LDAP_CALL
prldap_init( const char *defhost, int defport, int shared )
{
LDAP *ld;
if (( ld = ldap_init( defhost, defport )) != NULL ) {
if ( prldap_install_routines( ld, shared ) != LDAP_SUCCESS ) {
prldap_set_system_errno( EINVAL );
ldap_unbind( ld );
ld = NULL;
}
}
return( ld );
}
int LDAP_CALL
prldap_install_routines( LDAP *ld, int shared )
{
if ( prldap_install_io_functions( ld, shared ) != 0
|| prldap_install_thread_functions( ld, shared ) != 0
|| prldap_install_dns_functions( ld ) != 0 ) {
return( ldap_get_lderrno( ld, NULL, NULL ));
}
return( LDAP_SUCCESS );
}
int LDAP_CALL
prldap_set_session_option( LDAP *ld, void *sessionarg, int option, ... )
{
int rc = LDAP_SUCCESS;
PRLDAPIOSessionArg *prsessp = NULL;
va_list ap;
if ( NULL != ld ) {
if ( LDAP_SUCCESS !=
( rc = prldap_session_arg_from_ld( ld, &prsessp ))) {
return( rc );
}
} else if ( NULL != sessionarg ) {
prsessp = (PRLDAPIOSessionArg *)sessionarg;
}
va_start( ap, option );
switch ( option ) {
case PRLDAP_OPT_IO_MAX_TIMEOUT:
rc = prldap_set_io_max_timeout( prsessp, va_arg( ap, int ));
break;
default:
rc = LDAP_PARAM_ERROR;
}
va_end( ap );
return( rc );
}
int LDAP_CALL prldap_get_session_option( LDAP *ld, void *sessionarg,
int option, ... )
{
int rc = LDAP_SUCCESS;
PRLDAPIOSessionArg *prsessp = NULL;
va_list ap;
if ( NULL != ld ) {
if ( LDAP_SUCCESS !=
( rc = prldap_session_arg_from_ld( ld, &prsessp ))) {
return( rc );
}
} else if ( NULL != sessionarg ) {
prsessp = (PRLDAPIOSessionArg *)sessionarg;
}
va_start( ap, option );
switch ( option ) {
case PRLDAP_OPT_IO_MAX_TIMEOUT:
rc = prldap_get_io_max_timeout( prsessp, va_arg( ap, int * ));
break;
default:
rc = LDAP_PARAM_ERROR;
}
va_end( ap );
return( rc );
}
int LDAP_CALL
prldap_set_session_info( LDAP *ld, void *sessionarg, PRLDAPSessionInfo *seip )
{
int rc;
PRLDAPIOSessionArg *prsessp;
if ( seip == NULL || PRLDAP_SESSIONINFO_SIZE != seip->seinfo_size ) {
ldap_set_lderrno( ld, LDAP_PARAM_ERROR, NULL, NULL );
return( LDAP_PARAM_ERROR );
}
if ( NULL != ld ) {
if ( LDAP_SUCCESS !=
( rc = prldap_session_arg_from_ld( ld, &prsessp ))) {
return( rc );
}
} else if ( NULL != sessionarg ) {
prsessp = (PRLDAPIOSessionArg *)sessionarg;
} else {
ldap_set_lderrno( ld, LDAP_PARAM_ERROR, NULL, NULL );
return( LDAP_PARAM_ERROR );
}
prsessp->prsess_appdata = seip->seinfo_appdata;
return( LDAP_SUCCESS );
}
int LDAP_CALL
prldap_get_session_info( LDAP *ld, void *sessionarg, PRLDAPSessionInfo *seip )
{
int rc;
PRLDAPIOSessionArg *prsessp;
if ( seip == NULL || PRLDAP_SESSIONINFO_SIZE != seip->seinfo_size ) {
ldap_set_lderrno( ld, LDAP_PARAM_ERROR, NULL, NULL );
return( LDAP_PARAM_ERROR );
}
if ( NULL != ld ) {
if ( LDAP_SUCCESS !=
( rc = prldap_session_arg_from_ld( ld, &prsessp ))) {
return( rc );
}
} else if ( NULL != sessionarg ) {
prsessp = (PRLDAPIOSessionArg *)sessionarg;
} else {
ldap_set_lderrno( ld, LDAP_PARAM_ERROR, NULL, NULL );
return( LDAP_PARAM_ERROR );
}
seip->seinfo_appdata = prsessp->prsess_appdata;
return( LDAP_SUCCESS );
}
int LDAP_CALL
prldap_set_socket_info( int fd, void *socketarg, PRLDAPSocketInfo *soip )
{
PRLDAPIOSocketArg *prsockp;
if ( NULL == socketarg || NULL == soip ||
PRLDAP_SOCKETINFO_SIZE != soip->soinfo_size ) {
return( LDAP_PARAM_ERROR );
}
prsockp = (PRLDAPIOSocketArg *)socketarg;
prsockp->prsock_prfd = soip->soinfo_prfd;
prsockp->prsock_appdata = soip->soinfo_appdata;
return( LDAP_SUCCESS );
}
int LDAP_CALL
prldap_get_socket_info( int fd, void *socketarg, PRLDAPSocketInfo *soip )
{
PRLDAPIOSocketArg *prsockp;
if ( NULL == socketarg || NULL == soip ||
PRLDAP_SOCKETINFO_SIZE != soip->soinfo_size ) {
return( LDAP_PARAM_ERROR );
}
prsockp = (PRLDAPIOSocketArg *)socketarg;
soip->soinfo_prfd = prsockp->prsock_prfd;
soip->soinfo_appdata = prsockp->prsock_appdata;
return( LDAP_SUCCESS );
}
int LDAP_CALL
prldap_get_default_socket_info( LDAP *ld, PRLDAPSocketInfo *soip )
{
int rc;
PRLDAPIOSocketArg *prsockp;
if ( NULL == soip || PRLDAP_SOCKETINFO_SIZE != soip->soinfo_size ) {
ldap_set_lderrno( ld, LDAP_PARAM_ERROR, NULL, NULL );
return( LDAP_PARAM_ERROR );
}
if ( NULL != ld ) {
if ( LDAP_SUCCESS !=
( rc = prldap_socket_arg_from_ld( ld, &prsockp ))) {
return( rc );
}
} else {
ldap_set_lderrno( ld, LDAP_PARAM_ERROR, NULL, NULL );
return( LDAP_PARAM_ERROR );
}
soip->soinfo_prfd = prsockp->prsock_prfd;
soip->soinfo_appdata = prsockp->prsock_appdata;
return( LDAP_SUCCESS );
}
int LDAP_CALL
prldap_set_default_socket_info( LDAP *ld, PRLDAPSocketInfo *soip )
{
int rc;
PRLDAPIOSocketArg *prsockp;
if ( NULL == soip || PRLDAP_SOCKETINFO_SIZE != soip->soinfo_size ) {
ldap_set_lderrno( ld, LDAP_PARAM_ERROR, NULL, NULL );
return( LDAP_PARAM_ERROR );
}
if ( NULL != ld ) {
if ( LDAP_SUCCESS !=
( rc = prldap_socket_arg_from_ld( ld, &prsockp ))) {
return( rc );
}
} else {
ldap_set_lderrno( ld, LDAP_PARAM_ERROR, NULL, NULL );
return( LDAP_PARAM_ERROR );
}
prsockp->prsock_prfd = soip->soinfo_prfd;
prsockp->prsock_appdata = soip->soinfo_appdata;
return( LDAP_SUCCESS );
}