/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
- * Copyright 1999-2005 The OpenLDAP Foundation.
+ * Copyright 1999-2007 The OpenLDAP Foundation.
* Portions Copyright 2001-2003 Pierangelo Masarati.
* Portions Copyright 1999-2003 Howard Chu.
* All rights reserved.
{
metadncacheentry_t tmp_entry,
*entry;
- time_t curr_time;
int target = META_TARGET_NONE;
- assert( cache );
- assert( ndn );
+ assert( cache != NULL );
+ assert( ndn != NULL );
tmp_entry.dn = *ndn;
ldap_pvt_thread_mutex_lock( &cache->mutex );
target = entry->target;
} else {
-
- /*
- * Need mutex?
- */
- curr_time = time( NULL );
-
- if ( entry->lastupdated+cache->ttl > curr_time ) {
+ if ( entry->lastupdated+cache->ttl > slap_get_time() ) {
target = entry->target;
}
}
time_t curr_time = 0L;
int err = 0;
- assert( cache );
- assert( ndn );
+ assert( cache != NULL );
+ assert( ndn != NULL );
/*
* if cache->ttl < 0, cache never expires;
* else, cache is used with ttl
*/
if ( cache->ttl > 0 ) {
-
- /*
- * Need mutex?
- */
- curr_time = time( NULL );
+ curr_time = slap_get_time();
}
tmp_entry.dn = *ndn;
} else {
entry = ch_malloc( sizeof( metadncacheentry_t ) + ndn->bv_len + 1 );
if ( entry == NULL ) {
- ldap_pvt_thread_mutex_unlock( &cache->mutex );
- return -1;
+ err = -1;
+ goto error_return;
}
+ entry->dn.bv_len = ndn->bv_len;
entry->dn.bv_val = (char *)&entry[ 1 ];
- AC_MEMCPY( entry->dn.bv_val, ndn->bv_val, ndn->bv_len + 1 );
+ AC_MEMCPY( entry->dn.bv_val, ndn->bv_val, ndn->bv_len );
+ entry->dn.bv_val[ ndn->bv_len ] = '\0';
+
entry->target = target;
entry->lastupdated = curr_time;
err = avl_insert( &cache->tree, ( caddr_t )entry,
meta_dncache_cmp, meta_dncache_dup );
}
+
+error_return:;
ldap_pvt_thread_mutex_unlock( &cache->mutex );
return err;
metadncacheentry_t *entry,
tmp_entry;
- assert( cache );
- assert( ndn );
+ assert( cache != NULL );
+ assert( ndn != NULL );
tmp_entry.dn = *ndn;