Commit 53beda0a authored by François Cartegnie's avatar François Cartegnie 🤞
Browse files

demux: dash: fix and debug DOM Parsing

parent 98df0fd9
......@@ -29,6 +29,7 @@
#include "../Helper.h"
#include <vector>
#include <stack>
#include <vlc_xml.h>
#include <vlc_stream.h>
......@@ -68,43 +69,74 @@ bool DOMParser::parse ()
if(!this->vlc_reader)
return false;
this->root = this->processNode();
if ( this->root == NULL )
root = processNode();
if ( root == NULL )
return false;
return true;
}
Node* DOMParser::processNode ()
Node* DOMParser::processNode()
{
const char *data;
int type = xml_ReaderNextNode(this->vlc_reader, &data);
if(type != -1 && type != XML_READER_NONE && type != XML_READER_ENDELEM)
{
Node *node = new Node();
node->setType( type );
int type;
std::stack<Node *> lifo;
if ( type != XML_READER_TEXT )
while( (type = xml_ReaderNextNode(vlc_reader, &data)) > 0 )
{
switch(type)
{
std::string name = data;
bool isEmpty = xml_ReaderIsEmptyElement(this->vlc_reader);
node->setName(name);
this->addAttributesToNode(node);
case XML_READER_STARTELEM:
{
bool empty = xml_ReaderIsEmptyElement(vlc_reader);
Node *node = new (std::nothrow) Node();
if(node)
{
if(!lifo.empty())
lifo.top()->addSubNode(node);
lifo.push(node);
node->setName(std::string(data));
addAttributesToNode(node);
}
if(empty)
lifo.pop();
break;
}
case XML_READER_TEXT:
{
if(!lifo.empty())
lifo.top()->setText(std::string(data));
break;
}
case XML_READER_ENDELEM:
{
if(lifo.empty())
return NULL;
Node *node = lifo.top();
lifo.pop();
if(lifo.empty())
return node;
}
default:
break;
}
}
if(isEmpty)
return node;
while( lifo.size() > 1 )
lifo.pop();
Node *subnode = NULL;
if(!lifo.empty())
delete lifo.top();
while((subnode = this->processNode()) != NULL)
node->addSubNode(subnode);
}
else
node->setText( data );
return node;
}
return NULL;
}
void DOMParser::addAttributesToNode (Node *node)
{
const char *attrValue;
......
......@@ -94,20 +94,9 @@ std::vector<std::string> Node::getAttributeKeys () const
return keys;
}
bool Node::hasText () const
{
return false;
}
const std::string& Node::getText () const
{
if ( this->type == XML_READER_TEXT )
return this->text;
else
{
assert( this->subNodes.size() == 1 );
return this->subNodes[0]->getText();
}
return text;
}
void Node::setText(const std::string &text)
......@@ -129,3 +118,18 @@ void Node::setType(int type)
{
this->type = type;
}
std::vector<std::string> Node::toString(int indent) const
{
std::vector<std::string> ret;
std::string text(indent, ' ');
text.append(getName());
ret.push_back(text);
std::vector<Node *>::const_iterator l;
for(l = subNodes.begin(); l < subNodes.end(); l++)
{
std::vector<std::string> sub = (*l)->toString(indent + 1);
ret.insert(ret.end(), sub.begin(), sub.end());
}
return ret;
}
......@@ -48,12 +48,12 @@ namespace dash
void addAttribute (const std::string& key, const std::string& value);
const std::string& getAttributeValue (const std::string& key) const;
std::vector<std::string> getAttributeKeys () const;
bool hasText () const;
const std::string& getText () const;
void setText( const std::string &text );
const std::map<std::string, std::string>& getAttributes () const;
int getType() const;
void setType( int type );
std::vector<std::string> toString(int) const;
private:
static const std::string EmptyString;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment