]> git.sur5r.net Git - openldap/blob - servers/slapd/ava.c
SLAPD_SCHEMA_NOT_COMPAT:
[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         unsigned usage,
37         const char **text
38 )
39 {
40         int rc;
41         struct berval type, value, *nvalue;
42         AttributeAssertion *aa;
43
44         rc = ber_scanf( ber, "{oo}", &type, &value );
45
46         if( rc == LBER_ERROR ) {
47                 Debug( LDAP_DEBUG_ANY, "  get_ava ber_scanf\n", 0, 0, 0 );
48                 *text = "Error decoding attribute value assertion";
49                 return SLAPD_DISCONNECT;
50         }
51
52         aa = ch_malloc( sizeof( AttributeAssertion ) );
53         aa->aa_desc = 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
80 #else
81
82 void
83 ava_free(
84     Ava *ava,
85     int freeit
86 )
87 {
88         ch_free( (char *) ava->ava_type );
89         ch_free( (char *) ava->ava_value.bv_val );
90         if ( freeit ) {
91                 ch_free( (char *) ava );
92         }
93 }
94
95 int
96 get_ava(
97     BerElement  *ber,
98     Ava         *ava,
99         const char **text
100 )
101 {
102         if ( ber_scanf( ber, "{ao}", &ava->ava_type, &ava->ava_value )
103             == LBER_ERROR ) {
104                 Debug( LDAP_DEBUG_ANY, "  get_ava ber_scanf\n", 0, 0, 0 );
105                 *text = "Error decoding attribute value assertion";
106                 return SLAPD_DISCONNECT;
107         }
108
109         attr_normalize( ava->ava_type );
110         value_normalize( ava->ava_value.bv_val, attr_syntax( ava->ava_type ) );
111
112         return LDAP_SUCCESS;
113 }
114
115 #endif