]> git.sur5r.net Git - openldap/blob - libraries/libldap/references.c
Initial versions of functions to step through messages and references.
[openldap] / libraries / libldap / references.c
1 /*
2  *  references.c
3  */
4
5 #include "portable.h"
6
7 #include <stdio.h>
8 #include <stdlib.h>
9
10 #include <ac/ctype.h>
11 #include <ac/socket.h>
12 #include <ac/string.h>
13 #include <ac/time.h>
14
15 #include "ldap-int.h"
16
17 /* ARGSUSED */
18 LDAPMessage *
19 ldap_first_reference( LDAP *ld, LDAPMessage *chain )
20 {
21         if ( ld == NULL || chain == NULLMSG ) {
22                 return NULLMSG;
23         }
24
25         return chain->lm_msgtype == LDAP_RES_SEARCH_REFERENCE
26                 ? chain
27                 : ldap_next_reference( ld, chain );
28 }
29
30 /* ARGSUSED */
31 LDAPMessage *
32 ldap_next_reference( LDAP *ld, LDAPMessage *ref )
33 {
34         if ( ld == NULL || ref == NULLMSG ) {
35                 return NULLMSG;
36         }
37
38         for ( ; ref != NULLMSG; ref = ref->lm_chain ) {
39                 if( ref->lm_msgtype == LDAP_RES_SEARCH_REFERENCE ) {
40                         return( ref );
41                 }
42         }
43
44         return( NULLMSG );
45 }
46
47 /* ARGSUSED */
48 int
49 ldap_count_references( LDAP *ld, LDAPMessage *chain )
50 {
51         int     i;
52
53         if ( ld == NULL ) {
54                 return -1;
55         }
56
57         for ( i = 0; chain != NULL; chain = chain->lm_chain ) {
58                 if( chain->lm_msgtype == LDAP_RES_SEARCH_REFERENCE ) {
59                         i++;
60                 }
61         }
62
63         return( i );
64 }