1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  *
3*0Sstevel@tonic-gate  * Copyright %G% Sun Microsystems, Inc.
4*0Sstevel@tonic-gate  * All Rights Reserved
5*0Sstevel@tonic-gate  *
6*0Sstevel@tonic-gate  *
7*0Sstevel@tonic-gate  * Comments:
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  */
10*0Sstevel@tonic-gate 
11*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
12*0Sstevel@tonic-gate 
13*0Sstevel@tonic-gate #include <stdio.h>
14*0Sstevel@tonic-gate #include <ctype.h>
15*0Sstevel@tonic-gate #include <string.h>
16*0Sstevel@tonic-gate #include "lber.h"
17*0Sstevel@tonic-gate #include "ldap.h"
18*0Sstevel@tonic-gate #include "ldap-private.h"
19*0Sstevel@tonic-gate #include "ldap-int.h"
20*0Sstevel@tonic-gate 
21*0Sstevel@tonic-gate LDAPMessage * ldap_first_reference(LDAP *ld, LDAPMessage *res)
22*0Sstevel@tonic-gate {
23*0Sstevel@tonic-gate 	LDAPMessage *msg = res;
24*0Sstevel@tonic-gate 
25*0Sstevel@tonic-gate 	while ( msg != NULLMSG) {
26*0Sstevel@tonic-gate 		if (msg->lm_msgtype == LDAP_RES_SEARCH_REFERENCE)
27*0Sstevel@tonic-gate 			break;
28*0Sstevel@tonic-gate 		msg = msg->lm_chain;
29*0Sstevel@tonic-gate 	}
30*0Sstevel@tonic-gate 	return (msg);
31*0Sstevel@tonic-gate }
32*0Sstevel@tonic-gate 
33*0Sstevel@tonic-gate LDAPMessage * ldap_next_reference(LDAP *ld, LDAPMessage *entry)
34*0Sstevel@tonic-gate {
35*0Sstevel@tonic-gate 	LDAPMessage *msg;
36*0Sstevel@tonic-gate 
37*0Sstevel@tonic-gate 	if ( entry == NULLMSG)
38*0Sstevel@tonic-gate 		return( NULLMSG );
39*0Sstevel@tonic-gate 
40*0Sstevel@tonic-gate 	msg = entry->lm_chain;
41*0Sstevel@tonic-gate 	while(msg != NULLMSG){
42*0Sstevel@tonic-gate 		if (msg->lm_msgtype == LDAP_RES_SEARCH_REFERENCE)
43*0Sstevel@tonic-gate 			break;
44*0Sstevel@tonic-gate 		msg = msg->lm_chain;
45*0Sstevel@tonic-gate 	}
46*0Sstevel@tonic-gate 
47*0Sstevel@tonic-gate 	return( msg );
48*0Sstevel@tonic-gate }
49*0Sstevel@tonic-gate 
50*0Sstevel@tonic-gate int
51*0Sstevel@tonic-gate ldap_count_references( LDAP *ld, LDAPMessage *res )
52*0Sstevel@tonic-gate {
53*0Sstevel@tonic-gate 	int	i;
54*0Sstevel@tonic-gate 
55*0Sstevel@tonic-gate 	for ( i = 0; res != NULL; res = res->lm_chain )
56*0Sstevel@tonic-gate 		if (res->lm_msgtype == LDAP_RES_SEARCH_REFERENCE)
57*0Sstevel@tonic-gate 			i++;
58*0Sstevel@tonic-gate 
59*0Sstevel@tonic-gate 	return( i );
60*0Sstevel@tonic-gate }
61*0Sstevel@tonic-gate 
62*0Sstevel@tonic-gate char ** ldap_get_reference_urls(LDAP *ld, LDAPMessage *res)
63*0Sstevel@tonic-gate {
64*0Sstevel@tonic-gate 	BerElement tmp;
65*0Sstevel@tonic-gate 	char **urls = NULL;
66*0Sstevel@tonic-gate 
67*0Sstevel@tonic-gate 	Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 1274, "ldap_get_reference_urls\n"), 0, 0, 0 );
68*0Sstevel@tonic-gate 
69*0Sstevel@tonic-gate 	if (res == NULL){
70*0Sstevel@tonic-gate 		ld->ld_errno = LDAP_PARAM_ERROR;
71*0Sstevel@tonic-gate 		return (NULL);
72*0Sstevel@tonic-gate 	}
73*0Sstevel@tonic-gate 	tmp = *res->lm_ber; /* struct copy */
74*0Sstevel@tonic-gate 	if ( ber_scanf( &tmp, "{v}", &urls) == LBER_ERROR){
75*0Sstevel@tonic-gate 		ld->ld_errno = LDAP_DECODING_ERROR;
76*0Sstevel@tonic-gate 		return (NULL);
77*0Sstevel@tonic-gate 	}
78*0Sstevel@tonic-gate 	return (urls);
79*0Sstevel@tonic-gate }
80