mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-09-28 11:21:30 +00:00
fix: allow input ip address dialog to validate if is valid endpoint
This commit is contained in:
@@ -1777,7 +1777,7 @@ void InputIpAddressDialog::set_machine_obj(MachineObject* obj)
|
|||||||
auto str_ip = m_input_ip->GetTextCtrl()->GetValue();
|
auto str_ip = m_input_ip->GetTextCtrl()->GetValue();
|
||||||
auto str_access_code = m_input_access_code->GetTextCtrl()->GetValue();
|
auto str_access_code = m_input_access_code->GetTextCtrl()->GetValue();
|
||||||
// ORCA enabling / disabling buttons with conditions enough to change its style
|
// ORCA enabling / disabling buttons with conditions enough to change its style
|
||||||
m_button_ok->Enable(isIp(str_ip.ToStdString()) &&
|
m_button_ok->Enable(isValidEndpoint(str_ip.ToStdString()) &&
|
||||||
(str_access_code.IsEmpty() || str_access_code.Length() >= 8));
|
(str_access_code.IsEmpty() || str_access_code.Length() >= 8));
|
||||||
|
|
||||||
Layout();
|
Layout();
|
||||||
@@ -1815,19 +1815,29 @@ void InputIpAddressDialog::update_test_msg(wxString msg,bool connected)
|
|||||||
Fit();
|
Fit();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InputIpAddressDialog::isIp(std::string ipstr)
|
bool InputIpAddressDialog::isValidEndpoint(std::string endpoint)
|
||||||
{
|
{
|
||||||
istringstream ipstream(ipstr);
|
if (endpoint.empty() || std::any_of(endpoint.begin(), endpoint.end(), [](unsigned char c) {
|
||||||
int num[4];
|
return std::isspace(c) != 0;
|
||||||
char point[3];
|
}))
|
||||||
string end;
|
return false;
|
||||||
ipstream >> num[0] >> point[0] >> num[1] >> point[1] >> num[2] >> point[2] >> num[3] >> end;
|
|
||||||
for (int i = 0; i < 3; ++i) {
|
const bool has_http_scheme = endpoint.rfind("http://", 0) == 0;
|
||||||
if (num[i] < 0 || num[i]>255) return false;
|
const bool has_https_scheme = endpoint.rfind("https://", 0) == 0;
|
||||||
if (point[i] != '.') return false;
|
const auto scheme_pos = endpoint.find("://");
|
||||||
}
|
if (scheme_pos != std::string::npos && !has_http_scheme && !has_https_scheme)
|
||||||
if (num[3] < 0 || num[3]>255) return false;
|
return false;
|
||||||
if (!end.empty()) return false;
|
|
||||||
|
std::string port;
|
||||||
|
const std::string host = Http::get_host_from_url(endpoint, &port);
|
||||||
|
if (host.empty())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// get_host_from_url returns its input when libcurl cannot parse it. For a
|
||||||
|
// URL with a scheme, that means a failed parse still needs to be rejected.
|
||||||
|
if (scheme_pos != std::string::npos && host == endpoint)
|
||||||
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2130,7 +2140,7 @@ void InputIpAddressDialog::on_text(wxCommandEvent &evt)
|
|||||||
|
|
||||||
// ORCA enabling / disabling buttons with conditions enough to change its style
|
// ORCA enabling / disabling buttons with conditions enough to change its style
|
||||||
bool valid_access_code_length = str_access_code.IsEmpty() || str_access_code.Length() >= 8;
|
bool valid_access_code_length = str_access_code.IsEmpty() || str_access_code.Length() >= 8;
|
||||||
bool enable_btns = isIp(str_ip.ToStdString()) && valid_access_code_length && invalid_access_code;
|
bool enable_btns = isValidEndpoint(str_ip.ToStdString()) && valid_access_code_length && invalid_access_code;
|
||||||
m_button_manual_setup->Enable(enable_btns);
|
m_button_manual_setup->Enable(enable_btns);
|
||||||
m_button_ok->Enable(enable_btns);
|
m_button_ok->Enable(enable_btns);
|
||||||
|
|
||||||
|
|||||||
@@ -348,7 +348,7 @@ public:
|
|||||||
void update_title(wxString title);
|
void update_title(wxString title);
|
||||||
void set_machine_obj(MachineObject* obj);
|
void set_machine_obj(MachineObject* obj);
|
||||||
void update_test_msg(wxString msg, bool connected);
|
void update_test_msg(wxString msg, bool connected);
|
||||||
bool isIp(std::string ipstr);
|
bool isValidEndpoint(std::string endpoint);
|
||||||
void check_ip_address_failed(int result);
|
void check_ip_address_failed(int result);
|
||||||
void on_check_ip_address_failed(wxCommandEvent& evt);
|
void on_check_ip_address_failed(wxCommandEvent& evt);
|
||||||
void on_ok(wxMouseEvent& evt);
|
void on_ok(wxMouseEvent& evt);
|
||||||
|
|||||||
Reference in New Issue
Block a user