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:
00062 PNatMethod();
00063
00066 ~PNatMethod();
00068
00069
00074 static PNatMethod * Create(
00075 const PString & name,
00076 PPluginManager * pluginMgr = NULL
00077 );
00078
00081 virtual PString GetName() const = 0;
00082
00086 virtual PString GetServer() const;
00087
00090 virtual bool GetServerAddress(
00091 PIPSocket::Address & address,
00092 WORD & port
00093 ) const = 0;
00094
00098 virtual PBoolean GetExternalAddress(
00099 PIPSocket::Address & externalAddress,
00100 const PTimeInterval & maxAge = 1000
00101 ) = 0;
00102
00105 virtual bool GetInterfaceAddress(
00106 PIPSocket::Address & internalAddress
00107 ) const = 0;
00108
00122 virtual PBoolean CreateSocket(
00123 PUDPSocket * & socket,
00124 const PIPSocket::Address & binding = PIPSocket::GetDefaultIpAny(),
00125 WORD localPort = 0
00126 ) = 0;
00127
00141 virtual PBoolean CreateSocketPair(
00142 PUDPSocket * & socket1,
00143 PUDPSocket * & socket2,
00144 const PIPSocket::Address & binding = PIPSocket::GetDefaultIpAny()
00145 ) = 0;
00146
00154 virtual bool IsAvailable(
00155 const PIPSocket::Address & binding = PIPSocket::GetDefaultIpAny()
00156 ) = 0;
00157
00158 enum RTPSupportTypes {
00159 RTPSupported,
00160 RTPIfSendMedia,
00161 RTPUnsupported,
00162 RTPUnknown,
00163 NumRTPSupportTypes
00164 };
00165
00169 virtual RTPSupportTypes GetRTPSupport(
00170 PBoolean force = PFalse
00171 ) = 0;
00172
00183 virtual void SetPortRanges(
00184 WORD portBase,
00185 WORD portMax = 0,
00186 WORD portPairBase = 0,
00187 WORD portPairMax = 0
00188 );
00190
00191 protected:
00192 struct PortInfo {
00193 PortInfo(WORD port = 0)
00194 : basePort(port)
00195 , maxPort(port)
00196 , currentPort(port)
00197 {
00198 }
00199
00200 PMutex mutex;
00201 WORD basePort;
00202 WORD maxPort;
00203 WORD currentPort;
00204 } singlePortInfo, pairedPortInfo;
00205 };
00206
00208
00209 PLIST(PNatList, PNatMethod);
00210
00212
00218 class PNatStrategy : public PObject
00219 {
00220 PCLASSINFO(PNatStrategy,PObject);
00221
00222 public :
00223
00228 PNatStrategy();
00229
00232 ~PNatStrategy();
00234
00242 void AddMethod(PNatMethod * method);
00243
00249 PNatMethod * GetMethod();
00250
00251
00255 PBoolean RemoveMethod(const PString & meth);
00256
00267 void SetPortRanges(
00268 WORD portBase,
00269 WORD portMax = 0,
00270 WORD portPairBase = 0,
00271 WORD portPairMax = 0
00272 );
00273
00276 PNatList GetNATList() { return natlist; };
00277
00278 PNatMethod * LoadNatMethod(const PString & name);
00279
00280 PStringList GetRegisteredList();
00281
00283
00284 private:
00285 PNatList natlist;
00286 };
00287
00289
00290
00291
00292
00293 typedef PFactory<PNatMethod> NatFactory;
00294
00295 template <class className> class PNatMethodServiceDescriptor : public PDevicePluginServiceDescriptor
00296 {
00297 public:
00298 virtual PObject * CreateInstance(int ) const { return new className; }
00299 virtual PStringArray GetDeviceNames(int ) const { return className::GetNatMethodName(); }
00300 };
00301
00302 #define PCREATE_NAT_PLUGIN(name) \
00303 static PNatMethodServiceDescriptor<PNatMethod_##name> PNatMethod_##name##_descriptor; \
00304 PCREATE_PLUGIN(name, PNatMethod, &PNatMethod_##name##_descriptor)
00305
00306 #endif