Remove fr_connection_delete
[freeradius.git] / src / modules / rlm_couchbase / rlm_couchbase.c
index 8c5d48f..ffab0ed 100644 (file)
@@ -31,7 +31,7 @@ RCSID("$Id$");
 #include <freeradius-devel/rad_assert.h>
 
 #include <libcouchbase/couchbase.h>
-#include <json/json.h>
+#include <json.h>
 
 #include "mod.h"
 #include "couchbase.h"
@@ -41,31 +41,37 @@ RCSID("$Id$");
  * Module Configuration
  */
 static const CONF_PARSER module_config[] = {
-       {"acctkey", PW_TYPE_STRING_PTR, offsetof(rlm_couchbase_t, acctkey), NULL,
-               "radacct_%{%{Acct-Unique-Session-Id}:-%{Acct-Session-Id}}"},
-       {"doctype", PW_TYPE_STRING_PTR, offsetof(rlm_couchbase_t, doctype), NULL, "radacct"},
-       {"server", PW_TYPE_STRING_PTR | PW_TYPE_REQUIRED, offsetof(rlm_couchbase_t, server), NULL, NULL},
-       {"bucket", PW_TYPE_STRING_PTR | PW_TYPE_REQUIRED, offsetof(rlm_couchbase_t, bucket), NULL, NULL},
-       {"pass", PW_TYPE_STRING_PTR, offsetof(rlm_couchbase_t, pass), NULL, NULL},
-       {"expire", PW_TYPE_INTEGER, offsetof(rlm_couchbase_t, expire), NULL, 0},
-       {"userkey", PW_TYPE_STRING_PTR | PW_TYPE_REQUIRED, offsetof(rlm_couchbase_t, userkey), NULL,
-               "raduser_%{md5:%{tolower:%{%{Stripped-User-Name}:-%{User-Name}}}}"},
+       { "acct_key", FR_CONF_OFFSET(PW_TYPE_STRING, rlm_couchbase_t, acct_key), "radacct_%{%{Acct-Unique-Session-Id}:-%{Acct-Session-Id}}" },
+       { "doctype", FR_CONF_OFFSET(PW_TYPE_STRING, rlm_couchbase_t, doctype), "radacct" },
+       { "server", FR_CONF_OFFSET(PW_TYPE_STRING | PW_TYPE_REQUIRED, rlm_couchbase_t, server_raw), NULL },
+       { "bucket", FR_CONF_OFFSET(PW_TYPE_STRING | PW_TYPE_REQUIRED, rlm_couchbase_t, bucket), NULL },
+       { "password", FR_CONF_OFFSET(PW_TYPE_STRING, rlm_couchbase_t, password), NULL },
+       { "expire", FR_CONF_OFFSET(PW_TYPE_INTEGER, rlm_couchbase_t, expire), 0 },
+       { "user_key", FR_CONF_OFFSET(PW_TYPE_STRING | PW_TYPE_REQUIRED, rlm_couchbase_t, user_key), "raduser_%{md5:%{tolower:%{%{Stripped-User-Name}:-%{User-Name}}}}" },
        {NULL, -1, 0, NULL, NULL}     /* end the list */
 };
 
 /* initialize couchbase connection */
 static int mod_instantiate(CONF_SECTION *conf, void *instance) {
+       static bool version_done;
+
        rlm_couchbase_t *inst = instance;   /* our module instance */
 
+       if (!version_done) {
+               version_done = true;
+               INFO("rlm_couchbase: json-c version: %s", json_c_version());
+               INFO("rlm_couchbase: libcouchbase version: %s", lcb_get_version(NULL));
+       }
+
        {
                char *server, *p;
                size_t len, i;
                bool sep = false;
 
-               len = talloc_array_length(inst->server);
+               len = talloc_array_length(inst->server_raw);
                server = p = talloc_array(inst, char, len);
                for (i = 0; i < len; i++) {
-                       switch (inst->server[i]) {
+                       switch (inst->server_raw[i]) {
                        case '\t':
                        case ' ':
                        case ',':
@@ -78,13 +84,12 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance) {
 
                        default:
                                sep = false;
-                               *p++ = inst->server[i];
+                               *p++ = inst->server_raw[i];
                                break;
                        }
                }
 
                *p = '\0';
-               talloc_free(inst->server);
                inst->server = server;
        }
 
@@ -95,7 +100,7 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance) {
        }
 
        /* initiate connection pool */
-       inst->pool = fr_connection_pool_init(conf, inst, mod_conn_create, mod_conn_alive, mod_conn_delete, NULL);
+       inst->pool = fr_connection_pool_init(conf, inst, mod_conn_create, mod_conn_alive, NULL);
 
        /* check connection pool */
        if (!inst->pool) {
@@ -119,9 +124,9 @@ static rlm_rcode_t CC_HINT(nonnull) mod_authorize(void *instance, REQUEST *reque
        rad_assert(request->packet != NULL);
 
        /* attempt to build document key */
-       if (radius_xlat(dockey, sizeof(dockey), request, inst->userkey, NULL, NULL) < 0) {
+       if (radius_xlat(dockey, sizeof(dockey), request, inst->user_key, NULL, NULL) < 0) {
                /* log error */
-               RERROR("could not find user key attribute (%s) in packet", inst->userkey);
+               RERROR("could not find user key attribute (%s) in packet", inst->user_key);
                /* return */
                return RLM_MODULE_FAIL;
        }
@@ -266,9 +271,9 @@ static rlm_rcode_t CC_HINT(nonnull) mod_accounting(void *instance, REQUEST *requ
        }
 
        /* attempt to build document key */
-       if (radius_xlat(dockey, sizeof(dockey), request, inst->acctkey, NULL, NULL) < 0) {
+       if (radius_xlat(dockey, sizeof(dockey), request, inst->acct_key, NULL, NULL) < 0) {
                /* log error */
-               RERROR("could not find accounting key attribute (%s) in packet", inst->acctkey);
+               RERROR("could not find accounting key attribute (%s) in packet", inst->acct_key);
                /* release handle */
                if (handle) {
                        fr_connection_release(inst->pool, handle);