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 bool IsAvailable(
00106 const PIPSocket::Address & binding = PIPSocket::GetDefaultIpAny()
00107 ) = 0;
00108
00119 virtual void SetPortRanges(
00120 WORD portBase,
00121 WORD portMax = 0,
00122 WORD portPairBase = 0,
00123 WORD portPairMax = 0
00124 );
00125
00128 static PStringList GetNatMethodName() { return PStringList(); };
00129
00130 virtual PStringList GetName() const
00131 { return GetNatMethodName(); }
00132
00134
00135 protected:
00136 struct PortInfo {
00137 PortInfo(WORD port = 0)
00138 : basePort(port)
00139 , maxPort(port)
00140 , currentPort(port)
00141 {
00142 }
00143
00144 PMutex mutex;
00145 WORD basePort;
00146 WORD maxPort;
00147 WORD currentPort;
00148 } singlePortInfo, pairedPortInfo;
00149
00150 };
00151
00153
00154 PLIST(PNatList, PNatMethod);
00155
00157
00163 class PNatStrategy : public PObject
00164 {
00165 PCLASSINFO(PNatStrategy,PObject);
00166
00167 public :
00168
00173 PNatStrategy();
00174
00177 ~PNatStrategy();
00179
00187 void AddMethod(PNatMethod * method);
00188
00194 PNatMethod * GetMethod();
00195
00196
00200 PBoolean RemoveMethod(const PString & meth);
00201
00212 void SetPortRanges(
00213 WORD portBase,
00214 WORD portMax = 0,
00215 WORD portPairBase = 0,
00216 WORD portPairMax = 0
00217 );
00218
00221 PNatList GetNATList() { return natlist; };
00222
00223 PNatMethod * LoadNatMethod(const PString & name);
00224
00225 PStringList GetRegisteredList();
00226
00228
00229 private:
00230 PNatList natlist;
00231 };
00232
00234
00235
00236
00237
00238 typedef PFactory<PNatMethod> NatFactory;
00239
00240 template <class className> class PNatMethodServiceDescriptor : public PDevicePluginServiceDescriptor
00241 {
00242 public:
00243 virtual PObject * CreateInstance(int ) const { return new className; }
00244 virtual PStringArray GetDeviceNames(int ) const { return className::GetNatMethodName(); }
00245 };
00246
00247 #define PCREATE_NAT_PLUGIN(name) \
00248 static PNatMethodServiceDescriptor<PNatMethod_##name> PNatMethod_##name##_descriptor; \
00249 PCREATE_PLUGIN(name, PNatMethod, &PNatMethod_##name##_descriptor)
00250
00251 #endif