00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifndef _PTLIB_H
00035 #include <ptlib.h>
00036 #endif
00037
00038 #include <ptlib/sockets.h>
00039
00040 #ifndef P_NATMETHOD
00041 #define P_NATMETHOD
00042
00043 #include <ptlib/plugin.h>
00044 #include <ptlib/pluginmgr.h>
00045
00053 class PNatMethod : public PObject
00054 {
00055 PCLASSINFO(PNatMethod,PObject);
00056
00057 public:
00058
00063 PNatMethod();
00064
00067 ~PNatMethod();
00069
00070
00073 static PNatMethod * Create(
00074 const PString & name,
00075 PPluginManager * pluginMgr = NULL
00076 );
00077
00080
00084 virtual PBoolean GetExternalAddress(
00085 PIPSocket::Address & externalAddress,
00086 const PTimeInterval & maxAge = 1000
00087 ) = 0;
00088
00092 virtual PBoolean CreateSocketPair(
00093 PUDPSocket * & socket1,
00094 PUDPSocket * & socket2,
00095 const PIPSocket::Address & binding = PIPSocket::GetDefaultIpAny()
00096 ) = 0;
00097
00105 virtual PBoolean IsAvailable() { return PFalse; };
00106
00117 virtual void SetPortRanges(
00118 WORD portBase,
00119 WORD portMax = 0,
00120 WORD portPairBase = 0,
00121 WORD portPairMax = 0
00122 );
00123
00126 static PStringList GetNatMethodName() { return PStringList(); };
00127
00128 virtual PStringList GetName() const
00129 { return GetNatMethodName(); }
00130
00132
00133 protected:
00134 struct PortInfo {
00135 PortInfo(WORD port = 0)
00136 : basePort(port)
00137 , maxPort(port)
00138 , currentPort(port)
00139 {
00140 }
00141
00142 PMutex mutex;
00143 WORD basePort;
00144 WORD maxPort;
00145 WORD currentPort;
00146 } singlePortInfo, pairedPortInfo;
00147
00148 };
00149
00151
00152 PLIST(PNatList, PNatMethod);
00153
00155
00161 class PNatStrategy : public PObject
00162 {
00163 PCLASSINFO(PNatStrategy,PObject);
00164
00165 public :
00166
00171 PNatStrategy();
00172
00175 ~PNatStrategy();
00177
00185 void AddMethod(PNatMethod * method);
00186
00192 PNatMethod * GetMethod();
00193
00194
00198 PBoolean RemoveMethod(const PString & meth);
00199
00210 void SetPortRanges(
00211 WORD portBase,
00212 WORD portMax = 0,
00213 WORD portPairBase = 0,
00214 WORD portPairMax = 0
00215 );
00216
00219 PNatList GetNATList() { return natlist; };
00220
00221 PNatMethod * LoadNatMethod(const PString & name);
00222
00223 PStringList GetRegisteredList();
00224
00226
00227 private:
00228 PNatList natlist;
00229 };
00230
00232
00233
00234
00235
00236 typedef PFactory<PNatMethod> NatFactory;
00237
00238 template <class className> class PNatMethodServiceDescriptor : public PDevicePluginServiceDescriptor
00239 {
00240 public:
00241 virtual PObject * CreateInstance(int ) const { return new className; }
00242 virtual PStringList GetDeviceNames(int ) const { return className::GetNatMethodName(); }
00243 };
00244
00245 #define PCREATE_NAT_PLUGIN(name) \
00246 static PNatMethodServiceDescriptor<PNatMethod_##name> PNatMethod_##name##_descriptor; \
00247 PCREATE_PLUGIN(name, PNatMethod, &PNatMethod_##name##_descriptor)
00248
00249 #endif