dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / libldap5 / sources / ldap / common / referral.c
blob6d6973bb5f0351ed0a13d4ca53d0afa535e26b25
1 /*
2 * Copyright (c) 2001 by Sun Microsystems, Inc.
3 * All rights reserved.
4 */
6 #pragma ident "%Z%%M% %I% %E% SMI"
8 /*
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
20 * March 31, 1998.
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
25 * Rights Reserved.
27 * Contributor(s):
30 * referral.c - routines for handling LDAPv3 referrals and references.
33 #include "ldap-int.h"
36 LDAPMessage *
37 LDAP_CALL
38 ldap_first_reference( LDAP *ld, LDAPMessage *res )
40 if ( !NSLDAPI_VALID_LDAP_POINTER( ld ) || res == NULLMSG ) {
41 return( NULLMSG );
44 if ( res->lm_msgtype == LDAP_RES_SEARCH_REFERENCE ) {
45 return( res );
48 return( ldap_next_reference( ld, res ));
52 LDAPMessage *
53 LDAP_CALL
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 ) {
62 return( ref );
66 return( NULLMSG );
70 int
71 LDAP_CALL
72 ldap_count_references( LDAP *ld, LDAPMessage *res )
74 int i;
76 if ( !NSLDAPI_VALID_LDAP_POINTER( ld )) {
77 return( -1 );
80 for ( i = 0; res != NULL; res = res->lm_chain ) {
81 if ( res->lm_msgtype == LDAP_RES_SEARCH_REFERENCE ) {
82 ++i;
86 return( i );
91 * returns an LDAP error code.
93 int
94 LDAP_CALL
95 ldap_parse_reference( LDAP *ld, LDAPMessage *ref, char ***referralsp,
96 LDAPControl ***serverctrlsp, int freeit )
98 int err;
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,
106 serverctrlsp );
108 LDAP_SET_LDERRNO( ld, err, NULL, NULL );
110 if ( freeit ) {
111 ldap_msgfree( ref );
114 return( err );
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 )
126 int err;
127 BerElement ber;
128 char **refs;
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;
157 } else {
158 err = nsldapi_get_controls( &ber, serverctrlsp );
162 if ( referralsp == NULL ) {
163 ldap_value_free( refs );
164 } else {
165 *referralsp = refs;
168 return( err );
171 #ifdef _SOLARIS_SDK
173 char ** ldap_get_reference_urls(LDAP *ld, LDAPMessage *res)
175 BerElement tmp;
176 char **urls = NULL;
178 LDAPDebug( LDAP_DEBUG_TRACE, "ldap_get_reference_urls\n", 0, 0, 0 );
180 if (res == NULL){
181 ld->ld_errno = LDAP_PARAM_ERROR;
182 return (NULL);
184 tmp = *res->lm_ber; /* struct copy */
185 if ( ber_scanf( &tmp, "{v}", &urls) == LBER_ERROR){
186 ld->ld_errno = LDAP_DECODING_ERROR;
187 return (NULL);
189 return (urls);
192 #endif /* _SOLARIS_SDK */