00001 #ifndef CRYPTOPP_CHANNELS_H
00002 #define CRYPTOPP_CHANNELS_H
00003
00004 #include "simple.h"
00005 #include "smartptr.h"
00006 #include <map>
00007 #include <list>
00008
00009 NAMESPACE_BEGIN(CryptoPP)
00010
00011 #if 0
00012
00013 class MessageSwitch : public Sink
00014 {
00015 public:
00016 void AddDefaultRoute(BufferedTransformation &destination, const std::string &channel);
00017 void AddRoute(unsigned int begin, unsigned int end, BufferedTransformation &destination, const std::string &channel);
00018
00019 void Put(byte inByte);
00020 void Put(const byte *inString, unsigned int length);
00021
00022 void Flush(bool completeFlush, int propagation=-1);
00023 void MessageEnd(int propagation=-1);
00024 void PutMessageEnd(const byte *inString, unsigned int length, int propagation=-1);
00025 void MessageSeriesEnd(int propagation=-1);
00026
00027 private:
00028 typedef std::pair<BufferedTransformation *, std::string> Route;
00029 struct RangeRoute
00030 {
00031 RangeRoute(unsigned int begin, unsigned int end, const Route &route)
00032 : begin(begin), end(end), route(route) {}
00033 bool operator<(const RangeRoute &rhs) const {return begin < rhs.begin;}
00034 unsigned int begin, end;
00035 Route route;
00036 };
00037
00038 typedef std::list<RangeRoute> RouteList;
00039 typedef std::list<Route> DefaultRouteList;
00040
00041 RouteList m_routes;
00042 DefaultRouteList m_defaultRoutes;
00043 unsigned int m_nCurrentMessage;
00044 };
00045 #endif
00046
00047 class ChannelSwitchTypedefs
00048 {
00049 public:
00050 typedef std::pair<BufferedTransformation *, std::string> Route;
00051 typedef std::multimap<std::string, Route> RouteMap;
00052
00053 typedef std::pair<BufferedTransformation *, value_ptr<std::string> > DefaultRoute;
00054 typedef std::list<DefaultRoute> DefaultRouteList;
00055
00056
00057 typedef RouteMap::iterator MapIterator;
00058 typedef DefaultRouteList::iterator ListIterator;
00059 };
00060
00061 class ChannelSwitch;
00062
00063 class ChannelRouteIterator : public ChannelSwitchTypedefs
00064 {
00065 public:
00066 ChannelSwitch& m_cs;
00067 std::string m_channel;
00068 bool m_useDefault;
00069 MapIterator m_itMapCurrent, m_itMapEnd;
00070 ListIterator m_itListCurrent, m_itListEnd;
00071
00072 ChannelRouteIterator(ChannelSwitch &cs) : m_cs(cs) {}
00073 void Reset(const std::string &channel);
00074 bool End() const;
00075 void Next();
00076 BufferedTransformation & Destination();
00077 const std::string & Channel();
00078 };
00079
00080
00081 class CRYPTOPP_DLL ChannelSwitch : public Multichannel<Sink>, public ChannelSwitchTypedefs
00082 {
00083 public:
00084 ChannelSwitch() : m_it(*this), m_blocked(false) {}
00085 ChannelSwitch(BufferedTransformation &destination) : m_it(*this), m_blocked(false)
00086 {
00087 AddDefaultRoute(destination);
00088 }
00089 ChannelSwitch(BufferedTransformation &destination, const std::string &outChannel) : m_it(*this), m_blocked(false)
00090 {
00091 AddDefaultRoute(destination, outChannel);
00092 }
00093
00094 void IsolatedInitialize(const NameValuePairs ¶meters=g_nullNameValuePairs);
00095
00096 size_t ChannelPut2(const std::string &channel, const byte *begin, size_t length, int messageEnd, bool blocking);
00097 size_t ChannelPutModifiable2(const std::string &channel, byte *begin, size_t length, int messageEnd, bool blocking);
00098
00099 bool ChannelFlush(const std::string &channel, bool completeFlush, int propagation=-1, bool blocking=true);
00100 bool ChannelMessageSeriesEnd(const std::string &channel, int propagation=-1, bool blocking=true);
00101
00102 byte * ChannelCreatePutSpace(const std::string &channel, size_t &size);
00103
00104 void AddDefaultRoute(BufferedTransformation &destination);
00105 void RemoveDefaultRoute(BufferedTransformation &destination);
00106 void AddDefaultRoute(BufferedTransformation &destination, const std::string &outChannel);
00107 void RemoveDefaultRoute(BufferedTransformation &destination, const std::string &outChannel);
00108 void AddRoute(const std::string &inChannel, BufferedTransformation &destination, const std::string &outChannel);
00109 void RemoveRoute(const std::string &inChannel, BufferedTransformation &destination, const std::string &outChannel);
00110
00111 private:
00112 RouteMap m_routeMap;
00113 DefaultRouteList m_defaultRoutes;
00114
00115 ChannelRouteIterator m_it;
00116 bool m_blocked;
00117
00118 friend class ChannelRouteIterator;
00119 };
00120
00121 NAMESPACE_END
00122
00123 #endif