]> git.sur5r.net Git - openldap/blob - servers/slapd/ava.c
0864a9b9c5a6d37d689712ac005503b1ee033343
[openldap] / servers / slapd / ava.c
1 /* $OpenLDAP$ */
2 /*
3  * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
4  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5  */
6 /* ava.c - routines for dealing with attribute value assertions */
7
8 #include "portable.h"
9
10 #include <stdio.h>
11
12 #include <ac/string.h>
13 #include <ac/socket.h>
14
15 #include "slap.h"
16
17
18 void
19 ava_free(
20     AttributeAssertion *ava,
21     int freeit
22 )
23 {
24         free( ava->aa_value.bv_val );
25         if ( freeit ) {
26                 ch_free( (char *) ava );
27         }
28 }
29
30 int
31 get_ava(
32     BerElement  *ber,
33     AttributeAssertion  **ava,
34         unsigned usage,
35         const char **text
36 )
37 {
38         int rc;
39         struct berval type, value;
40         AttributeAssertion *aa;
41
42         rc = ber_scanf( ber, "{oo}", &type, &value );
43
44         if( rc == LBER_ERROR ) {
45 #ifdef NEW_LOGGING
46                 LDAP_LOG(( "filter", LDAP_LEVEL_ERR,
47                            "get_ava:  ber_scanf failure\n" ));
48 #else
49                 Debug( LDAP_DEBUG_ANY, "  get_ava ber_scanf\n", 0, 0, 0 );
50 #endif
51                 *text = "Error decoding attribute value assertion";
52                 return SLAPD_DISCONNECT;
53         }
54
55         aa = ch_malloc( sizeof( AttributeAssertion ) );
56         aa->aa_desc = NULL;
57         aa->aa_value.bv_val = NULL;
58
59         rc = slap_bv2ad( &type, &aa->aa_desc, text );
60         ch_free( type.bv_val );
61
62         if( rc != LDAP_SUCCESS ) {
63                 ch_free( value.bv_val );
64                 ch_free( aa );
65                 return rc;
66         }
67
68         rc = value_normalize( aa->aa_desc, usage, &value, &aa->aa_value, text );
69         ch_free( value.bv_val );
70
71         if( rc != LDAP_SUCCESS ) {
72                 ch_free( aa );
73                 return rc;
74         }
75
76         *ava = aa;
77
78         return LDAP_SUCCESS;
79 }