--- libraries/libldap/result.c 1998/08/20 17:42:38 1.6 +++ libraries/libldap/result.c 1998/10/25 02:13:43 1.7 @@ -5,86 +5,41 @@ * result.c - wait for an ldap result */ +#include "portable.h" + #ifndef lint static char copyright[] = "@(#) Copyright (c) 1990 Regents of the University of Michigan.\nAll rights reserved.\n"; #endif #include -#include #include -#ifdef MACOS -#include -#include "macos.h" -#else /* MACOS */ -#if defined( DOS ) || defined( _WIN32 ) -#include -#include "msdos.h" -#ifdef PCNFS -#include -#include -#include -#endif /* PCNFS */ -#ifdef NCSA -#include "externs.h" -#endif /* NCSA */ -#else /* DOS */ -#include -#include -#include -#include -#ifdef _AIX -#include -#endif /* _AIX */ -#endif /* DOS */ -#endif /* MACOS */ -#ifdef VMS -#include "ucx_select.h" -#endif - -#include "portable.h" +#include +#include +#include +#include +#include #include "lber.h" #include "ldap.h" #include "ldap-int.h" -#ifdef USE_SYSCONF -#include -#endif /* USE_SYSCONF */ - -#ifdef NEEDPROTOS -static int ldap_abandoned( LDAP *ld, int msgid ); -static int ldap_mark_abandoned( LDAP *ld, int msgid ); -static int wait4msg( LDAP *ld, int msgid, int all, struct timeval *timeout, - LDAPMessage **result ); + +static int ldap_abandoned LDAP_P(( LDAP *ld, int msgid )); +static int ldap_mark_abandoned LDAP_P(( LDAP *ld, int msgid )); +static int wait4msg LDAP_P(( LDAP *ld, int msgid, int all, struct timeval *timeout, + LDAPMessage **result )); #ifdef LDAP_REFERRALS -static int read1msg( LDAP *ld, int msgid, int all, Sockbuf *sb, LDAPConn *lc, - LDAPMessage **result ); -static int build_result_ber( LDAP *ld, BerElement *ber, LDAPRequest *lr ); -static void merge_error_info( LDAP *ld, LDAPRequest *parentr, LDAPRequest *lr ); +static int read1msg LDAP_P(( LDAP *ld, int msgid, int all, Sockbuf *sb, LDAPConn *lc, + LDAPMessage **result )); +static int build_result_ber LDAP_P(( LDAP *ld, BerElement *ber, LDAPRequest *lr )); +static void merge_error_info LDAP_P(( LDAP *ld, LDAPRequest *parentr, LDAPRequest *lr )); #else /* LDAP_REFERRALS */ -static int read1msg( LDAP *ld, int msgid, int all, Sockbuf *sb, - LDAPMessage **result ); +static int read1msg LDAP_P(( LDAP *ld, int msgid, int all, Sockbuf *sb, + LDAPMessage **result )); #endif /* LDAP_REFERRALS */ -#if defined( CLDAP ) || !defined( LDAP_REFERRALS ) -static int ldap_select1( LDAP *ld, struct timeval *timeout ); -#endif -#else /* NEEDPROTOS */ -static int ldap_abandoned(); -static int ldap_mark_abandoned(); -static int wait4msg(); -static int read1msg(); -#ifdef LDAP_REFERRALS -static int build_result_ber(); -static void merge_error_info(); -#endif /* LDAP_REFERRALS */ -#if defined( CLDAP ) || !defined( LDAP_REFERRALS ) -static int ldap_select1(); -#endif -#endif /* NEEDPROTOS */ - -#if !defined( MACOS ) && !defined( DOS ) -extern int errno; +#if defined( LDAP_CONNECTIONLESS ) || !defined( LDAP_REFERRALS ) +static int ldap_select1 LDAP_P(( LDAP *ld, struct timeval *timeout )); #endif @@ -215,12 +170,8 @@ wait4msg( LDAP *ld, int msgid, int all, if ( ld->ld_sb.sb_ber.ber_ptr >= ld->ld_sb.sb_ber.ber_end ) { rc = ldap_select1( ld, tvp ); -#if !defined( MACOS ) && !defined( DOS ) if ( rc == 0 || ( rc == -1 && (( ld->ld_options & LDAP_OPT_RESTART ) == 0 || errno != EINTR ))) { -#else - if ( rc == -1 || rc == 0 ) { -#endif ld->ld_errno = (rc == -1 ? LDAP_SERVER_DOWN : LDAP_TIMEOUT); return( rc ); @@ -252,7 +203,7 @@ wait4msg( LDAP *ld, int msgid, int all, rc = do_ldap_select( ld, tvp ); -#if defined( LDAP_DEBUG ) && !defined( MACOS ) && !defined( DOS ) +#ifdef LDAP_DEBUG if ( rc == -1 ) { Debug( LDAP_DEBUG_TRACE, "do_ldap_select returned -1: errno %d\n", @@ -260,12 +211,8 @@ wait4msg( LDAP *ld, int msgid, int all, } #endif -#if !defined( MACOS ) && !defined( DOS ) if ( rc == 0 || ( rc == -1 && (( ld->ld_options & LDAP_OPT_RESTART ) == 0 || errno != EINTR ))) { -#else - if ( rc == -1 || rc == 0 ) { -#endif ld->ld_errno = (rc == -1 ? LDAP_SERVER_DOWN : LDAP_TIMEOUT); return( rc ); @@ -483,11 +430,11 @@ lr->lr_res_matched ? lr->lr_res_matched new->lm_msgtype = tag; new->lm_ber = ber_dup( &ber ); -#ifndef NO_CACHE +#ifndef LDAP_NOCACHE if ( ld->ld_cache != NULL ) { ldap_add_result_to_cache( ld, new ); } -#endif /* NO_CACHE */ +#endif /* LDAP_NOCACHE */ /* is this the one we're looking for? */ if ( msgid == LDAP_RES_ANY || id == msgid ) { @@ -633,8 +580,8 @@ merge_error_info( LDAP *ld, LDAPRequest -#if defined( CLDAP ) || !defined( LDAP_REFERRALS ) -#if !defined( MACOS ) && !defined( DOS ) && !defined( _WIN32 ) +#if defined( LDAP_CONNECTIONLESS ) || !defined( LDAP_REFERRALS ) + static int ldap_select1( LDAP *ld, struct timeval *timeout ) { @@ -642,11 +589,13 @@ ldap_select1( LDAP *ld, struct timeval * static int tblsize; if ( tblsize == 0 ) { -#ifdef USE_SYSCONF +#ifdef HAVE_SYSCONF tblsize = sysconf( _SC_OPEN_MAX ); -#else /* !USE_SYSCONF */ +#elif HAVE_GETDTABLESIZE tblsize = getdtablesize(); -#endif /* !USE_SYSCONF */ +#else + tblsize = FD_SETSIZE; +#endif #ifdef FD_SETSIZE if ( tblsize > FD_SETSIZE ) { tblsize = FD_SETSIZE; @@ -659,77 +608,7 @@ ldap_select1( LDAP *ld, struct timeval * return( select( tblsize, &readfds, 0, 0, timeout ) ); } -#endif /* !MACOS */ - - -#ifdef MACOS -static int -ldap_select1( LDAP *ld, struct timeval *timeout ) -{ - return( tcpselect( ld->ld_sb.sb_sd, timeout )); -} -#endif /* MACOS */ - - -#if ( defined( DOS ) && defined( WINSOCK )) || defined( _WIN32 ) -static int -ldap_select1( LDAP *ld, struct timeval *timeout ) -{ - fd_set readfds; - int rc; - - FD_ZERO( &readfds ); - FD_SET( ld->ld_sb.sb_sd, &readfds ); - - rc = select( 1, &readfds, 0, 0, timeout ); - return( rc == SOCKET_ERROR ? -1 : rc ); -} -#endif /* WINSOCK || _WIN32 */ - - -#ifdef DOS -#ifdef PCNFS -static int -ldap_select1( LDAP *ld, struct timeval *timeout ) -{ - fd_set readfds; - int res; - - FD_ZERO( &readfds ); - FD_SET( ld->ld_sb.sb_sd, &readfds ); - - res = select( FD_SETSIZE, &readfds, NULL, NULL, timeout ); - if ( res == -1 && errno == EINTR) { - /* We've been CTRL-C'ed at this point. It'd be nice to - carry on but PC-NFS currently won't let us! */ - printf("\n*** CTRL-C ***\n"); - exit(-1); - } - return( res ); -} -#endif /* PCNFS */ -#ifdef NCSA -static int -ldap_select1( LDAP *ld, struct timeval *timeout ) -{ - int rc; - clock_t endtime; - - if ( timeout != NULL ) { - endtime = timeout->tv_sec * CLK_TCK + - timeout->tv_usec * CLK_TCK / 1000000 + clock(); - } - - do { - Stask(); - rc = netqlen( ld->ld_sb.sb_sd ); - } while ( rc <= 0 && ( timeout == NULL || clock() < endtime )); - - return( rc > 0 ? 1 : 0 ); -} -#endif /* NCSA */ -#endif /* DOS */ #endif /* !LDAP_REFERRALS */ @@ -827,7 +706,7 @@ ldap_mark_abandoned( LDAP *ld, int msgid } -#ifdef CLDAP +#ifdef LDAP_CONNECTIONLESS int cldap_getmsg( LDAP *ld, struct timeval *timeout, BerElement *ber ) { @@ -853,4 +732,4 @@ cldap_getmsg( LDAP *ld, struct timeval * return( tag ); } -#endif /* CLDAP */ +#endif /* LDAP_CONNECTIONLESS */