Security Scol plugin
channels.h
Go to the documentation of this file.
1// channels.h - originally written and placed in the public domain by Wei Dai
2
5
6#ifndef CRYPTOPP_CHANNELS_H
7#define CRYPTOPP_CHANNELS_H
8
9#include "cryptlib.h"
10#include "simple.h"
11#include "smartptr.h"
12#include "stdcpp.h"
13
14#if CRYPTOPP_MSC_VERSION
15# pragma warning(push)
16# pragma warning(disable: 4355)
17#endif
18
19NAMESPACE_BEGIN(CryptoPP)
20
21#if 0
23class MessageSwitch : public Sink
24{
25public:
26 void AddDefaultRoute(BufferedTransformation &destination, const std::string &channel);
27 void AddRoute(unsigned int begin, unsigned int end, BufferedTransformation &destination, const std::string &channel);
28
29 void Put(byte inByte);
30 void Put(const byte *inString, unsigned int length);
31
32 void Flush(bool completeFlush, int propagation=-1);
33 void MessageEnd(int propagation=-1);
34 void PutMessageEnd(const byte *inString, unsigned int length, int propagation=-1);
35 void MessageSeriesEnd(int propagation=-1);
36
37private:
38 typedef std::pair<BufferedTransformation *, std::string> Route;
39 struct RangeRoute
40 {
41 RangeRoute(unsigned int begin, unsigned int end, const Route &route)
42 : begin(begin), end(end), route(route) {}
43 bool operator<(const RangeRoute &rhs) const {return begin < rhs.begin;}
44 unsigned int begin, end;
45 Route route;
46 };
47
48 typedef std::list<RangeRoute> RouteList;
49 typedef std::list<Route> DefaultRouteList;
50
51 RouteList m_routes;
52 DefaultRouteList m_defaultRoutes;
53 unsigned int m_nCurrentMessage;
54};
55#endif
56
58{
59public:
60 typedef std::pair<BufferedTransformation *, std::string> Route;
61 typedef std::multimap<std::string, Route> RouteMap;
62
63 typedef std::pair<BufferedTransformation *, value_ptr<std::string> > DefaultRoute;
64 typedef std::list<DefaultRoute> DefaultRouteList;
65
66 // SunCC workaround: can't use const_iterator here
67 typedef RouteMap::iterator MapIterator;
68 typedef DefaultRouteList::iterator ListIterator;
69};
70
71class ChannelSwitch;
72
74{
75public:
76 ChannelRouteIterator(ChannelSwitch &cs) : m_cs(cs), m_useDefault(false) {}
77
78 void Reset(const std::string &channel);
79 bool End() const;
80 void Next();
81 BufferedTransformation & Destination();
82 const std::string & Channel();
83
84 ChannelSwitch& m_cs;
85 std::string m_channel;
86 bool m_useDefault;
87 MapIterator m_itMapCurrent, m_itMapEnd;
88 ListIterator m_itListCurrent, m_itListEnd;
89
90protected:
91 // Hide this to see if we break something...
93};
94
96class CRYPTOPP_DLL ChannelSwitch : public Multichannel<Sink>, public ChannelSwitchTypedefs
97{
98public:
99 ChannelSwitch() : m_it(*this), m_blocked(false) {}
100 ChannelSwitch(BufferedTransformation &destination) : m_it(*this), m_blocked(false)
101 {
102 AddDefaultRoute(destination);
103 }
104 ChannelSwitch(BufferedTransformation &destination, const std::string &outChannel) : m_it(*this), m_blocked(false)
105 {
106 AddDefaultRoute(destination, outChannel);
107 }
108
109 void IsolatedInitialize(const NameValuePairs &parameters=g_nullNameValuePairs);
110
111 size_t ChannelPut2(const std::string &channel, const byte *begin, size_t length, int messageEnd, bool blocking);
112 size_t ChannelPutModifiable2(const std::string &channel, byte *begin, size_t length, int messageEnd, bool blocking);
113
114 bool ChannelFlush(const std::string &channel, bool completeFlush, int propagation=-1, bool blocking=true);
115 bool ChannelMessageSeriesEnd(const std::string &channel, int propagation=-1, bool blocking=true);
116
117 byte * ChannelCreatePutSpace(const std::string &channel, size_t &size);
118
119 void AddDefaultRoute(BufferedTransformation &destination);
120 void RemoveDefaultRoute(BufferedTransformation &destination);
121 void AddDefaultRoute(BufferedTransformation &destination, const std::string &outChannel);
122 void RemoveDefaultRoute(BufferedTransformation &destination, const std::string &outChannel);
123 void AddRoute(const std::string &inChannel, BufferedTransformation &destination, const std::string &outChannel);
124 void RemoveRoute(const std::string &inChannel, BufferedTransformation &destination, const std::string &outChannel);
125
126private:
127 RouteMap m_routeMap;
128 DefaultRouteList m_defaultRoutes;
129
131 bool m_blocked;
132
133 friend class ChannelRouteIterator;
134};
135
136NAMESPACE_END
137
138#if CRYPTOPP_MSC_VERSION
139# pragma warning(pop)
140#endif
141
142#endif
Interface for buffered transformations.
Definition cryptlib.h:1652
bool MessageEnd(int propagation=-1, bool blocking=true)
Signals the end of messages to the object.
Definition cryptlib.h:1743
virtual bool Flush(bool hardFlush, int propagation=-1, bool blocking=true)
Flush buffered input and/or output, with signal propagation.
Definition cryptlib.cpp:441
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:1757
virtual bool MessageSeriesEnd(int propagation=-1, bool blocking=true)
Marks the end of a series of messages, with signal propagation.
Definition cryptlib.cpp:448
size_t Put(byte inByte, bool blocking=true)
Input a byte for processing.
Definition cryptlib.h:1673
Route input to different and/or multiple channels based on channel ID.
Definition channels.h:97
Multiple channels support for custom signal processing.
Definition simple.h:316
virtual bool ChannelFlush(const std::string &channel, bool hardFlush, int propagation=-1, bool blocking=true)=0
Flush buffered input and/or output on a channel.
size_t ChannelPutModifiable2(const std::string &channel, byte *begin, size_t length, int messageEnd, bool blocking)
Input multiple bytes that may be modified by callee on a channel.
Definition simple.h:405
virtual size_t ChannelPut2(const std::string &channel, const byte *begin, size_t length, int messageEnd, bool blocking)=0
Input multiple bytes for processing on a channel.
byte * ChannelCreatePutSpace(const std::string &channel, size_t &size)
Request space which can be written into by the caller.
Definition simple.h:378
Interface for retrieving values given their names.
Definition cryptlib.h:322
Implementation of BufferedTransformation's attachment interface.
Definition simple.h:479
Abstract base classes that provide a uniform interface to this library.
Classes providing basic library services.
Classes for automatic resource management.
Common C++ header files.