From 5db314722dfd74518b9a6916726382d25c63a3bb Mon Sep 17 00:00:00 2001 From: "Srivats P." Date: Sun, 10 Apr 2011 21:03:47 +0530 Subject: [PATCH] PCAP/PDML import: class PdmlProtocol - removed protoName member; made constructor protected --- common/pdml_p.cpp | 34 ------------------- common/pdml_p.h | 72 ++++++++++++++++++++++------------------- common/pdmlprotocol.cpp | 5 --- common/pdmlprotocol.h | 7 ++-- 4 files changed, 41 insertions(+), 77 deletions(-) diff --git a/common/pdml_p.cpp b/common/pdml_p.cpp index 322d714..a36a056 100644 --- a/common/pdml_p.cpp +++ b/common/pdml_p.cpp @@ -19,8 +19,6 @@ along with this program. If not, see #include "pdml_p.h" -#include "protocolmanager.h" - #include "arp.pb.h" #include "eth2.pb.h" #include "dot3.pb.h" @@ -41,24 +39,17 @@ along with this program. If not, see #include "udp.pb.h" #include "vlan.pb.h" -//#include #include - #include -extern ProtocolManager *OstProtocolManager; - const int kBaseHex = 16; -//static PdmlReader *gPdmlReader = NULL; - // ---------------------------------------------------------- // // PdmlUnknownProtocol // // ---------------------------------------------------------- // PdmlUnknownProtocol::PdmlUnknownProtocol() { - pdmlProtoName_ = ""; ostProtoId_ = OstProto::Protocol::kHexDumpFieldNumber; endPos_ = expPos_ = -1; @@ -168,7 +159,6 @@ void PdmlUnknownProtocol::unknownFieldHandler(QString name, int pos, PdmlGenInfoProtocol::PdmlGenInfoProtocol() { - pdmlProtoName_ = "geninfo"; } PdmlProtocol* PdmlGenInfoProtocol::createInstance() @@ -176,22 +166,12 @@ PdmlProtocol* PdmlGenInfoProtocol::createInstance() return new PdmlGenInfoProtocol(); } -#if 0 // done in frame proto -void PdmlGenInfoProtocol::unknownFieldHandler(QString name, int pos, - int size, const QXmlStreamAttributes &attributes, OstProto::Stream *stream) -{ - if (name == "len") - stream->mutable_core()->set_frame_len(size+4); // TODO:check FCS -} -#endif - // ---------------------------------------------------------- // // PdmlFrameProtocol // // ---------------------------------------------------------- // PdmlFrameProtocol::PdmlFrameProtocol() { - pdmlProtoName_ = "frame"; } PdmlProtocol* PdmlFrameProtocol::createInstance() @@ -244,7 +224,6 @@ void PdmlFrameProtocol::unknownFieldHandler(QString name, int /*pos*/, PdmlSvlanProtocol::PdmlSvlanProtocol() { - pdmlProtoName_ = "ieee8021ad"; ostProtoId_ = OstProto::Protocol::kSvlanFieldNumber; } @@ -336,7 +315,6 @@ void PdmlSvlanProtocol::unknownFieldHandler(QString name, int /*pos*/, PdmlVlanProtocol::PdmlVlanProtocol() { - pdmlProtoName_ = "vlan"; ostProtoId_ = OstProto::Protocol::kVlanFieldNumber; } @@ -409,7 +387,6 @@ void PdmlVlanProtocol::unknownFieldHandler(QString name, int /*pos*/, PdmlEthProtocol::PdmlEthProtocol() { - pdmlProtoName_ = "eth"; ostProtoId_ = OstProto::Protocol::kMacFieldNumber; fieldMap_.insert("eth.dst", OstProto::Mac::kDstMacFieldNumber); @@ -511,7 +488,6 @@ void PdmlEthProtocol::unknownFieldHandler(QString name, int /*pos*/, PdmlLlcProtocol::PdmlLlcProtocol() { - pdmlProtoName_ = "llc"; ostProtoId_ = OstProto::Protocol::kLlcFieldNumber; fieldMap_.insert("llc.dsap", OstProto::Llc::kDsapFieldNumber); @@ -571,7 +547,6 @@ void PdmlLlcProtocol::postProtocolHandler(OstProto::Protocol *pbProto, PdmlArpProtocol::PdmlArpProtocol() { - pdmlProtoName_ = "arp"; ostProtoId_ = OstProto::Protocol::kArpFieldNumber; fieldMap_.insert("arp.opcode", OstProto::Arp::kOpCodeFieldNumber); @@ -595,7 +570,6 @@ PdmlProtocol* PdmlArpProtocol::createInstance() PdmlIp4Protocol::PdmlIp4Protocol() { - pdmlProtoName_ = "ip"; ostProtoId_ = OstProto::Protocol::kIp4FieldNumber; fieldMap_.insert("ip.version", OstProto::Ip4::kVerHdrlenFieldNumber); @@ -669,7 +643,6 @@ void PdmlIp4Protocol::postProtocolHandler(OstProto::Protocol *pbProto, PdmlIp6Protocol::PdmlIp6Protocol() { - pdmlProtoName_ = "ipv6"; ostProtoId_ = OstProto::Protocol::kIp6FieldNumber; fieldMap_.insert("ipv6.version", OstProto::Ip6::kVersionFieldNumber); @@ -728,7 +701,6 @@ void PdmlIp6Protocol::postProtocolHandler(OstProto::Protocol *pbProto, PdmlIcmpProtocol::PdmlIcmpProtocol() { - pdmlProtoName_ = "icmp"; ostProtoId_ = OstProto::Protocol::kIcmpFieldNumber; fieldMap_.insert("icmp.type", OstProto::Icmp::kTypeFieldNumber); @@ -803,7 +775,6 @@ void PdmlIcmpProtocol::postProtocolHandler(OstProto::Protocol *pbProto, PdmlIcmp6Protocol::PdmlIcmp6Protocol() { - pdmlProtoName_ = "icmpv6"; ostProtoId_ = OstProto::Protocol::kSampleFieldNumber; proto_ = NULL; @@ -885,7 +856,6 @@ void PdmlIcmp6Protocol::unknownFieldHandler(QString name, PdmlIgmpProtocol::PdmlIgmpProtocol() { - pdmlProtoName_ = "igmp"; ostProtoId_ = OstProto::Protocol::kIgmpFieldNumber; fieldMap_.insert("igmp.max_resp", @@ -1009,7 +979,6 @@ void PdmlIgmpProtocol::postProtocolHandler(OstProto::Protocol* /*pbProto*/, PdmlMldProtocol::PdmlMldProtocol() { - pdmlProtoName_ = "mld"; ostProtoId_ = OstProto::Protocol::kMldFieldNumber; fieldMap_.insert("icmpv6.code", OstProto::Gmp::kRsvdCodeFieldNumber); @@ -1125,7 +1094,6 @@ void PdmlMldProtocol::unknownFieldHandler(QString name, int /*pos*/, PdmlTcpProtocol::PdmlTcpProtocol() { - pdmlProtoName_ = "tcp"; ostProtoId_ = OstProto::Protocol::kTcpFieldNumber; fieldMap_.insert("tcp.srcport", OstProto::Tcp::kSrcPortFieldNumber); @@ -1219,7 +1187,6 @@ void PdmlTcpProtocol::postProtocolHandler(OstProto::Protocol *pbProto, PdmlUdpProtocol::PdmlUdpProtocol() { - pdmlProtoName_ = "udp"; // OR udplite ostProtoId_ = OstProto::Protocol::kUdpFieldNumber; fieldMap_.insert("udp.srcport", OstProto::Udp::kSrcPortFieldNumber); @@ -1255,7 +1222,6 @@ void PdmlUdpProtocol::postProtocolHandler(OstProto::Protocol *pbProto, PdmlTextProtocol::PdmlTextProtocol() { - pdmlProtoName_ = "text"; ostProtoId_ = OstProto::Protocol::kTextProtocolFieldNumber; } diff --git a/common/pdml_p.h b/common/pdml_p.h index cfcd025..1824d9d 100644 --- a/common/pdml_p.h +++ b/common/pdml_p.h @@ -25,8 +25,6 @@ along with this program. If not, see class PdmlUnknownProtocol : public PdmlProtocol { public: - PdmlUnknownProtocol(); - static PdmlProtocol* createInstance(); virtual void preProtocolHandler(QString name, @@ -39,6 +37,9 @@ public: virtual void unknownFieldHandler(QString name, int pos, int size, const QXmlStreamAttributes &attributes, OstProto::Protocol *pbProto, OstProto::Stream *stream); +protected: + PdmlUnknownProtocol(); + private: int endPos_; int expPos_; @@ -47,40 +48,42 @@ private: class PdmlGenInfoProtocol : public PdmlProtocol { public: + static PdmlProtocol* createInstance(); + +protected: PdmlGenInfoProtocol(); - static PdmlProtocol* createInstance(); }; class PdmlFrameProtocol : public PdmlProtocol { public: - PdmlFrameProtocol(); - static PdmlProtocol* createInstance(); virtual void unknownFieldHandler(QString name, int pos, int size, const QXmlStreamAttributes &attributes, OstProto::Protocol *pbProto, OstProto::Stream *stream); + +protected: + PdmlFrameProtocol(); }; class PdmlEthProtocol : public PdmlProtocol { public: - PdmlEthProtocol(); - static PdmlProtocol* createInstance(); virtual void unknownFieldHandler(QString name, int pos, int size, const QXmlStreamAttributes &attributes, OstProto::Protocol *pbProto, OstProto::Stream *stream); + +protected: + PdmlEthProtocol(); }; class PdmlSvlanProtocol : public PdmlProtocol { public: - PdmlSvlanProtocol(); - static PdmlProtocol* createInstance(); virtual void preProtocolHandler(QString name, @@ -89,13 +92,13 @@ public: virtual void unknownFieldHandler(QString name, int pos, int size, const QXmlStreamAttributes &attributes, OstProto::Protocol *pbProto, OstProto::Stream *stream); +protected: + PdmlSvlanProtocol(); }; class PdmlVlanProtocol : public PdmlProtocol { public: - PdmlVlanProtocol(); - static PdmlProtocol* createInstance(); virtual void preProtocolHandler(QString name, @@ -104,13 +107,13 @@ public: virtual void unknownFieldHandler(QString name, int pos, int size, const QXmlStreamAttributes &attributes, OstProto::Protocol *pbProto, OstProto::Stream *stream); +protected: + PdmlVlanProtocol(); }; class PdmlLlcProtocol : public PdmlProtocol { public: - PdmlLlcProtocol(); - static PdmlProtocol* createInstance(); virtual void unknownFieldHandler(QString name, int pos, int size, @@ -118,21 +121,22 @@ public: OstProto::Protocol *pbProto, OstProto::Stream *stream); virtual void postProtocolHandler(OstProto::Protocol *pbProto, OstProto::Stream *stream); +protected: + PdmlLlcProtocol(); }; class PdmlArpProtocol : public PdmlProtocol { public: - PdmlArpProtocol(); - static PdmlProtocol* createInstance(); + +protected: + PdmlArpProtocol(); }; class PdmlIp4Protocol : public PdmlProtocol { public: - PdmlIp4Protocol(); - static PdmlProtocol* createInstance(); virtual void unknownFieldHandler(QString name, int pos, int size, @@ -140,6 +144,8 @@ public: OstProto::Protocol *pbProto, OstProto::Stream *stream); virtual void postProtocolHandler(OstProto::Protocol *pbProto, OstProto::Stream *stream); +protected: + PdmlIp4Protocol(); private: QByteArray options_; }; @@ -147,8 +153,6 @@ private: class PdmlIp6Protocol : public PdmlProtocol { public: - PdmlIp6Protocol(); - static PdmlProtocol* createInstance(); virtual void unknownFieldHandler(QString name, int pos, int size, @@ -156,14 +160,14 @@ public: OstProto::Protocol *pbProto, OstProto::Stream *stream); virtual void postProtocolHandler(OstProto::Protocol *pbProto, OstProto::Stream *stream); +protected: + PdmlIp6Protocol(); }; class PdmlIcmpProtocol : public PdmlProtocol { friend class PdmlIcmp6Protocol; public: - PdmlIcmpProtocol(); - static PdmlProtocol* createInstance(); virtual void preProtocolHandler(QString name, @@ -174,6 +178,8 @@ public: OstProto::Protocol *pbProto, OstProto::Stream *stream); virtual void postProtocolHandler(OstProto::Protocol *pbProto, OstProto::Stream *stream); +protected: + PdmlIcmpProtocol(); private: static const uint kIcmpInvalidType = 0xFFFFFFFF; @@ -185,8 +191,6 @@ class PdmlMldProtocol : public PdmlProtocol { friend class PdmlIcmp6Protocol; public: - PdmlMldProtocol(); - static PdmlProtocol* createInstance(); virtual void preProtocolHandler(QString name, @@ -195,6 +199,8 @@ public: virtual void unknownFieldHandler(QString name, int pos, int size, const QXmlStreamAttributes &attributes, OstProto::Protocol *pbProto, OstProto::Stream *stream); +protected: + PdmlMldProtocol(); private: static const uint kMldQuery = 0x82; static const uint kMldV1Query = 0x82; @@ -206,8 +212,6 @@ private: class PdmlIcmp6Protocol : public PdmlProtocol { public: - PdmlIcmp6Protocol(); - static PdmlProtocol* createInstance(); virtual void preProtocolHandler(QString name, @@ -219,6 +223,8 @@ public: virtual void unknownFieldHandler(QString name, int pos, int size, const QXmlStreamAttributes &attributes, OstProto::Protocol *pbProto, OstProto::Stream *stream); +protected: + PdmlIcmp6Protocol(); private: PdmlIcmpProtocol icmp_; PdmlMldProtocol mld_; @@ -228,8 +234,6 @@ private: class PdmlIgmpProtocol : public PdmlProtocol { public: - PdmlIgmpProtocol(); - static PdmlProtocol* createInstance(); virtual void preProtocolHandler(QString name, @@ -240,6 +244,8 @@ public: OstProto::Protocol *pbProto, OstProto::Stream *stream); virtual void postProtocolHandler(OstProto::Protocol *pbProto, OstProto::Stream *stream); +protected: + PdmlIgmpProtocol(); private: static const uint kIgmpQuery = 0x11; static const uint kIgmpV1Query = 0x11; @@ -252,8 +258,6 @@ private: class PdmlTcpProtocol : public PdmlProtocol { public: - PdmlTcpProtocol(); - static PdmlProtocol* createInstance(); virtual void unknownFieldHandler(QString name, int pos, int size, @@ -261,6 +265,8 @@ public: OstProto::Protocol *pbProto, OstProto::Stream *stream); virtual void postProtocolHandler(OstProto::Protocol *pbProto, OstProto::Stream *stream); +protected: + PdmlTcpProtocol(); private: QByteArray options_; QByteArray segmentData_; @@ -269,18 +275,16 @@ private: class PdmlUdpProtocol : public PdmlProtocol { public: - PdmlUdpProtocol(); - static PdmlProtocol* createInstance(); virtual void postProtocolHandler(OstProto::Protocol *pbProto, OstProto::Stream *stream); +protected: + PdmlUdpProtocol(); }; class PdmlTextProtocol : public PdmlProtocol { public: - PdmlTextProtocol(); - static PdmlProtocol* createInstance(); virtual void preProtocolHandler(QString name, @@ -291,6 +295,8 @@ public: OstProto::Protocol *pbProto, OstProto::Stream *stream); virtual void postProtocolHandler(OstProto::Protocol *pbProto, OstProto::Stream *stream); +protected: + PdmlTextProtocol(); private: enum ContentType { kUnknownContent, diff --git a/common/pdmlprotocol.cpp b/common/pdmlprotocol.cpp index 5706798..cb39a4f 100644 --- a/common/pdmlprotocol.cpp +++ b/common/pdmlprotocol.cpp @@ -35,11 +35,6 @@ PdmlProtocol* PdmlProtocol::createInstance() return new PdmlProtocol(); } -QString PdmlProtocol::pdmlProtoName() const -{ - return pdmlProtoName_; -} - int PdmlProtocol::ostProtoId() const { return ostProtoId_; diff --git a/common/pdmlprotocol.h b/common/pdmlprotocol.h index 0e99b9f..412f588 100644 --- a/common/pdmlprotocol.h +++ b/common/pdmlprotocol.h @@ -27,17 +27,13 @@ along with this program. If not, see #include #include -// TODO: add const where possible - class PdmlProtocol { public: - PdmlProtocol(); // TODO: make private virtual ~PdmlProtocol(); static PdmlProtocol* createInstance(); - QString pdmlProtoName() const; int ostProtoId() const; bool hasField(QString name) const; int fieldId(QString name) const; @@ -59,7 +55,8 @@ public: OstProto::Protocol *pbProto, OstProto::Stream *stream); protected: - QString pdmlProtoName_; // TODO: needed? duplicated in protocolMap_ + PdmlProtocol(); + int ostProtoId_; QMap fieldMap_; };