Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix mqtt commands with base path #2339 #2341

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/core/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@ std::vector<Command::CmdFunction> Command::cmdfunctions_;
// the entry point will be either via the Web API (api/) or MQTT (<base>/)
// returns a return code and json output
uint8_t Command::process(const char * path, const bool is_admin, const JsonObject input, JsonObject output) {
// check for MQTT, if so strip the "<base>" from the path
if (!strncmp(path, Mqtt::base().c_str(), Mqtt::base().length())) {
path += Mqtt::base().length();
}
SUrlParser p; // parse URL for the path names
p.parse(path);

// check first if it's from API or MQTT, if so strip the "api/" or "<base>/" from the path
if (p.paths().size() && ((p.paths().front() == "api") || (p.paths().front() == Mqtt::base()))) {
// check if it's from API
if (p.paths().size() && ((p.paths().front() == "api"))) {
p.paths().erase(p.paths().begin());
} else {
} else if (!p.paths().size()) {
return json_message(CommandRet::ERROR, "invalid path", output, path); // error
}

Expand Down
Loading