diff options
Diffstat (limited to 'lib/stream.ml')
-rw-r--r-- | lib/stream.ml | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/lib/stream.ml b/lib/stream.ml index e790980..6b46ed6 100644 --- a/lib/stream.ml +++ b/lib/stream.ml @@ -50,6 +50,12 @@ let parse_features (stanza : Xml.element) : features = | [], [STARTTLS] -> [STARTTLS], [] | _ -> features +(** [start domain portal] is a promise to features that starts a stream negotiation with + the XMPP server [portal]. *) +let start (domain : string) (portal : Portal.t) : features Lwt.t = + let* _id = Portal.header domain portal + in Wire.get portal.stream >|= parse_features + let negotiate_feature (mandatory : bool) (feat : feature) (portal : Portal.t) ({starttls; sasl; _} : config) : unit Lwt.t = (* authenticate using SASL with the XMPP server. *) @@ -94,19 +100,14 @@ let negotiate | Mechanisms _ | STARTTLS -> true | _ -> false in - (* Restart a stream: Send the usual business, ask for features. *) - let start_stream () : features Lwt.t = - let* _id = Portal.header domain portal - in Wire.get portal.stream >|= parse_features - in let rec handle_features (f : features) : features Lwt.t = match f with | m :: mandatory, optional -> let* () = negotiate_feature true m portal config in if needs_restart m - then start_stream () >>= handle_features + then start domain portal >>= handle_features else handle_features (mandatory, optional) | [], _ -> Lwt.return f - in start_stream () >>= handle_features + in start domain portal >>= handle_features (** [initiate domain] initiates a stream with the XMPP server [domain]. *) let initiate (domain : string) (config : config) : (Portal.t * features) Lwt.t = |