]> git.sur5r.net Git - openldap/blob - servers/slapd/back-perl/modify.c
Implemented the open, init functions correctly
[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
49                 for (; modlist != NULL; modlist = modlist->ml_next ) {
50                         LDAPMod *mods = &modlist->ml_mod;
51
52                         switch ( mods->mod_op & ~LDAP_MOD_BVALUES ) {
53                         case LDAP_MOD_ADD:
54                                 XPUSHs(sv_2mortal(newSVpv("ADD", 0 )));
55                                 break;
56                                 
57                         case LDAP_MOD_DELETE:
58                                 XPUSHs(sv_2mortal(newSVpv("DELETE", 0 )));
59                                 break;
60                                 
61                         case LDAP_MOD_REPLACE:
62                                 XPUSHs(sv_2mortal(newSVpv("REPLACE", 0 )));
63                                 break;
64                         }
65
66
67                         XPUSHs(sv_2mortal(newSVpv( mods->mod_type, 0 )));
68
69                         for ( i = 0;
70                                 mods->mod_bvalues != NULL && mods->mod_bvalues[i] != NULL;
71                                 i++ )
72                         {
73                                 XPUSHs(sv_2mortal(newSVpv( mods->mod_bvalues[i]->bv_val, 0 )));
74                         }
75                 }
76
77                 PUTBACK;
78
79                 count = perl_call_method("modify", G_SCALAR);
80
81                 SPAGAIN;
82
83                 if (count != 1) {
84                         croak("Big trouble in back_search\n");
85                 }
86                                                          
87                 return_code = POPi;
88
89                 PUTBACK; FREETMPS; LEAVE;
90         }
91
92         ldap_pvt_thread_mutex_unlock( &perl_interpreter_mutex );
93
94         if( return_code != 0 ) {
95                 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
96
97         } else {
98                 send_ldap_result( conn, op, LDAP_SUCCESS, "", "" );
99         }
100
101         Debug( LDAP_DEBUG_ANY, "Perl MODIFY\n", 0, 0, 0 );
102         return( 0 );
103 }
104