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