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 Certificate;
49  typedef boost::shared_ptr<Certificate> CertificatePtr;
50 
51  class Win32Certificate;
52  typedef boost::shared_ptr<Win32Certificate> Win32CertificatePtr;
53 
54  class X509Certificate;
55  typedef boost::shared_ptr<X509Certificate> X509CertificatePtr;
56 
58  class RCF_EXPORT Certificate
59  {
60  public:
61 
62  // *** SWIG BEGIN ***
63 
64  virtual CertificateImplementationType _getType();
65 
66  Win32CertificatePtr _downcastToWin32Certificate(CertificatePtr certPtr);
67  X509CertificatePtr _downcastToX509Certificate(CertificatePtr certPtr);
68 
69  // *** SWIG END ***
70 
71  virtual ~Certificate()
72  {
73  }
74  };
75 
76 
77 
78  typedef boost::shared_ptr<Certificate> CertificatePtr;
79 
80  class Filter;
81 
82  typedef boost::shared_ptr<Filter> FilterPtr;
83 
84  class RCF_EXPORT Filter
85  {
86  public:
87 
88  Filter();
89  virtual ~Filter();
90  virtual void resetState();
91 
92  // TODO: for generality, should take a vector<ByteBuffer> &
93  // (applicable if message arrives fragmented through the transport)
94  // BTW, bytesRequested is meaningful if byteBuffer is empty
95  virtual void read(
96  const ByteBuffer &byteBuffer,
97  std::size_t bytesRequested) = 0;
98 
99  virtual void write(const std::vector<ByteBuffer> &byteBuffers) = 0;
100 
101  virtual void onReadCompleted(const ByteBuffer &byteBuffer) = 0;
102 
103  virtual void onWriteCompleted(std::size_t bytesTransferred) = 0;
104 
105  virtual int getFilterId() const = 0;
106 
107  void setPreFilter(Filter &preFilter);
108  void setPostFilter(Filter &postFilter);
109 
110  virtual std::size_t getFrameSize()
111  {
112  return 0;
113  }
114 
115  protected:
116 
117  Filter &getPreFilter();
118  Filter &getPostFilter();
119 
120  Filter *mpPreFilter;
121  Filter *mpPostFilter;
122  };
123 
124  class RCF_EXPORT IdentityFilter : public Filter
125  {
126  public:
127  void read(const ByteBuffer &byteBuffer, std::size_t bytesRequested);
128  void write(const std::vector<ByteBuffer> &byteBuffers);
129  void onReadCompleted(const ByteBuffer &byteBuffer);
130  void onWriteCompleted(std::size_t bytesTransferred);
131 
132  virtual int getFilterId() const;
133  };
134 
135  typedef boost::shared_ptr<Filter> FilterPtr;
136  typedef std::vector<FilterPtr> VectorFilter;
137  typedef boost::shared_ptr< std::vector<FilterPtr> > VectorFilterPtr;
138 
139  class RcfServer;
140 
141  class FilterFactory
142  {
143  public:
144  virtual ~FilterFactory()
145  {}
146 
147  virtual FilterPtr createFilter(RcfServer & server) = 0;
148 
149  virtual int getFilterId() = 0;
150  };
151 
152  typedef boost::shared_ptr<FilterFactory> FilterFactoryPtr;
153 
154  RCF_EXPORT void connectFilters(const std::vector<FilterPtr> &filters);
155 
156  RCF_EXPORT bool filterData(
157  const std::vector<ByteBuffer> &unfilteredData,
158  std::vector<ByteBuffer> &filteredData,
159  const std::vector<FilterPtr> &filters);
160 
161  RCF_EXPORT bool unfilterData(
162  const ByteBuffer &filteredByteBuffer,
163  std::vector<ByteBuffer> &unfilteredByteBuffers,
164  std::size_t unfilteredDataLen,
165  const std::vector<FilterPtr> &filters);
166 
167  RCF_EXPORT bool unfilterData(
168  const ByteBuffer &filteredByteBuffer,
169  ByteBuffer &unfilteredByteBuffer,
170  std::size_t unfilteredDataLen,
171  const std::vector<FilterPtr> &filters);
172 
173 } // namespace RCF
174 
175 #endif // ! INCLUDE_RCF_FILTER_HPP