]> git.sur5r.net Git - openldap/blob - servers/slapd/back-perl/search.c
Add missing semicolon.
[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         int return_code;
53
54         ldap_pvt_thread_mutex_lock( &perl_interpreter_mutex );  
55
56         {
57                 dSP; ENTER; SAVETMPS;
58
59                 PUSHMARK(sp) ;
60                 XPUSHs( perl_back->pb_obj_ref );
61                 XPUSHs(sv_2mortal(newSVpv( filterstr , 0)));
62                 XPUSHs(sv_2mortal(newSViv( sizelimit )));
63                 XPUSHs(sv_2mortal(newSViv( timelimit )));
64                 XPUSHs(sv_2mortal(newSViv( attrsonly )));
65
66                 for ( i = 0; attrs != NULL && attrs[i] != NULL; i++ ) {
67                         XPUSHs(sv_2mortal(newSVpv( attrs[i] , 0)));
68                 }
69                 PUTBACK;
70
71                 count = perl_call_method("search", G_ARRAY );
72
73                 SPAGAIN;
74
75                 if (count < 1) {
76                         croak("Big trouble in back_search\n") ;
77                 }
78
79                 if ( count > 1 ) {
80                                                          
81                         for ( i = 1; i < count; i++ ) {
82
83                                 buf = POPp;
84
85                                 if ( (e = str2entry( buf )) == NULL ) {
86                                         Debug( LDAP_DEBUG_ANY, "str2entry(%s) failed\n", buf, 0, 0 );
87
88                                 } else {
89                                         send_search_entry( be, conn, op,
90                                                 e, attrs, attrsonly, 0, NULL );
91                                                          
92                                         entry_free( e );
93                                 }
94                         }
95                 }
96
97                 /*
98                  * We grab the return code last because the stack comes
99                  * from perl in reverse order. 
100                  *
101                  * ex perl: return ( 0, $res_1, $res_2 );
102                  *
103                  * ex stack: <$res_2> <$res_1> <0>
104                  */
105
106                 return_code = POPi;
107
108
109
110                 PUTBACK; FREETMPS; LEAVE;
111         }
112
113         ldap_pvt_thread_mutex_unlock( &perl_interpreter_mutex );        
114
115         if( return_code != 0 ) {
116                 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
117                         NULL, NULL, NULL, NULL );
118
119         } else {
120                 send_ldap_result( conn, op, LDAP_SUCCESS,
121                         NULL, NULL, NULL, NULL );
122         }
123 }
124