]> git.sur5r.net Git - openldap/blob - libraries/libldap/getentry.c
Updates for MSVC 5.0. Fix libraries names to be ol{ber,dap,..}32.lib.
[openldap] / libraries / libldap / getentry.c
1 /*
2  * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
3  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
4  */
5 /*  Portions
6  *  Copyright (c) 1990 Regents of the University of Michigan.
7  *  All rights reserved.
8  *
9  *  getentry.c
10  */
11
12 #include "portable.h"
13
14 #include <stdio.h>
15 #include <stdlib.h>
16
17 #include <ac/ctype.h>
18 #include <ac/socket.h>
19 #include <ac/string.h>
20 #include <ac/time.h>
21
22 #include "ldap-int.h"
23
24 /* ARGSUSED */
25 LDAPMessage *
26 ldap_first_entry( LDAP *ld, LDAPMessage *chain )
27 {
28         if( ld == NULL || chain == NULLMSG ) {
29                 return NULLMSG;
30         }
31
32         return chain->lm_msgtype == LDAP_RES_SEARCH_ENTRY
33                 ? chain
34                 : ldap_next_entry( ld, chain );
35 }
36
37 /* ARGSUSED */
38 LDAPMessage *
39 ldap_next_entry( LDAP *ld, LDAPMessage *entry )
40 {
41         if ( ld == NULL || entry == NULLMSG ) {
42                 return NULLMSG;
43         }
44
45         for (
46                 entry = entry->lm_chain;
47                 entry != NULLMSG;
48                 entry = entry->lm_chain )
49         {
50                 if( entry->lm_msgtype == LDAP_RES_SEARCH_ENTRY ) {
51                         return( entry );
52                 }
53         }
54
55         return( NULLMSG );
56 }
57
58 /* ARGSUSED */
59 int
60 ldap_count_entries( LDAP *ld, LDAPMessage *chain )
61 {
62         int     i;
63
64         if ( ld == NULL ) {
65                 return -1;
66         }
67
68         for ( i = 0; chain != NULL; chain = chain->lm_chain ) {
69                 if( chain->lm_msgtype == LDAP_RES_SEARCH_ENTRY ) {
70                         i++;
71                 }
72         }
73
74         return( i );
75 }
76
77 int
78 ldap_get_entry_controls(
79         LDAP *ld,
80         LDAPMessage *entry, 
81         LDAPControl ***serverctrls)
82 {
83         int rc;
84         BerElement be;
85
86         if ( ld == NULL || serverctrls == NULL ||
87                 entry == NULL || entry->lm_msgtype == LDAP_RES_SEARCH_ENTRY )
88         {
89                 return LDAP_PARAM_ERROR;
90         }
91
92         /* make a local copy of the BerElement */
93         SAFEMEMCPY(&be, entry->lm_ber, sizeof(be));
94
95         if ( ber_scanf( &be, "{xx" /*}*/ ) == LBER_ERROR ) {
96                 rc = LDAP_DECODING_ERROR;
97                 goto cleanup_and_return;
98         }
99
100         rc = ldap_get_ber_controls( &be, serverctrls );
101
102 cleanup_and_return:
103         if( rc != LDAP_SUCCESS ) {
104                 ld->ld_errno = rc;
105
106                 if( ld->ld_matched != NULL )
107                         free( ld->ld_matched );
108
109                 ld->ld_matched = NULL;
110
111                 if( ld->ld_error != NULL )
112                         free( ld->ld_error );
113
114                 ld->ld_error = NULL;
115         }
116
117         return rc;
118 }