Skip to content
Snippets Groups Projects
Verified Commit 59c37487 authored by Timm Fitschen's avatar Timm Fitschen
Browse files

WIP: basic c interface

parent 805704bd
Branches
Tags
1 merge request!1Minimal c interface
Pipeline #10261 failed
......@@ -21,6 +21,10 @@
cmake_minimum_required(VERSION 3.14)
set(libcaosdb_VERSION 0.0.5)
set(libcaosdb_COMPATIBLE_SERVER_VERSION_MAJOR 0)
set(libcaosdb_COMPATIBLE_SERVER_VERSION_MINOR 5)
set(libcaosdb_COMPATIBLE_SERVER_VERSION_PATCH 0)
set(libcaosdb_COMPATIBLE_SERVER_VERSION_PRE_RELEASE "GRPC${libcaosdb_VERSION}")
project(libcaosdb
VERSION ${libcaosdb_VERSION}
......
......@@ -21,9 +21,11 @@
find_package(Doxygen)
if (DOXYGEN_FOUND)
string(REPLACE ";" " " DOXYGEN_INPUT "${libcaosdb_INCL}")
string(REPLACE ";" " " DOXYGEN_INPUT "${PROJECT_INCLUDE_DIR} ${CMAKE_BINARY_DIR}/include")
string(REPLACE ";" " " DOXYGEN_STRIP_FROM_PATH "${PROJECT_INCLUDE_DIR} ${CMAKE_BINARY_DIR}/include")
configure_file(Doxyfile.in Doxyfile)
# Note: do not put "ALL" - this builds docs together with application EVERY TIME!
add_custom_target(doc-doxygen
COMMAND ${DOXYGEN_EXECUTABLE} Doxyfile
......@@ -35,7 +37,9 @@ if (DOXYGEN_FOUND)
if (SPHINX_CMD)
configure_file(conf.py.in conf.py)
configure_file(index.rst.in index.rst)
configure_file(api/index.rst.in api/index.rst)
# create C++ docs
configure_file(cppapi/index.rst.in cppapi/index.rst)
# create rst pages for every header file
list(LENGTH libcaosdb_INCL len_header_files)
......@@ -43,20 +47,28 @@ if (DOXYGEN_FOUND)
foreach (i RANGE "${len_header_files}")
list(GET libcaosdb_INCL ${i} HEADER_FILE)
string(REPLACE
"${PROJECT_INCLUDE_DIR}/caosdb/"
"${PROJECT_INCLUDE_DIR}/"
""
HEADER_FILE_NAME
${HEADER_FILE})
string(REPLACE
"${CMAKE_BINARY_DIR}/include/caosdb/"
"${CMAKE_BINARY_DIR}/include/"
""
HEADER_FILE_NAME
${HEADER_FILE_NAME})
configure_file(
api/header_file.rst.in
api/_${HEADER_FILE_NAME}.rst)
header_file.rst.in
cppapi/_${HEADER_FILE_NAME}.rst)
endforeach ()
# create (plain) C docs
configure_file(capi/index.rst.in capi/index.rst)
set(HEADER_FILE_NAME ccaosdb.h)
set(HEADER_FILE ccaosdb.h)
configure_file(
header_file.rst.in
capi/_ccaosdb.rst)
add_custom_target(doc-sphinx
COMMAND ${SPHINX_CMD}
-b html
......
......@@ -68,7 +68,7 @@ OUTPUT_DIRECTORY = doxygen_out
# performance problems for the file system.
# The default value is: NO.
CREATE_SUBDIRS = NO
CREATE_SUBDIRS = YES
# If the ALLOW_UNICODE_NAMES tag is set to YES, doxygen will allow non-ASCII
# characters to appear in the names of generated files. If set to NO, non-ASCII
......@@ -170,7 +170,7 @@ FULL_PATH_NAMES = YES
# will be relative from the directory where doxygen is started.
# This tag requires that the tag FULL_PATH_NAMES is set to YES.
STRIP_FROM_PATH =
STRIP_FROM_PATH = @DOXYGEN_STRIP_FROM_PATH@
# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the
# path mentioned in the documentation of a class, which tells the reader which
......@@ -944,7 +944,7 @@ FILE_PATTERNS = *.c \
# be searched for input files as well.
# The default value is: NO.
RECURSIVE = NO
RECURSIVE = YES
# The EXCLUDE tag can be used to specify files and/or directories that should be
# excluded from the INPUT source files. This way you can easily exclude a
......
_*.rst
......@@ -21,10 +21,11 @@
.. _api_root:
API
===
C API
=====
.. toctree::
:glob:
*
_*
_*/*
..
#
# This file is a part of the CaosDB Project.
#
# Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com>
# Copyright (C) 2021 IndiScale GmbH <info@indiscale.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
.. _api_root:
C++ API
=======
.. toctree::
:glob:
_*
_*/*
File moved
......@@ -35,6 +35,7 @@ This is work in progress.
:caption: Contents:
Welcome <self>
api/index
cppapi/index
capi/index
* :ref:`genindex`
......@@ -22,7 +22,7 @@
#ifndef CAOSDB_AUTHENTICATION_H
#define CAOSDB_AUTHENTICATION_H
/**
* @file authentication.h
* @file caosdb/authentication.h
* @author Timm Fitschen
* @date 2021-06-28
* @brief Configuration and setup of the client authentication.
......
......@@ -46,41 +46,40 @@ using caosdb::info::v1alpha1::GeneralInfoService;
using caosdb::transaction::Transaction;
using grpc::ChannelCredentials;
class CACertificateProvider {
class CertificateificateProvider {
public:
[[nodiscard]] auto virtual GetCACertPem() const -> std::string = 0;
[[nodiscard]] auto virtual GetCertificatePem() const -> std::string = 0;
};
class PemFileCACertProvider : public CACertificateProvider {
class PemFileCertificateProvider : public CertificateificateProvider {
private:
std::string cacert;
public:
explicit PemFileCACertProvider(const std::string &path);
[[nodiscard]] auto GetCACertPem() const -> std::string override;
explicit PemFileCertificateProvider(const std::string &path);
[[nodiscard]] auto GetCertificatePem() const -> std::string override;
};
class PemCACertProvider : public CACertificateProvider {
class PemCertificateProvider : public CertificateificateProvider {
private:
std::string cacert;
public:
explicit PemCACertProvider(const std::string &cacert);
[[nodiscard]] auto GetCACertPem() const -> std::string override;
explicit PemCertificateProvider(const std::string &cacert);
[[nodiscard]] auto GetCertificatePem() const -> std::string override;
};
/**
* @brief Configuration of the CaosDB connection.
*/
class CaosDBConnectionConfig {
class ConnectionConfig {
private:
std::string host;
int port;
public:
CaosDBConnectionConfig(const std::string &host, int port);
friend auto operator<<(std::ostream &out,
const CaosDBConnectionConfig &config)
ConnectionConfig(const std::string &host, int port);
friend auto operator<<(std::ostream &out, const ConnectionConfig &config)
-> std::ostream &;
[[nodiscard]] auto virtual ToString() const -> std::string = 0;
......@@ -90,30 +89,30 @@ public:
-> std::shared_ptr<ChannelCredentials> = 0;
};
class InsecureCaosDBConnectionConfig : public CaosDBConnectionConfig {
class InsecureConnectionConfig : public ConnectionConfig {
private:
std::shared_ptr<ChannelCredentials> credentials;
public:
InsecureCaosDBConnectionConfig(const std::string &host, int port);
InsecureConnectionConfig(const std::string &host, int port);
[[nodiscard]] auto GetChannelCredentials() const
-> std::shared_ptr<ChannelCredentials> override;
[[nodiscard]] auto ToString() const -> std::string override;
};
class SslCaosDBConnectionConfig : public CaosDBConnectionConfig {
class TlsConnectionConfig : public ConnectionConfig {
private:
std::shared_ptr<ChannelCredentials> credentials;
std::string cacert;
public:
SslCaosDBConnectionConfig(const std::string &host, int port);
SslCaosDBConnectionConfig(const std::string &host, int port,
TlsConnectionConfig(const std::string &host, int port);
TlsConnectionConfig(const std::string &host, int port,
const Authenticator &authenticator);
SslCaosDBConnectionConfig(const std::string &host, int port,
const CACertificateProvider &cacert);
SslCaosDBConnectionConfig(const std::string &host, int port,
const CACertificateProvider &cacert,
TlsConnectionConfig(const std::string &host, int port,
const CertificateificateProvider &cacert);
TlsConnectionConfig(const std::string &host, int port,
const CertificateificateProvider &cacert,
const Authenticator &authenticator);
[[nodiscard]] auto GetChannelCredentials() const
-> std::shared_ptr<ChannelCredentials> override;
......@@ -123,14 +122,14 @@ public:
/**
* @brief A reusable connection to a CaosDBServer.
*/
class CaosDBConnection {
class Connection {
std::shared_ptr<grpc::Channel> channel;
std::unique_ptr<GeneralInfoService::Stub> general_info_service;
std::shared_ptr<EntityTransactionService::Stub> entity_transaction_service;
public:
explicit CaosDBConnection(const CaosDBConnectionConfig &config);
friend auto operator<<(std::ostream &out, const CaosDBConnection &connection)
explicit Connection(const ConnectionConfig &config);
friend auto operator<<(std::ostream &out, const Connection &connection)
-> std::ostream &;
[[nodiscard]] auto GetVersionInfo() const -> std::unique_ptr<VersionInfo>;
[[nodiscard]] auto CreateTransaction() const -> std::unique_ptr<Transaction>;
......
......@@ -29,6 +29,10 @@ namespace caosdb {
const int LIBCAOSDB_VERSION_MAJOR = @libcaosdb_VERSION_MAJOR@;
const int LIBCAOSDB_VERSION_MINOR = @libcaosdb_VERSION_MINOR@;
const int LIBCAOSDB_VERSION_PATCH = @libcaosdb_VERSION_PATCH@;
const int COMPATIBLE_SERVER_VERSION_MAJOR = @libcaosdb_COMPATIBLE_SERVER_VERSION_MAJOR@;
const int COMPATIBLE_SERVER_VERSION_MINOR = @libcaosdb_COMPATIBLE_SERVER_VERSION_MINOR@;
const int COMPATIBLE_SERVER_VERSION_PATCH = @libcaosdb_COMPATIBLE_SERVER_VERSION_PATCH@;
const char* COMPATIBLE_SERVER_VERSION_PRE_RELEASE = "@libcaosdb_COMPATIBLE_SERVER_VERSION_PRE_RELEASE@";
// clang-format on
#ifdef __cplusplus
} // namespace caosdb
......
......@@ -5,22 +5,51 @@ extern "C" {
#endif
/**
* A wrapper of the C++ CaosDBConnection class.
* Return the constant caosdb::LIBCAOSDB_VERSION_MAJOR.
*/
const int caosdb_constants_LIBCAOSDB_VERSION_MAJOR();
/**
* Return the constant caosdb::LIBCAOSDB_VERSION_MINOR
*/
const int caosdb_constants_LIBCAOSDB_VERSION_MINOR();
/**
* Return the constant caosdb::LIBCAOSDB_VERSION_PATCH.
*/
const int caosdb_constants_LIBCAOSDB_VERSION_PATCH();
/**
* Return the constant caosdb::COMPATIBLE_SERVER_VERSION_MAJOR.
*/
const int caosdb_constants_COMPATIBLE_SERVER_VERSION_MAJOR();
/**
* Return the constant caosdb::COMPATIBLE_SERVER_VERSION_MINOR.
*/
const int caosdb_constants_COMPATIBLE_SERVER_VERSION_MINOR();
/**
* Return the constant caosdb::COMPATIBLE_SERVER_VERSION_PATCH.
*/
const int caosdb_constants_COMPATIBLE_SERVER_VERSION_PATCH();
/**
* Return the constant caosdb::COMPATIBLE_SERVER_VERSION_PRE_RELEASE.
*/
const char *caosdb_constants_COMPATIBLE_SERVER_VERSION_PRE_RELEASE();
/**
* A wrapper of the C++ Connection class.
*
* We use a wrapper for future extensibility and in order to have a minimal
* capability for type checking in C even though the C++ class
* CaosDBConnection is opaque in C.
* Connection is opaque in C.
*/
typedef struct {
void *wrapped_connection;
} caosdb_connection_connection;
/**
* A wrapper of the C++ CaosDBConnectionConfig class.
* A wrapper of the C++ ConnectionConfig class.
*
* We use a wrapper for future extensibility and in order to have a minimal
* capability for type checking in C even though the C++ class
* CaosDBConnection is opaque in C.
* Connection is opaque in C.
*/
typedef struct {
void *wrapped_connection_configuration;
......@@ -31,7 +60,7 @@ typedef struct {
*
* We use a wrapper for future extensibility and in order to have a minimal
* capability for type checking in C even though the C++ class
* CaosDBConnection is opaque in C.
* Connection is opaque in C.
*/
typedef struct {
int major;
......
......@@ -52,102 +52,99 @@ using grpc::InsecureChannelCredentials;
using grpc::SslCredentials;
using grpc::SslCredentialsOptions;
PemFileCACertProvider::PemFileCACertProvider(const std::string &path) {
PemFileCertificateProvider::PemFileCertificateProvider(
const std::string &path) {
this->cacert = load_string_file(path);
}
auto PemFileCACertProvider::GetCACertPem() const -> std::string {
auto PemFileCertificateProvider::GetCertificatePem() const -> std::string {
return this->cacert;
}
PemCACertProvider::PemCACertProvider(const std::string &cacert) {
PemCertificateProvider::PemCertificateProvider(const std::string &cacert) {
this->cacert = cacert;
}
auto PemCACertProvider::GetCACertPem() const -> std::string {
auto PemCertificateProvider::GetCertificatePem() const -> std::string {
return this->cacert;
}
CaosDBConnectionConfig::CaosDBConnectionConfig(const std::string &host,
int port) {
ConnectionConfig::ConnectionConfig(const std::string &host, int port) {
this->host = host;
this->port = port;
}
auto CaosDBConnectionConfig::GetHost() const -> std::string {
return this->host;
}
auto ConnectionConfig::GetHost() const -> std::string { return this->host; }
auto CaosDBConnectionConfig::GetPort() const -> int { return this->port; }
auto ConnectionConfig::GetPort() const -> int { return this->port; }
auto operator<<(std::ostream &out, const CaosDBConnectionConfig &config)
auto operator<<(std::ostream &out, const ConnectionConfig &config)
-> std::ostream & {
out << config.ToString();
return out;
}
InsecureCaosDBConnectionConfig::InsecureCaosDBConnectionConfig(
const std::string &host, int port)
: CaosDBConnectionConfig(host, port) {
InsecureConnectionConfig::InsecureConnectionConfig(const std::string &host,
int port)
: ConnectionConfig(host, port) {
this->credentials = InsecureChannelCredentials();
}
auto InsecureCaosDBConnectionConfig::GetChannelCredentials() const
auto InsecureConnectionConfig::GetChannelCredentials() const
-> std::shared_ptr<ChannelCredentials> {
return this->credentials;
}
auto InsecureCaosDBConnectionConfig::ToString() const -> std::string {
return "InsecureCaosDBConnectionConfig(" + this->GetHost() + "," +
auto InsecureConnectionConfig::ToString() const -> std::string {
return "InsecureConnectionConfig(" + this->GetHost() + "," +
std::to_string(this->GetPort()) + ")";
}
SslCaosDBConnectionConfig::SslCaosDBConnectionConfig(const std::string &host,
int port)
: CaosDBConnectionConfig(host, port) {
TlsConnectionConfig::TlsConnectionConfig(const std::string &host, int port)
: ConnectionConfig(host, port) {
SslCredentialsOptions options;
this->credentials = SslCredentials(options);
}
SslCaosDBConnectionConfig::SslCaosDBConnectionConfig(
const std::string &host, int port, const CACertificateProvider &cacert)
: CaosDBConnectionConfig(host, port) {
TlsConnectionConfig::TlsConnectionConfig(
const std::string &host, int port, const CertificateificateProvider &cacert)
: ConnectionConfig(host, port) {
SslCredentialsOptions options;
options.pem_root_certs = cacert.GetCACertPem();
options.pem_root_certs = cacert.GetCertificatePem();
this->credentials = SslCredentials(options);
}
SslCaosDBConnectionConfig::SslCaosDBConnectionConfig(
const std::string &host, int port, const Authenticator &authenticator)
: CaosDBConnectionConfig(host, port) {
TlsConnectionConfig::TlsConnectionConfig(const std::string &host, int port,
const Authenticator &authenticator)
: ConnectionConfig(host, port) {
SslCredentialsOptions options;
this->credentials = grpc::CompositeChannelCredentials(
SslCredentials(options), authenticator.GetCallCredentials());
}
SslCaosDBConnectionConfig::SslCaosDBConnectionConfig(
const std::string &host, int port, const CACertificateProvider &cacert,
TlsConnectionConfig::TlsConnectionConfig(
const std::string &host, int port, const CertificateificateProvider &cacert,
const Authenticator &authenticator)
: CaosDBConnectionConfig(host, port) {
: ConnectionConfig(host, port) {
SslCredentialsOptions options;
options.pem_root_certs = cacert.GetCACertPem();
options.pem_root_certs = cacert.GetCertificatePem();
this->credentials = grpc::CompositeChannelCredentials(
SslCredentials(options), authenticator.GetCallCredentials());
}
auto SslCaosDBConnectionConfig::GetChannelCredentials() const
auto TlsConnectionConfig::GetChannelCredentials() const
-> std::shared_ptr<ChannelCredentials> {
return this->credentials;
}
auto SslCaosDBConnectionConfig::ToString() const -> std::string {
return "SslCaosDBConnectionConfig(" + this->GetHost() + "," +
auto TlsConnectionConfig::ToString() const -> std::string {
return "TlsConnectionConfig(" + this->GetHost() + "," +
std::to_string(this->GetPort()) + "," + this->cacert + ")";
}
CaosDBConnection::CaosDBConnection(const CaosDBConnectionConfig &config) {
Connection::Connection(const ConnectionConfig &config) {
const std::string target =
config.GetHost() + ":" + std::to_string(config.GetPort());
this->channel = grpc::CreateChannel(target, config.GetChannelCredentials());
......@@ -156,13 +153,13 @@ CaosDBConnection::CaosDBConnection(const CaosDBConnectionConfig &config) {
std::make_shared<EntityTransactionService::Stub>(this->channel);
}
auto operator<<(std::ostream &out, const CaosDBConnection & /*connection*/)
auto operator<<(std::ostream &out, const Connection & /*connection*/)
-> std::ostream & {
out << "CaosDBConnection()";
out << "Connection()";
return out;
}
[[nodiscard]] auto CaosDBConnection::GetVersionInfo() const
[[nodiscard]] auto Connection::GetVersionInfo() const
-> std::unique_ptr<VersionInfo> {
const GetVersionInfoRequest request;
GetVersionInfoResponse response;
......@@ -185,7 +182,7 @@ auto operator<<(std::ostream &out, const CaosDBConnection & /*connection*/)
return std::make_unique<VersionInfo>(response.release_version_info());
}
[[nodiscard]] auto CaosDBConnection::CreateTransaction() const
[[nodiscard]] auto Connection::CreateTransaction() const
-> std::unique_ptr<Transaction> {
auto service_stub = this->entity_transaction_service;
return std::make_unique<Transaction>(service_stub);
......
#include <iostream>
#include <stdio.h>
#include "caosdb/constants.h"
#include "caosdb/utility.h"
#include "caosdb/constants.h"
#include "caosdb/connection.h"
......@@ -7,6 +8,34 @@
extern "C" {
const int caosdb_constants_LIBCAOSDB_VERSION_MAJOR() {
return caosdb::LIBCAOSDB_VERSION_MAJOR;
}
const int caosdb_constants_LIBCAOSDB_VERSION_MINOR() {
return caosdb::LIBCAOSDB_VERSION_MINOR;
}
const int caosdb_constants_LIBCAOSDB_VERSION_PATCH() {
return caosdb::LIBCAOSDB_VERSION_PATCH;
}
const int caosdb_constants_COMPATIBLE_SERVER_VERSION_MAJOR() {
return caosdb::COMPATIBLE_SERVER_VERSION_MAJOR;
}
const int caosdb_constants_COMPATIBLE_SERVER_VERSION_MINOR() {
return caosdb::COMPATIBLE_SERVER_VERSION_MINOR;
}
const int caosdb_constants_COMPATIBLE_SERVER_VERSION_PATCH() {
return caosdb::COMPATIBLE_SERVER_VERSION_PATCH;
}
const char *caosdb_constants_COMPATIBLE_SERVER_VERSION_PRE_RELEASE() {
return caosdb::COMPATIBLE_SERVER_VERSION_PRE_RELEASE;
}
const char *caosdb_utility_get_env_var(const char *name,
const char *fall_back) {
return caosdb::utility::get_env_var(name, fall_back);
......@@ -15,13 +44,13 @@ const char *caosdb_utility_get_env_var(const char *name,
int caosdb_connection_create_pem_file_certificate_provider(
caosdb_connection_certificate_provider *out, const char *path) {
out->wrapped_certificate_provider =
new caosdb::connection::PemFileCACertProvider(std::string(path));
new caosdb::connection::PemFileCertificateProvider(std::string(path));
return 0;
}
int caosdb_connection_delete_certificate_provider(
caosdb_connection_certificate_provider *provider) {
delete static_cast<caosdb::connection::CACertificateProvider *>(
delete static_cast<caosdb::connection::CertificateificateProvider *>(
provider->wrapped_certificate_provider);
return 0;
}
......@@ -50,31 +79,31 @@ int caosdb_connection_create_tls_connection_configuration(
auto host_str = std::string(host);
if (authenticator != nullptr && provider != nullptr) {
auto wrapped_provider =
static_cast<caosdb::connection::CACertificateProvider *>(
static_cast<caosdb::connection::CertificateificateProvider *>(
provider->wrapped_certificate_provider);
auto wrapped_authenticator =
static_cast<caosdb::authentication::Authenticator *>(
authenticator->wrapped_authenticator);
out->wrapped_connection_configuration =
new caosdb::connection::SslCaosDBConnectionConfig(
new caosdb::connection::TlsConnectionConfig(
host_str, port, *wrapped_provider, *wrapped_authenticator);
} else if (authenticator != nullptr) {
auto wrapped_authenticator =
static_cast<caosdb::authentication::Authenticator *>(
authenticator->wrapped_authenticator);
out->wrapped_connection_configuration =
new caosdb::connection::SslCaosDBConnectionConfig(host_str, port,
new caosdb::connection::TlsConnectionConfig(host_str, port,
*wrapped_authenticator);
} else if (provider != nullptr) {
auto wrapped_provider =
static_cast<caosdb::connection::CACertificateProvider *>(
static_cast<caosdb::connection::CertificateificateProvider *>(
provider->wrapped_certificate_provider);
out->wrapped_connection_configuration =
new caosdb::connection::SslCaosDBConnectionConfig(host_str, port,
new caosdb::connection::TlsConnectionConfig(host_str, port,
*wrapped_provider);
} else {
out->wrapped_connection_configuration =
new caosdb::connection::SslCaosDBConnectionConfig(host_str, port);
new caosdb::connection::TlsConnectionConfig(host_str, port);
}
return 0;
}
......@@ -83,13 +112,13 @@ int caosdb_connection_create_insecure_connection_configuration(
caosdb_connection_connection_configuration *out, const char *host,
const int port) {
out->wrapped_connection_configuration =
new caosdb::connection::InsecureCaosDBConnectionConfig(host, port);
new caosdb::connection::InsecureConnectionConfig(host, port);
return 0;
}
int caosdb_connection_delete_connection_configuration(
caosdb_connection_connection_configuration *configuration) {
delete static_cast<caosdb::connection::CaosDBConnectionConfig *>(
delete static_cast<caosdb::connection::ConnectionConfig *>(
configuration->wrapped_connection_configuration);
return 0;
}
......@@ -97,16 +126,16 @@ int caosdb_connection_delete_connection_configuration(
int caosdb_connection_create_connection(
caosdb_connection_connection *out,
const caosdb_connection_connection_configuration *configuration) {
caosdb::connection::CaosDBConnectionConfig *config =
static_cast<caosdb::connection::CaosDBConnectionConfig *>(
caosdb::connection::ConnectionConfig *config =
static_cast<caosdb::connection::ConnectionConfig *>(
configuration->wrapped_connection_configuration);
out->wrapped_connection = new caosdb::connection::CaosDBConnection(*config);
out->wrapped_connection = new caosdb::connection::Connection(*config);
return 0;
}
int caosdb_connection_delete_connection(
caosdb_connection_connection *connection) {
delete static_cast<caosdb::connection::CaosDBConnection *>(
delete static_cast<caosdb::connection::Connection *>(
connection->wrapped_connection);
return 0;
}
......@@ -114,8 +143,7 @@ int caosdb_connection_delete_connection(
int caosdb_connection_get_version_info(
caosdb_info_version_info *out,
const caosdb_connection_connection *connection) {
auto *wrapped_connection =
static_cast<caosdb::connection::CaosDBConnection *>(
auto *wrapped_connection = static_cast<caosdb::connection::Connection *>(
connection->wrapped_connection);
auto version_info = wrapped_connection->GetVersionInfo();
......
......@@ -54,10 +54,10 @@ auto main() -> int {
// setup the connection
auto auth =
caosdb::authentication::PlainPasswordAuthenticator(user, password);
auto cacert = caosdb::connection::PemFileCACertProvider(pem_file);
auto cacert = caosdb::connection::PemFileCertificateProvider(pem_file);
auto config =
caosdb::connection::SslCaosDBConnectionConfig(host, port, cacert, auth);
caosdb::connection::CaosDBConnection connection(config);
caosdb::connection::TlsConnectionConfig(host, port, cacert, auth);
caosdb::connection::Connection connection(config);
// get version info of the server
const auto &v_info = connection.GetVersionInfo();
......
......@@ -23,13 +23,13 @@
#include <gtest/gtest-message.h> // for Message
#include <gtest/gtest-test-part.h> // for TestPartResult, SuiteApiRes...
#include <memory> // for allocator, operator!=, shar...
#include "caosdb/connection.h" // for PemCACertProvider, Insecure...
#include "caosdb/connection.h" // for PemCertificateProvider, Insecure...
#include "gtest/gtest_pred_impl.h" // for Test, AssertionResult, EXPE...
namespace caosdb::connection {
TEST(test_connection, configure_insecure_localhost_8080) {
InsecureCaosDBConnectionConfig config("localhost", 8000);
InsecureConnectionConfig config("localhost", 8000);
EXPECT_EQ("localhost", config.GetHost());
EXPECT_EQ(8000, config.GetPort());
......@@ -38,8 +38,8 @@ TEST(test_connection, configure_insecure_localhost_8080) {
}
TEST(test_connection, configure_ssl_localhost_8080) {
auto cacert = PemCACertProvider("ca chain");
SslCaosDBConnectionConfig config("localhost", 44300, cacert);
auto cacert = PemCertificateProvider("ca chain");
TlsConnectionConfig config("localhost", 44300, cacert);
EXPECT_EQ("localhost", config.GetHost());
EXPECT_EQ(44300, config.GetPort());
......
......@@ -21,7 +21,7 @@
*/
#include <memory> // for allocator, make_shared
#include "caosdb/connection.h" // for InsecureCaosDBConnection...
#include "caosdb/connection.h" // for InsecureConnection...
#include "caosdb/entity.h" // for Entity
#include "caosdb/entity/v1alpha1/main.pb.h" // for Entity
#include "caosdb/exceptions.h" // for ConnectionError
......@@ -32,16 +32,16 @@
#include "gtest/gtest_pred_impl.h" // for Test, TestInfo, TEST
namespace caosdb::transaction {
using caosdb::connection::CaosDBConnection;
using caosdb::connection::InsecureCaosDBConnectionConfig;
using caosdb::connection::Connection;
using caosdb::connection::InsecureConnectionConfig;
using caosdb::exceptions::ConnectionError;
using caosdb::transaction::UniqueResult;
using ProtoEntity = caosdb::entity::v1alpha1::Entity;
TEST(test_transaction, create_transaction) {
const auto *host = "localhost";
auto config = InsecureCaosDBConnectionConfig(host, 8000);
CaosDBConnection connection(config);
auto config = InsecureConnectionConfig(host, 8000);
Connection connection(config);
auto transaction = connection.CreateTransaction();
transaction->RetrieveById("100");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment