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 #include <ptlib/sockets.h>
00035
00036 #ifndef PTLIB_PNAT_H
00037 #define PTLIB_PNAT_H
00038
00039 #include <ptlib/plugin.h>
00040 #include <ptlib/pluginmgr.h>
00041
00049 class PNatMethod : public PObject
00050 {
00051 PCLASSINFO(PNatMethod,PObject);
00052
00053 public:
00058 PNatMethod();
00059
00062 ~PNatMethod();
00064
00065
00068 virtual void PrintOn(
00069 ostream & strm
00070 ) const;
00072
00073
00078 static PNatMethod * Create(
00079 const PString & name,
00080 PPluginManager * pluginMgr = NULL
00081 );
00082
00085 virtual PString GetName() const = 0;
00086
00090 virtual PString GetServer() const;
00091
00094 virtual bool GetServerAddress(
00095 PIPSocket::Address & address,
00096 WORD & port
00097 ) const = 0;
00098
00102 virtual PBoolean GetExternalAddress(
00103 PIPSocket::Address & externalAddress,
00104 const PTimeInterval & maxAge = 1000
00105 ) = 0;
00106
00109 virtual bool GetInterfaceAddress(
00110 PIPSocket::Address & internalAddress
00111 ) const = 0;
00112
00126 virtual PBoolean CreateSocket(
00127 PUDPSocket * & socket,
00128 const PIPSocket::Address & binding = PIPSocket::GetDefaultIpAny(),
00129 WORD localPort = 0
00130 ) = 0;
00131
00145 virtual PBoolean CreateSocketPair(
00146 PUDPSocket * & socket1,
00147 PUDPSocket * & socket2,
00148 const PIPSocket::Address & binding = PIPSocket::GetDefaultIpAny()
00149 ) = 0;
00150
00158 virtual bool IsAvailable(
00159 const PIPSocket::Address & binding = PIPSocket::GetDefaultIpAny()
00160 ) = 0;
00161
00162 enum RTPSupportTypes {
00163 RTPSupported,
00164 RTPIfSendMedia,
00165 RTPUnsupported,
00166 RTPUnknown,
00167 NumRTPSupportTypes
00168 };
00169
00173 virtual RTPSupportTypes GetRTPSupport(
00174 PBoolean force = PFalse
00175 ) = 0;
00176
00187 virtual void SetPortRanges(
00188 WORD portBase,
00189 WORD portMax = 0,
00190 WORD portPairBase = 0,
00191 WORD portPairMax = 0
00192 );
00194
00195 protected:
00196 struct PortInfo {
00197 PortInfo(WORD port = 0)
00198 : basePort(port)
00199 , maxPort(port)
00200 , currentPort(port)
00201 {
00202 }
00203
00204 PMutex mutex;
00205 WORD basePort;
00206 WORD maxPort;
00207 WORD currentPort;
00208 } singlePortInfo, pairedPortInfo;
00209 };
00210
00212
00213 PLIST(PNatList, PNatMethod);
00214
00216
00222 class PNatStrategy : public PObject
00223 {
00224 PCLASSINFO(PNatStrategy,PObject);
00225
00226 public :
00227
00232 PNatStrategy();
00233
00236 ~PNatStrategy();
00238
00246 void AddMethod(PNatMethod * method);
00247
00253 PNatMethod * GetMethod();
00254
00255
00259 PBoolean RemoveMethod(const PString & meth);
00260
00271 void SetPortRanges(
00272 WORD portBase,
00273 WORD portMax = 0,
00274 WORD portPairBase = 0,
00275 WORD portPairMax = 0
00276 );
00277
00280 PNatList GetNATList() { return natlist; };
00281
00282 PNatMethod * LoadNatMethod(const PString & name);
00283
00284 PStringList GetRegisteredList();
00285
00287
00288 private:
00289 PNatList natlist;
00290 };
00291
00293
00294
00295
00296
00297 typedef PFactory<PNatMethod> NatFactory;
00298
00299 template <class className> class PNatMethodServiceDescriptor : public PDevicePluginServiceDescriptor
00300 {
00301 public:
00302 virtual PObject * CreateInstance(int ) const { return new className; }
00303 virtual PStringArray GetDeviceNames(int ) const { return className::GetNatMethodName(); }
00304 };
00305
00306 #define PCREATE_NAT_PLUGIN(name) \
00307 static PNatMethodServiceDescriptor<PNatMethod_##name> PNatMethod_##name##_descriptor; \
00308 PCREATE_PLUGIN(name, PNatMethod, &PNatMethod_##name##_descriptor)
00309
00310
00311 #endif // PTLIB_PNAT_H
00312
00313
00314