Add MySQLBytesRequest

This commit is contained in:
Xie Han
2023-02-06 02:57:51 +08:00
parent defd4d5922
commit f7285fe708
2 changed files with 37 additions and 7 deletions
+9 -4
View File
@@ -408,8 +408,13 @@ int MySQLAuthResponse::decode_packet(const unsigned char *buf, size_t buflen)
if (end == buf)
return -2;
if (*buf == 0xfe)
switch (*buf)
{
case 0x00:
case 0xff:
return MySQLResponse::decode_packet(buf, buflen);
case 0xfe:
pos = ++buf;
while (pos < end && *pos)
pos++;
@@ -423,11 +428,11 @@ int MySQLAuthResponse::decode_packet(const unsigned char *buf, size_t buflen)
return -2;
plugin_data_.assign((const char *)buf, end - 1 - buf);
auth_switch_ = true;
return 1;
}
return MySQLResponse::decode_packet(buf, buflen);
default:
return -2;
}
}
void MySQLResponse::set_ok_packet()
+28 -3
View File
@@ -152,7 +152,6 @@ class MySQLAuthResponse : public MySQLResponse
public:
std::string auth_plugin_name() const { return plugin_name_; }
std::string auth_plugin_data() const { return plugin_data_; }
bool auth_switched() const { return auth_switch_; }
private:
virtual int decode_packet(const unsigned char *buf, size_t buflen);
@@ -160,16 +159,42 @@ private:
private:
std::string plugin_name_;
std::string plugin_data_;
bool auth_switch_;
public:
MySQLAuthResponse() : auth_switch_(false) { }
MySQLAuthResponse() { }
//move constructor
MySQLAuthResponse(MySQLAuthResponse&& move) = default;
//move operator
MySQLAuthResponse& operator= (MySQLAuthResponse&& move) = default;
};
class MySQLBytesRequest : public MySQLRequest
{
public:
void set_bytes(const void *bytes, size_t len)
{
buf_.assign((const char *)bytes, len);
}
std::string get_bytes() const
{
return buf_;
}
private:
virtual int decode_packet(const unsigned char *buf, size_t buflen)
{
buf_.assign((const char *)buf, buflen);
return 1;
}
private:
MySQLBytesRequest() { }
MySQLBytesRequest(MySQLBytesRequest&& move) = default;
//move operator
MySQLBytesRequest& operator= (MySQLBytesRequest&& move) = default;
};
//////////
inline mysql_parser_t *MySQLMessage::get_parser() const