]> git.sur5r.net Git - openldap/blob - libraries/libldap/getattr.c
24f6d08509e0fe4bf7beabf580de701b0a8783b1
[openldap] / libraries / libldap / getattr.c
1 /*
2  *  Copyright (c) 1990 Regents of the University of Michigan.
3  *  All rights reserved.
4  *
5  *  getattr.c
6  */
7
8 #include "portable.h"
9
10 #ifndef lint 
11 static char copyright[] = "@(#) Copyright (c) 1990 Regents of the University of Michigan.\nAll rights reserved.\n";
12 #endif
13
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <ctype.h>
17
18 #include <ac/socket.h>
19 #include <ac/string.h>
20
21 #include "lber.h"
22 #include "ldap.h"
23 #include "ldap-int.h"
24
25 char *
26 ldap_first_attribute( LDAP *ld, LDAPMessage *entry, BerElement **ber )
27 {
28         long    len;
29
30         Debug( LDAP_DEBUG_TRACE, "ldap_first_attribute\n", 0, 0, 0 );
31
32         if ( (*ber = ldap_alloc_ber_with_options( ld )) == NULLBER ) {
33                 return( NULL );
34         }
35
36         **ber = *entry->lm_ber;
37
38         /* 
39          * Skip past the sequence, dn, sequence of sequence, snarf the
40          * attribute type, and skip the set of values, leaving us
41          * positioned right before the next attribute type/value sequence.
42          */
43
44         len = LDAP_MAX_ATTR_LEN;
45         if ( ber_scanf( *ber, "{x{{sx}", ld->ld_attrbuffer, &len )
46             == LBER_ERROR ) {
47                 ld->ld_errno = LDAP_DECODING_ERROR;
48                 ber_free( *ber, 0 );
49                 return( NULL );
50         }
51
52         return( ld->ld_attrbuffer );
53 }
54
55 /* ARGSUSED */
56 char *
57 ldap_next_attribute( LDAP *ld, LDAPMessage *entry, BerElement *ber )
58 {
59         long    len;
60
61         Debug( LDAP_DEBUG_TRACE, "ldap_next_attribute\n", 0, 0, 0 );
62
63         /* skip sequence, snarf attribute type, skip values */
64         len = LDAP_MAX_ATTR_LEN;
65         if ( ber_scanf( ber, "{sx}", ld->ld_attrbuffer, &len ) 
66             == LBER_ERROR ) {
67                 ld->ld_errno = LDAP_DECODING_ERROR;
68                 ber_free( ber, 0 );
69                 return( NULL );
70         }
71
72         return( ld->ld_attrbuffer );
73 }