* @brief Applies endpoint + credential + topic fields to the subscriber. */
| 491 | * @brief Applies endpoint + credential + topic fields to the subscriber. |
| 492 | */ |
| 493 | [[nodiscard]] static std::optional<QString> applySubscriberEndpoint(IO::Drivers::MQTT* d, |
| 494 | const QJsonObject& params) |
| 495 | { |
| 496 | if (params.contains(QStringLiteral("hostname"))) { |
| 497 | const auto host = params.value(QStringLiteral("hostname")).toString(); |
| 498 | if (host.trimmed().isEmpty()) |
| 499 | return QStringLiteral("hostname must not be empty"); |
| 500 | |
| 501 | d->setHostname(host); |
| 502 | } |
| 503 | |
| 504 | if (params.contains(QStringLiteral("port"))) { |
| 505 | const int port = params.value(QStringLiteral("port")).toInt(-1); |
| 506 | if (!portIsValid(port)) |
| 507 | return QStringLiteral("port must be in [1, 65535] (got %1)").arg(port); |
| 508 | |
| 509 | d->setPort(static_cast<quint16>(port)); |
| 510 | } |
| 511 | |
| 512 | if (params.contains(QStringLiteral("clientId"))) |
| 513 | d->setClientId(params.value(QStringLiteral("clientId")).toString()); |
| 514 | |
| 515 | const bool hasUser = params.contains(QStringLiteral("username")); |
| 516 | const bool hasPass = params.contains(QStringLiteral("password")); |
| 517 | if (hasPass && !hasUser) |
| 518 | return QStringLiteral("Setting 'password' requires 'username' in the same call"); |
| 519 | |
| 520 | if (hasUser) |
| 521 | d->setUsername(params.value(QStringLiteral("username")).toString()); |
| 522 | |
| 523 | if (hasPass) |
| 524 | d->setPassword(params.value(QStringLiteral("password")).toString()); |
| 525 | |
| 526 | if (params.contains(QStringLiteral("topicFilter"))) |
| 527 | d->setTopicFilter(params.value(QStringLiteral("topicFilter")).toString()); |
| 528 | |
| 529 | return std::nullopt; |
| 530 | } |
| 531 | |
| 532 | /** |
| 533 | * @brief Applies session + TLS fields to the subscriber. |
no test coverage detected