The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
couchbase.h
Go to the documentation of this file.
1 #pragma once
2 /*
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16  */
17 
18 /**
19  * $Id: 0aabb447e0c40c9162d2d764841ae76019a53da7 $
20  *
21  * @brief Couchbase wrapper function prototypes and datatypes.
22  * @file couchbase.h
23  *
24  * @author Aaron Hurt (ahurt@anbcs.com)
25  * @copyright 2013-2014 The FreeRADIUS Server Project.
26  */
27 RCSIDH(couchbase_h, "$Id: 0aabb447e0c40c9162d2d764841ae76019a53da7 $")
28 
29 #ifdef HAVE_WDOCUMENTATION
30 DIAG_OFF(documentation)
31 #endif
32 #include <libcouchbase/couchbase.h>
33 #ifdef HAVE_WDOCUMENTATION
34 DIAG_ON(documentation)
35 #endif
36 
37 #include <freeradius-devel/json/base.h>
38 
39 /** Information relating to the parsing of Couchbase document payloads
40  *
41  * This structure holds various references to json-c objects used when parsing
42  * Couchbase document payloads.
43  */
44 typedef struct {
45  json_object *jobj; //!< JSON objects handled by the json-c library.
46  json_tokener *jtok; //!< JSON tokener objects handled by the json-c library.
47  enum json_tokener_error jerr; //!< Error values produced by the json-c library.
48 } cookie_t;
49 
50 /** Union of constant and non-constant pointers
51  *
52  * This is used to squelch compiler warnings about casting when passing data
53  * between functions expecting different data types.
54  */
55 typedef union cookie_u {
56  const void *cdata; //!< Constant pointer to cookie payload (@p cookie_t).
57  void *data; //!< Non-constant pointer to data payload (@p cookie_t).
59 
60 /**
61  * This may be used to provide a simple interface from a command line or higher
62  * evel language to allow the setting of specific key-value pairs.
63  *
64  * Options ref: https://docs.couchbase.com/sdk-api/couchbase-c-client-2.5.6/group__lcb-cntl.html
65  */
66 typedef struct couchbase_opts_s couchbase_opts_t;
68  char *key; //!< Key value for lcb_cntl_string().
69  char *val; //!< Value for the key used in lcb_cntl_string().
70  couchbase_opts_t *next; //!< Linked list.
71 };
72 
76 
77 /* couchbase statistics callback */
78 void couchbase_stat_callback(lcb_t instance, const void *cookie, lcb_error_t error,
79  const lcb_server_stat_resp_t *resp);
80 
81 /* store a key/document in couchbase */
82 void couchbase_store_callback(lcb_t instance, const void *cookie, lcb_storage_t operation,
83  lcb_error_t error, const lcb_store_resp_t *item);
84 
85 /* get a document by key from couchbase */
86 void couchbase_get_callback(lcb_t instance, const void *cookie, lcb_error_t error,
87  const lcb_get_resp_t *item);
88 
89 /* couchbase http callback for data chunks */
90 void couchbase_http_data_callback(lcb_http_request_t request, lcb_t instance,
91  const void *cookie, lcb_error_t error, const lcb_http_resp_t *resp);
92 
93 /* create a couchbase instance and connect to the cluster */
94 lcb_error_t couchbase_init_connection(lcb_t *instance, const char *host, const char *bucket, const char *user,
95  const char *pass, lcb_uint32_t timeout, const couchbase_opts_t *opts);
96 
97 /* get server statistics */
98 lcb_error_t couchbase_server_stats(lcb_t instance, const void *cookie);
99 
100 /* store document/key in couchbase */
101 lcb_error_t couchbase_set_key(lcb_t instance, const char *key, const char *document, int expire);
102 
103 /* pull document from couchbase by key */
104 lcb_error_t couchbase_get_key(lcb_t instance, const void *cookie, const char *key);
105 
106 /* query a couchbase view via http */
107 lcb_error_t couchbase_query_view(lcb_t instance, const void *cookie, const char *path, const char *post);
#define DIAG_ON(_x)
Definition: build.h:419
#define RCSIDH(h, id)
Definition: build.h:445
#define HIDDEN
Definition: build.h:312
#define DIAG_OFF(_x)
Definition: build.h:418
lcb_error_t couchbase_query_view(lcb_t instance, const void *cookie, const char *path, const char *post)
Query a Couchbase design document view.
Definition: couchbase.c:377
lcb_error_t couchbase_server_stats(lcb_t instance, const void *cookie)
Request Couchbase server statistics.
Definition: couchbase.c:254
lcb_error_t couchbase_init_connection(lcb_t *instance, const char *host, const char *bucket, const char *user, const char *pass, lcb_uint32_t timeout, const couchbase_opts_t *opts)
Initialize a Couchbase connection instance.
Definition: couchbase.c:196
json_object * jobj
JSON objects handled by the json-c library.
Definition: couchbase.h:45
union cookie_u cookie_u
Union of constant and non-constant pointers.
lcb_error_t couchbase_set_key(lcb_t instance, const char *key, const char *document, int expire)
Store a document by key in Couchbase.
Definition: couchbase.c:288
HIDDEN fr_dict_attr_t const * attr_event_timestamp
Definition: rlm_couchbase.c:78
void couchbase_http_data_callback(lcb_http_request_t request, lcb_t instance, const void *cookie, lcb_error_t error, const lcb_http_resp_t *resp)
Couchbase callback for http (view) operations.
Definition: couchbase.c:138
const void * cdata
Constant pointer to cookie payload (cookie_t).
Definition: couchbase.h:56
HIDDEN fr_dict_attr_t const * attr_acct_session_time
Definition: rlm_couchbase.c:77
void * data
Non-constant pointer to data payload (cookie_t).
Definition: couchbase.h:57
void couchbase_store_callback(lcb_t instance, const void *cookie, lcb_storage_t operation, lcb_error_t error, const lcb_store_resp_t *item)
Couchbase callback for store (write) operations.
Definition: couchbase.c:61
void couchbase_stat_callback(lcb_t instance, const void *cookie, lcb_error_t error, const lcb_server_stat_resp_t *resp)
Couchbase callback for cluster statistics requests.
Definition: couchbase.c:42
char * val
Value for the key used in lcb_cntl_string().
Definition: couchbase.h:69
HIDDEN fr_dict_attr_t const * attr_acct_status_type
Definition: rlm_couchbase.c:76
void couchbase_get_callback(lcb_t instance, const void *cookie, lcb_error_t error, const lcb_get_resp_t *item)
Couchbase callback for get (read) operations.
Definition: couchbase.c:81
char * key
Key value for lcb_cntl_string().
Definition: couchbase.h:68
lcb_error_t couchbase_get_key(lcb_t instance, const void *cookie, const char *key)
Retrieve a document by key from Couchbase.
Definition: couchbase.c:325
couchbase_opts_t * next
Linked list.
Definition: couchbase.h:70
Information relating to the parsing of Couchbase document payloads.
Definition: couchbase.h:44
Union of constant and non-constant pointers.
Definition: couchbase.h:55
static fr_time_delta_t timeout
Definition: dhcpclient.c:54
static void * item(fr_lst_t const *lst, fr_lst_index_t idx)
Definition: lst.c:122