aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/stream.ml16
1 files changed, 16 insertions, 0 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