Back to index

openldap  2.4.31
entry.c
Go to the documentation of this file.
00001 /* entry.c - monitor backend entry handling routines */
00002 /* $OpenLDAP$ */
00003 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00004  *
00005  * Copyright 2001-2012 The OpenLDAP Foundation.
00006  * Portions Copyright 2001-2003 Pierangelo Masarati.
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 /* ACKNOWLEDGEMENTS:
00018  * This work was initially developed by Pierangelo Masarati for inclusion
00019  * in OpenLDAP Software.
00020  */
00021 
00022 #include "portable.h"
00023 
00024 #include <slap.h>
00025 #include "back-monitor.h"
00026 
00027 int
00028 monitor_entry_update(
00029        Operation            *op,
00030        SlapReply            *rs,
00031        Entry                *e
00032 )
00033 {
00034        monitor_info_t       *mi = ( monitor_info_t * )op->o_bd->be_private;
00035        monitor_entry_t *mp;
00036 
00037        int           rc = SLAP_CB_CONTINUE;
00038 
00039        assert( mi != NULL );
00040        assert( e != NULL );
00041        assert( e->e_private != NULL );
00042 
00043        mp = ( monitor_entry_t * )e->e_private;
00044 
00045        if ( mp->mp_cb ) {
00046               struct monitor_callback_t   *mc;
00047 
00048               for ( mc = mp->mp_cb; mc; mc = mc->mc_next ) {
00049                      if ( mc->mc_update ) {
00050                             rc = mc->mc_update( op, rs, e, mc->mc_private );
00051                             if ( rc != SLAP_CB_CONTINUE ) {
00052                                    break;
00053                             }
00054                      }
00055               }
00056        }
00057 
00058        if ( rc == SLAP_CB_CONTINUE && mp->mp_info && mp->mp_info->mss_update ) {
00059               rc = mp->mp_info->mss_update( op, rs, e );
00060        }
00061 
00062        if ( rc == SLAP_CB_CONTINUE ) {
00063               rc = LDAP_SUCCESS;
00064        }
00065 
00066        return rc;
00067 }
00068 
00069 int
00070 monitor_entry_create(
00071        Operation            *op,
00072        SlapReply            *rs,
00073        struct berval        *ndn,
00074        Entry                *e_parent,
00075        Entry                **ep )
00076 {
00077        monitor_info_t       *mi = ( monitor_info_t * )op->o_bd->be_private;
00078        monitor_entry_t *mp;
00079 
00080        int           rc = SLAP_CB_CONTINUE;
00081 
00082        assert( mi != NULL );
00083        assert( e_parent != NULL );
00084        assert( e_parent->e_private != NULL );
00085        assert( ep != NULL );
00086 
00087        mp = ( monitor_entry_t * )e_parent->e_private;
00088 
00089        if ( mp->mp_info && mp->mp_info->mss_create ) {
00090               rc = mp->mp_info->mss_create( op, rs, ndn, e_parent, ep );
00091        }
00092 
00093        if ( rc == SLAP_CB_CONTINUE ) {
00094               rc = LDAP_SUCCESS;
00095        }
00096        
00097        return rc;
00098 }
00099 
00100 int
00101 monitor_entry_modify(
00102        Operation            *op,
00103        SlapReply            *rs,
00104        Entry                *e
00105 )
00106 {
00107        monitor_info_t       *mi = ( monitor_info_t * )op->o_bd->be_private;
00108        monitor_entry_t *mp;
00109 
00110        int           rc = SLAP_CB_CONTINUE;
00111 
00112        assert( mi != NULL );
00113        assert( e != NULL );
00114        assert( e->e_private != NULL );
00115 
00116        mp = ( monitor_entry_t * )e->e_private;
00117 
00118        if ( mp->mp_cb ) {
00119               struct monitor_callback_t   *mc;
00120 
00121               for ( mc = mp->mp_cb; mc; mc = mc->mc_next ) {
00122                      if ( mc->mc_modify ) {
00123                             rc = mc->mc_modify( op, rs, e, mc->mc_private );
00124                             if ( rc != SLAP_CB_CONTINUE ) {
00125                                    break;
00126                             }
00127                      }
00128               }
00129        }
00130 
00131        if ( rc == SLAP_CB_CONTINUE && mp->mp_info && mp->mp_info->mss_modify ) {
00132               rc = mp->mp_info->mss_modify( op, rs, e );
00133        }
00134 
00135        if ( rc == SLAP_CB_CONTINUE ) {
00136               rc = LDAP_SUCCESS;
00137        }
00138 
00139        return rc;
00140 }
00141 
00142 int
00143 monitor_entry_test_flags(
00144        monitor_entry_t             *mp,
00145        int                  cond
00146 )
00147 {
00148        assert( mp != NULL );
00149 
00150        return( ( mp->mp_flags & cond ) || ( mp->mp_info->mss_flags & cond ) );
00151 }
00152 
00153 monitor_entry_t *
00154 monitor_entrypriv_create( void )
00155 {
00156        monitor_entry_t      *mp;
00157 
00158        mp = ( monitor_entry_t * )ch_calloc( sizeof( monitor_entry_t ), 1 );
00159 
00160        mp->mp_next = NULL;
00161        mp->mp_children = NULL;
00162        mp->mp_info = NULL;
00163        mp->mp_flags = MONITOR_F_NONE;
00164        mp->mp_cb = NULL;
00165 
00166        ldap_pvt_thread_mutex_init( &mp->mp_mutex );
00167 
00168        return mp;
00169 }
00170 
00171 Entry *
00172 monitor_entry_stub(
00173        struct berval *pdn,
00174        struct berval *pndn,
00175        struct berval *rdn,
00176        ObjectClass *oc,
00177        monitor_info_t       *mi,
00178        struct berval *create,
00179        struct berval *modify
00180 )
00181 {
00182        AttributeDescription *nad = NULL;
00183        Entry *e;
00184        struct berval nat;
00185        char *ptr;
00186        const char *text;
00187        int rc;
00188 
00189        nat = *rdn;
00190        ptr = strchr( nat.bv_val, '=' );
00191        nat.bv_len = ptr - nat.bv_val;
00192        rc = slap_bv2ad( &nat, &nad, &text );
00193        if ( rc )
00194               return NULL;
00195 
00196        e = entry_alloc();
00197        if ( e ) {
00198               struct berval nrdn;
00199 
00200               rdnNormalize( 0, NULL, NULL, rdn, &nrdn, NULL );
00201               build_new_dn( &e->e_name, pdn, rdn, NULL );
00202               build_new_dn( &e->e_nname, pndn, &nrdn, NULL );
00203               ber_memfree( nrdn.bv_val );
00204               nat.bv_val = ptr + 1;
00205               nat.bv_len = rdn->bv_len - ( nat.bv_val - rdn->bv_val );
00206               attr_merge_normalize_one( e, slap_schema.si_ad_objectClass,
00207                      &oc->soc_cname, NULL );
00208               attr_merge_normalize_one( e, slap_schema.si_ad_structuralObjectClass,
00209                      &oc->soc_cname, NULL );
00210               attr_merge_normalize_one( e, nad, &nat, NULL );
00211               attr_merge_one( e, slap_schema.si_ad_creatorsName, &mi->mi_creatorsName,
00212                      &mi->mi_ncreatorsName );
00213               attr_merge_one( e, slap_schema.si_ad_modifiersName, &mi->mi_creatorsName,
00214                      &mi->mi_ncreatorsName );
00215               attr_merge_normalize_one( e, slap_schema.si_ad_createTimestamp,
00216                      create ? create : &mi->mi_startTime, NULL );
00217               attr_merge_normalize_one( e, slap_schema.si_ad_modifyTimestamp,
00218                      modify ? modify : &mi->mi_startTime, NULL );
00219        }
00220        return e;
00221 }