pnat.h
Go to the documentation of this file.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
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 #include <ptlib.h>
00056 #include <ptlib/sockets.h>
00057
00058 #ifndef P_NATMETHOD
00059 #define P_NATMETHOD
00060
00061 #include <ptlib/plugin.h>
00062 #include <ptlib/pluginmgr.h>
00063
00071 class PNatMethod : public PObject
00072 {
00073 PCLASSINFO(PNatMethod,PObject);
00074
00075 public:
00076
00081 PNatMethod();
00082
00085 ~PNatMethod();
00087
00088
00091 static PNatMethod * Create(const PString & name,
00092 PPluginManager * pluginMgr = NULL
00093 );
00094
00097
00101 virtual BOOL GetExternalAddress(
00102 PIPSocket::Address & externalAddress,
00103 const PTimeInterval & maxAge = 1000
00104 ) =0;
00105
00109 virtual BOOL CreateSocketPair(
00110 PUDPSocket * & socket1,
00111 PUDPSocket * & socket2
00112 ) =0;
00113
00121 virtual BOOL IsAvailable() { return FALSE; };
00122
00133 virtual void SetPortRanges(
00134 WORD portBase,
00135 WORD portMax = 0,
00136 WORD portPairBase = 0,
00137 WORD portPairMax = 0
00138 );
00139
00142 static PStringList GetNatMethodName() { return PStringList(); };
00143
00145
00146 protected:
00147 struct PortInfo {
00148 PMutex mutex;
00149 WORD basePort;
00150 WORD maxPort;
00151 WORD currentPort;
00152 } singlePortInfo, pairedPortInfo;
00153
00154 };
00155
00157
00158 PLIST(PNatList, PNatMethod);
00159
00161
00167 class PNatStrategy : public PObject
00168 {
00169 PCLASSINFO(PNatStrategy,PObject);
00170
00171 public :
00172
00177 PNatStrategy();
00178
00181 ~PNatStrategy();
00183
00191 void AddMethod(PNatMethod * method);
00192
00198 PNatMethod * GetMethod();
00199
00200
00204 BOOL RemoveMethod(const PString & meth);
00205
00216 void SetPortRanges(
00217 WORD portBase,
00218 WORD portMax = 0,
00219 WORD portPairBase = 0,
00220 WORD portPairMax = 0
00221 );
00222
00225 PNatList GetNATList() { return natlist; };
00226
00227 PNatMethod * LoadNatMethod(const PString & name);
00228
00229 PStringList GetRegisteredList();
00230
00232
00233 private:
00234 PNatList natlist;
00235 };
00236
00238
00239
00240
00241
00242 typedef PFactory<PNatMethod> NatFactory;
00243
00244 template <class className> class PNatMethodServiceDescriptor : public PDevicePluginServiceDescriptor
00245 {
00246 public:
00247 virtual PObject * CreateInstance(int ) const { return new className; }
00248 virtual PStringList GetDeviceNames(int ) const { return className::GetNatMethodName(); }
00249 };
00250
00251 #define PCREATE_NAT_PLUGIN(name) \
00252 static PNatMethodServiceDescriptor<PNatMethod_##name> PNatMethod_##name##_descriptor; \
00253 PCREATE_PLUGIN(name, PNatMethod, &PNatMethod_##name##_descriptor)
00254
00255 #endif