| 1 | // Copyright (C) 2019 The Qt Company Ltd. |
|---|---|
| 2 | // Copyright (C) 2018 Unified Automation GmbH |
| 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 "qopcuaapplicationidentity.h" |
| 6 | |
| 7 | QT_BEGIN_NAMESPACE |
| 8 | |
| 9 | /*! |
| 10 | \class QOpcUaApplicationIdentity |
| 11 | \inmodule QtOpcUa |
| 12 | \since QtOpcUa 5.13 |
| 13 | \brief QOpcUaApplicationIdentity defines the identity of the application. |
| 14 | |
| 15 | This info must be configured using \l QOpcUaClient::setApplicationIdentity. |
| 16 | The application identity can be set up manually or derived from a certificate. |
| 17 | |
| 18 | \code |
| 19 | QOpcUaApplicationIdentity identity; |
| 20 | |
| 21 | const QString applicationUri = QStringLiteral("urn:%1:%2:%3") |
| 22 | .arg(QHostInfo::localHostName()) |
| 23 | .arg(QCoreApplication::organizationName()) |
| 24 | .arg(QCoreApplication::applicationName()); |
| 25 | const QString productUri = QStringLiteral("urn:%1:%2") |
| 26 | .arg(QCoreApplication::organizationName()) |
| 27 | .arg(QCoreApplication::applicationName()); |
| 28 | |
| 29 | identity.setProductUri(productUri); |
| 30 | identity.setApplicationUri(applicationUri); |
| 31 | identity.setApplicationName(QCoreApplication::applicationName()); |
| 32 | identity.setApplicationType(QOpcUaApplicationDescription::Client); |
| 33 | |
| 34 | client->setApplicationIdentity(identity); |
| 35 | \endcode |
| 36 | |
| 37 | In case your application authenticates using certificates the application identity has to match |
| 38 | the used certificate. In this case all information is extracted from the certificate given in the |
| 39 | PKI configuration. |
| 40 | |
| 41 | \code |
| 42 | QOpcUaApplicationIdentity identity; |
| 43 | identity = pkiConfig.applicationIdentity(); |
| 44 | \endcode |
| 45 | */ |
| 46 | |
| 47 | class QOpcUaApplicationIdentityData : public QSharedData |
| 48 | { |
| 49 | public: |
| 50 | QOpcUaApplicationIdentityData() {} |
| 51 | |
| 52 | QOpcUaApplicationDescription::ApplicationType m_applicationType |
| 53 | {QOpcUaApplicationDescription::ApplicationType::Client}; |
| 54 | QString m_applicationUri; |
| 55 | QString m_applicationName; |
| 56 | QString m_productUri; |
| 57 | }; |
| 58 | |
| 59 | /*! |
| 60 | Default constructs an application identity with no parameters set. |
| 61 | */ |
| 62 | QOpcUaApplicationIdentity::QOpcUaApplicationIdentity() |
| 63 | : data(new QOpcUaApplicationIdentityData()) |
| 64 | {} |
| 65 | |
| 66 | QOpcUaApplicationIdentity::~QOpcUaApplicationIdentity() |
| 67 | {} |
| 68 | |
| 69 | /*! |
| 70 | Constructs an application identity from \a other. |
| 71 | */ |
| 72 | QOpcUaApplicationIdentity::QOpcUaApplicationIdentity(const QOpcUaApplicationIdentity &other) |
| 73 | : data(other.data) |
| 74 | {} |
| 75 | |
| 76 | /*! |
| 77 | Sets the values of \a rhs in this \l QOpcUaApplicationIdentity. |
| 78 | */ |
| 79 | QOpcUaApplicationIdentity &QOpcUaApplicationIdentity::operator=(const QOpcUaApplicationIdentity &rhs) |
| 80 | { |
| 81 | if (this != &rhs) |
| 82 | data.operator=(o: rhs.data); |
| 83 | return *this; |
| 84 | } |
| 85 | |
| 86 | /*! |
| 87 | Returns the application's application URI. |
| 88 | |
| 89 | This must be unique for each installation instance of the application and must match the ApplicationURI |
| 90 | in the application's certificate. |
| 91 | */ |
| 92 | QString QOpcUaApplicationIdentity::applicationUri() const |
| 93 | { |
| 94 | return data->m_applicationUri; |
| 95 | } |
| 96 | |
| 97 | /*! |
| 98 | Sets the applicationUri to \a value. |
| 99 | |
| 100 | \sa setApplicationName() |
| 101 | */ |
| 102 | void QOpcUaApplicationIdentity::setApplicationUri(const QString &value) |
| 103 | { |
| 104 | data->m_applicationUri = value; |
| 105 | } |
| 106 | |
| 107 | /*! |
| 108 | Returns the human readable name of the application. |
| 109 | This does not need to be unique. |
| 110 | */ |
| 111 | QString QOpcUaApplicationIdentity::applicationName() const |
| 112 | { |
| 113 | return data->m_applicationName; |
| 114 | } |
| 115 | |
| 116 | /*! |
| 117 | Sets the application name to \a value. |
| 118 | */ |
| 119 | void QOpcUaApplicationIdentity::setApplicationName(const QString &value) |
| 120 | { |
| 121 | data->m_applicationName = value; |
| 122 | } |
| 123 | |
| 124 | /*! |
| 125 | Returns the application's productUri. |
| 126 | |
| 127 | This uniquely identifies the product. |
| 128 | */ |
| 129 | QString QOpcUaApplicationIdentity::productUri() const |
| 130 | { |
| 131 | return data->m_productUri; |
| 132 | } |
| 133 | |
| 134 | /*! |
| 135 | Sets the productUri to \a value. |
| 136 | */ |
| 137 | void QOpcUaApplicationIdentity::setProductUri(const QString &value) |
| 138 | { |
| 139 | data->m_productUri = value; |
| 140 | } |
| 141 | |
| 142 | /*! |
| 143 | Returns the application's type. |
| 144 | */ |
| 145 | QOpcUaApplicationDescription::ApplicationType QOpcUaApplicationIdentity::applicationType() const |
| 146 | { |
| 147 | return data->m_applicationType; |
| 148 | } |
| 149 | |
| 150 | /*! |
| 151 | Sets the type of the application. |
| 152 | Client applications should set \a value to \l {QOpcUaApplicationDescription::Client}{Client}. |
| 153 | |
| 154 | The default value is \l{QOpcUaApplicationDescription::Client}{Client}. |
| 155 | */ |
| 156 | void QOpcUaApplicationIdentity::setApplicationType(QOpcUaApplicationDescription::ApplicationType value) |
| 157 | { |
| 158 | data->m_applicationType = value; |
| 159 | } |
| 160 | |
| 161 | /*! |
| 162 | Returns true if the application identity contains valid data. |
| 163 | */ |
| 164 | bool QOpcUaApplicationIdentity::isValid() const |
| 165 | { |
| 166 | return !data->m_applicationUri.isEmpty() && |
| 167 | !data->m_applicationName.isEmpty() && |
| 168 | !data->m_productUri.isEmpty(); |
| 169 | } |
| 170 | |
| 171 | QT_END_NAMESPACE |
| 172 |
