Skip to content

Commit

Permalink
auth response include service version
Browse files Browse the repository at this point in the history
  • Loading branch information
张晨 authored and mingzc0508 committed May 24, 2019
1 parent 2d974f1 commit f3ded51
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/cli.cc
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,9 @@ bool Client::handle_received(int32_t size) {
bool Client::handle_cmd_before_auth(int32_t cmd, shared_ptr<Caps> &resp) {
if (cmd != CMD_AUTH_RESP)
return false;
uint32_t version;
lock_guard<mutex> 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;
Expand Down
4 changes: 2 additions & 2 deletions src/disp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ bool Dispatcher::handle_auth_req(shared_ptr<Caps> &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);
Expand Down
11 changes: 8 additions & 3 deletions src/ser-helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 = 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;
Expand Down Expand Up @@ -428,9 +430,12 @@ int32_t RequestParser::parse_reply(shared_ptr<Caps> &caps, int32_t &id,
return 0;
}

int32_t ResponseParser::parse_auth(shared_ptr<Caps> &caps, int32_t &result) {
int32_t ResponseParser::parse_auth(shared_ptr<Caps> &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;
}

Expand Down
7 changes: 4 additions & 3 deletions src/ser-helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Caps> &args, uint64_t tag,
Expand Down Expand Up @@ -138,7 +138,8 @@ class RequestParser {

class ResponseParser {
public:
static int32_t parse_auth(std::shared_ptr<Caps> &caps, int32_t &result);
static int32_t parse_auth(std::shared_ptr<Caps> &caps, int32_t &result,
uint32_t &version);

static int32_t parse_post(std::shared_ptr<Caps> &caps, std::string &name,
uint32_t &msgtype, std::shared_ptr<Caps> &args,
Expand Down

0 comments on commit f3ded51

Please sign in to comment.