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