aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClombrong <cromblong@egregore.fun>2025-06-30 20:09:13 +0200
committerClombrong <cromblong@egregore.fun>2025-07-26 21:55:11 +0200
commit519cca49042948b01b63ba2a6eb5392de11d69bd (patch)
tree55a53ca88bfaecbc584f6886a91e9886c0ff2313
parent6157a418a779bbb8c862332e6cae3f03d45a7665 (diff)
feat(sasl): use Jid.t as the jid type
-rw-r--r--lib/sasl.ml10
-rw-r--r--test/hello.ml34
2 files changed, 17 insertions, 27 deletions
diff --git a/lib/sasl.ml b/lib/sasl.ml
index 3cd1220..a7f30d9 100644
--- a/lib/sasl.ml
+++ b/lib/sasl.ml
@@ -5,7 +5,7 @@ type mechanism =
| Unknown of string [@@deriving show { with_path = false }]
type config = {
- jid : string;
+ jid : Jid.t;
password : string;
preferred_mechanisms : mechanism list;
}
@@ -66,11 +66,9 @@ let authenticate
(portal : Portal.t)
({jid; password; preferred_mechanisms} : config)
(sasl_mechanisms : mechanism list) =
- (* Probably not exactly compliant with https://xmpp.org/extensions/xep-0029.html,
- but it's just for simplicity's sake in alpha. *)
- let localpart = match String.split_on_char '@' jid with
- | [localpart; _domain] -> localpart
- | _ -> failwith "Invalid JID"
+ let localpart = match jid.localpart with
+ | Some l -> l
+ | None -> failwith "Invalid JID: No localpart"
and preferred, not_preferred =
List.partition (fun f -> List.exists ((=) f) preferred_mechanisms) sasl_mechanisms
in
diff --git a/test/hello.ml b/test/hello.ml
index a43b90a..55a735e 100644
--- a/test/hello.ml
+++ b/test/hello.ml
@@ -6,30 +6,22 @@ let main =
let config : Stream.config = {
starttls = {prefer = true};
sasl = {
- jid = (Sys.getenv "FLESH_JID");
+ jid = Jid.of_string (Sys.getenv "FLESH_JID");
password = (Sys.getenv "FLESH_PASSWORD");
preferred_mechanisms = [Sasl.PLAIN]
};
other = [];
}
in
- begin
- let jid = Jid.of_string (Sys.getenv "FLESH_JID")
- in
- Option.iter print_endline jid.localpart;
- print_endline jid.domainpart;
- Option.iter print_endline jid.resourcepart;
- end;
- let domain = (List.nth (String.split_on_char '@' config.sasl.jid) 1) in
- try%lwt connect domain config >|= (fun (portal, _) -> portal.push None)
- with exn ->
- begin
- (* I suspect JavaScript's [wrap_callback] swallows the Exceptions thrown by
- OCaml, so... The next best thing is probably printing something. *)
- print_endline
- (match exn with
- | Xml.InvalidStanza stanza -> "Invalid stanza: " ^ stanza
- | Portal.MalformedStanza err -> "Server sent malformed stanza: " ^ (Markup.Error.to_string err)
- | _ -> "... and so I stumble back to bed.");
- Lwt.fail exn
- end
+ try%lwt connect config.sasl.jid.domainpart config >|= (fun (portal, _) -> portal.push None)
+ with exn ->
+ begin
+ (* I suspect JavaScript's [wrap_callback] swallows the Exceptions thrown by
+ OCaml, so... The next best thing is probably printing something. *)
+ print_endline
+ (match exn with
+ | Xml.InvalidStanza stanza -> "Invalid stanza: " ^ stanza
+ | Portal.MalformedStanza err -> "Server sent malformed stanza: " ^ (Markup.Error.to_string err)
+ | _ -> "... and so I stumble back to bed.");
+ Lwt.fail exn
+ end