1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
|
// SPDX-FileCopyrightText: 2012 Jeremy Lainé <jeremy.laine@m4x.org>
// SPDX-FileCopyrightText: 2019 Linus Jahn <lnj@kaidan.im>
//
// SPDX-License-Identifier: LGPL-2.1-or-later
#include "QXmppRegisterIq.h"
#include "QXmppBitsOfBinaryDataList.h"
#include "QXmppConstants_p.h"
#include <QDomElement>
#include <QSharedData>
#define ELEMENT_REGISTERED QStringLiteral("registered")
#define ELEMENT_REMOVE QStringLiteral("remove")
class QXmppRegisterIqPrivate : public QSharedData
{
public:
QXmppRegisterIqPrivate();
QXmppDataForm form;
QString email;
QString instructions;
QString password;
QString username;
bool isRegistered;
bool isRemove;
QXmppBitsOfBinaryDataList bitsOfBinaryData;
QString outOfBandUrl;
};
QXmppRegisterIqPrivate::QXmppRegisterIqPrivate()
: isRegistered(false),
isRemove(false)
{
}
QXmppRegisterIq::QXmppRegisterIq()
: d(new QXmppRegisterIqPrivate)
{
}
/// Default copy-constructor
QXmppRegisterIq::QXmppRegisterIq(const QXmppRegisterIq &other) = default;
/// Default move-constructor
QXmppRegisterIq::QXmppRegisterIq(QXmppRegisterIq &&) = default;
QXmppRegisterIq::~QXmppRegisterIq() = default;
/// Default assignment operator
QXmppRegisterIq &QXmppRegisterIq::operator=(const QXmppRegisterIq &other) = default;
/// Default move-assignment operator
QXmppRegisterIq &QXmppRegisterIq::operator=(QXmppRegisterIq &&) = default;
/// Constructs a regular change password request.
///
/// \param username The username of the account of which the password should be
/// changed.
/// \param newPassword The new password that should be set.
/// \param to Optional JID of the registration service. If this is omitted, the
/// IQ is automatically addressed to the local server.
///
/// \since QXmpp 1.2
QXmppRegisterIq QXmppRegisterIq::createChangePasswordRequest(const QString &username, const QString &newPassword, const QString &to)
{
QXmppRegisterIq iq;
iq.setType(QXmppIq::Set);
iq.setTo(to);
iq.setUsername(username);
iq.setPassword(newPassword);
return iq;
}
/// Constructs a regular unregistration request.
///
/// \param to Optional JID of the registration service. If this is omitted, the
/// IQ is automatically addressed to the local server.
///
/// \since QXmpp 1.2
QXmppRegisterIq QXmppRegisterIq::createUnregistrationRequest(const QString &to)
{
QXmppRegisterIq iq;
iq.setType(QXmppIq::Set);
iq.setTo(to);
iq.setIsRemove(true);
return iq;
}
/// Returns the email for this registration IQ.
QString QXmppRegisterIq::email() const
{
return d->email;
}
/// Sets the \a email for this registration IQ.
void QXmppRegisterIq::setEmail(const QString &email)
{
d->email = email;
}
/// Returns the QXmppDataForm for this registration IQ.
QXmppDataForm QXmppRegisterIq::form() const
{
return d->form;
}
/// Sets the QXmppDataForm for this registration IQ.
///
/// \param form
void QXmppRegisterIq::setForm(const QXmppDataForm &form)
{
d->form = form;
}
/// Returns the instructions for this registration IQ.
QString QXmppRegisterIq::instructions() const
{
return d->instructions;
}
/// Sets the \a instructions for this registration IQ.
void QXmppRegisterIq::setInstructions(const QString &instructions)
{
d->instructions = instructions;
}
/// Returns the password for this registration IQ.
QString QXmppRegisterIq::password() const
{
return d->password;
}
/// Sets the \a password for this registration IQ.
void QXmppRegisterIq::setPassword(const QString &password)
{
d->password = password;
}
/// Returns the username for this registration IQ.
QString QXmppRegisterIq::username() const
{
return d->username;
}
/// Sets the \a username for this registration IQ.
void QXmppRegisterIq::setUsername(const QString &username)
{
d->username = username;
}
///
/// Returns whether the account is registered.
///
/// By default this is set to false.
///
/// \since QXmpp 1.2
///
bool QXmppRegisterIq::isRegistered() const
{
return d->isRegistered;
}
///
/// Sets whether the account is registered.
///
/// By default this is set to false.
///
/// \since QXmpp 1.2
///
void QXmppRegisterIq::setIsRegistered(bool isRegistered)
{
d->isRegistered = isRegistered;
}
///
/// Returns whether to remove (unregister) the account.
///
/// By default this is set to false.
///
/// \since QXmpp 1.2
///
bool QXmppRegisterIq::isRemove() const
{
return d->isRemove;
}
///
/// Sets whether to remove (unregister) the account.
///
/// By default this is set to false.
///
/// \since QXmpp 1.2
///
void QXmppRegisterIq::setIsRemove(bool isRemove)
{
d->isRemove = isRemove;
}
///
/// Returns a list of data packages attached using \xep{0231}: Bits of Binary.
///
/// This could be used to resolve a \c cid: URL of an CAPTCHA field of the
/// form.
///
/// \since QXmpp 1.2
///
QXmppBitsOfBinaryDataList QXmppRegisterIq::bitsOfBinaryData() const
{
return d->bitsOfBinaryData;
}
///
/// Returns a list of data attached using \xep{0231}: Bits of Binary.
///
/// This could be used to resolve a \c cid: URL of an CAPTCHA field of the
/// form.
///
/// \since QXmpp 1.2
///
QXmppBitsOfBinaryDataList &QXmppRegisterIq::bitsOfBinaryData()
{
return d->bitsOfBinaryData;
}
///
/// Sets a list of \xep{0231}: Bits of Binary attachments to be included.
///
/// \since QXmpp 1.2
///
void QXmppRegisterIq::setBitsOfBinaryData(const QXmppBitsOfBinaryDataList &bitsOfBinaryData)
{
d->bitsOfBinaryData = bitsOfBinaryData;
}
///
/// Returns a \xep{0066, Out of Band Data} URL used for out-of-band registration.
///
/// \since QXmpp 1.5
///
QString QXmppRegisterIq::outOfBandUrl() const
{
return d->outOfBandUrl;
}
///
/// Sets a \xep{0066, Out of Band Data} URL used for out-of-band registration.
///
/// \since QXmpp 1.5
///
void QXmppRegisterIq::setOutOfBandUrl(const QString &outOfBandUrl)
{
d->outOfBandUrl = outOfBandUrl;
}
/// \cond
bool QXmppRegisterIq::isRegisterIq(const QDomElement &element)
{
return (element.firstChildElement(QStringLiteral("query")).namespaceURI() == ns_register);
}
void QXmppRegisterIq::parseElementFromChild(const QDomElement &element)
{
QDomElement queryElement = element.firstChildElement(QStringLiteral("query"));
d->instructions = queryElement.firstChildElement(QStringLiteral("instructions")).text();
d->username = queryElement.firstChildElement(QStringLiteral("username")).text();
d->password = queryElement.firstChildElement(QStringLiteral("password")).text();
d->email = queryElement.firstChildElement(QStringLiteral("email")).text();
for (auto xElement = queryElement.firstChildElement(QStringLiteral("x"));
!xElement.isNull();
xElement = xElement.nextSiblingElement(QStringLiteral("x"))) {
if (xElement.namespaceURI() == ns_data) {
d->form.parse(xElement);
} else if (xElement.namespaceURI() == ns_oob) {
d->outOfBandUrl = xElement.firstChildElement(QStringLiteral("url")).text();
}
}
d->isRegistered = !queryElement.firstChildElement(ELEMENT_REGISTERED).isNull();
d->isRemove = !queryElement.firstChildElement(ELEMENT_REMOVE).isNull();
d->bitsOfBinaryData.parse(queryElement);
}
void QXmppRegisterIq::toXmlElementFromChild(QXmlStreamWriter *writer) const
{
writer->writeStartElement(QStringLiteral("query"));
writer->writeDefaultNamespace(ns_register);
if (!d->instructions.isEmpty()) {
writer->writeTextElement(QStringLiteral("instructions"), d->instructions);
}
if (d->isRegistered) {
writer->writeEmptyElement(ELEMENT_REGISTERED);
}
if (d->isRemove) {
writer->writeEmptyElement(ELEMENT_REMOVE);
}
if (!d->username.isEmpty()) {
writer->writeTextElement(QStringLiteral("username"), d->username);
} else if (!d->username.isNull()) {
writer->writeEmptyElement(QStringLiteral("username"));
}
if (!d->password.isEmpty()) {
writer->writeTextElement(QStringLiteral("password"), d->password);
} else if (!d->password.isNull()) {
writer->writeEmptyElement(QStringLiteral("password"));
}
if (!d->email.isEmpty()) {
writer->writeTextElement(QStringLiteral("email"), d->email);
} else if (!d->email.isNull()) {
writer->writeEmptyElement(QStringLiteral("email"));
}
d->form.toXml(writer);
d->bitsOfBinaryData.toXml(writer);
if (!d->outOfBandUrl.isEmpty()) {
writer->writeStartElement(QStringLiteral("x"));
writer->writeDefaultNamespace(ns_oob);
writer->writeTextElement(QStringLiteral("url"), d->outOfBandUrl);
writer->writeEndElement();
}
writer->writeEndElement();
}
/// \endcond
|