All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
couchbase.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: 930487f21af58229b2d95807d9411048f9409f8e $
19  *
20  * @brief Couchbase wrapper function prototypes and datatypes.
21  * @file couchbase.h
22  *
23  * @author Aaron Hurt <ahurt@anbcs.com>
24  * @copyright 2013-2014 The FreeRADIUS Server Project.
25  */
26 
27 #ifndef _couchbase_h_
28 #define _couchbase_h_
29 
30 RCSIDH(couchbase_h, "$Id: 930487f21af58229b2d95807d9411048f9409f8e $")
31 
32 #include <libcouchbase/couchbase.h>
33 #include "../rlm_json/json.h"
34 
35 /** Information relating to the parsing of Couchbase document payloads
36  *
37  * This structure holds various references to json-c objects used when parsing
38  * Couchbase document payloads.
39  */
40 typedef struct cookie_t {
41  json_object *jobj; //!< JSON objects handled by the json-c library.
42  json_tokener *jtok; //!< JSON tokener objects handled by the json-c library.
43  enum json_tokener_error jerr; //!< Error values produced by the json-c library.
44 } cookie_t;
45 
46 /** Union of constant and non-constant pointers
47  *
48  * This is used to squelch compiler warnings about casting when passing data
49  * between functions expecting different data types.
50  */
51 typedef union cookie_u {
52  const void *cdata; //!< Constant pointer to cookie payload (@p cookie_t).
53  void *data; //!< Non-constant pointer to data payload (@p cookie_t).
54 } cookie_u;
55 
56 /* couchbase statistics callback */
57 void couchbase_stat_callback(lcb_t instance, const void *cookie, lcb_error_t error,
58  const lcb_server_stat_resp_t *resp);
59 
60 /* store a key/document in couchbase */
61 void couchbase_store_callback(lcb_t instance, const void *cookie, lcb_storage_t operation,
62  lcb_error_t error, const lcb_store_resp_t *item);
63 
64 /* get a document by key from couchbase */
65 void couchbase_get_callback(lcb_t instance, const void *cookie, lcb_error_t error,
66  const lcb_get_resp_t *item);
67 
68 /* couchbase http callback for data chunks */
69 void couchbase_http_data_callback(lcb_http_request_t request, lcb_t instance,
70  const void *cookie, lcb_error_t error, const lcb_http_resp_t *resp);
71 
72 /* create a couchbase instance and connect to the cluster */
73 lcb_error_t couchbase_init_connection(lcb_t *instance, const char *host, const char *bucket, const char *pass,
74  lcb_uint32_t timeout);
75 
76 /* get server statistics */
77 lcb_error_t couchbase_server_stats(lcb_t instance, const void *cookie);
78 
79 /* store document/key in couchbase */
80 lcb_error_t couchbase_set_key(lcb_t instance, const char *key, const char *document, int expire);
81 
82 /* pull document from couchbase by key */
83 lcb_error_t couchbase_get_key(lcb_t instance, const void *cookie, const char *key);
84 
85 /* query a couchbase view via http */
86 lcb_error_t couchbase_query_view(lcb_t instance, const void *cookie, const char *path, const char *post);
87 
88 #endif /* _couchbase_h_ */
lcb_error_t couchbase_init_connection(lcb_t *instance, const char *host, const char *bucket, const char *pass, lcb_uint32_t timeout)
Initialize a Couchbase connection instance.
Definition: couchbase.c:198
#define RCSIDH(h, id)
Definition: build.h:136
const void * cdata
Constant pointer to cookie payload (cookie_t).
Definition: couchbase.h:52
void * data
Non-constant pointer to data payload (cookie_t).
Definition: couchbase.h:53
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:62
union cookie_u cookie_u
Union of constant and non-constant pointers.
static float timeout
Definition: radclient.c:43
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:370
struct cookie_t cookie_t
Information relating to the parsing of Couchbase document payloads.
json_tokener * jtok
JSON tokener objects handled by the json-c library.
Definition: couchbase.h:42
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:82
Union of constant and non-constant pointers.
Definition: couchbase.h:51
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:281
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:43
json_object * jobj
JSON objects handled by the json-c library.
Definition: couchbase.h:41
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:318
enum json_tokener_error jerr
Error values produced by the json-c library.
Definition: couchbase.h:43
lcb_error_t couchbase_server_stats(lcb_t instance, const void *cookie)
Request Couchbase server statistics.
Definition: couchbase.c:247
Information relating to the parsing of Couchbase document payloads.
Definition: couchbase.h:40
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:139