]> git.sur5r.net Git - openldap/blob - servers/slapd/ava.c
BDB_INDEX code does no harm (but no good yet, not used by filters yet).
[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         ad_free( ava->aa_desc, 1 );
25         ber_bvfree( ava->aa_value );
26         if ( freeit ) {
27                 ch_free( (char *) ava );
28         }
29 }
30
31 int
32 get_ava(
33     BerElement  *ber,
34     AttributeAssertion  **ava,
35         unsigned usage,
36         const char **text
37 )
38 {
39         int rc;
40         struct berval type, value, *nvalue;
41         AttributeAssertion *aa;
42
43         rc = ber_scanf( ber, "{oo}", &type, &value );
44
45         if( rc == LBER_ERROR ) {
46 #ifdef NEW_LOGGING
47                 LDAP_LOG(( "filter", LDAP_LEVEL_ERR,
48                            "get_ava:  ber_scanf failure\n" ));
49 #else
50                 Debug( LDAP_DEBUG_ANY, "  get_ava ber_scanf\n", 0, 0, 0 );
51 #endif
52                 *text = "Error decoding attribute value assertion";
53                 return SLAPD_DISCONNECT;
54         }
55
56         aa = ch_malloc( sizeof( AttributeAssertion ) );
57         aa->aa_desc = NULL;
58         aa->aa_value = NULL;
59
60         rc = slap_bv2ad( &type, &aa->aa_desc, text );
61         ch_free( type.bv_val );
62
63         if( rc != LDAP_SUCCESS ) {
64                 ch_free( value.bv_val );
65                 ch_free( aa );
66                 return rc;
67         }
68
69         rc = value_normalize( aa->aa_desc, usage, &value, &nvalue, text );
70         ch_free( value.bv_val );
71
72         if( rc != LDAP_SUCCESS ) {
73                 ad_free( aa->aa_desc, 1 );
74                 ch_free( aa );
75                 return rc;
76         }
77
78         aa->aa_value = nvalue;
79         *ava = aa;
80
81         return LDAP_SUCCESS;
82 }
83