]> git.sur5r.net Git - openldap/blob - servers/slapd/ava.c
To conform to the SLAPI spec, slapi_filter_get_ava() should not duplicate
[openldap] / servers / slapd / ava.c
1 /* $OpenLDAP$ */
2 /*
3  * Copyright 1998-2003 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         ber_tag_t rtag;
40         struct berval type, value;
41         AttributeAssertion *aa;
42
43         rtag = ber_scanf( ber, "{mm}", &type, &value );
44
45         if( rtag == LBER_ERROR ) {
46 #ifdef NEW_LOGGING
47                 LDAP_LOG( FILTER, ERR, "get_ava:  ber_scanf failure\n", 0, 0, 0 );
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
61         if( rc != LDAP_SUCCESS ) {
62                 ch_free( aa );
63                 return rc;
64         }
65
66         rc = value_validate_normalize( aa->aa_desc, usage,
67                 &value, &aa->aa_value, text );
68
69         if( rc != LDAP_SUCCESS ) {
70                 ch_free( aa );
71                 return rc;
72         }
73
74         *ava = aa;
75
76         return LDAP_SUCCESS;
77 }