]> git.sur5r.net Git - openldap/blob - servers/slapd/back-perl/modify.c
3b52095c21fafbff2efa29031caffd42f4764747
[openldap] / servers / slapd / back-perl / modify.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 int
25 perl_back_modify(
26         Backend *be,
27         Connection      *conn,
28         Operation       *op,
29         char    *dn,
30         char    *ndn,
31         LDAPModList     *modlist
32 )
33 {
34         char test[500];
35         int return_code;
36         int count;
37         int i;
38         int err = 0;
39         char *matched = NULL, *info = NULL;
40
41         PerlBackend *perl_back = (PerlBackend *)be->be_private;
42
43         ldap_pvt_thread_mutex_lock( &perl_interpreter_mutex );  
44
45         {
46                 dSP; ENTER; SAVETMPS;
47                 
48                 PUSHMARK(sp);
49                 XPUSHs( perl_back->pb_obj_ref );
50                 XPUSHs(sv_2mortal(newSVpv( dn , 0)));
51
52                 for (; modlist != NULL; modlist = modlist->ml_next ) {
53                         LDAPMod *mods = &modlist->ml_mod;
54
55                         switch ( mods->mod_op & ~LDAP_MOD_BVALUES ) {
56                         case LDAP_MOD_ADD:
57                                 XPUSHs(sv_2mortal(newSVpv("ADD", 0 )));
58                                 break;
59                                 
60                         case LDAP_MOD_DELETE:
61                                 XPUSHs(sv_2mortal(newSVpv("DELETE", 0 )));
62                                 break;
63                                 
64                         case LDAP_MOD_REPLACE:
65                                 XPUSHs(sv_2mortal(newSVpv("REPLACE", 0 )));
66                                 break;
67                         }
68
69                         
70                         XPUSHs(sv_2mortal(newSVpv( mods->mod_type, 0 )));
71
72                         for ( i = 0;
73                                 mods->mod_bvalues != NULL && mods->mod_bvalues[i] != NULL;
74                                 i++ )
75                         {
76                                 XPUSHs(sv_2mortal(newSVpv( mods->mod_bvalues[i]->bv_val, 0 )));
77                         }
78                 }
79
80                 PUTBACK;
81
82                 count = perl_call_method("modify", G_SCALAR);
83
84                 SPAGAIN;
85
86                 if (count != 1) {
87                         croak("Big trouble in back_search\n");
88                 }
89                                                          
90                 return_code = POPi;
91
92                 PUTBACK; FREETMPS; LEAVE;
93         }
94
95         ldap_pvt_thread_mutex_unlock( &perl_interpreter_mutex );
96
97         if( return_code != 0 ) {
98                 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
99                         NULL, NULL, NULL, NULL );
100
101         } else {
102                 send_ldap_result( conn, op, LDAP_SUCCESS,
103                         NULL, NULL, NULL, NULL );
104         }
105
106         Debug( LDAP_DEBUG_ANY, "Perl MODIFY\n", 0, 0, 0 );
107         return( 0 );
108 }
109