1 /*
2  * h323annexg.cxx
3  *
4  * Implementation of H.323 Annex G using H.501
5  *
6  * Open H323 Library
7  *
8  * Copyright (c) 2001 Equivalence Pty. Ltd.
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is Open H323 Library.
21  *
22  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
23  *
24  * Contributor(s): ______________________________________.
25  *
26  * $Revision: 21293 $
27  * $Author: rjongbloed $
28  * $Date: 2008-10-12 18:24:41 -0500 (Sun, 12 Oct 2008) $
29  */
30 
31 #include <ptlib.h>
32 
33 #include <opal/buildopts.h>
34 
35 #if OPAL_H501
36 
37 #ifdef __GNUC__
38 #pragma implementation "h323annexg.h"
39 #endif
40 
41 
42 #include <h323/h323annexg.h>
43 
44 #include <h323/h323ep.h>
45 #include <h323/h323pdu.h>
46 
47 #include <ptclib/random.h>
48 
49 
50 #define new PNEW
51 
52 
53 ///////////////////////////////////////////////////////////////////////////////
54 
H323_AnnexG(H323EndPoint & ep,H323Transport * trans)55 H323_AnnexG::H323_AnnexG(H323EndPoint & ep, H323Transport * trans)
56   : H323Transactor(ep, trans, DefaultUdpPort, DefaultUdpPort)
57 {
58   Construct();
59 }
60 
H323_AnnexG(H323EndPoint & ep,const H323TransportAddress & addr)61 H323_AnnexG::H323_AnnexG(H323EndPoint & ep, const H323TransportAddress & addr)
62   : H323Transactor(ep, addr, DefaultUdpPort, DefaultUdpPort)
63 {
64   Construct();
65 }
66 
Construct()67 void H323_AnnexG::Construct()
68 {
69   lastRequest = NULL;
70   requests.DisallowDeleteObjects();
71 }
72 
~H323_AnnexG()73 H323_AnnexG::~H323_AnnexG()
74 {
75   StopChannel();
76 }
77 
PrintOn(ostream & strm) const78 void H323_AnnexG::PrintOn(ostream & strm) const
79 {
80   strm << "H501@";
81   H323Transactor::PrintOn(strm);
82 }
83 
84 
CreateTransactionPDU() const85 H323TransactionPDU * H323_AnnexG::CreateTransactionPDU() const
86 {
87   return new H501PDU;
88 }
89 
90 
HandleTransaction(const PASN_Object & rawPDU)91 PBoolean H323_AnnexG::HandleTransaction(const PASN_Object & rawPDU)
92 {
93   const H501PDU & pdu = (const H501PDU &)rawPDU;
94 
95   switch (pdu.m_body.GetTag()) {
96     case H501_MessageBody::e_serviceRequest :
97       if (SendCachedResponse(pdu))
98         return PFalse;
99       OnReceiveServiceRequest(pdu, pdu.m_body);
100       break;
101 
102     case H501_MessageBody::e_serviceConfirmation :
103       return OnReceiveServiceConfirmation(pdu, pdu.m_body);
104 
105     case H501_MessageBody::e_serviceRejection :
106       return OnReceiveServiceRejection(pdu, pdu.m_body);
107 
108     case H501_MessageBody::e_serviceRelease :
109       if (SendCachedResponse(pdu))
110         return PFalse;
111       OnReceiveServiceRelease(pdu, pdu.m_body);
112       break;
113 
114     case H501_MessageBody::e_descriptorRequest :
115       if (SendCachedResponse(pdu))
116         return PFalse;
117       OnReceiveDescriptorRequest(pdu, pdu.m_body);
118       break;
119 
120     case H501_MessageBody::e_descriptorConfirmation :
121       return OnReceiveDescriptorConfirmation(pdu, pdu.m_body);
122 
123     case H501_MessageBody::e_descriptorRejection :
124       return OnReceiveDescriptorRejection(pdu, pdu.m_body);
125 
126     case H501_MessageBody::e_descriptorIDRequest :
127       if (SendCachedResponse(pdu))
128         return PFalse;
129       OnReceiveDescriptorIDRequest(pdu, pdu.m_body);
130       break;
131 
132     case H501_MessageBody::e_descriptorIDConfirmation :
133       return OnReceiveDescriptorIDConfirmation(pdu, pdu.m_body);
134 
135     case H501_MessageBody::e_descriptorIDRejection :
136       return OnReceiveDescriptorIDRejection(pdu, pdu.m_body);
137 
138     case H501_MessageBody::e_descriptorUpdate :
139       if (SendCachedResponse(pdu))
140         return PFalse;
141       OnReceiveDescriptorUpdate(pdu, pdu.m_body);
142       break;
143 
144     case H501_MessageBody::e_descriptorUpdateAck :
145       return OnReceiveDescriptorUpdateACK(pdu, pdu.m_body);
146 
147     case H501_MessageBody::e_accessRequest :
148       if (SendCachedResponse(pdu))
149         return PFalse;
150       OnReceiveAccessRequest(pdu, pdu.m_body);
151       break;
152 
153     case H501_MessageBody::e_accessConfirmation :
154       return OnReceiveAccessConfirmation(pdu, pdu.m_body);
155 
156     case H501_MessageBody::e_accessRejection :
157       return OnReceiveAccessRejection(pdu, pdu.m_body);
158 
159     case H501_MessageBody::e_requestInProgress :
160       return OnReceiveRequestInProgress(pdu, pdu.m_body);
161 
162     case H501_MessageBody::e_nonStandardRequest :
163       if (SendCachedResponse(pdu))
164         return PFalse;
165       OnReceiveNonStandardRequest(pdu, pdu.m_body);
166       break;
167 
168     case H501_MessageBody::e_nonStandardConfirmation :
169       return OnReceiveNonStandardConfirmation(pdu, pdu.m_body);
170 
171     case H501_MessageBody::e_nonStandardRejection :
172       return OnReceiveNonStandardRejection(pdu, pdu.m_body);
173 
174     case H501_MessageBody::e_unknownMessageResponse :
175       OnReceiveUnknownMessageResponse(pdu, pdu.m_body);
176       break;
177 
178     case H501_MessageBody::e_usageRequest :
179       if (SendCachedResponse(pdu))
180         return PFalse;
181       OnReceiveUsageRequest(pdu, pdu.m_body);
182       break;
183 
184     case H501_MessageBody::e_usageConfirmation :
185       return OnReceiveUsageConfirmation(pdu, pdu.m_body);
186 
187     case H501_MessageBody::e_usageIndication :
188       if (SendCachedResponse(pdu))
189         return PFalse;
190       OnReceiveUnknownMessageResponse(pdu, pdu.m_body);
191       break;
192 
193     case H501_MessageBody::e_usageIndicationConfirmation :
194       return OnReceiveUsageIndicationConfirmation(pdu, pdu.m_body);
195 
196     case H501_MessageBody::e_usageIndicationRejection :
197       return OnReceiveUsageIndicationRejection(pdu, pdu.m_body);
198 
199     case H501_MessageBody::e_usageRejection :
200       return OnReceiveUsageRejection(pdu, pdu.m_body);
201 
202     case H501_MessageBody::e_validationRequest :
203       if (SendCachedResponse(pdu))
204         return PFalse;
205       OnReceiveValidationRequest(pdu, pdu.m_body);
206       break;
207 
208     case H501_MessageBody::e_validationConfirmation :
209       return OnReceiveValidationConfirmation(pdu, pdu.m_body);
210 
211     case H501_MessageBody::e_validationRejection :
212       return OnReceiveValidationRejection(pdu, pdu.m_body);
213 
214     case H501_MessageBody::e_authenticationRequest :
215       if (SendCachedResponse(pdu))
216         return PFalse;
217       OnReceiveAuthenticationRequest(pdu, pdu.m_body);
218       break;
219 
220     case H501_MessageBody::e_authenticationConfirmation :
221       return OnReceiveAuthenticationConfirmation(pdu, pdu.m_body);
222 
223     case H501_MessageBody::e_authenticationRejection :
224       return OnReceiveAuthenticationRejection(pdu, pdu.m_body);
225 
226     default :
227       OnReceiveUnknown(pdu);
228   }
229 
230   return PFalse;
231 }
232 
233 
OnSendingPDU(PASN_Object &)234 void H323_AnnexG::OnSendingPDU(PASN_Object & /*rawPDU*/)
235 {
236 }
237 
238 
OnReceiveUnknown(const H501PDU &)239 PBoolean H323_AnnexG::OnReceiveUnknown(const H501PDU &)
240 {
241   H501PDU response;
242   response.BuildUnknownMessageResponse(0);
243   return response.Write(*transport);
244 }
245 
OnReceiveServiceRequest(const H501PDU & pdu,const H501_ServiceRequest &)246 PBoolean H323_AnnexG::OnReceiveServiceRequest(const H501PDU & pdu, const H501_ServiceRequest & /*pduBody*/)
247 {
248   PTRACE(3, "AnnexG\tOnReceiveServiceRequest - seq: " << pdu.m_common.m_sequenceNumber);
249   H501PDU response;
250   response.BuildServiceRejection(pdu.m_common.m_sequenceNumber, H501_ServiceRejectionReason::e_serviceUnavailable);
251   return response.Write(*transport);
252 }
253 
OnReceiveServiceConfirmation(const H501PDU & pdu,const H501_ServiceConfirmation &)254 PBoolean H323_AnnexG::OnReceiveServiceConfirmation(const H501PDU & pdu, const H501_ServiceConfirmation & /*pduBody*/)
255 {
256   return CheckForResponse(H501_MessageBody::e_serviceRequest, pdu.m_common.m_sequenceNumber);
257 }
258 
OnReceiveServiceRejection(const H501PDU & pdu,const H501_ServiceRejection & pduBody)259 PBoolean H323_AnnexG::OnReceiveServiceRejection(const H501PDU & pdu, const H501_ServiceRejection & pduBody)
260 {
261   return CheckForResponse(H501_MessageBody::e_serviceRequest, pdu.m_common.m_sequenceNumber, &pduBody.m_reason);
262 }
263 
OnReceiveServiceRelease(const H501PDU &,const H501_ServiceRelease &)264 PBoolean H323_AnnexG::OnReceiveServiceRelease(const H501PDU & /*common*/, const H501_ServiceRelease & /*pdu*/)
265 {
266   return PFalse;
267 }
268 
OnReceiveDescriptorRequest(const H501PDU & PTRACE_PARAM (pdu),const H501_DescriptorRequest &)269 PBoolean H323_AnnexG::OnReceiveDescriptorRequest(const H501PDU & PTRACE_PARAM(pdu), const H501_DescriptorRequest & /*pdu*/)
270 {
271   PTRACE(3, "AnnexG\tOnReceiveDescriptorRequest - seq: " << pdu.m_common.m_sequenceNumber);
272   return PFalse;
273 }
274 
OnReceiveDescriptorConfirmation(const H501PDU & PTRACE_PARAM (pdu),const H501_DescriptorConfirmation &)275 PBoolean H323_AnnexG::OnReceiveDescriptorConfirmation(const H501PDU & PTRACE_PARAM(pdu), const H501_DescriptorConfirmation & /*pdu*/)
276 {
277   PTRACE(3, "AnnexG\tOnReceiveDescriptorConfirmation - seq: " << pdu.m_common.m_sequenceNumber);
278   return PFalse;
279 }
280 
OnReceiveDescriptorRejection(const H501PDU & PTRACE_PARAM (pdu),const H501_DescriptorRejection &)281 PBoolean H323_AnnexG::OnReceiveDescriptorRejection(const H501PDU & PTRACE_PARAM(pdu), const H501_DescriptorRejection & /*pdu*/)
282 {
283   PTRACE(3, "AnnexG\tOnReceiveDescriptorRejection - seq: " << pdu.m_common.m_sequenceNumber);
284   return PFalse;
285 }
286 
OnReceiveDescriptorIDRequest(const H501PDU & PTRACE_PARAM (pdu),const H501_DescriptorIDRequest &)287 PBoolean H323_AnnexG::OnReceiveDescriptorIDRequest(const H501PDU & PTRACE_PARAM(pdu), const H501_DescriptorIDRequest & /*pdu*/)
288 {
289   PTRACE(3, "AnnexG\tOnReceiveDescriptorIDRequest - seq: " << pdu.m_common.m_sequenceNumber);
290   return PFalse;
291 }
292 
OnReceiveDescriptorIDConfirmation(const H501PDU & PTRACE_PARAM (pdu),const H501_DescriptorIDConfirmation &)293 PBoolean H323_AnnexG::OnReceiveDescriptorIDConfirmation(const H501PDU & PTRACE_PARAM(pdu), const H501_DescriptorIDConfirmation & /*pdu*/)
294 {
295   PTRACE(3, "AnnexG\tOnReceiveDescriptorIDConfirmation - seq: " << pdu.m_common.m_sequenceNumber);
296   return PFalse;
297 }
298 
OnReceiveDescriptorIDRejection(const H501PDU & PTRACE_PARAM (pdu),const H501_DescriptorIDRejection &)299 PBoolean H323_AnnexG::OnReceiveDescriptorIDRejection(const H501PDU & PTRACE_PARAM(pdu), const H501_DescriptorIDRejection & /*pdu*/)
300 {
301   PTRACE(3, "AnnexG\tOnReceiveDescriptorIDRejection - seq: " << pdu.m_common.m_sequenceNumber);
302   return PFalse;
303 }
304 
OnReceiveDescriptorUpdate(const H501PDU & PTRACE_PARAM (pdu),const H501_DescriptorUpdate &)305 PBoolean H323_AnnexG::OnReceiveDescriptorUpdate(const H501PDU & PTRACE_PARAM(pdu), const H501_DescriptorUpdate & /*pdu*/)
306 {
307   PTRACE(3, "AnnexG\tOnReceiveDescriptorUpdate - seq: " << pdu.m_common.m_sequenceNumber);
308   return PFalse;
309 }
310 
OnReceiveDescriptorUpdateACK(const H501PDU & pdu,const H501_DescriptorUpdateAck &)311 PBoolean H323_AnnexG::OnReceiveDescriptorUpdateACK(const H501PDU & pdu, const H501_DescriptorUpdateAck & /*pdu*/)
312 {
313   PTRACE(3, "AnnexG\tOnReceiveDescriptorUpdateACK - seq: " << pdu.m_common.m_sequenceNumber);
314   return CheckForResponse(H501_MessageBody::e_descriptorUpdate, pdu.m_common.m_sequenceNumber);
315 }
316 
OnReceiveAccessRequest(const H501PDU & PTRACE_PARAM (pdu),const H501_AccessRequest &)317 PBoolean H323_AnnexG::OnReceiveAccessRequest(const H501PDU & PTRACE_PARAM(pdu), const H501_AccessRequest & /*pdu*/)
318 {
319   PTRACE(3, "AnnexG\tOnReceiveAccessRequest - seq: " << pdu.m_common.m_sequenceNumber);
320   return PFalse;
321 }
322 
OnReceiveAccessConfirmation(const H501PDU & pdu,const H501_AccessConfirmation &)323 PBoolean H323_AnnexG::OnReceiveAccessConfirmation(const H501PDU & pdu, const H501_AccessConfirmation & /*pdu*/)
324 {
325   PTRACE(3, "AnnexG\tOnReceiveAccessConfirmation - seq: " << pdu.m_common.m_sequenceNumber);
326   return CheckForResponse(H501_MessageBody::e_accessRequest, pdu.m_common.m_sequenceNumber);
327 }
328 
OnReceiveAccessRejection(const H501PDU & pdu,const H501_AccessRejection & pduBody)329 PBoolean H323_AnnexG::OnReceiveAccessRejection(const H501PDU & pdu, const H501_AccessRejection & pduBody)
330 {
331   PTRACE(3, "AnnexG\tOnReceiveAccessRejection - seq: " << pdu.m_common.m_sequenceNumber);
332   return CheckForResponse(H501_MessageBody::e_accessRequest, pdu.m_common.m_sequenceNumber, &pduBody.m_reason);
333 }
334 
OnReceiveRequestInProgress(const H501PDU & pdu,const H501_RequestInProgress & rip)335 PBoolean H323_AnnexG::OnReceiveRequestInProgress(const H501PDU & pdu, const H501_RequestInProgress & rip)
336 {
337   return HandleRequestInProgress(pdu, rip.m_delay);
338 }
339 
OnReceiveNonStandardRequest(const H501PDU & PTRACE_PARAM (pdu),const H501_NonStandardRequest &)340 PBoolean H323_AnnexG::OnReceiveNonStandardRequest(const H501PDU & PTRACE_PARAM(pdu), const H501_NonStandardRequest & /*pdu*/)
341 {
342   PTRACE(3, "AnnexG\tOnReceiveNonStandardRequest - seq: " << pdu.m_common.m_sequenceNumber);
343   return PFalse;
344 }
345 
OnReceiveNonStandardConfirmation(const H501PDU & PTRACE_PARAM (pdu),const H501_NonStandardConfirmation &)346 PBoolean H323_AnnexG::OnReceiveNonStandardConfirmation(const H501PDU & PTRACE_PARAM(pdu), const H501_NonStandardConfirmation & /*pdu*/)
347 {
348   PTRACE(3, "AnnexG\tOnReceiveNonStandardConfirmation - seq: " << pdu.m_common.m_sequenceNumber);
349   return PFalse;
350 }
351 
OnReceiveNonStandardRejection(const H501PDU & PTRACE_PARAM (pdu),const H501_NonStandardRejection &)352 PBoolean H323_AnnexG::OnReceiveNonStandardRejection(const H501PDU & PTRACE_PARAM(pdu), const H501_NonStandardRejection & /*pdu*/)
353 {
354   PTRACE(3, "AnnexG\tOnReceiveNonStandardRejection - seq: " << pdu.m_common.m_sequenceNumber);
355   return PFalse;
356 }
357 
OnReceiveUnknownMessageResponse(const H501PDU & PTRACE_PARAM (pdu),const H501_UnknownMessageResponse &)358 PBoolean H323_AnnexG::OnReceiveUnknownMessageResponse(const H501PDU & PTRACE_PARAM(pdu), const H501_UnknownMessageResponse & /*pdu*/)
359 {
360   PTRACE(3, "AnnexG\tOnReceiveUnknownMessageResponse - seq: " << pdu.m_common.m_sequenceNumber);
361   return PFalse;
362 }
363 
OnReceiveUsageRequest(const H501PDU & PTRACE_PARAM (pdu),const H501_UsageRequest &)364 PBoolean H323_AnnexG::OnReceiveUsageRequest(const H501PDU & PTRACE_PARAM(pdu), const H501_UsageRequest & /*pdu*/)
365 {
366   PTRACE(3, "AnnexG\tOnReceiveUsageRequest - seq: " << pdu.m_common.m_sequenceNumber);
367   return PFalse;
368 }
369 
OnReceiveUsageConfirmation(const H501PDU & PTRACE_PARAM (pdu),const H501_UsageConfirmation &)370 PBoolean H323_AnnexG::OnReceiveUsageConfirmation(const H501PDU & PTRACE_PARAM(pdu), const H501_UsageConfirmation & /*pdu*/)
371 {
372   PTRACE(3, "AnnexG\tOnReceiveUsageConfirmation - seq: " << pdu.m_common.m_sequenceNumber);
373   return PFalse;
374 }
375 
OnReceiveUsageIndicationConfirmation(const H501PDU & PTRACE_PARAM (pdu),const H501_UsageIndicationConfirmation &)376 PBoolean H323_AnnexG::OnReceiveUsageIndicationConfirmation(const H501PDU & PTRACE_PARAM(pdu), const H501_UsageIndicationConfirmation & /*pdu*/)
377 {
378   PTRACE(3, "AnnexG\tOnReceiveUsageIndicationConfirmation - seq: " << pdu.m_common.m_sequenceNumber);
379   return PFalse;
380 }
381 
OnReceiveUsageIndicationRejection(const H501PDU & PTRACE_PARAM (pdu),const H501_UsageIndicationRejection &)382 PBoolean H323_AnnexG::OnReceiveUsageIndicationRejection(const H501PDU & PTRACE_PARAM(pdu), const H501_UsageIndicationRejection & /*pdu*/)
383 {
384   PTRACE(3, "AnnexG\tOnReceiveUsageIndicationRejection - seq: " << pdu.m_common.m_sequenceNumber);
385   return PFalse;
386 }
387 
OnReceiveUsageRejection(const H501PDU & PTRACE_PARAM (pdu),const H501_UsageRejection &)388 PBoolean H323_AnnexG::OnReceiveUsageRejection(const H501PDU & PTRACE_PARAM(pdu), const H501_UsageRejection & /*pdu*/)
389 {
390   PTRACE(3, "AnnexG\tOnReceiveUsageRejection - seq: " << pdu.m_common.m_sequenceNumber);
391   return PFalse;
392 }
393 
OnReceiveValidationRequest(const H501PDU & PTRACE_PARAM (pdu),const H501_ValidationRequest &)394 PBoolean H323_AnnexG::OnReceiveValidationRequest(const H501PDU & PTRACE_PARAM(pdu), const H501_ValidationRequest & /*pdu*/)
395 {
396   PTRACE(3, "AnnexG\tOnReceiveValidationRequest - seq: " << pdu.m_common.m_sequenceNumber);
397   return PFalse;
398 }
399 
OnReceiveValidationConfirmation(const H501PDU & PTRACE_PARAM (pdu),const H501_ValidationConfirmation &)400 PBoolean H323_AnnexG::OnReceiveValidationConfirmation(const H501PDU & PTRACE_PARAM(pdu), const H501_ValidationConfirmation & /*pdu*/)
401 {
402   PTRACE(3, "AnnexG\tOnReceiveValidationConfirmation - seq: " << pdu.m_common.m_sequenceNumber);
403   return PFalse;
404 }
405 
OnReceiveValidationRejection(const H501PDU & PTRACE_PARAM (pdu),const H501_ValidationRejection &)406 PBoolean H323_AnnexG::OnReceiveValidationRejection(const H501PDU & PTRACE_PARAM(pdu), const H501_ValidationRejection & /*pdu*/)
407 {
408   PTRACE(3, "AnnexG\tOnReceiveValidationRejection - seq: " << pdu.m_common.m_sequenceNumber);
409   return PFalse;
410 }
411 
OnReceiveAuthenticationRequest(const H501PDU & PTRACE_PARAM (pdu),const H501_AuthenticationRequest &)412 PBoolean H323_AnnexG::OnReceiveAuthenticationRequest(const H501PDU & PTRACE_PARAM(pdu), const H501_AuthenticationRequest & /*pdu*/)
413 {
414   PTRACE(3, "AnnexG\tOnReceiveAuthenticationRequest - seq: " << pdu.m_common.m_sequenceNumber);
415   return PFalse;
416 }
417 
OnReceiveAuthenticationConfirmation(const H501PDU & PTRACE_PARAM (pdu),const H501_AuthenticationConfirmation &)418 PBoolean H323_AnnexG::OnReceiveAuthenticationConfirmation(const H501PDU & PTRACE_PARAM(pdu), const H501_AuthenticationConfirmation & /*pdu*/)
419 {
420   PTRACE(3, "AnnexG\tOnReceiveAuthenticationConfirmation - seq: " << pdu.m_common.m_sequenceNumber);
421   return PFalse;
422 }
423 
OnReceiveAuthenticationRejection(const H501PDU & PTRACE_PARAM (pdu),const H501_AuthenticationRejection &)424 PBoolean H323_AnnexG::OnReceiveAuthenticationRejection(const H501PDU & PTRACE_PARAM(pdu), const H501_AuthenticationRejection & /*pdu*/)
425 {
426   PTRACE(3, "AnnexG\tOnReceiveAuthenticationRejection - seq: " << pdu.m_common.m_sequenceNumber);
427   return PFalse;
428 }
429 
430 
431 #endif // OPAL_H501
432 
433 /////////////////////////////////////////////////////////////////////////////
434