No empty .Rs/.Re
[netbsd-mini2440.git] / external / bsd / openldap / dist / libraries / libldap / getentry.c
blobb06d34fe7c88d6422300a5566c36fdc486b69a7e
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.
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted only as authorized by the OpenLDAP
9 * Public License.
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.
19 #include "portable.h"
21 #include <stdio.h>
22 #include <ac/stdlib.h>
24 #include <ac/socket.h>
25 #include <ac/string.h>
26 #include <ac/time.h>
28 #include "ldap-int.h"
30 /* ARGSUSED */
31 LDAPMessage *
32 ldap_first_entry( LDAP *ld, LDAPMessage *chain )
34 assert( ld != NULL );
35 assert( LDAP_VALID( ld ) );
36 assert( chain != NULL );
38 return chain->lm_msgtype == LDAP_RES_SEARCH_ENTRY
39 ? chain
40 : ldap_next_entry( ld, chain );
43 LDAPMessage *
44 ldap_next_entry( LDAP *ld, LDAPMessage *entry )
46 assert( ld != NULL );
47 assert( LDAP_VALID( ld ) );
48 assert( entry != NULL );
50 for(
51 entry = entry->lm_chain;
52 entry != NULL;
53 entry = entry->lm_chain )
55 if( entry->lm_msgtype == LDAP_RES_SEARCH_ENTRY ) {
56 return( entry );
60 return( NULL );
63 int
64 ldap_count_entries( LDAP *ld, LDAPMessage *chain )
66 int i;
68 assert( ld != NULL );
69 assert( LDAP_VALID( ld ) );
71 for ( i = 0; chain != NULL; chain = chain->lm_chain ) {
72 if( chain->lm_msgtype == LDAP_RES_SEARCH_ENTRY ) {
73 i++;
77 return( i );
80 int
81 ldap_get_entry_controls(
82 LDAP *ld,
83 LDAPMessage *entry,
84 LDAPControl ***sctrls )
86 int rc;
87 BerElement be;
89 assert( ld != NULL );
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 );
108 cleanup_and_return:
109 if( rc != LDAP_SUCCESS ) {
110 ld->ld_errno = rc;
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 );
119 ld->ld_error = NULL;
123 return rc;