The FreeRADIUS server
$Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
|
Utility functions used in the module. More...
#include <freeradius-devel/json/base.h>
#include <freeradius-devel/server/base.h>
#include <freeradius-devel/server/map.h>
#include "mod.h"
#include "couchbase.h"
Go to the source code of this file.
Macros | |
#define | LOG_PREFIX "couchbase" |
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 connection 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_api_opts (CONF_SECTION *conf, rlm_couchbase_t *inst) |
Build a couchbase_opts_t structure from the configuration "couchbase_api" list. More... | |
int | mod_build_attribute_element_map (CONF_SECTION *conf, rlm_couchbase_t *inst) |
Build a JSON object map from the configuration "map" list. More... | |
int | mod_conn_alive (UNUSED void *opaque, void *connection) |
Check the health of a connection handle. More... | |
void * | mod_conn_create (TALLOC_CTX *ctx, void *instance, fr_time_delta_t timeout) |
Create a new connection pool handle. More... | |
int | mod_ensure_start_timestamp (json_object *json, fr_pair_list_t *vps) |
Ensure accounting documents always contain a valid timestamp. More... | |
int | mod_free_api_opts (rlm_couchbase_t *inst) |
Delete a object built by mod_build_api_opts() More... | |
int | mod_json_object_to_map (TALLOC_CTX *ctx, fr_dcursor_t *out, request_t *request, json_object *json, fr_dict_attr_t const *list) |
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_t *request, fr_pair_t *vp) |
Convert value pairs to json objects. More... | |
Utility 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 674 of file mod.c.
|
static |
Delete a connection 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 311 of file mod.c.
int mod_build_api_opts | ( | CONF_SECTION * | conf, |
rlm_couchbase_t * | inst | ||
) |
Build a couchbase_opts_t structure from the configuration "couchbase_api" list.
Parse the "couchbase_api" list from the module configuration file and store this as a couchbase_opts_t object (key/value list).
conf | Configuration list. |
inst | The module instance. |
Definition at line 93 of file mod.c.
int mod_build_attribute_element_map | ( | CONF_SECTION * | conf, |
rlm_couchbase_t * | inst | ||
) |
Build a JSON object map from the configuration "map" list.
Parse the "map" list 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 list. |
inst | The module instance. |
Definition at line 237 of file mod.c.
int mod_conn_alive | ( | UNUSED void * | opaque, |
void * | connection | ||
) |
Check the health of a connection handle.
Attempt to determine 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.
opaque | The module instance (currently unused). |
connection | The connection handle. |
Definition at line 208 of file mod.c.
void* mod_conn_create | ( | TALLOC_CTX * | ctx, |
void * | instance, | ||
fr_time_delta_t | 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. |
Definition at line 154 of file mod.c.
int mod_ensure_start_timestamp | ( | json_object * | json, |
fr_pair_list_t * | 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 604 of file mod.c.
int mod_free_api_opts | ( | rlm_couchbase_t * | inst | ) |
Delete a object built by mod_build_api_opts()
Release the underlying mod_build_api_opts() objects
inst | The module instance. |
Definition at line 63 of file mod.c.
int mod_json_object_to_map | ( | TALLOC_CTX * | ctx, |
fr_dcursor_t * | out, | ||
request_t * | request, | ||
json_object * | json, | ||
fr_dict_attr_t const * | list | ||
) |
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:
[in] | ctx | to allocate maps in. |
[in] | out | Cursor to append maps to. |
[in] | request | The request to which the generated pairs should be added. |
[in] | json | The JSON object representation of the user document. |
[in] | list | The pair list fr_request_attr_control or fr_request_attr_reply |
Definition at line 373 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 server startup this should not be a concern.
inst | The module instance. |
tmpl | Default values for new clients. |
map | The client attribute configuration list. |
Definition at line 706 of file mod.c.
Convert value pairs to json objects.
Take the passed value pair and convert it to a json-c JSON object..
request | The request object. |
vp | The value pair to convert. |
Definition at line 510 of file mod.c.