/* create new connection pool handle */ void *mod_conn_create(void *instance) { rlm_couchbase_t *inst = instance; /* module instance pointer */ rlm_couchbase_handle_t *chandle = NULL; /* connection handle pointer */ cookie_t *cookie = NULL; /* couchbase cookie */ lcb_t cb_inst; /* couchbase connection instance */ lcb_error_t cb_error = LCB_SUCCESS; /* couchbase error status */ /* create instance */ cb_inst = couchbase_init_connection(inst->server, inst->bucket, inst->password); /* check couchbase instance status */ if ((cb_error = lcb_get_last_error(cb_inst)) != 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); /* fail */ return NULL; } /* allocate memory for couchbase connection instance abstraction */ chandle = talloc_zero(inst, rlm_couchbase_handle_t); cookie = talloc_zero(chandle, cookie_t); /* initialize cookie error holder */ cookie->jerr = json_tokener_success; /* populate handle with allocated structs */ chandle->cookie = cookie; chandle->handle = cb_inst; /* return handle struct */ return chandle; }
/** Create a new connection pool handle * * Create a new connection to Couchbase within the pool and initialize * information associated with the connection instance. * * @param ctx The connection parent context. * @param instance The module instance. * @param timeout Maximum time to establish the connection. * @return * - New connection handle. * - NULL on error. */ void *mod_conn_create(TALLOC_CTX *ctx, void *instance, struct timeval const *timeout) { rlm_couchbase_t *inst = instance; /* module instance pointer */ rlm_couchbase_handle_t *chandle = NULL; /* connection handle pointer */ cookie_t *cookie = NULL; /* couchbase cookie */ lcb_t cb_inst; /* couchbase connection instance */ lcb_error_t cb_error; /* couchbase error status */ /* create instance */ cb_error = couchbase_init_connection(&cb_inst, inst->server, inst->bucket, inst->password, FR_TIMEVAL_TO_MS(timeout)); /* 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); /* fail */ return NULL; } /* allocate memory for couchbase connection instance abstraction */ chandle = talloc_zero(ctx, rlm_couchbase_handle_t); talloc_set_destructor(chandle, _mod_conn_free); /* allocate cookie off handle */ cookie = talloc_zero(chandle, cookie_t); /* init tokener error and json object */ cookie->jerr = json_tokener_success; cookie->jobj = NULL; /* populate handle */ chandle->cookie = cookie; chandle->handle = cb_inst; /* return handle struct */ return chandle; }