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
00072 virtual void PrintOn(
00073 ostream & strm
00074 ) const;
00076
00077
00082 static PNatMethod * Create(
00083 const PString & name,
00084 PPluginManager * pluginMgr = NULL
00085 );
00086
00089 virtual PString GetName() const = 0;
00090
00094 virtual PString GetServer() const;
00095
00098 virtual bool GetServerAddress(
00099 PIPSocket::Address & address,
00100 WORD & port
00101 ) const = 0;
00102
00106 virtual PBoolean GetExternalAddress(
00107 PIPSocket::Address & externalAddress,
00108 const PTimeInterval & maxAge = 1000
00109 ) = 0;
00110
00113 virtual bool GetInterfaceAddress(
00114 PIPSocket::Address & internalAddress
00115 ) const = 0;
00116
00130 virtual PBoolean CreateSocket(
00131 PUDPSocket * & socket,
00132 const PIPSocket::Address & binding = PIPSocket::GetDefaultIpAny(),
00133 WORD localPort = 0
00134 ) = 0;
00135
00149 virtual PBoolean CreateSocketPair(
00150 PUDPSocket * & socket1,
00151 PUDPSocket * & socket2,
00152 const PIPSocket::Address & binding = PIPSocket::GetDefaultIpAny()
00153 ) = 0;
00154
00162 virtual bool IsAvailable(
00163 const PIPSocket::Address & binding = PIPSocket::GetDefaultIpAny()
00164 ) = 0;
00165
00166 enum RTPSupportTypes {
00167 RTPSupported,
00168 RTPIfSendMedia,
00169 RTPUnsupported,
00170 RTPUnknown,
00171 NumRTPSupportTypes
00172 };
00173
00177 virtual RTPSupportTypes GetRTPSupport(
00178 PBoolean force = PFalse
00179 ) = 0;
00180
00191 virtual void SetPortRanges(
00192 WORD portBase,
00193 WORD portMax = 0,
00194 WORD portPairBase = 0,
00195 WORD portPairMax = 0
00196 );
00198
00199 protected:
00200 struct PortInfo {
00201 PortInfo(WORD port = 0)
00202 : basePort(port)
00203 , maxPort(port)
00204 , currentPort(port)
00205 {
00206 }
00207
00208 PMutex mutex;
00209 WORD basePort;
00210 WORD maxPort;
00211 WORD currentPort;
00212 } singlePortInfo, pairedPortInfo;
00213 };
00214
00216
00217 PLIST(PNatList, PNatMethod);
00218
00220
00226 class PNatStrategy : public PObject
00227 {
00228 PCLASSINFO(PNatStrategy,PObject);
00229
00230 public :
00231
00236 PNatStrategy();
00237
00240 ~PNatStrategy();
00242
00250 void AddMethod(PNatMethod * method);
00251
00257 PNatMethod * GetMethod();
00258
00259
00263 PBoolean RemoveMethod(const PString & meth);
00264
00275 void SetPortRanges(
00276 WORD portBase,
00277 WORD portMax = 0,
00278 WORD portPairBase = 0,
00279 WORD portPairMax = 0
00280 );
00281
00284 PNatList GetNATList() { return natlist; };
00285
00286 PNatMethod * LoadNatMethod(const PString & name);
00287
00288 PStringList GetRegisteredList();
00289
00291
00292 private:
00293 PNatList natlist;
00294 };
00295
00297
00298
00299
00300
00301 typedef PFactory<PNatMethod> NatFactory;
00302
00303 template <class className> class PNatMethodServiceDescriptor : public PDevicePluginServiceDescriptor
00304 {
00305 public:
00306 virtual PObject * CreateInstance(int ) const { return new className; }
00307 virtual PStringArray GetDeviceNames(int ) const { return className::GetNatMethodName(); }
00308 };
00309
00310 #define PCREATE_NAT_PLUGIN(name) \
00311 static PNatMethodServiceDescriptor<PNatMethod_##name> PNatMethod_##name##_descriptor; \
00312 PCREATE_PLUGIN(name, PNatMethod, &PNatMethod_##name##_descriptor)
00313
00314 #endif