]> git.sur5r.net Git - openldap/blob - servers/slapd/ava.c
4b797978fa5324a9112e163346b73114f6f4b872
[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                 Debug( LDAP_DEBUG_ANY, "  get_ava ber_scanf\n", 0, 0, 0 );
47                 *text = "Error decoding attribute value assertion";
48                 return SLAPD_DISCONNECT;
49         }
50
51         aa = ch_malloc( sizeof( AttributeAssertion ) );
52         aa->aa_desc = NULL;
53         aa->aa_value = NULL;
54
55         rc = slap_bv2ad( &type, &aa->aa_desc, text );
56
57         if( rc != LDAP_SUCCESS ) {
58                 ch_free( type.bv_val );
59                 ch_free( value.bv_val );
60                 ch_free( aa );
61                 return rc;
62         }
63
64         rc = value_normalize( aa->aa_desc, usage, &value, &nvalue, text );
65         ch_free( value.bv_val );
66
67         if( rc != LDAP_SUCCESS ) {
68                 ch_free( type.bv_val );
69                 ad_free( aa->aa_desc, 1 );
70                 ch_free( aa );
71                 return rc;
72         }
73
74         aa->aa_value = nvalue;
75         *ava = aa;
76
77         return LDAP_SUCCESS;
78 }
79