| 1 | // Copyright (C) 2019 The Qt Company Ltd. |
|---|---|
| 2 | // Copyright (C) 2015 basysKom GmbH, opensource@basyskom.com |
| 3 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 4 | |
| 5 | #include "qopcuaendpointdescription.h" |
| 6 | |
| 7 | QT_BEGIN_NAMESPACE |
| 8 | |
| 9 | /*! |
| 10 | \class QOpcUaEndpointDescription |
| 11 | \inmodule QtOpcUa |
| 12 | \brief The OPC UA EndpointDescription. |
| 13 | |
| 14 | An endpoint description contains information about an endpoint and how to connect to it. |
| 15 | */ |
| 16 | |
| 17 | /*! |
| 18 | \qmltype EndpointDescription |
| 19 | \inqmlmodule QtOpcUa |
| 20 | \brief The OPC UA EndpointDescription. |
| 21 | \since QtOpcUa 5.13 |
| 22 | \deprecated [6.9] |
| 23 | |
| 24 | An endpoint description contains information about an endpoint and how to connect to it. |
| 25 | */ |
| 26 | |
| 27 | /*! |
| 28 | \enum QOpcUaEndpointDescription::MessageSecurityMode |
| 29 | |
| 30 | This enum type holds the security mode supported by the endpoint. |
| 31 | |
| 32 | \value Invalid The default value, will be rejected by the server. |
| 33 | \value None No security. |
| 34 | \value Sign Messages are signed but not encrypted. |
| 35 | \value SignAndEncrypt Messages are signed and encrypted. |
| 36 | */ |
| 37 | |
| 38 | /*! |
| 39 | \qmlproperty enumeration EndpointDescription::MessageSecurityMode |
| 40 | |
| 41 | The security mode supported by the endpoint. |
| 42 | |
| 43 | \value Invalid The default value, will be rejected by the server. |
| 44 | \value None No security. |
| 45 | \value Sign Messages are signed but not encrypted. |
| 46 | \value SignAndEncrypt Messages are signed and encrypted. |
| 47 | */ |
| 48 | |
| 49 | |
| 50 | /*! |
| 51 | \property QOpcUaEndpointDescription::endpointUrl |
| 52 | |
| 53 | The URL for the endpoint. |
| 54 | */ |
| 55 | |
| 56 | /*! |
| 57 | \qmlproperty string EndpointDescription::endpointUrl |
| 58 | |
| 59 | The URL for the endpoint. |
| 60 | */ |
| 61 | |
| 62 | /*! |
| 63 | \property QOpcUaEndpointDescription::securityMode |
| 64 | |
| 65 | Security mode supported by this endpoint. |
| 66 | */ |
| 67 | |
| 68 | /*! |
| 69 | \qmlproperty MessageSecurityMode EndpointDescription::securityMode |
| 70 | |
| 71 | Security mode supported by this endpoint. |
| 72 | */ |
| 73 | |
| 74 | /*! |
| 75 | \property QOpcUaEndpointDescription::securityPolicy |
| 76 | |
| 77 | The URI of the security policy. |
| 78 | */ |
| 79 | |
| 80 | /*! |
| 81 | \qmlproperty string EndpointDescription::securityPolicy |
| 82 | |
| 83 | The URI of the security policy. |
| 84 | */ |
| 85 | |
| 86 | |
| 87 | /*! |
| 88 | \property QOpcUaEndpointDescription::server |
| 89 | |
| 90 | The application description of the server. |
| 91 | */ |
| 92 | |
| 93 | /*! |
| 94 | \qmlproperty ApplicationDescription EndpointDescription::server |
| 95 | |
| 96 | The application description of the server. |
| 97 | */ |
| 98 | |
| 99 | /*! |
| 100 | \property QOpcUaEndpointDescription::userIdentityTokens |
| 101 | |
| 102 | List of user identity tokens the endpoint will accept. |
| 103 | */ |
| 104 | |
| 105 | /*! |
| 106 | \qmlproperty list<UserTokenPolicy> EndpointDescription::userIdentityTokens |
| 107 | |
| 108 | List of user identity tokens the endpoint will accept. |
| 109 | */ |
| 110 | |
| 111 | class QOpcUaEndpointDescriptionData : public QSharedData |
| 112 | { |
| 113 | public: |
| 114 | QString endpointUrl; |
| 115 | QOpcUaApplicationDescription server; |
| 116 | QByteArray serverCertificate; |
| 117 | QOpcUaEndpointDescription::MessageSecurityMode securityMode{QOpcUaEndpointDescription::MessageSecurityMode::None}; |
| 118 | QString securityPolicy; |
| 119 | QList<QOpcUaUserTokenPolicy> userIdentityTokens; |
| 120 | QString transportProfileUri; |
| 121 | quint8 securityLevel{0}; |
| 122 | }; |
| 123 | |
| 124 | /*! |
| 125 | Default constructs an endpoint description with no parameters set. |
| 126 | */ |
| 127 | QOpcUaEndpointDescription::QOpcUaEndpointDescription() |
| 128 | : data(new QOpcUaEndpointDescriptionData) |
| 129 | { |
| 130 | } |
| 131 | |
| 132 | /*! |
| 133 | Constructs an endpoint description from \a rhs. |
| 134 | */ |
| 135 | QOpcUaEndpointDescription::QOpcUaEndpointDescription(const QOpcUaEndpointDescription &rhs) |
| 136 | : data(rhs.data) |
| 137 | { |
| 138 | } |
| 139 | |
| 140 | /*! |
| 141 | Sets the values from \a rhs in this endpoint description. |
| 142 | */ |
| 143 | QOpcUaEndpointDescription &QOpcUaEndpointDescription::operator=(const QOpcUaEndpointDescription &rhs) |
| 144 | { |
| 145 | if (this != &rhs) |
| 146 | data.operator=(o: rhs.data); |
| 147 | return *this; |
| 148 | } |
| 149 | |
| 150 | /*! |
| 151 | Returns \c true if this endpoint description has the same value as \a rhs. |
| 152 | */ |
| 153 | bool QOpcUaEndpointDescription::operator==(const QOpcUaEndpointDescription &rhs) const |
| 154 | { |
| 155 | return rhs.server() == server() && |
| 156 | rhs.endpointUrl() == endpointUrl() && |
| 157 | rhs.securityMode() == securityMode() && |
| 158 | rhs.securityLevel() == securityLevel() && |
| 159 | rhs.securityPolicy() == securityPolicy() && |
| 160 | rhs.serverCertificate() == serverCertificate() && |
| 161 | rhs.userIdentityTokens() == userIdentityTokens() && |
| 162 | rhs.transportProfileUri() == transportProfileUri(); |
| 163 | } |
| 164 | |
| 165 | QOpcUaEndpointDescription::~QOpcUaEndpointDescription() |
| 166 | { |
| 167 | } |
| 168 | |
| 169 | /*! |
| 170 | Returns a relative index assigned by the server. It describes how secure this |
| 171 | endpoint is compared to other endpoints of the same server. An endpoint with strong |
| 172 | security measures has a higher security level than one with weaker or no security |
| 173 | measures. |
| 174 | |
| 175 | Security level 0 indicates an endpoint for backward compatibility purposes which |
| 176 | should only be used if the client does not support the security measures required |
| 177 | by more secure endpoints. |
| 178 | */ |
| 179 | quint8 QOpcUaEndpointDescription::securityLevel() const |
| 180 | { |
| 181 | return data->securityLevel; |
| 182 | } |
| 183 | |
| 184 | /*! |
| 185 | Sets the security level to \a securityLevel. |
| 186 | */ |
| 187 | void QOpcUaEndpointDescription::setSecurityLevel(quint8 securityLevel) |
| 188 | { |
| 189 | data->securityLevel = securityLevel; |
| 190 | } |
| 191 | |
| 192 | /*! |
| 193 | Returns the URI of the transport profile supported by the endpoint. |
| 194 | */ |
| 195 | QString QOpcUaEndpointDescription::transportProfileUri() const |
| 196 | { |
| 197 | return data->transportProfileUri; |
| 198 | } |
| 199 | |
| 200 | /*! |
| 201 | Sets the URI of the transport profile supported by the endpoint to \a transportProfileUri. |
| 202 | */ |
| 203 | void QOpcUaEndpointDescription::setTransportProfileUri(const QString &transportProfileUri) |
| 204 | { |
| 205 | data->transportProfileUri = transportProfileUri; |
| 206 | } |
| 207 | |
| 208 | /*! |
| 209 | Returns a list of user identity tokens the endpoint will accept. |
| 210 | */ |
| 211 | QList<QOpcUaUserTokenPolicy> QOpcUaEndpointDescription::userIdentityTokens() const |
| 212 | { |
| 213 | return data->userIdentityTokens; |
| 214 | } |
| 215 | |
| 216 | /*! |
| 217 | Returns a reference to a list of user identity tokens the endpoint will accept. |
| 218 | */ |
| 219 | QList<QOpcUaUserTokenPolicy> &QOpcUaEndpointDescription::userIdentityTokensRef() |
| 220 | { |
| 221 | return data->userIdentityTokens; |
| 222 | } |
| 223 | |
| 224 | /*! |
| 225 | Sets the user identity tokens to \a userIdentityTokens. |
| 226 | */ |
| 227 | void QOpcUaEndpointDescription::setUserIdentityTokens(const QList<QOpcUaUserTokenPolicy> &userIdentityTokens) |
| 228 | { |
| 229 | data->userIdentityTokens = userIdentityTokens; |
| 230 | } |
| 231 | |
| 232 | /*! |
| 233 | Returns the URI of the security policy. |
| 234 | |
| 235 | The Basic128Rsa15 and Basic256 security policies are deprecated and should only be used |
| 236 | for backward compatibility if the server doesn't support any of the policies currently |
| 237 | considered as secure. |
| 238 | */ |
| 239 | QString QOpcUaEndpointDescription::securityPolicy() const |
| 240 | { |
| 241 | return data->securityPolicy; |
| 242 | } |
| 243 | |
| 244 | /*! |
| 245 | Sets the URI of the security policy to \a securityPolicy. |
| 246 | |
| 247 | The Basic128Rsa15 and Basic256 security policies are deprecated and should only be used |
| 248 | for backward compatibility if the server doesn't support any of the policies currently |
| 249 | considered as secure. |
| 250 | */ |
| 251 | void QOpcUaEndpointDescription::setSecurityPolicy(const QString &securityPolicy) |
| 252 | { |
| 253 | data->securityPolicy = securityPolicy; |
| 254 | } |
| 255 | |
| 256 | /*! |
| 257 | Returns the security mode supported by this endpoint. |
| 258 | */ |
| 259 | QOpcUaEndpointDescription::MessageSecurityMode QOpcUaEndpointDescription::securityMode() const |
| 260 | { |
| 261 | return data->securityMode; |
| 262 | } |
| 263 | |
| 264 | /*! |
| 265 | Sets the security mode supported by this endpoint to \a securityMode. |
| 266 | */ |
| 267 | void QOpcUaEndpointDescription::setSecurityMode(MessageSecurityMode securityMode) |
| 268 | { |
| 269 | data->securityMode = securityMode; |
| 270 | } |
| 271 | |
| 272 | /*! |
| 273 | Returns the application instance certificate of the server. |
| 274 | */ |
| 275 | QByteArray QOpcUaEndpointDescription::serverCertificate() const |
| 276 | { |
| 277 | return data->serverCertificate; |
| 278 | } |
| 279 | |
| 280 | /*! |
| 281 | Sets the application instance certificate of the server to \a serverCertificate. |
| 282 | */ |
| 283 | void QOpcUaEndpointDescription::setServerCertificate(const QByteArray &serverCertificate) |
| 284 | { |
| 285 | data->serverCertificate = serverCertificate; |
| 286 | } |
| 287 | |
| 288 | /*! |
| 289 | Returns the application description of the server. |
| 290 | */ |
| 291 | QOpcUaApplicationDescription QOpcUaEndpointDescription::server() const |
| 292 | { |
| 293 | return data->server; |
| 294 | } |
| 295 | |
| 296 | /*! |
| 297 | Returns a reference to the application description of the server. |
| 298 | */ |
| 299 | QOpcUaApplicationDescription &QOpcUaEndpointDescription::serverRef() |
| 300 | { |
| 301 | return data->server; |
| 302 | } |
| 303 | |
| 304 | /*! |
| 305 | Sets the application description of the server to \a server. |
| 306 | */ |
| 307 | void QOpcUaEndpointDescription::setServer(const QOpcUaApplicationDescription &server) |
| 308 | { |
| 309 | data->server = server; |
| 310 | } |
| 311 | |
| 312 | /*! |
| 313 | Returns the URL for the endpoint. |
| 314 | */ |
| 315 | QString QOpcUaEndpointDescription::endpointUrl() const |
| 316 | { |
| 317 | return data->endpointUrl; |
| 318 | } |
| 319 | |
| 320 | /*! |
| 321 | Sets the URL for the endpoint to \a endpointUrl. |
| 322 | */ |
| 323 | void QOpcUaEndpointDescription::setEndpointUrl(const QString &endpointUrl) |
| 324 | { |
| 325 | data->endpointUrl = endpointUrl; |
| 326 | } |
| 327 | |
| 328 | QT_END_NAMESPACE |
| 329 |
