ava.c 1.76 KB
Newer Older
1
/* $OpenLDAP$ */
Kurt Zeilenga's avatar
Kurt Zeilenga committed
2
/*
Kurt Zeilenga's avatar
Kurt Zeilenga committed
3
 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
Kurt Zeilenga's avatar
Kurt Zeilenga committed
4
5
 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
 */
Kurt Zeilenga's avatar
Kurt Zeilenga committed
6
7
/* ava.c - routines for dealing with attribute value assertions */

Kurt Zeilenga's avatar
Kurt Zeilenga committed
8
9
#include "portable.h"

Kurt Zeilenga's avatar
Kurt Zeilenga committed
10
#include <stdio.h>
Kurt Zeilenga's avatar
Kurt Zeilenga committed
11
12
13
14

#include <ac/string.h>
#include <ac/socket.h>

Kurt Zeilenga's avatar
Kurt Zeilenga committed
15
16
#include "slap.h"

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#ifdef SLAPD_SCHEMA_NOT_COMPAT

void
ava_free(
    AttributeAssertion *ava,
    int	freeit
)
{
	ad_free( ava->aa_desc, 1 );
	ber_bvfree( ava->aa_value );
	if ( freeit ) {
		ch_free( (char *) ava );
	}
}

32
33
34
int
get_ava(
    BerElement	*ber,
35
36
    AttributeAssertion	**ava,
	char **text
37
38
39
40
41
42
43
44
45
46
)
{
	int rc;
	struct berval type, *value;
	AttributeAssertion *aa;

	rc = ber_scanf( ber, "{oO}", &type, &value );

	if( rc == LBER_ERROR ) {
		Debug( LDAP_DEBUG_ANY, "  get_ava ber_scanf\n", 0, 0, 0 );
47
		*text = "Error decoding attribute value assertion";
48
49
50
51
		return SLAPD_DISCONNECT;
	}

	aa = ch_malloc( sizeof( AttributeAssertion ) );
52
	aa->aa_desc = NULL;
53

54
	rc = slap_bv2ad( &type, &aa->aa_desc, text );
55
56
57
58
59
60
61
62
63

	if( rc != LDAP_SUCCESS ) {
		ch_free( type.bv_val );
		ber_bvfree( value );
		ch_free( aa );
		return rc;
	}

	aa->aa_value = value;
64
	*ava = aa;
65
66
67
68

	return LDAP_SUCCESS;
}

69
70
#else

71
72
73
74
75
76
77
78
79
80
81
82
83
void
ava_free(
    Ava	*ava,
    int	freeit
)
{
	ch_free( (char *) ava->ava_type );
	ch_free( (char *) ava->ava_value.bv_val );
	if ( freeit ) {
		ch_free( (char *) ava );
	}
}

Kurt Zeilenga's avatar
Kurt Zeilenga committed
84
85
86
int
get_ava(
    BerElement	*ber,
87
88
    Ava		*ava,
	char **text
Kurt Zeilenga's avatar
Kurt Zeilenga committed
89
90
91
92
93
)
{
	if ( ber_scanf( ber, "{ao}", &ava->ava_type, &ava->ava_value )
	    == LBER_ERROR ) {
		Debug( LDAP_DEBUG_ANY, "  get_ava ber_scanf\n", 0, 0, 0 );
94
		*text = "Error decoding attribute value assertion";
95
		return SLAPD_DISCONNECT;
Kurt Zeilenga's avatar
Kurt Zeilenga committed
96
	}
97

Kurt Zeilenga's avatar
Kurt Zeilenga committed
98
99
100
	attr_normalize( ava->ava_type );
	value_normalize( ava->ava_value.bv_val, attr_syntax( ava->ava_type ) );

101
	return LDAP_SUCCESS;
Kurt Zeilenga's avatar
Kurt Zeilenga committed
102
103
}

104
#endif