2 /* $OpenLDAP: pkg/ldap/libraries/libldap/references.c,v 1.24.2.3 2008/02/11 23:26:41 kurt Exp $ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2008 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
21 #include <ac/stdlib.h>
23 #include <ac/socket.h>
24 #include <ac/string.h>
30 ldap_first_reference( LDAP
*ld
, LDAPMessage
*chain
)
33 assert( LDAP_VALID( ld
) );
34 assert( chain
!= NULL
);
36 return chain
->lm_msgtype
== LDAP_RES_SEARCH_REFERENCE
38 : ldap_next_reference( ld
, chain
);
42 ldap_next_reference( LDAP
*ld
, LDAPMessage
*ref
)
45 assert( LDAP_VALID( ld
) );
46 assert( ref
!= NULL
);
53 if( ref
->lm_msgtype
== LDAP_RES_SEARCH_REFERENCE
) {
62 ldap_count_references( LDAP
*ld
, LDAPMessage
*chain
)
67 assert( LDAP_VALID( ld
) );
69 for ( i
= 0; chain
!= NULL
; chain
= chain
->lm_chain
) {
70 if( chain
->lm_msgtype
== LDAP_RES_SEARCH_REFERENCE
) {
83 LDAPControl
***serverctrls
,
91 assert( LDAP_VALID( ld
) );
92 assert( ref
!= NULL
);
94 if( ref
->lm_msgtype
!= LDAP_RES_SEARCH_REFERENCE
) {
95 return LDAP_PARAM_ERROR
;
98 /* make a private copy of BerElement */
99 AC_MEMCPY(&be
, ref
->lm_ber
, sizeof(be
));
101 if ( ber_scanf( &be
, "{v" /*}*/, &refs
) == LBER_ERROR
) {
102 rc
= LDAP_DECODING_ERROR
;
103 goto free_and_return
;
106 if ( serverctrls
== NULL
) {
108 goto free_and_return
;
111 if ( ber_scanf( &be
, /*{*/ "}" ) == LBER_ERROR
) {
112 rc
= LDAP_DECODING_ERROR
;
113 goto free_and_return
;
116 rc
= ldap_pvt_get_controls( &be
, serverctrls
);
120 if( referralsp
!= NULL
) {
121 /* provide references regradless of return code */
132 if( rc
!= LDAP_SUCCESS
) {
135 if( ld
->ld_matched
!= NULL
) {
136 LDAP_FREE( ld
->ld_matched
);
137 ld
->ld_matched
= NULL
;
140 if( ld
->ld_error
!= NULL
) {
141 LDAP_FREE( ld
->ld_error
);