Removed SAX based PDML parser
This commit is contained in:
parent
69d488d8a2
commit
f0e2b1ca50
@ -103,255 +103,6 @@ void PdmlDefaultProtocol::unknownFieldHandler(QString name,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
// ---------------------------------------------------------- //
|
|
||||||
// PdmlParser
|
|
||||||
// ---------------------------------------------------------- //
|
|
||||||
PdmlParser::PdmlParser(OstProto::StreamConfigList *streams)
|
|
||||||
{
|
|
||||||
skipCount_ = 0;
|
|
||||||
currentPdmlProtocol_ = NULL;
|
|
||||||
|
|
||||||
streams_ = streams;
|
|
||||||
|
|
||||||
protocolMap_.insert("unknown", new PdmlUnknownProtocol());
|
|
||||||
protocolMap_.insert("geninfo", new PdmlGenInfoProtocol());
|
|
||||||
protocolMap_.insert("frame", new PdmlFrameProtocol());
|
|
||||||
#if 0
|
|
||||||
protocolMap_.insert("fake-field-wrapper",
|
|
||||||
new PdmlFakeFieldWrapperProtocol());
|
|
||||||
#endif
|
|
||||||
#if 0
|
|
||||||
protocolMap_.insert("eth", new PdmlEthProtocol());
|
|
||||||
protocolMap_.insert("ip", new PdmlIp4Protocol());
|
|
||||||
protocolMap_.insert("ipv6", new PdmlIp6Protocol());
|
|
||||||
protocolMap_.insert("tcp", new PdmlTcpProtocol());
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
PdmlParser::~PdmlParser()
|
|
||||||
{
|
|
||||||
// TODO: free protocolMap_.values()
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PdmlParser::startElement(const QString & /* namespaceURI */,
|
|
||||||
const QString & /* localName */,
|
|
||||||
const QString &qName,
|
|
||||||
const QXmlAttributes &attributes)
|
|
||||||
{
|
|
||||||
qDebug("%s (%s)", __FUNCTION__, qName.toAscii().constData());
|
|
||||||
|
|
||||||
if (skipCount_)
|
|
||||||
{
|
|
||||||
skipCount_++;
|
|
||||||
goto _exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (qName == "pdml")
|
|
||||||
{
|
|
||||||
packetCount_ = 0;
|
|
||||||
}
|
|
||||||
else if (qName == "packet")
|
|
||||||
{
|
|
||||||
// XXX: For now, each packet is converted to a stream
|
|
||||||
currentStream_ = streams_->add_stream();
|
|
||||||
currentStream_->mutable_stream_id()->set_id(packetCount_);
|
|
||||||
currentStream_->mutable_core()->set_is_enabled(true);
|
|
||||||
|
|
||||||
qDebug("packetCount_ = %d\n", packetCount_);
|
|
||||||
}
|
|
||||||
else if (qName == "proto")
|
|
||||||
{
|
|
||||||
QString protoName = attributes.value("name");
|
|
||||||
if (protoName.isEmpty()
|
|
||||||
|| (protoName == "expert"))
|
|
||||||
{
|
|
||||||
skipCount_++;
|
|
||||||
goto _exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
// HACK HACK HACK
|
|
||||||
if (currentPdmlProtocol_ && (currentPdmlProtocol_->ostProtoId()
|
|
||||||
== OstProto::Protocol::kHexDumpFieldNumber))
|
|
||||||
currentPdmlProtocol_->postProtocolHandler(currentStream_);
|
|
||||||
|
|
||||||
|
|
||||||
if (!protocolMap_.contains(protoName))
|
|
||||||
protoName = "unknown"; // FIXME: change to Ost:Hexdump
|
|
||||||
|
|
||||||
currentPdmlProtocol_ = protocolMap_.value(protoName);
|
|
||||||
|
|
||||||
Q_ASSERT(currentPdmlProtocol_ != NULL);
|
|
||||||
|
|
||||||
int protoId = currentPdmlProtocol_->ostProtoId();
|
|
||||||
|
|
||||||
// PdmlDefaultProtocol =>
|
|
||||||
if (protoId <= 0)
|
|
||||||
goto _exit;
|
|
||||||
|
|
||||||
OstProto::Protocol *proto = currentStream_->add_protocol();
|
|
||||||
|
|
||||||
proto->mutable_protocol_id()->set_id(protoId);
|
|
||||||
|
|
||||||
const google::protobuf::Reflection *msgRefl =
|
|
||||||
proto->GetReflection();
|
|
||||||
const google::protobuf::FieldDescriptor *fDesc =
|
|
||||||
msgRefl->FindKnownExtensionByNumber(protoId);
|
|
||||||
|
|
||||||
// TODO: if !fDesc
|
|
||||||
// init default values of all fields in protocol
|
|
||||||
currentProtocolMsg_ = msgRefl->MutableMessage(proto, fDesc);
|
|
||||||
|
|
||||||
currentPdmlProtocol_->preProtocolHandler(protoName, attributes,
|
|
||||||
currentStream_);
|
|
||||||
|
|
||||||
}
|
|
||||||
else if (qName == "field")
|
|
||||||
{
|
|
||||||
// fields with "hide='yes'" are informational and should be skipped
|
|
||||||
if (attributes.value("hide") == "yes")
|
|
||||||
{
|
|
||||||
skipCount_++;
|
|
||||||
goto _exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString name = attributes.value("name");
|
|
||||||
QString valueStr = attributes.value("value");
|
|
||||||
int pos = -1;
|
|
||||||
int size = -1;
|
|
||||||
|
|
||||||
if (!attributes.value("pos").isEmpty())
|
|
||||||
pos = attributes.value("pos").toInt();
|
|
||||||
if (!attributes.value("size").isEmpty())
|
|
||||||
size = attributes.value("size").toInt();
|
|
||||||
|
|
||||||
qDebug("\tname:%s, pos:%d, size:%d value:%s",
|
|
||||||
name.toAscii().constData(),
|
|
||||||
pos,
|
|
||||||
size,
|
|
||||||
valueStr.toAscii().constData());
|
|
||||||
|
|
||||||
if (!currentPdmlProtocol_->hasField(name))
|
|
||||||
{
|
|
||||||
currentPdmlProtocol_->unknownFieldHandler(name, pos, size,
|
|
||||||
attributes, currentStream_);
|
|
||||||
goto _exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO
|
|
||||||
int fId = currentPdmlProtocol_->fieldId(name);
|
|
||||||
const google::protobuf::Descriptor *msgDesc =
|
|
||||||
currentProtocolMsg_->GetDescriptor();
|
|
||||||
const google::protobuf::FieldDescriptor *fDesc =
|
|
||||||
msgDesc->FindFieldByNumber(fId);
|
|
||||||
const google::protobuf::Reflection *msgRefl =
|
|
||||||
currentProtocolMsg_->GetReflection();
|
|
||||||
|
|
||||||
bool isOk;
|
|
||||||
|
|
||||||
switch(fDesc->cpp_type())
|
|
||||||
{
|
|
||||||
case google::protobuf::FieldDescriptor::CPPTYPE_ENUM: // TODO
|
|
||||||
case google::protobuf::FieldDescriptor::CPPTYPE_UINT32:
|
|
||||||
msgRefl->SetUInt32(currentProtocolMsg_, fDesc,
|
|
||||||
valueStr.toUInt(&isOk, kBaseHex));
|
|
||||||
break;
|
|
||||||
case google::protobuf::FieldDescriptor::CPPTYPE_UINT64:
|
|
||||||
msgRefl->SetUInt64(currentProtocolMsg_, fDesc,
|
|
||||||
valueStr.toULongLong(&isOk, kBaseHex));
|
|
||||||
break;
|
|
||||||
case google::protobuf::FieldDescriptor::CPPTYPE_STRING:
|
|
||||||
{
|
|
||||||
QByteArray hexVal = QByteArray::fromHex(valueStr.toUtf8());
|
|
||||||
std::string str(hexVal.constData(), hexVal.size());
|
|
||||||
msgRefl->SetString(currentProtocolMsg_, fDesc, str);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
qDebug("%s: unhandled cpptype = %d", __FUNCTION__,
|
|
||||||
fDesc->cpp_type());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_exit:
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PdmlParser::characters(const QString &str)
|
|
||||||
{
|
|
||||||
//qDebug("%s (%s)", __FUNCTION__, str.toAscii().constData());
|
|
||||||
//_currentText += str;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PdmlParser::endElement(const QString & /* namespaceURI */,
|
|
||||||
const QString & /* localName */,
|
|
||||||
const QString &qName)
|
|
||||||
{
|
|
||||||
qDebug("%s (%s)", __FUNCTION__, qName.toAscii().constData());
|
|
||||||
|
|
||||||
if (qName == "packet")
|
|
||||||
{
|
|
||||||
if (currentStream_->core().name().size())
|
|
||||||
{
|
|
||||||
OstProto::Protocol *proto = currentStream_->add_protocol();
|
|
||||||
|
|
||||||
proto->mutable_protocol_id()->set_id(
|
|
||||||
OstProto::Protocol::kHexDumpFieldNumber);
|
|
||||||
|
|
||||||
OstProto::HexDump *hexDump = proto->MutableExtension(OstProto::hexDump);
|
|
||||||
|
|
||||||
hexDump->set_content(currentStream_->core().name());
|
|
||||||
hexDump->set_pad_until_end(false);
|
|
||||||
currentStream_->mutable_core()->set_name("");
|
|
||||||
}
|
|
||||||
packetCount_++;
|
|
||||||
currentPdmlProtocol_ = NULL;
|
|
||||||
goto _exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (skipCount_)
|
|
||||||
{
|
|
||||||
skipCount_--;
|
|
||||||
goto _exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (qName == "proto")
|
|
||||||
{
|
|
||||||
currentPdmlProtocol_->postProtocolHandler(currentStream_);
|
|
||||||
//currentPdmlProtocol_ = NULL;
|
|
||||||
}
|
|
||||||
else if (qName == "field")
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
_exit:
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PdmlParser::fatalError(const QXmlParseException &exception)
|
|
||||||
{
|
|
||||||
QString extra;
|
|
||||||
|
|
||||||
qDebug("%s", __FUNCTION__);
|
|
||||||
#if 0
|
|
||||||
if (exception.message() == "tag mismatch" && lastElement == "fieldData")
|
|
||||||
extra = "\nAre you using an old version of Wireshark? If so, try using a newer version. Alternatively, view the packet dump decode in Wireshark by clicking the \"External\" button.";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
QMessageBox::warning(0, QObject::tr("PDML Parser"),
|
|
||||||
QObject::tr("XML parse error for packet %1 "
|
|
||||||
"at line %2, column %3:\n %4\n%5")
|
|
||||||
.arg(packetCount_+1)
|
|
||||||
.arg(exception.lineNumber())
|
|
||||||
.arg(exception.columnNumber())
|
|
||||||
.arg(exception.message())
|
|
||||||
.arg(extra));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// ---------------------------------------------------------- //
|
// ---------------------------------------------------------- //
|
||||||
// PdmlReader //
|
// PdmlReader //
|
||||||
// ---------------------------------------------------------- //
|
// ---------------------------------------------------------- //
|
||||||
|
@ -60,37 +60,6 @@ protected:
|
|||||||
QMap<QString, int> fieldMap_;
|
QMap<QString, int> fieldMap_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#if 0
|
|
||||||
class PdmlParser : public QXmlDefaultHandler
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
PdmlParser(OstProto::StreamConfigList *streams);
|
|
||||||
~PdmlParser();
|
|
||||||
|
|
||||||
bool startElement(const QString &namespaceURI,
|
|
||||||
const QString &localName,
|
|
||||||
const QString &qName,
|
|
||||||
const QXmlAttributes &attributes);
|
|
||||||
bool endElement(const QString &namespaceURI,
|
|
||||||
const QString &localName,
|
|
||||||
const QString &qName);
|
|
||||||
bool characters(const QString &str);
|
|
||||||
bool fatalError(const QXmlParseException &exception);
|
|
||||||
|
|
||||||
private:
|
|
||||||
void initProtocolMaps();
|
|
||||||
|
|
||||||
QMap<QString, PdmlDefaultProtocol*> protocolMap_;
|
|
||||||
PdmlDefaultProtocol *currentPdmlProtocol_;
|
|
||||||
int skipCount_;
|
|
||||||
int packetCount_;
|
|
||||||
OstProto::StreamConfigList *streams_;
|
|
||||||
|
|
||||||
OstProto::Stream *currentStream_;
|
|
||||||
google::protobuf::Message *currentProtocolMsg_;
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class PdmlUnknownProtocol;
|
class PdmlUnknownProtocol;
|
||||||
class PcapFileFormat;
|
class PcapFileFormat;
|
||||||
class PdmlReader : public QXmlStreamReader
|
class PdmlReader : public QXmlStreamReader
|
||||||
|
Loading…
Reference in New Issue
Block a user