KUnifiedPush

connector.h
1/*
2 SPDX-FileCopyrightText: 2022 Volker Krause <vkrause@kde.org>
3 SPDX-License-Identifier: LGPL-2.0-or-later
4*/
5
6#ifndef KUNIFIEDPUSH_CONNECTOR_H
7#define KUNIFIEDPUSH_CONNECTOR_H
8
9#include "kunifiedpush_export.h"
10
11#include <QObject>
12
13/** Client-side integration with UnifiedPush. */
14namespace KUnifiedPush {
15
16class ConnectorPrivate;
17
18/** Client connector to UnifiedPush.
19 * Registers with a local UnifedPush distributor if present
20 * and obtains an endpoint that can be used for push notifications.
21 */
22class KUNIFIEDPUSH_EXPORT Connector : public QObject
23{
25 Q_PROPERTY(QString endpoint READ endpoint NOTIFY endpointChanged)
26 Q_PROPERTY(State state READ state NOTIFY stateChanged)
27 Q_PROPERTY(QString vapidPublicKey READ vapidPublicKey WRITE setVapidPublicKey NOTIFY vapidPublicKeyChanged)
28 Q_PROPERTY(bool vapidPublicKeyRequired READ vapidPublicKeyRequired WRITE setVapidPublicKeyRequired NOTIFY vapidPublicKeyRequiredChanged)
29public:
30 /** Create a new connector instance.
31 * @param serviceName The application identifier, same as used for registration
32 * on D-Bus and for D-Bus activation.
33 */
34 explicit Connector(const QString &serviceName, QObject *parent = nullptr);
35 ~Connector();
36
37 /** HTTP endpoint to trigger the push notification.
38 * This needs to be communicated to the corresponding server-side application.
39 * @see endpointChanged
40 */
41 [[nodiscard]] QString endpoint() const;
42
43 /** Register this client.
44 * This is for subscribing to push notifications and is only needed the first
45 * time an application uses this, or after explicitly unregistering. The registration
46 * is persisted until explicitly changed.
47 * @param description A human-readable explanation what push notifications are used
48 * for by this application.
49 *
50 * @see setVapidPublicKey
51 */
52 void registerClient(const QString &description);
53
54 /** Unregister this client.
55 * This is for permanently unsubscribing, do not use on regular application shutdown.
56 */
57 void unregisterClient();
58
59 /** Connector state. */
60 enum State {
61 Unregistered, ///< Connector is not yet registered, or explicitly unregistered.
62 Registering, ///< Connector is registering with the push provider.
63 Registered, ///< Connector is registered and thus operational.
64 NoDistributor, ///< Connector cannot find a UnifiedPush distributor to register at.
65 Error, ///< Any other error condition.
66 };
67 Q_ENUM(State)
68 /** State of the connector. */
69 [[nodiscard]] State state() const;
70 // TODO error message
71
72 /** Returns the VAPID public key of the corresponding application.
73 * @see setVapidPublicKey
74 * @since 25.08
75 */
76 [[nodiscard]] QString vapidPublicKey() const;
77
78 /** Sets the Voluntary Application Server Identification (VAPID) public key of the corresponding application.
79 *
80 * This is a public key on the P-256 curve encoded in the uncompressed form and BASE64 URL encoded.
81 * This is used by the application server to identify itself to the push server, following RFC8292.
82 *
83 * The VAPID public key is persisted, ie. you don't need to store it separately in the application.
84 *
85 * @note This should be either called before calling registerClient() or vapidPublicKeyRequired should
86 * be set to @c true.
87 *
88 * @see RFC 8292
89 *
90 * @since 25.08
91 */
92 void setVapidPublicKey(const QString &vapidPublicKey);
93
94 /** Returns whether a VAPID public key is required before registering
95 * with the push provider.
96 * @see setVapidPublicKeyRequired
97 * @since 25.08
98 */
99 [[nodiscard]] bool vapidPublicKeyRequired() const;
100
101 /** Sets whether a Voluntary Application Server Identification (VAPID) public key
102 * is required before registering with the push provider.
103 *
104 * When this is set, calling registerClient() will wait for a VAPID key to be set
105 * via setVapidPublicKey(). This is useful when the VAPID key has first to be retrieved
106 * asynchronously from the application server.
107 *
108 * @see setVapidPublicKey
109 *
110 * @since 25.08
111 */
112 void setVapidPublicKeyRequired(bool vapidRequired);
113
114 /** Content encryption user agent public key.
115 *
116 * When now key pair and authentication secret exist yet, a new one is generated
117 * and persisted.
118 *
119 * When a key pair and authentication secret exists incoming messages are
120 * automatically decrypted.
121 *
122 * @note This returns the raw 65 byte key data, application server APIs
123 * typically want this in e.g. Base64 URL encoding.
124 *
125 * @see RFC 8291
126 *
127 * @since 25.08
128 */
129 [[nodiscard]] QByteArray contentEncryptionPublicKey() const;
130
131 /** Content encryption authentication secret.
132 *
133 * When now key pair and authentication secret exist yet, a new one is generated
134 * and persisted.
135 *
136 * When a key pair and authentication secret exists incoming messages are
137 * automatically decrypted.
138 *
139 * @note This returns the raw 16 byte key data, application server APIs
140 * typically want this in e.g. Base64 URL encoding.
141 *
142 * @see RFC 8291
143 *
144 * @since 25.08
145 */
146 [[nodiscard]] QByteArray contentEncryptionAuthSecret() const;
147
148Q_SIGNALS:
149 /** Emitted for each newly received push message. */
150 void messageReceived(const QByteArray &msg);
151
152 /** Emitted when a new endpoint URL has been received. */
153 void endpointChanged(const QString &endpoint);
154
155 /** Emitted when the connector state changes. */
157
158 /** Emitted when the VAPID public key changed.
159 * @since 25.08
160 */
162
163 /** Emitted when the VAPID public key required property changed.
164 * @since 25.08
165 */
167
168private:
169 ConnectorPrivate *const d;
170};
171
172}
173
174#endif
Connector(const QString &serviceName, QObject *parent=nullptr)
Create a new connector instance.
void endpointChanged(const QString &endpoint)
Emitted when a new endpoint URL has been received.
void setVapidPublicKeyRequired(bool vapidRequired)
Sets whether a Voluntary Application Server Identification (VAPID) public key is required before regi...
void messageReceived(const QByteArray &msg)
Emitted for each newly received push message.
void vapidPublicKeyChanged()
Emitted when the VAPID public key changed.
void unregisterClient()
Unregister this client.
State
Connector state.
Definition connector.h:60
@ Error
Any other error condition.
Definition connector.h:65
@ NoDistributor
Connector cannot find a UnifiedPush distributor to register at.
Definition connector.h:64
@ Registering
Connector is registering with the push provider.
Definition connector.h:62
@ Registered
Connector is registered and thus operational.
Definition connector.h:63
@ Unregistered
Connector is not yet registered, or explicitly unregistered.
Definition connector.h:61
void vapidPublicKeyRequiredChanged()
Emitted when the VAPID public key required property changed.
void registerClient(const QString &description)
Register this client.
void setVapidPublicKey(const QString &vapidPublicKey)
Sets the Voluntary Application Server Identification (VAPID) public key of the corresponding applicat...
void stateChanged(KUnifiedPush::Connector::State state)
Emitted when the connector state changes.
Client-side integration with UnifiedPush.
Definition connector.h:14
QObject(QObject *parent)
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Apr 25 2025 12:05:39 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.