All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Typedefs | Functions | Variables
rlm_cache_memcached.c File Reference

memcached based cache. More...

#include <libmemcached/memcached.h>
#include <freeradius-devel/radiusd.h>
#include <freeradius-devel/modules.h>
#include <freeradius-devel/rad_assert.h>
#include "../../rlm_cache.h"
#include "../../serialize.h"
+ Include dependency graph for rlm_cache_memcached.c:

Go to the source code of this file.

Data Structures

struct  rlm_cache_memcached
 
struct  rlm_cache_memcached_handle
 

Typedefs

typedef struct
rlm_cache_memcached_handle 
rlm_cache_memcached_handle_t
 
typedef struct rlm_cache_memcached rlm_cache_memcached_t
 

Functions

static int _mod_conn_free (rlm_cache_memcached_handle_t *mandle)
 Free a connection handle. More...
 
static cache_status_t cache_entry_expire (UNUSED rlm_cache_config_t const *config, UNUSED void *driver_inst, REQUEST *request, void *handle, uint8_t const *key, size_t key_len)
 Call delete the cache entry from memcached. More...
 
static cache_status_t cache_entry_find (rlm_cache_entry_t **out, UNUSED rlm_cache_config_t const *config, UNUSED void *driver_inst, REQUEST *request, void *handle, uint8_t const *key, size_t key_len)
 Locate a cache entry in memcached. More...
 
static void cache_entry_free (rlm_cache_entry_t *c)
 Locate a cache entry in memcached. More...
 
static cache_status_t cache_entry_insert (UNUSED rlm_cache_config_t const *config, UNUSED void *driver_inst, REQUEST *request, void *handle, const rlm_cache_entry_t *c)
 Insert a new entry into the data store. More...
 
static void * mod_conn_create (TALLOC_CTX *ctx, void *instance, struct timeval const *timeout)
 Create a new memcached handle. More...
 
static int mod_conn_get (void **handle, UNUSED rlm_cache_config_t const *config, void *driver_inst, UNUSED REQUEST *request)
 Get a memcached handle. More...
 
static int mod_conn_reconnect (void **handle, UNUSED rlm_cache_config_t const *config, void *driver_inst, UNUSED REQUEST *request)
 Reconnect a memcached handle. More...
 
static void mod_conn_release (UNUSED rlm_cache_config_t const *config, void *driver_inst, UNUSED REQUEST *request, rlm_cache_handle_t *handle)
 Release a memcached handle. More...
 
static int mod_instantiate (CONF_SECTION *conf, rlm_cache_config_t const *config, void *driver_inst)
 Create a new rlm_cache_memcached instance. More...
 

Variables

static const CONF_PARSER driver_config []
 
cache_driver_t rlm_cache_memcached
 

Detailed Description

memcached based cache.

Id:
c93bb687087dae23bde27bdcafeb68e0aa1bf200

Definition in file rlm_cache_memcached.c.


Data Structure Documentation

struct rlm_cache_memcached

Definition at line 37 of file rlm_cache_memcached.c.

+ Collaboration diagram for rlm_cache_memcached:
Data Fields
char const * options Connection options.
fr_connection_pool_t * pool
struct rlm_cache_memcached_handle

Definition at line 33 of file rlm_cache_memcached.c.

Data Fields
memcached_st * handle

Typedef Documentation

Function Documentation

static int _mod_conn_free ( rlm_cache_memcached_handle_t mandle)
static

Free a connection handle.

Parameters
mandleto free.

Definition at line 51 of file rlm_cache_memcached.c.

+ Here is the caller graph for this function:

static cache_status_t cache_entry_expire ( UNUSED rlm_cache_config_t const *  config,
UNUSED void *  driver_inst,
REQUEST request,
void *  handle,
uint8_t const *  key,
size_t  key_len 
)
static

Call delete the cache entry from memcached.

Note
This callback is not optional.
Parameters
[in]configfor this instance of the rlm_cache module.
[in]driver_instDriver specific instance data.
[in]requestThe current request.
[in]handlethe driver gave us when we called cache_acquire_t, or NULL if no cache_acquire_t callback was provided.
[in]keyof entry to expire.
[in]key_lenthe length of the key string.
Returns

Definition at line 242 of file rlm_cache_memcached.c.

static cache_status_t cache_entry_find ( rlm_cache_entry_t **  out,
UNUSED rlm_cache_config_t const *  config,
UNUSED void *  driver_inst,
REQUEST request,
void *  handle,
uint8_t const *  key,
size_t  key_len 
)
static

Locate a cache entry in memcached.

If a cache entry is found, but the cache entry needs to be deserialized, the driver is expected to allocate an appropriately sized rlm_cache_entry_t, perform the deserialisation, and write a pointer to the new entry to out, returning CACHE_OK.

If the rlm_cache_handle_t is inviable, the driver should return CACHE_RECONNECT, to have it reinitialised/reconnected.

Parameters
[out]outWhere to write a pointer to the retrieved entry (if there was one).
[in]configfor this instance of the rlm_cache module.
[in]driver_instDriver specific instance data.
[in]requestThe current request.
[in]handlethe driver gave us when we called cache_acquire_t, or NULL if no cache_acquire_t callback was provided.
[in]keyto use to lookup cache entry
[in]key_lenthe length of the key string.
Returns

Definition at line 160 of file rlm_cache_memcached.c.

+ Here is the call graph for this function:

static void cache_entry_free ( rlm_cache_entry_t c)
static

Locate a cache entry in memcached.

Note
This callback is optional, but the driver assume responsibility for freeing the cache_entry_t on cache_entry_expire_t.

If the driver does not need to keep a local copy of the cache entry, it should provide a callback to free the memory previously allocated for the cache entry by cache_entry_find_t or by rlm_cache.

Parameters
centry to free.

Definition at line 151 of file rlm_cache_memcached.c.

static cache_status_t cache_entry_insert ( UNUSED rlm_cache_config_t const *  config,
UNUSED void *  driver_inst,
REQUEST request,
void *  handle,
const rlm_cache_entry_t c 
)
static

Insert a new entry into the data store.

Serialize (if necessary) the entry passed to us, and write it to the cache with the key c->key.

The cache entry should not be freed by the driver, irrespective of success or failure. If the entry needs to be freed after insertion because a local copy should not be kept, the driver should provide a cache_entry_free_t callback.

If the rlm_cache_handle_t is inviable, the driver should return CACHE_RECONNECT, to have it reinitialised/reconnected.

Note
This callback is not optional.
This callback must overwrite existing cache entries on insert.
Parameters
configfor this instance of the rlm_cache module.
driver_instDriver specific instance data.
requestThe current request.
handlethe driver gave us when we called cache_acquire_t, or NULL if no cache_acquire_t callback was provided.
cto insert.
Returns

Definition at line 205 of file rlm_cache_memcached.c.

+ Here is the call graph for this function:

static void* mod_conn_create ( TALLOC_CTX *  ctx,
void *  instance,
struct timeval const *  timeout 
)
static

Create a new memcached handle.

Definition at line 61 of file rlm_cache_memcached.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int mod_conn_get ( void **  handle,
UNUSED rlm_cache_config_t const *  config,
void *  driver_inst,
UNUSED REQUEST request 
)
static

Get a memcached handle.

Note
This callback is optional. If it's not provided the handle argument to other callbacks will be NULL.
Parameters
[out]handleWhere to write pointer to handle to access the cache with.
[in]configfor this instance of the rlm_cache module.
[in]driver_instDriver specific instance data.
[in]requestThe current request.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 267 of file rlm_cache_memcached.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int mod_conn_reconnect ( void **  handle,
UNUSED rlm_cache_config_t const *  config,
void *  driver_inst,
UNUSED REQUEST request 
)
static

Reconnect a memcached handle.

Note
This callback is optional.
Parameters
[in,out]handleto reinitialise/reconnect.
[in]configfor this instance of the rlm_cache module.
[in]driver_instDriver specific instance data.
[in]requestThe current request.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 301 of file rlm_cache_memcached.c.

+ Here is the call graph for this function:

static void mod_conn_release ( UNUSED rlm_cache_config_t const *  config,
void *  driver_inst,
UNUSED REQUEST request,
rlm_cache_handle_t handle 
)
static

Release a memcached handle.

Note
This callback is optional.
Parameters
[in]configfor this instance of the rlm_cache module.
[in]driver_instDriver specific instance data.
[in]requestThe current request.
[in]handleto release.

Definition at line 289 of file rlm_cache_memcached.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int mod_instantiate ( CONF_SECTION conf,
rlm_cache_config_t const *  config,
void *  driver_inst 
)
static

Create a new rlm_cache_memcached instance.

Function to handle any driver specific instantiation.

Parameters
confsection holding driver specific CONF_PAIR (s).
configof the rlm_cache module. Should not be modified.
driver_instA uint8_t array of inst_size if inst_size > 0, else NULL. Drivers should add their own cleanup function to this chunk using talloc_set_destructor.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 103 of file rlm_cache_memcached.c.

+ Here is the call graph for this function:

Variable Documentation

const CONF_PARSER driver_config[]
static
Initial value:
= {
{ FR_CONF_OFFSET("options", PW_TYPE_STRING | PW_TYPE_REQUIRED, rlm_cache_memcached_t, options), .dflt = "--SERVER=localhost" },
}
#define CONF_PARSER_TERMINATOR
Definition: conffile.h:289
#define FR_CONF_OFFSET(_n, _t, _s, _f)
Definition: conffile.h:168
#define PW_TYPE_REQUIRED
Error out if no matching CONF_PAIR is found, and no dflt value is set.
Definition: conffile.h:200
String of printable characters.
Definition: radius.h:33

Definition at line 42 of file rlm_cache_memcached.c.

Initial value:
= {
.name = "rlm_cache_memcached",
.instantiate = mod_instantiate,
.inst_size = sizeof(rlm_cache_memcached_t),
.insert = cache_entry_insert,
.expire = cache_entry_expire,
.acquire = mod_conn_get,
.release = mod_conn_release,
.reconnect = mod_conn_reconnect
}
static void cache_entry_free(rlm_cache_entry_t *c)
Locate a cache entry in memcached.
static cache_status_t cache_entry_expire(UNUSED rlm_cache_config_t const *config, UNUSED void *driver_inst, REQUEST *request, void *handle, uint8_t const *key, size_t key_len)
Call delete the cache entry from memcached.
static cache_status_t cache_entry_find(rlm_cache_entry_t **out, UNUSED rlm_cache_config_t const *config, UNUSED void *driver_inst, REQUEST *request, void *handle, uint8_t const *key, size_t key_len)
Locate a cache entry in memcached.
struct rlm_cache_memcached rlm_cache_memcached_t
static int mod_instantiate(CONF_SECTION *conf, rlm_cache_config_t const *config, void *driver_inst)
Create a new rlm_cache_memcached instance.
static int mod_conn_reconnect(void **handle, UNUSED rlm_cache_config_t const *config, void *driver_inst, UNUSED REQUEST *request)
Reconnect a memcached handle.
static int mod_conn_get(void **handle, UNUSED rlm_cache_config_t const *config, void *driver_inst, UNUSED REQUEST *request)
Get a memcached handle.
static void mod_conn_release(UNUSED rlm_cache_config_t const *config, void *driver_inst, UNUSED REQUEST *request, rlm_cache_handle_t *handle)
Release a memcached handle.
static cache_status_t cache_entry_insert(UNUSED rlm_cache_config_t const *config, UNUSED void *driver_inst, REQUEST *request, void *handle, const rlm_cache_entry_t *c)
Insert a new entry into the data store.

Definition at line 318 of file rlm_cache_memcached.c.