]> git.sur5r.net Git - openldap/blob - servers/slapd/ava.c
8b42b7eb6d999356f25bbedd55b4248f8d1f8247
[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 )
37 {
38         int rc;
39         char *text;
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                 return SLAPD_DISCONNECT;
48         }
49
50         aa = ch_malloc( sizeof( AttributeAssertion ) );
51
52         rc = slap_bv2ad( &type, &aa->aa_desc, &text );
53
54         if( rc != LDAP_SUCCESS ) {
55                 ch_free( type.bv_val );
56                 ber_bvfree( value );
57                 ch_free( aa );
58                 return rc;
59         }
60
61         aa->aa_value = value;
62
63         return LDAP_SUCCESS;
64 }
65
66 #else
67
68 void
69 ava_free(
70     Ava *ava,
71     int freeit
72 )
73 {
74         ch_free( (char *) ava->ava_type );
75         ch_free( (char *) ava->ava_value.bv_val );
76         if ( freeit ) {
77                 ch_free( (char *) ava );
78         }
79 }
80
81 int
82 get_ava(
83     BerElement  *ber,
84     Ava         *ava
85 )
86 {
87         if ( ber_scanf( ber, "{ao}", &ava->ava_type, &ava->ava_value )
88             == LBER_ERROR ) {
89                 Debug( LDAP_DEBUG_ANY, "  get_ava ber_scanf\n", 0, 0, 0 );
90                 return SLAPD_DISCONNECT;
91         }
92
93         attr_normalize( ava->ava_type );
94         value_normalize( ava->ava_value.bv_val, attr_syntax( ava->ava_type ) );
95
96         return LDAP_SUCCESS;
97 }
98
99 #endif