Exemplo n.º 1
0
LIBCOUCHBASE_API
libcouchbase_error_t libcouchbase_create_compat(libcouchbase_cluster_t type,
                                                const void *specific,
                                                libcouchbase_t *instance,
                                                struct libcouchbase_io_opt_st *io)
{
    libcouchbase_error_t ret = LIBCOUCHBASE_NOT_SUPPORTED;
    VBUCKET_CONFIG_HANDLE config;

    *instance = libcouchbase_create(NULL, NULL, NULL, NULL, io);
    if (*instance == NULL) {
        return LIBCOUCHBASE_CLIENT_ENOMEM;
    }

    config = vbucket_config_create();
    if (config == NULL) {
        libcouchbase_destroy(*instance);
        *instance = NULL;
        return LIBCOUCHBASE_CLIENT_ENOMEM;
    }

    if (type == LIBCOUCHBASE_MEMCACHED_CLUSTER) {
        ret = create_memcached(specific, config);
    }

    if (ret == LIBCOUCHBASE_SUCCESS) {
        libcouchbase_apply_vbucket_config(*instance, config);
    } else {
        vbucket_config_destroy(config);
        libcouchbase_destroy(*instance);
        *instance = NULL;
    }

    return ret;
}
Exemplo n.º 2
0
static void teardown(void)
{
    libcouchbase_destroy(session);
    session = NULL;
    io = NULL;
    shutdown_mock_server(mock);
    mock = NULL;
}
Exemplo n.º 3
0
static apr_status_t _couchbase_reslist_free_connection(void *conn_, void *params, apr_pool_t *pool) {
   libcouchbase_t *instance = (libcouchbase_t*)conn_;
   libcouchbase_destroy(*instance);
   return APR_SUCCESS; 
}
Exemplo n.º 4
0
LIBCOUCHBASE_API
libcouchbase_t libcouchbase_create(const char *host,
                                   const char *user,
                                   const char *passwd,
                                   const char *bucket,
                                   struct libcouchbase_io_opt_st *io)
{
    char buffer[1024];
    libcouchbase_ssize_t offset;
    libcouchbase_t ret;

    if (io == NULL) {
        io = libcouchbase_create_io_ops(LIBCOUCHBASE_IO_OPS_DEFAULT,
                                        NULL, NULL);
        if (io == NULL) {
            /* You can't initialize the library without a io-handler! */
            return NULL;
        }
    }

    if (host == NULL) {
        host = "localhost";
    }

    if (bucket == NULL || strlen(bucket) == 0) {
        bucket = "default";
    }

    if (sasl_client_init(NULL) != SASL_OK) {
        return NULL;
    }

    if ((ret = calloc(1, sizeof(*ret))) == NULL) {
        return NULL;
    }
    libcouchbase_initialize_packet_handlers(ret);
    libcouchbase_behavior_set_syncmode(ret, LIBCOUCHBASE_ASYNCHRONOUS);

    if (setup_boostrap_hosts(ret, host) == -1) {
        free(ret);
        return NULL;
    }

    offset = snprintf(buffer, sizeof(buffer),
                      "GET /pools/default/bucketsStreaming/%s HTTP/1.1\r\n",
                      bucket);

    if (user && passwd) {
        char cred[256];
        char base64[256];
        snprintf(cred, sizeof(cred), "%s:%s", user, passwd);
        if (libcouchbase_base64_encode(cred, base64, sizeof(base64)) == -1) {
            libcouchbase_destroy(ret);
            return NULL;
        }

        offset += snprintf(buffer + offset, sizeof(buffer) - (libcouchbase_size_t)offset,
                           "Authorization: Basic %s\r\n", base64);
    }
    offset += snprintf(buffer + offset, sizeof(buffer) - (libcouchbase_size_t)offset, "\r\n");
    ret->http_uri = strdup(buffer);

    if (ret->http_uri == NULL) {
        libcouchbase_destroy(ret);
        return NULL;
    }

    ret->sock = INVALID_SOCKET;

    /* No error has occurred yet. */
    ret->last_error = LIBCOUCHBASE_SUCCESS;

    /* setup io iops! */
    ret->io = io;
    ret->timeout.event = ret->io->create_timer(ret->io);
    assert(ret->timeout.event);

    libcouchbase_set_timeout(ret, LIBCOUCHBASE_DEFAULT_TIMEOUT);

    return ret;
}