]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-perl/search.c
group rewrite/map stuff in one structure and optimize more function calls
[openldap] / servers / slapd / back-perl / search.c
index 1e71424d67163051af324aee20dc263a521667ee..176b6fb69759357b73d313564fd28ee069e7f680 100644 (file)
@@ -1,6 +1,7 @@
 /* $OpenLDAP$ */
 /*
  *      Copyright 1999, John C. Quillan, All rights reserved.
+ *      Portions Copyright 2002, myinternet Limited. All rights reserved.
  *
  *      Redistribution and use in source and binary forms are permitted only
  *      as authorized by the OpenLDAP Public License.  A copy of this
 #include "portable.h"
 
 #include <stdio.h>
-/*     #include <ac/types.h>
-       #include <ac/socket.h>
-*/
+
+#include "slap.h"
+#ifdef HAVE_WIN32_ASPERL
+#include "asperl_undefs.h"
+#endif
 
 #include <EXTERN.h>
 #include <perl.h>
 
-#include "slap.h"
 #include "perl_back.h"
 
 /**********************************************************
  **********************************************************/
 int
 perl_back_search(
-       Backend *be,
-       Connection *conn,
        Operation *op,
-       const char *base,
-       const char *nbase,
-       int scope,
-       int deref,
-       int sizelimit,
-       int timelimit,
-       Filter *filter,
-       const char *filterstr,
-       AttributeName *attrs,
-       int attrsonly
-       )
+       SlapReply *rs )
 {
-       char test[500];
+       PerlBackend *perl_back = (PerlBackend *)op->o_bd->be_private;
        int count ;
-       int err = 0;
-       char *matched = NULL, *info = NULL;
-       PerlBackend *perl_back = (PerlBackend *)be->be_private;
        AttributeName *an;
        Entry   *e;
        char *buf;
        int i;
-       int return_code;
 
        ldap_pvt_thread_mutex_lock( &perl_interpreter_mutex );  
 
@@ -61,17 +47,24 @@ perl_back_search(
 
                PUSHMARK(sp) ;
                XPUSHs( perl_back->pb_obj_ref );
-               XPUSHs(sv_2mortal(newSVpv( filterstr , 0)));
-               XPUSHs(sv_2mortal(newSViv( sizelimit )));
-               XPUSHs(sv_2mortal(newSViv( timelimit )));
-               XPUSHs(sv_2mortal(newSViv( attrsonly )));
-
-               for ( an = attrs; an && an->an_name.bv_val; an++ ) {
+               XPUSHs(sv_2mortal(newSVpv( op->o_req_ndn.bv_val , 0)));
+               XPUSHs(sv_2mortal(newSViv( op->ors_scope )));
+               XPUSHs(sv_2mortal(newSViv( op->ors_deref )));
+               XPUSHs(sv_2mortal(newSViv( op->ors_slimit )));
+               XPUSHs(sv_2mortal(newSViv( op->ors_tlimit )));
+               XPUSHs(sv_2mortal(newSVpv( op->ors_filterstr.bv_val , 0)));
+               XPUSHs(sv_2mortal(newSViv( op->ors_attrsonly )));
+
+               for ( an = op->ors_attrs; an && an->an_name.bv_val; an++ ) {
                        XPUSHs(sv_2mortal(newSVpv( an->an_name.bv_val , 0)));
                }
                PUTBACK;
 
+#ifdef PERL_IS_5_6
+               count = call_method("search", G_ARRAY );
+#else
                count = perl_call_method("search", G_ARRAY );
+#endif
 
                SPAGAIN;
 
@@ -89,9 +82,19 @@ perl_back_search(
                                        Debug( LDAP_DEBUG_ANY, "str2entry(%s) failed\n", buf, 0, 0 );
 
                                } else {
-                                       send_search_entry( be, conn, op,
-                                               e, attrs, attrsonly, NULL );
-                                                        
+                                       int send_entry;
+
+                                       if (perl_back->pb_filter_search_results)
+                                               send_entry = (test_filter( op, e, op->ors_filter ) == LDAP_COMPARE_TRUE);
+                                       else
+                                               send_entry = 1;
+
+                                       if (send_entry) {
+                                               rs->sr_entry = e;
+                                               rs->sr_attrs = op->ors_attrs;
+                                               send_search_entry( op, rs );
+                                       }
+
                                        entry_free( e );
                                }
                        }
@@ -106,7 +109,7 @@ perl_back_search(
                 * ex stack: <$res_2> <$res_1> <0>
                 */
 
-               return_code = POPi;
+               rs->sr_err = POPi;
 
 
 
@@ -115,13 +118,8 @@ perl_back_search(
 
        ldap_pvt_thread_mutex_unlock( &perl_interpreter_mutex );        
 
-       if( return_code != 0 ) {
-               send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
-                       NULL, NULL, NULL, NULL );
+       send_ldap_result( op, rs );
 
-       } else {
-               send_ldap_result( conn, op, LDAP_SUCCESS,
-                       NULL, NULL, NULL, NULL );
-       }
+       return 0;
 }