2 * Copyright (c) 2001 by Sun Microsystems, Inc.
6 #pragma ident "%Z%%M% %I% %E% SMI"
9 * The contents of this file are subject to the Netscape Public
10 * License Version 1.1 (the "License"); you may not use this file
11 * except in compliance with the License. You may obtain a copy of
12 * the License at http://www.mozilla.org/NPL/
14 * Software distributed under the License is distributed on an "AS
15 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
16 * implied. See the License for the specific language governing
17 * rights and limitations under the License.
19 * The Original Code is Mozilla Communicator client code, released
22 * The Initial Developer of the Original Code is Netscape
23 * Communications Corporation. Portions created by Netscape are
24 * Copyright (C) 1998-1999 Netscape Communications Corporation. All
30 * referral.c - routines for handling LDAPv3 referrals and references.
38 ldap_first_reference( LDAP
*ld
, LDAPMessage
*res
)
40 if ( !NSLDAPI_VALID_LDAP_POINTER( ld
) || res
== NULLMSG
) {
44 if ( res
->lm_msgtype
== LDAP_RES_SEARCH_REFERENCE
) {
48 return( ldap_next_reference( ld
, res
));
54 ldap_next_reference( LDAP
*ld
, LDAPMessage
*ref
)
56 if ( !NSLDAPI_VALID_LDAP_POINTER( ld
) || ref
== NULLMSG
) {
57 return( NULLMSG
); /* punt */
60 for ( ref
= ref
->lm_chain
; ref
!= NULLMSG
; ref
= ref
->lm_chain
) {
61 if ( ref
->lm_msgtype
== LDAP_RES_SEARCH_REFERENCE
) {
72 ldap_count_references( LDAP
*ld
, LDAPMessage
*res
)
76 if ( !NSLDAPI_VALID_LDAP_POINTER( ld
)) {
80 for ( i
= 0; res
!= NULL
; res
= res
->lm_chain
) {
81 if ( res
->lm_msgtype
== LDAP_RES_SEARCH_REFERENCE
) {
91 * returns an LDAP error code.
95 ldap_parse_reference( LDAP
*ld
, LDAPMessage
*ref
, char ***referralsp
,
96 LDAPControl
***serverctrlsp
, int freeit
)
100 if ( !NSLDAPI_VALID_LDAP_POINTER( ld
) ||
101 !NSLDAPI_VALID_LDAPMESSAGE_REFERENCE_POINTER( ref
)) {
102 return( LDAP_PARAM_ERROR
);
105 err
= nsldapi_parse_reference( ld
, ref
->lm_ber
, referralsp
,
108 LDAP_SET_LDERRNO( ld
, err
, NULL
, NULL
);
119 * returns an LDAP error code indicating success or failure of parsing
120 * does NOT set any error information inside "ld"
123 nsldapi_parse_reference( LDAP
*ld
, BerElement
*rber
, char ***referralsp
,
124 LDAPControl
***serverctrlsp
)
131 * Parse a searchResultReference message. These are used in LDAPv3
132 * and beyond and look like this:
134 * SearchResultReference ::= [APPLICATION 19] SEQUENCE OF LDAPURL
136 * all wrapped up in an LDAPMessage sequence which looks like this:
138 * LDAPMessage ::= SEQUENCE {
139 * messageID MessageID,
140 * SearchResultReference
141 * controls [0] Controls OPTIONAL
144 * ldap_result() pulls out the message id, so by the time a result
145 * message gets here we are conveniently sitting at the start of the
146 * SearchResultReference itself.
148 err
= LDAP_SUCCESS
; /* optimistic */
149 ber
= *rber
; /* struct copy */
151 if ( ber_scanf( &ber
, "{v", &refs
) == LBER_ERROR
) {
152 err
= LDAP_DECODING_ERROR
;
153 } else if ( serverctrlsp
!= NULL
) {
154 /* pull out controls (if requested and any are present) */
155 if ( ber_scanf( &ber
, "}" ) == LBER_ERROR
) {
156 err
= LDAP_DECODING_ERROR
;
158 err
= nsldapi_get_controls( &ber
, serverctrlsp
);
162 if ( referralsp
== NULL
) {
163 ldap_value_free( refs
);
173 char ** ldap_get_reference_urls(LDAP
*ld
, LDAPMessage
*res
)
178 LDAPDebug( LDAP_DEBUG_TRACE
, "ldap_get_reference_urls\n", 0, 0, 0 );
181 ld
->ld_errno
= LDAP_PARAM_ERROR
;
184 tmp
= *res
->lm_ber
; /* struct copy */
185 if ( ber_scanf( &tmp
, "{v}", &urls
) == LBER_ERROR
){
186 ld
->ld_errno
= LDAP_DECODING_ERROR
;
192 #endif /* _SOLARIS_SDK */