Back to index

openldap  2.4.31
modify.c
Go to the documentation of this file.
00001 /* $OpenLDAP$ */
00002 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00003  *
00004  * Copyright 1999-2012 The OpenLDAP Foundation.
00005  * Portions Copyright 1999 John C. Quillan.
00006  * Portions Copyright 2002 myinternet Limited.
00007  * All rights reserved.
00008  *
00009  * Redistribution and use in source and binary forms, with or without
00010  * modification, are permitted only as authorized by the OpenLDAP
00011  * Public License.
00012  *
00013  * A copy of this license is available in file LICENSE in the
00014  * top-level directory of the distribution or, alternatively, at
00015  * <http://www.OpenLDAP.org/license.html>.
00016  */
00017 
00018 #include "perl_back.h"
00019 #include <ac/string.h>
00020 
00021 int
00022 perl_back_modify(
00023        Operation     *op,
00024        SlapReply     *rs )
00025 {
00026        PerlBackend *perl_back = (PerlBackend *)op->o_bd->be_private;
00027        Modifications *modlist = op->orm_modlist;
00028        int count;
00029        int i;
00030 
00031        PERL_SET_CONTEXT( PERL_INTERPRETER );
00032        ldap_pvt_thread_mutex_lock( &perl_interpreter_mutex );  
00033 
00034        {
00035               dSP; ENTER; SAVETMPS;
00036               
00037               PUSHMARK(sp);
00038               XPUSHs( perl_back->pb_obj_ref );
00039               XPUSHs(sv_2mortal(newSVpv( op->o_req_dn.bv_val , 0)));
00040 
00041               for (; modlist != NULL; modlist = modlist->sml_next ) {
00042                      Modification *mods = &modlist->sml_mod;
00043 
00044                      switch ( mods->sm_op & ~LDAP_MOD_BVALUES ) {
00045                      case LDAP_MOD_ADD:
00046                             XPUSHs(sv_2mortal(newSVpv("ADD", STRLENOF("ADD") )));
00047                             break;
00048                             
00049                      case LDAP_MOD_DELETE:
00050                             XPUSHs(sv_2mortal(newSVpv("DELETE", STRLENOF("DELETE") )));
00051                             break;
00052                             
00053                      case LDAP_MOD_REPLACE:
00054                             XPUSHs(sv_2mortal(newSVpv("REPLACE", STRLENOF("REPLACE") )));
00055                             break;
00056                      }
00057 
00058                      
00059                      XPUSHs(sv_2mortal(newSVpv( mods->sm_desc->ad_cname.bv_val,
00060                             mods->sm_desc->ad_cname.bv_len )));
00061 
00062                      for ( i = 0;
00063                             mods->sm_values != NULL && mods->sm_values[i].bv_val != NULL;
00064                             i++ )
00065                      {
00066                             XPUSHs(sv_2mortal(newSVpv( mods->sm_values[i].bv_val, mods->sm_values[i].bv_len )));
00067                      }
00068 
00069                      /* Fix delete attrib without value. */
00070                      if ( i == 0) {
00071                             XPUSHs(sv_newmortal());
00072                      }
00073               }
00074 
00075               PUTBACK;
00076 
00077               count = call_method("modify", G_SCALAR);
00078 
00079               SPAGAIN;
00080 
00081               if (count != 1) {
00082                      croak("Big trouble in back_modify\n");
00083               }
00084                                                   
00085               rs->sr_err = POPi;
00086 
00087               PUTBACK; FREETMPS; LEAVE;
00088        }
00089 
00090        ldap_pvt_thread_mutex_unlock( &perl_interpreter_mutex );
00091 
00092        send_ldap_result( op, rs );
00093 
00094        Debug( LDAP_DEBUG_ANY, "Perl MODIFY\n", 0, 0, 0 );
00095        return( 0 );
00096 }
00097