mirror of
https://github.com/esphome/esphome.git
synced 2025-08-01 07:57:47 +00:00
Exclude ConnectRequest/Response messages when API password is disabled
This commit is contained in:
parent
8953e53a04
commit
2372cba099
@ -136,6 +136,7 @@ message ConnectRequest {
|
|||||||
option (id) = 3;
|
option (id) = 3;
|
||||||
option (source) = SOURCE_CLIENT;
|
option (source) = SOURCE_CLIENT;
|
||||||
option (no_delay) = true;
|
option (no_delay) = true;
|
||||||
|
option (ifdef) = "USE_API_PASSWORD";
|
||||||
|
|
||||||
// The password to log in with
|
// The password to log in with
|
||||||
string password = 1;
|
string password = 1;
|
||||||
@ -147,6 +148,7 @@ message ConnectResponse {
|
|||||||
option (id) = 4;
|
option (id) = 4;
|
||||||
option (source) = SOURCE_SERVER;
|
option (source) = SOURCE_SERVER;
|
||||||
option (no_delay) = true;
|
option (no_delay) = true;
|
||||||
|
option (ifdef) = "USE_API_PASSWORD";
|
||||||
|
|
||||||
bool invalid_password = 1;
|
bool invalid_password = 1;
|
||||||
}
|
}
|
||||||
|
@ -1436,11 +1436,10 @@ HelloResponse APIConnection::hello(const HelloRequest &msg) {
|
|||||||
this->flags_.connection_state = static_cast<uint8_t>(ConnectionState::CONNECTED);
|
this->flags_.connection_state = static_cast<uint8_t>(ConnectionState::CONNECTED);
|
||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
|
#ifdef USE_API_PASSWORD
|
||||||
ConnectResponse APIConnection::connect(const ConnectRequest &msg) {
|
ConnectResponse APIConnection::connect(const ConnectRequest &msg) {
|
||||||
bool correct = true;
|
bool correct = true;
|
||||||
#ifdef USE_API_PASSWORD
|
|
||||||
correct = this->parent_->check_password(msg.password);
|
correct = this->parent_->check_password(msg.password);
|
||||||
#endif
|
|
||||||
|
|
||||||
ConnectResponse resp;
|
ConnectResponse resp;
|
||||||
// bool invalid_password = 1;
|
// bool invalid_password = 1;
|
||||||
@ -1459,6 +1458,7 @@ ConnectResponse APIConnection::connect(const ConnectRequest &msg) {
|
|||||||
}
|
}
|
||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
DeviceInfoResponse APIConnection::device_info(const DeviceInfoRequest &msg) {
|
DeviceInfoResponse APIConnection::device_info(const DeviceInfoRequest &msg) {
|
||||||
DeviceInfoResponse resp{};
|
DeviceInfoResponse resp{};
|
||||||
#ifdef USE_API_PASSWORD
|
#ifdef USE_API_PASSWORD
|
||||||
|
@ -173,7 +173,9 @@ class APIConnection : public APIServerConnection {
|
|||||||
void on_get_time_response(const GetTimeResponse &value) override;
|
void on_get_time_response(const GetTimeResponse &value) override;
|
||||||
#endif
|
#endif
|
||||||
HelloResponse hello(const HelloRequest &msg) override;
|
HelloResponse hello(const HelloRequest &msg) override;
|
||||||
|
#ifdef USE_API_PASSWORD
|
||||||
ConnectResponse connect(const ConnectRequest &msg) override;
|
ConnectResponse connect(const ConnectRequest &msg) override;
|
||||||
|
#endif
|
||||||
DisconnectResponse disconnect(const DisconnectRequest &msg) override;
|
DisconnectResponse disconnect(const DisconnectRequest &msg) override;
|
||||||
PingResponse ping(const PingRequest &msg) override { return {}; }
|
PingResponse ping(const PingRequest &msg) override { return {}; }
|
||||||
DeviceInfoResponse device_info(const DeviceInfoRequest &msg) override;
|
DeviceInfoResponse device_info(const DeviceInfoRequest &msg) override;
|
||||||
|
@ -82,6 +82,7 @@ void HelloResponse::calculate_size(uint32_t &total_size) const {
|
|||||||
ProtoSize::add_string_field(total_size, 1, this->server_info, false);
|
ProtoSize::add_string_field(total_size, 1, this->server_info, false);
|
||||||
ProtoSize::add_string_field(total_size, 1, this->name, false);
|
ProtoSize::add_string_field(total_size, 1, this->name, false);
|
||||||
}
|
}
|
||||||
|
#ifdef USE_API_PASSWORD
|
||||||
bool ConnectRequest::decode_length(uint32_t field_id, ProtoLengthDelimited value) {
|
bool ConnectRequest::decode_length(uint32_t field_id, ProtoLengthDelimited value) {
|
||||||
switch (field_id) {
|
switch (field_id) {
|
||||||
case 1: {
|
case 1: {
|
||||||
@ -110,6 +111,7 @@ void ConnectResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_bool
|
|||||||
void ConnectResponse::calculate_size(uint32_t &total_size) const {
|
void ConnectResponse::calculate_size(uint32_t &total_size) const {
|
||||||
ProtoSize::add_bool_field(total_size, 1, this->invalid_password, false);
|
ProtoSize::add_bool_field(total_size, 1, this->invalid_password, false);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
bool AreaInfo::decode_varint(uint32_t field_id, ProtoVarInt value) {
|
bool AreaInfo::decode_varint(uint32_t field_id, ProtoVarInt value) {
|
||||||
switch (field_id) {
|
switch (field_id) {
|
||||||
case 1: {
|
case 1: {
|
||||||
|
@ -348,6 +348,7 @@ class HelloResponse : public ProtoMessage {
|
|||||||
bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override;
|
bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override;
|
||||||
bool decode_varint(uint32_t field_id, ProtoVarInt value) override;
|
bool decode_varint(uint32_t field_id, ProtoVarInt value) override;
|
||||||
};
|
};
|
||||||
|
#ifdef USE_API_PASSWORD
|
||||||
class ConnectRequest : public ProtoMessage {
|
class ConnectRequest : public ProtoMessage {
|
||||||
public:
|
public:
|
||||||
static constexpr uint16_t MESSAGE_TYPE = 3;
|
static constexpr uint16_t MESSAGE_TYPE = 3;
|
||||||
@ -382,6 +383,7 @@ class ConnectResponse : public ProtoMessage {
|
|||||||
protected:
|
protected:
|
||||||
bool decode_varint(uint32_t field_id, ProtoVarInt value) override;
|
bool decode_varint(uint32_t field_id, ProtoVarInt value) override;
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
class DisconnectRequest : public ProtoMessage {
|
class DisconnectRequest : public ProtoMessage {
|
||||||
public:
|
public:
|
||||||
static constexpr uint16_t MESSAGE_TYPE = 5;
|
static constexpr uint16_t MESSAGE_TYPE = 5;
|
||||||
|
@ -632,6 +632,7 @@ void HelloResponse::dump_to(std::string &out) const {
|
|||||||
out.append("\n");
|
out.append("\n");
|
||||||
out.append("}");
|
out.append("}");
|
||||||
}
|
}
|
||||||
|
#ifdef USE_API_PASSWORD
|
||||||
void ConnectRequest::dump_to(std::string &out) const {
|
void ConnectRequest::dump_to(std::string &out) const {
|
||||||
__attribute__((unused)) char buffer[64];
|
__attribute__((unused)) char buffer[64];
|
||||||
out.append("ConnectRequest {\n");
|
out.append("ConnectRequest {\n");
|
||||||
@ -648,6 +649,7 @@ void ConnectResponse::dump_to(std::string &out) const {
|
|||||||
out.append("\n");
|
out.append("\n");
|
||||||
out.append("}");
|
out.append("}");
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
void DisconnectRequest::dump_to(std::string &out) const { out.append("DisconnectRequest {}"); }
|
void DisconnectRequest::dump_to(std::string &out) const { out.append("DisconnectRequest {}"); }
|
||||||
void DisconnectResponse::dump_to(std::string &out) const { out.append("DisconnectResponse {}"); }
|
void DisconnectResponse::dump_to(std::string &out) const { out.append("DisconnectResponse {}"); }
|
||||||
void PingRequest::dump_to(std::string &out) const { out.append("PingRequest {}"); }
|
void PingRequest::dump_to(std::string &out) const { out.append("PingRequest {}"); }
|
||||||
|
@ -25,6 +25,7 @@ void APIServerConnectionBase::read_message(uint32_t msg_size, uint32_t msg_type,
|
|||||||
this->on_hello_request(msg);
|
this->on_hello_request(msg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
#ifdef USE_API_PASSWORD
|
||||||
case 3: {
|
case 3: {
|
||||||
ConnectRequest msg;
|
ConnectRequest msg;
|
||||||
msg.decode(msg_data, msg_size);
|
msg.decode(msg_data, msg_size);
|
||||||
@ -34,6 +35,7 @@ void APIServerConnectionBase::read_message(uint32_t msg_size, uint32_t msg_type,
|
|||||||
this->on_connect_request(msg);
|
this->on_connect_request(msg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
case 5: {
|
case 5: {
|
||||||
DisconnectRequest msg;
|
DisconnectRequest msg;
|
||||||
msg.decode(msg_data, msg_size);
|
msg.decode(msg_data, msg_size);
|
||||||
@ -600,12 +602,14 @@ void APIServerConnection::on_hello_request(const HelloRequest &msg) {
|
|||||||
this->on_fatal_error();
|
this->on_fatal_error();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#ifdef USE_API_PASSWORD
|
||||||
void APIServerConnection::on_connect_request(const ConnectRequest &msg) {
|
void APIServerConnection::on_connect_request(const ConnectRequest &msg) {
|
||||||
ConnectResponse ret = this->connect(msg);
|
ConnectResponse ret = this->connect(msg);
|
||||||
if (!this->send_message(ret)) {
|
if (!this->send_message(ret)) {
|
||||||
this->on_fatal_error();
|
this->on_fatal_error();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
void APIServerConnection::on_disconnect_request(const DisconnectRequest &msg) {
|
void APIServerConnection::on_disconnect_request(const DisconnectRequest &msg) {
|
||||||
DisconnectResponse ret = this->disconnect(msg);
|
DisconnectResponse ret = this->disconnect(msg);
|
||||||
if (!this->send_message(ret)) {
|
if (!this->send_message(ret)) {
|
||||||
|
@ -27,7 +27,9 @@ class APIServerConnectionBase : public ProtoService {
|
|||||||
|
|
||||||
virtual void on_hello_request(const HelloRequest &value){};
|
virtual void on_hello_request(const HelloRequest &value){};
|
||||||
|
|
||||||
|
#ifdef USE_API_PASSWORD
|
||||||
virtual void on_connect_request(const ConnectRequest &value){};
|
virtual void on_connect_request(const ConnectRequest &value){};
|
||||||
|
#endif
|
||||||
|
|
||||||
virtual void on_disconnect_request(const DisconnectRequest &value){};
|
virtual void on_disconnect_request(const DisconnectRequest &value){};
|
||||||
virtual void on_disconnect_response(const DisconnectResponse &value){};
|
virtual void on_disconnect_response(const DisconnectResponse &value){};
|
||||||
@ -206,7 +208,9 @@ class APIServerConnectionBase : public ProtoService {
|
|||||||
class APIServerConnection : public APIServerConnectionBase {
|
class APIServerConnection : public APIServerConnectionBase {
|
||||||
public:
|
public:
|
||||||
virtual HelloResponse hello(const HelloRequest &msg) = 0;
|
virtual HelloResponse hello(const HelloRequest &msg) = 0;
|
||||||
|
#ifdef USE_API_PASSWORD
|
||||||
virtual ConnectResponse connect(const ConnectRequest &msg) = 0;
|
virtual ConnectResponse connect(const ConnectRequest &msg) = 0;
|
||||||
|
#endif
|
||||||
virtual DisconnectResponse disconnect(const DisconnectRequest &msg) = 0;
|
virtual DisconnectResponse disconnect(const DisconnectRequest &msg) = 0;
|
||||||
virtual PingResponse ping(const PingRequest &msg) = 0;
|
virtual PingResponse ping(const PingRequest &msg) = 0;
|
||||||
virtual DeviceInfoResponse device_info(const DeviceInfoRequest &msg) = 0;
|
virtual DeviceInfoResponse device_info(const DeviceInfoRequest &msg) = 0;
|
||||||
@ -323,7 +327,9 @@ class APIServerConnection : public APIServerConnectionBase {
|
|||||||
#endif
|
#endif
|
||||||
protected:
|
protected:
|
||||||
void on_hello_request(const HelloRequest &msg) override;
|
void on_hello_request(const HelloRequest &msg) override;
|
||||||
|
#ifdef USE_API_PASSWORD
|
||||||
void on_connect_request(const ConnectRequest &msg) override;
|
void on_connect_request(const ConnectRequest &msg) override;
|
||||||
|
#endif
|
||||||
void on_disconnect_request(const DisconnectRequest &msg) override;
|
void on_disconnect_request(const DisconnectRequest &msg) override;
|
||||||
void on_ping_request(const PingRequest &msg) override;
|
void on_ping_request(const PingRequest &msg) override;
|
||||||
void on_device_info_request(const DeviceInfoRequest &msg) override;
|
void on_device_info_request(const DeviceInfoRequest &msg) override;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user