Skip to content

Commit

Permalink
Do FlashMQ plugin ACL check first
Browse files Browse the repository at this point in the history
It's more likely that this one is loaded, and then version 2, so we
reduce if checks this way.
  • Loading branch information
halfgaar committed Jul 27, 2024
1 parent 00f5e08 commit d013e7f
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,24 @@ AuthResult Authentication::aclCheck(const std::string &clientid, const std::stri
if (settings.pluginSerializeAuthChecks)
lock.lock();

if (pluginFamily == PluginFamily::MosquittoV2)
if (__builtin_expect(pluginFamily == PluginFamily::FlashMQ, 1))
{
// I'm using this try/catch because propagating the exception higher up conflicts with who gets the blame, and then the publisher
// gets disconnected.
try
{
if (flashmqPluginVersionNumber == 2)
return flashmq_plugin_acl_check_v2(pluginData, access, clientid, username, topic, subtopics, payload, qos, retain, userProperties);
else
return flashmq_plugin_acl_check_v1(pluginData, access, clientid, username, topic, subtopics, qos, retain, userProperties);
}
catch (std::exception &ex)
{
logger->logf(LOG_ERR, "Error doing ACL check in plugin: '%s'", ex.what());
logger->logf(LOG_WARNING, "Throwing exceptions from auth plugin login/ACL checks is slow. There's no need.");
}
}
else if (pluginFamily == PluginFamily::MosquittoV2)
{
// We have to do this, because Mosquitto plugin v2 has no notion of checking subscribes.
if (access == AclAccess::subscribe)
Expand All @@ -356,23 +373,6 @@ AuthResult Authentication::aclCheck(const std::string &clientid, const std::stri

return result_;
}
else if (pluginFamily == PluginFamily::FlashMQ)
{
// I'm using this try/catch because propagating the exception higher up conflicts with who gets the blame, and then the publisher
// gets disconnected.
try
{
if (flashmqPluginVersionNumber == 1)
return flashmq_plugin_acl_check_v1(pluginData, access, clientid, username, topic, subtopics, qos, retain, userProperties);
else
return flashmq_plugin_acl_check_v2(pluginData, access, clientid, username, topic, subtopics, payload, qos, retain, userProperties);
}
catch (std::exception &ex)
{
logger->logf(LOG_ERR, "Error doing ACL check in plugin: '%s'", ex.what());
logger->logf(LOG_WARNING, "Throwing exceptions from auth plugin login/ACL checks is slow. There's no need.");
}
}

return AuthResult::error;
}
Expand Down

0 comments on commit d013e7f

Please sign in to comment.