Remote Call Framework 3.1
Filter.hpp
1 
2 //******************************************************************************
3 // RCF - Remote Call Framework
4 //
5 // Copyright (c) 2005 - 2019, Delta V Software. All rights reserved.
6 // http://www.deltavsoft.com
7 //
8 // RCF is distributed under dual licenses - closed source or GPL.
9 // Consult your particular license for conditions of use.
10 //
11 // If you have not purchased a commercial license, you are using RCF
12 // under GPL terms.
13 //
14 // Version: 3.1
15 // Contact: support <at> deltavsoft.com
16 //
17 //******************************************************************************
18 
19 #ifndef INCLUDE_RCF_FILTER_HPP
20 #define INCLUDE_RCF_FILTER_HPP
21 
22 #include <string>
23 #include <vector>
24 #include <memory>
25 
26 #include <RCF/Export.hpp>
27 
28 namespace RCF {
29 
30  // collect these constants here so we can avoid collisions
31  static const int RcfFilter_Unknown = 0;
32  static const int RcfFilter_Identity = 1;
33  static const int RcfFilter_OpenSsl = 2;
34  static const int RcfFilter_ZlibCompressionStateless = 3;
35  static const int RcfFilter_ZlibCompressionStateful = 4;
36  static const int RcfFilter_SspiNtlm = 5;
37  static const int RcfFilter_SspiKerberos = 6;
38  static const int RcfFilter_SspiNegotiate = 7;
39  static const int RcfFilter_SspiSchannel = 8;
40 
41  static const int RcfFilter_Xor = 101;
42 
43  class Filter;
44 
45  class ByteBuffer;
46 
47  typedef std::shared_ptr<Filter> FilterPtr;
48 
49  class RCF_EXPORT Filter
50  {
51  public:
52 
53  Filter();
54  virtual ~Filter();
55  virtual void resetState();
56 
57  // TODO: for generality, should take a vector<ByteBuffer> &
58  // (applicable if message arrives fragmented through the transport)
59  // BTW, bytesRequested is meaningful if byteBuffer is empty
60  virtual void read(
61  const ByteBuffer &byteBuffer,
62  std::size_t bytesRequested) = 0;
63 
64  virtual void write(const std::vector<ByteBuffer> &byteBuffers) = 0;
65 
66  virtual void onReadCompleted(const ByteBuffer &byteBuffer) = 0;
67 
68  virtual void onWriteCompleted(std::size_t bytesTransferred) = 0;
69 
70  virtual int getFilterId() const = 0;
71 
72  void setPreFilter(Filter &preFilter);
73  void setPostFilter(Filter &postFilter);
74 
75  virtual std::size_t getFrameSize()
76  {
77  return 0;
78  }
79 
80  protected:
81 
82  Filter &getPreFilter();
83  Filter &getPostFilter();
84 
85  Filter *mpPreFilter;
86  Filter *mpPostFilter;
87  };
88 
89  class RCF_EXPORT IdentityFilter : public Filter
90  {
91  public:
92  void read(const ByteBuffer &byteBuffer, std::size_t bytesRequested);
93  void write(const std::vector<ByteBuffer> &byteBuffers);
94  void onReadCompleted(const ByteBuffer &byteBuffer);
95  void onWriteCompleted(std::size_t bytesTransferred);
96 
97  virtual int getFilterId() const;
98  };
99 
100  class RcfServer;
101 
102  class FilterFactory
103  {
104  public:
105  virtual ~FilterFactory()
106  {}
107 
108  virtual FilterPtr createFilter(RcfServer & server) = 0;
109 
110  virtual int getFilterId() = 0;
111  };
112 
113  typedef std::shared_ptr<FilterFactory> FilterFactoryPtr;
114 
115  RCF_EXPORT void connectFilters(const std::vector<FilterPtr> &filters);
116 
117  RCF_EXPORT bool filterData(
118  const std::vector<ByteBuffer> &unfilteredData,
119  std::vector<ByteBuffer> &filteredData,
120  const std::vector<FilterPtr> &filters);
121 
122  RCF_EXPORT bool unfilterData(
123  const ByteBuffer &filteredByteBuffer,
124  std::vector<ByteBuffer> &unfilteredByteBuffers,
125  std::size_t unfilteredDataLen,
126  const std::vector<FilterPtr> &filters);
127 
128  RCF_EXPORT bool unfilterData(
129  const ByteBuffer &filteredByteBuffer,
130  ByteBuffer &unfilteredByteBuffer,
131  std::size_t unfilteredDataLen,
132  const std::vector<FilterPtr> &filters);
133 
134 } // namespace RCF
135 
136 #endif // ! INCLUDE_RCF_FILTER_HPP
Definition: AmiIoHandler.hpp:24