]> git.sur5r.net Git - openldap/blob - servers/slapd/back-perl/search.c
Add OpenLDAP RCSid to *.[ch] in clients, libraries, and servers.
[openldap] / servers / slapd / back-perl / search.c
1 /* $OpenLDAP$ */
2 /*
3  *       Copyright 1999, John C. Quillan, All rights reserved.
4  *
5  *       Redistribution and use in source and binary forms are permitted only
6  *       as authorized by the OpenLDAP Public License.  A copy of this
7  *       license is available at http://www.OpenLDAP.org/license.html or
8  *       in file LICENSE in the top-level directory of the distribution.
9  */
10
11 #include "portable.h"
12
13 #include <stdio.h>
14 /*      #include <ac/types.h>
15         #include <ac/socket.h>
16 */
17
18 #include <EXTERN.h>
19 #include <perl.h>
20
21 #include "slap.h"
22 #include "perl_back.h"
23
24 /**********************************************************
25  *
26  * Search
27  *
28  **********************************************************/
29 int
30 perl_back_search(
31         Backend *be,
32         Connection *conn,
33         Operation *op,
34         char *base,
35         int scope,
36         int deref,
37         int sizelimit,
38         int timelimit,
39         Filter *filter,
40         char *filterstr,
41         char **attrs,
42         int attrsonly
43         )
44 {
45         char test[500];
46         int count ;
47         int err = 0;
48         char *matched = NULL, *info = NULL;
49         PerlBackend *perl_back = (PerlBackend *)be->be_private;
50         Entry   *e;
51         char *buf;
52         int i;
53         int return_code;
54
55         ldap_pvt_thread_mutex_lock( &perl_interpreter_mutex );  
56
57         {
58                 dSP; ENTER; SAVETMPS;
59
60                 PUSHMARK(sp) ;
61                 XPUSHs( perl_back->pb_obj_ref );
62                 XPUSHs(sv_2mortal(newSVpv( filterstr , 0)));
63                 XPUSHs(sv_2mortal(newSViv( sizelimit )));
64                 XPUSHs(sv_2mortal(newSViv( timelimit )));
65                 XPUSHs(sv_2mortal(newSViv( attrsonly )));
66
67                 for ( i = 0; attrs != NULL && attrs[i] != NULL; i++ ) {
68                         XPUSHs(sv_2mortal(newSVpv( attrs[i] , 0)));
69                 }
70                 PUTBACK;
71
72                 count = perl_call_method("search", G_ARRAY );
73
74                 SPAGAIN;
75
76                 if (count < 1) {
77                         croak("Big trouble in back_search\n") ;
78                 }
79
80                 if ( count > 1 ) {
81                                                          
82                         for ( i = 1; i < count; i++ ) {
83
84                                 buf = POPp;
85
86                                 if ( (e = str2entry( buf )) == NULL ) {
87                                         Debug( LDAP_DEBUG_ANY, "str2entry(%s) failed\n", buf, 0, 0 );
88
89                                 } else {
90                                         send_search_entry( be, conn, op,
91                                                 e, attrs, attrsonly, NULL );
92                                                          
93                                         entry_free( e );
94                                 }
95                         }
96                 }
97
98                 /*
99                  * We grab the return code last because the stack comes
100                  * from perl in reverse order. 
101                  *
102                  * ex perl: return ( 0, $res_1, $res_2 );
103                  *
104                  * ex stack: <$res_2> <$res_1> <0>
105                  */
106
107                 return_code = POPi;
108
109
110
111                 PUTBACK; FREETMPS; LEAVE;
112         }
113
114         ldap_pvt_thread_mutex_unlock( &perl_interpreter_mutex );        
115
116         if( return_code != 0 ) {
117                 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
118                         NULL, NULL, NULL, NULL );
119
120         } else {
121                 send_ldap_result( conn, op, LDAP_SUCCESS,
122                         NULL, NULL, NULL, NULL );
123         }
124 }
125