1 | #ifndef PROTOCOL_INFO_H |
---|
2 | #define PROTOCOL_INFO_H |
---|
3 | |
---|
4 | #include <list> |
---|
5 | #include <vector> |
---|
6 | |
---|
7 | #ifdef DISPATCH_DEBUG |
---|
8 | // TODO: For debugging only !!! |
---|
9 | namespace t3devlib |
---|
10 | { |
---|
11 | typedef int ComponentId; |
---|
12 | } |
---|
13 | #else |
---|
14 | #include <t3devlib/t3devlib.h> |
---|
15 | #endif |
---|
16 | |
---|
17 | enum EProtocolType |
---|
18 | { |
---|
19 | EProtocolType_None, |
---|
20 | EProtocolType_Unknown, |
---|
21 | EProtocolType_Ethernet, |
---|
22 | EProtocolType_IPv4, |
---|
23 | EProtocolType_Udp, |
---|
24 | EProtocolType_Tcp, |
---|
25 | EProtocolType_Sip, |
---|
26 | EProtocolType_Dns |
---|
27 | }; |
---|
28 | |
---|
29 | class ProtocolInfoElement |
---|
30 | { |
---|
31 | protected: |
---|
32 | ProtocolInfoElement(); |
---|
33 | public: |
---|
34 | virtual ~ProtocolInfoElement(); |
---|
35 | virtual EProtocolType GetId() const = 0; |
---|
36 | virtual bool Match(const ProtocolInfoElement & toCompare) const; |
---|
37 | virtual ProtocolInfoElement * Clone() const = 0; |
---|
38 | }; |
---|
39 | |
---|
40 | class ProtocolInfo : private std::vector<ProtocolInfoElement *> |
---|
41 | { |
---|
42 | public: |
---|
43 | ProtocolInfo(); |
---|
44 | ~ProtocolInfo(); |
---|
45 | void AddItem(ProtocolInfoElement * info); |
---|
46 | size_t Count(); |
---|
47 | const ProtocolInfoElement * operator[] ( int nIndex ) const; |
---|
48 | bool Match(ProtocolInfo & info) const; |
---|
49 | }; |
---|
50 | |
---|
51 | class IPv4Info : public ProtocolInfoElement |
---|
52 | { |
---|
53 | private: |
---|
54 | unsigned int m_nSrcAddr, m_nDstAddr; |
---|
55 | public: |
---|
56 | IPv4Info(); |
---|
57 | IPv4Info(const IPv4Info & src); |
---|
58 | virtual ~IPv4Info(); |
---|
59 | virtual EProtocolType GetId() const { return EProtocolType_IPv4; } |
---|
60 | virtual bool Match(const ProtocolInfoElement & toCompare) const; |
---|
61 | unsigned int GetSourceAddress() const { return m_nSrcAddr; } |
---|
62 | unsigned int GetDestinationAddress() const { return m_nDstAddr; } |
---|
63 | void SetSourceAddress(unsigned int nAddr) { m_nSrcAddr = nAddr; } |
---|
64 | void SetDestinationAddress(unsigned int nAddr) { m_nDstAddr = nAddr; } |
---|
65 | virtual ProtocolInfoElement * Clone() const; |
---|
66 | }; |
---|
67 | |
---|
68 | class TransportLayerInfo : public ProtocolInfoElement |
---|
69 | { |
---|
70 | private: |
---|
71 | unsigned short m_nSrcPort, m_nDstPort; |
---|
72 | protected: |
---|
73 | TransportLayerInfo(); |
---|
74 | TransportLayerInfo(const TransportLayerInfo & src); |
---|
75 | public: |
---|
76 | virtual ~TransportLayerInfo(); |
---|
77 | virtual bool Match(const ProtocolInfoElement & toCompare) const; |
---|
78 | unsigned short GetSourcePort() const { return m_nSrcPort; } |
---|
79 | unsigned short GetDestinationPort() const { return m_nDstPort; } |
---|
80 | void SetSourcePort(unsigned short nPort) { m_nSrcPort = nPort; } |
---|
81 | void SetDestinationPort(unsigned short nPort) { m_nDstPort = nPort; } |
---|
82 | }; |
---|
83 | |
---|
84 | class TcpInfo : public TransportLayerInfo |
---|
85 | { |
---|
86 | public: |
---|
87 | TcpInfo(); |
---|
88 | TcpInfo(const TcpInfo & src); |
---|
89 | virtual ~TcpInfo(); |
---|
90 | virtual EProtocolType GetId() const { return EProtocolType_Tcp; } |
---|
91 | virtual ProtocolInfoElement * Clone() const; |
---|
92 | }; |
---|
93 | |
---|
94 | class UdpInfo : public TransportLayerInfo |
---|
95 | { |
---|
96 | public: |
---|
97 | UdpInfo(); |
---|
98 | UdpInfo(const UdpInfo & src); |
---|
99 | virtual ~UdpInfo(); |
---|
100 | virtual EProtocolType GetId() const { return EProtocolType_Udp; } |
---|
101 | virtual ProtocolInfoElement * Clone() const; |
---|
102 | }; |
---|
103 | |
---|
104 | #endif |
---|