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