blob: 7afa762fc5e801c221e347da37d8dc038ac80eae (
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
|
#include "Swiften/StreamStack/XMPPLayer.h"
#include "Swiften/Parser/XMPPParser.h"
#include "Swiften/Serializer/XMPPSerializer.h"
namespace Swift {
XMPPLayer::XMPPLayer(
PayloadParserFactoryCollection* payloadParserFactories,
PayloadSerializerCollection* payloadSerializers) :
payloadParserFactories_(payloadParserFactories),
payloadSerializers_(payloadSerializers),
resetParserAfterParse_(false),
inParser_(false) {
xmppParser_ = new XMPPParser(this, payloadParserFactories_);
xmppSerializer_ = new XMPPSerializer(payloadSerializers_);
}
XMPPLayer::~XMPPLayer() {
delete xmppSerializer_;
delete xmppParser_;
}
void XMPPLayer::writeHeader(const String& domain) {
onWriteData(ByteArray(xmppSerializer_->serializeHeader(domain)));
}
void XMPPLayer::writeFooter() {
onWriteData(ByteArray(xmppSerializer_->serializeFooter()));
}
void XMPPLayer::writeElement(boost::shared_ptr<Element> element) {
onWriteData(ByteArray(xmppSerializer_->serializeElement(element)));
}
void XMPPLayer::writeData(const String& data) {
onWriteData(ByteArray(data));
}
void XMPPLayer::parseData(ByteArray data) {
onDataRead(data);
inParser_ = true;
if (!xmppParser_->parse(String(data.getData(), data.getSize()))) {
inParser_ = false;
onError();
return;
}
inParser_ = false;
if (resetParserAfterParse_) {
doResetParser();
}
}
void XMPPLayer::doResetParser() {
delete xmppParser_;
xmppParser_ = new XMPPParser(this, payloadParserFactories_);
resetParserAfterParse_ = false;
}
void XMPPLayer::handleStreamStart() {
onStreamStart();
}
void XMPPLayer::handleElement(boost::shared_ptr<Element> stanza) {
onElement(stanza);
}
void XMPPLayer::handleStreamEnd() {
}
void XMPPLayer::resetParser() {
if (inParser_) {
resetParserAfterParse_ = true;
}
else {
doResetParser();
}
}
}
|