Skip to content

Commit cf8a000

Browse files

File tree

17 files changed

+455
-0
lines changed

17 files changed

+455
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module(
2+
name = "paho.mqtt.c",
3+
version = "1.3.14",
4+
)
5+
6+
bazel_dep(name = "boringssl", version = "0.20250311.0")
7+
bazel_dep(name = "cmake_configure_file", version = "0.1.3")
8+
bazel_dep(name = "libuuid", version = "2.39.3.bcr.1")
9+
bazel_dep(name = "platforms", version = "0.0.11")
10+
bazel_dep(name = "rules_cc", version = "0.1.1")
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
load("@cmake_configure_file//:cmake_configure_file.bzl", "cmake_configure_file")
2+
load("@rules_cc//cc:defs.bzl", "cc_library")
3+
4+
cmake_configure_file(
5+
name = "configure_version_info",
6+
src = "src/VersionInfo.h.in",
7+
out = "VersionInfo.h",
8+
cmakelists = ["src/CMakeLists.txt"],
9+
defines = [
10+
"BUILD_TIMESTAMP=redacted",
11+
"PROJECT_VERSION=" + module_version(),
12+
"PROJECT_VERSION_MAJOR=" + module_version().split(".")[0],
13+
"PROJECT_VERSION_MINOR=" + module_version().split(".")[1],
14+
"PROJECT_VERSION_PATCH=" + module_version().split(".")[2],
15+
],
16+
)
17+
18+
_COMMON_SRCS = ["VersionInfo.h"] + glob(
19+
[
20+
"src/*.c",
21+
"src/*.h",
22+
],
23+
exclude = [
24+
"src/MQTTClient.c",
25+
"src/MQTTAsync.c",
26+
"src/MQTTAsyncUtils.c",
27+
"src/MQTTVersion.c",
28+
"src/MQTTAsync.h",
29+
"src/MQTTAsyncUtils.h",
30+
],
31+
)
32+
33+
_COMMON_HDRS = [
34+
"src/MQTTClientPersistence.h",
35+
"src/MQTTExportDeclarations.h",
36+
"src/MQTTProperties.h",
37+
"src/MQTTReasonCodes.h",
38+
"src/MQTTSubscribeOpts.h",
39+
"src/MQTTClient.h",
40+
]
41+
42+
_LOCAL_DEFINES = [
43+
"OPENSSL",
44+
"PAHO_MQTT_EXPORTS=1",
45+
] + select({
46+
"@platforms//os:windows": [],
47+
"//conditions:default": ["USE_LIBUUID"],
48+
})
49+
50+
_DEPS = [
51+
"@boringssl//:crypto",
52+
"@boringssl//:ssl",
53+
] + select({
54+
"@platforms//os:windows": [],
55+
"//conditions:default": ["@libuuid"],
56+
})
57+
58+
cc_library(
59+
name = "mqtt3cs",
60+
srcs = _COMMON_SRCS + ["src/MQTTClient.c"],
61+
hdrs = _COMMON_HDRS,
62+
includes = ["src"],
63+
local_defines = _LOCAL_DEFINES,
64+
visibility = ["//visibility:public"],
65+
deps = _DEPS,
66+
)
67+
68+
cc_library(
69+
name = "mqtt3as",
70+
srcs = _COMMON_SRCS + [
71+
"src/MQTTAsync.c",
72+
"src/MQTTAsyncUtils.c",
73+
],
74+
hdrs = _COMMON_HDRS + [
75+
"src/MQTTAsync.h",
76+
"src/MQTTAsyncUtils.h",
77+
],
78+
includes = ["src"],
79+
local_defines = _LOCAL_DEFINES,
80+
visibility = ["//visibility:public"],
81+
deps = _DEPS,
82+
)
83+
84+
alias(
85+
name = "paho.mqtt.c",
86+
actual = ":mqtt3as",
87+
visibility = ["//visibility:public"],
88+
)
89+
90+
# TODO: this doesn't seem to work yet...
91+
cc_binary(
92+
name = "MQTTVersion",
93+
srcs = ["src/MQTTVersion.c"],
94+
linkshared = True,
95+
linkstatic = False,
96+
local_defines = ["PAHO_MQTT_IMPORTS=1"],
97+
deps = [
98+
":mqtt3as",
99+
":mqtt3cs",
100+
],
101+
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../MODULE.bazel
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
diff --git a/src/Base64.c b/src/Base64.c
2+
index 4634af2fe..c673ce2a8 100644
3+
--- a/src/Base64.c
4+
+++ b/src/Base64.c
5+
@@ -48,40 +48,45 @@ static b64_size_t Base64_encodeDecode(
6+
b64_size_t ret = 0u;
7+
if ( in_len > 0u )
8+
{
9+
- int rv;
10+
- BIO *bio, *b64, *b_in, *b_out;
11+
-
12+
- b64 = BIO_new(BIO_f_base64());
13+
- bio = BIO_new(BIO_s_mem());
14+
- b64 = BIO_push(b64, bio);
15+
- BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL); /* ignore new-lines */
16+
-
17+
if ( encode )
18+
{
19+
- b_in = bio;
20+
- b_out = b64;
21+
+ /* For encoding: output length is 4 * (input_length / 3) rounded up to nearest multiple of 4 */
22+
+ b64_size_t required_len = ((in_len + 2) / 3) * 4;
23+
+ if (out_len >= required_len + 1) /* +1 for null terminator */
24+
+ {
25+
+ int encoded_len = EVP_EncodeBlock((unsigned char*)out, (const unsigned char*)in, (int)in_len);
26+
+ if (encoded_len > 0)
27+
+ {
28+
+ ret = (b64_size_t)encoded_len;
29+
+ if (out_len > ret)
30+
+ out[ret] = '\0';
31+
+ }
32+
+ }
33+
}
34+
else
35+
{
36+
- b_in = b64;
37+
- b_out = bio;
38+
- }
39+
-
40+
- rv = BIO_write(b_out, in, (int)in_len);
41+
- BIO_flush(b_out); /* indicate end of encoding */
42+
-
43+
- if ( rv > 0 )
44+
- {
45+
- rv = BIO_read(b_in, out, (int)out_len);
46+
- if ( rv > 0 )
47+
+ /* For decoding: output length is at most 3 * (input_length / 4) */
48+
+ b64_size_t max_out_len = (in_len / 4) * 3;
49+
+ if (out_len >= max_out_len + 1) /* +1 for null terminator */
50+
{
51+
- ret = (b64_size_t)rv;
52+
- if ( out_len > ret )
53+
- out[ret] = '\0';
54+
+ EVP_ENCODE_CTX *ctx = EVP_ENCODE_CTX_new();
55+
+ if (ctx)
56+
+ {
57+
+ int decoded_len = 0;
58+
+ int final_len = 0;
59+
+ unsigned char *temp_out = (unsigned char*)out;
60+
+
61+
+ EVP_DecodeInit(ctx);
62+
+ EVP_DecodeUpdate(ctx, temp_out, &decoded_len, (const unsigned char*)in, (int)in_len);
63+
+ EVP_DecodeFinal(ctx, temp_out + decoded_len, &final_len);
64+
+ EVP_ENCODE_CTX_free(ctx);
65+
+
66+
+ ret = (b64_size_t)(decoded_len + final_len);
67+
+ if (out_len > ret)
68+
+ out[ret] = '\0';
69+
+ }
70+
}
71+
}
72+
-
73+
- BIO_free_all(b64); /* free all used memory */
74+
}
75+
return ret;
76+
}
77+
diff --git a/src/MQTTAsyncUtils.c b/src/MQTTAsyncUtils.c
78+
index c084a11e3..208fa0917 100644
79+
--- a/src/MQTTAsyncUtils.c
80+
+++ b/src/MQTTAsyncUtils.c
81+
@@ -1864,7 +1864,7 @@ thread_return_type WINAPI MQTTAsync_sendThread(void* n)
82+
MQTTAsync_unlock_mutex(mqttasync_mutex);
83+
84+
#if defined(OPENSSL)
85+
-#if ((OPENSSL_VERSION_NUMBER < 0x1010000fL) || defined(LIBRESSL_VERSION_NUMBER))
86+
+#if ((OPENSSL_VERSION_NUMBER < 0x1010000fL) || defined(LIBRESSL_VERSION_NUMBER)) || defined(OPENSSL_IS_BORINGSSL)
87+
ERR_remove_state(0);
88+
#else
89+
OPENSSL_thread_stop();
90+
@@ -2397,7 +2397,7 @@ thread_return_type WINAPI MQTTAsync_receiveThread(void* n)
91+
#endif
92+
93+
#if defined(OPENSSL)
94+
-#if ((OPENSSL_VERSION_NUMBER < 0x1010000fL) || defined(LIBRESSL_VERSION_NUMBER))
95+
+#if ((OPENSSL_VERSION_NUMBER < 0x1010000fL) || defined(LIBRESSL_VERSION_NUMBER)) || defined(OPENSSL_IS_BORINGSSL)
96+
ERR_remove_state(0);
97+
#else
98+
OPENSSL_thread_stop();
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
matrix:
2+
platform: [debian11, ubuntu2404, macos, macos_arm64]
3+
bazel: [7.x, 8.x, rolling]
4+
tasks:
5+
verify_targets:
6+
name: Verify build targets
7+
platform: ${{ platform }}
8+
bazel: ${{ bazel }}
9+
build_flags: [--cxxopt=-std=c++17]
10+
build_targets: ["@paho.mqtt.c//..."]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"integrity": "sha256-evfZBuYKaWqA8bfCvX1usWSqrZCP9MQMMzKsIAbQc0Y=",
3+
"strip_prefix": "paho.mqtt.c-1.3.14",
4+
"url": "https://github.com/eclipse-paho/paho.mqtt.c/archive/refs/tags/v1.3.14.tar.gz",
5+
"patches": {
6+
"1594.patch": "sha256-PL4Mo0FnBzNN7HiYoi9ehrFkBfGGkVWF5MYS5cYmdwA="
7+
},
8+
"patch_strip": 1,
9+
"overlay": {
10+
"BUILD.bazel": "sha256-2b1tnwogEQVQD1sXtT2Oxus0OIBK73Caiq6l0UHwD3g=",
11+
"MODULE.bazel": "sha256-GqoH4F0/45bHLYKueVD+GXU28zVbsRYQSRpvN8E4eEc="
12+
}
13+
}

modules/paho.mqtt.c/metadata.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"homepage": "https://eclipse.org/paho",
3+
"maintainers": [
4+
{
5+
"email": "bcr@laure.nz",
6+
"github": "lalten",
7+
"github_user_id": 11611719,
8+
"name": "Laurenz Altenmueller"
9+
}
10+
],
11+
"repository": [
12+
"github:eclipse-paho/paho.mqtt.c"
13+
],
14+
"versions": [
15+
"1.3.14"
16+
],
17+
"yanked_versions": {}
18+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module(
2+
name = "paho.mqtt.cpp",
3+
version = "1.5.2",
4+
)
5+
6+
bazel_dep(name = "paho.mqtt.c", version = "1.3.14")
7+
bazel_dep(name = "rules_cc", version = "0.1.1")
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
load("@rules_cc//cc:defs.bzl", "cc_library")
2+
3+
cc_library(
4+
name = "paho.mqtt.cpp",
5+
srcs = glob(["src/*.cpp"]),
6+
hdrs = glob(["include/mqtt/*.h"]),
7+
includes = ["include"],
8+
local_defines = [
9+
"PAHO_MQTTPP_EXPORTS",
10+
"OPENSSL",
11+
],
12+
visibility = ["//visibility:public"],
13+
deps = ["@paho.mqtt.c"],
14+
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../MODULE.bazel
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
load("@rules_cc//cc:defs.bzl", "cc_test")
2+
3+
cc_test(
4+
name = "tests",
5+
srcs = glob(
6+
[
7+
"unit/*.cpp",
8+
"unit/*.h",
9+
],
10+
exclude = ["unit/test_async_client_v3.cpp"], # Needs Cppunit
11+
),
12+
data = glob(["ssl/*"]),
13+
local_defines = ["TEST_EXTERNAL_SERVER"],
14+
tags = ["requires-network"],
15+
deps = [
16+
"@catch2",
17+
"@paho.mqtt.cpp",
18+
],
19+
)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
bazel_dep(name = "paho.mqtt.cpp")
2+
local_path_override(
3+
module_name = "paho.mqtt.cpp",
4+
path = "..",
5+
)
6+
7+
bazel_dep(name = "rules_cc", version = "0.1.1")
8+
bazel_dep(name = "catch2", version = "3.8.0")
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
diff --git a/test/unit/test_async_client.cpp b/test/unit/test_async_client.cpp
2+
index dc19cbe..c746062 100644
3+
--- a/test/unit/test_async_client.cpp
4+
+++ b/test/unit/test_async_client.cpp
5+
@@ -36,7 +36,8 @@ using namespace mqtt;
6+
// NOTE: This test case requires network access. It uses one of
7+
// the public available MQTT brokers
8+
#if defined(TEST_EXTERNAL_SERVER)
9+
-static const std::string GOOD_SERVER_URI{"tcp://mqtt.eclipse.org:1883"};
10+
+static const std::string GOOD_SERVER_URI{"tcp://mqtt.eclipseprojects.io:1883"};
11+
+static const std::string GOOD_SSL_SERVER_URI{"ssl://mqtt.eclipseprojects.io:1885"};
12+
#else
13+
static const std::string GOOD_SERVER_URI{"tcp://localhost:1883"};
14+
static const std::string GOOD_SSL_SERVER_URI{"ssl://localhost:18885"};
15+
diff --git a/test/unit/test_async_client_v3.cpp b/test/unit/test_async_client_v3.cpp
16+
index a887ffc..8bd0eef 100644
17+
--- a/test/unit/test_async_client_v3.cpp
18+
+++ b/test/unit/test_async_client_v3.cpp
19+
@@ -98,7 +98,7 @@ class async_client_v3_test : public CppUnit::TestFixture
20+
// NOTE: This test case requires network access. It uses one of
21+
// the public available MQTT brokers
22+
#if defined(TEST_EXTERNAL_SERVER)
23+
- const std::string GOOD_SERVER_URI{"tcp://mqtt.eclipse.org:1883"};
24+
+ const std::string GOOD_SERVER_URI{"tcp://mqtt.eclipseprojects.io:1883"};
25+
#else
26+
const std::string GOOD_SERVER_URI{"tcp://localhost:1883"};
27+
const std::string GOOD_SSL_SERVER_URI{"ssl://localhost:18885"};
28+
diff --git a/test/unit/test_client.cpp b/test/unit/test_client.cpp
29+
index d39d5f6..9526b46 100644
30+
--- a/test/unit/test_client.cpp
31+
+++ b/test/unit/test_client.cpp
32+
@@ -40,7 +40,7 @@ using namespace mqtt;
33+
// NOTE: This test case requires network access. It uses one of
34+
// the public available MQTT brokers
35+
#if defined(TEST_EXTERNAL_SERVER)
36+
-static const std::string GOOD_SERVER_URI{"tcp://mqtt.eclipse.org:1883"};
37+
+static const std::string GOOD_SERVER_URI{"tcp://mqtt.eclipseprojects.io:1883"};
38+
#else
39+
static const std::string GOOD_SERVER_URI{"tcp://localhost:1883"};
40+
#endif

0 commit comments

Comments
 (0)