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

#include <Swiften/Parser/PayloadParsers/ErrorParser.h>

#include <Swiften/Parser/PayloadParserFactory.h>
#include <Swiften/Parser/PayloadParserFactoryCollection.h>

namespace Swift {

ErrorParser::ErrorParser(PayloadParserFactoryCollection* factories) : factories(factories), level_(TopLevel) {
}

void ErrorParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
	if (level_ == TopLevel) {
		std::string type = attributes.getAttribute("type");
		if (type == "continue") {
			getPayloadInternal()->setType(ErrorPayload::Continue);
		}
		else if (type == "modify") {
			getPayloadInternal()->setType(ErrorPayload::Modify);
		}
		else if (type == "auth") {
			getPayloadInternal()->setType(ErrorPayload::Auth);
		}
		else if (type == "wait") {
			getPayloadInternal()->setType(ErrorPayload::Wait);
		}
		else {
			getPayloadInternal()->setType(ErrorPayload::Cancel);
		}
	}
	else if (level_ == PayloadLevel) {
		if (element == "text") {

		}
		else if (element == "bad-request") {
			getPayloadInternal()->setCondition(ErrorPayload::BadRequest);
		}
		else if (element == "conflict") {
			getPayloadInternal()->setCondition(ErrorPayload::Conflict);
		}
		else if (element == "feature-not-implemented") {
			getPayloadInternal()->setCondition(ErrorPayload::FeatureNotImplemented);
		}
		else if (element == "forbidden") {
			getPayloadInternal()->setCondition(ErrorPayload::Forbidden);
		}
		else if (element == "gone") {
			getPayloadInternal()->setCondition(ErrorPayload::Gone);
		}
		else if (element == "internal-server-error") {
			getPayloadInternal()->setCondition(ErrorPayload::InternalServerError);
		}
		else if (element == "item-not-found") {
			getPayloadInternal()->setCondition(ErrorPayload::ItemNotFound);
		}
		else if (element == "jid-malformed") {
			getPayloadInternal()->setCondition(ErrorPayload::JIDMalformed);
		}
		else if (element == "not-acceptable") {
			getPayloadInternal()->setCondition(ErrorPayload::NotAcceptable);
		}
		else if (element == "not-allowed") {
			getPayloadInternal()->setCondition(ErrorPayload::NotAllowed);
		}
		else if (element == "not-authorized") {
			getPayloadInternal()->setCondition(ErrorPayload::NotAuthorized);
		}
		else if (element == "payment-required") {
			getPayloadInternal()->setCondition(ErrorPayload::PaymentRequired);
		}
		else if (element == "recipient-unavailable") {
			getPayloadInternal()->setCondition(ErrorPayload::RecipientUnavailable);
		}
		else if (element == "redirect") {
			getPayloadInternal()->setCondition(ErrorPayload::Redirect);
		}
		else if (element == "registration-required") {
			getPayloadInternal()->setCondition(ErrorPayload::RegistrationRequired);
		}
		else if (element == "remote-server-not-found") {
			getPayloadInternal()->setCondition(ErrorPayload::RemoteServerNotFound);
		}
		else if (element == "remote-server-timeout") {
			getPayloadInternal()->setCondition(ErrorPayload::RemoteServerTimeout);
		}
		else if (element == "resource-constraint") {
			getPayloadInternal()->setCondition(ErrorPayload::ResourceConstraint);
		}
		else if (element == "service-unavailable") {
			getPayloadInternal()->setCondition(ErrorPayload::ServiceUnavailable);
		}
		else if (element == "subscription-required") {
			getPayloadInternal()->setCondition(ErrorPayload::SubscriptionRequired);
		}
		else if (element == "unexpected-request") {
			getPayloadInternal()->setCondition(ErrorPayload::UnexpectedRequest);
		}
		else {
			PayloadParserFactory* payloadParserFactory = factories->getPayloadParserFactory(element, ns, attributes);
			if (payloadParserFactory) {
				currentPayloadParser.reset(payloadParserFactory->createPayloadParser());
			} else {
				getPayloadInternal()->setCondition(ErrorPayload::UndefinedCondition);
			}
		}
	}
	if (level_ >= PayloadLevel && currentPayloadParser) {
		currentPayloadParser->handleStartElement(element, ns, attributes);
	}
	++level_;
}

void ErrorParser::handleEndElement(const std::string& element, const std::string& ns) {
	--level_;
	if (currentPayloadParser) {
		if (level_ >= PayloadLevel) {
			currentPayloadParser->handleEndElement(element, ns);
		}

		if (level_ == PayloadLevel) {
			getPayloadInternal()->setPayload(currentPayloadParser->getPayload());
			currentPayloadParser.reset();
		}
	}
	else if (level_ == PayloadLevel) {
		if (element == "text") {
			getPayloadInternal()->setText(currentText_);
		}
	}
}

void ErrorParser::handleCharacterData(const std::string& data) {
	if (level_ > PayloadLevel && currentPayloadParser) {
		currentPayloadParser->handleCharacterData(data);
	}
	else {
		currentText_ += data;
	}
}

}