Skip to content

Commit 6c79f7b

Browse files
committed
Add support for libstrophe-0.13 and 0.14
1 parent 2a1a4bd commit 6c79f7b

File tree

23 files changed

+472
-394
lines changed

23 files changed

+472
-394
lines changed

.github/workflows/libstrophe.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ jobs:
1818
- 0.10.1
1919
- 0.11.0
2020
- 0.12.3
21+
- 0.13.1
22+
- 0.14.0
2123
runs-on: ubuntu-24.04
2224
env:
2325
LIBSTROPHE_VERSION: ${{ matrix.libstrophe-version }}
@@ -35,10 +37,6 @@ jobs:
3537
with:
3638
components: clippy,rustfmt
3739

38-
- name: Checks
39-
run: ci/checks.sh
40-
shell: bash
41-
4240
- name: Test
4341
run: ci/script.sh
4442
shell: bash

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ names = "0.14"
3333
trybuild = "1"
3434

3535
[features]
36-
default = ["rust-log", "libstrophe-0_12_0"]
36+
default = ["rust-log", "libstrophe-0_14"]
3737
buildtime_bindgen = ["sys/buildtime_bindgen"]
3838
libstrophe-0_9_3 = []
3939
libstrophe-0_10_0 = ["libstrophe-0_9_3"]
4040
libstrophe-0_11_0 = ["libstrophe-0_10_0"]
4141
libstrophe-0_12_0 = ["libstrophe-0_11_0"]
42+
libstrophe-0_13 = ["libstrophe-0_12_0"]
43+
libstrophe-0_14 = ["libstrophe-0_13"]
4244
rust-log = ["log"]

ci/0.13.1-tls-segfault.patch

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
From 9fef4b7d024b99aac9101bfa8b45cf78eef6508b Mon Sep 17 00:00:00 2001
2+
From: Steffen Jaeckel <[email protected]>
3+
Date: Wed, 10 Apr 2024 16:55:18 +0200
4+
Subject: [PATCH] Restore old interface if TLS connection failed
5+
6+
This was reported as creating a segfault in [0]
7+
8+
[0] https://github.com/profanity-im/profanity/issues/1963
9+
10+
Signed-off-by: Steffen Jaeckel <[email protected]>
11+
---
12+
src/conn.c | 2 ++
13+
1 file changed, 2 insertions(+)
14+
15+
diff --git a/src/conn.c b/src/conn.c
16+
index 73a2737a..d8c7ab1e 100644
17+
--- a/src/conn.c
18+
+++ b/src/conn.c
19+
@@ -1092,6 +1092,7 @@ int conn_tls_start(xmpp_conn_t *conn)
20+
}
21+
22+
if (conn->tls != NULL) {
23+
+ struct conn_interface old_intf = conn->intf;
24+
conn->intf = tls_intf;
25+
conn->intf.conn = conn;
26+
if (tls_start(conn->tls)) {
27+
@@ -1102,6 +1103,7 @@ int conn_tls_start(xmpp_conn_t *conn)
28+
tls_free(conn->tls);
29+
conn->tls = NULL;
30+
conn->tls_failed = 1;
31+
+ conn->intf = old_intf;
32+
}
33+
}
34+
if (rc != 0) {

ci/install.sh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,17 @@ build_dir=~/build
1616

1717
mkdir -p "$build_dir"
1818
curl -L "https://github.com/strophe/libstrophe/archive/$LIBSTROPHE_VERSION.tar.gz" | tar -xzC "$build_dir"
19-
pushd "$build_dir/libstrophe-$LIBSTROPHE_VERSION"
19+
if [[ "$LIBSTROPHE_VERSION" == "0.13.1" ]]; then
20+
pwd
21+
ls -lR
22+
# https://github.com/strophe/libstrophe/commit/9fef4b7d024b99aac9101bfa8b45cf78eef6508b
23+
patch -p1 -d "$build_dir" < ci/0.13.1-tls-segfault.patch
24+
fi
25+
cd "$build_dir/libstrophe-$LIBSTROPHE_VERSION"
2026
./bootstrap.sh
2127
./configure --prefix=/usr
2228
sudo make -j"$(nproc)" install
23-
popd
24-
sudo systemctl start ejabberd
29+
cd -
30+
31+
sudo sed -ri 's/starttls_required: true/starttls_required: false\n starttls: true/' /etc/ejabberd/ejabberd.yml
32+
sudo systemctl restart ejabberd

ci/script.sh

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,30 @@ verlte() {
77
[ "$1" = "`echo -e "$1\n$2" | sort -V | head -n1`" ]
88
}
99

10-
if verlte "0.9.3" "$LIBSTROPHE_VERSION"; then
11-
ARGS="--no-default-features --features=buildtime_bindgen,libstrophe-0_9_3"
10+
if verlte "0.14.0" "$LIBSTROPHE_VERSION"; then
11+
cargo test -v -- --test-threads=1
12+
cargo test -v --release -- --test-threads=1
13+
cargo test -v --features=buildtime_bindgen -- --test-threads=1
14+
cargo test -v --release --features=buildtime_bindgen -- --test-threads=1
15+
elif verlte "0.13.0" "$LIBSTROPHE_VERSION"; then
16+
ARGS="--no-default-features --features=buildtime_bindgen,libstrophe-0_13"
1217
cargo test -v $ARGS -- --test-threads=1
1318
cargo test -v $ARGS --release -- --test-threads=1
14-
fi
15-
16-
if verlte "0.10.0" "$LIBSTROPHE_VERSION"; then
17-
ARGS="--no-default-features --features=buildtime_bindgen,libstrophe-0_10_0"
19+
elif verlte "0.12.0" "$LIBSTROPHE_VERSION"; then
20+
ARGS="--no-default-features --features=buildtime_bindgen,libstrophe-0_12_0"
1821
cargo test -v $ARGS -- --test-threads=1
1922
cargo test -v $ARGS --release -- --test-threads=1
20-
fi
21-
22-
if verlte "0.11.0" "$LIBSTROPHE_VERSION"; then
23+
elif verlte "0.11.0" "$LIBSTROPHE_VERSION"; then
2324
ARGS="--no-default-features --features=buildtime_bindgen,libstrophe-0_11_0"
2425
cargo test -v $ARGS -- --test-threads=1
2526
cargo test -v $ARGS --release -- --test-threads=1
27+
elif verlte "0.10.0" "$LIBSTROPHE_VERSION"; then
28+
ARGS="--no-default-features --features=buildtime_bindgen,libstrophe-0_10_0"
29+
cargo test -v $ARGS -- --test-threads=1
30+
cargo test -v $ARGS --release -- --test-threads=1
31+
elif verlte "0.9.3" "$LIBSTROPHE_VERSION"; then
32+
ARGS="--no-default-features --features=buildtime_bindgen,libstrophe-0_9_3"
33+
cargo test -v $ARGS -- --test-threads=1
34+
cargo test -v $ARGS --release -- --test-threads=1
2635
fi
2736

28-
if verlte "0.12.0" "$LIBSTROPHE_VERSION"; then
29-
cargo test -v -- --test-threads=1
30-
cargo test -v --release -- --test-threads=1
31-
cargo test -v --features=buildtime_bindgen -- --test-threads=1
32-
cargo test -v --release --features=buildtime_bindgen -- --test-threads=1
33-
fi

libstrophe-sys-bindgen/build.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ fn build_wrapper() {
1616
}
1717

1818
fn int_macro(&self, name: &str, _value: i64) -> Option<IntKind> {
19-
if name == "XMPP_EOK" {
20-
Some(IntKind::I32)
19+
if name.starts_with("XMPP_E") {
20+
Some(IntKind::Int)
21+
} else if name.starts_with("XMPP_CONN_FLAG_") {
22+
Some(IntKind::Long)
2123
} else {
2224
None
2325
}

libstrophe-sys-bindgen/src/ffi.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ pub const XMPP_NS_REGISTER: &[u8; 19] = b"jabber:iq:register\0";
1717
pub const XMPP_NS_SM: &[u8; 14] = b"urn:xmpp:sm:3\0";
1818
pub const XMPP_NS_COMPRESSION: &[u8; 36] = b"http://jabber.org/protocol/compress\0";
1919
pub const XMPP_NS_FEATURE_COMPRESSION: &[u8; 36] = b"http://jabber.org/features/compress\0";
20-
pub const XMPP_EOK: i32 = 0;
21-
pub const XMPP_EMEM: i32 = -1;
22-
pub const XMPP_EINVOP: i32 = -2;
23-
pub const XMPP_EINT: i32 = -3;
24-
pub const XMPP_CONN_FLAG_DISABLE_TLS: u32 = 1;
25-
pub const XMPP_CONN_FLAG_MANDATORY_TLS: u32 = 2;
26-
pub const XMPP_CONN_FLAG_LEGACY_SSL: u32 = 4;
27-
pub const XMPP_CONN_FLAG_TRUST_TLS: u32 = 8;
28-
pub const XMPP_CONN_FLAG_LEGACY_AUTH: u32 = 16;
29-
pub const XMPP_CONN_FLAG_DISABLE_SM: u32 = 32;
30-
pub const XMPP_CONN_FLAG_ENABLE_COMPRESSION: u32 = 64;
31-
pub const XMPP_CONN_FLAG_COMPRESSION_DONT_RESET: u32 = 128;
20+
pub const XMPP_EOK: ::std::os::raw::c_int = 0;
21+
pub const XMPP_EMEM: ::std::os::raw::c_int = -1;
22+
pub const XMPP_EINVOP: ::std::os::raw::c_int = -2;
23+
pub const XMPP_EINT: ::std::os::raw::c_int = -3;
24+
pub const XMPP_CONN_FLAG_DISABLE_TLS: ::std::os::raw::c_long = 1;
25+
pub const XMPP_CONN_FLAG_MANDATORY_TLS: ::std::os::raw::c_long = 2;
26+
pub const XMPP_CONN_FLAG_LEGACY_SSL: ::std::os::raw::c_long = 4;
27+
pub const XMPP_CONN_FLAG_TRUST_TLS: ::std::os::raw::c_long = 8;
28+
pub const XMPP_CONN_FLAG_LEGACY_AUTH: ::std::os::raw::c_long = 16;
29+
pub const XMPP_CONN_FLAG_DISABLE_SM: ::std::os::raw::c_long = 32;
30+
pub const XMPP_CONN_FLAG_ENABLE_COMPRESSION: ::std::os::raw::c_long = 64;
31+
pub const XMPP_CONN_FLAG_COMPRESSION_DONT_RESET: ::std::os::raw::c_long = 128;
3232
pub const XMPP_SHA1_DIGEST_SIZE: u32 = 20;
3333
pub type __u_char = ::std::os::raw::c_uchar;
3434
pub type __u_short = ::std::os::raw::c_ushort;

libstrophe-sys-bindgen/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! This crate provides bindings to [libstrophe] C library which enables you the creation of XMPP
44
//! clients and servers. The bindings were statically generated using [bindgen] so the crate doesn't
55
//! have a hard dependency on bindgen. If you still want to regenerate the bindings during building
6-
//! of the create, enable `buildtime_bindgen` feature.
6+
//! of the crate, enable `buildtime_bindgen` feature.
77
//!
88
//! Usage of this crate creates runtime dependency on libstrophe.so so be sure to install that using
99
//! your package manager.

src/alloc_context.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,23 @@ impl AllocContext {
2323
unsafe fn write_real_alloc(p: *mut u8, size: usize) -> *mut c_void {
2424
#![allow(clippy::cast_ptr_alignment)]
2525
// it's ok to cast it as *mut AllocUnit=usize because we align to it during allocation and p points to the beginning of that buffer
26-
let out = p as *mut AllocUnit;
26+
let out = p.cast::<AllocUnit>();
2727
out.write(size);
28-
out.add(1) as _
28+
out.add(1).cast::<c_void>()
2929
}
3030

3131
#[inline(always)]
3232
unsafe fn read_real_alloc(p: *mut c_void) -> (*mut u8, alloc::Layout) {
3333
if p.is_null() {
3434
(
35-
p as _,
35+
p.cast::<u8>(),
3636
alloc::Layout::from_size_align(0, align_of::<AllocUnit>()).expect("Cannot create layout"),
3737
)
3838
} else {
39-
let memory = (p as *mut AllocUnit).sub(1);
39+
let memory = p.cast::<AllocUnit>().sub(1);
4040
let size = memory.read();
4141
(
42-
memory as _,
42+
memory.cast::<u8>(),
4343
alloc::Layout::from_size_align(size, align_of::<AllocUnit>()).expect("Cannot create layout"),
4444
)
4545
}
@@ -82,12 +82,12 @@ impl AllocContext {
8282
self.inner.as_ptr()
8383
}
8484

85-
/// [xmpp_free](https://strophe.im/libstrophe/doc/0.12.2/ctx_8c.html#acc734a5f5f115629c9e7775a4d3796e2)
85+
/// [xmpp_free](https://strophe.im/libstrophe/doc/0.13.0/ctx_8c.html#acc734a5f5f115629c9e7775a4d3796e2)
8686
///
8787
/// # Safety
8888
/// p must be non-null and allocated by the libstrophe library (xmpp_alloc function)
8989
pub unsafe fn free<T>(&self, p: *mut T) {
90-
sys::xmpp_free(self.inner.as_ptr(), p as _)
90+
sys::xmpp_free(self.inner.as_ptr(), p.cast::<c_void>())
9191
}
9292
}
9393

0 commit comments

Comments
 (0)