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