xref: /onnv-gate/usr/src/lib/libldap4/common/getentry.c (revision 3857:21b9b714e4ab)
1 /*
2  * Portions Copyright 1998 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 #pragma ident	"%Z%%M%	%I%	%E% SMI"
7 
8 /*
9  *  Copyright (c) 1990 Regents of the University of Michigan.
10  *  All rights reserved.
11  *
12  *  getentry.c
13  */
14 
15 #ifndef lint
16 static char copyright[] = "@(#) Copyright (c) 1990 Regents of the University of Michigan.\nAll rights reserved.\n";
17 #endif
18 
19 #include <stdio.h>
20 #include <ctype.h>
21 #include <string.h>
22 #ifdef MACOS
23 #include <stdlib.h>
24 #include "macos.h"
25 #else /* MACOS */
26 #if defined( DOS ) || defined( _WIN32 )
27 #include <malloc.h>
28 #include "msdos.h"
29 #else /* DOS */
30 #include <sys/types.h>
31 #include <sys/socket.h>
32 #endif /* DOS */
33 #endif /* MACOS */
34 
35 #include "lber.h"
36 #include "ldap.h"
37 #include "ldap-private.h"
38 
39 /* ARGSUSED */
40 LDAPMessage *
ldap_first_entry(LDAP * ld,LDAPMessage * res)41 ldap_first_entry( LDAP *ld, LDAPMessage *res )
42 {
43 	LDAPMessage *msg = res;
44 
45 	while ( msg != NULLMSG) {
46 		if (msg->lm_msgtype == LDAP_RES_SEARCH_ENTRY)
47 			break;
48 		msg = msg->lm_chain;
49 	}
50 	return (msg);
51 }
52 
53 /* ARGSUSED */
ldap_next_entry(LDAP * ld,LDAPMessage * entry)54 LDAPMessage *ldap_next_entry( LDAP *ld, LDAPMessage *entry )
55 {
56 	LDAPMessage *msg;
57 
58 	if ( entry == NULLMSG)
59 		return( NULLMSG );
60 
61 	msg = entry->lm_chain;
62 	while(msg != NULLMSG){
63 		if (msg->lm_msgtype == LDAP_RES_SEARCH_ENTRY)
64 			break;
65 		msg = msg->lm_chain;
66 	}
67 
68 	return( msg );
69 }
70 
71 /* ARGSUSED */
72 int
ldap_count_entries(LDAP * ld,LDAPMessage * res)73 ldap_count_entries( LDAP *ld, LDAPMessage *res )
74 {
75 	int	i;
76 
77 	for ( i = 0; res != NULL; res = res->lm_chain )
78 		if (res->lm_msgtype == LDAP_RES_SEARCH_ENTRY)
79 			i++;
80 
81 	return( i );
82 }
83