]> git.sur5r.net Git - openldap/blob - servers/slapd/back-perl/compare.c
ITS#1646
[openldap] / servers / slapd / back-perl / compare.c
1 /* $OpenLDAP$ */
2 /*
3  *       Copyright 1999, John C. Quillan, All rights reserved.
4  *       Portions Copyright 2002, myinternet pty ltd. All rights reserved.
5  *
6  *       Redistribution and use in source and binary forms are permitted only
7  *       as authorized by the OpenLDAP Public License.  A copy of this
8  *       license is available at http://www.OpenLDAP.org/license.html or
9  *       in file LICENSE in the top-level directory of the distribution.
10  */
11
12 #include "portable.h"
13
14 #include <stdio.h>
15
16 #include "slap.h"
17 #ifdef HAVE_WIN32_ASPERL
18 #include "asperl_undefs.h"
19 #endif
20
21 #include <EXTERN.h>
22 #include <perl.h>
23
24 #include "perl_back.h"
25
26 /**********************************************************
27  *
28  * Compare
29  *
30  **********************************************************/
31
32 int
33 perl_back_compare(
34         Backend *be,
35         Connection      *conn,
36         Operation       *op,
37         struct berval   *dn,
38         struct berval   *ndn,
39         AttributeAssertion              *ava
40 )
41 {
42         int return_code;
43         int count;
44         char *avastr, *ptr;
45
46         PerlBackend *perl_back = (PerlBackend *)be->be_private;
47
48         avastr = ch_malloc( ava->aa_desc->ad_cname.bv_len + 1 +
49                 ava->aa_value.bv_len + 1 );
50         
51         slap_strcopy( slap_strcopy( slap_strcopy( avastr,
52                 ava->aa_desc->ad_cname.bv_val ), "=" ),
53                 ava->aa_value.bv_val );
54
55         ldap_pvt_thread_mutex_lock( &perl_interpreter_mutex );  
56
57         {
58                 dSP; ENTER; SAVETMPS;
59
60                 PUSHMARK(sp);
61                 XPUSHs( perl_back->pb_obj_ref );
62                 XPUSHs(sv_2mortal(newSVpv( dn->bv_val , 0)));
63                 XPUSHs(sv_2mortal(newSVpv( avastr , 0)));
64                 PUTBACK;
65
66 #ifdef PERL_IS_5_6
67                 count = call_method("compare", G_SCALAR);
68 #else
69                 count = perl_call_method("compare", G_SCALAR);
70 #endif
71
72                 SPAGAIN;
73
74                 if (count != 1) {
75                         croak("Big trouble in back_compare\n");
76                 }
77
78                 return_code = POPi;
79                                                          
80                 PUTBACK; FREETMPS; LEAVE;
81         }
82
83         ldap_pvt_thread_mutex_unlock( &perl_interpreter_mutex );        
84
85         ch_free( avastr );
86
87         send_ldap_result( conn, op, return_code,
88                 NULL, NULL, NULL, NULL );
89
90         Debug( LDAP_DEBUG_ANY, "Perl COMPARE\n", 0, 0, 0 );
91
92         return (0);
93 }
94