xmppstanzaparser.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  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. #ifndef THIRD_PARTY_LIBJINGLE_XMPP_XMPP_XMPPSTANZAPARSER_H_
  11. #define THIRD_PARTY_LIBJINGLE_XMPP_XMPP_XMPPSTANZAPARSER_H_
  12. #include "third_party/libjingle_xmpp/xmllite/xmlbuilder.h"
  13. #include "third_party/libjingle_xmpp/xmllite/xmlparser.h"
  14. namespace jingle_xmpp {
  15. class XmlElement;
  16. class XmppStanzaParseHandler {
  17. public:
  18. virtual ~XmppStanzaParseHandler() {}
  19. virtual void StartStream(const XmlElement * pelStream) = 0;
  20. virtual void Stanza(const XmlElement * pelStanza) = 0;
  21. virtual void EndStream() = 0;
  22. virtual void XmlError() = 0;
  23. };
  24. class XmppStanzaParser {
  25. public:
  26. XmppStanzaParser(XmppStanzaParseHandler *psph);
  27. bool Parse(const char * data, size_t len, bool isFinal)
  28. { return parser_.Parse(data, len, isFinal); }
  29. void Reset();
  30. private:
  31. class ParseHandler : public XmlParseHandler {
  32. public:
  33. ParseHandler(XmppStanzaParser * outer) : outer_(outer) {}
  34. virtual void StartElement(XmlParseContext * pctx,
  35. const char * name, const char ** atts)
  36. { outer_->IncomingStartElement(pctx, name, atts); }
  37. virtual void EndElement(XmlParseContext * pctx,
  38. const char * name)
  39. { outer_->IncomingEndElement(pctx, name); }
  40. virtual void CharacterData(XmlParseContext * pctx,
  41. const char * text, int len)
  42. { outer_->IncomingCharacterData(pctx, text, len); }
  43. virtual void Error(XmlParseContext * pctx,
  44. XML_Error errCode)
  45. { outer_->IncomingError(pctx, errCode); }
  46. private:
  47. XmppStanzaParser * const outer_;
  48. };
  49. friend class ParseHandler;
  50. void IncomingStartElement(XmlParseContext * pctx,
  51. const char * name, const char ** atts);
  52. void IncomingEndElement(XmlParseContext * pctx,
  53. const char * name);
  54. void IncomingCharacterData(XmlParseContext * pctx,
  55. const char * text, int len);
  56. void IncomingError(XmlParseContext * pctx,
  57. XML_Error errCode);
  58. XmppStanzaParseHandler * psph_;
  59. ParseHandler innerHandler_;
  60. XmlParser parser_;
  61. int depth_;
  62. XmlBuilder builder_;
  63. };
  64. }
  65. #endif // THIRD_PARTY_LIBJINGLE_XMPP_XMPP_XMPPSTANZAPARSER_H_