Back to index

openldap  2.4.31
search.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 
00020 /**********************************************************
00021  *
00022  * Search
00023  *
00024  **********************************************************/
00025 int
00026 perl_back_search(
00027        Operation *op,
00028        SlapReply *rs )
00029 {
00030        PerlBackend *perl_back = (PerlBackend *)op->o_bd->be_private;
00031        int count ;
00032        AttributeName *an;
00033        Entry  *e;
00034        char *buf;
00035        int i;
00036 
00037        PERL_SET_CONTEXT( PERL_INTERPRETER );
00038        ldap_pvt_thread_mutex_lock( &perl_interpreter_mutex );  
00039 
00040        {
00041               dSP; ENTER; SAVETMPS;
00042 
00043               PUSHMARK(sp) ;
00044               XPUSHs( perl_back->pb_obj_ref );
00045               XPUSHs(sv_2mortal(newSVpv( op->o_req_ndn.bv_val , op->o_req_ndn.bv_len)));
00046               XPUSHs(sv_2mortal(newSViv( op->ors_scope )));
00047               XPUSHs(sv_2mortal(newSViv( op->ors_deref )));
00048               XPUSHs(sv_2mortal(newSViv( op->ors_slimit )));
00049               XPUSHs(sv_2mortal(newSViv( op->ors_tlimit )));
00050               XPUSHs(sv_2mortal(newSVpv( op->ors_filterstr.bv_val , op->ors_filterstr.bv_len)));
00051               XPUSHs(sv_2mortal(newSViv( op->ors_attrsonly )));
00052 
00053               for ( an = op->ors_attrs; an && an->an_name.bv_val; an++ ) {
00054                      XPUSHs(sv_2mortal(newSVpv( an->an_name.bv_val , an->an_name.bv_len)));
00055               }
00056               PUTBACK;
00057 
00058               count = call_method("search", G_ARRAY );
00059 
00060               SPAGAIN;
00061 
00062               if (count < 1) {
00063                      croak("Big trouble in back_search\n") ;
00064               }
00065 
00066               if ( count > 1 ) {
00067                                                   
00068                      for ( i = 1; i < count; i++ ) {
00069 
00070                             buf = POPp;
00071 
00072                             if ( (e = str2entry( buf )) == NULL ) {
00073                                    Debug( LDAP_DEBUG_ANY, "str2entry(%s) failed\n", buf, 0, 0 );
00074 
00075                             } else {
00076                                    int send_entry;
00077 
00078                                    if (perl_back->pb_filter_search_results)
00079                                           send_entry = (test_filter( op, e, op->ors_filter ) == LDAP_COMPARE_TRUE);
00080                                    else
00081                                           send_entry = 1;
00082 
00083                                    if (send_entry) {
00084                                           rs->sr_entry = e;
00085                                           rs->sr_attrs = op->ors_attrs;
00086                                           rs->sr_flags = REP_ENTRY_MODIFIABLE;
00087                                           rs->sr_err = LDAP_SUCCESS;
00088                                           rs->sr_err = send_search_entry( op, rs );
00089                                           rs->sr_flags = 0;
00090                                           rs->sr_attrs = NULL;
00091                                           rs->sr_entry = NULL;
00092                                           if ( rs->sr_err == LDAP_SIZELIMIT_EXCEEDED ) {
00093                                                  goto done;
00094                                           }
00095                                    }
00096 
00097                                    entry_free( e );
00098                             }
00099                      }
00100               }
00101 
00102               /*
00103                * We grab the return code last because the stack comes
00104                * from perl in reverse order. 
00105                *
00106                * ex perl: return ( 0, $res_1, $res_2 );
00107                *
00108                * ex stack: <$res_2> <$res_1> <0>
00109                */
00110 
00111               rs->sr_err = POPi;
00112 
00113 done:;
00114               PUTBACK; FREETMPS; LEAVE;
00115        }
00116 
00117        ldap_pvt_thread_mutex_unlock( &perl_interpreter_mutex );       
00118 
00119        send_ldap_result( op, rs );
00120 
00121        return 0;
00122 }