Skip to content

Commit 5053150

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

25 files changed

Lines changed: 1137 additions & 760 deletions

.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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,16 @@ sys = { package = "libstrophe-sys-bindgen", version = "7", path = "libstrophe-sy
2828

2929
[dev-dependencies]
3030
env_logger = "0.11"
31-
matches = "0.1"
3231
names = "0.14"
3332
trybuild = "1"
3433

3534
[features]
36-
default = ["rust-log", "libstrophe-0_12_0"]
35+
default = ["rust-log", "libstrophe-0_14"]
3736
buildtime_bindgen = ["sys/buildtime_bindgen"]
3837
libstrophe-0_9_3 = []
3938
libstrophe-0_10_0 = ["libstrophe-0_9_3"]
4039
libstrophe-0_11_0 = ["libstrophe-0_10_0"]
4140
libstrophe-0_12_0 = ["libstrophe-0_11_0"]
41+
libstrophe-0_13 = ["libstrophe-0_12_0"]
42+
libstrophe-0_14 = ["libstrophe-0_13"]
4243
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 <jaeckel-floss@eyet-services.de>
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 <jaeckel-floss@eyet-services.de>
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: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,15 @@ 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+
# https://github.com/strophe/libstrophe/commit/9fef4b7d024b99aac9101bfa8b45cf78eef6508b
21+
patch -p1 -d "$build_dir/libstrophe-$LIBSTROPHE_VERSION" < ci/0.13.1-tls-segfault.patch
22+
fi
23+
cd "$build_dir/libstrophe-$LIBSTROPHE_VERSION"
2024
./bootstrap.sh
2125
./configure --prefix=/usr
2226
sudo make -j"$(nproc)" install
23-
popd
24-
sudo systemctl start ejabberd
27+
cd -
28+
29+
sudo sed -ri 's/starttls_required: true/starttls_required: false\n starttls: true/' /etc/ejabberd/ejabberd.yml
30+
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: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use std::ffi::c_void;
2-
use std::mem::{align_of, size_of};
3-
use std::ptr::NonNull;
4-
use std::{alloc, ptr};
1+
use core::ffi::c_void;
2+
use core::mem::{align_of, size_of};
3+
use core::ptr;
4+
use core::ptr::NonNull;
5+
use std::alloc;
56

67
/// Internal `Context` that only specifies allocation functions and uses null logger. Needed to not pass
78
/// `Context` to e.g. `Stanza` because it uses only allocation functions from `Context`.
@@ -23,23 +24,23 @@ impl AllocContext {
2324
unsafe fn write_real_alloc(p: *mut u8, size: usize) -> *mut c_void {
2425
#![allow(clippy::cast_ptr_alignment)]
2526
// 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;
27+
let out = p.cast::<AllocUnit>();
2728
out.write(size);
28-
out.add(1) as _
29+
out.add(1).cast::<c_void>()
2930
}
3031

3132
#[inline(always)]
3233
unsafe fn read_real_alloc(p: *mut c_void) -> (*mut u8, alloc::Layout) {
3334
if p.is_null() {
3435
(
35-
p as _,
36+
p.cast::<u8>(),
3637
alloc::Layout::from_size_align(0, align_of::<AllocUnit>()).expect("Cannot create layout"),
3738
)
3839
} else {
39-
let memory = (p as *mut AllocUnit).sub(1);
40+
let memory = p.cast::<AllocUnit>().sub(1);
4041
let size = memory.read();
4142
(
42-
memory as _,
43+
memory.cast::<u8>(),
4344
alloc::Layout::from_size_align(size, align_of::<AllocUnit>()).expect("Cannot create layout"),
4445
)
4546
}
@@ -82,12 +83,12 @@ impl AllocContext {
8283
self.inner.as_ptr()
8384
}
8485

85-
/// [xmpp_free](https://strophe.im/libstrophe/doc/0.12.2/ctx_8c.html#acc734a5f5f115629c9e7775a4d3796e2)
86+
/// [xmpp_free](https://strophe.im/libstrophe/doc/0.13.0/ctx_8c.html#acc734a5f5f115629c9e7775a4d3796e2)
8687
///
8788
/// # Safety
8889
/// p must be non-null and allocated by the libstrophe library (xmpp_alloc function)
8990
pub unsafe fn free<T>(&self, p: *mut T) {
90-
sys::xmpp_free(self.inner.as_ptr(), p as _)
91+
sys::xmpp_free(self.inner.as_ptr(), p.cast::<c_void>())
9192
}
9293
}
9394

0 commit comments

Comments
 (0)