pnat.h

Go to the documentation of this file.
00001 /*
00002  * pnat.h
00003  *
00004  * NAT Strategy support for Portable Windows Library.
00005  *
00006  * Virteos is a Trade Mark of ISVO (Asia) Pte Ltd.
00007  *
00008  * Copyright (c) 2004 ISVO (Asia) Pte Ltd. All Rights Reserved.
00009  *
00010  * The contents of this file are subject to the Mozilla Public License
00011  * Version 1.0 (the "License"); you may not use this file except in
00012  * compliance with the License. You may obtain a copy of the License at
00013  * http://www.mozilla.org/MPL/
00014  *
00015  * Software distributed under the License is distributed on an "AS IS"
00016  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00017  * the License for the specific language governing rights and limitations
00018  * under the License.
00019  *
00020  *
00021  * The Original Code is derived from and used in conjunction with the 
00022  * OpenH323 Project (www.openh323.org/)
00023  *
00024  * The Initial Developer of the Original Code is ISVO (Asia) Pte Ltd.
00025  *
00026  *
00027  * Contributor(s): ______________________________________.
00028  *
00029  * $Revision: 19008 $
00030  * $Author: rjongbloed $
00031  * $Date: 2007-11-29 09:17:41 +0000 (Thu, 29 Nov 2007) $
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 PBoolean IsAvailable() { return PFalse; };
00106 
00117    virtual void SetPortRanges(
00118       WORD portBase,          
00119       WORD portMax = 0,       
00120       WORD portPairBase = 0,  
00121       WORD portPairMax = 0    
00122    );
00123 
00126    static PStringList GetNatMethodName() { return PStringList(); };
00127 
00128    virtual PStringList GetName() const
00129       { return GetNatMethodName(); }
00130 
00132 
00133 protected:
00134   struct PortInfo {
00135       PortInfo(WORD port = 0)
00136         : basePort(port)
00137         , maxPort(port)
00138         , currentPort(port)
00139       {
00140       }
00141 
00142       PMutex mutex;
00143       WORD   basePort;
00144       WORD   maxPort;
00145       WORD   currentPort;
00146     } singlePortInfo, pairedPortInfo;
00147 
00148 };
00149 
00151 
00152 PLIST(PNatList, PNatMethod);
00153 
00155 
00161 class PNatStrategy : public PObject
00162 {
00163   PCLASSINFO(PNatStrategy,PObject);
00164 
00165 public :
00166 
00171   PNatStrategy();
00172 
00175   ~PNatStrategy();
00177 
00185   void AddMethod(PNatMethod * method);
00186 
00192   PNatMethod * GetMethod();
00193 
00194 
00198   PBoolean RemoveMethod(const PString & meth);
00199 
00210     void SetPortRanges(
00211       WORD portBase,          
00212       WORD portMax = 0,       
00213       WORD portPairBase = 0,  
00214       WORD portPairMax = 0    
00215     );
00216 
00219     PNatList GetNATList() {  return natlist; };
00220 
00221         PNatMethod * LoadNatMethod(const PString & name);
00222 
00223     PStringList GetRegisteredList();
00224 
00226 
00227 private:
00228   PNatList natlist;
00229 };
00230 
00232 //
00233 // declare macros and structures needed for NAT plugins
00234 //
00235 
00236 typedef PFactory<PNatMethod> NatFactory;
00237 
00238 template <class className> class PNatMethodServiceDescriptor : public PDevicePluginServiceDescriptor
00239 {
00240   public:
00241     virtual PObject *   CreateInstance(int /*userData*/) const { return new className; }
00242     virtual PStringList GetDeviceNames(int /*userData*/) const { return className::GetNatMethodName(); }
00243 };
00244 
00245 #define PCREATE_NAT_PLUGIN(name) \
00246   static PNatMethodServiceDescriptor<PNatMethod_##name> PNatMethod_##name##_descriptor; \
00247   PCREATE_PLUGIN(name, PNatMethod, &PNatMethod_##name##_descriptor)
00248 
00249 #endif

Generated on Mon Dec 10 11:18:57 2007 for PTLib by  doxygen 1.5.1