diff options
author | Clombrong <cromblong@egregore.fun> | 2025-06-26 17:28:38 +0200 |
---|---|---|
committer | Clombrong <cromblong@egregore.fun> | 2025-06-27 08:56:27 +0200 |
commit | 7e83c196ca21aef56c42fd122f0d65cfa4becd6c (patch) | |
tree | c0defbf534c12b6cbaffe6a8b8aae27194df5bb1 | |
parent | 30f002289ef6f5dd544f25bc4965fa8f1761a199 (diff) |
feat(sasl): add negotiate function
-rw-r--r-- | lib/stream.ml | 16 | ||||
-rw-r--r-- | test/hello.ml | 3 |
2 files changed, 17 insertions, 2 deletions
diff --git a/lib/stream.ml b/lib/stream.ml index e3ed62f..ff3b939 100644 --- a/lib/stream.ml +++ b/lib/stream.ml @@ -1,3 +1,6 @@ +open Lwt.Syntax +open Lwt.Infix + exception ClosedStream type features = { @@ -31,3 +34,16 @@ let parse_features (el : Xml.element) : features = parse_feature {mechanisms=[]; starttls=`None; unknown=[]} (List.filter_map find_left el.children) + +(** [negotiate domain stream] is a promise containing the features supported by the + XMPP server communicating with [stream]. + + This function should be called every time a stream needs to be reopened and stream + negotiation takes place. + + Basically, it conforms to + {{: https://datatracker.ietf.org/doc/html/rfc6120#section-4.3 }}. *) +let negotiate (domain : string) ((stream, push) : Portal.t) : features Lwt.t = + let* _id = Portal.header domain (stream, push) + in let+ features = Xml.get stream >|= parse_features + in features diff --git a/test/hello.ml b/test/hello.ml index 1975871..1659787 100644 --- a/test/hello.ml +++ b/test/hello.ml @@ -20,8 +20,7 @@ let main = } in let domain = (List.nth (String.split_on_char '@' config.jid) 1) in let* stream, push = Portal.connect domain in - let* _id = Portal.header domain (stream, push) in - let* features = Xml.get stream >|= Stream.parse_features in + let* features = Stream.negotiate domain (stream, push) in Lwt.catch (fun () -> program (stream, push) config features >|= (fun () -> push None)) (fun exn -> |