All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
mod.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 2 of the License, or
5  * (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
15  */
16 
17 /**
18  * $Id: 0660f07c247659a1e315bb700eefc7737c87adf0 $
19  *
20  * @brief Function prototypes and datatypes used in the module.
21  * @file mod.h
22  *
23  * @author Aaron Hurt <ahurt@anbcs.com>
24  * @copyright 2013-2014 The FreeRADIUS Server Project.
25  */
26 
27 #ifndef _mod_h_
28 #define _mod_h_
29 
30 RCSIDH(mod_h, "$Id: 0660f07c247659a1e315bb700eefc7737c87adf0 $")
31 
32 #include <freeradius-devel/radiusd.h>
33 
34 #include <libcouchbase/couchbase.h>
35 #include "../rlm_json/json.h"
36 
37 /* maximum size of a stored value */
38 #define MAX_VALUE_SIZE 20480
39 
40 /* maximum length of a document key */
41 #define MAX_KEY_SIZE 250
42 
43 /** The main module instance
44  *
45  * This struct contains the core module configuration.
46  */
47 typedef struct rlm_couchbase_t {
48  vp_tmpl_t *acct_key; //!< Accounting document key.
49  char const *doctype; //!< Value of accounting 'docType' element name.
50  uint32_t expire; //!< Accounting document expire time in seconds.
51 
52  char const *server_raw; //!< Raw server string before parsing.
53  char const *server; //!< Couchbase server list.
54  char const *bucket; //!< Couchbase bucket.
55  char const *password; //!< Couchbase bucket password.
56 
57  vp_tmpl_t *user_key; //!< User document key.
58 
59  bool read_clients; //!< Toggle for loading client records.
60  const char *client_view; //!< Couchbase view that returns client documents.
61 
62  bool check_simul; //!< Toggle to enable simultaneous use checking.
63  const char *simul_view; //!< Couchbase view that returns accounting documents.
64 
65  bool verify_simul; //!< Toggle to enable user login state verification.
66  vp_tmpl_t *simul_vkey; //!< The query key to be used with simul_view.
67  bool delete_stale_sessions; //!< Toggle to trigger zapping of stale sessions.
68 
69  json_object *map; //!< Json object to hold user defined attribute map.
70  fr_connection_pool_t *pool; //!< Connection pool.
72 
73 /** Couchbase instance specific information
74  *
75  * This struct contains the Couchbase connection handle as well as a
76  * cookie pointer to store fetched document payloads.
77  */
78 typedef struct rlm_couchbase_handle_t {
79  void *handle; //!< Real couchbase instance.
80  void *cookie; //!< Couchbase cookie (@p cookie_u @p cookie_t).
82 
83 /* define functions */
84 void *mod_conn_create(TALLOC_CTX *ctx, void *instance, struct timeval const *timeout);
85 
86 int mod_conn_alive(UNUSED void *instance, void *handle);
87 
89 
90 int mod_attribute_to_element(const char *name, json_object *map, void *buf);
91 
92 void *mod_json_object_to_value_pairs(json_object *json, const char *section, REQUEST *request);
93 
94 json_object *mod_value_pair_to_json_object(REQUEST *request, VALUE_PAIR *vp);
95 
96 int mod_ensure_start_timestamp(json_object *json, VALUE_PAIR *vps);
97 
98 int mod_client_map_section(CONF_SECTION *client, CONF_SECTION const *map, json_object *json, char const *docid);
99 
101 
102 #endif /* _mod_h_ */
int mod_load_client_documents(rlm_couchbase_t *inst, CONF_SECTION *tmpl, CONF_SECTION *map)
Load client entries from Couchbase client documents on startup.
Definition: mod.c:577
bool read_clients
Toggle for loading client records.
Definition: mod.h:59
#define RCSIDH(h, id)
Definition: build.h:136
json_object * map
Json object to hold user defined attribute map.
Definition: mod.h:69
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.
Definition: mod.c:281
uint32_t expire
Accounting document expire time in seconds.
Definition: mod.h:50
fr_connection_pool_t * pool
Connection pool.
Definition: mod.h:70
void * mod_conn_create(TALLOC_CTX *ctx, void *instance, struct timeval const *timeout)
Create a new connection pool handle.
Definition: mod.c:68
static char const * name
char const * password
Couchbase bucket password.
Definition: mod.h:55
void * handle
Real couchbase instance.
Definition: mod.h:79
struct rlm_couchbase_handle_t rlm_couchbase_handle_t
Couchbase instance specific information.
#define UNUSED
Definition: libradius.h:134
bool delete_stale_sessions
Toggle to trigger zapping of stale sessions.
Definition: mod.h:67
int mod_build_attribute_element_map(CONF_SECTION *conf, void *instance)
Build a JSON object map from the configuration "map" section.
Definition: mod.c:150
static float timeout
Definition: radclient.c:43
#define inst
const char * simul_view
Couchbase view that returns accounting documents.
Definition: mod.h:63
static expr_map_t map[]
Definition: rlm_expr.c:169
char const * server
Couchbase server list.
Definition: mod.h:53
struct rlm_couchbase_t rlm_couchbase_t
The main module instance.
int mod_conn_alive(UNUSED void *instance, void *handle)
Check the health of a connection handle.
Definition: mod.c:121
The main module instance.
Definition: mod.h:47
vp_tmpl_t * simul_vkey
The query key to be used with simul_view.
Definition: mod.h:66
vp_tmpl_t * user_key
User document key.
Definition: mod.h:57
vp_tmpl_t * acct_key
Accounting document key.
Definition: mod.h:48
json_object * mod_value_pair_to_json_object(REQUEST *request, VALUE_PAIR *vp)
Convert value pairs to json objects.
Definition: mod.c:382
bool check_simul
Toggle to enable simultaneous use checking.
Definition: mod.h:62
Stores an attribute, a value and various bits of other data.
Definition: pair.h:112
static rs_t * conf
Definition: radsniff.c:46
int mod_ensure_start_timestamp(json_object *json, VALUE_PAIR *vps)
Ensure accounting documents always contain a valid timestamp.
Definition: mod.c:476
char const * server_raw
Raw server string before parsing.
Definition: mod.h:52
char const * bucket
Couchbase bucket.
Definition: mod.h:54
const char * client_view
Couchbase view that returns client documents.
Definition: mod.h:60
char const * doctype
Value of accounting 'docType' element name.
Definition: mod.h:49
bool verify_simul
Toggle to enable user login state verification.
Definition: mod.h:65
A connection pool.
Definition: connection.c:85
void * cookie
Couchbase cookie (cookie_u cookie_t).
Definition: mod.h:80
Couchbase instance specific information.
Definition: mod.h:78
int mod_attribute_to_element(const char *name, json_object *map, void *buf)
Map attributes to JSON element names.
Definition: mod.c:225
int mod_client_map_section(CONF_SECTION *client, CONF_SECTION const *map, json_object *json, char const *docid)
A source or sink of value data.
Definition: tmpl.h:187