KDIS  2-8-x
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ConnectionAddressFilter.h
Go to the documentation of this file.
1 /*********************************************************************
2 Copyright 2013 Karl Jones
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7 
8 1. Redistributions of source code must retain the above copyright notice, this
9  list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright notice,
11  this list of conditions and the following disclaimer in the documentation
12  and/or other materials provided with the distribution.
13 
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
18 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 
25 For Further Information Please Contact me at
26 Karljj1@yahoo.com
27 http://p.sf.net/kdis/UserGuide
28 *********************************************************************/
29 
30 /********************************************************************
31  class: ConnectionAddressFilter
32  created: 04/02/2011
33  author: Karl Jones
34 
35  purpose: A simple filter for allowing data through based on its IP address.
36 *********************************************************************/
37 
38 #pragma once
39 
40 #include "./ConnectionSubscriber.h"
41 #include <set>
42 
43 namespace KDIS {
44 namespace NETWORK {
45 
47 {
48 public:
49 
51  {
53  BlockAddressesInFilterList
54  };
55 
56 protected:
57 
59 
60  std::set<KString> m_Filter;
61 
62 public:
63 
64  ConnectionAddressFilter( FilterMode FM = AllowAddressesInFilterList );
65 
67 
68  //************************************
69  // FullName: KDIS::NETWORK::ConnectionAddressFilter::SetFilterMode
70  // KDIS::NETWORK::ConnectionAddressFilter::GetFilterMode
71  //!Description: How is the filter operating? Should it block all
72  //! addresses in its list or only allow those?
73  // Parameter: const KString & A
74  //************************************
75  void SetFilterMode( FilterMode FM );
76  FilterMode GetFilterMode() const;
77 
78  //************************************
79  // FullName: KDIS::NETWORK::ConnectionAddressFilter::AddAddress
80  //!Description: Add an address to the filter list, this address will either
81  //! be blocked or allowed depending on the FilterMode.
82  // Parameter: const KString & A
83  //************************************
84  void AddAddress( const KString & A );
85 
86  //************************************
87  // FullName: KDIS::NETWORK::ConnectionAddressFilter::RemoveAddress
88  //!Description: Remove an address from the filter list.
89  // If the address is not in the list then nothing happens.
90  // Parameter: const KString & A
91  //************************************
92  void RemoveAddress( const KString & A );
93 
94  //************************************
95  // FullName: KDIS::NETWORK::ConnectionAddressFilter::TestAddress
96  //!Description: Test an address to see if it will be allowed through the filter.
97  // Returns true if address is allowed else false.
98  // Parameter: const KString & A
99  //************************************
100  KBOOL TestAddress( const KString & A );
101 
102  //************************************
103  // FullName: KDIS::NETWORK::ConnectionAddressFilter::OnDataReceived
104  //!Description: This is where the filtering is done, we check if the IP address is in
105  //! the block/allow list and return true/false to allow/stop the PDU.
106  // Parameter: const KOCTET * Data
107  // Parameter: KUINT32 DataLength
108  // Parameter: const KString & SenderIp
109  //************************************
110  virtual KBOOL OnDataReceived( const KOCTET * Data, KUINT32 DataLength, const KString & SenderIp );
111 };
112 
113 } // END namespace NETWORK
114 } // END namespace KDIS
unsigned int KUINT32
Definition: KDefines.h:103
FilterMode
Definition: ConnectionAddressFilter.h:50
Definition: ConnectionSubscriber.h:53
Definition: ConnectionAddressFilter.h:46
std::set< KString > m_Filter
Definition: ConnectionAddressFilter.h:60
FilterMode m_FM
Definition: ConnectionAddressFilter.h:58
bool KBOOL
Definition: KDefines.h:119
std::string KString
Definition: KDefines.h:116
char KOCTET
Definition: KDefines.h:108
#define KDIS_EXPORT
Definition: KDefines.h:82