]> git.sur5r.net Git - openldap/blob - servers/slapd/ava.c
6b11ba04a8ff7805f3fa784568e8489d11068e11
[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 #ifdef SLAPD_SCHEMA_NOT_COMPAT
18
19 void
20 ava_free(
21     AttributeAssertion *ava,
22     int freeit
23 )
24 {
25         ad_free( ava->aa_desc, 1 );
26         ber_bvfree( ava->aa_value );
27         if ( freeit ) {
28                 ch_free( (char *) ava );
29         }
30 }
31
32 int
33 get_ava(
34     BerElement  *ber,
35     AttributeAssertion  **ava,
36         char **text
37 )
38 {
39         int rc;
40         struct berval type, *value;
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
54         rc = slap_bv2ad( &type, &aa->aa_desc, text );
55
56         if( rc != LDAP_SUCCESS ) {
57                 ch_free( type.bv_val );
58                 ber_bvfree( value );
59                 ch_free( aa );
60                 return rc;
61         }
62
63         aa->aa_value = value;
64         *ava = aa;
65
66         return LDAP_SUCCESS;
67 }
68
69 #else
70
71 void
72 ava_free(
73     Ava *ava,
74     int freeit
75 )
76 {
77         ch_free( (char *) ava->ava_type );
78         ch_free( (char *) ava->ava_value.bv_val );
79         if ( freeit ) {
80                 ch_free( (char *) ava );
81         }
82 }
83
84 int
85 get_ava(
86     BerElement  *ber,
87     Ava         *ava,
88         char **text
89 )
90 {
91         if ( ber_scanf( ber, "{ao}", &ava->ava_type, &ava->ava_value )
92             == LBER_ERROR ) {
93                 Debug( LDAP_DEBUG_ANY, "  get_ava ber_scanf\n", 0, 0, 0 );
94                 *text = "Error decoding attribute value assertion";
95                 return SLAPD_DISCONNECT;
96         }
97
98         attr_normalize( ava->ava_type );
99         value_normalize( ava->ava_value.bv_val, attr_syntax( ava->ava_type ) );
100
101         return LDAP_SUCCESS;
102 }
103
104 #endif