blob: 3ad052e4ff2fcc05bf722f77f80d0139ea84b016 [file] [log] [blame]
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +00001/*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#ifndef WEBRTC_LIBJINGLE_XMPP_XMPPSTANZAPARSER_H_
12#define WEBRTC_LIBJINGLE_XMPP_XMPPSTANZAPARSER_H_
13
14#include "webrtc/libjingle/xmllite/xmlbuilder.h"
15#include "webrtc/libjingle/xmllite/xmlparser.h"
16
17
18namespace buzz {
19
20class XmlElement;
21
22class XmppStanzaParseHandler {
23public:
24 virtual ~XmppStanzaParseHandler() {}
25 virtual void StartStream(const XmlElement * pelStream) = 0;
26 virtual void Stanza(const XmlElement * pelStanza) = 0;
27 virtual void EndStream() = 0;
28 virtual void XmlError() = 0;
29};
30
31class XmppStanzaParser {
32public:
33 XmppStanzaParser(XmppStanzaParseHandler *psph);
34 bool Parse(const char * data, size_t len, bool isFinal)
35 { return parser_.Parse(data, len, isFinal); }
36 void Reset();
37
38private:
39 class ParseHandler : public XmlParseHandler {
40 public:
41 ParseHandler(XmppStanzaParser * outer) : outer_(outer) {}
42 virtual void StartElement(XmlParseContext * pctx,
43 const char * name, const char ** atts)
44 { outer_->IncomingStartElement(pctx, name, atts); }
45 virtual void EndElement(XmlParseContext * pctx,
46 const char * name)
47 { outer_->IncomingEndElement(pctx, name); }
48 virtual void CharacterData(XmlParseContext * pctx,
49 const char * text, int len)
50 { outer_->IncomingCharacterData(pctx, text, len); }
51 virtual void Error(XmlParseContext * pctx,
52 XML_Error errCode)
53 { outer_->IncomingError(pctx, errCode); }
54 private:
55 XmppStanzaParser * const outer_;
56 };
57
58 friend class ParseHandler;
59
60 void IncomingStartElement(XmlParseContext * pctx,
61 const char * name, const char ** atts);
62 void IncomingEndElement(XmlParseContext * pctx,
63 const char * name);
64 void IncomingCharacterData(XmlParseContext * pctx,
65 const char * text, int len);
66 void IncomingError(XmlParseContext * pctx,
67 XML_Error errCode);
68
69 XmppStanzaParseHandler * psph_;
70 ParseHandler innerHandler_;
71 XmlParser parser_;
72 int depth_;
73 XmlBuilder builder_;
74
75 };
76
77
78}
79
80#endif // WEBRTC_LIBJINGLE_XMPP_XMPPSTANZAPARSER_H_