1cb29c7621935928ec47785bb37d495df711ebf9
[freeradius.git] / src / modules / rlm_couchbase / couchbase.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 Couchbase wrapper function prototypes and datatypes.
21  * @file couchbase.h
22  *
23  * @copyright 2013-2014 Aaron Hurt <ahurt@anbcs.com>
24  */
25
26 #ifndef _couchbase_h_
27 #define _couchbase_h_
28
29 RCSIDH(couchbase_h, "$Id$");
30
31 #include <libcouchbase/couchbase.h>
32 #include <json/json.h>
33
34 /* struct to hold cookie data for couchbase callbacks */
35 typedef struct cookie_t {
36         json_object *jobj;              /* json object */
37         json_tokener *jtok;             /* json tokener */
38         enum json_tokener_error jerr;   /* tokener error */
39 } cookie_t;
40
41 /* union of const and non const pointers */
42 typedef union cookie_u {
43         const void *cdata;
44         void *data;
45 } cookie_u;
46
47 /* general error callback */
48 void couchbase_error_callback(lcb_t instance, lcb_error_t error, const char *errinfo);
49
50 /* store a key/document in couchbase */
51 void couchbase_store_callback(lcb_t instance, const void *cookie, lcb_storage_t operation,
52         lcb_error_t error, const lcb_store_resp_t *item);
53
54 /* get a document by key from couchbase */
55 void couchbase_get_callback(lcb_t instance, const void *cookie, lcb_error_t error,
56         const lcb_get_resp_t *item);
57
58 /* create a couchbase instance and connect to the cluster */
59 lcb_t couchbase_init_connection(const char *host, const char *bucket, const char *pass);
60
61 /* store document/key in couchbase */
62 lcb_error_t couchbase_set_key(lcb_t instance, const char *key, const char *document, int expire);
63
64 /* pull document from couchbase by key */
65 lcb_error_t couchbase_get_key(lcb_t instance, const void *cookie, const char *key);
66
67 #endif /* _couchbase_h_ */