Finished implementing PDML Text Protocol - verified for HTTP

This commit is contained in:
Srivats P. 2011-04-02 00:14:43 +05:30
parent e47319feda
commit ead67d80aa
3 changed files with 149 additions and 4 deletions

View File

@ -724,7 +724,7 @@ void Ip4Protocol::storeConfigWidget()
data.set_proto(configForm->leIpProto->text().remove(QChar(' ')).toULong(&isOk, 16));
data.set_is_override_cksum(configForm->cbIpCksumOverride->isChecked());
data.set_cksum(configForm->leIpCksum->text().remove(QChar(' ')).toULong(&isOk));
data.set_cksum(configForm->leIpCksum->text().remove(QChar(' ')).toULong(&isOk, 16));
data.set_src_ip(QHostAddress(configForm->leIpSrcAddr->text()).toIPv4Address());
data.set_src_ip_mode((OstProto::Ip4_IpAddrMode)configForm->cmbIpSrcAddrMode->currentIndex());

View File

@ -35,6 +35,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "snap.pb.h"
#include "svlan.pb.h"
#include "tcp.pb.h"
#include "textproto.pb.h"
#include "udp.pb.h"
#include "vlan.pb.h"
@ -203,12 +204,16 @@ PdmlReader::PdmlReader(OstProto::StreamConfigList *streams)
factory_.insert("geninfo", PdmlGenInfoProtocol::createInstance);
factory_.insert("frame", PdmlFrameProtocol::createInstance);
factory_.insert("eth", PdmlEthProtocol::createInstance);
factory_.insert("ip", PdmlIp4Protocol::createInstance);
factory_.insert("arp", PdmlArpProtocol::createInstance);
factory_.insert("eth", PdmlEthProtocol::createInstance);
factory_.insert("http", PdmlTextProtocol::createInstance);
factory_.insert("ieee8021ad", PdmlSvlanProtocol::createInstance);
factory_.insert("ip", PdmlIp4Protocol::createInstance);
factory_.insert("ipv6", PdmlIp6Protocol::createInstance);
factory_.insert("llc", PdmlLlcProtocol::createInstance);
factory_.insert("ieee8021ad", PdmlSvlanProtocol::createInstance);
//factory_.insert("nntp", PdmlTextProtocol::createInstance);
//factory_.insert("rtsp", PdmlTextProtocol::createInstance);
//factory_.insert("sip", PdmlTextProtocol::createInstance);
factory_.insert("tcp", PdmlTcpProtocol::createInstance);
factory_.insert("udp", PdmlUdpProtocol::createInstance);
factory_.insert("udplite", PdmlUdpProtocol::createInstance);
@ -1406,3 +1411,116 @@ void PdmlUdpProtocol::postProtocolHandler(OstProto::Protocol *pbProto,
udp->set_is_override_cksum(true);
}
// ---------------------------------------------------------- //
// PdmlTextProtocol //
// ---------------------------------------------------------- //
PdmlTextProtocol::PdmlTextProtocol()
{
pdmlProtoName_ = "text";
ostProtoId_ = OstProto::Protocol::kTextProtocolFieldNumber;
}
PdmlDefaultProtocol* PdmlTextProtocol::createInstance()
{
return new PdmlTextProtocol();
}
void PdmlTextProtocol::preProtocolHandler(QString name,
const QXmlStreamAttributes &attributes, int expectedPos,
OstProto::Protocol *pbProto, OstProto::Stream *stream)
{
bool isOk;
int size;
int pos = attributes.value("pos").toString().toUInt(&isOk);
if (!isOk)
{
if (expectedPos >= 0)
expPos_ = pos = expectedPos;
else
goto _skip_pos_size_proc;
}
size = attributes.value("size").toString().toUInt(&isOk);
if (!isOk)
goto _skip_pos_size_proc;
// If pos+size goes beyond the frame length, this is a "reassembled"
// protocol and should be skipped
if ((pos + size) > int(stream->core().frame_len()))
goto _skip_pos_size_proc;
expPos_ = pos;
endPos_ = expPos_ + size;
_skip_pos_size_proc:
OstProto::TextProtocol *text = pbProto->MutableExtension(
OstProto::textProtocol);
text->set_port_num(0);
text->set_eol(OstProto::TextProtocol::kCrLf);
contentType_ = kUnknownContent;
}
void PdmlTextProtocol::unknownFieldHandler(QString name, int pos, int size,
const QXmlStreamAttributes &attributes, OstProto::Protocol *pbProto,
OstProto::Stream *stream)
{
if (contentType_ == kUnknownContent)
{
if (name == "data")
contentType_ = kOtherContent;
else
contentType_ = kTextContent;
}
else if (contentType_ == kOtherContent)
return;
else // kTextContent
{
if (name == "data")
contentType_ = kOtherContent;
return;
}
// We process only kTextContent
if (pos != expPos_)
return;
if ((pos + size) > endPos_)
return;
if (attributes.value("show") == "HTTP chunked response")
return;
OstProto::TextProtocol *text = pbProto->MutableExtension(
OstProto::textProtocol);
QByteArray line = QByteArray::fromHex(
attributes.value("value").toString().toUtf8());
// Convert line endings to LF only - Qt requirement that TextProto honours
line.replace("\r\n", "\n");
line.replace("\r", "\n");
text->mutable_text()->append(line.constData(), line.size());
expPos_ += size;
}
void PdmlTextProtocol::postProtocolHandler(OstProto::Protocol *pbProto,
OstProto::Stream *stream)
{
OstProto::TextProtocol *text = pbProto->MutableExtension(
OstProto::textProtocol);
// Empty Text Content - remove ourselves
if (text->text().length() == 0)
stream->mutable_protocol()->RemoveLast();
expPos_ = endPos_ = -1;
contentType_ = kUnknownContent;
}

View File

@ -275,4 +275,31 @@ public:
OstProto::Stream *stream);
};
class PdmlTextProtocol : public PdmlDefaultProtocol
{
public:
PdmlTextProtocol();
static PdmlDefaultProtocol* createInstance();
virtual void preProtocolHandler(QString name,
const QXmlStreamAttributes &attributes, int expectedPos,
OstProto::Protocol *pbProto, OstProto::Stream *stream);
virtual void unknownFieldHandler(QString name, int pos, int size,
const QXmlStreamAttributes &attributes,
OstProto::Protocol *pbProto, OstProto::Stream *stream);
virtual void postProtocolHandler(OstProto::Protocol *pbProto,
OstProto::Stream *stream);
private:
enum ContentType {
kUnknownContent,
kTextContent,
kOtherContent
};
ContentType contentType_;
int expPos_;
int endPos_;
};
#endif