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"
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... | |
Utillity functions used in the module.
Definition in file mod.c.
|
static |
Handle client value processing for client_map_section()
out | Character output |
cp | Configuration pair |
data | The client data |
Definition at line 545 of file mod.c.
|
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.
chandle | The connection handle to destroy. |
Definition at line 45 of file mod.c.
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().
name | The character name of the requested attribute. |
map | The JSON object map to use for the lookup. |
buf | The buffer where the given element will be stored if found. |
Definition at line 225 of file mod.c.
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.
conf | Configuration section. |
instance | The module instance. |
Definition at line 150 of file mod.c.
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.
instance | The module instance (currently unused). |
handle | The connection handle. |
Definition at line 121 of file mod.c.
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.
ctx | The connection parent context. |
instance | The module instance. |
timeout | Maximum time to establish the connection. |
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.
json | JSON object representation of an accounting document. |
vps | The value pairs associated with the current accounting request. |
Definition at line 476 of file mod.c.
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:
json | The JSON object representation of the user documnent. |
section | The pair section ("config" or "reply"). |
request | The request to which the generated pairs should be added. |
Definition at line 281 of file mod.c.
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.
inst | The module instance. |
tmpl | Default values for new clients. |
map | The client attribute configuration section. |
Definition at line 577 of file mod.c.
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.
request | The request object. |
vp | The value pair to convert. |
Definition at line 382 of file mod.c.