]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Fixes for deprecated libcouchbase functions
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 16 Sep 2014 01:07:08 +0000 (21:07 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 16 Sep 2014 01:09:53 +0000 (21:09 -0400)
src/modules/rlm_couchbase/couchbase.c
src/modules/rlm_couchbase/couchbase.h
src/modules/rlm_couchbase/mod.c

index c68fe8de0766ae8f8f0688d1190a7448e7ff23a6..a161f03b3a1c9b3057c7c48a6f6a415f20ba7bf2 100644 (file)
@@ -33,10 +33,15 @@ RCSID("$Id$");
 #include "couchbase.h"
 #include "jsonc_missing.h"
 
-/* general couchbase error callback */
-void couchbase_error_callback(lcb_t instance, lcb_error_t error, const char *errinfo) {
-       /* log error */
-       ERROR("rlm_couchbase: (error_callback) %s (0x%x), %s", lcb_strerror(instance, error), error, errinfo);
+/* couchbase statistics callback */
+void couchbase_stat_callback(lcb_t instance, const void *cookie, lcb_error_t error, const lcb_server_stat_resp_t *resp) {
+       if (error != LCB_SUCCESS) {
+               /* log error */
+               ERROR("rlm_couchbase: (stats_callback) %s (0x%x)", lcb_strerror(instance, error), error);
+       }
+       /* silent compiler */
+       (void)cookie;
+       (void)resp;
 }
 
 /* couchbase value store callback */
@@ -95,8 +100,7 @@ void couchbase_get_callback(lcb_t instance, const void *cookie, lcb_error_t erro
 }
 
 /* connect to couchbase */
-lcb_t couchbase_init_connection(const char *host, const char *bucket, const char *pass) {
-       lcb_t instance;                         /* couchbase instance */
+lcb_error_t couchbase_init_connection(lcb_t *instance, const char *host, const char *bucket, const char *pass) {
        lcb_error_t error;                      /* couchbase command return */
        struct lcb_create_st options;           /* init create struct */
 
@@ -114,28 +118,50 @@ lcb_t couchbase_init_connection(const char *host, const char *bucket, const char
        }
 
        /* create couchbase connection instance */
-       if ((error = lcb_create(&instance, &options)) != LCB_SUCCESS) {
-               /* log error and return */
-               ERROR("rlm_couchbase: failed to create couchbase instance: %s (0x%x)", lcb_strerror(NULL, error), error);
-               /* return instance */
-               return instance;
+       if ((error = lcb_create(instance, &options)) != LCB_SUCCESS) {
+               /* return error */
+               return error;
        }
 
        /* initiate connection */
-       if ((error = lcb_connect(instance)) == LCB_SUCCESS) {
+       if ((error = lcb_connect(*instance)) == LCB_SUCCESS) {
                /* set general method callbacks */
-               lcb_set_error_callback(instance, couchbase_error_callback);
-               lcb_set_get_callback(instance, couchbase_get_callback);
-               lcb_set_store_callback(instance, couchbase_store_callback);
+               lcb_set_stat_callback(*instance, couchbase_stat_callback);
+               lcb_set_get_callback(*instance, couchbase_get_callback);
+               lcb_set_store_callback(*instance, couchbase_store_callback);
                /* wait on connection */
-               lcb_wait(instance);
+               lcb_wait(*instance);
        } else {
-               /* log error */
-               ERROR("rlm_couchbase: Failed to initiate couchbase connection: %s (0x%x)", lcb_strerror(NULL, error), error);
+               /* return error */
+               return error;
        }
 
        /* return instance */
-       return instance;
+       return error;
+}
+
+/* get server statistics */
+lcb_error_t couchbase_server_stats(lcb_t instance, const void *cookie) {
+       lcb_error_t error;                         /* couchbase command return */
+       lcb_server_stats_cmd_t cmd;                /* server stats command stuct */
+       const lcb_server_stats_cmd_t *commands[1]; /* server stats commands array */
+
+       /* init commands */
+       commands[0] = &cmd;
+       memset(&cmd, 0, sizeof(cmd));
+
+       /* populate command struct */
+       cmd.v.v0.name = "tap";
+       cmd.v.v0.nname = strlen(cmd.v.v0.name);
+
+       /* get statistics */
+       if ((error = lcb_server_stats(instance, cookie, 1, commands)) == LCB_SUCCESS) {
+               /* enter event look on sucess */
+               lcb_wait(instance);
+       }
+
+       /* return error */
+       return error;
 }
 
 /* store document/key in couchbase */
index 6a08e58781579fb31bb88db74872361cb8720434..99128750dcfe01ce256e152bdb84b02ba0f8d31d 100644 (file)
@@ -44,8 +44,9 @@ typedef union cookie_u {
        void *data;
 } cookie_u;
 
-/* general error callback */
-void couchbase_error_callback(lcb_t instance, lcb_error_t error, const char *errinfo);
+/* couchbase statistics callback */
+void couchbase_stat_callback(lcb_t instance, const void *cookie, lcb_error_t error,
+       const lcb_server_stat_resp_t *resp);
 
 /* store a key/document in couchbase */
 void couchbase_store_callback(lcb_t instance, const void *cookie, lcb_storage_t operation,
@@ -56,7 +57,10 @@ void couchbase_get_callback(lcb_t instance, const void *cookie, lcb_error_t erro
        const lcb_get_resp_t *item);
 
 /* create a couchbase instance and connect to the cluster */
-lcb_t couchbase_init_connection(const char *host, const char *bucket, const char *pass);
+lcb_error_t couchbase_init_connection(lcb_t *instance, const char *host, const char *bucket, const char *pass);
+
+/* get server statistics */
+lcb_error_t couchbase_server_stats(lcb_t instance, const void *cookie);
 
 /* store document/key in couchbase */
 lcb_error_t couchbase_set_key(lcb_t instance, const char *key, const char *document, int expire);
index cc14677bfb1885d6b9a93b55c793e9966665b33c..8d2ddd6ac881aa32bc6aceed6cab9f39be484a6f 100644 (file)
@@ -56,10 +56,10 @@ void *mod_conn_create(TALLOC_CTX *ctx, void *instance)
        lcb_error_t cb_error = LCB_SUCCESS;         /* couchbase error status */
 
        /* create instance */
-       cb_inst = couchbase_init_connection(inst->server, inst->bucket, inst->password);
+       cb_error = couchbase_init_connection(&cb_inst, inst->server, inst->bucket, inst->password);
 
-       /* check couchbase instance status */
-       if ((cb_error = lcb_get_last_error(cb_inst)) != LCB_SUCCESS) {
+       /* check couchbase instance */
+       if (cb_error != LCB_SUCCESS) {
                ERROR("rlm_couchbase: failed to initiate couchbase connection: %s (0x%x)", lcb_strerror(NULL, cb_error), cb_error);
                /* destroy/free couchbase instance */
                lcb_destroy(cb_inst);
@@ -91,13 +91,10 @@ int mod_conn_alive(UNUSED void *instance, void *handle)
        lcb_t cb_inst = chandle->handle;            /* couchbase instance */
        lcb_error_t cb_error = LCB_SUCCESS;         /* couchbase error status */
 
-       /* attempt to get server list */
-       const char *const *servers = lcb_get_server_list(cb_inst);
-
-       /* check error state and server list return */
-       if (((cb_error = lcb_get_last_error(cb_inst)) != LCB_SUCCESS) || (servers == NULL)) {
+       /* attempt to get server stats */
+       if ((cb_error = couchbase_server_stats(cb_inst, NULL)) != LCB_SUCCESS) {
                /* log error */
-               ERROR("rlm_couchbase: failed to get couchbase server topology: %s (0x%x)", lcb_strerror(NULL, cb_error), cb_error);
+               ERROR("rlm_couchbase: failed to get couchbase server stats: %s (0x%x)", lcb_strerror(NULL, cb_error), cb_error);
                /* return false */
                return false;
        }