aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorClombrong <cromblong@egregore.fun>2025-06-25 18:06:07 +0200
committerClombrong <cromblong@egregore.fun>2025-06-25 18:06:07 +0200
commit9b22f650dafeb8dc193dadd1a10182724382c6a7 (patch)
treed1d64e6b0fbef0c00273cd03f5c33efa90797ff9 /lib
parent5f52ab70862cfa8332ec5bd9d1dc3d3f6af37d16 (diff)
chore: move comments to correct location
Diffstat (limited to 'lib')
-rw-r--r--lib/stream.ml19
-rw-r--r--lib/xml.ml14
2 files changed, 16 insertions, 17 deletions
diff --git a/lib/stream.ml b/lib/stream.ml
index 4781161..21c134d 100644
--- a/lib/stream.ml
+++ b/lib/stream.ml
@@ -18,10 +18,9 @@ type stream_features = {
unknown_features : Xml.element list;
}
+(** [next stream] is a promise containing a full stanza of the fragments of
+ [stream]. *)
let next (stream : (signal, async) stream) : (signal, sync) stream Lwt.t =
- (** [next stream] is a promise containing a full stanza of the fragments of
- [stream]. *)
-
let traverse_stanza depth fragment =
let depth = match fragment with
| `Start_element _ -> depth + 1
@@ -30,18 +29,18 @@ let next (stream : (signal, async) stream) : (signal, sync) stream Lwt.t =
in ([fragment], if depth = 0 then None else Some depth)
in transform traverse_stanza 0 stream |> Markup_lwt.load
+(** [get stream] is a promise containing a single Xml element of [stream]. *)
let get (stream : (signal, async) stream) : Xml.element Lwt.t =
- (** [get stream] is a promise containing a single Xml element of [stream]. *)
let* signal = next stream
in match Xml.tree signal with
| Some xml -> Lwt.return xml
| None -> Lwt.fail (InvalidStanza (signal |> write_xml |> to_string))
-let start domain : Portal.t Lwt.t =
- (** [start domain] is a promise containing a Portal (stream * push) connected to the
- XMPP server [domain].
+(** [start domain] is a promise containing a Portal (stream * push) connected to the
+ XMPP server [domain].
- Currently, it doesn't handle anything except the initial [<open/>] stanza. *)
+ Currently, it doesn't handle anything except the initial [<open/>] stanza. *)
+let start domain : Portal.t Lwt.t =
let* stream, _push = Portal.connect domain
in let push = function
| None -> _push (Some Portal.stanza_close);
@@ -52,9 +51,9 @@ let start domain : Portal.t Lwt.t =
let+ _ = get stream
in stream, push
+(** [parse_features el] is a [stream_features] record with all the features of the
+ [<stream:features>] stanza contained in [el]. *)
let parse_features (el : Xml.element) : stream_features =
- (** [parse_features el] is a [stream_features] record with all the features of the
- [<stream:features>] stanza contained in [el]. *)
let open Xml in
let open Either in
let parse_mechanism_stanza = function
diff --git a/lib/xml.ml b/lib/xml.ml
index dff9652..840aaf0 100644
--- a/lib/xml.ml
+++ b/lib/xml.ml
@@ -7,9 +7,9 @@ type element = {
children : (element, string) Either.t list;
}
+(** [tree s] is an [element option] representing the XML element inside of stream [s],
+ if [s] is a complete element from start to end. *)
let tree s : element option =
- (** [tree s] is an [element option] representing the XML element inside of stream [s],
- if [s] is a complete element from start to end. *)
let element (namespace, name) attributes children =
Either.Left {
namespace;
@@ -27,12 +27,12 @@ let tree s : element option =
let opt_el = tree ~text ~element s in
Option.bind opt_el (Either.fold ~left:Option.some ~right:(fun _ -> None))
-let element_to_string ?(indent = 2) (el : element) =
- (** [element_to_string element] is a string representation of the underlying XML in
- [element], for debugging purposes.
+(** [element_to_string element] is a string representation of the underlying XML in
+ [element], for debugging purposes.
- Note this isn't serialization: namely, XML namespaces are inferred and don't exist
- in the actual [element]. *)
+ Note this isn't serialization: namely, XML namespaces are inferred and don't exist
+ in the actual [element]. *)
+let element_to_string ?(indent = 2) (el : element) =
let rec element_to_string parent {local_name; attributes; children; namespace} =
let attributes =
(if parent == namespace then "" else " xmlns=\"" ^ namespace ^ "\"") ^