From a4822cf3284027995cd114793a4e32e0b1adb69b Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Thu, 24 Dec 1998 04:45:54 +0000 Subject: [PATCH] Initial versions of functions to step through messages and references. Fixed entry step through functions to check specifically fore entries. --- libraries/libldap/Makefile.in | 6 ++-- libraries/libldap/getentry.c | 38 ++++++++++++++------ libraries/libldap/messages.c | 51 +++++++++++++++++++++++++++ libraries/libldap/references.c | 64 ++++++++++++++++++++++++++++++++++ 4 files changed, 147 insertions(+), 12 deletions(-) create mode 100644 libraries/libldap/messages.c create mode 100644 libraries/libldap/references.c diff --git a/libraries/libldap/Makefile.in b/libraries/libldap/Makefile.in index cb14f22a0c..0e57ee5d95 100644 --- a/libraries/libldap/Makefile.in +++ b/libraries/libldap/Makefile.in @@ -6,14 +6,16 @@ XLIBRARY = ../libldap.a PROGRAMS = apitest ltest ttest -SRCS = bind.c controls.c open.c result.c error.c compare.c search.c \ +SRCS = bind.c open.c result.c error.c compare.c search.c \ + controls.c messages.c references.c \ modify.c add.c modrdn.c delete.c abandon.c ufn.c cache.c \ getfilter.c sbind.c kbind.c unbind.c friendly.c cldap.c \ free.c disptmpl.c srchpref.c dsparse.c tmplout.c sort.c \ getdn.c getentry.c getattr.c getvalues.c addentry.c \ request.c getdxbyname.c os-ip.c url.c charset.c \ init.c options.c strdup.c util-int.c -OBJS = bind.lo controls.lo open.lo result.lo error.lo compare.lo search.lo \ +OBJS = bind.lo open.lo result.lo error.lo compare.lo search.lo \ + controls.lo messages.lo references.lo \ modify.lo add.lo modrdn.lo delete.lo abandon.lo ufn.lo cache.lo \ getfilter.lo sbind.lo kbind.lo unbind.lo friendly.lo cldap.lo \ free.lo disptmpl.lo srchpref.lo dsparse.lo tmplout.lo sort.lo \ diff --git a/libraries/libldap/getentry.c b/libraries/libldap/getentry.c index 01d8f2c125..f3c0b8fa5e 100644 --- a/libraries/libldap/getentry.c +++ b/libraries/libldap/getentry.c @@ -25,18 +25,30 @@ static char copyright[] = "@(#) Copyright (c) 1990 Regents of the University of LDAPMessage * ldap_first_entry( LDAP *ld, LDAPMessage *chain ) { - return( chain == NULLMSG || chain->lm_msgtype == LDAP_RES_SEARCH_RESULT - ? NULLMSG : chain ); + if( ld == NULL || chain == NULLMSG ) { + return NULLMSG; + } + + return chain->lm_msgtype == LDAP_RES_SEARCH_ENTRY + ? chain + : ldap_next_entry( ld, chain ); } /* ARGSUSED */ -LDAPMessage *ldap_next_entry( LDAP *ld, LDAPMessage *entry ) +LDAPMessage * +ldap_next_entry( LDAP *ld, LDAPMessage *entry ) { - if ( entry == NULLMSG || entry->lm_chain == NULLMSG - || entry->lm_chain->lm_msgtype == LDAP_RES_SEARCH_RESULT ) - return( NULLMSG ); + if ( ld == NULL || entry == NULLMSG ) { + return NULLMSG; + } - return( entry->lm_chain ); + for ( ; entry != NULLMSG; entry = entry->lm_chain ) { + if( entry->lm_msgtype == LDAP_RES_SEARCH_ENTRY ) { + return( entry ); + } + } + + return( NULLMSG ); } /* ARGSUSED */ @@ -45,9 +57,15 @@ ldap_count_entries( LDAP *ld, LDAPMessage *chain ) { int i; - for ( i = 0; chain != NULL && chain->lm_msgtype - != LDAP_RES_SEARCH_RESULT; chain = chain->lm_chain ) - i++; + if ( ld == NULL ) { + return -1; + } + + for ( i = 0; chain != NULL; chain = chain->lm_chain ) { + if( chain->lm_msgtype == LDAP_RES_SEARCH_ENTRY ) { + i++; + } + } return( i ); } diff --git a/libraries/libldap/messages.c b/libraries/libldap/messages.c new file mode 100644 index 0000000000..87aebdca9d --- /dev/null +++ b/libraries/libldap/messages.c @@ -0,0 +1,51 @@ +/* + * messages.c + */ + +#include "portable.h" + +#include +#include + +#include +#include +#include +#include + +#include "ldap-int.h" + +/* ARGSUSED */ +LDAPMessage * +ldap_first_message( LDAP *ld, LDAPMessage *chain ) +{ + return( ld == NULL || chain == NULLMSG + ? NULLMSG : chain ); +} + +/* ARGSUSED */ +LDAPMessage * +ldap_next_message( LDAP *ld, LDAPMessage *msg ) +{ + if ( ld == NULL || msg == NULLMSG || msg->lm_chain == NULL ) { + return NULLMSG; + } + + return( msg->lm_chain ); +} + +/* ARGSUSED */ +int +ldap_count_messages( LDAP *ld, LDAPMessage *chain ) +{ + int i; + + if ( ld == NULL ) { + return -1; + } + + for ( i = 0; chain != NULL; chain = chain->lm_chain ) { + i++; + } + + return( i ); +} diff --git a/libraries/libldap/references.c b/libraries/libldap/references.c new file mode 100644 index 0000000000..569e209518 --- /dev/null +++ b/libraries/libldap/references.c @@ -0,0 +1,64 @@ +/* + * references.c + */ + +#include "portable.h" + +#include +#include + +#include +#include +#include +#include + +#include "ldap-int.h" + +/* ARGSUSED */ +LDAPMessage * +ldap_first_reference( LDAP *ld, LDAPMessage *chain ) +{ + if ( ld == NULL || chain == NULLMSG ) { + return NULLMSG; + } + + return chain->lm_msgtype == LDAP_RES_SEARCH_REFERENCE + ? chain + : ldap_next_reference( ld, chain ); +} + +/* ARGSUSED */ +LDAPMessage * +ldap_next_reference( LDAP *ld, LDAPMessage *ref ) +{ + if ( ld == NULL || ref == NULLMSG ) { + return NULLMSG; + } + + for ( ; ref != NULLMSG; ref = ref->lm_chain ) { + if( ref->lm_msgtype == LDAP_RES_SEARCH_REFERENCE ) { + return( ref ); + } + } + + return( NULLMSG ); +} + +/* ARGSUSED */ +int +ldap_count_references( LDAP *ld, LDAPMessage *chain ) +{ + int i; + + if ( ld == NULL ) { + return -1; + } + + for ( i = 0; chain != NULL; chain = chain->lm_chain ) { + if( chain->lm_msgtype == LDAP_RES_SEARCH_REFERENCE ) { + i++; + } + } + + return( i ); +} -- 2.39.5