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

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

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

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

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

	aa = ch_malloc( sizeof( AttributeAssertion ) );
57
	aa->aa_desc = NULL;
58
	aa->aa_value = NULL;
59

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

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

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

	if( rc != LDAP_SUCCESS ) {
		ad_free( aa->aa_desc, 1 );
		ch_free( aa );
		return rc;
	}

78
	aa->aa_value = nvalue;
79
	*ava = aa;
80
81
82
83

	return LDAP_SUCCESS;
}