]> git.sur5r.net Git - openldap/blob - servers/slapd/ava.c
Use "uri" directive (instead of "server") to specify server. Add "bin
[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         aa->aa_value = NULL;
55
56         rc = slap_bv2ad( &type, &aa->aa_desc, text );
57
58         if( rc != LDAP_SUCCESS ) {
59                 ch_free( type.bv_val );
60                 ch_free( value.bv_val );
61                 ch_free( aa );
62                 return rc;
63         }
64
65         rc = value_normalize( aa->aa_desc, usage, &value, &nvalue, text );
66         ch_free( value.bv_val );
67
68         if( rc != LDAP_SUCCESS ) {
69                 ch_free( type.bv_val );
70                 ad_free( aa->aa_desc, 1 );
71                 ch_free( aa );
72                 return rc;
73         }
74
75         aa->aa_value = nvalue;
76         *ava = aa;
77
78         return LDAP_SUCCESS;
79 }
80
81 #else
82
83 void
84 ava_free(
85     Ava *ava,
86     int freeit
87 )
88 {
89         ch_free( (char *) ava->ava_type );
90         ch_free( (char *) ava->ava_value.bv_val );
91         if ( freeit ) {
92                 ch_free( (char *) ava );
93         }
94 }
95
96 int
97 get_ava(
98     BerElement  *ber,
99     Ava         *ava,
100         const char **text
101 )
102 {
103         if ( ber_scanf( ber, "{ao}", &ava->ava_type, &ava->ava_value )
104             == LBER_ERROR ) {
105                 Debug( LDAP_DEBUG_ANY, "  get_ava ber_scanf\n", 0, 0, 0 );
106                 *text = "Error decoding attribute value assertion";
107                 return SLAPD_DISCONNECT;
108         }
109
110         attr_normalize( ava->ava_type );
111         value_normalize( ava->ava_value.bv_val, attr_syntax( ava->ava_type ) );
112
113         return LDAP_SUCCESS;
114 }
115
116 #endif