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