h460_std23.h

Go to the documentation of this file.
00001 /* H460_std23.h
00002 *
00003 * Copyright (c) 2009 ISVO (Asia) Pte Ltd. All Rights Reserved.
00004 *
00005 * The contents of this file are subject to the Mozilla Public License
00006 * Version 1.1 (the "License"); you may not use this file except in
00007 * compliance with the License. You may obtain a copy of the License at
00008 * http://www.mozilla.org/MPL/
00009 *
00010 * Alternatively, the contents of this file may be used under the terms
00011 * of the General Public License (the  "GNU License"), in which case the
00012 * provisions of GNU License are applicable instead of those
00013 * above. If you wish to allow use of your version of this file only
00014 * under the terms of the GNU License and not to allow others to use
00015 * your version of this file under the MPL, indicate your decision by
00016 * deleting the provisions above and replace them with the notice and
00017 * other provisions required by the GNU License. If you do not delete
00018 * the provisions above, a recipient may use your version of this file
00019 * under either the MPL or the GNU License."
00020 *
00021 * Software distributed under the License is distributed on an "AS IS"
00022 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00023 * the License for the specific language governing rights and limitations
00024 * under the License.
00025 *
00026 * The Original Code is derived from and used in conjunction with the 
00027 * H323Plus Project (www.h323plus.org/)
00028 *
00029 * The Initial Developer of the Original Code is ISVO (Asia) Pte Ltd.
00030 *
00031 *
00032 * Contributor(s): ______________________________________.
00033 *
00034 * $Revision: 28624 $
00035 * $Author: rjongbloed $
00036 * $Date: 2012-12-02 22:13:25 -0600 (Sun, 02 Dec 2012) $
00037 */
00038 
00039 #ifndef H_H460_Featurestd23
00040 #define H_H460_Featurestd23
00041 
00042 
00043 #include <h460/h4601.h>
00044 #include <ptlib/plugin.h>
00045 #include <ptclib/pstun.h>
00046 
00047 #if _MSC_VER
00048 #pragma once
00049 #endif
00050 
00051 class H323EndPoint;
00052 class H460_FeatureStd23;
00053 class PNatMethod_H46024  : public PSTUNClient, public PThread
00054 {
00055     PCLASSINFO(PNatMethod_H46024, PNatMethod);
00056 
00057   public:
00058     PNatMethod_H46024();
00059 
00060     ~PNatMethod_H46024();
00061 
00062     static PString GetNatMethodName();
00063     virtual PString GetName() const;
00064 
00065     // Start the Nat Method testing
00066     void Start(const PString & server,H460_FeatureStd23 * _feat);
00067 
00068     // Main thread testing
00069     void Main();
00070 
00071     // Whether the NAT method is Available
00072     virtual bool IsAvailable(
00073       const PIPSocket::Address & binding = PIPSocket::GetDefaultIpAny()  
00074     );
00075 
00076     // Create the socket pair
00077     virtual PBoolean CreateSocketPair(
00078       PUDPSocket * & socket1,
00079       PUDPSocket * & socket2,
00080       const PIPSocket::Address & binding = PIPSocket::GetDefaultIpAny()
00081     );
00082 
00083     // Whether the NAT Method is available
00084     void SetAvailable();
00085 
00086     // Whether the NAT method is activated for this call
00087     virtual void Activate(bool act);
00088 
00089     // Reportable NAT Type
00090     PSTUNClient::NatTypes GetNATType();
00091 
00092   protected:
00093     // Do a NAT test
00094     PSTUNClient::NatTypes NATTest();
00095 
00096   private:
00097     bool                    isActive;
00098     bool                    isAvailable;
00099     PSTUNClient::NatTypes    natType;
00100     H460_FeatureStd23 *        feat;
00101 };
00102 
00103 
00105 
00106 class H460_FeatureStd23 : public H460_FeatureStd 
00107 {
00108     PCLASSINFO(H460_FeatureStd23, H460_FeatureStd);
00109 
00110   public:
00111 
00112     H460_FeatureStd23();
00113     virtual ~H460_FeatureStd23();
00114 
00115     // Universal Declarations Every H460 Feature should have the following
00116     virtual void AttachEndPoint(H323EndPoint * _ep);
00117 
00118     static PStringArray GetFeatureName()         { return PStringArray("Std23"); };
00119     static PStringArray GetFeatureFriendlyName() { return PStringArray("P2Pnat Detect-H.460.23"); };
00120     static int GetPurpose()                     { return FeatureRas; };
00121     static PStringArray GetIdentifier()          { return PStringArray("23"); };
00122 
00123     virtual PBoolean CommonFeature() { return isEnabled; }
00124 
00125     // Messages
00126     // GK -> EP
00127     virtual PBoolean OnSendGatekeeperRequest(H225_FeatureDescriptor & pdu);
00128     virtual void OnReceiveGatekeeperConfirm(const H225_FeatureDescriptor & pdu);
00129 
00130     virtual PBoolean OnSendRegistrationRequest(H225_FeatureDescriptor & pdu);
00131     virtual void OnReceiveRegistrationConfirm(const H225_FeatureDescriptor & pdu);
00132 
00133     H323EndPoint * GetEndPoint() const { return (H323EndPoint *)EP; }
00134 
00135     // Reporting the NAT Type
00136     void OnNATTypeDetection(PSTUNClient::NatTypes type, const PIPSocket::Address & ExtIP);
00137 
00138     bool IsAvailable();
00139 
00140     bool AlternateNATMethod();
00141     bool UseAlternate();
00142 
00143   #ifdef H323_UPnP
00144     void InitialiseUPnP();
00145   #endif
00146 
00147   protected:
00148     bool DetectALG(const PIPSocket::Address & detectAddress);
00149     void StartSTUNTest(const PString & server);
00150 
00151     void DelayedReRegistration();
00152 
00153   private:
00154     H323EndPoint *         EP;
00155     PSTUNClient::NatTypes  natType;
00156     PIPSocket::Address     externalIP;
00157     PBoolean               natNotify;
00158     PBoolean               alg;
00159     PBoolean               isavailable;
00160     PBoolean               isEnabled; 
00161     int                    useAlternate;
00162 
00163     // Delayed Reregistration
00164     PThread  *  RegThread;
00165     PDECLARE_NOTIFIER(PThread, H460_FeatureStd23, RegMethod);
00166 };
00167 
00168 
00169 // Need to declare for Factory Loader
00170 #if !defined(_WIN32_WCE)
00171 PPLUGIN_STATIC_LOAD(Std23, H460_Feature);
00172 #endif
00173 
00174 
00176 
00177 class H323EndPoint;
00178 class H323Connection;
00179 
00180 class H460_FeatureStd24 : public H460_FeatureStd 
00181 {
00182     PCLASSINFO(H460_FeatureStd24, H460_FeatureStd);
00183 
00184   public:
00185     H460_FeatureStd24();
00186     virtual ~H460_FeatureStd24();
00187 
00188     // Universal Declarations Every H460 Feature should have the following
00189     virtual void AttachEndPoint(H323EndPoint * _ep);
00190     virtual void AttachConnection(H323Connection * _ep);
00191 
00192     static PStringArray GetFeatureName() { return PStringArray("Std24"); };
00193     static PStringArray GetFeatureFriendlyName() { return PStringArray("P2Pnat Media-H.460.24"); };
00194     static int GetPurpose()    { return FeatureSignal; };
00195     static PStringArray GetIdentifier() { return PStringArray("24"); };
00196 
00197     virtual PBoolean CommonFeature() { return isEnabled; }
00198 
00199     enum NatInstruct {
00200       e_unknown,
00201       e_noassist,
00202       e_localMaster,
00203       e_remoteMaster,
00204       e_localProxy,
00205       e_remoteProxy,
00206       e_natFullProxy,
00207       e_natAnnexA,                // Same NAT
00208       e_natAnnexB,                // NAT Offload
00209       e_natFailure = 100
00210     };
00211 
00212     static PString GetNATStrategyString(NatInstruct method);
00213 
00214     enum H46024NAT {
00215       e_default,        // This will use the underlying NAT Method
00216       e_enable,        // Use H.460.24 method (STUN)
00217       e_AnnexA,       // Disable H.460.24 method but initiate AnnexA
00218       e_AnnexB,        // Disable H.460.24 method but initiate AnnexB
00219       e_disable        // Disable all and remote will do the NAT help        
00220     };
00221 
00222     // Messages
00223     virtual PBoolean OnSendAdmissionRequest(H225_FeatureDescriptor & pdu);
00224     virtual void OnReceiveAdmissionConfirm(const H225_FeatureDescriptor & pdu);
00225     virtual void OnReceiveAdmissionReject(const H225_FeatureDescriptor & pdu);
00226 
00227     virtual PBoolean OnSendSetup_UUIE(H225_FeatureDescriptor & pdu);
00228     virtual void OnReceiveSetup_UUIE(const H225_FeatureDescriptor & pdu);
00229 
00230   protected:
00231     void HandleNATInstruction(NatInstruct natconfig);
00232     void SetNATMethods(H46024NAT state);
00233     void SetH46019State(bool state);
00234 
00235   private:
00236     H323EndPoint * EP;
00237     H323Connection * CON;
00238     NatInstruct natconfig;
00239     PMutex h460mute;
00240     int nattype;
00241     bool isEnabled;
00242     bool useAlternate;
00243 };
00244 
00245 
00246 inline ostream & operator<<(ostream & strm, H460_FeatureStd24::NatInstruct method) { return strm << H460_FeatureStd24::GetNATStrategyString(method); }
00247 
00248 // Need to declare for Factory Loader
00249 #if !defined(_WIN32_WCE)
00250 PPLUGIN_STATIC_LOAD(Std24, H460_Feature);
00251 #endif
00252 
00253 
00254 #endif // H_H460_Featurestd23

Generated on 21 Jun 2013 for OPAL by  doxygen 1.4.7