aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClombrong <cromblong@egregore.fun>2025-06-18 22:09:25 +0200
committerClombrong <cromblong@egregore.fun>2025-06-18 22:09:25 +0200
commitc90fe3ed3f35ea01b0d1299a0e721a5ab902ca11 (patch)
tree8d872f86d95cf887a2eb110a4ec697815ab42408
parentb039051748d023a004f2c8848a756b8fb67617b1 (diff)
style: change fill-column to 88
-rw-r--r--.dir-locals.el1
-rw-r--r--lib/sasl.ml9
-rw-r--r--lib/stream.ml6
-rw-r--r--portal/lib/ws/portal.ml60
4 files changed, 47 insertions, 29 deletions
diff --git a/.dir-locals.el b/.dir-locals.el
index 228d9a7..b97f826 100644
--- a/.dir-locals.el
+++ b/.dir-locals.el
@@ -2,6 +2,7 @@
;;; For more information see (info "(emacs) Directory Variables")
((nil . ((jinx-dir-local-words . "Lwt")
+ (fill-column . 88)
(eval . (let
((opam-share
(car
diff --git a/lib/sasl.ml b/lib/sasl.ml
index 8fbb8b2..c745aaa 100644
--- a/lib/sasl.ml
+++ b/lib/sasl.ml
@@ -29,12 +29,15 @@ let send_auth_stanza (stream, push) localpart pass mechanism =
| `Text t :: _ -> Some (String.concat "" t)
| _ -> None
and parse_descriptive_text = function
- | `Start_element ((_, "text"), [((_, "lang"), lang)]) :: `Text desc :: _ -> Some (lang, String.concat "" desc)
- | `Start_element ((_, "text"), []) :: `Text desc :: _ -> Some ("en", String.concat "" desc)
+ | `Start_element ((_, "text"), [((_, "lang"), lang)]) :: `Text desc :: _ ->
+ Some (lang, String.concat "" desc)
+ | `Start_element ((_, "text"), []) :: `Text desc :: _ ->
+ Some ("en", String.concat "" desc)
| _ -> None
in
let parse_error_stanza = function
- | `Start_element ((_, error), _) :: `End_element :: rest -> (parse_sasl_error error, parse_descriptive_text rest)
+ | `Start_element ((_, error), _) :: `End_element :: rest ->
+ (parse_sasl_error error, parse_descriptive_text rest)
| _ -> raise (InvalidStanza string_stanza)
in match stanza with
| `Start_element ((_, "success"), _) :: rest -> Ok (parse_additional_info rest)
diff --git a/lib/stream.ml b/lib/stream.ml
index adf852c..1363352 100644
--- a/lib/stream.ml
+++ b/lib/stream.ml
@@ -9,7 +9,8 @@ type auth_mechanism =
| Unknown of string [@@deriving show { with_path = false }]
let get (stream : (signal, async) stream) : (signal, sync) stream Lwt.t =
- (** [stanza stream] is a promise containing a full stanza of the fragments of [stream].*)
+ (** [stanza stream] is a promise containing a full stanza of the fragments of
+ [stream]. *)
let traverse_stanza depth fragment =
let depth = match fragment with
@@ -20,7 +21,8 @@ let get (stream : (signal, async) stream) : (signal, sync) stream Lwt.t =
in transform traverse_stanza 0 stream |> Markup_lwt.load
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. *)
let* stream, _push = Portal.connect domain
diff --git a/portal/lib/ws/portal.ml b/portal/lib/ws/portal.ml
index 0be0d81..3fd142a 100644
--- a/portal/lib/ws/portal.ml
+++ b/portal/lib/ws/portal.ml
@@ -9,7 +9,8 @@ type t = (signal, async) stream * ((signal, sync) stream option -> unit)
let xmlns = "urn:ietf:params:xml:ns:xmpp-framing"
-(* sic. XEP-0156: "host-meta files MUST be fetched only over HTTPS". I don't make the rules. *)
+(* sic. XEP-0156: "host-meta files MUST be fetched only over HTTPS". I don't make the
+ rules. *)
let well_known_of (domain : string) = "https://" ^ domain ^ "/.well-known/host-meta"
let stanza_open ?from domain : (signal, sync) stream =
@@ -37,15 +38,18 @@ let stanza_close = {|<close xmlns="|} ^ xmlns ^ {|" />|} |> string |> parse_xml
exception MalformedStanza of Markup.location * Markup.Error.t
let ws_endpoint (domain : string) =
- (** [ws_endpoint domain] is a promise containing the XMPP websocket endpoint associated with [domain], by using the
- domain's Web-host Metadata.
+ (** [ws_endpoint domain] is a promise containing the XMPP websocket endpoint
+ associated with [domain], by using the domain's Web-host Metadata.
- This function uses XMLHttpRequest, so while it should work fine in the browser, in environments that don't provide
- this constructor (Node.js), there should be some sort of polyfill.
+ This function uses XMLHttpRequest, so while it should work fine in the browser, in
+ environments that don't provide this constructor (Node.js), there should be some
+ sort of polyfill.
- Lastly, if [domain] doesn't provide a well-formed Web-host Metadata file, the function throws an exception. *)
+ Lastly, if [domain] doesn't provide a well-formed Web-host Metadata file, the
+ function throws an exception. *)
let open Markup in
- (* This ugly function extracts the href element from a Link tag's attributes if it's a websocket. *)
+ (* This ugly function extracts the href element from a Link tag's attributes if it's a
+ websocket. *)
let link_websocket = function
| ((_, "rel"), "urn:xmpp:alt-connections:websocket") :: ((_, "href"), href) :: _
| ((_, "href"), href) :: ((_, "rel"), "urn:xmpp:alt-connections:websocket") :: _
@@ -62,17 +66,18 @@ let ws_endpoint (domain : string) =
| _ -> None
)
|> Option.join
- in let+ host_meta = Js_of_ocaml_lwt.XmlHttpRequest.perform_raw_url (well_known_of domain)
+ in let+ host_meta =
+ Js_of_ocaml_lwt.XmlHttpRequest.perform_raw_url (well_known_of domain)
in match parse_xrd host_meta.content with
- | Some x -> x
- | None -> failwith (domain ^ "doesn't advertise a WebSocket endpoint via Web-host Metadata.")
+ | Some x -> x
+ | None -> failwith (domain ^ "doesn't advertise a WebSocket endpoint via Web-host Metadata.")
let ws_stream (url : string) =
- (** [ws_stream url] is a promise to a framed Lwt stream (and its push function) communicating with the websocket
- located at [url] using the XMPP protocol.
+ (** [ws_stream url] is a promise to a framed Lwt stream (and its push function)
+ communicating with the websocket located at [url] using the XMPP protocol.
- Valid XMPP WebSocket subprotocol frames must be sent to the stream, because it directly exposes the websocket
- under.
+ Valid XMPP WebSocket subprotocol frames must be sent to the stream, because it
+ directly exposes the websocket under.
Pushing [None] closes the websocket.
@@ -81,7 +86,8 @@ let ws_stream (url : string) =
let stream, message = create () in
let open Lwt_condition in
let is_open = create () in
- let (ws : WebSockets.webSocket Js.t) = new%js WebSockets.webSocket_withProtocol (jss url) (jss "xmpp")
+ let (ws : WebSockets.webSocket Js.t) =
+ new%js WebSockets.webSocket_withProtocol (jss url) (jss "xmpp")
in let push = function
| Some msg -> ws##send (jss msg)
| None -> ws##close
@@ -91,13 +97,15 @@ let ws_stream (url : string) =
let+ () = wait is_open in stream, push
let connect domain =
- (** [connect domain] is an Lwt stream (and its push function) communicating with the XMPP server running at [domain]
- via the Websocket subprotocol.
+ (** [connect domain] is an Lwt stream (and its push function) communicating with the
+ XMPP server running at [domain] via the Websocket subprotocol.
- This function is a complex wrapper around ws_stream, that accepts Markup.ml signals and sends framed XML stanzas
- to the underlying socket, with exactly one stanza per frame, according to RFC 7935.
+ This function is a complex wrapper around ws_stream, that accepts Markup.ml
+ signals and sends framed XML stanzas to the underlying socket, with exactly one
+ stanza per frame, according to RFC 7935.
- In essence, it (tries to) expose an identical interface to the original XMPP streamed protocol.
+ In essence, it (tries to) expose an identical interface to the original XMPP
+ streamed protocol.
Here's an ASCII rendered flow of the data through the various streams.
/ -> push -> mu_stream -> to_frames -> ws_push -> \
@@ -105,15 +113,19 @@ let connect domain =
\ <--- stream <--- markup_lwt <--- ws_stream <--- / *)
let+ ws_stream, ws_push = ws_endpoint domain >>= ws_stream in
let open Markup_lwt in
- (* When sending a malformed stanza (one that Markup.ml doesn't like), a MalformedStanza exception is raised. *)
+ (* When sending a malformed stanza (one that Markup.ml doesn't like), a
+ MalformedStanza exception is raised. *)
let report loc err =
raise (MalformedStanza (loc, err))
in
- (* Consumes a stream of Markup.ml signals into a series of frames sent to the WebSocket. *)
+ (* Consumes a stream of Markup.ml signals into a series of frames sent to the
+ WebSocket. *)
let stanza = ref [] in
let total_depth = ref 0 in
- let stanza_to_string stanza = Markup.(!stanza |> List.rev |> of_list |> write_xml |> to_string) in
- (* Consume a single fragment, and add it to the "stanza" ref if it's not complete -- as soon as it's completed, send it. *)
+ let stanza_to_string stanza =
+ Markup.(!stanza |> List.rev |> of_list |> write_xml |> to_string) in
+ (* Consume a single fragment, and add it to the "stanza" ref if it's not complete --
+ as soon as it's completed, send it. *)
let chomp_fragment depth fragment =
let depth = match fragment with
| `Start_element _ -> depth + 1