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