parser.h
/*
Copyright (c) 2004-2023 by Jakob Schröter <js@camaya.net>
This file is part of the gloox library. http://camaya.net/gloox
This software is distributed under a license. The full license
agreement can be found in the file LICENSE in this distribution.
This software may not be copied, modified, sold or distributed
other than expressed in the named license agreement.
This software is distributed without any warranty.
*/
#ifndef PARSER_H__
#define PARSER_H__
#include "gloox.h"
#include "taghandler.h"
#include "tag.h"
#include <string>
namespace gloox
{
class GLOOX_API Parser
{
public:
Parser( TagHandler* ph, bool deleteRoot = true );
virtual ~Parser();
int feed( std::string& data );
void cleanup( bool deleteRoot = true );
private:
enum ParserInternalState
{
Initial,
InterTag,
TagOpening,
TagOpeningSlash,
TagOpeningLt,
TagInside,
TagNameCollect,
TagNameComplete,
TagNameAlmostComplete,
TagAttribute,
TagAttributeComplete,
TagAttributeEqual,
TagClosing,
TagClosingSlash,
TagValueApos,
TagAttributeValue,
TagPreamble,
TagCDATASection
};
enum ForwardScanState
{
ForwardFound,
ForwardNotFound,
ForwardInsufficientSize
};
enum DecodeState
{
DecodeValid,
DecodeInvalid,
DecodeInsufficient
};
void addTag();
void addAttribute();
void addCData();
bool closeTag();
bool isWhitespace( unsigned char c );
void streamEvent( Tag* tag );
ForwardScanState forwardScan( std::string::size_type& pos, const std::string& data,
const std::string& needle );
DecodeState decode( std::string::size_type& pos, const std::string& data );
TagHandler* m_tagHandler;
Tag* m_current;
Tag* m_root;
StringMap* m_xmlnss;
ParserInternalState m_state;
Tag::AttributeList m_attribs;
std::string m_tag;
std::string m_cdata;
std::string m_attrib;
std::string m_value;
std::string m_xmlns;
std::string m_tagPrefix;
std::string m_attribPrefix;
std::string m_backBuffer;
int m_preamble;
bool m_quote;
bool m_haveTagPrefix;
bool m_haveAttribPrefix;
bool m_attribIsXmlns;
bool m_deleteRoot;
};
}
#endif // PARSER_H__
gloox::Parser::Parser
Parser(TagHandler *ph, bool deleteRoot=true)
Definition parser.cpp:22
gloox::Parser::cleanup
void cleanup(bool deleteRoot=true)
Definition parser.cpp:774
gloox::Parser::feed
int feed(std::string &data)
Definition parser.cpp:161
gloox::TagHandler
A virtual interface which can be reimplemented to receive non-XMPP Core stanzas.
Definition taghandler.h:33
gloox::Tag
This is an abstraction of an XML element.
Definition tag.h:47
gloox::Tag::AttributeList
std::list< Attribute * > AttributeList
Definition tag.h:187
gloox
The namespace for the gloox library.
Definition adhoc.cpp:28
gloox::StringMap
std::map< std::string, std::string > StringMap
Definition gloox.h:1261