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