ava.c 1.39 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

void
ava_free(
    AttributeAssertion *ava,
    int	freeit
)
{
24
	free( ava->aa_value.bv_val );
25
26
27
28
29
	if ( freeit ) {
		ch_free( (char *) ava );
	}
}

30
31
32
int
get_ava(
    BerElement	*ber,
33
    AttributeAssertion	**ava,
34
	unsigned usage,
Kurt Zeilenga's avatar
Kurt Zeilenga committed
35
	const char **text
36
37
38
)
{
	int rc;
39
	struct berval type, value;
40
41
	AttributeAssertion *aa;

42
	rc = ber_scanf( ber, "{oo}", &type, &value );
43
44

	if( rc == LBER_ERROR ) {
45
#ifdef NEW_LOGGING
Gary Williams's avatar
Gary Williams committed
46
47
		LDAP_LOG(( "filter", LDAP_LEVEL_ERR,
			   "get_ava:  ber_scanf failure\n" ));
48
#else
49
		Debug( LDAP_DEBUG_ANY, "  get_ava ber_scanf\n", 0, 0, 0 );
50
#endif
51
		*text = "Error decoding attribute value assertion";
52
53
54
55
		return SLAPD_DISCONNECT;
	}

	aa = ch_malloc( sizeof( AttributeAssertion ) );
56
	aa->aa_desc = NULL;
57
	aa->aa_value.bv_val = NULL;
58

59
	rc = slap_bv2ad( &type, &aa->aa_desc, text );
60
	ch_free( type.bv_val );
61
62

	if( rc != LDAP_SUCCESS ) {
63
		ch_free( value.bv_val );
64
65
66
67
		ch_free( aa );
		return rc;
	}

68
	rc = value_normalize( aa->aa_desc, usage, &value, &aa->aa_value, text );
69
	ch_free( value.bv_val );
70
71
72
73
74
75

	if( rc != LDAP_SUCCESS ) {
		ch_free( aa );
		return rc;
	}

76
	*ava = aa;
77
78
79

	return LDAP_SUCCESS;
}