]> git.sur5r.net Git - openldap/blob - libraries/libldap/getattr.c
s/<stdlib.h>/<ac/stdlib.h>/
[openldap] / libraries / libldap / getattr.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  *  getattr.c
10  */
11
12 #include "portable.h"
13
14 #include <stdio.h>
15 #include <ac/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 char *
25 ldap_first_attribute( LDAP *ld, LDAPMessage *entry, BerElement **ber )
26 {
27         char *attr;
28
29         assert( ld != NULL );
30         assert( entry != NULL );
31         assert( ber != NULL );
32
33         Debug( LDAP_DEBUG_TRACE, "ldap_first_attribute\n", 0, 0, 0 );
34
35         if ( (*ber = ldap_alloc_ber_with_options( ld )) == NULLBER ) {
36                 *ber = NULL;
37                 return( NULL );
38         }
39
40         **ber = *entry->lm_ber;
41
42         /* 
43          * Skip past the sequence, dn, sequence of sequence, snarf the
44          * attribute type, and skip the set of values, leaving us
45          * positioned right before the next attribute type/value sequence.
46          */
47
48         if ( ber_scanf( *ber, "{x{{ax}", &attr )
49             == LBER_ERROR ) {
50                 ld->ld_errno = LDAP_DECODING_ERROR;
51                 ber_free( *ber, 0 );
52                 *ber = NULL;
53                 return( NULL );
54         }
55
56         return( attr );
57 }
58
59 /* ARGSUSED */
60 char *
61 ldap_next_attribute( LDAP *ld, LDAPMessage *entry, BerElement *ber )
62 {
63         char *attr;
64
65         assert( ld != NULL );
66         assert( entry != NULL );
67         assert( ber != NULL );
68
69         Debug( LDAP_DEBUG_TRACE, "ldap_next_attribute\n", 0, 0, 0 );
70
71         /* skip sequence, snarf attribute type, skip values */
72         if ( ber_scanf( ber, "{ax}", &attr ) 
73             == LBER_ERROR ) {
74                 ld->ld_errno = LDAP_DECODING_ERROR;
75                 return( NULL );
76         }
77
78         return( attr );
79 }