Neo4j-Client
view release on metacpan or search on metacpan
build/lib/src/client_config.c view on Meta::CPAN
return PACKAGE_NAME "/" PACKAGE_VERSION;
}
const char *libneo4j_client_version(void)
{
return PACKAGE_VERSION;
}
neo4j_config_t *neo4j_new_config(void)
{
neo4j_config_t *config = calloc(1, sizeof(neo4j_config_t));
if (config == NULL)
{
return NULL;
}
config->connection_factory = &neo4j_std_connection_factory;
config->allocator = &neo4j_std_memory_allocator;
config->mpool_block_size = NEO4J_DEFAULT_MPOOL_BLOCK_SIZE;
config->client_id = libneo4j_client_id();
config->io_rcvbuf_size = NEO4J_DEFAULT_RCVBUF_SIZE;
config->io_sndbuf_size = NEO4J_DEFAULT_SNDBUF_SIZE;
config->snd_min_chunk_size = 1024;
config->snd_max_chunk_size = UINT16_MAX;
config->session_request_queue_size =
NEO4J_DEFAULT_SESSION_REQUEST_QUEUE_SIZE;
config->max_pipelined_requests = NEO4J_DEFAULT_MAX_PIPELINED_REQUESTS;
config->trust_known = true;
config->render_inspect_rows = NEO4J_DEFAULT_RENDER_INSPECT_ROWS;
config->results_table_colors = neo4j_results_table_no_colors;
config->plan_table_colors = neo4j_plan_table_no_colors;
config->supported_versions = neo4j_supported_versions;
return config;
}
neo4j_config_t *neo4j_config_dup(const neo4j_config_t *config)
{
if (config == NULL)
{
return neo4j_new_config();
}
neo4j_config_t *dup = malloc(sizeof(neo4j_config_t));
if (config == NULL)
{
return NULL;
}
memcpy(dup, config, sizeof(neo4j_config_t));
if (strdup_null(&(dup->username), config->username))
{
goto failure;
}
if (strdup_null(&(dup->password), config->password))
{
goto failure;
}
#ifdef HAVE_TLS
if (strdup_null(&(dup->tls_private_key_file), config->tls_private_key_file))
{
goto failure;
}
if (strdup_null(&(dup->tls_ca_file), config->tls_ca_file))
{
goto failure;
}
if (strdup_null(&(dup->tls_ca_dir), config->tls_ca_dir))
{
goto failure;
}
#endif
if (strdup_null(&(dup->known_hosts_file), config->known_hosts_file))
{
goto failure;
}
return dup;
int errsv;
failure:
errsv = errno;
neo4j_config_free(dup);
errno = errsv;
return NULL;
}
void neo4j_config_free(neo4j_config_t *config)
{
if (config == NULL)
{
return;
}
ignore_unused_result(neo4j_config_set_username(config, NULL));
ignore_unused_result(neo4j_config_set_password(config, NULL));
#ifdef HAVE_TLS
ignore_unused_result(neo4j_config_set_TLS_private_key(config, NULL));
ignore_unused_result(neo4j_config_set_TLS_ca_file(config, NULL));
ignore_unused_result(neo4j_config_set_TLS_ca_dir(config, NULL));
#endif
ignore_unused_result(neo4j_config_set_known_hosts_file(config, NULL));
free(config);
}
void neo4j_config_set_client_id(neo4j_config_t *config, const char *client_id)
{
config->client_id = client_id;
}
const char *neo4j_config_get_client_id(const neo4j_config_t *config)
{
return config->client_id;
}
int neo4j_config_set_username(neo4j_config_t *config, const char *username)
{
REQUIRE(config != NULL, -1);
return replace_strptr_dup(&(config->username), username);
}
const char *neo4j_config_get_username(const neo4j_config_t *config)
{
return config->username;
}
int neo4j_config_nset_username(neo4j_config_t *config,
const char *username, size_t n)
{
REQUIRE(config != NULL, -1);
return replace_strptr_ndup(&(config->username), username, n);
}
int neo4j_config_set_password(neo4j_config_t *config, const char *password)
{
REQUIRE(config != NULL, -1);
if (config->password != NULL)
{
size_t plen = strlen(config->password);
memset_s(config->password, plen, 0, plen);
}
return replace_strptr_dup(&(config->password), password);
}
int neo4j_config_set_basic_auth_callback(neo4j_config_t *config,
neo4j_basic_auth_callback_t callback, void *userdata)
{
REQUIRE(config != NULL, -1);
config->basic_auth_callback = callback;
config->basic_auth_callback_userdata = userdata;
return 0;
}
int neo4j_config_set_TLS_private_key(neo4j_config_t *config, const char *path)
{
REQUIRE(config != NULL, -1);
#ifdef HAVE_TLS
return replace_strptr_dup(&(config->tls_private_key_file), path);
#else
errno = NEO4J_TLS_NOT_SUPPORTED;
return -1;
#endif
}
const char *neo4j_config_get_TLS_private_key(const neo4j_config_t *config)
{
REQUIRE(config != NULL, NULL);
#ifdef HAVE_TLS
return config->tls_private_key_file;
#else
return NULL;
#endif
}
int neo4j_config_set_TLS_private_key_password_callback(neo4j_config_t *config,
neo4j_password_callback_t callback, void *userdata)
{
REQUIRE(config != NULL, -1);
#ifdef HAVE_TLS
config->tls_pem_pw_callback = callback;
config->tls_pem_pw_callback_userdata = userdata;
return 0;
#else
errno = NEO4J_TLS_NOT_SUPPORTED;
return -1;
#endif
}
int neo4j_config_set_TLS_private_key_password(neo4j_config_t *config,
const char *password)
{
REQUIRE(config != NULL, -1);
return neo4j_config_set_TLS_private_key_password_callback(config,
default_password_callback, (void *)(intptr_t)password);
}
int neo4j_config_set_TLS_ca_file(neo4j_config_t *config, const char *path)
{
REQUIRE(config != NULL, -1);
#ifdef HAVE_TLS
return replace_strptr_dup(&(config->tls_ca_file), path);
#else
errno = NEO4J_TLS_NOT_SUPPORTED;
return -1;
#endif
}
const char *neo4j_config_get_TLS_ca_file(const neo4j_config_t *config)
{
REQUIRE(config != NULL, NULL);
#ifdef HAVE_TLS
return config->tls_ca_file;
#else
return NULL;
#endif
}
int neo4j_config_set_TLS_ca_dir(neo4j_config_t *config, const char *path)
{
REQUIRE(config != NULL, -1);
#ifdef HAVE_TLS
return replace_strptr_dup(&(config->tls_ca_dir), path);
#else
errno = NEO4J_TLS_NOT_SUPPORTED;
return -1;
#endif
}
const char *neo4j_config_get_TLS_ca_dir(const neo4j_config_t *config)
{
REQUIRE(config != NULL, NULL);
#ifdef HAVE_TLS
return config->tls_ca_dir;
#else
return NULL;
#endif
}
int neo4j_config_set_trust_known_hosts(neo4j_config_t *config, bool enable)
{
REQUIRE(config != NULL, -1);
config->trust_known = enable;
return 0;
}
bool neo4j_config_get_trust_known_hosts(const neo4j_config_t *config)
{
( run in 0.954 second using v1.01-cache-2.11-cpan-39bf76dae61 )