OPAL  Version 3.12.9
h460_std23.h
Go to the documentation of this file.
1 /* H460_std23.h
2 *
3 * Copyright (c) 2009 ISVO (Asia) Pte Ltd. All Rights Reserved.
4 *
5 * The contents of this file are subject to the Mozilla Public License
6 * Version 1.1 (the "License"); you may not use this file except in
7 * compliance with the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Alternatively, the contents of this file may be used under the terms
11 * of the General Public License (the "GNU License"), in which case the
12 * provisions of GNU License are applicable instead of those
13 * above. If you wish to allow use of your version of this file only
14 * under the terms of the GNU License and not to allow others to use
15 * your version of this file under the MPL, indicate your decision by
16 * deleting the provisions above and replace them with the notice and
17 * other provisions required by the GNU License. If you do not delete
18 * the provisions above, a recipient may use your version of this file
19 * under either the MPL or the GNU License."
20 *
21 * Software distributed under the License is distributed on an "AS IS"
22 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
23 * the License for the specific language governing rights and limitations
24 * under the License.
25 *
26 * The Original Code is derived from and used in conjunction with the
27 * H323Plus Project (www.h323plus.org/)
28 *
29 * The Initial Developer of the Original Code is ISVO (Asia) Pte Ltd.
30 *
31 *
32 * Contributor(s): ______________________________________.
33 *
34 * $Revision: 28624 $
35 * $Author: rjongbloed $
36 * $Date: 2012-12-03 15:13:25 +1100 (Mon, 03 Dec 2012) $
37 */
38 
39 #ifndef H_H460_Featurestd23
40 #define H_H460_Featurestd23
41 
42 
43 #include <h460/h4601.h>
44 #include <ptlib/plugin.h>
45 #include <ptclib/pstun.h>
46 
47 #if _MSC_VER
48 #pragma once
49 #endif
50 
51 class H323EndPoint;
52 class H460_FeatureStd23;
53 class PNatMethod_H46024 : public PSTUNClient, public PThread
54 {
55  PCLASSINFO(PNatMethod_H46024, PNatMethod);
56 
57  public:
59 
61 
62  static PString GetNatMethodName();
63  virtual PString GetName() const;
64 
65  // Start the Nat Method testing
66  void Start(const PString & server,H460_FeatureStd23 * _feat);
67 
68  // Main thread testing
69  void Main();
70 
71  // Whether the NAT method is Available
72  virtual bool IsAvailable(
73  const PIPSocket::Address & binding = PIPSocket::GetDefaultIpAny()
74  );
75 
76  // Create the socket pair
77  virtual PBoolean CreateSocketPair(
78  PUDPSocket * & socket1,
79  PUDPSocket * & socket2,
80  const PIPSocket::Address & binding = PIPSocket::GetDefaultIpAny()
81  );
82 
83  // Whether the NAT Method is available
84  void SetAvailable();
85 
86  // Whether the NAT method is activated for this call
87  virtual void Activate(bool act);
88 
89  // Reportable NAT Type
90  PSTUNClient::NatTypes GetNATType();
91 
92  protected:
93  // Do a NAT test
94  PSTUNClient::NatTypes NATTest();
95 
96  private:
97  bool isActive;
98  bool isAvailable;
99  PSTUNClient::NatTypes natType;
100  H460_FeatureStd23 * feat;
101 };
102 
103 
105 
107 {
108  PCLASSINFO(H460_FeatureStd23, H460_FeatureStd);
109 
110  public:
111 
113  virtual ~H460_FeatureStd23();
114 
115  // Universal Declarations Every H460 Feature should have the following
116  virtual void AttachEndPoint(H323EndPoint * _ep);
117 
118  static PStringArray GetFeatureName() { return PStringArray("Std23"); };
119  static PStringArray GetFeatureFriendlyName() { return PStringArray("P2Pnat Detect-H.460.23"); };
120  static int GetPurpose() { return FeatureRas; };
121  static PStringArray GetIdentifier() { return PStringArray("23"); };
122 
123  virtual PBoolean CommonFeature() { return isEnabled; }
124 
125  // Messages
126  // GK -> EP
127  virtual PBoolean OnSendGatekeeperRequest(H225_FeatureDescriptor & pdu);
128  virtual void OnReceiveGatekeeperConfirm(const H225_FeatureDescriptor & pdu);
129 
130  virtual PBoolean OnSendRegistrationRequest(H225_FeatureDescriptor & pdu);
131  virtual void OnReceiveRegistrationConfirm(const H225_FeatureDescriptor & pdu);
132 
133  H323EndPoint * GetEndPoint() const { return (H323EndPoint *)EP; }
134 
135  // Reporting the NAT Type
136  void OnNATTypeDetection(PSTUNClient::NatTypes type, const PIPSocket::Address & ExtIP);
137 
138  bool IsAvailable();
139 
140  bool AlternateNATMethod();
141  bool UseAlternate();
142 
143  #ifdef H323_UPnP
144  void InitialiseUPnP();
145  #endif
146 
147  protected:
148  bool DetectALG(const PIPSocket::Address & detectAddress);
149  void StartSTUNTest(const PString & server);
150 
151  void DelayedReRegistration();
152 
153  private:
154  H323EndPoint * EP;
155  PSTUNClient::NatTypes natType;
156  PIPSocket::Address externalIP;
157  PBoolean natNotify;
158  PBoolean alg;
159  PBoolean isavailable;
160  PBoolean isEnabled;
161  int useAlternate;
162 
163  // Delayed Reregistration
164  PThread * RegThread;
165  PDECLARE_NOTIFIER(PThread, H460_FeatureStd23, RegMethod);
166 };
167 
168 
169 // Need to declare for Factory Loader
170 #if !defined(_WIN32_WCE)
172 #endif
173 
174 
176 
177 class H323EndPoint;
178 class H323Connection;
179 
181 {
182  PCLASSINFO(H460_FeatureStd24, H460_FeatureStd);
183 
184  public:
186  virtual ~H460_FeatureStd24();
187 
188  // Universal Declarations Every H460 Feature should have the following
189  virtual void AttachEndPoint(H323EndPoint * _ep);
190  virtual void AttachConnection(H323Connection * _ep);
191 
192  static PStringArray GetFeatureName() { return PStringArray("Std24"); };
193  static PStringArray GetFeatureFriendlyName() { return PStringArray("P2Pnat Media-H.460.24"); };
194  static int GetPurpose() { return FeatureSignal; };
195  static PStringArray GetIdentifier() { return PStringArray("24"); };
196 
197  virtual PBoolean CommonFeature() { return isEnabled; }
198 
199  enum NatInstruct {
207  e_natAnnexA, // Same NAT
208  e_natAnnexB, // NAT Offload
210  };
211 
212  static PString GetNATStrategyString(NatInstruct method);
213 
214  enum H46024NAT {
215  e_default, // This will use the underlying NAT Method
216  e_enable, // Use H.460.24 method (STUN)
217  e_AnnexA, // Disable H.460.24 method but initiate AnnexA
218  e_AnnexB, // Disable H.460.24 method but initiate AnnexB
219  e_disable // Disable all and remote will do the NAT help
220  };
221 
222  // Messages
223  virtual PBoolean OnSendAdmissionRequest(H225_FeatureDescriptor & pdu);
224  virtual void OnReceiveAdmissionConfirm(const H225_FeatureDescriptor & pdu);
225  virtual void OnReceiveAdmissionReject(const H225_FeatureDescriptor & pdu);
226 
227  virtual PBoolean OnSendSetup_UUIE(H225_FeatureDescriptor & pdu);
228  virtual void OnReceiveSetup_UUIE(const H225_FeatureDescriptor & pdu);
229 
230  protected:
231  void HandleNATInstruction(NatInstruct natconfig);
232  void SetNATMethods(H46024NAT state);
233  void SetH46019State(bool state);
234 
235  private:
236  H323EndPoint * EP;
237  H323Connection * CON;
238  NatInstruct natconfig;
239  PMutex h460mute;
240  int nattype;
241  bool isEnabled;
242  bool useAlternate;
243 };
244 
245 
246 inline ostream & operator<<(ostream & strm, H460_FeatureStd24::NatInstruct method) { return strm << H460_FeatureStd24::GetNATStrategyString(method); }
247 
248 // Need to declare for Factory Loader
249 #if !defined(_WIN32_WCE)
251 #endif
252 
253 
254 #endif // H_H460_Featurestd23