]> git.sur5r.net Git - openldap/blob - servers/slapd/back-perl/search.c
e85435fe65dff25ed78e931e36fd85e89d185218
[openldap] / servers / slapd / back-perl / search.c
1 /*
2  *       Copyright 1999, John C. Quillan, All rights reserved.
3  *
4  *       Redistribution and use in source and binary forms are permitted only
5  *       as authorized by the OpenLDAP Public License.  A copy of this
6  *       license is available at http://www.OpenLDAP.org/license.html or
7  *       in file LICENSE in the top-level directory of the distribution.
8  */
9
10 #include "portable.h"
11
12 #include <stdio.h>
13 /*      #include <ac/types.h>
14         #include <ac/socket.h>
15 */
16
17 #include <EXTERN.h>
18 #include <perl.h>
19
20 #include "slap.h"
21 #include "perl_back.h"
22
23 /**********************************************************
24  *
25  * Search
26  *
27  **********************************************************/
28 int
29 perl_back_search(
30          Backend *be,
31          Connection *conn,
32          Operation *op,
33          char *base,
34          int scope,
35          int deref,
36          int sizelimit,
37          int timelimit,
38          Filter *filter,
39          char *filterstr,
40          char **attrs,
41          int attrsonly
42 )
43 {
44         char test[500];
45         int count ;
46         int err = 0;
47         char *matched = NULL, *info = NULL;
48         PerlBackend *perl_back = (PerlBackend *)be->be_private;
49         Entry   *e;
50         char *buf;
51         int i;
52
53         pthread_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( filterstr , 0)));
61                 XPUSHs(sv_2mortal(newSViv( sizelimit )));
62                 XPUSHs(sv_2mortal(newSViv( timelimit )));
63                 XPUSHs(sv_2mortal(newSViv( attrsonly )));
64
65                 for ( i = 0; attrs != NULL && attrs[i] != NULL; i++ ) {
66                         XPUSHs(sv_2mortal(newSVpv( attrs[i] , 0)));
67                 }
68                 PUTBACK;
69
70                 count = perl_call_method("search", G_SCALAR);
71
72                 SPAGAIN;
73
74                 if (count != 1) {
75                         croak("Big trouble in back_search\n") ;
76                 }
77                                                          
78                 printf( "Before send search entry\n");
79                 buf = POPp;
80
81                 if ( (e = str2entry( buf )) == NULL ) {
82                         Debug( LDAP_DEBUG_ANY, "str2entry(%s) failed\n", buf, 0, 0 );
83
84                 } else {
85                         send_search_entry( be,
86                                 conn,
87                                 op,
88                                 e,
89                                 attrs,
90                                 attrsonly );
91                                                          
92                         entry_free( e );
93                 }
94
95                 PUTBACK; FREETMPS; LEAVE;
96         }
97
98         pthread_mutex_unlock( &perl_interpreter_mutex );        
99
100         send_ldap_result( conn, op, err, matched, info );
101 }
102