diff options
author | Daniil Baturin <daniil@baturin.org> | 2017-12-13 15:31:13 +0100 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2017-12-13 15:31:13 +0100 |
commit | 1df4b0b50993985af84236c4508eeec5ec739a48 (patch) | |
tree | 1c3fdf36bbd722a60409fab04f3c8bf15f9ebac1 | |
parent | cacc8ee6f2ccb43faa971a75d2c4585c8e1a27fc (diff) | |
download | vyconf-1df4b0b50993985af84236c4508eeec5ec739a48.tar.gz vyconf-1df4b0b50993985af84236c4508eeec5ec739a48.zip |
Fix message encoding in Vyconf_client.
-rw-r--r-- | src/vyconf_client.ml | 8 | ||||
-rw-r--r-- | src/vyconf_client.mli | 2 |
2 files changed, 5 insertions, 5 deletions
diff --git a/src/vyconf_client.ml b/src/vyconf_client.ml index 7528def..9afc1f2 100644 --- a/src/vyconf_client.ml +++ b/src/vyconf_client.ml @@ -33,12 +33,11 @@ let shutdown client = let do_request client req = let enc = Pbrt.Encoder.create () in - let () = encode_request req enc in + let () = encode_request_envelope {token=client.session; request=req} enc in let msg = Pbrt.Encoder.to_bytes enc in let%lwt () = Message.write client.oc msg in let%lwt resp = Message.read client.ic in decode_response (Pbrt.Decoder.of_bytes resp) |> Lwt.return - let get_status client = let req = Status in @@ -46,12 +45,13 @@ let get_status client = Lwt.return resp let setup_session ?(on_behalf_of=None) client client_app = + if BatOption.is_some client.session then Lwt.return (Error "Client is already associated with a session") else let id = on_behalf_of |> (function None -> None | Some x -> (Some (Int32.of_int x))) in let req = Setup_session {client_application=(Some client_app); on_behalf_of=id} in let%lwt resp = do_request client req in match resp.status with | Success -> (match resp.output with - | Some token -> Lwt.return (Ok token) - | None -> failwith "setup_session did not return a token!") + | Some token -> Lwt.return (Ok {client with session=(Some token)}) + | None -> failwith "setup_session did not return a session token!") | _ -> Error (substitute_default "Unknown error" resp.error) |> Lwt.return diff --git a/src/vyconf_client.mli b/src/vyconf_client.mli index ff48d86..db9489d 100644 --- a/src/vyconf_client.mli +++ b/src/vyconf_client.mli @@ -25,4 +25,4 @@ val shutdown : t -> t Lwt.t val get_status : t -> response Lwt.t -val setup_session : ?on_behalf_of:(int option) -> t -> string -> (string, string) result Lwt.t +val setup_session : ?on_behalf_of:(int option) -> t -> string -> (t, string) result Lwt.t |