]> git.sur5r.net Git - openldap/blob - servers/slapd/back-perl/add.c
ed30475ac9fa2eab7b87dc68beb104246fcef774
[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         ldap_pvt_thread_mutex_lock( &perl_interpreter_mutex );
38         ldap_pvt_thread_mutex_lock( &entry2str_mutex );
39
40         {
41                 dSP; ENTER; SAVETMPS;
42
43                 PUSHMARK(sp);
44                 XPUSHs( perl_back->pb_obj_ref );
45                 XPUSHs(sv_2mortal(newSVpv( entry2str( e, &len ), 0 )));
46
47                 PUTBACK;
48
49                 count = perl_call_method("add", G_SCALAR);
50
51                 SPAGAIN;
52
53                 if (count != 1) {
54                         croak("Big trouble in back_search\n");
55                 }
56                                                          
57                 return_code = POPi;
58
59                 PUTBACK; FREETMPS; LEAVE;
60         }
61
62         ldap_pvt_thread_mutex_unlock( &entry2str_mutex );
63         ldap_pvt_thread_mutex_unlock( &perl_interpreter_mutex );        
64
65         if( return_code != 0 ) {
66                 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
67                         NULL, NULL, NULL, NULL );
68
69         } else {
70                 send_ldap_result( conn, op, LDAP_SUCCESS,
71                         NULL, NULL, NULL, NULL );
72         }
73
74         Debug( LDAP_DEBUG_ANY, "Here ADD\n", 0, 0, 0 );
75         return( 0 );
76 }