summaryrefslogtreecommitdiffstats
blob: 31b023fd620a3c2c865b59a78a93993fd61a01de (plain)
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
/*
 * Copyright (c) 2010-2016 Isode Limited.
 * All rights reserved.
 * See the COPYING file for more information.
 */

#include <Swiften/Serializer/PayloadSerializers/InBandRegistrationPayloadSerializer.h>

#include <memory>

#include <Swiften/Base/foreach.h>
#include <Swiften/Serializer/PayloadSerializers/FormSerializer.h>
#include <Swiften/Serializer/XML/XMLElement.h>
#include <Swiften/Serializer/XML/XMLRawTextNode.h>

namespace Swift {

InBandRegistrationPayloadSerializer::InBandRegistrationPayloadSerializer() {
}

std::string InBandRegistrationPayloadSerializer::serializePayload(std::shared_ptr<InBandRegistrationPayload> registration)    const {
    XMLElement registerElement("query", "jabber:iq:register");

    if (registration->isRegistered()) {
        registerElement.addNode(XMLElement::ref(new XMLElement("registered")));
    }

    if (registration->isRemove()) {
        registerElement.addNode(XMLElement::ref(new XMLElement("remove")));
    }

    if (registration->getInstructions()) {
        registerElement.addNode(XMLElement::ref(new XMLElement("instructions", "", *registration->getInstructions())));
    }


    if (registration->getUsername()) {
        registerElement.addNode(XMLElement::ref(new XMLElement("username", "", *registration->getUsername())));
    }

    if (registration->getNick()) {
        registerElement.addNode(XMLElement::ref(new XMLElement("nick", "", *registration->getNick())));
    }

    if (registration->getPassword()) {
        registerElement.addNode(XMLElement::ref(new XMLElement("password", "", *registration->getPassword())));
    }

    if (registration->getName()) {
        registerElement.addNode(XMLElement::ref(new XMLElement("name", "", *registration->getName())));
    }

    if (registration->getFirst()) {
        registerElement.addNode(XMLElement::ref(new XMLElement("first", "", *registration->getFirst())));
    }

    if (registration->getLast()) {
        registerElement.addNode(XMLElement::ref(new XMLElement("last", "", *registration->getLast())));
    }

    if (registration->getEMail()) {
        registerElement.addNode(XMLElement::ref(new XMLElement("email", "", *registration->getEMail())));
    }

    if (registration->getAddress()) {
        registerElement.addNode(XMLElement::ref(new XMLElement("address", "", *registration->getAddress())));
    }

    if (registration->getCity()) {
        registerElement.addNode(XMLElement::ref(new XMLElement("city", "", *registration->getCity())));
    }

    if (registration->getState()) {
        registerElement.addNode(XMLElement::ref(new XMLElement("state", "", *registration->getState())));
    }

    if (registration->getZip()) {
        registerElement.addNode(XMLElement::ref(new XMLElement("zip", "", *registration->getZip())));
    }

    if (registration->getPhone()) {
        registerElement.addNode(XMLElement::ref(new XMLElement("phone", "", *registration->getPhone())));
    }

    if (registration->getURL()) {
        registerElement.addNode(XMLElement::ref(new XMLElement("url", "", *registration->getURL())));
    }

    if (registration->getDate()) {
        registerElement.addNode(XMLElement::ref(new XMLElement("date", "", *registration->getDate())));
    }

    if (registration->getMisc()) {
        registerElement.addNode(XMLElement::ref(new XMLElement("misc", "", *registration->getMisc())));
    }

    if (registration->getText()) {
        registerElement.addNode(XMLElement::ref(new XMLElement("text", "", *registration->getText())));
    }

    if (registration->getKey()) {
        registerElement.addNode(XMLElement::ref(new XMLElement("key", "", *registration->getKey())));
    }

    if (Form::ref form = registration->getForm()) {
        registerElement.addNode(std::make_shared<XMLRawTextNode>(FormSerializer().serialize(form)));
    }

    return registerElement.serialize();
}

}