]> git.sur5r.net Git - openldap/blob - servers/slapd/back-perl/add.c
6ff3b8d1cad97c74991cf5235923e2cd2999f577
[openldap] / servers / slapd / back-perl / add.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 int
24 perl_back_add(
25         Backend *be,
26         Connection      *conn,
27         Operation       *op,
28         Entry   *e
29 )
30 {
31         int len;
32         int count;
33         int return_code;
34
35         PerlBackend *perl_back = (PerlBackend *) be->be_private;
36
37         pthread_mutex_lock( &perl_interpreter_mutex );  
38
39         {
40                 dSP; ENTER; SAVETMPS;
41
42                 PUSHMARK(sp);
43                 XPUSHs( perl_back->pb_obj_ref );
44                 XPUSHs(sv_2mortal(newSVpv( entry2str( e, &len, 0 ), 0 )));
45
46                 PUTBACK;
47
48                 count = perl_call_method("add", G_SCALAR);
49
50                 SPAGAIN;
51
52                 if (count != 1) {
53                         croak("Big trouble in back_search\n");
54                 }
55                                                          
56                 return_code = POPi;
57
58                 PUTBACK; FREETMPS; LEAVE;
59         }
60
61         pthread_mutex_unlock( &perl_interpreter_mutex );        
62
63         if( return_code != 0 ) {
64                 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
65
66         } else {
67                 send_ldap_result( conn, op, LDAP_SUCCESS, "", "" );
68         }
69
70         Debug( LDAP_DEBUG_ANY, "Here ADD\n", 0, 0, 0 );
71         return( 0 );
72 }