Skip to content

Commit 89724e3

Browse files
committed
Merge branch 'master' into add-custom-auth
2 parents d7561ad + d8d0115 commit 89724e3

File tree

11 files changed

+110
-49
lines changed

11 files changed

+110
-49
lines changed

.github/workflows/ci.yml

+14-15
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ jobs:
1818
build_and_test_apple:
1919
strategy:
2020
matrix:
21-
platform: [macos-11]
21+
platform: [macos-14]
2222
runs-on: ${{ matrix.platform }}
23-
env:
24-
MG_VERSION: "1.4.0"
2523
steps:
2624
- name: Set-up repository
2725
uses: actions/checkout@v2
@@ -42,7 +40,7 @@ jobs:
4240
fail-fast: false
4341
matrix:
4442
include:
45-
- os: windows-2019
43+
- os: windows-2022
4644
env:
4745
VCPKG_ROOT: "${{ github.workspace }}\\vcpkg"
4846
deps: "openssl:x64-windows"
@@ -78,8 +76,8 @@ jobs:
7876
build_and_test_linux:
7977
strategy:
8078
matrix:
81-
platform: [ubuntu-20.04, ubuntu-22.04]
82-
mgversion: ["2.0.0", "2.3.0"]
79+
platform: [ubuntu-24.04]
80+
mgversion: ["2.19.0"]
8381
packages: ["gcc g++ clang"]
8482
gcc-postfix: [""]
8583
clang-postfix: [""]
@@ -100,11 +98,11 @@ jobs:
10098
if: steps.cache-memgraph-docker.outputs.cache-hit != 'true'
10199
run: |
102100
mkdir ~/memgraph
103-
curl -L https://memgraph.com/download/memgraph/v${{ matrix.mgversion }}/docker/memgraph-${{ matrix.mgversion }}-docker.tar.gz > ~/memgraph/memgraph-docker.tar.gz
101+
curl -L https://download.memgraph.com/memgraph/v${{ matrix.mgversion }}/docker/memgraph-${{ matrix.mgversion }}-docker.tar.gz > ~/memgraph/memgraph-docker.tar.gz
104102
- name: Load and run Memgraph Docker image
105103
run: |
106104
docker load -i ~/memgraph/memgraph-docker.tar.gz
107-
docker run -d -p 7687:7687 memgraph --telemetry-enabled=false
105+
docker run -d -p 7687:7687 memgraph/memgraph --telemetry-enabled=false
108106
- name: Build with gcc, test and install mgclient
109107
run: |
110108
mkdir build-gcc && cd build-gcc
@@ -128,11 +126,11 @@ jobs:
128126
# Memgraph has to be started manually because systemd is not available on
129127
# WSL (init process does not exist).
130128
build_and_test_windows_mingw:
131-
runs-on: windows-2019
129+
runs-on: windows-2022
132130
strategy:
133131
matrix:
134132
include: [
135-
{ msystem: MINGW64, arch: x86_64, mgversion: "1.4.0" }
133+
{ msystem: MINGW64, arch: x86_64, mgversion: "2.19.0" }
136134
]
137135
defaults:
138136
run:
@@ -147,14 +145,15 @@ jobs:
147145
install: git base-devel mingw-w64-${{ matrix.arch }}-toolchain mingw-w64-${{ matrix.arch }}-cmake mingw-w64-${{ matrix.arch }}-openssl
148146
- uses: Vampire/setup-wsl@v1
149147
with:
150-
distribution: Ubuntu-18.04
148+
distribution: Ubuntu-22.04
151149
- name: Download, install and run Memgraph under WSL
152150
shell: wsl-bash {0} # root shell
153151
run: |
154152
mkdir ~/memgraph
155-
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
156-
dpkg -i ~/memgraph/memgraph-community.deb
157-
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='' &
153+
# https://download.memgraph.com/memgraph/v2.19.0/ubuntu-24.04/memgraph_2.19.0-1_amd64.deb
154+
curl -L https://download.memgraph.com/memgraph/v${{matrix.mgversion}}/ubuntu-22.04/memgraph_${{matrix.mgversion}}-1_amd64.deb --output ~/memgraph/memgraph.deb
155+
dpkg -i ~/memgraph/memgraph.deb
156+
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='' &
158157
sleep 1 # Wait for Memgraph a bit.
159158
- name: Build and test mgclient
160159
run: |
@@ -167,7 +166,7 @@ jobs:
167166
build_and_test_linux_wasm:
168167
strategy:
169168
matrix:
170-
platform: [ubuntu-20.04]
169+
platform: [ubuntu-24.04]
171170
runs-on: ${{ matrix.platform }}
172171
steps:
173172
- name: Set-up repository

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![Actions Status](https://github.com/memgraph/mgclient/workflows/CI/badge.svg)](https://github.com/memgraph/mgclient/actions)
1+
[![Actions Status](https://github.com/memgraph/mgclient/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/memgraph/mgclient/actions)
22

33
# mgclient
44

examples/advanced.cpp

+14-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ std::string MgValueToString(const mg::ConstValue &value) {
2121
value_str = std::to_string(value.ValueBool());
2222
} else if (value.type() == mg::Value::Type::Double) {
2323
value_str = std::to_string(value.ValueDouble());
24+
} else if (value.type() == mg::Value::Type::Point2d) {
25+
auto point2d = value.ValuePoint2d();
26+
value_str += "Point2D({ srid:" + std::to_string(point2d.srid()) +
27+
", x:" + std::to_string(point2d.x()) +
28+
", y:" + std::to_string(point2d.y()) + " })";
29+
} else if (value.type() == mg::Value::Type::Point3d) {
30+
auto point3d = value.ValuePoint3d();
31+
value_str += "Point3D({ srid:" + std::to_string(point3d.srid()) +
32+
", x:" + std::to_string(point3d.x()) +
33+
", y:" + std::to_string(point3d.y()) +
34+
", z:" + std::to_string(point3d.z()) + " })";
2435
} else if (value.type() == mg::Value::Type::List) {
2536
value_str += "[";
2637
for (auto item : value.ValueList()) {
@@ -63,7 +74,9 @@ int main(int argc, char *argv[]) {
6374

6475
if (!client->Execute(
6576
"CREATE (:Person:Entrepreneur {id: 0, age: 40, name: 'John', "
66-
"isStudent: false, score: 5.0});")) {
77+
"isStudent: false, score: 5.0, "
78+
"position2D: point({x: 1, y: 2, srid: 4326}), "
79+
"position3D: point({x: 8, y: 9, z: 10, srid: 9757}) });")) {
6780
std::cerr << "Failed to add data." << std::endl;
6881
return 1;
6982
}

include/mgclient.h

+16-5
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,17 @@ extern "C" {
137137
/// Client software version.
138138
///
139139
/// \return Client version in the major.minor.patch format.
140-
MGCLIENT_EXPORT const char *mg_client_version();
140+
MGCLIENT_EXPORT const char *mg_client_version(void);
141141

142142
/// Initializes the client (the whole process).
143143
/// Should be called at the beginning of each process using the client.
144144
///
145145
/// \return Zero if initialization was successful.
146-
MGCLIENT_EXPORT int mg_init();
146+
MGCLIENT_EXPORT int mg_init(void);
147147

148148
/// Finalizes the client (the whole process).
149149
/// Should be called at the end of each process using the client.
150-
MGCLIENT_EXPORT void mg_finalize();
150+
MGCLIENT_EXPORT void mg_finalize(void);
151151

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

302302
/// Constructs a boolean \ref mg_value.
303303
///
@@ -1010,6 +1010,11 @@ MGCLIENT_EXPORT mg_duration *mg_duration_copy(const mg_duration *duration);
10101010
/// Destroy the given duration.
10111011
MGCLIENT_EXPORT void mg_duration_destroy(mg_duration *duration);
10121012

1013+
/// Creates mg_point_2d from srid, x_longitude and y_latitude.
1014+
/// \return a pointer to mg_point_2d or NULL if an error occured.
1015+
MGCLIENT_EXPORT mg_point_2d *mg_point_2d_make(uint16_t srid, double x_longitude,
1016+
double y_latitude);
1017+
10131018
/// Returns SRID of the 2D point.
10141019
MGCLIENT_EXPORT int64_t mg_point_2d_srid(const mg_point_2d *point_2d);
10151020

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

1035+
/// Creates mg_point_3d from srid, x_longitude, y_latitude and z_height.
1036+
/// \return a pointer to mg_point_3d or NULL if an error occured.
1037+
MGCLIENT_EXPORT mg_point_3d *mg_point_3d_make(uint16_t srid, double x_longitude,
1038+
double y_latitude,
1039+
double z_height);
1040+
10301041
/// Returns SRID of the 3D point.
10311042
MGCLIENT_EXPORT int64_t mg_point_3d_srid(const mg_point_3d *point_3d);
10321043

@@ -1221,7 +1232,7 @@ typedef int (*mg_trust_callback_type)(const char *, const char *, const char *,
12211232
const char *, void *);
12221233

12231234
/// Creates a new `mg_session_params` object.
1224-
MGCLIENT_EXPORT mg_session_params *mg_session_params_make();
1235+
MGCLIENT_EXPORT mg_session_params *mg_session_params_make(void);
12251236

12261237
/// Destroys a `mg_session_params` object.
12271238
MGCLIENT_EXPORT void mg_session_params_destroy(mg_session_params *);

src/apple/mgsocket.c

+3-5
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
#include <string.h>
1818

19-
#include "mgcommon.h"
20-
2119
#define MG_RETRY_ON_EINTR(expression) \
2220
__extension__({ \
2321
long result; \
@@ -27,7 +25,7 @@
2725
result; \
2826
})
2927

30-
int mg_socket_init() { return MG_SUCCESS; }
28+
int mg_socket_init(void) { return MG_SUCCESS; }
3129

3230
int mg_socket_create(int af, int type, int protocol) {
3331
int sockfd = socket(af, type, protocol);
@@ -92,6 +90,6 @@ int mg_socket_pair(int d, int type, int protocol, int *sv) {
9290

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

95-
char *mg_socket_error() { return strerror(errno); }
93+
char *mg_socket_error(void) { return strerror(errno); }
9694

97-
void mg_socket_finalize() {}
95+
void mg_socket_finalize(void) {}

src/linux/mgsocket.c

+3-5
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
#include <stdlib.h>
1818
#include <string.h>
1919

20-
#include "mgcommon.h"
21-
2220
#ifdef __EMSCRIPTEN__
2321
#include "emscripten.h"
2422
#include "mgwasm.h"
@@ -36,7 +34,7 @@
3634
// Please refer to https://man7.org/linux/man-pages/man2 for more details about
3735
// Linux system calls.
3836

39-
int mg_socket_init() { return MG_SUCCESS; }
37+
int mg_socket_init(void) { return MG_SUCCESS; }
4038

4139
int mg_socket_create(int af, int type, int protocol) {
4240
int sockfd = socket(af, type, protocol);
@@ -151,6 +149,6 @@ int mg_socket_pair(int d, int type, int protocol, int *sv) {
151149

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

154-
char *mg_socket_error() { return strerror(errno); }
152+
char *mg_socket_error(void) { return strerror(errno); }
155153

156-
void mg_socket_finalize() {}
154+
void mg_socket_finalize(void) {}

src/mgclient.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
#include "mgtransport.h"
3030
#include "mgvalue.h"
3131

32-
const char *mg_client_version() { return MGCLIENT_VERSION; }
32+
const char *mg_client_version(void) { return MGCLIENT_VERSION; }
3333

34-
int mg_init_session_static_vars() {
34+
int mg_init_session_static_vars(void) {
3535
mg_value *n_val = mg_value_make_integer(-1);
3636
if (!n_val) {
3737
goto fatal_failure;
@@ -55,13 +55,13 @@ int mg_init_session_static_vars() {
5555
return MG_ERROR_CLIENT_ERROR;
5656
}
5757

58-
int mg_init() {
58+
int mg_init(void) {
5959
int init_status = mg_init_session_static_vars();
6060
if (init_status != 0) return init_status;
6161
return mg_socket_init();
6262
}
6363

64-
void mg_finalize() { mg_socket_finalize(); }
64+
void mg_finalize(void) { mg_socket_finalize(); }
6565

6666
typedef struct mg_session_params {
6767
const char *address;
@@ -79,7 +79,7 @@ typedef struct mg_session_params {
7979
void *trust_data;
8080
} mg_session_params;
8181

82-
mg_session_params *mg_session_params_make() {
82+
mg_session_params *mg_session_params_make(void) {
8383
mg_session_params *params =
8484
mg_allocator_malloc(&mg_system_allocator, sizeof(mg_session_params));
8585
if (!params) {

src/mgsession-encoder.c

+23-4
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,27 @@ int mg_session_write_duration(mg_session *session, const mg_duration *dur) {
168168
return 0;
169169
}
170170

171+
int mg_session_write_point_2d(mg_session *session, const mg_point_2d *point) {
172+
MG_RETURN_IF_FAILED(
173+
mg_session_write_uint8(session, (uint8_t)(MG_MARKER_TINY_STRUCT3)));
174+
MG_RETURN_IF_FAILED(mg_session_write_uint8(session, MG_SIGNATURE_POINT_2D));
175+
MG_RETURN_IF_FAILED(mg_session_write_integer(session, point->srid));
176+
MG_RETURN_IF_FAILED(mg_session_write_float(session, point->x));
177+
MG_RETURN_IF_FAILED(mg_session_write_float(session, point->y));
178+
return 0;
179+
}
180+
181+
int mg_session_write_point_3d(mg_session *session, const mg_point_3d *point) {
182+
MG_RETURN_IF_FAILED(
183+
mg_session_write_uint8(session, (uint8_t)(MG_MARKER_TINY_STRUCT4)));
184+
MG_RETURN_IF_FAILED(mg_session_write_uint8(session, MG_SIGNATURE_POINT_3D));
185+
MG_RETURN_IF_FAILED(mg_session_write_integer(session, point->srid));
186+
MG_RETURN_IF_FAILED(mg_session_write_float(session, point->x));
187+
MG_RETURN_IF_FAILED(mg_session_write_float(session, point->y));
188+
MG_RETURN_IF_FAILED(mg_session_write_float(session, point->z));
189+
return 0;
190+
}
191+
171192
int mg_session_write_value(mg_session *session, const mg_value *value) {
172193
switch (value->type) {
173194
case MG_VALUE_TYPE_NULL:
@@ -219,11 +240,9 @@ int mg_session_write_value(mg_session *session, const mg_value *value) {
219240
case MG_VALUE_TYPE_DURATION:
220241
return mg_session_write_duration(session, value->duration_v);
221242
case MG_VALUE_TYPE_POINT_2D:
222-
mg_session_set_error(session, "tried to send value of type 'point_2d'");
223-
return MG_ERROR_INVALID_VALUE;
243+
return mg_session_write_point_2d(session, value->point_2d_v);
224244
case MG_VALUE_TYPE_POINT_3D:
225-
mg_session_set_error(session, "tried to send value of type 'point_3d'");
226-
return MG_ERROR_INVALID_VALUE;
245+
return mg_session_write_point_3d(session, value->point_3d_v);
227246
case MG_VALUE_TYPE_UNKNOWN:
228247
mg_session_set_error(session, "tried to send value of unknown type");
229248
return MG_ERROR_INVALID_VALUE;

src/mgsocket.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ typedef long ssize_t;
5454

5555
/// Initializes underlying resources. Has to be called at the beginning of a
5656
/// process using socket resources.
57-
int mg_socket_init();
57+
int mg_socket_init(void);
5858

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

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

115115
/// Should be called at the end of any process which previously called the
116116
/// \ref mg_socket_init function.
117-
void mg_socket_finalize();
117+
void mg_socket_finalize(void);
118118

119119
#ifdef __cplusplus
120120
}

src/mgtransport.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include "mgtransport.h"
1616

1717
#include <assert.h>
18-
#include <errno.h>
1918
#include <stdlib.h>
2019
#include <string.h>
2120
#ifdef MGCLIENT_ON_LINUX
@@ -26,7 +25,6 @@
2625

2726
#include "mgallocator.h"
2827
#include "mgclient.h"
29-
#include "mgcommon.h"
3028
#include "mgsocket.h"
3129
#ifdef __EMSCRIPTEN__
3230
#include "mgwasm.h"
@@ -160,7 +158,7 @@ static char *hex_encode(unsigned char *data, unsigned int len,
160158
return encoded;
161159
}
162160

163-
static void mg_openssl_init() {
161+
static void mg_openssl_init(void) {
164162
#if OPENSSL_VERSION_NUMBER < 0x10100000L
165163
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
166164
static int mg_ssl_initialized = 0;

0 commit comments

Comments
 (0)