1 /* $OpenLDAP: pkg/ldap/libraries/libldap/getentry.c,v 1.28.2.3 2008/02/11 23:26:41 kurt Exp $ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2008 The OpenLDAP Foundation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted only as authorized by the OpenLDAP
11 * A copy of this license is available in the file LICENSE in the
12 * top-level directory of the distribution or, alternatively, at
13 * <http://www.OpenLDAP.org/license.html>.
15 /* Portions Copyright (c) 1990 Regents of the University of Michigan.
16 * All rights reserved.
22 #include <ac/stdlib.h>
24 #include <ac/socket.h>
25 #include <ac/string.h>
32 ldap_first_entry( LDAP
*ld
, LDAPMessage
*chain
)
35 assert( LDAP_VALID( ld
) );
36 assert( chain
!= NULL
);
38 return chain
->lm_msgtype
== LDAP_RES_SEARCH_ENTRY
40 : ldap_next_entry( ld
, chain
);
44 ldap_next_entry( LDAP
*ld
, LDAPMessage
*entry
)
47 assert( LDAP_VALID( ld
) );
48 assert( entry
!= NULL
);
51 entry
= entry
->lm_chain
;
53 entry
= entry
->lm_chain
)
55 if( entry
->lm_msgtype
== LDAP_RES_SEARCH_ENTRY
) {
64 ldap_count_entries( LDAP
*ld
, LDAPMessage
*chain
)
69 assert( LDAP_VALID( ld
) );
71 for ( i
= 0; chain
!= NULL
; chain
= chain
->lm_chain
) {
72 if( chain
->lm_msgtype
== LDAP_RES_SEARCH_ENTRY
) {
81 ldap_get_entry_controls(
84 LDAPControl
***sctrls
)
90 assert( LDAP_VALID( ld
) );
91 assert( entry
!= NULL
);
92 assert( sctrls
!= NULL
);
94 if ( entry
->lm_msgtype
!= LDAP_RES_SEARCH_ENTRY
) {
95 return LDAP_PARAM_ERROR
;
98 /* make a local copy of the BerElement */
99 AC_MEMCPY(&be
, entry
->lm_ber
, sizeof(be
));
101 if ( ber_scanf( &be
, "{xx" /*}*/ ) == LBER_ERROR
) {
102 rc
= LDAP_DECODING_ERROR
;
103 goto cleanup_and_return
;
106 rc
= ldap_pvt_get_controls( &be
, sctrls
);
109 if( rc
!= LDAP_SUCCESS
) {
112 if( ld
->ld_matched
!= NULL
) {
113 LDAP_FREE( ld
->ld_matched
);
114 ld
->ld_matched
= NULL
;
117 if( ld
->ld_error
!= NULL
) {
118 LDAP_FREE( ld
->ld_error
);