gloox 1.0.24
parser.h
1/*
2 Copyright (c) 2004-2019 by Jakob Schröter <js@camaya.net>
3 This file is part of the gloox library. http://camaya.net/gloox
4
5 This software is distributed under a license. The full license
6 agreement can be found in the file LICENSE in this distribution.
7 This software may not be copied, modified, sold or distributed
8 other than expressed in the named license agreement.
9
10 This software is distributed without any warranty.
11*/
12
13
14
15#ifndef PARSER_H__
16#define PARSER_H__
17
18#include "gloox.h"
19#include "taghandler.h"
20#include "tag.h"
21
22#include <string>
23
24namespace gloox
25{
26
27
34 class GLOOX_API Parser
35 {
36 public:
43 Parser( TagHandler* ph, bool deleteRoot = true );
44
48 virtual ~Parser();
49
56 int feed( std::string& data );
57
63 void cleanup( bool deleteRoot = true );
64
65 private:
66 enum ParserInternalState
67 {
68 Initial,
69 InterTag,
70 TagOpening,
71 TagOpeningSlash,
72 TagOpeningLt,
73 TagInside,
74 TagNameCollect,
75 TagNameComplete,
76 TagNameAlmostComplete,
77 TagAttribute,
78 TagAttributeComplete,
79 TagAttributeEqual,
80 TagClosing,
81 TagClosingSlash,
82 TagValueApos,
83 TagAttributeValue,
84 TagPreamble,
85 TagCDATASection
86 };
87
88 enum ForwardScanState
89 {
90 ForwardFound,
91 ForwardNotFound,
92 ForwardInsufficientSize
93 };
94
95 enum DecodeState
96 {
97 DecodeValid,
98 DecodeInvalid,
99 DecodeInsufficient
100 };
101
102 void addTag();
103 void addAttribute();
104 void addCData();
105 bool closeTag();
106 bool isWhitespace( unsigned char c );
107 void streamEvent( Tag* tag );
108 ForwardScanState forwardScan( std::string::size_type& pos, const std::string& data,
109 const std::string& needle );
110 DecodeState decode( std::string::size_type& pos, const std::string& data );
111
112 TagHandler* m_tagHandler;
113 Tag* m_current;
114 Tag* m_root;
115 StringMap* m_xmlnss;
116
117 ParserInternalState m_state;
118 Tag::AttributeList m_attribs;
119 std::string m_tag;
120 std::string m_cdata;
121 std::string m_attrib;
122 std::string m_value;
123 std::string m_xmlns;
124 std::string m_tagPrefix;
125 std::string m_attribPrefix;
126 std::string m_backBuffer;
127 int m_preamble;
128 bool m_quote;
129 bool m_haveTagPrefix;
130 bool m_haveAttribPrefix;
131 bool m_attribIsXmlns;
132 bool m_deleteRoot;
133
134 };
135
136}
137
138#endif // PARSER_H__
This class implements an XML parser.
Definition: parser.h:35
A virtual interface which can be reimplemented to receive non-XMPP Core stanzas.
Definition: taghandler.h:33
This is an abstraction of an XML element.
Definition: tag.h:47
std::list< Attribute * > AttributeList
Definition: tag.h:187
The namespace for the gloox library.
Definition: adhoc.cpp:28
std::map< std::string, std::string > StringMap
Definition: gloox.h:1261