]> git.sur5r.net Git - openldap/blob - libraries/libldap/getattr.c
8e655da12efea0cb1aeb4a518ccc0f9f5b7780c2
[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 <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         long    len;
28
29         Debug( LDAP_DEBUG_TRACE, "ldap_first_attribute\n", 0, 0, 0 );
30
31         if ( (*ber = ldap_alloc_ber_with_options( ld )) == NULLBER ) {
32                 *ber = NULL;
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                 *ber = NULL;
50                 return( NULL );
51         }
52
53         return( ld->ld_attrbuffer );
54 }
55
56 /* ARGSUSED */
57 char *
58 ldap_next_attribute( LDAP *ld, LDAPMessage *entry, BerElement *ber )
59 {
60         long    len;
61
62         Debug( LDAP_DEBUG_TRACE, "ldap_next_attribute\n", 0, 0, 0 );
63
64         /* skip sequence, snarf attribute type, skip values */
65         len = LDAP_MAX_ATTR_LEN;
66         if ( ber_scanf( ber, "{sx}", ld->ld_attrbuffer, &len ) 
67             == LBER_ERROR ) {
68                 ld->ld_errno = LDAP_DECODING_ERROR;
69                 /* ber_free( ber, 0 ); *//* don't free the BerElement */
70                 return( NULL );
71         }
72
73         return( ld->ld_attrbuffer );
74 }