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  * $Log: pnat.h,v $
00030  * Revision 1.7  2007/01/05 04:09:05  dereksmithies
00031  * Get it to compile on linux correctly.
00032  * Previous code failed, with message about pasting STUN and > together.
00033  *
00034  * Revision 1.6  2006/12/23 15:08:00  shorne
00035  * Now Factory loaded for ease of addition of new NAT Methods
00036  *
00037  * Revision 1.5  2006/02/26 09:29:10  shorne
00038  * Added GetMethodName and GetList functions
00039  *
00040  * Revision 1.4  2006/01/26 03:23:41  shorne
00041  * Fix compile error when merging code
00042  *
00043  * Revision 1.3  2005/11/30 12:47:37  csoutheren
00044  * Removed tabs, reformatted some code, and changed tags for Doxygen
00045  *
00046  * Revision 1.2  2005/07/13 11:15:14  csoutheren
00047  * Backported NAT abstraction files from isvo branch
00048  *
00049  * Revision 1.1.2.1  2005/04/25 13:23:19  shorne
00050  * Initial version
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 // declare macros and structures needed for NAT plugins
00240 //
00241 
00242 typedef PFactory<PNatMethod> NatFactory;
00243 
00244 template <class className> class PNatMethodServiceDescriptor : public PDevicePluginServiceDescriptor
00245 {
00246   public:
00247     virtual PObject *   CreateInstance(int /*userData*/) const { return new className; }
00248     virtual PStringList GetDeviceNames(int /*userData*/) 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

Generated on Sun Sep 6 03:50:33 2009 for PWLib by  doxygen 1.6.1