MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / applySubscriberEndpoint

Function applySubscriberEndpoint

app/src/API/Handlers/MqttHandler.cpp:493–530  ·  view source on GitHub ↗

* @brief Applies endpoint + credential + topic fields to the subscriber. */

Source from the content-addressed store, hash-verified

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.

Callers 1

subscriberSetConfigMethod · 0.85

Calls 10

portIsValidFunction · 0.85
isEmptyMethod · 0.80
setTopicFilterMethod · 0.80
containsMethod · 0.45
valueMethod · 0.45
setHostnameMethod · 0.45
setPortMethod · 0.45
setClientIdMethod · 0.45
setUsernameMethod · 0.45
setPasswordMethod · 0.45

Tested by

no test coverage detected