aboutsummaryrefslogtreecommitdiff
path: root/src/base/QXmppRegisterIq.cpp
blob: df44341147427e21007558f612a2be7afca85695 (plain) (blame)
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
/*
 * Copyright (C) 2008-2019 The QXmpp developers
 *
 * Author:
 *  Jeremy Lainé
 *
 * Source:
 *  https://github.com/qxmpp-project/qxmpp
 *
 * This file is a part of QXmpp library.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 */

#include <QDomElement>

#include "QXmppConstants_p.h"
#include "QXmppRegisterIq.h"

/// Returns the email for this registration IQ.

QString QXmppRegisterIq::email() const
{
    return m_email;
}

/// Sets the \a email for this registration IQ.

void QXmppRegisterIq::setEmail(const QString &email)
{
    m_email = email;
}

/// Returns the QXmppDataForm for this registration IQ.

QXmppDataForm QXmppRegisterIq::form() const
{
    return m_form;
}

/// Sets the QXmppDataForm for this registration IQ.
///
/// \param form

void QXmppRegisterIq::setForm(const QXmppDataForm &form)
{
    m_form = form;
}

/// Returns the instructions for this registration IQ.

QString QXmppRegisterIq::instructions() const
{
    return m_instructions;
}

/// Sets the \a instructions for this registration IQ.

void QXmppRegisterIq::setInstructions(const QString &instructions)
{
    m_instructions = instructions;
}

/// Returns the password for this registration IQ.

QString QXmppRegisterIq::password() const
{
    return m_password;
}

/// Sets the \a password for this registration IQ.

void QXmppRegisterIq::setPassword(const QString &password)
{
    m_password = password;
}

/// Returns the username for this registration IQ.

QString QXmppRegisterIq::username() const
{
    return m_username;
}

/// Sets the \a username for this registration IQ.

void QXmppRegisterIq::setUsername(const QString &username)
{
    m_username = username;
}

/// \cond
bool QXmppRegisterIq::isRegisterIq(const QDomElement &element)
{
    return (element.firstChildElement("query").namespaceURI() == ns_register);
}

void QXmppRegisterIq::parseElementFromChild(const QDomElement &element)
{
    QDomElement queryElement = element.firstChildElement("query");
    m_instructions = queryElement.firstChildElement("instructions").text();
    m_username = queryElement.firstChildElement("username").text();
    m_password = queryElement.firstChildElement("password").text();
    m_email = queryElement.firstChildElement("email").text();
    m_form.parse(queryElement.firstChildElement("x"));
}

void QXmppRegisterIq::toXmlElementFromChild(QXmlStreamWriter *writer) const
{
    writer->writeStartElement("query");
    writer->writeAttribute("xmlns", ns_register);
    if (!m_instructions.isEmpty())
        writer->writeTextElement("instructions", m_instructions);

    if (!m_username.isEmpty())
        writer->writeTextElement("username", m_username);
    else if (!m_username.isNull())
        writer->writeEmptyElement("username");

    if (!m_password.isEmpty())
        writer->writeTextElement("password", m_password);
    else if (!m_password.isNull())
        writer->writeEmptyElement("password");

    if (!m_email.isEmpty())
        writer->writeTextElement("email", m_email);
    else if (!m_email.isNull())
        writer->writeEmptyElement("email");

    m_form.toXml(writer);
    writer->writeEndElement();
}
/// \endcond