diff options
author | Clombrong <cromblong@egregore.fun> | 2025-06-26 17:08:25 +0200 |
---|---|---|
committer | Clombrong <cromblong@egregore.fun> | 2025-06-26 21:40:53 +0200 |
commit | fada25b1563d3d1da08da3ce8c47fa5b820cfbd8 (patch) | |
tree | f209c7e2f71b0c4ee6c1b5e2f86fa6ba06611906 | |
parent | 3362a074c7dddf439ff878cf94d9169ab208eb10 (diff) |
refactor(sasl): rename features record and its fields
-rw-r--r-- | lib/sasl.ml | 4 | ||||
-rw-r--r-- | lib/stream.ml | 18 |
2 files changed, 11 insertions, 11 deletions
diff --git a/lib/sasl.ml b/lib/sasl.ml index ff6436a..2241a91 100644 --- a/lib/sasl.ml +++ b/lib/sasl.ml @@ -63,9 +63,9 @@ let authenticate (portal : Portal.t) ({jid; password; preferred_mechanisms} : au | [localpart; _domain] -> localpart | _ -> failwith "Invalid JID" in - let* {sasl_mechanisms; _} = Xml.get (fst portal) >|= Stream.parse_features + let* {mechanisms; _} = Xml.get (fst portal) >|= Stream.parse_features in let preferred, not_preferred = - List.partition (fun f -> List.exists ((=) f) preferred_mechanisms) sasl_mechanisms + List.partition (fun f -> List.exists ((=) f) preferred_mechanisms) mechanisms in (* Function that takes a [sasl_auth] and returns whether this attempt should be retried, or is definitive (e.g, success or bad credentials). *) diff --git a/lib/stream.ml b/lib/stream.ml index 83587cd..607319d 100644 --- a/lib/stream.ml +++ b/lib/stream.ml @@ -8,15 +8,15 @@ let parse_auth_mechanism = function | "PLAIN" -> PLAIN | other -> Unknown other -type stream_features = { - sasl_mechanisms : auth_mechanism list; +type features = { + mechanisms : auth_mechanism list; starttls : [`Required | `Optional | `None]; - unknown_features : Xml.element list; + unknown : Xml.element list; } -(** [parse_features el] is a [stream_features] record with all the features of the +(** [parse_features el] is a [features] record with all the features of the [<stream:features>] stanza contained in [el]. *) -let parse_features (el : Xml.element) : stream_features = +let parse_features (el : Xml.element) : features = let open Xml in let open Either in let parse_mechanism_stanza = function @@ -24,7 +24,7 @@ let parse_features (el : Xml.element) : stream_features = Some (parse_auth_mechanism mechanism) | _ -> None in - let parse_feature (acc : stream_features) (feature : Xml.element) : stream_features = + let parse_feature (acc : features) (feature : Xml.element) : features = let parse_mechanisms ch = List.filter_map parse_mechanism_stanza ch and parse_starttls = function @@ -32,10 +32,10 @@ let parse_features (el : Xml.element) : stream_features = | [] -> `Optional | _ -> raise (InvalidStanza (element_to_string el)) in match feature.local_name with - | "mechanisms" -> {acc with sasl_mechanisms=parse_mechanisms feature.children} + | "mechanisms" -> {acc with mechanisms=parse_mechanisms feature.children} | "starttls" -> {acc with starttls=parse_starttls feature.children} - | _ -> {acc with unknown_features = feature :: acc.unknown_features} + | _ -> {acc with unknown = feature :: acc.unknown} in List.fold_left parse_feature - {sasl_mechanisms=[]; starttls=`None; unknown_features=[]} + {mechanisms=[]; starttls=`None; unknown=[]} (List.filter_map find_left el.children) |