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