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

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

namespace Swift {
	CarbonsSentParser::CarbonsSentParser(PayloadParserFactoryCollection* factories) : GenericPayloadParser<CarbonsSent>(), factories_(factories), level_(TopLevel) {
	}

	CarbonsSentParser::~CarbonsSentParser() {
	}

	void CarbonsSentParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
		if (level_ == PayloadLevel) {
			if (element == "forwarded") {
				forwardedParser_ = boost::dynamic_pointer_cast<ForwardedParser>(boost::make_shared<ForwardedParser>(factories_));
			}
		}
		if (forwardedParser_) {
			forwardedParser_->handleStartElement(element, ns, attributes);
		}
		++level_;
	}

	void CarbonsSentParser::handleEndElement(const std::string& element, const std::string& ns) {
		--level_;
		if (forwardedParser_ && level_ >= PayloadLevel) {
			forwardedParser_->handleEndElement(element, ns);
		}
		if (forwardedParser_ && level_ == PayloadLevel) {
			/* done parsing nested stanza */
			getPayloadInternal()->setForwarded(forwardedParser_->getPayloadInternal());
			forwardedParser_.reset();
		}
	}

	void CarbonsSentParser::handleCharacterData(const std::string& data) {
		if (forwardedParser_) {
			forwardedParser_->handleCharacterData(data);
		}
	}
}