OPAL Version 3.10.4

- Main Page
- Related Pages
- Namespaces
- Data Structures
- Files

- File List
- Globals

h323trans.h
Go to the documentation of this file.
1 /*
2 * h323trans.h
3 *
4 * H.323 Transactor handler
5 *
6 * Open H323 Library
7 *
8 * Copyright (c) 2003 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: 24178 $
27 * $Author: rjongbloed $
28 * $Date: 2010-04-05 19:10:56 -0500 (Mon, 05 Apr 2010) $
29 */
30
31 #ifndef OPAL_H323_H323TRANS_H
32 #define OPAL_H323_H323TRANS_H
33
34 #ifdef P_USE_PRAGMA
35 #pragma interface
36 #endif
37
38 #include <opal/buildopts.h>
39
40 #if OPAL_H323
41
42 #include <h323/transaddr.h>
43 #include <h323/h235auth.h>
44
45 #include <ptclib/asner.h>
46
47
48 class H323EndPoint;
49
50
51 class H323TransactionPDU {
52 public:
53 H323TransactionPDU();
54 H323TransactionPDU(const H235Authenticators & auth);
55
56 virtual ~H323TransactionPDU() { }
57
58 virtual PBoolean Read(H323Transport & transport);
59 virtual PBoolean Write(H323Transport & transport);
60
61 virtual PASN_Object & GetPDU() = 0;
62 virtual PASN_Choice & GetChoice() = 0;
63 virtual const PASN_Object & GetPDU() const = 0;
64 virtual const PASN_Choice & GetChoice() const = 0;
65 virtual unsigned GetSequenceNumber() const = 0;
66 virtual unsigned GetRequestInProgressDelay() const = 0;
67 #if PTRACING
68 virtual const char * GetProtocolName() const = 0;
69 #endif
70 virtual H323TransactionPDU * ClonePDU() const = 0;
71 virtual void DeletePDU() = 0;
72
73 const H235Authenticators & GetAuthenticators() const { return authenticators; }
74 H235Authenticators & GetAuthenticators() { return authenticators; }
75 void SetAuthenticators(
76 const H235Authenticators & auth
77 ) { authenticators = auth; }
78
79 H235Authenticator::ValidationResult Validate(
80 const PASN_Array & clearTokens,
81 unsigned clearOptionalField,
82 const PASN_Array & cryptoTokens,
83 unsigned cryptoOptionalField
84 ) const { return authenticators.ValidatePDU(*this, clearTokens, clearOptionalField, cryptoTokens, cryptoOptionalField, rawPDU); }
85
86 void Prepare(
87 PASN_Array & clearTokens,
88 unsigned clearOptionalField,
89 PASN_Array & cryptoTokens,
90 unsigned cryptoOptionalField
91 ) { authenticators.PreparePDU(*this, clearTokens, clearOptionalField, cryptoTokens, cryptoOptionalField); }
92
93 protected:
94 mutable H235Authenticators authenticators;
95 PPER_Stream rawPDU;
96 };
97
98
100
101 class H323Transactor : public PObject
102 {
103 PCLASSINFO(H323Transactor, PObject);
104 public:
107
110 H323Transactor(
111 H323EndPoint & endpoint,
112 H323Transport * transport,
113 WORD localPort,
114 WORD remotePort
115 );
116 H323Transactor(
117 H323EndPoint & endpoint,
118 const H323TransportAddress & iface,
119 WORD localPort,
120 WORD remotePort
121 );
122
125 ~H323Transactor();
127
132 void PrintOn(
133 ostream & strm
134 ) const;
136
141 PBoolean SetTransport(
142 const H323TransportAddress & iface
143 );
144
147 H323TransportAddressArray GetInterfaceAddresses(
148 bool excludeLocalHost = true
149 );
150
153 virtual PBoolean StartChannel();
154
158 virtual void StopChannel();
159
162 virtual H323TransactionPDU * CreateTransactionPDU() const = 0;
163
166 virtual PBoolean HandleTransaction(
167 const PASN_Object & rawPDU
168 ) = 0;
169
172 virtual void OnSendingPDU(
173 PASN_Object & rawPDU
174 ) = 0;
175
178 virtual PBoolean WritePDU(
179 H323TransactionPDU & pdu
180 );
181
184 virtual PBoolean WriteTo(
185 H323TransactionPDU & pdu,
186 const H323TransportAddressArray & addresses,
187 PBoolean callback = true
188 );
190
195 H323EndPoint & GetEndPoint() const { return endpoint; }
196
199 H323Transport & GetTransport() const { return *transport; }
200
203 void SetCheckResponseCryptoTokens(
204 PBoolean value
205 ) { checkResponseCryptoTokens = value; }
206
209 PBoolean GetCheckResponseCryptoTokens() { return checkResponseCryptoTokens; }
211
212 protected:
213 void Construct();
214
215 unsigned GetNextSequenceNumber();
216 PBoolean SetUpCallSignalAddresses(
217 H225_ArrayOf_TransportAddress & addresses
218 );
219
220 //Background thread handler.
221 PDECLARE_NOTIFIER(PThread, H323Transactor, HandleTransactions);
222
223 class Request : public PObject
224 {
225 PCLASSINFO(Request, PObject);
226 public:
227 Request(
228 unsigned seqNum,
229 H323TransactionPDU & pdu
230 );
231 Request(
232 unsigned seqNum,
233 H323TransactionPDU & pdu,
234 const H323TransportAddressArray & addresses
235 );
236
237 PBoolean Poll(H323Transactor &,
238 unsigned numRetries = 0,
239 PTimeInterval timeout = 0);
240 void CheckResponse(unsigned, const PASN_Choice *);
241 void OnReceiveRIP(unsigned milliseconds);
242
243 // Inter-thread transfer variables
244 unsigned rejectReason;
245 void * responseInfo;
246
247 H323TransportAddressArray requestAddresses;
248
249 unsigned sequenceNumber;
250 H323TransactionPDU & requestPDU;
251 PTimeInterval whenResponseExpected;
252 PSyncPoint responseHandled;
253 PMutex responseMutex;
254
255 enum {
256 AwaitingResponse,
257 ConfirmReceived,
258 RejectReceived,
259 TryAlternate,
260 BadCryptoTokens,
261 RequestInProgress,
262 NoResponseReceived
263 } responseResult;
264 };
265
266 virtual PBoolean MakeRequest(
267 Request & request
268 );
269 PBoolean CheckForResponse(
270 unsigned,
271 unsigned,
272 const PASN_Choice * = NULL
273 );
274 PBoolean HandleRequestInProgress(
275 const H323TransactionPDU & pdu,
276 unsigned delay
277 );
278 PBoolean CheckCryptoTokens(
279 const H323TransactionPDU & pdu,
280 const PASN_Array & clearTokens,
281 unsigned clearOptionalField,
282 const PASN_Array & cryptoTokens,
283 unsigned cryptoOptionalField
284 );
285
286 void AgeResponses();
287 PBoolean SendCachedResponse(
288 const H323TransactionPDU & pdu
289 );
290
291 class Response : public PString
292 {
293 PCLASSINFO(Response, PString);
294 public:
295 Response(const H323TransportAddress & addr, unsigned seqNum);
296 ~Response();
297
298 void SetPDU(const H323TransactionPDU & pdu);
299 PBoolean SendCachedResponse(H323Transport & transport);
300
301 PTime lastUsedTime;
302 PTimeInterval retirementAge;
303 H323TransactionPDU * replyPDU;
304 };
305
306 // Configuration variables
307 H323EndPoint & endpoint;
308 WORD defaultLocalPort;
309 WORD defaultRemotePort;
310 H323Transport * transport;
311 PBoolean checkResponseCryptoTokens;
312
313 unsigned nextSequenceNumber;
314 PMutex nextSequenceNumberMutex;
315
316 PDictionary<POrdinalKey, Request> requests;
317 PMutex requestsMutex;
318 Request * lastRequest;
319
320 PMutex pduWriteMutex;
321 PSortedList<Response> responses;
322 };
323
324
326
327 class H323Transaction : public PObject
328 {
329 PCLASSINFO(H323Transaction, PObject);
330 public:
335 H323Transaction(
336 H323Transactor & transactor,
337 const H323TransactionPDU & requestToCopy,
338 H323TransactionPDU * confirm,
339 H323TransactionPDU * reject
340 );
341 ~H323Transaction();
343
344 enum Response {
345 Ignore = -2,
346 Reject = -1,
347 Confirm = 0
348 };
349 inline static Response InProgress(unsigned time) { return (Response)(time&0xffff); }
350
351 virtual H323TransactionPDU * CreateRIP(
352 unsigned sequenceNumber,
353 unsigned delay
354 ) const = 0;
355
356 PBoolean HandlePDU();
357
358 virtual PBoolean WritePDU(
359 H323TransactionPDU & pdu
360 );
361
362 PBoolean CheckCryptoTokens(
363 const H235Authenticators & authenticators
364 );
365
366 #if PTRACING
367 virtual const char * GetName() const = 0;
368 #endif
369 virtual H235Authenticator::ValidationResult ValidatePDU() const = 0;
370 virtual void SetRejectReason(
371 unsigned reasonCode
372 ) = 0;
373
374 PBoolean IsFastResponseRequired() const { return fastResponseRequired && canSendRIP; }
375 PBoolean CanSendRIP() const { return canSendRIP; }
376 H323TransportAddress GetReplyAddress() const { return replyAddresses[0]; }
377 const H323TransportAddressArray & GetReplyAddresses() const { return replyAddresses; }
378 PBoolean IsBehindNAT() const { return isBehindNAT; }
379 H323Transactor & GetTransactor() const { return transactor; }
380 H235Authenticator::ValidationResult GetAuthenticatorResult() const { return authenticatorResult; }
381
382 protected:
383 virtual Response OnHandlePDU() = 0;
384 PDECLARE_NOTIFIER(PThread, H323Transaction, SlowHandler);
385
386 H323Transactor & transactor;
387 unsigned requestSequenceNumber;
388 H323TransportAddressArray replyAddresses;
389 PBoolean fastResponseRequired;
390 H323TransactionPDU * request;
391 H323TransactionPDU * confirm;
392 H323TransactionPDU * reject;
393
394 H235Authenticators authenticators;
395 H235Authenticator::ValidationResult authenticatorResult;
396 PBoolean isBehindNAT;
397 PBoolean canSendRIP;
398 };
399
400
402
403 class H323TransactionServer : public PObject
404 {
405 PCLASSINFO(H323TransactionServer, PObject);
406 public:
411 H323TransactionServer(
412 H323EndPoint & endpoint
413 );
414
417 ~H323TransactionServer();
419
420 virtual WORD GetDefaultUdpPort() = 0;
421
426 H323EndPoint & GetOwnerEndPoint() const { return ownerEndPoint; }
427
441 PBoolean AddListeners(
442 const H323TransportAddressArray & ifaces
443 );
444
448 PBoolean AddListener(
449 const H323TransportAddress & interfaceName
450 );
451
458 PBoolean AddListener(
459 H323Transport * transport
460 );
461
468 PBoolean AddListener(
469 H323Transactor * listener
470 );
471
480 virtual H323Transactor * CreateListener(
481 H323Transport * transport
482 ) = 0;
483
487 PBoolean RemoveListener(
488 H323Transactor * listener
489 );
490
491 PBoolean SetUpCallSignalAddresses(H225_ArrayOf_TransportAddress & addresses);
493
494 protected:
495 H323EndPoint & ownerEndPoint;
496
497 PThread * monitorThread;
498 PSyncPoint monitorExit;
499
500 PMutex mutex;
501 PLIST(ListenerList, H323Transactor);
502 ListenerList listeners;
503 };
504
505
506 #endif // OPAL_H323
507
508 #endif // OPAL_H323_H323TRANS_H
509
510