Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:54:54

0001 // channels.h - originally written and placed in the public domain by Wei Dai

0002 
0003 /// \file channels.h

0004 /// \brief Classes for multiple named channels

0005 
0006 #ifndef CRYPTOPP_CHANNELS_H
0007 #define CRYPTOPP_CHANNELS_H
0008 
0009 #include "cryptlib.h"
0010 #include "simple.h"
0011 #include "smartptr.h"
0012 #include "stdcpp.h"
0013 
0014 #if CRYPTOPP_MSC_VERSION
0015 # pragma warning(push)
0016 # pragma warning(disable: 4355)
0017 #endif
0018 
0019 NAMESPACE_BEGIN(CryptoPP)
0020 
0021 #if 0
0022 /// Route input on default channel to different and/or multiple channels based on message sequence number

0023 class MessageSwitch : public Sink
0024 {
0025 public:
0026     void AddDefaultRoute(BufferedTransformation &destination, const std::string &channel);
0027     void AddRoute(unsigned int begin, unsigned int end, BufferedTransformation &destination, const std::string &channel);
0028 
0029     void Put(byte inByte);
0030     void Put(const byte *inString, unsigned int length);
0031 
0032     void Flush(bool completeFlush, int propagation=-1);
0033     void MessageEnd(int propagation=-1);
0034     void PutMessageEnd(const byte *inString, unsigned int length, int propagation=-1);
0035     void MessageSeriesEnd(int propagation=-1);
0036 
0037 private:
0038     typedef std::pair<BufferedTransformation *, std::string> Route;
0039     struct RangeRoute
0040     {
0041         RangeRoute(unsigned int begin, unsigned int end, const Route &route)
0042             : begin(begin), end(end), route(route) {}
0043         bool operator<(const RangeRoute &rhs) const {return begin < rhs.begin;}
0044         unsigned int begin, end;
0045         Route route;
0046     };
0047 
0048     typedef std::list<RangeRoute> RouteList;
0049     typedef std::list<Route> DefaultRouteList;
0050 
0051     RouteList m_routes;
0052     DefaultRouteList m_defaultRoutes;
0053     unsigned int m_nCurrentMessage;
0054 };
0055 #endif
0056 
0057 class ChannelSwitchTypedefs
0058 {
0059 public:
0060     typedef std::pair<BufferedTransformation *, std::string> Route;
0061     typedef std::multimap<std::string, Route> RouteMap;
0062 
0063     typedef std::pair<BufferedTransformation *, value_ptr<std::string> > DefaultRoute;
0064     typedef std::list<DefaultRoute> DefaultRouteList;
0065 
0066     // SunCC workaround: can't use const_iterator here

0067     typedef RouteMap::iterator MapIterator;
0068     typedef DefaultRouteList::iterator ListIterator;
0069 };
0070 
0071 class ChannelSwitch;
0072 
0073 class ChannelRouteIterator : public ChannelSwitchTypedefs
0074 {
0075 public:
0076     ChannelRouteIterator(ChannelSwitch &cs) : m_cs(cs), m_useDefault(false) {}
0077 
0078     void Reset(const std::string &channel);
0079     bool End() const;
0080     void Next();
0081     BufferedTransformation & Destination();
0082     const std::string & Channel();
0083 
0084     ChannelSwitch& m_cs;
0085     std::string m_channel;
0086     bool m_useDefault;
0087     MapIterator m_itMapCurrent, m_itMapEnd;
0088     ListIterator m_itListCurrent, m_itListEnd;
0089 
0090 protected:
0091     // Hide this to see if we break something...

0092     ChannelRouteIterator();
0093 };
0094 
0095 /// Route input to different and/or multiple channels based on channel ID

0096 class CRYPTOPP_DLL ChannelSwitch : public Multichannel<Sink>, public ChannelSwitchTypedefs
0097 {
0098 public:
0099     ChannelSwitch() : m_it(*this), m_blocked(false) {}
0100     ChannelSwitch(BufferedTransformation &destination) : m_it(*this), m_blocked(false)
0101     {
0102         AddDefaultRoute(destination);
0103     }
0104     ChannelSwitch(BufferedTransformation &destination, const std::string &outChannel) : m_it(*this), m_blocked(false)
0105     {
0106         AddDefaultRoute(destination, outChannel);
0107     }
0108 
0109     void IsolatedInitialize(const NameValuePairs &parameters=g_nullNameValuePairs);
0110 
0111     size_t ChannelPut2(const std::string &channel, const byte *begin, size_t length, int messageEnd, bool blocking);
0112     size_t ChannelPutModifiable2(const std::string &channel, byte *begin, size_t length, int messageEnd, bool blocking);
0113 
0114     bool ChannelFlush(const std::string &channel, bool completeFlush, int propagation=-1, bool blocking=true);
0115     bool ChannelMessageSeriesEnd(const std::string &channel, int propagation=-1, bool blocking=true);
0116 
0117     byte * ChannelCreatePutSpace(const std::string &channel, size_t &size);
0118 
0119     void AddDefaultRoute(BufferedTransformation &destination);
0120     void RemoveDefaultRoute(BufferedTransformation &destination);
0121     void AddDefaultRoute(BufferedTransformation &destination, const std::string &outChannel);
0122     void RemoveDefaultRoute(BufferedTransformation &destination, const std::string &outChannel);
0123     void AddRoute(const std::string &inChannel, BufferedTransformation &destination, const std::string &outChannel);
0124     void RemoveRoute(const std::string &inChannel, BufferedTransformation &destination, const std::string &outChannel);
0125 
0126 private:
0127     RouteMap m_routeMap;
0128     DefaultRouteList m_defaultRoutes;
0129 
0130     ChannelRouteIterator m_it;
0131     bool m_blocked;
0132 
0133     friend class ChannelRouteIterator;
0134 };
0135 
0136 NAMESPACE_END
0137 
0138 #if CRYPTOPP_MSC_VERSION
0139 # pragma warning(pop)
0140 #endif
0141 
0142 #endif