Back to index

openldap  2.4.31
Classes | Typedefs | Functions
dncache.c File Reference
#include "portable.h"
#include <stdio.h>
#include <ac/string.h>
#include "slap.h"
#include "../back-ldap/back-ldap.h"
#include "back-meta.h"

Go to the source code of this file.

Classes

struct  metadncacheentry_t

Typedefs

typedef struct metadncacheentry_t metadncacheentry_t

Functions

int meta_dncache_cmp (const void *c1, const void *c2)
int meta_dncache_dup (void *c1, void *c2)
int meta_dncache_get_target (metadncache_t *cache, struct berval *ndn)
int meta_dncache_update_entry (metadncache_t *cache, struct berval *ndn, int target)
int meta_dncache_delete_entry (metadncache_t *cache, struct berval *ndn)
void meta_dncache_free (void *e)

Class Documentation

struct metadncacheentry_t

Definition at line 36 of file dncache.c.

Class Members
time_t lastupdated
int target

Typedef Documentation


Function Documentation

int meta_dncache_cmp ( const void c1,
const void c2 
)

Definition at line 51 of file dncache.c.

{
       metadncacheentry_t   *cc1 = ( metadncacheentry_t * )c1;
       metadncacheentry_t   *cc2 = ( metadncacheentry_t * )c2;

       /*
        * case sensitive, because the dn MUST be normalized
        */
       return ber_bvcmp( &cc1->dn, &cc2->dn);
}

Here is the caller graph for this function:

int meta_dncache_delete_entry ( metadncache_t cache,
struct berval ndn 
)

Definition at line 199 of file dncache.c.

{
       metadncacheentry_t   *entry,
                            tmp_entry;

       assert( cache != NULL );
       assert( ndn != NULL );

       tmp_entry.dn = *ndn;

       ldap_pvt_thread_mutex_lock( &cache->mutex );
       entry = avl_delete( &cache->tree, ( caddr_t )&tmp_entry,
                     meta_dncache_cmp );
       ldap_pvt_thread_mutex_unlock( &cache->mutex );

       if ( entry != NULL ) {
              meta_dncache_free( ( void * )entry );
       }

       return 0;
}

Here is the call graph for this function:

int meta_dncache_dup ( void c1,
void c2 
)

Definition at line 71 of file dncache.c.

{
       metadncacheentry_t   *cc1 = ( metadncacheentry_t * )c1;
       metadncacheentry_t   *cc2 = ( metadncacheentry_t * )c2;
       
       /*
        * case sensitive, because the dn MUST be normalized
        */
       return ( ber_bvcmp( &cc1->dn, &cc2->dn ) == 0 ) ? -1 : 0;
}

Here is the caller graph for this function:

Definition at line 230 of file dncache.c.

{
       free( e );
}

Here is the caller graph for this function:

int meta_dncache_get_target ( metadncache_t cache,
struct berval ndn 
)

Definition at line 91 of file dncache.c.

{
       metadncacheentry_t   tmp_entry,
                            *entry;
       int                  target = META_TARGET_NONE;

       assert( cache != NULL );
       assert( ndn != NULL );

       tmp_entry.dn = *ndn;
       ldap_pvt_thread_mutex_lock( &cache->mutex );
       entry = ( metadncacheentry_t * )avl_find( cache->tree,
                     ( caddr_t )&tmp_entry, meta_dncache_cmp );

       if ( entry != NULL ) {
              
              /*
               * if cache->ttl < 0, cache never expires;
               * if cache->ttl = 0 no cache is used; shouldn't get here
               * else, cache is used with ttl
               */
              if ( cache->ttl < 0 ) { 
                     target = entry->target;

              } else {
                     if ( entry->lastupdated+cache->ttl > slap_get_time() ) {
                            target = entry->target;
                     }
              }
       }
       ldap_pvt_thread_mutex_unlock( &cache->mutex );

       return target;
}

Here is the call graph for this function:

int meta_dncache_update_entry ( metadncache_t cache,
struct berval ndn,
int  target 
)

Definition at line 135 of file dncache.c.

{
       metadncacheentry_t   *entry,
                            tmp_entry;
       time_t               curr_time = 0L;
       int                  err = 0;

       assert( cache != NULL );
       assert( ndn != NULL );

       /*
        * if cache->ttl < 0, cache never expires;
        * if cache->ttl = 0 no cache is used; shouldn't get here
        * else, cache is used with ttl
        */
       if ( cache->ttl > 0 ) {
              curr_time = slap_get_time();
       }

       tmp_entry.dn = *ndn;

       ldap_pvt_thread_mutex_lock( &cache->mutex );
       entry = ( metadncacheentry_t * )avl_find( cache->tree,
                     ( caddr_t )&tmp_entry, meta_dncache_cmp );

       if ( entry != NULL ) {
              entry->target = target;
              entry->lastupdated = curr_time;

       } else {
              entry = ch_malloc( sizeof( metadncacheentry_t ) + ndn->bv_len + 1 );
              if ( entry == NULL ) {
                     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 );
              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;
}

Here is the call graph for this function:

Here is the caller graph for this function: