2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
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.
11 #ifndef WEBRTC_LIBJINGLE_XMPP_XMPPSTANZAPARSER_H_
12 #define WEBRTC_LIBJINGLE_XMPP_XMPPSTANZAPARSER_H_
14 #include "webrtc/libjingle/xmllite/xmlbuilder.h"
15 #include "webrtc/libjingle/xmllite/xmlparser.h"
22 class XmppStanzaParseHandler {
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;
31 class XmppStanzaParser {
33 XmppStanzaParser(XmppStanzaParseHandler *psph);
34 bool Parse(const char * data, size_t len, bool isFinal)
35 { return parser_.Parse(data, len, isFinal); }
39 class ParseHandler : public XmlParseHandler {
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,
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,
53 { outer_->IncomingError(pctx, errCode); }
55 XmppStanzaParser * const outer_;
58 friend class ParseHandler;
60 void IncomingStartElement(XmlParseContext * pctx,
61 const char * name, const char ** atts);
62 void IncomingEndElement(XmlParseContext * pctx,
64 void IncomingCharacterData(XmlParseContext * pctx,
65 const char * text, int len);
66 void IncomingError(XmlParseContext * pctx,
69 XmppStanzaParseHandler * psph_;
70 ParseHandler innerHandler_;
80 #endif // WEBRTC_LIBJINGLE_XMPP_XMPPSTANZAPARSER_H_