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: 20766 $
00030  * $Author: rjongbloed $
00031  * $Date: 2008-08-29 06:41:59 +0000 (Fri, 29 Aug 2008) $
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 // declare macros and structures needed for NAT plugins
00299 //
00300 
00301 typedef PFactory<PNatMethod> NatFactory;
00302 
00303 template <class className> class PNatMethodServiceDescriptor : public PDevicePluginServiceDescriptor
00304 {
00305   public:
00306     virtual PObject *    CreateInstance(int /*userData*/) const { return new className; }
00307     virtual PStringArray GetDeviceNames(int /*userData*/) 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

Generated on Mon Feb 23 01:57:54 2009 for PTLib by  doxygen 1.5.1