]> git.sur5r.net Git - openldap/blob - libraries/libldap/getentry.c
069b2dcbe97f2df759e56623dc3ed5ebb36e806b
[openldap] / libraries / libldap / getentry.c
1 /*
2  *  Copyright (c) 1990 Regents of the University of Michigan.
3  *  All rights reserved.
4  *
5  *  getentry.c
6  */
7
8 #include "portable.h"
9
10 #ifndef lint 
11 static char copyright[] = "@(#) Copyright (c) 1990 Regents of the University of Michigan.\nAll rights reserved.\n";
12 #endif
13
14 #include <stdio.h>
15 #include <stdlib.h>
16
17 #include <ac/ctype.h>
18 #include <ac/socket.h>
19 #include <ac/string.h>
20 #include <ac/time.h>
21
22 #include "ldap-int.h"
23
24 /* ARGSUSED */
25 LDAPMessage *
26 ldap_first_entry( LDAP *ld, LDAPMessage *chain )
27 {
28         if( ld == NULL || chain == NULLMSG ) {
29                 return NULLMSG;
30         }
31
32         return chain->lm_msgtype == LDAP_RES_SEARCH_ENTRY
33                 ? chain
34                 : ldap_next_entry( ld, chain );
35 }
36
37 /* ARGSUSED */
38 LDAPMessage *
39 ldap_next_entry( LDAP *ld, LDAPMessage *entry )
40 {
41         if ( ld == NULL || entry == NULLMSG ) {
42                 return NULLMSG;
43         }
44
45         for (
46                 entry = entry->lm_chain;
47                 entry != NULLMSG;
48                 entry = entry->lm_chain )
49         {
50                 if( entry->lm_msgtype == LDAP_RES_SEARCH_ENTRY ) {
51                         return( entry );
52                 }
53         }
54
55         return( NULLMSG );
56 }
57
58 /* ARGSUSED */
59 int
60 ldap_count_entries( LDAP *ld, LDAPMessage *chain )
61 {
62         int     i;
63
64         if ( ld == NULL ) {
65                 return -1;
66         }
67
68         for ( i = 0; chain != NULL; chain = chain->lm_chain ) {
69                 if( chain->lm_msgtype == LDAP_RES_SEARCH_ENTRY ) {
70                         i++;
71                 }
72         }
73
74         return( i );
75 }