From f3ded5105143883614f602d543632530f4581bfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=99=A8?= Date: Fri, 24 May 2019 19:31:23 +0800 Subject: [PATCH] auth response include service version --- src/cli.cc | 3 ++- src/disp.cc | 4 ++-- src/ser-helper.cc | 11 ++++++++--- src/ser-helper.h | 7 ++++--- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/cli.cc b/src/cli.cc index 35d8e2b..e70367c 100644 --- a/src/cli.cc +++ b/src/cli.cc @@ -217,8 +217,9 @@ bool Client::handle_received(int32_t size) { bool Client::handle_cmd_before_auth(int32_t cmd, shared_ptr &resp) { if (cmd != CMD_AUTH_RESP) return false; + uint32_t version; lock_guard locker(auth_result->amutex); - if (ResponseParser::parse_auth(resp, auth_result->result) < 0) + if (ResponseParser::parse_auth(resp, auth_result->result, version) < 0) return false; auth_result->acond.notify_one(); cmd_handler = &Client::handle_cmd_after_auth; diff --git a/src/disp.cc b/src/disp.cc index 9898e41..098bf80 100644 --- a/src/disp.cc +++ b/src/disp.cc @@ -196,8 +196,8 @@ bool Dispatcher::handle_auth_req(shared_ptr &msg_caps, KLOGE(TAG, "<<< %s: auth failed. client id already used", extra.c_str()); } } - int32_t c = ResponseSerializer::serialize_auth(result, buffer, buf_size, - sender->serialize_flags); + int32_t c = ResponseSerializer::serialize_auth( + result, FLORA_VERSION, buffer, buf_size, sender->serialize_flags); if (c < 0) return false; sender->write(buffer, c); diff --git a/src/ser-helper.cc b/src/ser-helper.cc index 352dae6..d4f1da3 100644 --- a/src/ser-helper.cc +++ b/src/ser-helper.cc @@ -141,11 +141,13 @@ int32_t RequestSerializer::serialize_ping(void *data, uint32_t size, return r; } -int32_t ResponseSerializer::serialize_auth(int32_t result, void *data, - uint32_t size, uint32_t flags) { +int32_t ResponseSerializer::serialize_auth(int32_t result, uint32_t version, + void *data, uint32_t size, + uint32_t flags) { shared_ptr caps = Caps::new_instance(); caps->write(CMD_AUTH_RESP); caps->write(result); + caps->write(version); int32_t r = caps->serialize(data, size, flags); if (r < 0) return -1; @@ -428,9 +430,12 @@ int32_t RequestParser::parse_reply(shared_ptr &caps, int32_t &id, return 0; } -int32_t ResponseParser::parse_auth(shared_ptr &caps, int32_t &result) { +int32_t ResponseParser::parse_auth(shared_ptr &caps, int32_t &result, + uint32_t &version) { if (caps->read(result) != CAPS_SUCCESS) return -1; + if (caps->read(version) != CAPS_SUCCESS) + return -1; return 0; } diff --git a/src/ser-helper.h b/src/ser-helper.h index 218f87b..2cee747 100644 --- a/src/ser-helper.h +++ b/src/ser-helper.h @@ -47,8 +47,8 @@ class RequestSerializer { class ResponseSerializer { public: - static int32_t serialize_auth(int32_t result, void *data, uint32_t size, - uint32_t flags); + static int32_t serialize_auth(int32_t result, uint32_t version, void *data, + uint32_t size, uint32_t flags); static int32_t serialize_post(const char *name, uint32_t msgtype, std::shared_ptr &args, uint64_t tag, @@ -138,7 +138,8 @@ class RequestParser { class ResponseParser { public: - static int32_t parse_auth(std::shared_ptr &caps, int32_t &result); + static int32_t parse_auth(std::shared_ptr &caps, int32_t &result, + uint32_t &version); static int32_t parse_post(std::shared_ptr &caps, std::string &name, uint32_t &msgtype, std::shared_ptr &args,