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

Utillity functions used in the module. More...

#include <freeradius-devel/radiusd.h>
#include <libcouchbase/couchbase.h>
#include "../rlm_json/json.h"
#include "mod.h"
#include "couchbase.h"
+ Include dependency graph for mod.c:

Go to the source code of this file.

Functions

static int _get_client_value (char **out, CONF_PAIR const *cp, void *data)
 Handle client value processing for client_map_section() More...
 
static int _mod_conn_free (rlm_couchbase_handle_t *chandle)
 Delete a conneciton pool handle and free related resources. More...
 
int mod_attribute_to_element (const char *name, json_object *map, void *buf)
 Map attributes to JSON element names. More...
 
int mod_build_attribute_element_map (CONF_SECTION *conf, void *instance)
 Build a JSON object map from the configuration "map" section. More...
 
int mod_conn_alive (UNUSED void *instance, void *handle)
 Check the health of a connection handle. More...
 
void * mod_conn_create (TALLOC_CTX *ctx, void *instance, struct timeval const *timeout)
 Create a new connection pool handle. More...
 
int mod_ensure_start_timestamp (json_object *json, VALUE_PAIR *vps)
 Ensure accounting documents always contain a valid timestamp. More...
 
void * mod_json_object_to_value_pairs (json_object *json, const char *section, REQUEST *request)
 Build value pairs from the passed JSON object and add to the request. More...
 
int mod_load_client_documents (rlm_couchbase_t *inst, CONF_SECTION *tmpl, CONF_SECTION *map)
 Load client entries from Couchbase client documents on startup. More...
 
json_object * mod_value_pair_to_json_object (REQUEST *request, VALUE_PAIR *vp)
 Convert value pairs to json objects. More...
 

Detailed Description

Utillity functions used in the module.

Id:
e1da2bba2eeec286e091e0a9f24be2c7fa151df3
Author
Aaron Hurt ahurt.nosp@m.@anb.nosp@m.cs.co.nosp@m.m

Definition in file mod.c.

Function Documentation

static int _get_client_value ( char **  out,
CONF_PAIR const *  cp,
void *  data 
)
static

Handle client value processing for client_map_section()

Parameters
outCharacter output
cpConfiguration pair
dataThe client data
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 545 of file mod.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int _mod_conn_free ( rlm_couchbase_handle_t chandle)
static

Delete a conneciton pool handle and free related resources.

Destroys the underlying Couchbase connection handle freeing any related resources and closes the socket connection.

Parameters
chandleThe connection handle to destroy.
Returns
0.

Definition at line 45 of file mod.c.

+ Here is the caller graph for this function:

int mod_attribute_to_element ( const char *  name,
json_object *  map,
void *  buf 
)

Map attributes to JSON element names.

Attempt to map the passed attribute name to the configured JSON element name using the JSON object map mod_build_attribute_element_map().

Parameters
nameThe character name of the requested attribute.
mapThe JSON object map to use for the lookup.
bufThe buffer where the given element will be stored if found.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 225 of file mod.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int mod_build_attribute_element_map ( CONF_SECTION conf,
void *  instance 
)

Build a JSON object map from the configuration "map" section.

Parse the "map" section from the module configuration file and store this as a JSON object (key/value list) in the module instance. This map will be used to lookup and map attributes for all incoming accounting requests.

Parameters
confConfiguration section.
instanceThe module instance.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 150 of file mod.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int mod_conn_alive ( UNUSED void *  instance,
void *  handle 
)

Check the health of a connection handle.

Attempt to determing the state of the Couchbase connection by requesting a cluster statistics report. Mark the connection as failed if the request returns anything other than success.

Parameters
instanceThe module instance (currently unused).
handleThe connection handle.
Returns
  • 0 on success (alive).
  • -1 on failure (unavailable).

Definition at line 121 of file mod.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Create a new connection pool handle.

Create a new connection to Couchbase within the pool and initialize information associated with the connection instance.

Parameters
ctxThe connection parent context.
instanceThe module instance.
timeoutMaximum time to establish the connection.
Returns
  • New connection handle.
  • NULL on error.

Definition at line 68 of file mod.c.

int mod_ensure_start_timestamp ( json_object *  json,
VALUE_PAIR vps 
)

Ensure accounting documents always contain a valid timestamp.

Inspect the given JSON object representation of an accounting document fetched from Couchbase and ensuse it contains a valid (non NULL) timestamp value.

Parameters
jsonJSON object representation of an accounting document.
vpsThe value pairs associated with the current accounting request.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 476 of file mod.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void* mod_json_object_to_value_pairs ( json_object *  json,
const char *  section,
REQUEST request 
)

Build value pairs from the passed JSON object and add to the request.

Parse the passed JSON object and create value pairs that will be injected into the given request for authorization.

Example JSON document structure:

{
"docType": "raduser",
"userName": "test",
"config": {
"SHA-Password": {
"value": "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3",
"op": ":="
}
},
"reply": {
"Reply-Message": {
"value": "Hidey Ho!",
"op": "="
}
}
}
Parameters
jsonThe JSON object representation of the user documnent.
sectionThe pair section ("config" or "reply").
requestThe request to which the generated pairs should be added.

Definition at line 281 of file mod.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int mod_load_client_documents ( rlm_couchbase_t inst,
CONF_SECTION tmpl,
CONF_SECTION map 
)

Load client entries from Couchbase client documents on startup.

This function executes the view defined in the module configuration and loops through all returned rows. The view is called with "stale=false" to ensure the most accurate data available when the view is called. This will force an index rebuild on this design document in Couchbase. However, since this function is only run once at sever startup this should not be a concern.

Parameters
instThe module instance.
tmplDefault values for new clients.
mapThe client attribute configuration section.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 577 of file mod.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

json_object* mod_value_pair_to_json_object ( REQUEST request,
VALUE_PAIR vp 
)

Convert value pairs to json objects.

Take the passed value pair and convert it to a json-c JSON object. This code is heavily based on the fr_json_from_pair() function from src/lib/print.c.

Parameters
requestThe request object.
vpThe value pair to convert.
Returns
A JSON object.

Definition at line 382 of file mod.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function: