]> git.sur5r.net Git - openldap/blob - servers/slapd/back-perl/compare.c
ITS#1659
[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 /*      #include <ac/types.h>
16         #include <ac/socket.h>
17 */
18
19 #include <EXTERN.h>
20 #include <perl.h>
21
22 #include "slap.h"
23 #include "perl_back.h"
24
25 /**********************************************************
26  *
27  * Compare
28  *
29  **********************************************************/
30
31 perl_back_compare(
32         Backend *be,
33         Connection      *conn,
34         Operation       *op,
35         struct berval   *dn,
36         struct berval   *ndn,
37         AttributeAssertion              *ava
38 )
39 {
40         int return_code;
41         int count;
42         char *avastr, *ptr;
43
44         PerlBackend *perl_back = (PerlBackend *)be->be_private;
45
46         avastr = ch_malloc( ava->aa_desc->ad_cname.bv_len + 1 +
47                 ava->aa_value.bv_len + 1 );
48         
49         slap_strcopy( slap_strcopy( slap_strcopy( avastr,
50                 ava->aa_desc->ad_cname.bv_val ), "=" ),
51                 ava->aa_value.bv_val );
52
53         ldap_pvt_thread_mutex_lock( &perl_interpreter_mutex );  
54
55         {
56                 dSP; ENTER; SAVETMPS;
57
58                 PUSHMARK(sp);
59                 XPUSHs( perl_back->pb_obj_ref );
60                 XPUSHs(sv_2mortal(newSVpv( dn->bv_val , 0)));
61                 XPUSHs(sv_2mortal(newSVpv( avastr , 0)));
62                 PUTBACK;
63
64 #ifdef PERL_IS_5_6
65                 count = call_method("compare", G_SCALAR);
66 #else
67                 count = perl_call_method("compare", G_SCALAR);
68 #endif
69
70                 SPAGAIN;
71
72                 if (count != 1) {
73                         croak("Big trouble in back_compare\n");
74                 }
75
76                 return_code = POPi;
77                                                          
78                 PUTBACK; FREETMPS; LEAVE;
79         }
80
81         ldap_pvt_thread_mutex_unlock( &perl_interpreter_mutex );        
82
83         ch_free( avastr );
84
85         send_ldap_result( conn, op, return_code,
86                 NULL, NULL, NULL, NULL );
87
88         Debug( LDAP_DEBUG_ANY, "Perl COMPARE\n", 0, 0, 0 );
89
90         return (0);
91 }
92