]> git.sur5r.net Git - openldap/blob - servers/slapd/back-perl/modify.c
17b0597305ef319040d7481d063f0cb486e2de13
[openldap] / servers / slapd / back-perl / modify.c
1 /* $OpenLDAP$ */
2 /*
3  *       Copyright 1999, John C. Quillan, All rights reserved.
4  *       Portions Copyright 2002, myinternet Limited. All rights reserved.
5  *
6  *       Redistribution and use in source and binary forms are permitted only
7  *       as authorized by the OpenLDAP Public License.  A copy of this
8  *       license is available at http://www.OpenLDAP.org/license.html or
9  *       in file LICENSE in the top-level directory of the distribution.
10  */
11
12 #include "portable.h"
13
14 #include <stdio.h>
15
16 #include "slap.h"
17 #ifdef HAVE_WIN32_ASPERL
18 #include "asperl_undefs.h"
19 #endif
20
21 #include <EXTERN.h>
22 #include <perl.h>
23
24 #include "perl_back.h"
25
26 int
27 perl_back_modify(
28         Operation       *op,
29         SlapReply       *rs )
30 {
31         PerlBackend *perl_back = (PerlBackend *)op->o_bd->be_private;
32         Modifications *modlist = op->orm_modlist;
33         int count;
34         int i;
35
36
37         ldap_pvt_thread_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( op->o_req_dn.bv_val , 0)));
45
46                 for (; modlist != NULL; modlist = modlist->sml_next ) {
47                         Modification *mods = &modlist->sml_mod;
48
49                         switch ( mods->sm_op & ~LDAP_MOD_BVALUES ) {
50                         case LDAP_MOD_ADD:
51                                 XPUSHs(sv_2mortal(newSVpv("ADD", 0 )));
52                                 break;
53                                 
54                         case LDAP_MOD_DELETE:
55                                 XPUSHs(sv_2mortal(newSVpv("DELETE", 0 )));
56                                 break;
57                                 
58                         case LDAP_MOD_REPLACE:
59                                 XPUSHs(sv_2mortal(newSVpv("REPLACE", 0 )));
60                                 break;
61                         }
62
63                         
64                         XPUSHs(sv_2mortal(newSVpv( mods->sm_desc->ad_cname.bv_val, 0 )));
65
66                         for ( i = 0;
67                                 mods->sm_bvalues != NULL && mods->sm_bvalues[i].bv_val != NULL;
68                                 i++ )
69                         {
70                                 XPUSHs(sv_2mortal(newSVpv( mods->sm_bvalues[i].bv_val, 0 )));
71                         }
72                 }
73
74                 PUTBACK;
75
76 #ifdef PERL_IS_5_6
77                 count = call_method("modify", G_SCALAR);
78 #else
79                 count = perl_call_method("modify", G_SCALAR);
80 #endif
81
82                 SPAGAIN;
83
84                 if (count != 1) {
85                         croak("Big trouble in back_modify\n");
86                 }
87                                                          
88                 rs->sr_err = POPi;
89
90                 PUTBACK; FREETMPS; LEAVE;
91         }
92
93         ldap_pvt_thread_mutex_unlock( &perl_interpreter_mutex );
94
95         send_ldap_result( op, rs );
96
97         Debug( LDAP_DEBUG_ANY, "Perl MODIFY\n", 0, 0, 0 );
98         return( 0 );
99 }
100