aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClombrong <cromblong@egregore.fun>2025-06-29 18:41:14 +0200
committerClombrong <cromblong@egregore.fun>2025-06-29 19:01:41 +0200
commitfa95a6ba1f42611c068b14941a141a995421d5f6 (patch)
tree80666af1e0b1ee2186e85d06dad428e8d0d5b420
parent1842a1fe0f21457d55c4479f2e3cb7a7b2c2b3e0 (diff)
feat(stream): detach starttls function from handle_features
-rw-r--r--lib/stream.ml17
1 files changed, 11 insertions, 6 deletions
diff --git a/lib/stream.ml b/lib/stream.ml
index 0ea7850..362b3ee 100644
--- a/lib/stream.ml
+++ b/lib/stream.ml
@@ -50,6 +50,15 @@ let parse_features (stanza : Xml.element) : features =
| [], [STARTTLS] -> [STARTTLS], []
| _ -> features
+(** [starttls mandatory portal config] negotiates STARTTLS and establishes a TLS
+ handshake with the XMPP server [portal], following the stream config [config].
+
+ If STARTLS is required during negotiation, [mandatory] is true. *)
+let starttls mandatory portal {starttls=config; _} =
+ if (mandatory || config.prefer_starttls)
+ then Starttls.upgrade portal
+ else Lwt.return_unit
+
(** [negotiate domain portal auth] is a promise containing the features supported by the
XMPP server [portal], after eventual STARTTLS negotiation and authentication using
the auth config [auth].
@@ -75,11 +84,7 @@ let negotiate
in
(* Handle a single feature. Mandatory is whether the feature is mandatory. *)
let handle_feature (mandatory : bool) (f : feature) : unit Lwt.t =
- let handle_starttls () =
- if (mandatory || config.starttls.prefer_starttls)
- then Starttls.upgrade portal
- else Lwt.return_unit
- and handle_mechanisms mechanisms =
+ let handle_mechanisms mechanisms =
let open Sasl in
let allow_auth () =
Portal._encrypted portal._socket ||
@@ -96,7 +101,7 @@ let negotiate
| Ok _ -> print_endline "Success!"; Lwt.return_unit
else Lwt.fail InsufficientEncryption
in match f with
- | STARTTLS -> handle_starttls ()
+ | STARTTLS -> starttls mandatory portal config
| Mechanisms m -> handle_mechanisms m
| _ -> Lwt.return_unit
in