ava.c 1.64 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
int
get_ava(
    BerElement	*ber,
    AttributeAssertion	**ava
)
{
	int rc;
	char *text;
	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 );
		return SLAPD_DISCONNECT;
	}

	aa = ch_malloc( sizeof( AttributeAssertion ) );
51
	aa->aa_desc = NULL;
52
53
54
55
56
57
58
59
60
61
62

	rc = slap_bv2ad( &type, &aa->aa_desc, &text );

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

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

	return LDAP_SUCCESS;
}

68
69
#else

70
71
72
73
74
75
76
77
78
79
80
81
82
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
83
84
85
86
87
88
89
90
91
int
get_ava(
    BerElement	*ber,
    Ava		*ava
)
{
	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 );
92
		return SLAPD_DISCONNECT;
Kurt Zeilenga's avatar
Kurt Zeilenga committed
93
	}
94

Kurt Zeilenga's avatar
Kurt Zeilenga committed
95
96
97
	attr_normalize( ava->ava_type );
	value_normalize( ava->ava_value.bv_val, attr_syntax( ava->ava_type ) );

98
	return LDAP_SUCCESS;
Kurt Zeilenga's avatar
Kurt Zeilenga committed
99
100
}

101
#endif