multiple fixes and minor additions
[freeradius.git] / src / modules / rlm_couchbase / mod.h
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$
19  *
20  * @brief Function prototypes and datatypes used in the module.
21  * @file mod.h
22  *
23  * @copyright 2013-2014 Aaron Hurt <ahurt@anbcs.com>
24  */
25
26 #ifndef _mod_h_
27 #define _mod_h_
28
29 RCSIDH(mod_h, "$Id$");
30
31 #include <freeradius-devel/radiusd.h>
32
33 #include <libcouchbase/couchbase.h>
34 #include <json.h>
35
36 #include "jsonc_missing.h"
37
38 /* maximum size of a stored value */
39 #define MAX_VALUE_SIZE 20480
40
41 /* maximum length of a document key */
42 #define MAX_KEY_SIZE 250
43
44 /* configuration struct */
45 typedef struct rlm_couchbase_t {
46         char const *acct_key;           //!< Accounting document key.
47         char const *doctype;            //!< Value of 'docType' element name.
48         char const *server_raw;         //!< Raw server string before parsing.
49         char const *server;             //!< Couchbase server list.
50         char const *bucket;             //!< Couchbase bucket.
51         char const *password;           //!< Couchbase bucket password.
52         uint32_t expire;                //!< Document expire time in seconds.
53         const char *user_key;           //!< User document key.
54         json_object *map;               //!< Json object to hold user defined attribute map.
55         fr_connection_pool_t *pool;     //!< Connection pool.
56 } rlm_couchbase_t;
57
58 /* connection pool handle struct */
59 typedef struct rlm_couchbase_handle_t {
60         void *handle;                   //!< Real couchbase instance.
61         void *cookie;                   //!< Couchbase cookie.
62 } rlm_couchbase_handle_t;
63
64 /* define functions */
65 void *mod_conn_create(void *instance);
66
67 int mod_conn_alive(UNUSED void *instance, void *handle);
68
69 int mod_conn_delete(UNUSED void *instance, void *handle);
70
71 int mod_build_attribute_element_map(CONF_SECTION *conf, void *instance);
72
73 int mod_attribute_to_element(const char *name, json_object *map, void *buf);
74
75 void *mod_json_object_to_value_pairs(json_object *json, const char *section, REQUEST *request);
76
77 json_object *mod_value_pair_to_json_object(REQUEST *request, VALUE_PAIR *vp);
78
79 int mod_ensure_start_timestamp(json_object *json, VALUE_PAIR *vps);
80
81 #endif /* _mod_h_ */