1/*	$NetBSD: compare.c,v 1.3 2021/08/14 16:15:01 christos Exp $	*/
2
3/* $OpenLDAP$ */
4/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 *
6 * Copyright 1999-2021 The OpenLDAP Foundation.
7 * Portions Copyright 1999 John C. Quillan.
8 * Portions Copyright 2002 myinternet Limited.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted only as authorized by the OpenLDAP
13 * Public License.
14 *
15 * A copy of this license is available in file LICENSE in the
16 * top-level directory of the distribution or, alternatively, at
17 * <http://www.OpenLDAP.org/license.html>.
18 */
19
20#include "perl_back.h"
21#include "lutil.h"
22
23/**********************************************************
24 *
25 * Compare
26 *
27 **********************************************************/
28
29int
30perl_back_compare(
31	Operation	*op,
32	SlapReply	*rs )
33{
34	int count, avalen;
35	char *avastr;
36
37	PerlBackend *perl_back = (PerlBackend *)op->o_bd->be_private;
38
39	avalen = op->orc_ava->aa_desc->ad_cname.bv_len + 1 +
40		op->orc_ava->aa_value.bv_len;
41	avastr = ch_malloc( avalen + 1 );
42
43	lutil_strcopy( lutil_strcopy( lutil_strcopy( avastr,
44		op->orc_ava->aa_desc->ad_cname.bv_val ), "=" ),
45		op->orc_ava->aa_value.bv_val );
46
47	PERL_SET_CONTEXT( PERL_INTERPRETER );
48	ldap_pvt_thread_mutex_lock( &perl_interpreter_mutex );
49
50	{
51		dSP; ENTER; SAVETMPS;
52
53		PUSHMARK(sp);
54		XPUSHs( perl_back->pb_obj_ref );
55		XPUSHs(sv_2mortal(newSVpv( op->o_req_dn.bv_val , op->o_req_dn.bv_len)));
56		XPUSHs(sv_2mortal(newSVpv( avastr , avalen)));
57		PUTBACK;
58
59		count = call_method("compare", G_SCALAR);
60
61		SPAGAIN;
62
63		if (count != 1) {
64			croak("Big trouble in back_compare\n");
65		}
66
67		rs->sr_err = POPi;
68
69		PUTBACK; FREETMPS; LEAVE;
70	}
71
72	ldap_pvt_thread_mutex_unlock( &perl_interpreter_mutex );
73
74	ch_free( avastr );
75
76	send_ldap_result( op, rs );
77
78	Debug( LDAP_DEBUG_ANY, "Perl COMPARE\n" );
79
80	return (0);
81}
82
83