Skip to content

Commit

Permalink
Merge branch 'master' into add-custom-auth
Browse files Browse the repository at this point in the history
  • Loading branch information
gitbuda committed Aug 30, 2024
2 parents d7561ad + d8d0115 commit 89724e3
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 49 deletions.
29 changes: 14 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ jobs:
build_and_test_apple:
strategy:
matrix:
platform: [macos-11]
platform: [macos-14]
runs-on: ${{ matrix.platform }}
env:
MG_VERSION: "1.4.0"
steps:
- name: Set-up repository
uses: actions/checkout@v2
Expand All @@ -42,7 +40,7 @@ jobs:
fail-fast: false
matrix:
include:
- os: windows-2019
- os: windows-2022
env:
VCPKG_ROOT: "${{ github.workspace }}\\vcpkg"
deps: "openssl:x64-windows"
Expand Down Expand Up @@ -78,8 +76,8 @@ jobs:
build_and_test_linux:
strategy:
matrix:
platform: [ubuntu-20.04, ubuntu-22.04]
mgversion: ["2.0.0", "2.3.0"]
platform: [ubuntu-24.04]
mgversion: ["2.19.0"]
packages: ["gcc g++ clang"]
gcc-postfix: [""]
clang-postfix: [""]
Expand All @@ -100,11 +98,11 @@ jobs:
if: steps.cache-memgraph-docker.outputs.cache-hit != 'true'
run: |
mkdir ~/memgraph
curl -L https://memgraph.com/download/memgraph/v${{ matrix.mgversion }}/docker/memgraph-${{ matrix.mgversion }}-docker.tar.gz > ~/memgraph/memgraph-docker.tar.gz
curl -L https://download.memgraph.com/memgraph/v${{ matrix.mgversion }}/docker/memgraph-${{ matrix.mgversion }}-docker.tar.gz > ~/memgraph/memgraph-docker.tar.gz
- name: Load and run Memgraph Docker image
run: |
docker load -i ~/memgraph/memgraph-docker.tar.gz
docker run -d -p 7687:7687 memgraph --telemetry-enabled=false
docker run -d -p 7687:7687 memgraph/memgraph --telemetry-enabled=false
- name: Build with gcc, test and install mgclient
run: |
mkdir build-gcc && cd build-gcc
Expand All @@ -128,11 +126,11 @@ jobs:
# Memgraph has to be started manually because systemd is not available on
# WSL (init process does not exist).
build_and_test_windows_mingw:
runs-on: windows-2019
runs-on: windows-2022
strategy:
matrix:
include: [
{ msystem: MINGW64, arch: x86_64, mgversion: "1.4.0" }
{ msystem: MINGW64, arch: x86_64, mgversion: "2.19.0" }
]
defaults:
run:
Expand All @@ -147,14 +145,15 @@ jobs:
install: git base-devel mingw-w64-${{ matrix.arch }}-toolchain mingw-w64-${{ matrix.arch }}-cmake mingw-w64-${{ matrix.arch }}-openssl
- uses: Vampire/setup-wsl@v1
with:
distribution: Ubuntu-18.04
distribution: Ubuntu-22.04
- name: Download, install and run Memgraph under WSL
shell: wsl-bash {0} # root shell
run: |
mkdir ~/memgraph
curl -L https://download.memgraph.com/memgraph/v${{matrix.mgversion}}/ubuntu-18.04/memgraph_${{matrix.mgversion}}-community-1_amd64.deb --output ~/memgraph/memgraph-community.deb
dpkg -i ~/memgraph/memgraph-community.deb
nohup /usr/lib/memgraph/memgraph --bolt-port 7687 --bolt-cert-file="" --bolt-key-file="" --data-directory="~/memgraph/data" --storage-properties-on-edges=true --storage-snapshot-interval-sec=0 --storage-wal-enabled=false --storage-recover-on-startup=false --storage-snapshot-on-exit=false --telemetry-enabled=false --log-file='' &
# https://download.memgraph.com/memgraph/v2.19.0/ubuntu-24.04/memgraph_2.19.0-1_amd64.deb
curl -L https://download.memgraph.com/memgraph/v${{matrix.mgversion}}/ubuntu-22.04/memgraph_${{matrix.mgversion}}-1_amd64.deb --output ~/memgraph/memgraph.deb
dpkg -i ~/memgraph/memgraph.deb
nohup /usr/lib/memgraph/memgraph --bolt-port 7687 --bolt-cert-file="" --bolt-key-file="" --data-directory="~/memgraph/data" --storage-properties-on-edges=true --storage-snapshot-interval-sec=0 --storage-wal-enabled=false --data-recovery-on-startup=false --storage-snapshot-on-exit=false --telemetry-enabled=false --log-file='' &
sleep 1 # Wait for Memgraph a bit.
- name: Build and test mgclient
run: |
Expand All @@ -167,7 +166,7 @@ jobs:
build_and_test_linux_wasm:
strategy:
matrix:
platform: [ubuntu-20.04]
platform: [ubuntu-24.04]
runs-on: ${{ matrix.platform }}
steps:
- name: Set-up repository
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Actions Status](https://github.com/memgraph/mgclient/workflows/CI/badge.svg)](https://github.com/memgraph/mgclient/actions)
[![Actions Status](https://github.com/memgraph/mgclient/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/memgraph/mgclient/actions)

# mgclient

Expand Down
15 changes: 14 additions & 1 deletion examples/advanced.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ std::string MgValueToString(const mg::ConstValue &value) {
value_str = std::to_string(value.ValueBool());
} else if (value.type() == mg::Value::Type::Double) {
value_str = std::to_string(value.ValueDouble());
} else if (value.type() == mg::Value::Type::Point2d) {
auto point2d = value.ValuePoint2d();
value_str += "Point2D({ srid:" + std::to_string(point2d.srid()) +
", x:" + std::to_string(point2d.x()) +
", y:" + std::to_string(point2d.y()) + " })";
} else if (value.type() == mg::Value::Type::Point3d) {
auto point3d = value.ValuePoint3d();
value_str += "Point3D({ srid:" + std::to_string(point3d.srid()) +
", x:" + std::to_string(point3d.x()) +
", y:" + std::to_string(point3d.y()) +
", z:" + std::to_string(point3d.z()) + " })";
} else if (value.type() == mg::Value::Type::List) {
value_str += "[";
for (auto item : value.ValueList()) {
Expand Down Expand Up @@ -63,7 +74,9 @@ int main(int argc, char *argv[]) {

if (!client->Execute(
"CREATE (:Person:Entrepreneur {id: 0, age: 40, name: 'John', "
"isStudent: false, score: 5.0});")) {
"isStudent: false, score: 5.0, "
"position2D: point({x: 1, y: 2, srid: 4326}), "
"position3D: point({x: 8, y: 9, z: 10, srid: 9757}) });")) {
std::cerr << "Failed to add data." << std::endl;
return 1;
}
Expand Down
21 changes: 16 additions & 5 deletions include/mgclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,17 @@ extern "C" {
/// Client software version.
///
/// \return Client version in the major.minor.patch format.
MGCLIENT_EXPORT const char *mg_client_version();
MGCLIENT_EXPORT const char *mg_client_version(void);

/// Initializes the client (the whole process).
/// Should be called at the beginning of each process using the client.
///
/// \return Zero if initialization was successful.
MGCLIENT_EXPORT int mg_init();
MGCLIENT_EXPORT int mg_init(void);

/// Finalizes the client (the whole process).
/// Should be called at the end of each process using the client.
MGCLIENT_EXPORT void mg_finalize();
MGCLIENT_EXPORT void mg_finalize(void);

/// An enum listing all the types as specified by Bolt protocol.
enum mg_value_type {
Expand Down Expand Up @@ -297,7 +297,7 @@ typedef struct mg_point_3d mg_point_3d;
/// Constructs a nil \ref mg_value.
///
/// \return Pointer to the newly constructed value or NULL if error occurred.
MGCLIENT_EXPORT mg_value *mg_value_make_null();
MGCLIENT_EXPORT mg_value *mg_value_make_null(void);

/// Constructs a boolean \ref mg_value.
///
Expand Down Expand Up @@ -1010,6 +1010,11 @@ MGCLIENT_EXPORT mg_duration *mg_duration_copy(const mg_duration *duration);
/// Destroy the given duration.
MGCLIENT_EXPORT void mg_duration_destroy(mg_duration *duration);

/// Creates mg_point_2d from srid, x_longitude and y_latitude.
/// \return a pointer to mg_point_2d or NULL if an error occured.
MGCLIENT_EXPORT mg_point_2d *mg_point_2d_make(uint16_t srid, double x_longitude,
double y_latitude);

/// Returns SRID of the 2D point.
MGCLIENT_EXPORT int64_t mg_point_2d_srid(const mg_point_2d *point_2d);

Expand All @@ -1027,6 +1032,12 @@ MGCLIENT_EXPORT mg_point_2d *mg_point_2d_copy(const mg_point_2d *point_2d);
/// Destroys the given 2D point.
MGCLIENT_EXPORT void mg_point_2d_destroy(mg_point_2d *point_2d);

/// Creates mg_point_3d from srid, x_longitude, y_latitude and z_height.
/// \return a pointer to mg_point_3d or NULL if an error occured.
MGCLIENT_EXPORT mg_point_3d *mg_point_3d_make(uint16_t srid, double x_longitude,
double y_latitude,
double z_height);

/// Returns SRID of the 3D point.
MGCLIENT_EXPORT int64_t mg_point_3d_srid(const mg_point_3d *point_3d);

Expand Down Expand Up @@ -1221,7 +1232,7 @@ typedef int (*mg_trust_callback_type)(const char *, const char *, const char *,
const char *, void *);

/// Creates a new `mg_session_params` object.
MGCLIENT_EXPORT mg_session_params *mg_session_params_make();
MGCLIENT_EXPORT mg_session_params *mg_session_params_make(void);

/// Destroys a `mg_session_params` object.
MGCLIENT_EXPORT void mg_session_params_destroy(mg_session_params *);
Expand Down
8 changes: 3 additions & 5 deletions src/apple/mgsocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

#include <string.h>

#include "mgcommon.h"

#define MG_RETRY_ON_EINTR(expression) \
__extension__({ \
long result; \
Expand All @@ -27,7 +25,7 @@
result; \
})

int mg_socket_init() { return MG_SUCCESS; }
int mg_socket_init(void) { return MG_SUCCESS; }

int mg_socket_create(int af, int type, int protocol) {
int sockfd = socket(af, type, protocol);
Expand Down Expand Up @@ -92,6 +90,6 @@ int mg_socket_pair(int d, int type, int protocol, int *sv) {

int mg_socket_close(int sock) { return MG_RETRY_ON_EINTR(close(sock)); }

char *mg_socket_error() { return strerror(errno); }
char *mg_socket_error(void) { return strerror(errno); }

void mg_socket_finalize() {}
void mg_socket_finalize(void) {}
8 changes: 3 additions & 5 deletions src/linux/mgsocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
#include <stdlib.h>
#include <string.h>

#include "mgcommon.h"

#ifdef __EMSCRIPTEN__
#include "emscripten.h"
#include "mgwasm.h"
Expand All @@ -36,7 +34,7 @@
// Please refer to https://man7.org/linux/man-pages/man2 for more details about
// Linux system calls.

int mg_socket_init() { return MG_SUCCESS; }
int mg_socket_init(void) { return MG_SUCCESS; }

int mg_socket_create(int af, int type, int protocol) {
int sockfd = socket(af, type, protocol);
Expand Down Expand Up @@ -151,6 +149,6 @@ int mg_socket_pair(int d, int type, int protocol, int *sv) {

int mg_socket_close(int sock) { return MG_RETRY_ON_EINTR(close(sock)); }

char *mg_socket_error() { return strerror(errno); }
char *mg_socket_error(void) { return strerror(errno); }

void mg_socket_finalize() {}
void mg_socket_finalize(void) {}
10 changes: 5 additions & 5 deletions src/mgclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
#include "mgtransport.h"
#include "mgvalue.h"

const char *mg_client_version() { return MGCLIENT_VERSION; }
const char *mg_client_version(void) { return MGCLIENT_VERSION; }

int mg_init_session_static_vars() {
int mg_init_session_static_vars(void) {
mg_value *n_val = mg_value_make_integer(-1);
if (!n_val) {
goto fatal_failure;
Expand All @@ -55,13 +55,13 @@ int mg_init_session_static_vars() {
return MG_ERROR_CLIENT_ERROR;
}

int mg_init() {
int mg_init(void) {
int init_status = mg_init_session_static_vars();
if (init_status != 0) return init_status;
return mg_socket_init();
}

void mg_finalize() { mg_socket_finalize(); }
void mg_finalize(void) { mg_socket_finalize(); }

typedef struct mg_session_params {
const char *address;
Expand All @@ -79,7 +79,7 @@ typedef struct mg_session_params {
void *trust_data;
} mg_session_params;

mg_session_params *mg_session_params_make() {
mg_session_params *mg_session_params_make(void) {
mg_session_params *params =
mg_allocator_malloc(&mg_system_allocator, sizeof(mg_session_params));
if (!params) {
Expand Down
27 changes: 23 additions & 4 deletions src/mgsession-encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,27 @@ int mg_session_write_duration(mg_session *session, const mg_duration *dur) {
return 0;
}

int mg_session_write_point_2d(mg_session *session, const mg_point_2d *point) {
MG_RETURN_IF_FAILED(
mg_session_write_uint8(session, (uint8_t)(MG_MARKER_TINY_STRUCT3)));
MG_RETURN_IF_FAILED(mg_session_write_uint8(session, MG_SIGNATURE_POINT_2D));
MG_RETURN_IF_FAILED(mg_session_write_integer(session, point->srid));
MG_RETURN_IF_FAILED(mg_session_write_float(session, point->x));
MG_RETURN_IF_FAILED(mg_session_write_float(session, point->y));
return 0;
}

int mg_session_write_point_3d(mg_session *session, const mg_point_3d *point) {
MG_RETURN_IF_FAILED(
mg_session_write_uint8(session, (uint8_t)(MG_MARKER_TINY_STRUCT4)));
MG_RETURN_IF_FAILED(mg_session_write_uint8(session, MG_SIGNATURE_POINT_3D));
MG_RETURN_IF_FAILED(mg_session_write_integer(session, point->srid));
MG_RETURN_IF_FAILED(mg_session_write_float(session, point->x));
MG_RETURN_IF_FAILED(mg_session_write_float(session, point->y));
MG_RETURN_IF_FAILED(mg_session_write_float(session, point->z));
return 0;
}

int mg_session_write_value(mg_session *session, const mg_value *value) {
switch (value->type) {
case MG_VALUE_TYPE_NULL:
Expand Down Expand Up @@ -219,11 +240,9 @@ int mg_session_write_value(mg_session *session, const mg_value *value) {
case MG_VALUE_TYPE_DURATION:
return mg_session_write_duration(session, value->duration_v);
case MG_VALUE_TYPE_POINT_2D:
mg_session_set_error(session, "tried to send value of type 'point_2d'");
return MG_ERROR_INVALID_VALUE;
return mg_session_write_point_2d(session, value->point_2d_v);
case MG_VALUE_TYPE_POINT_3D:
mg_session_set_error(session, "tried to send value of type 'point_3d'");
return MG_ERROR_INVALID_VALUE;
return mg_session_write_point_3d(session, value->point_3d_v);
case MG_VALUE_TYPE_UNKNOWN:
mg_session_set_error(session, "tried to send value of unknown type");
return MG_ERROR_INVALID_VALUE;
Expand Down
6 changes: 3 additions & 3 deletions src/mgsocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ typedef long ssize_t;

/// Initializes underlying resources. Has to be called at the beginning of a
/// process using socket resources.
int mg_socket_init();
int mg_socket_init(void);

/// Returns a descriptor referencing the new socket or MG_ERROR_SOCKET in the
/// case of any failure.
Expand Down Expand Up @@ -110,11 +110,11 @@ int mg_socket_close(int sock);

/// Used to get a native error message after some socket call fails.
/// Has to be called immediately after the failed socket function.
char *mg_socket_error();
char *mg_socket_error(void);

/// Should be called at the end of any process which previously called the
/// \ref mg_socket_init function.
void mg_socket_finalize();
void mg_socket_finalize(void);

#ifdef __cplusplus
}
Expand Down
4 changes: 1 addition & 3 deletions src/mgtransport.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "mgtransport.h"

#include <assert.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#ifdef MGCLIENT_ON_LINUX
Expand All @@ -26,7 +25,6 @@

#include "mgallocator.h"
#include "mgclient.h"
#include "mgcommon.h"
#include "mgsocket.h"
#ifdef __EMSCRIPTEN__
#include "mgwasm.h"
Expand Down Expand Up @@ -160,7 +158,7 @@ static char *hex_encode(unsigned char *data, unsigned int len,
return encoded;
}

static void mg_openssl_init() {
static void mg_openssl_init(void) {
#if OPENSSL_VERSION_NUMBER < 0x10100000L
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
static int mg_ssl_initialized = 0;
Expand Down
Loading

0 comments on commit 89724e3

Please sign in to comment.