KanoopProtocolQt 1.2.3
Qt HTTP operations and MQTT client library
Loading...
Searching...
No Matches
mqttparameters.h
1#ifndef MQTTPARAMETERS_H
2#define MQTTPARAMETERS_H
3#include <QString>
4#include <QMqttClient>
5#include <QSslKey>
6#include <Kanoop/kanoopprotocol.h>
7
8/** @brief Encapsulates connection parameters for an MQTT broker. */
9class LIBKANOOPPROTOCOL_EXPORT MqttParameters
10{
11public:
12 /** @brief Construct default MQTT parameters. */
14 /** @brief Construct MQTT parameters with the given host and port.
15 * @param host The broker hostname or IP address.
16 * @param port The broker port number (default 1883). */
17 MqttParameters(const QString& host, int port = 1883) :
18 _host(host), _port(port) {}
19
20 /** @brief Get the broker hostname.
21 * @return The broker hostname or IP address. */
22 QString host() const { return _host; }
23 /** @brief Set the broker hostname.
24 * @param value The broker hostname or IP address. */
25 void setHost(const QString& value) { _host = value; }
26
27 /** @brief Get the broker port number.
28 * @return The port number. */
29 int port() const { return _port; }
30 /** @brief Set the broker port number.
31 * @param value The port number. */
32 void setPort(int value) { _port = value; }
33
34 /** @brief Get the authentication username.
35 * @return The username string. */
36 QString username() const { return _username; }
37 /** @brief Set the authentication username.
38 * @param value The username string. */
39 void setUsername(const QString& value) { _username = value; }
40
41 /** @brief Get the authentication password.
42 * @return The password string. */
43 QString password() const { return _password; }
44 /** @brief Set the authentication password.
45 * @param value The password string. */
46 void setPassword(const QString& value) { _password = value; }
47
48 /** @brief Get the MQTT client identifier.
49 * @return The client ID string. */
50 QString clientId() const { return _clientId; }
51 /** @brief Set the MQTT client identifier.
52 * @param value The client ID string. */
53 void setClientId(const QString& value) { _clientId = value; }
54
55 /** @brief Get the MQTT protocol version.
56 * @return The protocol version enum value. */
57 QMqttClient::ProtocolVersion protocolVersion() const { return _protocolVersion; }
58 /** @brief Set the MQTT protocol version.
59 * @param value The protocol version enum value. */
60 void setProtocolVersion(QMqttClient::ProtocolVersion value) { _protocolVersion = value; }
61
62 /** @brief Get whether SSL/TLS is enabled.
63 * @return True if SSL is enabled. */
64 bool useSsl() const { return _useSsl; }
65 /** @brief Set whether SSL/TLS is enabled.
66 * @param value True to enable SSL. */
67 void setUseSsl(bool value) { _useSsl = value; }
68
69 /** @brief Get whether peer certificate verification is enabled.
70 * @return True if peer verification is enabled. */
71 bool verifyPeer() const { return _verifyPeer; }
72 /** @brief Set whether peer certificate verification is enabled.
73 * @param value True to enable peer verification. */
74 void setVerifyPeer(bool value) { _verifyPeer = value; }
75
76 /** @brief Get the client SSL certificate.
77 * @return The client certificate. */
78 QSslCertificate clientCertificate() const { return _clientCertificate; }
79 /** @brief Set the client SSL certificate.
80 * @param value The client certificate. */
81 void setClientCertificate(const QSslCertificate& value) { _clientCertificate = value; }
82 /** @brief Set the client SSL certificate from a PEM file.
83 * @param filename Path to the certificate file. */
84 void setClientCertificate(const QString& filename);
85
86 /** @brief Get the CA certificate used to verify the broker.
87 * @return The CA certificate. */
88 QSslCertificate caCertificate() const { return _caCertificate; }
89 /** @brief Set the CA certificate used to verify the broker.
90 * @param value The CA certificate. */
91 void setCaCertificate(const QSslCertificate& value) { _caCertificate = value; }
92 /** @brief Set the CA certificate from a PEM file.
93 * @param filename Path to the CA certificate file. */
94 void setCaCertificate(const QString& filename);
95
96 /** @brief Get the client private key for SSL authentication.
97 * @return The private key. */
98 QSslKey privateKey() const { return _privateKey; }
99 /** @brief Set the client private key for SSL authentication.
100 * @param value The private key. */
101 void setPrivateKey(const QSslKey& value) { _privateKey = value; }
102 /** @brief Set the client private key from a PEM file.
103 * @param filename Path to the private key file. */
104 void setPrivateKey(const QString& filename);
105
106private:
107 QString _host;
108 int _port = 1883;
109 QString _username;
110 QString _password;
111 QString _clientId;
112 QMqttClient::ProtocolVersion _protocolVersion = QMqttClient::MQTT_5_0;
113 bool _useSsl = false;
114 bool _verifyPeer = false;
115
116 QSslCertificate _clientCertificate;
117 QSslCertificate _caCertificate;
118 QSslKey _privateKey;
119};
120
121#endif // MQTTPARAMETERS_H
Encapsulates connection parameters for an MQTT broker.
void setPrivateKey(const QSslKey &value)
Set the client private key for SSL authentication.
QString username() const
Get the authentication username.
void setUseSsl(bool value)
Set whether SSL/TLS is enabled.
QSslCertificate caCertificate() const
Get the CA certificate used to verify the broker.
void setPassword(const QString &value)
Set the authentication password.
void setClientCertificate(const QSslCertificate &value)
Set the client SSL certificate.
MqttParameters()
Construct default MQTT parameters.
void setClientCertificate(const QString &filename)
Set the client SSL certificate from a PEM file.
bool useSsl() const
Get whether SSL/TLS is enabled.
void setCaCertificate(const QSslCertificate &value)
Set the CA certificate used to verify the broker.
bool verifyPeer() const
Get whether peer certificate verification is enabled.
void setCaCertificate(const QString &filename)
Set the CA certificate from a PEM file.
void setProtocolVersion(QMqttClient::ProtocolVersion value)
Set the MQTT protocol version.
QSslCertificate clientCertificate() const
Get the client SSL certificate.
void setVerifyPeer(bool value)
Set whether peer certificate verification is enabled.
MqttParameters(const QString &host, int port=1883)
Construct MQTT parameters with the given host and port.
int port() const
Get the broker port number.
void setPort(int value)
Set the broker port number.
QString password() const
Get the authentication password.
void setPrivateKey(const QString &filename)
Set the client private key from a PEM file.
QString host() const
Get the broker hostname.
QString clientId() const
Get the MQTT client identifier.
QSslKey privateKey() const
Get the client private key for SSL authentication.
void setHost(const QString &value)
Set the broker hostname.
QMqttClient::ProtocolVersion protocolVersion() const
Get the MQTT protocol version.
void setClientId(const QString &value)
Set the MQTT client identifier.
void setUsername(const QString &value)
Set the authentication username.