Back to index

openldap  2.4.31
compare.c
Go to the documentation of this file.
00001 /* $OpenLDAP$ */
00002 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00003  *
00004  * Copyright 1999-2012 The OpenLDAP Foundation.
00005  * Portions Copyright 1999 John C. Quillan.
00006  * Portions Copyright 2002 myinternet Limited.
00007  * All rights reserved.
00008  *
00009  * Redistribution and use in source and binary forms, with or without
00010  * modification, are permitted only as authorized by the OpenLDAP
00011  * Public License.
00012  *
00013  * A copy of this license is available in file LICENSE in the
00014  * top-level directory of the distribution or, alternatively, at
00015  * <http://www.OpenLDAP.org/license.html>.
00016  */
00017 
00018 #include "perl_back.h"
00019 #include "lutil.h"
00020 
00021 /**********************************************************
00022  *
00023  * Compare
00024  *
00025  **********************************************************/
00026 
00027 int
00028 perl_back_compare(
00029        Operation     *op,
00030        SlapReply     *rs )
00031 {
00032        int count, avalen;
00033        char *avastr;
00034 
00035        PerlBackend *perl_back = (PerlBackend *)op->o_bd->be_private;
00036 
00037        avalen = op->orc_ava->aa_desc->ad_cname.bv_len + 1 +
00038               op->orc_ava->aa_value.bv_len;
00039        avastr = ch_malloc( avalen + 1 );
00040 
00041        lutil_strcopy( lutil_strcopy( lutil_strcopy( avastr,
00042               op->orc_ava->aa_desc->ad_cname.bv_val ), "=" ),
00043               op->orc_ava->aa_value.bv_val );
00044 
00045        PERL_SET_CONTEXT( PERL_INTERPRETER );
00046        ldap_pvt_thread_mutex_lock( &perl_interpreter_mutex );  
00047 
00048        {
00049               dSP; ENTER; SAVETMPS;
00050 
00051               PUSHMARK(sp);
00052               XPUSHs( perl_back->pb_obj_ref );
00053               XPUSHs(sv_2mortal(newSVpv( op->o_req_dn.bv_val , op->o_req_dn.bv_len)));
00054               XPUSHs(sv_2mortal(newSVpv( avastr , avalen)));
00055               PUTBACK;
00056 
00057               count = call_method("compare", G_SCALAR);
00058 
00059               SPAGAIN;
00060 
00061               if (count != 1) {
00062                      croak("Big trouble in back_compare\n");
00063               }
00064 
00065               rs->sr_err = POPi;
00066 
00067               PUTBACK; FREETMPS; LEAVE;
00068        }
00069 
00070        ldap_pvt_thread_mutex_unlock( &perl_interpreter_mutex );       
00071 
00072        ch_free( avastr );
00073 
00074        send_ldap_result( op, rs );
00075 
00076        Debug( LDAP_DEBUG_ANY, "Perl COMPARE\n", 0, 0, 0 );
00077 
00078        return (0);
00079 }
00080