summaryrefslogtreecommitdiffstats
blob: d222c40fd67998e998b9a7e0aa0b8b453313870c (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
/*
 * Copyright (c) 2010 Remko Tronçon
 * Licensed under the GNU General Public License v3.
 * See Documentation/Licenses/GPLv3.txt for more information.
 */

#include <Swiften/Parser/StreamErrorParser.h>

namespace Swift {

StreamErrorParser::StreamErrorParser() : level(TopLevel) {
}

void StreamErrorParser::handleStartElement(const String&, const String&, const AttributeMap&) {
	++level;
}

void StreamErrorParser::handleEndElement(const String& element, const String& ns) {
	--level;
	if (level == ElementLevel && ns == "urn:ietf:params:xml:ns:xmpp-streams") {
		if (element == "text") {
			getElementGeneric()->setText(currentText);
		}
		else if (element == "bad-format") {
			getElementGeneric()->setType(StreamError::BadFormat);
		}
		else if(element == "bad-namespace-prefix") {
			getElementGeneric()->setType(StreamError::BadNamespacePrefix);
		}
		else if(element == "conflict") {
			getElementGeneric()->setType(StreamError::Conflict);
		}
		else if(element == "connection-timeout") {
			getElementGeneric()->setType(StreamError::ConnectionTimeout);
		}
		else if(element == "host-gone") {
			getElementGeneric()->setType(StreamError::HostGone);
		}
		else if(element == "host-unknown") {
			getElementGeneric()->setType(StreamError::HostUnknown);
		}
		else if(element == "improper-addressing") {
			getElementGeneric()->setType(StreamError::ImproperAddressing);
		}
		else if(element == "internal-server-error") {
			getElementGeneric()->setType(StreamError::InternalServerError);
		}
		else if(element == "invalid-from") {
			getElementGeneric()->setType(StreamError::InvalidFrom);
		}
		else if(element == "invalid-id") {
			getElementGeneric()->setType(StreamError::InvalidID);
		}
		else if(element == "invalid-namespace") {
			getElementGeneric()->setType(StreamError::InvalidNamespace);
		}
		else if(element == "invalid-xml") {
			getElementGeneric()->setType(StreamError::InvalidXML);
		}
		else if(element == "not-authorized") {
			getElementGeneric()->setType(StreamError::NotAuthorized);
		}
		else if(element == "not-well-formed") {
			getElementGeneric()->setType(StreamError::NotWellFormed);
		}
		else if(element == "policy-violation") {
			getElementGeneric()->setType(StreamError::PolicyViolation);
		}
		else if(element == "remote-connection-failed") {
			getElementGeneric()->setType(StreamError::RemoteConnectionFailed);
		}
		else if(element == "reset") {
			getElementGeneric()->setType(StreamError::Reset);
		}
		else if(element == "resource-constraint") {
			getElementGeneric()->setType(StreamError::ResourceConstraint);
		}
		else if(element == "restricted-xml") {
			getElementGeneric()->setType(StreamError::RestrictedXML);
		}
		else if(element == "see-other-host") {
			getElementGeneric()->setType(StreamError::SeeOtherHost);
		}
		else if(element == "system-shutdown") {
			getElementGeneric()->setType(StreamError::SystemShutdown);
		}
		else if(element == "undefined-condition") {
			getElementGeneric()->setType(StreamError::UndefinedCondition);
		}
		else if(element == "unsupported-encoding") {
			getElementGeneric()->setType(StreamError::UnsupportedEncoding);
		}
		else if(element == "unsupported-stanza-type") {
			getElementGeneric()->setType(StreamError::UnsupportedStanzaType);
		}
		else if(element == "unsupported-version") {
			getElementGeneric()->setType(StreamError::UnsupportedVersion);
		}
		else {
			getElementGeneric()->setType(StreamError::UndefinedCondition);
		}
	}
}

void StreamErrorParser::handleCharacterData(const String& data) {
	currentText += data;
}

}