Skip to content

Commit 0dfef5f

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

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1359
-965
lines changed

.github/workflows/libstrophe.yml

+2-4
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

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[package]
22
name = "libstrophe"
33
version = "0.19.3"
4-
edition = "2021"
5-
rust-version = "1.82.0"
4+
edition = "2024"
5+
rust-version = "1.85.0"
66
description = "Rust ergonomic wrapper for libstrophe"
77
keywords = ["jabber", "xmpp", "libstrophe", "messaging", "im"]
88
categories = ["api-bindings", "network-programming"]
@@ -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

+34
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

+9-3
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

+19-15
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,31 @@ 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+
export RUSTFLAGS='-D warnings'
11+
if verlte "0.14.0" "$LIBSTROPHE_VERSION"; then
12+
cargo test -v -- --test-threads=1
13+
cargo test -v --release -- --test-threads=1
14+
cargo test -v --features=buildtime_bindgen -- --test-threads=1
15+
cargo test -v --release --features=buildtime_bindgen -- --test-threads=1
16+
elif verlte "0.13.0" "$LIBSTROPHE_VERSION"; then
17+
ARGS="--no-default-features --features=buildtime_bindgen,libstrophe-0_13"
1218
cargo test -v $ARGS -- --test-threads=1
1319
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"
20+
elif verlte "0.12.0" "$LIBSTROPHE_VERSION"; then
21+
ARGS="--no-default-features --features=buildtime_bindgen,libstrophe-0_12_0"
1822
cargo test -v $ARGS -- --test-threads=1
1923
cargo test -v $ARGS --release -- --test-threads=1
20-
fi
21-
22-
if verlte "0.11.0" "$LIBSTROPHE_VERSION"; then
24+
elif verlte "0.11.0" "$LIBSTROPHE_VERSION"; then
2325
ARGS="--no-default-features --features=buildtime_bindgen,libstrophe-0_11_0"
2426
cargo test -v $ARGS -- --test-threads=1
2527
cargo test -v $ARGS --release -- --test-threads=1
28+
elif verlte "0.10.0" "$LIBSTROPHE_VERSION"; then
29+
ARGS="--no-default-features --features=buildtime_bindgen,libstrophe-0_10_0"
30+
cargo test -v $ARGS -- --test-threads=1
31+
cargo test -v $ARGS --release -- --test-threads=1
32+
elif verlte "0.9.3" "$LIBSTROPHE_VERSION"; then
33+
ARGS="--no-default-features --features=buildtime_bindgen,libstrophe-0_9_3"
34+
cargo test -v $ARGS -- --test-threads=1
35+
cargo test -v $ARGS --release -- --test-threads=1
2636
fi
2737

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

src/examples/bot_closure.rs renamed to examples/bot_closure.rs

+22-29
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,38 @@
1-
// hack to emulate `extern crate libstrophe`
2-
mod libstrophe {
3-
pub use crate::*;
4-
}
1+
//! Port of https://github.com/strophe/libstrophe/blob/0.14.0/examples/bot.c
2+
3+
use libstrophe::{Connection, ConnectionEvent, Context, HandlerResult, Stanza};
54

6-
/// Port of the [bot.c](https://github.com/strophe/libstrophe/blob/0.12.2/examples/bot.c) code
7-
#[allow(dead_code)]
85
pub fn main() {
96
env_logger::init();
107

118
let jid = "[email protected]";
129
let pass = "<password>";
1310

14-
let version_handler = |_ctx: &libstrophe::Context, conn: &mut libstrophe::Connection, stanza: &libstrophe::Stanza| {
11+
let version_handler = |_ctx: &Context, conn: &mut Connection, stanza: &Stanza| {
1512
eprintln!("Received version request from {}", stanza.from().expect("Empty from"));
1613

1714
let mut reply = stanza.reply();
1815
reply.set_stanza_type("result").expect("Cannot set stanza type");
1916

20-
let mut query = libstrophe::Stanza::new();
17+
let mut query = Stanza::new();
2118
query.set_name("query").expect("Cannot set stanza name");
2219
if let Some(ns) = stanza.get_first_child().expect("No children").ns() {
2320
query.set_ns(ns).expect("Cannot set stanza ns");
2421
}
2522

26-
let mut name = libstrophe::Stanza::new();
23+
let mut name = Stanza::new();
2724
name.set_name("name").expect("Cannot set stanza name");
2825

29-
let mut text = libstrophe::Stanza::new();
26+
let mut text = Stanza::new();
3027
text.set_text("libstrophe example bot").expect("Cannot set stanza text");
3128
name.add_child(text).expect("Cannot add child");
3229

3330
query.add_child(name).expect("Cannot add child");
3431

35-
let mut version = libstrophe::Stanza::new();
32+
let mut version = Stanza::new();
3633
version.set_name("version").expect("Cannot set stanza name");
3734

38-
let mut text = libstrophe::Stanza::new();
35+
let mut text = Stanza::new();
3936
text.set_text("1.0").expect("Cannot set stanza text");
4037
version.add_child(text).expect("Cannot add child");
4138

@@ -44,31 +41,27 @@ pub fn main() {
4441
reply.add_child(query).expect("Cannot add child");
4542

4643
conn.send(&reply);
47-
libstrophe::HandlerResult::KeepHandler
44+
HandlerResult::KeepHandler
4845
};
4946

50-
let message_handler = |_ctx: &libstrophe::Context, conn: &mut libstrophe::Connection, stanza: &libstrophe::Stanza| {
47+
let message_handler = |_ctx: &Context, conn: &mut Connection, stanza: &Stanza| {
5148
let body = match stanza.get_child_by_name("body") {
5249
Some(body) => body,
53-
None => return libstrophe::HandlerResult::KeepHandler,
50+
None => return HandlerResult::KeepHandler,
5451
};
5552

5653
match stanza.stanza_type() {
5754
Some(typ) => {
5855
if typ == "error" {
59-
return libstrophe::HandlerResult::KeepHandler;
56+
return HandlerResult::KeepHandler;
6057
}
6158
}
62-
None => return libstrophe::HandlerResult::KeepHandler,
59+
None => return HandlerResult::KeepHandler,
6360
};
6461

6562
let intext = body.text().expect("Cannot get body");
6663

67-
eprintln!(
68-
"Incoming message from {}: {}",
69-
stanza.from().expect("Cannot get from"),
70-
intext
71-
);
64+
eprintln!("Incoming message from {}: {intext}", stanza.from().expect("Cannot get from"));
7265

7366
let mut reply = stanza.reply();
7467
if reply.stanza_type().is_none() {
@@ -78,7 +71,7 @@ pub fn main() {
7871
let (quit, replytext) = if intext == "quit" {
7972
(true, "bye!".to_owned())
8073
} else {
81-
(false, format!("{} to you too!", intext))
74+
(false, format!("{intext} to you too!"))
8275
};
8376
reply.set_body(replytext).expect("Cannot set body");
8477

@@ -88,26 +81,26 @@ pub fn main() {
8881
conn.disconnect();
8982
}
9083

91-
libstrophe::HandlerResult::KeepHandler
84+
HandlerResult::KeepHandler
9285
};
9386

94-
let conn_handler = move |ctx: &libstrophe::Context, conn: &mut libstrophe::Connection, evt: libstrophe::ConnectionEvent| {
95-
if let libstrophe::ConnectionEvent::Connect = evt {
87+
let conn_handler = move |ctx: &Context, conn: &mut Connection, evt: ConnectionEvent| {
88+
if let ConnectionEvent::Connect = evt {
9689
eprintln!("Connected");
9790
conn.handler_add(version_handler, Some("jabber:iq:version"), Some("iq"), None);
9891
conn.handler_add(message_handler, None, Some("message"), None);
99-
let pres = libstrophe::Stanza::new_presence();
92+
let pres = Stanza::new_presence();
10093
conn.send(&pres);
10194
} else {
10295
eprintln!("Disconnected");
10396
ctx.stop();
10497
}
10598
};
10699

107-
let mut conn = libstrophe::Connection::new(libstrophe::Context::new_with_default_logger());
100+
let mut conn = Connection::new(Context::new_with_default_logger());
108101
conn.set_jid(jid);
109102
conn.set_pass(pass);
110-
let ctx = conn
103+
let mut ctx = conn
111104
.connect_client(None, None, conn_handler)
112105
.expect("Cannot connect to XMPP server");
113106
ctx.run();

0 commit comments

Comments
 (0)