36711d84370d3b8e7825bcfda05b0b60f196095f
[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 <libcouchbase/couchbase.h>
32 #include <json/json.h>
33
34 #include "jsonc_missing.h"
35
36 /* maximum size of a stored value */
37 #define MAX_VALUE_SIZE 20480
38
39 /* maximum length of a document key */
40 #define MAX_KEY_SIZE 250
41
42 /* configuration struct */
43 typedef struct rlm_couchbase_t {
44         char const *acct_key;           //!< Accounting document key.
45         char const *doctype;            //!< Value of 'docType' element name.
46         char const *server_raw;         //!< Raw server string before parsing.
47         char const *server;             //!< Couchbase server list.
48         char const *bucket;             //!< Couchbase bucket.
49         char const *password;           //!< Couchbase bucket password.
50         uint32_t expire;                //!< Document expire time in seconds.
51         const char *user_key;           //!< User document key.
52         json_object *map;               //!< Json object to hold user defined attribute map.
53         fr_connection_pool_t *pool;     //!< Connection pool.
54 } rlm_couchbase_t;
55
56 /* connection pool handle struct */
57 typedef struct rlm_couchbase_handle_t {
58         void *handle;                   //!< Real couchbase instance.
59         void *cookie;                   //!< Couchbase cookie.
60 } rlm_couchbase_handle_t;
61
62 /* define functions */
63 void *mod_conn_create(void *instance);
64
65 int mod_conn_alive(UNUSED void *instance, void *handle);
66
67 int mod_conn_delete(UNUSED void *instance, void *handle);
68
69 int mod_build_attribute_element_map(CONF_SECTION *conf, void *instance);
70
71 int mod_attribute_to_element(const char *name, json_object *map, void *buf);
72
73 void *mod_json_object_to_value_pairs(json_object *json, const char *section, REQUEST *request);
74
75 json_object *mod_value_pair_to_json_object(REQUEST *request, VALUE_PAIR *vp);
76
77 int mod_ensure_start_timestamp(json_object *json, VALUE_PAIR *vps);
78
79 #endif /* _mod_h_ */