Crypto++  5.6.3
Free C++ class library of cryptographic schemes
channels.h
Go to the documentation of this file.
1 // channels.h - written and placed in the public domain by Wei Dai
2 
3 //! \file
4 //! \headerfile channels.h
5 //! \brief Classes for multiple named channels
6 
7 #ifndef CRYPTOPP_CHANNELS_H
8 #define CRYPTOPP_CHANNELS_H
9 
10 #include "cryptlib.h"
11 #include "simple.h"
12 #include "smartptr.h"
13 #include "stdcpp.h"
14 
15 NAMESPACE_BEGIN(CryptoPP)
16 
17 #if 0
18 //! Route input on default channel to different and/or multiple channels based on message sequence number
19 class MessageSwitch : public Sink
20 {
21 public:
22  void AddDefaultRoute(BufferedTransformation &destination, const std::string &channel);
23  void AddRoute(unsigned int begin, unsigned int end, BufferedTransformation &destination, const std::string &channel);
24 
25  void Put(byte inByte);
26  void Put(const byte *inString, unsigned int length);
27 
28  void Flush(bool completeFlush, int propagation=-1);
29  void MessageEnd(int propagation=-1);
30  void PutMessageEnd(const byte *inString, unsigned int length, int propagation=-1);
31  void MessageSeriesEnd(int propagation=-1);
32 
33 private:
34  typedef std::pair<BufferedTransformation *, std::string> Route;
35  struct RangeRoute
36  {
37  RangeRoute(unsigned int begin, unsigned int end, const Route &route)
38  : begin(begin), end(end), route(route) {}
39  bool operator<(const RangeRoute &rhs) const {return begin < rhs.begin;}
40  unsigned int begin, end;
41  Route route;
42  };
43 
44  typedef std::list<RangeRoute> RouteList;
45  typedef std::list<Route> DefaultRouteList;
46 
47  RouteList m_routes;
48  DefaultRouteList m_defaultRoutes;
49  unsigned int m_nCurrentMessage;
50 };
51 #endif
52 
54 {
55 public:
56  typedef std::pair<BufferedTransformation *, std::string> Route;
57  typedef std::multimap<std::string, Route> RouteMap;
58 
59  typedef std::pair<BufferedTransformation *, value_ptr<std::string> > DefaultRoute;
60  typedef std::list<DefaultRoute> DefaultRouteList;
61 
62  // SunCC workaround: can't use const_iterator here
63  typedef RouteMap::iterator MapIterator;
64  typedef DefaultRouteList::iterator ListIterator;
65 };
66 
67 class ChannelSwitch;
68 
70 {
71 public:
72  ChannelRouteIterator(ChannelSwitch &cs) : m_cs(cs), m_useDefault(false) {}
73 
74  void Reset(const std::string &channel);
75  bool End() const;
76  void Next();
77  BufferedTransformation & Destination();
78  const std::string & Channel();
79 
80  ChannelSwitch& m_cs;
81  std::string m_channel;
82  bool m_useDefault;
83  MapIterator m_itMapCurrent, m_itMapEnd;
84  ListIterator m_itListCurrent, m_itListEnd;
85 
86 protected:
87  // Hide this to see if we break something...
89 };
90 
91 //! Route input to different and/or multiple channels based on channel ID
92 class CRYPTOPP_DLL ChannelSwitch : public Multichannel<Sink>, public ChannelSwitchTypedefs
93 {
94 public:
95  ChannelSwitch() : m_it(*this), m_blocked(false) {}
96  ChannelSwitch(BufferedTransformation &destination) : m_it(*this), m_blocked(false)
97  {
98  AddDefaultRoute(destination);
99  }
100  ChannelSwitch(BufferedTransformation &destination, const std::string &outChannel) : m_it(*this), m_blocked(false)
101  {
102  AddDefaultRoute(destination, outChannel);
103  }
104 
105  void IsolatedInitialize(const NameValuePairs &parameters=g_nullNameValuePairs);
106 
107  size_t ChannelPut2(const std::string &channel, const byte *begin, size_t length, int messageEnd, bool blocking);
108  size_t ChannelPutModifiable2(const std::string &channel, byte *begin, size_t length, int messageEnd, bool blocking);
109 
110  bool ChannelFlush(const std::string &channel, bool completeFlush, int propagation=-1, bool blocking=true);
111  bool ChannelMessageSeriesEnd(const std::string &channel, int propagation=-1, bool blocking=true);
112 
113  byte * ChannelCreatePutSpace(const std::string &channel, size_t &size);
114 
115  void AddDefaultRoute(BufferedTransformation &destination);
116  void RemoveDefaultRoute(BufferedTransformation &destination);
117  void AddDefaultRoute(BufferedTransformation &destination, const std::string &outChannel);
118  void RemoveDefaultRoute(BufferedTransformation &destination, const std::string &outChannel);
119  void AddRoute(const std::string &inChannel, BufferedTransformation &destination, const std::string &outChannel);
120  void RemoveRoute(const std::string &inChannel, BufferedTransformation &destination, const std::string &outChannel);
121 
122 private:
123  RouteMap m_routeMap;
124  DefaultRouteList m_defaultRoutes;
125 
127  bool m_blocked;
128 
129  friend class ChannelRouteIterator;
130 };
131 
132 NAMESPACE_END
133 
134 #endif
Classes providing basic library services.
Abstract base classes that provide a uniform interface to this library.
Classes for automatic resource management.
virtual bool MessageSeriesEnd(int propagation=-1, bool blocking=true)
Marks the end of a series of messages, with signal propagation.
Definition: cryptlib.cpp:452
Interface for buffered transformations.
Definition: cryptlib.h:1352
Route input to different and/or multiple channels based on channel ID.
Definition: channels.h:92
bool MessageEnd(int propagation=-1, bool blocking=true)
Signals the end of messages to the object.
Definition: cryptlib.h:1436
bool operator<(const OID &lhs, const OID &rhs)
Compare two OIDs for ordering.
size_t Put(byte inByte, bool blocking=true)
Input a byte for processing.
Definition: cryptlib.h:1378
virtual bool Flush(bool hardFlush, int propagation=-1, bool blocking=true)
Flush buffered input and/or output, with signal propagation.
Definition: cryptlib.cpp:445
const NameValuePairs & g_nullNameValuePairs
An empty set of name-value pairs.
Definition: cryptlib.cpp:79
Implementation of BufferedTransformation's attachment interface.
Definition: simple.h:276
size_t PutMessageEnd(const byte *inString, size_t length, int propagation=-1, bool blocking=true)
Input multiple bytes for processing and signal the end of a message.
Definition: cryptlib.h:1449
Crypto++ library namespace.
Provides multiple channels support for custom flush signal processing.
Definition: simple.h:193
Interface for retrieving values given their names.
Definition: cryptlib.h:277